models: remove belongs_to_creator macro.
The belongs_to_creator macro was used to initialize the creator_id field to the CurrentUser. This made tests complicated because it meant you had to create and set the current user every time you wanted to create an object, when lead to the current user being set over and over again. It also meant you had to constantly be aware of what the CurrentUser was in many different contexts, which was often confusing. Setting creators explicitly simplifies everything greatly.
This commit is contained in:
@@ -53,7 +53,7 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
context "outside a quote block" do
|
||||
setup do
|
||||
@user2 = FactoryBot.create(:user)
|
||||
@post = FactoryBot.build(:forum_post, :topic_id => @topic.id, :body => "Hey @#{@user2.name} check this out!")
|
||||
@post = build(:forum_post, creator: @user, topic: @topic, body: "Hey @#{@user2.name} check this out!")
|
||||
end
|
||||
|
||||
should "create a dmail" do
|
||||
@@ -63,7 +63,7 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
|
||||
dmail = Dmail.last
|
||||
assert_equal(<<-EOS.strip_heredoc, dmail.body)
|
||||
@#{CurrentUser.name} mentioned you in topic ##{@topic.id} (\"#{@topic.title}\":[/forum_topics/#{@topic.id}?page=1]):
|
||||
@#{@user.name} mentioned you in topic ##{@topic.id} (\"#{@topic.title}\":[/forum_topics/#{@topic.id}?page=1]):
|
||||
|
||||
[quote]
|
||||
Hey @#{@user2.name} check this out!
|
||||
@@ -169,7 +169,7 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "initialize its creator" do
|
||||
post = FactoryBot.create(:forum_post, :topic_id => @topic.id)
|
||||
post = create(:forum_post, topic: @topic, creator: @user)
|
||||
assert_equal(@user.id, post.creator_id)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user