fix post specs
This commit is contained in:
@@ -28,10 +28,10 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def limit_of_post_per_day
|
def limit_of_post_per_day
|
||||||
posts_from_day = user.posts.where('created_at >= ?', Time.zone.now.beginning_of_day)
|
posts_from_day = user&.posts&.where('created_at >= ?', Time.zone.now.beginning_of_day)
|
||||||
|
|
||||||
|
return if posts_from_day && posts_from_day.count < 5
|
||||||
|
|
||||||
if posts_from_day.count >= 5
|
|
||||||
errors.add(:base, 'You can post only 5 posts per day')
|
errors.add(:base, 'You can post only 5 posts per day')
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user