ref: extract support configs
parent
bcc2edbf0a
commit
a9be6d3b40
|
@ -0,0 +1,16 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
ENV['RAILS_ENV'] ||= 'test'
|
||||||
|
|
||||||
|
require 'support/coverage'
|
||||||
|
|
||||||
|
require 'active_record/railtie'
|
||||||
|
require 'debug'
|
||||||
|
require 'rating'
|
||||||
|
|
||||||
|
require 'support/common'
|
||||||
|
require 'support/mysql'
|
||||||
|
require 'support/database_cleaner'
|
||||||
|
require 'support/factory_bot'
|
||||||
|
require 'support/migrate'
|
||||||
|
require 'support/models'
|
|
@ -1,7 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Rating::Config, '.rate_table' do
|
RSpec.describe Rating::Config, '.rate_table' do
|
||||||
if ENV['CONFIG_ENABLED'] != 'true'
|
if ENV['CONFIG_ENABLED'] != 'true'
|
||||||
context 'when rating.yml does not exist' do
|
context 'when rating.yml does not exist' do
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Rating::Config, '.rating_table' do
|
RSpec.describe Rating::Config, '.rating_table' do
|
||||||
if ENV['CONFIG_ENABLED'] != 'true'
|
if ENV['CONFIG_ENABLED'] != 'true'
|
||||||
context 'when rating.yml does not exist' do
|
context 'when rating.yml does not exist' do
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Rating::Config, '.validations' do
|
RSpec.describe Rating::Config, '.validations' do
|
||||||
if ENV['CONFIG_ENABLED_WITH_EXTRA_SCOPES'] != 'true'
|
if ENV['CONFIG_ENABLED_WITH_EXTRA_SCOPES'] != 'true'
|
||||||
context 'when rating.yml does not exist' do
|
context 'when rating.yml does not exist' do
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, 'after_create' do
|
RSpec.describe Rating::Extension, 'after_create' do
|
||||||
context 'when record is author' do
|
context 'when record is author' do
|
||||||
let!(:record) { build :author }
|
let!(:record) { build :author }
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'support/shared_context/with_database_records'
|
require 'support/shared_context/with_database_records'
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, ':order_by_rating' do
|
RSpec.describe Rating::Extension, ':order_by_rating' do
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, ':rate_for' do
|
RSpec.describe Rating::Extension, ':rate_for' do
|
||||||
let!(:author) { create :author }
|
let!(:author) { create :author }
|
||||||
let!(:article) { create :article }
|
let!(:article) { create :article }
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, ':rate' do
|
RSpec.describe Rating::Extension, ':rate' do
|
||||||
let!(:author) { create :author }
|
let!(:author) { create :author }
|
||||||
let!(:article) { create :article }
|
let!(:article) { create :article }
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, ':rated?' do
|
RSpec.describe Rating::Extension, ':rated?' do
|
||||||
let!(:author) { create :author }
|
let!(:author) { create :author }
|
||||||
let!(:resource) { create :article }
|
let!(:resource) { create :article }
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'support/shared_context/with_database_records'
|
require 'support/shared_context/with_database_records'
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, '.rated_records' do
|
RSpec.describe Rating::Extension, '.rated_records' do
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'support/shared_context/with_database_records'
|
require 'support/shared_context/with_database_records'
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, ':rated' do
|
RSpec.describe Rating::Extension, ':rated' do
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'support/shared_context/with_database_records'
|
require 'support/shared_context/with_database_records'
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, '.rates_records' do
|
RSpec.describe Rating::Extension, '.rates_records' do
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'support/shared_context/with_database_records'
|
require 'support/shared_context/with_database_records'
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, ':rates' do
|
RSpec.describe Rating::Extension, ':rates' do
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'support/shared_context/with_database_records'
|
require 'support/shared_context/with_database_records'
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, '.rating' do
|
RSpec.describe Rating::Extension, '.rating' do
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'support/shared_context/with_database_records'
|
require 'support/shared_context/with_database_records'
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, '.rating' do
|
RSpec.describe Rating::Extension, '.rating' do
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, '.rating_warm_up' do
|
RSpec.describe Rating::Extension, '.rating_warm_up' do
|
||||||
context 'when scoping is nil' do
|
context 'when scoping is nil' do
|
||||||
context 'when update is made' do
|
context 'when update is made' do
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, 'unscoped_rating' do
|
RSpec.describe Rating::Extension, 'unscoped_rating' do
|
||||||
let!(:author_1) { create :author }
|
let!(:author_1) { create :author }
|
||||||
let!(:author_2) { create :author }
|
let!(:author_2) { create :author }
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, 'unscoped_rating' do
|
RSpec.describe Rating::Extension, 'unscoped_rating' do
|
||||||
let!(:author_1) { create :author }
|
let!(:author_1) { create :author }
|
||||||
let!(:author_2) { create :author }
|
let!(:author_2) { create :author }
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Rating::Rate, ':create' do
|
RSpec.describe Rating::Rate, ':create' do
|
||||||
let!(:author) { create :author }
|
let!(:author) { create :author }
|
||||||
let!(:article) { create :article }
|
let!(:article) { create :article }
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Rating::Rate, ':rate_for' do
|
RSpec.describe Rating::Rate, ':rate_for' do
|
||||||
let!(:author) { create :author }
|
let!(:author) { create :author }
|
||||||
let!(:article) { create :article }
|
let!(:article) { create :article }
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'support/shoulda'
|
||||||
|
|
||||||
RSpec.describe Rating::Rate do
|
RSpec.describe Rating::Rate do
|
||||||
let!(:object) { build :rating_rate }
|
let!(:object) { build(:rating_rate) }
|
||||||
|
|
||||||
it { expect(object).to be_valid }
|
it { expect(object.valid?).to be(true) }
|
||||||
|
|
||||||
it { is_expected.to belong_to :author }
|
it { is_expected.to belong_to(:author) }
|
||||||
it { is_expected.to belong_to :resource }
|
it { is_expected.to belong_to(:resource) }
|
||||||
it { is_expected.to belong_to :scopeable }
|
it { is_expected.to belong_to(:scopeable) }
|
||||||
|
|
||||||
it { is_expected.to validate_presence_of :author }
|
it { is_expected.to validate_presence_of(:author) }
|
||||||
it { is_expected.to validate_presence_of :resource }
|
it { is_expected.to validate_presence_of(:resource) }
|
||||||
it { is_expected.to validate_presence_of :value }
|
it { is_expected.to validate_presence_of(:value) }
|
||||||
|
|
||||||
it do
|
it do
|
||||||
expect(subject).to validate_numericality_of(:value).is_less_than_or_equal_to(100).is_less_than_or_equal_to 100
|
expect(subject).to validate_numericality_of(:value).is_less_than_or_equal_to(100).is_less_than_or_equal_to(100)
|
||||||
end
|
end
|
||||||
|
|
||||||
it do
|
it do
|
||||||
scopes = %i[author_type resource_id resource_type scopeable_id scopeable_type]
|
scopes = %i[author_type resource_id resource_type scopeable_id scopeable_type]
|
||||||
scopes += %i[scope_1 scope_2] if ENV['CONFIG_ENABLED_WITH_EXTRA_SCOPES'] == 'true'
|
scopes += %i[scope_1 scope_2] if ENV.fetch('CONFIG_ENABLED_WITH_EXTRA_SCOPES', 'false') == 'true'
|
||||||
|
|
||||||
expect(object).to validate_uniqueness_of(:author_id).scoped_to(scopes).case_insensitive
|
expect(object).to validate_uniqueness_of(:author_id).scoped_to(scopes).case_insensitive
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'support/shared_context/with_database_records'
|
require 'support/shared_context/with_database_records'
|
||||||
|
|
||||||
RSpec.describe Rating::Rating, ':averager_data' do
|
RSpec.describe Rating::Rating, ':averager_data' do
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'support/shared_context/with_database_records'
|
require 'support/shared_context/with_database_records'
|
||||||
|
|
||||||
RSpec.describe Rating::Rating, ':data' do
|
RSpec.describe Rating::Rating, ':data' do
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'support/shared_context/with_database_records'
|
require 'support/shared_context/with_database_records'
|
||||||
|
|
||||||
RSpec.describe Rating::Rating, ':update_rating' do
|
RSpec.describe Rating::Rating, ':update_rating' do
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'support/shared_context/with_database_records'
|
require 'support/shared_context/with_database_records'
|
||||||
|
|
||||||
RSpec.describe Rating::Rating, ':values_data' do
|
RSpec.describe Rating::Rating, ':values_data' do
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'support/shoulda'
|
||||||
|
|
||||||
RSpec.describe Rating::Rating do
|
RSpec.describe Rating::Rating, type: :model do
|
||||||
let!(:object) { build :rating_rating }
|
let!(:object) { build(:rating_rating) }
|
||||||
|
|
||||||
it { expect(object).to be_valid }
|
it { expect(object.valid?).to be(true) }
|
||||||
|
|
||||||
it { is_expected.to belong_to :resource }
|
it { is_expected.to belong_to(:resource) }
|
||||||
it { is_expected.to belong_to :scopeable }
|
it { is_expected.to belong_to(:scopeable) }
|
||||||
|
|
||||||
it { is_expected.to validate_presence_of :average }
|
it { is_expected.to validate_presence_of(:average) }
|
||||||
it { is_expected.to validate_presence_of :estimate }
|
it { is_expected.to validate_presence_of(:estimate) }
|
||||||
it { is_expected.to validate_presence_of :resource }
|
it { is_expected.to validate_presence_of(:resource) }
|
||||||
it { is_expected.to validate_presence_of :sum }
|
it { is_expected.to validate_presence_of(:sum) }
|
||||||
it { is_expected.to validate_presence_of :total }
|
it { is_expected.to validate_presence_of(:total) }
|
||||||
|
|
||||||
it do
|
it do
|
||||||
expect(object).to validate_uniqueness_of(:resource_id)
|
expect(object).to validate_uniqueness_of(:resource_id)
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
ENV['RAILS_ENV'] ||= 'test'
|
|
||||||
|
|
||||||
require 'active_record/railtie'
|
|
||||||
require 'mysql2'
|
|
||||||
require 'rating'
|
|
||||||
|
|
||||||
client = Mysql2::Client.new(host: '127.0.0.1', username: :root)
|
|
||||||
|
|
||||||
client.query 'DROP DATABASE IF EXISTS rating_test;'
|
|
||||||
client.query 'CREATE DATABASE IF NOT EXISTS rating_test;'
|
|
||||||
|
|
||||||
ActiveRecord::Base.establish_connection adapter: :mysql2, database: :rating_test, username: :root, host: '127.0.0.1'
|
|
||||||
|
|
||||||
Dir[File.expand_path('support/**/*.rb', __dir__)].each { |file| require file }
|
|
|
@ -3,20 +3,8 @@
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.filter_run_when_matching :focus
|
|
||||||
|
|
||||||
config.disable_monkey_patching!
|
config.disable_monkey_patching!
|
||||||
config.infer_spec_type_from_file_location!
|
config.infer_spec_type_from_file_location!
|
||||||
|
|
||||||
config.expect_with :rspec do |expectations|
|
config.order = :random
|
||||||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
||||||
end
|
|
||||||
|
|
||||||
config.mock_with :rspec do |mocks|
|
|
||||||
mocks.verify_partial_doubles = true
|
|
||||||
end
|
|
||||||
|
|
||||||
config.infer_base_class_for_anonymous_controllers = false
|
|
||||||
config.order = :random
|
|
||||||
config.profile_examples = true
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
Dir[File.expand_path('models/*.rb', __dir__)].each { |file| require file }
|
|
@ -1,20 +1,20 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
RSpec.shared_context 'with_database_records' do
|
RSpec.shared_context 'with_database_records' do
|
||||||
let!(:category) { create :category }
|
let!(:category) { create(:category) }
|
||||||
|
|
||||||
let!(:author_1) { create :author }
|
let!(:author_1) { create(:author) }
|
||||||
let!(:author_2) { create :author }
|
let!(:author_2) { create(:author) }
|
||||||
|
|
||||||
let!(:article_1) { create :article }
|
let!(:article_1) { create(:article) }
|
||||||
let!(:article_2) { create :article }
|
let!(:article_2) { create(:article) }
|
||||||
let!(:article_3) { create :article }
|
let!(:article_3) { create(:article) }
|
||||||
|
|
||||||
let!(:rate_1) { create :rating_rate, author: author_1, resource: article_1, value: 100 }
|
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_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_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_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_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 }
|
let!(:rate_6) { create(:rating_rate, author: author_2, resource: article_1, scopeable: category, value: 2) }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue