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

@@ -18,7 +18,7 @@ class ArtistsController < ApplicationController
end
def ban
@artist.ban!
@artist.ban!(banner: CurrentUser.user)
redirect_to(artist_path(@artist), :notice => "Artist was banned")
end
@@ -48,7 +48,7 @@ class ArtistsController < ApplicationController
end
def create
@artist = Artist.create(artist_params)
@artist = Artist.create(artist_params.merge(creator: CurrentUser.user))
respond_with(@artist)
end

View File

@@ -10,7 +10,7 @@ class BulkUpdateRequestsController < ApplicationController
end
def create
@bulk_update_request = BulkUpdateRequest.create(bur_params(:create))
@bulk_update_request = BulkUpdateRequest.create(bur_params(:create).merge(user: CurrentUser.user))
respond_with(@bulk_update_request, :location => bulk_update_requests_path)
end

View File

@@ -33,7 +33,7 @@ class CommentsController < ApplicationController
end
def create
@comment = Comment.create(comment_params(:create))
@comment = Comment.create(comment_params(:create).merge(creator: CurrentUser.user, creator_ip_addr: CurrentUser.ip_addr))
flash[:notice] = @comment.valid? ? "Comment posted" : @comment.errors.full_messages.join("; ")
respond_with(@comment) do |format|
format.html do

View File

@@ -24,7 +24,7 @@ class FavoriteGroupsController < ApplicationController
end
def create
@favorite_group = FavoriteGroup.create(favgroup_params)
@favorite_group = CurrentUser.favorite_groups.create(favgroup_params)
respond_with(@favorite_group)
end

View File

@@ -9,7 +9,7 @@ class ForumPostVotesController < ApplicationController
def create
@forum_post = ForumPost.find(params[:forum_post_id])
@forum_post_vote = @forum_post.votes.create(forum_post_vote_params)
@forum_post_vote = @forum_post.votes.create(forum_post_vote_params.merge(creator: CurrentUser.user))
respond_with(@forum_post_vote)
end

View File

@@ -42,7 +42,7 @@ class ForumPostsController < ApplicationController
end
def create
@forum_post = ForumPost.create(forum_post_params(:create))
@forum_post = ForumPost.create(forum_post_params(:create).merge(creator: CurrentUser.user))
page = @forum_post.topic.last_page if @forum_post.topic.last_page > 1
respond_with(@forum_post, :location => forum_topic_path(@forum_post.topic, :page => page))
end

View File

@@ -43,7 +43,11 @@ class ForumTopicsController < ApplicationController
end
def create
@forum_topic = ForumTopic.create(forum_topic_params(:create))
@forum_topic = ForumTopic.new(forum_topic_params(:create))
@forum_topic.creator = CurrentUser.user
@forum_topic.original_post.creator = CurrentUser.user
@forum_topic.save
respond_with(@forum_topic)
end

View File

@@ -7,7 +7,7 @@ class IpBansController < ApplicationController
end
def create
@ip_ban = IpBan.create(ip_ban_params)
@ip_ban = CurrentUser.ip_bans.create(ip_ban_params)
respond_with(@ip_ban, :location => ip_bans_path)
end

View File

@@ -24,7 +24,7 @@ class NewsUpdatesController < ApplicationController
end
def create
@news_update = NewsUpdate.create(news_update_params)
@news_update = NewsUpdate.create(news_update_params.merge(creator: CurrentUser.user))
respond_with(@news_update, :location => news_updates_path)
end

View File

@@ -19,7 +19,7 @@ class NotesController < ApplicationController
end
def create
@note = Note.create(note_params(:create))
@note = Note.create(note_params(:create).merge(creator: CurrentUser.user))
respond_with(@note) do |fmt|
fmt.json do
if @note.errors.any?

View File

@@ -43,7 +43,7 @@ class PoolsController < ApplicationController
end
def create
@pool = Pool.create(pool_params)
@pool = Pool.create(pool_params.merge(creator: CurrentUser.user))
flash[:notice] = @pool.valid? ? "Pool created" : @pool.errors.full_messages.join("; ")
respond_with(@pool)
end

View File

@@ -13,7 +13,7 @@ class PostAppealsController < ApplicationController
end
def create
@post_appeal = PostAppeal.create(post_appeal_params)
@post_appeal = PostAppeal.create(post_appeal_params.merge(creator: CurrentUser.user))
respond_with(@post_appeal)
end

View File

@@ -13,7 +13,7 @@ class PostFlagsController < ApplicationController
end
def create
@post_flag = PostFlag.create(post_flag_params)
@post_flag = PostFlag.create(post_flag_params.merge(creator: CurrentUser.user))
respond_with(@post_flag)
end

View File

@@ -24,7 +24,7 @@ class UserFeedbacksController < ApplicationController
end
def create
@user_feedback = UserFeedback.create(user_feedback_params(:create))
@user_feedback = UserFeedback.create(user_feedback_params(:create).merge(creator: CurrentUser.user))
respond_with(@user_feedback)
end