2017-10-30 01:44:23 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-05-18 02:42:51 +00:00
|
|
|
require 'support/shoulda'
|
2017-10-30 01:44:23 +00:00
|
|
|
|
|
|
|
RSpec.describe Rating::Rate do
|
2022-05-18 02:42:51 +00:00
|
|
|
let!(:object) { build(:rating_rate) }
|
2017-10-30 01:44:23 +00:00
|
|
|
|
2022-05-18 02:42:51 +00:00
|
|
|
it { expect(object.valid?).to be(true) }
|
2017-10-30 01:44:23 +00:00
|
|
|
|
2022-05-18 02:42:51 +00:00
|
|
|
it { is_expected.to belong_to(:author) }
|
|
|
|
it { is_expected.to belong_to(:resource) }
|
|
|
|
it { is_expected.to belong_to(:scopeable) }
|
2017-10-30 01:44:23 +00:00
|
|
|
|
2022-05-18 02:42:51 +00:00
|
|
|
it { is_expected.to validate_presence_of(:author) }
|
|
|
|
it { is_expected.to validate_presence_of(:resource) }
|
|
|
|
it { is_expected.to validate_presence_of(:value) }
|
2017-10-30 01:44:23 +00:00
|
|
|
|
2018-01-15 00:29:59 +00:00
|
|
|
it do
|
2022-05-18 02:42:51 +00:00
|
|
|
expect(subject).to validate_numericality_of(:value).is_less_than_or_equal_to(100).is_less_than_or_equal_to(100)
|
2017-10-30 01:44:23 +00:00
|
|
|
end
|
2018-02-28 16:58:56 +00:00
|
|
|
|
|
|
|
it do
|
2018-03-01 20:50:28 +00:00
|
|
|
scopes = %i[author_type resource_id resource_type scopeable_id scopeable_type]
|
2022-05-18 02:42:51 +00:00
|
|
|
scopes += %i[scope_1 scope_2] if ENV.fetch('CONFIG_ENABLED_WITH_EXTRA_SCOPES', 'false') == 'true'
|
2018-03-01 20:50:28 +00:00
|
|
|
|
|
|
|
expect(object).to validate_uniqueness_of(:author_id).scoped_to(scopes).case_insensitive
|
2018-02-28 16:58:56 +00:00
|
|
|
end
|
2017-10-30 01:44:23 +00:00
|
|
|
end
|