diff --git a/spec/factories/rating/rate.rb b/spec/factories/rating/rate.rb index 5b85595..c4a71a1 100644 --- a/spec/factories/rating/rate.rb +++ b/spec/factories/rating/rate.rb @@ -4,7 +4,7 @@ FactoryBot.define do factory :rating_rate, class: Rating::Rate do value 100 - author { create :user } + author { create :author } resource { create :article } end end diff --git a/spec/factories/user.rb b/spec/factories/user.rb deleted file mode 100644 index 347d708..0000000 --- a/spec/factories/user.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.define do - factory :user do - sequence(:name) { |i| "User #{i}" } - end -end diff --git a/spec/models/extension/after_create_spec.rb b/spec/models/extension/after_create_spec.rb index ce9a38f..cb68339 100644 --- a/spec/models/extension/after_create_spec.rb +++ b/spec/models/extension/after_create_spec.rb @@ -3,22 +3,22 @@ require 'rails_helper' RSpec.describe Rating::Extension, ':after_create' do - context 'with :as as nil' do - let!(:user) { create :user } + context 'when :as is nil' do + let!(:article) { create :article } it 'creates a rating record with zero values just to be easy to make the count' do - rating = Rating::Rating.find_by(resource: user) + rating = Rating::Rating.find_by(resource: article) expect(rating.average).to eq 0 expect(rating.estimate).to eq 0 - expect(rating.resource).to eq user + expect(rating.resource).to eq article expect(rating.scopeable).to eq nil expect(rating.sum).to eq 0 expect(rating.total).to eq 0 end end - context 'with :as as :author' do + context 'when :as is :author' do let!(:author) { create :author } it 'does not creates a rating record' do diff --git a/spec/models/extension/order_by_rating_spec.rb b/spec/models/extension/order_by_rating_spec.rb index ccb0170..caa285b 100644 --- a/spec/models/extension/order_by_rating_spec.rb +++ b/spec/models/extension/order_by_rating_spec.rb @@ -5,21 +5,21 @@ require 'rails_helper' RSpec.describe Rating::Extension, ':order_by_rating' do let!(:category) { create :category } - let!(:user_1) { create :user } - let!(:user_2) { create :user } + 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: user_1, resource: article_1, value: 100 - create :rating_rate, author: user_1, resource: article_2, value: 11 - create :rating_rate, author: user_1, resource: article_3, value: 10 - create :rating_rate, author: user_2, resource: article_1, value: 1 + 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: user_1, resource: article_1, scopeable: category, value: 1 - create :rating_rate, author: user_2, resource: article_1, scopeable: category, value: 2 + 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 context 'with default filters' do @@ -184,12 +184,12 @@ RSpec.describe Rating::Extension, ':order_by_rating' do context 'with other resource' do it 'works' do - expect(User.order_by_rating(:total, :desc)).to match_array [user_1, user_2] + expect(Author.order_by_rating(:total, :desc)).to match_array [author_1, author_2] end context 'with scope' do it 'returns empty since creation has no scope' do - expect(User.order_by_rating(:total, :desc, scope: category)).to eq [] + expect(Author.order_by_rating(:total, :desc, scope: category)).to eq [] end end end diff --git a/spec/models/extension/rate_for_spec.rb b/spec/models/extension/rate_for_spec.rb index c90bdd2..c3682f5 100644 --- a/spec/models/extension/rate_for_spec.rb +++ b/spec/models/extension/rate_for_spec.rb @@ -3,14 +3,14 @@ require 'rails_helper' RSpec.describe Rating::Extension, ':rate_for' do - let!(:user) { create :user } + let!(:author) { create :author } let!(:article) { create :article } context 'with no scopeable' do it 'delegates to rate object' do - expect(Rating::Rate).to receive(:rate_for).with author: user, resource: article, scopeable: nil + expect(Rating::Rate).to receive(:rate_for).with author: author, resource: article, scopeable: nil - user.rate_for article + author.rate_for article end end @@ -18,9 +18,9 @@ RSpec.describe Rating::Extension, ':rate_for' do let!(:category) { build :category } it 'delegates to rate object' do - expect(Rating::Rate).to receive(:rate_for).with author: user, resource: article, scopeable: category + expect(Rating::Rate).to receive(:rate_for).with author: author, resource: article, scopeable: category - user.rate_for article, scope: category + author.rate_for article, scope: category end end end diff --git a/spec/models/extension/rate_spec.rb b/spec/models/extension/rate_spec.rb index 4de2241..1fedbd2 100644 --- a/spec/models/extension/rate_spec.rb +++ b/spec/models/extension/rate_spec.rb @@ -3,14 +3,14 @@ require 'rails_helper' RSpec.describe Rating::Extension, ':rate' do - let!(:user) { create :user } + let!(:author) { create :author } let!(:article) { create :article } context 'with no scopeable' do it 'delegates to rate object' do - expect(Rating::Rate).to receive(:create).with author: user, resource: article, scopeable: nil, value: 3 + expect(Rating::Rate).to receive(:create).with author: author, resource: article, scopeable: nil, value: 3 - user.rate article, 3 + author.rate article, 3 end end @@ -18,9 +18,9 @@ RSpec.describe Rating::Extension, ':rate' do let!(:category) { build :category } it 'delegates to rate object' do - expect(Rating::Rate).to receive(:create).with author: user, resource: article, scopeable: category, value: 3 + expect(Rating::Rate).to receive(:create).with author: author, resource: article, scopeable: category, value: 3 - user.rate article, 3, scope: category + author.rate article, 3, scope: category end end end diff --git a/spec/models/extension/rated_question_spec.rb b/spec/models/extension/rated_question_spec.rb index 02b3f61..b30d880 100644 --- a/spec/models/extension/rated_question_spec.rb +++ b/spec/models/extension/rated_question_spec.rb @@ -3,20 +3,20 @@ require 'rails_helper' RSpec.describe Rating::Extension, ':rated?' do - let!(:user) { create :user } + let!(:author) { create :author } let!(:article) { create :article } context 'with no scopeable' do context 'when has no rate for the given resource' do - before { allow(user).to receive(:rate_for).with(article, scope: nil) { nil } } + before { allow(author).to receive(:rate_for).with(article, scope: nil) { nil } } - specify { expect(user.rated?(article)).to eq false } + specify { expect(author.rated?(article)).to eq false } end context 'when has rate for the given resource' do - before { allow(user).to receive(:rate_for).with(article, scope: nil) { double } } + before { allow(author).to receive(:rate_for).with(article, scope: nil) { double } } - specify { expect(user.rated?(article)).to eq true } + specify { expect(author.rated?(article)).to eq true } end end @@ -24,15 +24,15 @@ RSpec.describe Rating::Extension, ':rated?' do let!(:category) { build :category } context 'when has no rate for the given resource' do - before { allow(user).to receive(:rate_for).with(article, scope: category) { nil } } + before { allow(author).to receive(:rate_for).with(article, scope: category) { nil } } - specify { expect(user.rated?(article, scope: category)).to eq false } + specify { expect(author.rated?(article, scope: category)).to eq false } end context 'when has rate for the given resource' do - before { allow(user).to receive(:rate_for).with(article, scope: category) { double } } + before { allow(author).to receive(:rate_for).with(article, scope: category) { double } } - specify { expect(user.rated?(article, scope: category)).to eq true } + specify { expect(author.rated?(article, scope: category)).to eq true } end end end diff --git a/spec/models/extension/rated_records_spec.rb b/spec/models/extension/rated_records_spec.rb index d18e718..90a0db5 100644 --- a/spec/models/extension/rated_records_spec.rb +++ b/spec/models/extension/rated_records_spec.rb @@ -5,22 +5,22 @@ require 'rails_helper' RSpec.describe Rating::Extension, '.rated_records' do let!(:category) { create :category } - let!(:user_1) { create :user } - let!(:user_2) { create :user } + 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: user_1, resource: article_1, value: 100 } - let!(:rate_2) { create :rating_rate, author: user_1, resource: article_2, value: 11 } - let!(:rate_3) { create :rating_rate, author: user_1, resource: article_3, value: 10 } - let!(:rate_4) { create :rating_rate, author: user_2, resource: article_1, value: 1 } + 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: user_1, resource: article_1, scopeable: category, value: 1 } - let!(:rate_6) { create :rating_rate, author: user_2, resource: article_1, scopeable: category, value: 2 } + 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 } it 'returns all rates that this author gave' do - expect(user_1.rated_records).to match_array [rate_1, rate_2, rate_3, rate_5] + expect(author_1.rated_records).to match_array [rate_1, rate_2, rate_3, rate_5] end end diff --git a/spec/models/extension/rated_spec.rb b/spec/models/extension/rated_spec.rb index a041097..179e2e4 100644 --- a/spec/models/extension/rated_spec.rb +++ b/spec/models/extension/rated_spec.rb @@ -5,42 +5,42 @@ require 'rails_helper' RSpec.describe Rating::Extension, ':rated' do let!(:category) { create :category } - let!(:user_1) { create :user } - let!(:user_2) { create :user } + 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: user_1, resource: article_1, value: 100 } - let!(:rate_2) { create :rating_rate, author: user_1, resource: article_2, value: 11 } - let!(:rate_3) { create :rating_rate, author: user_1, resource: article_3, value: 10 } - let!(:rate_4) { create :rating_rate, author: user_2, resource: article_1, value: 1 } + 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: user_1, resource: article_1, scopeable: category, value: 1 } - let!(:rate_6) { create :rating_rate, author: user_2, resource: article_1, scopeable: category, value: 2 } + 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 } context 'with no scope' do it 'returns rates made by this author' do - expect(user_1.rated).to match_array [rate_1, rate_2, rate_3] + expect(author_1.rated).to match_array [rate_1, rate_2, rate_3] end end context 'with no scope' do it 'returns scoped rates made by this author' do - expect(user_1.rated(scope: category)).to eq [rate_5] + expect(author_1.rated(scope: category)).to eq [rate_5] end end context 'when destroy author' do before do - expect(Rating::Rate.where(author: user_1).count).to eq 4 + expect(Rating::Rate.where(author: author_1).count).to eq 4 - user_1.destroy! + author_1.destroy! end it 'destroys rates of that author' do - expect(Rating::Rate.where(author: user_1).count).to eq 0 + expect(Rating::Rate.where(author: author_1).count).to eq 0 end end diff --git a/spec/models/extension/rates_records_spec.rb b/spec/models/extension/rates_records_spec.rb index c27ea6f..7a87e7d 100644 --- a/spec/models/extension/rates_records_spec.rb +++ b/spec/models/extension/rates_records_spec.rb @@ -5,20 +5,20 @@ require 'rails_helper' RSpec.describe Rating::Extension, '.rates_records' do let!(:category) { create :category } - let!(:user_1) { create :user } - let!(:user_2) { create :user } + 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: user_1, resource: article_1, value: 100 } - let!(:rate_2) { create :rating_rate, author: user_1, resource: article_2, value: 11 } - let!(:rate_3) { create :rating_rate, author: user_1, resource: article_3, value: 10 } - let!(:rate_4) { create :rating_rate, author: user_2, resource: article_1, value: 1 } + 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: user_1, resource: article_1, scopeable: category, value: 1 } - let!(:rate_6) { create :rating_rate, author: user_2, resource: article_1, scopeable: category, value: 2 } + 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 } 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] diff --git a/spec/models/extension/rates_spec.rb b/spec/models/extension/rates_spec.rb index 4aadfcd..0580c89 100644 --- a/spec/models/extension/rates_spec.rb +++ b/spec/models/extension/rates_spec.rb @@ -5,20 +5,20 @@ require 'rails_helper' RSpec.describe Rating::Extension, ':rates' do let!(:category) { create :category } - let!(:user_1) { create :user } - let!(:user_2) { create :user } + 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: user_1, resource: article_1, value: 100 } - let!(:rate_2) { create :rating_rate, author: user_1, resource: article_2, value: 11 } - let!(:rate_3) { create :rating_rate, author: user_1, resource: article_3, value: 10 } - let!(:rate_4) { create :rating_rate, author: user_2, resource: article_1, value: 1 } + 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: user_1, resource: article_1, scopeable: category, value: 1 } - let!(:rate_6) { create :rating_rate, author: user_2, resource: article_1, scopeable: category, value: 2 } + 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 } context 'with no scope' do it 'returns rates that this resource received' do @@ -34,11 +34,11 @@ RSpec.describe Rating::Extension, ':rates' do context 'when destroy author' do it 'destroys rates of that author' do - expect(Rating::Rate.where(author: user_1).count).to eq 4 + expect(Rating::Rate.where(author: author_1).count).to eq 4 - user_1.destroy! + author_1.destroy! - expect(Rating::Rate.where(author: user_1).count).to eq 0 + expect(Rating::Rate.where(author: author_1).count).to eq 0 end end diff --git a/spec/models/extension/rating_records_spec.rb b/spec/models/extension/rating_records_spec.rb index f110e26..fefe92b 100644 --- a/spec/models/extension/rating_records_spec.rb +++ b/spec/models/extension/rating_records_spec.rb @@ -5,21 +5,21 @@ require 'rails_helper' RSpec.describe Rating::Extension, '.rating' do let!(:category) { create :category } - let!(:user_1) { create :user } - let!(:user_2) { create :user } + 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: user_1, resource: article_1, value: 100 - create :rating_rate, author: user_1, resource: article_2, value: 11 - create :rating_rate, author: user_1, resource: article_3, value: 10 - create :rating_rate, author: user_2, resource: article_1, value: 1 + 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: user_1, resource: article_1, scopeable: category, value: 1 - create :rating_rate, author: user_2, resource: article_1, scopeable: category, value: 2 + 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 it 'returns all rating of this resource' do diff --git a/spec/models/extension/rating_spec.rb b/spec/models/extension/rating_spec.rb index bfc6ffe..505d13b 100644 --- a/spec/models/extension/rating_spec.rb +++ b/spec/models/extension/rating_spec.rb @@ -5,20 +5,20 @@ require 'rails_helper' RSpec.describe Rating::Extension, '.rating' do let!(:category) { create :category } - let!(:user_1) { create :user } - let!(:user_2) { create :user } + 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: user_1, resource: article_1, value: 100 } - let!(:rate_2) { create :rating_rate, author: user_1, resource: article_2, value: 11 } - let!(:rate_3) { create :rating_rate, author: user_1, resource: article_3, value: 10 } - let!(:rate_4) { create :rating_rate, author: user_2, resource: article_1, value: 1 } + 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: user_1, resource: article_1, scopeable: category, value: 1 } - let!(:rate_6) { create :rating_rate, author: user_2, resource: article_1, scopeable: category, value: 2 } + 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 } context 'with no scope' do it 'returns rating record' do @@ -36,7 +36,7 @@ RSpec.describe Rating::Extension, '.rating' do it 'does not destroy resource rating' do expect(Rating::Rating.where(resource: article_1).count).to eq 2 - user_1.destroy! + author_1.destroy! expect(Rating::Rating.where(resource: article_1).count).to eq 2 end diff --git a/spec/models/rate/create_spec.rb b/spec/models/rate/create_spec.rb index 49e399a..5e94611 100644 --- a/spec/models/rate/create_spec.rb +++ b/spec/models/rate/create_spec.rb @@ -3,17 +3,17 @@ require 'rails_helper' RSpec.describe Rating::Rate, ':create' do - let!(:user) { create :user } + let!(:author) { create :author } let!(:article) { create :article } context 'with no scopeable' do - before { create :rating_rate, author: user, resource: article, value: 3 } + before { create :rating_rate, author: author, resource: article, value: 3 } context 'when rate does not exist yet' do it 'creates a rate entry' do rate = described_class.last - expect(rate.author).to eq user + expect(rate.author).to eq author expect(rate.resource).to eq article expect(rate.value).to eq 3 end @@ -30,24 +30,24 @@ RSpec.describe Rating::Rate, ':create' do end context 'when rate already exists' do - let!(:user_2) { create :user } + let!(:author_2) { create :author } - before { create :rating_rate, author: user_2, resource: article, value: 4 } + before { create :rating_rate, author: author_2, resource: article, value: 4 } it 'creates one more rate entry' do - rates = described_class.where(author: [user, user_2]).order('created_at asc') + rates = described_class.where(author: [author, author_2]).order('created_at asc') expect(rates.size).to eq 2 rate = rates[0] - expect(rate.author).to eq user + expect(rate.author).to eq author expect(rate.resource).to eq article expect(rate.value).to eq 3 rate = rates[1] - expect(rate.author).to eq user_2 + expect(rate.author).to eq author_2 expect(rate.resource).to eq article expect(rate.value).to eq 4 end @@ -67,13 +67,13 @@ RSpec.describe Rating::Rate, ':create' do context 'with scopeable' do let!(:category) { create :category } - before { create :rating_rate, author: user, resource: article, scopeable: category, value: 3 } + before { create :rating_rate, author: author, resource: article, scopeable: category, value: 3 } context 'when rate does not exist yet' do it 'creates a rate entry' do rate = described_class.last - expect(rate.author).to eq user + expect(rate.author).to eq author expect(rate.resource).to eq article expect(rate.scopeable).to eq category expect(rate.value).to eq 3 @@ -92,25 +92,25 @@ RSpec.describe Rating::Rate, ':create' do end context 'when rate already exists' do - let!(:user_2) { create :user } + let!(:author_2) { create :author } - before { create :rating_rate, author: user_2, resource: article, scopeable: category, value: 4 } + before { create :rating_rate, author: author_2, resource: article, scopeable: category, value: 4 } it 'creates one more rate entry' do - rates = described_class.where(author: [user, user_2]).order('created_at asc') + rates = described_class.where(author: [author, author_2]).order('created_at asc') expect(rates.size).to eq 2 rate = rates[0] - expect(rate.author).to eq user + expect(rate.author).to eq author expect(rate.resource).to eq article expect(rate.scopeable).to eq category expect(rate.value).to eq 3 rate = rates[1] - expect(rate.author).to eq user_2 + expect(rate.author).to eq author_2 expect(rate.resource).to eq article expect(rate.scopeable).to eq category expect(rate.value).to eq 4 diff --git a/spec/models/rate/rate_for_spec.rb b/spec/models/rate/rate_for_spec.rb index 2bcf779..fb8cb69 100644 --- a/spec/models/rate/rate_for_spec.rb +++ b/spec/models/rate/rate_for_spec.rb @@ -3,19 +3,19 @@ require 'rails_helper' RSpec.describe Rating::Rate, ':rate_for' do - let!(:user) { create :user } + let!(:author) { create :author } let!(:article) { create :article } 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 } + specify { expect(described_class.rate_for(author: author, resource: article)).to eq nil } end context 'when rate does not exist' do - before { described_class.create author: user, resource: article, value: 3 } + before { described_class.create author: author, resource: article, value: 3 } it 'returns the record' do - expect(described_class.rate_for(author: user, resource: article)).to eq described_class.last + expect(described_class.rate_for(author: author, resource: article)).to eq described_class.last end end end @@ -24,14 +24,14 @@ RSpec.describe Rating::Rate, ':rate_for' do let!(:category) { create :category } context 'when rate does not exist' do - specify { expect(described_class.rate_for(author: user, resource: article, scopeable: category)).to eq nil } + specify { expect(described_class.rate_for(author: author, 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 } + before { described_class.create author: author, resource: article, scopeable: category, value: 3 } it 'returns the record' do - query = described_class.rate_for(author: user, resource: article, scopeable: category) + query = described_class.rate_for(author: author, resource: article, scopeable: category) expect(query).to eq described_class.last end diff --git a/spec/models/rating/averager_data_spec.rb b/spec/models/rating/averager_data_spec.rb index 0bc77c2..f6f50bb 100644 --- a/spec/models/rating/averager_data_spec.rb +++ b/spec/models/rating/averager_data_spec.rb @@ -5,21 +5,21 @@ require 'rails_helper' RSpec.describe Rating::Rating, ':averager_data' do let!(:category) { create :category } - let!(:user_1) { create :user } - let!(:user_2) { create :user } + 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: user_1, resource: article_1, value: 100 - create :rating_rate, author: user_1, resource: article_2, value: 11 - create :rating_rate, author: user_1, resource: article_3, value: 10 - create :rating_rate, author: user_2, resource: article_1, value: 1 + 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: user_1, resource: article_1, scopeable: category, value: 1 - create :rating_rate, author: user_2, resource: article_1, scopeable: category, value: 2 + 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 context 'with no scopeable' do diff --git a/spec/models/rating/data_spec.rb b/spec/models/rating/data_spec.rb index edacb80..bc12225 100644 --- a/spec/models/rating/data_spec.rb +++ b/spec/models/rating/data_spec.rb @@ -5,21 +5,21 @@ require 'rails_helper' RSpec.describe Rating::Rating, ':data' do let!(:category) { create :category } - let!(:user_1) { create :user } - let!(:user_2) { create :user } + 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: user_1, resource: article_1, value: 100 - create :rating_rate, author: user_1, resource: article_2, value: 11 - create :rating_rate, author: user_1, resource: article_3, value: 10 - create :rating_rate, author: user_2, resource: article_1, value: 1 + 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: user_1, resource: article_1, scopeable: category, value: 1 - create :rating_rate, author: user_2, resource: article_1, scopeable: category, value: 2 + 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 context 'with no scopeable' do diff --git a/spec/models/rating/update_rating_spec.rb b/spec/models/rating/update_rating_spec.rb index 8e31981..5db016e 100644 --- a/spec/models/rating/update_rating_spec.rb +++ b/spec/models/rating/update_rating_spec.rb @@ -5,21 +5,21 @@ require 'rails_helper' RSpec.describe Rating::Rating, ':update_rating' do let!(:category) { create :category } - let!(:user_1) { create :user } - let!(:user_2) { create :user } + 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: user_1, resource: article_1, value: 100 - create :rating_rate, author: user_1, resource: article_2, value: 11 - create :rating_rate, author: user_1, resource: article_3, value: 10 - create :rating_rate, author: user_2, resource: article_1, value: 1 + 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: user_1, resource: article_1, scopeable: category, value: 1 - create :rating_rate, author: user_2, resource: article_1, scopeable: category, value: 2 + 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 context 'with no scopeable' do diff --git a/spec/models/rating/values_data_spec.rb b/spec/models/rating/values_data_spec.rb index efe3a57..d79119e 100644 --- a/spec/models/rating/values_data_spec.rb +++ b/spec/models/rating/values_data_spec.rb @@ -5,21 +5,21 @@ require 'rails_helper' RSpec.describe Rating::Rating, ':values_data' do let!(:category) { create :category } - let!(:user_1) { create :user } - let!(:user_2) { create :user } + 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: user_1, resource: article_1, value: 100 - create :rating_rate, author: user_1, resource: article_2, value: 11 - create :rating_rate, author: user_1, resource: article_3, value: 10 - create :rating_rate, author: user_2, resource: article_1, value: 4 + 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: user_1, resource: article_1, scopeable: category, value: 1 - create :rating_rate, author: user_2, resource: article_1, scopeable: category, value: 2 + 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 context 'with no scopeable' do diff --git a/spec/support/db/migrate/create_users_table.rb b/spec/support/db/migrate/create_users_table.rb deleted file mode 100644 index f3e4835..0000000 --- a/spec/support/db/migrate/create_users_table.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class CreateUsersTable < ActiveRecord::Migration[5.0] - def change - create_table :users do |t| - t.string :name, null: false - end - end -end diff --git a/spec/support/migrate.rb b/spec/support/migrate.rb index 9f904fc..33937e7 100644 --- a/spec/support/migrate.rb +++ b/spec/support/migrate.rb @@ -8,4 +8,3 @@ CreateArticlesTable.new.change CreateAuthorsTable.new.change CreateCategoriesTable.new.change CreateRatingTables.new.change -CreateUsersTable.new.change diff --git a/spec/support/models/user.rb b/spec/support/models/user.rb deleted file mode 100644 index a92ffd2..0000000 --- a/spec/support/models/user.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -class User < ::ActiveRecord::Base - rating -end