spec/models/rate/rate_for_spec.rb in rating-0.1.0 vs spec/models/rate/rate_for_spec.rb in rating-0.2.0

- old
+ new

@@ -4,17 +4,37 @@ RSpec.describe Rating::Rate, ':rate_for' do let!(:user) { create :user } let!(:article) { create :article } - context 'when rate does not exist' do - specify { expect(described_class.rate_for(author: user, resource: article)).to eq nil } + context 'with no scopeable' do + context 'when rate does not exist' do + specify { expect(described_class.rate_for(author: user, resource: article)).to eq nil } + end + + context 'when rate does not exist' do + before { described_class.create author: user, resource: article, value: 3 } + + it 'returns the record' do + expect(described_class.rate_for(author: user, resource: article)).to eq described_class.last + end + end end - context 'when rate does not exist' do - before { described_class.create author: user, resource: article, value: 3 } + context 'with scopeable' do + let!(:category) { create :category } - it 'returns the record' do - expect(described_class.rate_for(author: user, resource: article)).to eq described_class.last + context 'when rate does not exist' do + specify { expect(described_class.rate_for(author: user, resource: article, scopeable: category)).to eq nil } + end + + context 'when rate does not exist' do + before { described_class.create author: user, resource: article, scopeable: category, value: 3 } + + it 'returns the record' do + query = described_class.rate_for(author: user, resource: article, scopeable: category) + + expect(query).to eq described_class.last + end end end end