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:
evazion
2020-01-18 15:52:01 -06:00
parent 77bf9ac7f3
commit b4ce2d83a6
86 changed files with 215 additions and 433 deletions

View File

@@ -7,8 +7,9 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
@other_user = create(:user)
@mod = create(:moderator_user)
as_user do
@forum_topic = create(:forum_topic, :title => "my forum topic", :original_post_attributes => {:body => "xxx"})
as(@user) do
@forum_topic = create(:forum_topic, creator: @user, title: "my forum topic")
@forum_post = create(:forum_post, creator: @user, topic: @forum_topic, body: "xxx")
end
end
@@ -28,9 +29,7 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
@gold_user = create(:gold_user)
# An open topic should bump...
as(@gold_user) do
@open_topic = create(:forum_topic)
end
@open_topic = as(@gold_user) { create(:forum_topic, creator: @gold_user) }
@gold_user.reload
as(@gold_user) do
assert(@gold_user.has_forum_been_updated?)
@@ -47,9 +46,7 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
end
# Then adding an unread private topic should not bump.
as(@mod) do
create(:forum_post, :topic_id => @forum_topic.id)
end
as(@mod) { create(:forum_post, topic: @forum_topic, creator: @mod) }
@gold_user.reload
as(@gold_user) do
assert_equal(false, @gold_user.has_forum_been_updated?)
@@ -91,8 +88,10 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
context "index action" do
setup do
as_user do
@topic1 = create(:forum_topic, :is_sticky => true, :original_post_attributes => {:body => "xxx"})
@topic2 = create(:forum_topic, :original_post_attributes => {:body => "xxx"})
@topic1 = create(:forum_topic, is_sticky: true, creator: @user)
@topic2 = create(:forum_topic, creator: @user)
@post1 = create(:forum_post, topic: @topic1, creator: @user, body: "xxx")
@post2 = create(:forum_post, topic: @topic2, creator: @user, body: "xxx")
end
end
@@ -158,7 +157,7 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
context "create action" do
should "create a new forum topic and post" do
assert_difference(["ForumPost.count", "ForumTopic.count"], 1) do
post_auth forum_topics_path, @user, params: {:forum_topic => {:title => "bababa", :original_post_attributes => {:body => "xaxaxa"}}}
post_auth forum_topics_path, @user, params: { forum_topic: { title: "bababa", original_post_attributes: { body: "xaxaxa" }}}
end
forum_topic = ForumTopic.last