docbrown/spec/models/user_counter_spec.rb
rhymes a1835ae5b9
User counters using PostgreSQL JSON (#5373) [deploy]
Co-authored-by: Ben Halpern <bendhalpern@gmail.com>
2020-02-03 10:35:08 -05:00

39 lines
1.1 KiB
Ruby

require "rails_helper"
RSpec.describe UserCounter, type: :model do
let(:counters) { build(:user_counter) }
describe "validations" do
describe "builtin validations" do
subject { build(:user_counter, user: create(:user)) }
it { is_expected.to belong_to(:user) }
it { is_expected.to validate_presence_of(:user) }
it { is_expected.to validate_uniqueness_of(:user) }
end
describe "#comments_these_7_days" do
it "is valid if comments_these_7_days is an integer" do
counters.comments_these_7_days = 1
expect(counters).to be_valid
end
it "is is not if comments_these_7_days is not an integer" do
counters.comments_these_7_days = 1.2
expect(counters).not_to be_valid
end
end
describe "#comments_prior_7_days" do
it "is valid if comments_prior_7_days is an integer" do
counters.comments_prior_7_days = 1
expect(counters).to be_valid
end
it "is is not if comments_prior_7_days is not an integer" do
counters.comments_prior_7_days = 1.2
expect(counters).not_to be_valid
end
end
end
end