Permalink
Browse files
restrict comment hats to user's own hats
- Loading branch information...
Showing
with
20 additions
and
0 deletions.
-
+3
−0
app/models/comment.rb
-
+16
−0
spec/models/comment_spec.rb
-
+1
−0
spec/support/blueprints.rb
|
|
@@ -57,6 +57,9 @@ class Comment < ApplicationRecord |
|
|
|
|
|
self.comment.to_s.strip.match(/\Ame too.?\z/i) &&
|
|
|
errors.add(:base, "Please just upvote the parent post instead.")
|
|
|
+
|
|
|
+ self.hat.present? && self.user.wearable_hats.exclude?(self.hat) &&
|
|
|
+ errors.add(:hat, "not wearable by user")
|
|
|
end
|
|
|
|
|
|
def self.arrange_for_user(user)
|
|
|
|
|
|
@@ -6,4 +6,20 @@ |
|
|
|
|
|
expect(c.short_id).to match(/^\A[a-zA-Z0-9]{1,10}\z/)
|
|
|
end
|
|
|
+
|
|
|
+ describe "hat" do
|
|
|
+ it "can't be worn if user doesn't have that hat" do
|
|
|
+ comment = Comment.make(hat: Hat.make!)
|
|
|
+ comment.valid?
|
|
|
+ expect(comment.errors[:hat]).to eq(['not wearable by user'])
|
|
|
+ end
|
|
|
+
|
|
|
+ it "can be one of the user's hats" do
|
|
|
+ user = User.make!
|
|
|
+ hat = Hat.make!(user_id: user.id)
|
|
|
+ comment = Comment.make!(user_id: user.id, hat: hat)
|
|
|
+ comment.valid?
|
|
|
+ expect(comment.errors[:hat]).to be_empty
|
|
|
+ end
|
|
|
+ end
|
|
|
end
|
|
|
@@ -43,6 +43,7 @@ |
|
|
user_id { User.make!.id }
|
|
|
story_id { Story.make!.id }
|
|
|
comment { "comment text #{sn}" }
|
|
|
+ hat { nil }
|
|
|
end
|
|
|
|
|
|
Message.blueprint do
|
|
|
|
0 comments on commit
07a0a4f