From 4fc253ccc2a227e4a4d043ad324367a2f2bca360 Mon Sep 17 00:00:00 2001 From: Washington Botelho Date: Thu, 3 Oct 2019 20:06:47 -0300 Subject: [PATCH] spec: fix --- .../add_extra_fields_on_rating_rates_table.rb | 2 -- spec/support/db/migrate/create_rates_table.rb | 19 ++++++++++++++++++ .../support/db/migrate/create_rating_table.rb | 20 +++++++++++++++++++ spec/support/migrate.rb | 12 +++++------ 4 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 spec/support/db/migrate/create_rates_table.rb create mode 100644 spec/support/db/migrate/create_rating_table.rb diff --git a/spec/support/db/migrate/add_extra_fields_on_rating_rates_table.rb b/spec/support/db/migrate/add_extra_fields_on_rating_rates_table.rb index 1b9d2e0..faebef2 100644 --- a/spec/support/db/migrate/add_extra_fields_on_rating_rates_table.rb +++ b/spec/support/db/migrate/add_extra_fields_on_rating_rates_table.rb @@ -4,7 +4,5 @@ class AddExtraScopesOnRatingRatesTable < ActiveRecord::Migration[5.0] def change add_column :rating_rates, :scope_1, :string add_column :rating_rates, :scope_2, :string - - # remove_index :rating_rates, %i[author_id author_type resource_id resource_type scopeable_id scopeable_type] end end diff --git a/spec/support/db/migrate/create_rates_table.rb b/spec/support/db/migrate/create_rates_table.rb new file mode 100644 index 0000000..5d3aa99 --- /dev/null +++ b/spec/support/db/migrate/create_rates_table.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class CreateRateTable < ActiveRecord::Migration[5.0] + def change + create_table :rating_rates do |t| + t.decimal :value, default: 0, precision: 25, scale: 16 + + t.references :author, index: true, null: false, polymorphic: true + t.references :resource, index: true, null: false, polymorphic: true + t.references :scopeable, index: true, null: true, polymorphic: true + + t.timestamps null: false + end + + change_column :rating_rates, :author_type, :string, limit: 10 + change_column :rating_rates, :resource_type, :string, limit: 10 + change_column :rating_rates, :scopeable_type, :string, limit: 10 + end +end diff --git a/spec/support/db/migrate/create_rating_table.rb b/spec/support/db/migrate/create_rating_table.rb new file mode 100644 index 0000000..1238ff9 --- /dev/null +++ b/spec/support/db/migrate/create_rating_table.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class CreateRatingTable < ActiveRecord::Migration[5.0] + def change + create_table :rating_ratings do |t| + t.decimal :average, default: 0, mull: false, precision: 25, scale: 16 + t.decimal :estimate, default: 0, mull: false, precision: 25, scale: 16 + t.integer :sum, default: 0, mull: false + t.integer :total, default: 0, mull: false + + t.references :resource, index: true, null: false, polymorphic: true + t.references :scopeable, index: true, null: true, polymorphic: true + + t.timestamps null: false + end + + change_column :rating_ratings, :resource_type, :string, limit: 10 + change_column :rating_ratings, :scopeable_type, :string, limit: 10 + end +end diff --git a/spec/support/migrate.rb b/spec/support/migrate.rb index be92c8d..75e2028 100644 --- a/spec/support/migrate.rb +++ b/spec/support/migrate.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require File.expand_path('../../lib/generators/rating/templates/db/migrate/create_rating_table.rb', __dir__) -require File.expand_path('../../lib/generators/rating/templates/db/migrate/create_rate_table.rb', __dir__) - Dir[File.expand_path('db/migrate/*.rb', __dir__)].each { |file| require file } +CreateRateTable.new.change +CreateRatingTable.new.change + CreateArticlesTable.new.change CreateAuthorsTable.new.change @@ -12,9 +12,9 @@ CreateGlobalsTable.new.change CreateCategoriesTable.new.change CreateCommentsTable.new.change -CreateRateTable.new.change -CreateRatingTable.new.change + CreateReviewRatingsTable.new.change CreateReviewsTable.new.change + AddCommentOnRatingRatesTable.new.change -AddExtraScopesOnRatingRatesTable.new.change +AddExtraScopesOnRatingRatesTable.new.change if ENV['CONFIG_ENABLED_WITH_EXTRA_SCOPES'] == 'true'