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

@@ -9,7 +9,7 @@ class PostFlag < ApplicationRecord
COOLDOWN_PERIOD = 3.days
belongs_to_creator :class_name => "User"
belongs_to :creator, class_name: "User"
belongs_to :post
validates_presence_of :reason
validate :validate_creator_is_not_limited, on: :create
@@ -124,7 +124,7 @@ class PostFlag < ApplicationRecord
def validate_creator_is_not_limited
return if is_deletion
if CurrentUser.can_approve_posts?
if creator.can_approve_posts?
# do nothing
elsif creator.created_at > 1.week.ago
errors[:creator] << "cannot flag within the first week of sign up"