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

@@ -268,8 +268,8 @@ class Post < ApplicationRecord
!is_status_locked? && (is_pending? || is_flagged? || is_deleted?) && uploader != user && !approved_by?(user)
end
def flag!(reason, options = {})
flag = flags.create(:reason => reason, :is_resolved => false, :is_deletion => options[:is_deletion])
def flag!(reason, is_deletion: false)
flag = flags.create(reason: reason, is_resolved: false, is_deletion: is_deletion, creator: CurrentUser.user)
if flag.errors.any?
raise PostFlag::Error.new(flag.errors.full_messages.join("; "))
@@ -746,7 +746,7 @@ class Post < ApplicationRecord
when /^newpool:(.+)$/i
pool = Pool.find_by_name($1)
if pool.nil?
pool = Pool.create(:name => $1, :description => "This pool was automatically generated")
pool = Pool.create(name: $1, creator: CurrentUser.user, description: "This pool was automatically generated")
end
end
end