spec: refactor setup on shared context
parent
acfae75b60
commit
20975c8f29
|
@ -1,26 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/shared_context/with_database_records'
|
||||
|
||||
RSpec.describe Rating::Extension, ':order_by_rating' do
|
||||
let!(:category) { create :category }
|
||||
|
||||
let!(:author_1) { create :author }
|
||||
let!(:author_2) { create :author }
|
||||
|
||||
let!(:article_1) { create :article }
|
||||
let!(:article_2) { create :article }
|
||||
let!(:article_3) { create :article }
|
||||
|
||||
before do
|
||||
create :rating_rate, author: author_1, resource: article_1, value: 100
|
||||
create :rating_rate, author: author_1, resource: article_2, value: 11
|
||||
create :rating_rate, author: author_1, resource: article_3, value: 10
|
||||
create :rating_rate, author: author_2, resource: article_1, value: 1
|
||||
|
||||
create :rating_rate, author: author_1, resource: article_1, scopeable: category, value: 1
|
||||
create :rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2
|
||||
end
|
||||
include_context 'with_database_records'
|
||||
|
||||
context 'with default filters' do
|
||||
it 'sorts by :estimate :desc' do
|
||||
|
|
|
@ -1,24 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/shared_context/with_database_records'
|
||||
|
||||
RSpec.describe Rating::Extension, '.rated_records' do
|
||||
let!(:category) { create :category }
|
||||
|
||||
let!(:author_1) { create :author }
|
||||
let!(:author_2) { create :author }
|
||||
|
||||
let!(:article_1) { create :article }
|
||||
let!(:article_2) { create :article }
|
||||
let!(:article_3) { create :article }
|
||||
|
||||
let!(:rate_1) { create :rating_rate, author: author_1, resource: article_1, value: 100 }
|
||||
let!(:rate_2) { create :rating_rate, author: author_1, resource: article_2, value: 11 }
|
||||
let!(:rate_3) { create :rating_rate, author: author_1, resource: article_3, value: 10 }
|
||||
let!(:rate_4) { create :rating_rate, author: author_2, resource: article_1, value: 1 }
|
||||
|
||||
let!(:rate_5) { create :rating_rate, author: author_1, resource: article_1, scopeable: category, value: 1 }
|
||||
let!(:rate_6) { create :rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2 }
|
||||
include_context 'with_database_records'
|
||||
|
||||
it 'returns all rates that this author gave' do
|
||||
expect(author_1.rated_records).to match_array [rate_1, rate_2, rate_3, rate_5]
|
||||
|
|
|
@ -1,24 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/shared_context/with_database_records'
|
||||
|
||||
RSpec.describe Rating::Extension, ':rated' do
|
||||
let!(:category) { create :category }
|
||||
|
||||
let!(:author_1) { create :author }
|
||||
let!(:author_2) { create :author }
|
||||
|
||||
let!(:article_1) { create :article }
|
||||
let!(:article_2) { create :article }
|
||||
let!(:article_3) { create :article }
|
||||
|
||||
let!(:rate_1) { create :rating_rate, author: author_1, resource: article_1, value: 100 }
|
||||
let!(:rate_2) { create :rating_rate, author: author_1, resource: article_2, value: 11 }
|
||||
let!(:rate_3) { create :rating_rate, author: author_1, resource: article_3, value: 10 }
|
||||
let!(:rate_4) { create :rating_rate, author: author_2, resource: article_1, value: 1 }
|
||||
|
||||
let!(:rate_5) { create :rating_rate, author: author_1, resource: article_1, scopeable: category, value: 1 }
|
||||
let!(:rate_6) { create :rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2 }
|
||||
include_context 'with_database_records'
|
||||
|
||||
context 'with no scope' do
|
||||
it 'returns rates made by this author' do
|
||||
|
|
|
@ -1,24 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/shared_context/with_database_records'
|
||||
|
||||
RSpec.describe Rating::Extension, '.rates_records' do
|
||||
let!(:category) { create :category }
|
||||
|
||||
let!(:author_1) { create :author }
|
||||
let!(:author_2) { create :author }
|
||||
|
||||
let!(:article_1) { create :article }
|
||||
let!(:article_2) { create :article }
|
||||
let!(:article_3) { create :article }
|
||||
|
||||
let!(:rate_1) { create :rating_rate, author: author_1, resource: article_1, value: 100 }
|
||||
let!(:rate_2) { create :rating_rate, author: author_1, resource: article_2, value: 11 }
|
||||
let!(:rate_3) { create :rating_rate, author: author_1, resource: article_3, value: 10 }
|
||||
let!(:rate_4) { create :rating_rate, author: author_2, resource: article_1, value: 1 }
|
||||
|
||||
let!(:rate_5) { create :rating_rate, author: author_1, resource: article_1, scopeable: category, value: 1 }
|
||||
let!(:rate_6) { create :rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2 }
|
||||
include_context 'with_database_records'
|
||||
|
||||
it 'returns all rates that this resource received' do
|
||||
expect(article_1.rates_records).to match_array [rate_1, rate_4, rate_5, rate_6]
|
||||
|
|
|
@ -1,24 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/shared_context/with_database_records'
|
||||
|
||||
RSpec.describe Rating::Extension, ':rates' do
|
||||
let!(:category) { create :category }
|
||||
|
||||
let!(:author_1) { create :author }
|
||||
let!(:author_2) { create :author }
|
||||
|
||||
let!(:article_1) { create :article }
|
||||
let!(:article_2) { create :article }
|
||||
let!(:article_3) { create :article }
|
||||
|
||||
let!(:rate_1) { create :rating_rate, author: author_1, resource: article_1, value: 100 }
|
||||
let!(:rate_2) { create :rating_rate, author: author_1, resource: article_2, value: 11 }
|
||||
let!(:rate_3) { create :rating_rate, author: author_1, resource: article_3, value: 10 }
|
||||
let!(:rate_4) { create :rating_rate, author: author_2, resource: article_1, value: 1 }
|
||||
|
||||
let!(:rate_5) { create :rating_rate, author: author_1, resource: article_1, scopeable: category, value: 1 }
|
||||
let!(:rate_6) { create :rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2 }
|
||||
include_context 'with_database_records'
|
||||
|
||||
context 'with no scope' do
|
||||
it 'returns rates that this resource received' do
|
||||
|
|
|
@ -1,26 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/shared_context/with_database_records'
|
||||
|
||||
RSpec.describe Rating::Extension, '.rating' do
|
||||
let!(:category) { create :category }
|
||||
|
||||
let!(:author_1) { create :author }
|
||||
let!(:author_2) { create :author }
|
||||
|
||||
let!(:article_1) { create :article }
|
||||
let!(:article_2) { create :article }
|
||||
let!(:article_3) { create :article }
|
||||
|
||||
before do
|
||||
create :rating_rate, author: author_1, resource: article_1, value: 100
|
||||
create :rating_rate, author: author_1, resource: article_2, value: 11
|
||||
create :rating_rate, author: author_1, resource: article_3, value: 10
|
||||
create :rating_rate, author: author_2, resource: article_1, value: 1
|
||||
|
||||
create :rating_rate, author: author_1, resource: article_1, scopeable: category, value: 1
|
||||
create :rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2
|
||||
end
|
||||
include_context 'with_database_records'
|
||||
|
||||
it 'returns all rating of this resource' do
|
||||
expect(article_1.rating_records).to match_array Rating::Rating.where(resource: article_1)
|
||||
|
|
|
@ -1,24 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/shared_context/with_database_records'
|
||||
|
||||
RSpec.describe Rating::Extension, '.rating' do
|
||||
let!(:category) { create :category }
|
||||
|
||||
let!(:author_1) { create :author }
|
||||
let!(:author_2) { create :author }
|
||||
|
||||
let!(:article_1) { create :article }
|
||||
let!(:article_2) { create :article }
|
||||
let!(:article_3) { create :article }
|
||||
|
||||
let!(:rate_1) { create :rating_rate, author: author_1, resource: article_1, value: 100 }
|
||||
let!(:rate_2) { create :rating_rate, author: author_1, resource: article_2, value: 11 }
|
||||
let!(:rate_3) { create :rating_rate, author: author_1, resource: article_3, value: 10 }
|
||||
let!(:rate_4) { create :rating_rate, author: author_2, resource: article_1, value: 1 }
|
||||
|
||||
let!(:rate_5) { create :rating_rate, author: author_1, resource: article_1, scopeable: category, value: 1 }
|
||||
let!(:rate_6) { create :rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2 }
|
||||
include_context 'with_database_records'
|
||||
|
||||
context 'with no scope' do
|
||||
it 'returns rating record' do
|
||||
|
|
|
@ -1,26 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/shared_context/with_database_records'
|
||||
|
||||
RSpec.describe Rating::Rating, ':averager_data' do
|
||||
let!(:category) { create :category }
|
||||
|
||||
let!(:author_1) { create :author }
|
||||
let!(:author_2) { create :author }
|
||||
|
||||
let!(:article_1) { create :article }
|
||||
let!(:article_2) { create :article }
|
||||
let!(:article_3) { create :article }
|
||||
|
||||
before do
|
||||
create :rating_rate, author: author_1, resource: article_1, value: 100
|
||||
create :rating_rate, author: author_1, resource: article_2, value: 11
|
||||
create :rating_rate, author: author_1, resource: article_3, value: 10
|
||||
create :rating_rate, author: author_2, resource: article_1, value: 1
|
||||
|
||||
create :rating_rate, author: author_1, resource: article_1, scopeable: category, value: 1
|
||||
create :rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2
|
||||
end
|
||||
include_context 'with_database_records'
|
||||
|
||||
context 'with no scopeable' do
|
||||
subject { described_class.averager_data article_1, nil }
|
||||
|
|
|
@ -1,26 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/shared_context/with_database_records'
|
||||
|
||||
RSpec.describe Rating::Rating, ':data' do
|
||||
let!(:category) { create :category }
|
||||
|
||||
let!(:author_1) { create :author }
|
||||
let!(:author_2) { create :author }
|
||||
|
||||
let!(:article_1) { create :article }
|
||||
let!(:article_2) { create :article }
|
||||
let!(:article_3) { create :article }
|
||||
|
||||
before do
|
||||
create :rating_rate, author: author_1, resource: article_1, value: 100
|
||||
create :rating_rate, author: author_1, resource: article_2, value: 11
|
||||
create :rating_rate, author: author_1, resource: article_3, value: 10
|
||||
create :rating_rate, author: author_2, resource: article_1, value: 1
|
||||
|
||||
create :rating_rate, author: author_1, resource: article_1, scopeable: category, value: 1
|
||||
create :rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2
|
||||
end
|
||||
include_context 'with_database_records'
|
||||
|
||||
context 'with no scopeable' do
|
||||
subject { described_class.data article_1, nil }
|
||||
|
|
|
@ -1,26 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/shared_context/with_database_records'
|
||||
|
||||
RSpec.describe Rating::Rating, ':update_rating' do
|
||||
let!(:category) { create :category }
|
||||
|
||||
let!(:author_1) { create :author }
|
||||
let!(:author_2) { create :author }
|
||||
|
||||
let!(:article_1) { create :article }
|
||||
let!(:article_2) { create :article }
|
||||
let!(:article_3) { create :article }
|
||||
|
||||
before do
|
||||
create :rating_rate, author: author_1, resource: article_1, value: 100
|
||||
create :rating_rate, author: author_1, resource: article_2, value: 11
|
||||
create :rating_rate, author: author_1, resource: article_3, value: 10
|
||||
create :rating_rate, author: author_2, resource: article_1, value: 1
|
||||
|
||||
create :rating_rate, author: author_1, resource: article_1, scopeable: category, value: 1
|
||||
create :rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2
|
||||
end
|
||||
include_context 'with_database_records'
|
||||
|
||||
context 'with no scopeable' do
|
||||
it 'updates the rating data of the given resource' do
|
||||
|
|
|
@ -1,36 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/shared_context/with_database_records'
|
||||
|
||||
RSpec.describe Rating::Rating, ':values_data' do
|
||||
let!(:category) { create :category }
|
||||
|
||||
let!(:author_1) { create :author }
|
||||
let!(:author_2) { create :author }
|
||||
|
||||
let!(:article_1) { create :article }
|
||||
let!(:article_2) { create :article }
|
||||
let!(:article_3) { create :article }
|
||||
|
||||
before do
|
||||
create :rating_rate, author: author_1, resource: article_1, value: 100
|
||||
create :rating_rate, author: author_1, resource: article_2, value: 11
|
||||
create :rating_rate, author: author_1, resource: article_3, value: 10
|
||||
create :rating_rate, author: author_2, resource: article_1, value: 4
|
||||
|
||||
create :rating_rate, author: author_1, resource: article_1, scopeable: category, value: 1
|
||||
create :rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2
|
||||
end
|
||||
include_context 'with_database_records'
|
||||
|
||||
context 'with no scopeable' do
|
||||
subject { described_class.values_data article_1, nil }
|
||||
|
||||
it 'returns the average of value for a resource' do
|
||||
expect(subject.as_json['rating_avg']).to eq 52.0
|
||||
expect(subject.as_json['rating_avg']).to eq 50.5
|
||||
end
|
||||
|
||||
it 'returns the sum of values for a resource' do
|
||||
expect(subject.as_json['rating_sum']).to eq 104
|
||||
expect(subject.as_json['rating_sum']).to eq 101
|
||||
end
|
||||
|
||||
it 'returns the count of votes for a resource' do
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
RSpec.shared_context 'with_database_records' do
|
||||
let!(:category) { create :category }
|
||||
|
||||
let!(:author_1) { create :author }
|
||||
let!(:author_2) { create :author }
|
||||
|
||||
let!(:article_1) { create :article }
|
||||
let!(:article_2) { create :article }
|
||||
let!(:article_3) { create :article }
|
||||
|
||||
let!(:rate_1) { create :rating_rate, author: author_1, resource: article_1, value: 100 }
|
||||
let!(:rate_2) { create :rating_rate, author: author_1, resource: article_2, value: 11 }
|
||||
let!(:rate_3) { create :rating_rate, author: author_1, resource: article_3, value: 10 }
|
||||
let!(:rate_4) { create :rating_rate, author: author_2, resource: article_1, value: 1 }
|
||||
|
||||
let!(:rate_5) { create :rating_rate, author: author_1, resource: article_1, scopeable: category, value: 1 }
|
||||
let!(:rate_6) { create :rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2 }
|
||||
end
|
Loading…
Reference in New Issue