fix post specs

This commit is contained in:
João Victor Geonizeli
2022-02-27 17:26:22 -03:00
parent fb40dca2da
commit d3ec59dd2e
2 changed files with 5 additions and 5 deletions

View File

@@ -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)
if posts_from_day.count >= 5 return if posts_from_day && posts_from_day.count < 5
errors.add(:base, 'You can post only 5 posts per day')
end errors.add(:base, 'You can post only 5 posts per day')
end end
end end

View File

@@ -24,7 +24,7 @@ RSpec.describe "/posts", type: :request do
let(:invalid_attributes) { let(:invalid_attributes) {
{ {
content: "Quo dolorem recusandae. Vero laborum deleniti. Qui ipsam illum." content: "Quo dolorem recusandae. Vero laborum deleniti. Qui ipsam illum."
} }
} }