rating/spec/models/rate/rate_for_spec.rb

41 lines
1.2 KiB
Ruby
Raw Normal View History

2017-10-30 01:44:23 +00:00
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Rating::Rate, ':rate_for' do
let!(:author) { create :author }
2017-10-30 01:44:23 +00:00
let!(:article) { create :article }
2017-11-02 18:55:46 +00:00
context 'with no scopeable' do
context 'when rate does not exist' do
specify { expect(described_class.rate_for(author: author, resource: article)).to eq nil }
2017-11-02 18:55:46 +00:00
end
context 'when rate does not exist' do
2018-01-26 21:32:45 +00:00
before { described_class.create author: author, metadata: {}, resource: article, value: 3 }
2017-11-02 18:55:46 +00:00
it 'returns the record' do
expect(described_class.rate_for(author: author, resource: article)).to eq described_class.last
2017-11-02 18:55:46 +00:00
end
end
2017-10-30 01:44:23 +00:00
end
2017-11-02 18:55:46 +00:00
context 'with scopeable' do
let!(:category) { create :category }
context 'when rate does not exist' do
specify { expect(described_class.rate_for(author: author, resource: article, scopeable: category)).to eq nil }
2017-11-02 18:55:46 +00:00
end
context 'when rate does not exist' do
2018-01-26 21:32:45 +00:00
before { described_class.create author: author, metadata: {}, resource: article, scopeable: category, value: 3 }
2017-11-02 18:55:46 +00:00
it 'returns the record' do
query = described_class.rate_for(author: author, resource: article, scopeable: category)
2017-10-30 01:44:23 +00:00
2017-11-02 18:55:46 +00:00
expect(query).to eq described_class.last
end
2017-10-30 01:44:23 +00:00
end
end
end