diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4523ebb..4237833 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,13 +14,25 @@ jobs: fail-fast: false matrix: gemfile: - - Gemfile.rails-6.1-stable - Gemfile.rails-7.0-stable - Gemfile.rails-7.2-stable - ruby-version: ['3.1', '3.0'] + - Gemfile.rails-8.0-stable + - Gemfile.rails-8.1-stable + ruby-version: ['3.0', '3.1', '3.2', '3.3'] exclude: + # Rails 7.2 doesn't work with Ruby 3.0 (requires Ruby 3.1+) - gemfile: Gemfile.rails-7.2-stable - ruby-version: "3.0" + ruby-version: '3.0' + # Rails 8.0 doesn't work with Ruby 3.0 or 3.1 (requires Ruby 3.2+) + - gemfile: Gemfile.rails-8.0-stable + ruby-version: '3.0' + - gemfile: Gemfile.rails-8.0-stable + ruby-version: '3.1' + # Rails 8.1 requires Ruby 3.2+ + - gemfile: Gemfile.rails-8.1-stable + ruby-version: '3.0' + - gemfile: Gemfile.rails-8.1-stable + ruby-version: '3.1' env: BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }} steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e66bf5..517b404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v3.5.0 (2026-04-30) + +### Added + +- Add Rails 8.1 compatibility. Rails 8.1 changed `PredicateBuilder::PolymorphicArrayValue#initialize` from `(associated_table, values)` to `(reflection, values)`, dropping the `@associated_table` ivar. `type_to_ids_mapping` now reads `@reflection` when available and falls back to `@associated_table.send(:reflection)` for older Rails versions. + ## v3.2.1 (2023-12-14) ### Fixed @@ -26,3 +32,11 @@ - Remove unsupported rails versions(5.0, 5.2, 6.0) and ruby version(2.7) +## v3.4.0 (2024-XX-XX) + +### Added + +- Add Rails 8.0 compatibility (requires Ruby 3.2+) + +### Removed +- Remove unsupported rails versions 6.x \ No newline at end of file diff --git a/README.md b/README.md index 5d72bd9..d01a0a4 100644 --- a/README.md +++ b/README.md @@ -138,16 +138,23 @@ Lastly, you will need to be careful of any place where you are doing raw SQL que ## Setup -You'll need to have git, Ruby, and MySQL. Then get up and running with a few commands: +You'll need to have git and Ruby. Then get up and running with a few commands: ```bash $ git clone ... $ bundle install $ vim spec/support/database.yml # Update username and password -$ bin/setup +$ bin/setup # Uses SQLite3 for testing (no additional setup required) $ bundle exec rspec ``` +## Database Compatibility + +This gem works with any database supported by ActiveRecord (SQLite3, MySQL, PostgreSQL, etc.). +The gem extends ActiveRecord's polymorphic associations and doesn't use database-specific features. + +Development and testing uses SQLite3 for simplicity. + ## Contributing 1. Fork it @@ -155,3 +162,13 @@ $ bundle exec rspec 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request + +# FCM Annotations + +This fork of `clio/polymorphic_integer_type` should stay in sync with upstream. As of the Rails 8 upgrade (FCM-8671) it is based on upstream **v3.5.0** with a single intentional difference. + +**The only change from the fork** is a guard in `lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb`. Upstream unconditionally rewrites a polymorphic association's stored `_type` to the target's `base_class`, which clobbers a model's custom `polymorphic_name` on plain `polymorphic: true` associations. We scope that rewrite to this gem's integer-type associations only, so plain polymorphic associations respect `polymorphic_name` (the `rma` app relies on this, for example: `Enrollment.polymorphic_name => 'Patient::Segment'`). + +Regression coverage is in `spec/fcm_polymorphic_name_guard_spec.rb`, along with the `Country` / `legacy_source` test fixtures. + +**When re-syncing with upstream, re-apply the guard after merging.** diff --git a/Rakefile b/Rakefile index 4fcea63..39eb26e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,53 +1,52 @@ -require "bundler/gem_tasks" -require "yaml" -require "active_record" +# frozen_string_literal: true + +require 'bundler/gem_tasks' +require 'yaml' +require 'active_record' namespace :test do task :all do - Dir.glob("./gemfiles/Gemfile*").each do |gemfile| - next if gemfile.end_with?(".lock") + Dir.glob('./gemfiles/Gemfile*').each do |gemfile| + next if gemfile.end_with?('.lock') + puts "Running specs for #{Pathname.new(gemfile).basename}" system("BUNDLE_GEMFILE=#{gemfile} bundle install > /dev/null && BUNDLE_GEMFILE=#{gemfile} bundle exec rspec") - puts "" + puts '' end end end namespace :db do - database_config = YAML.load(File.open("./spec/support/database.yml")) - admin_database_config = database_config.merge(database: "mysql") - migration_path = File.expand_path("./spec/support/migrations") + database_config = YAML.load(File.open('./spec/support/database.yml')) + migration_path = File.expand_path('./spec/support/migrations') - desc "Create the database" + desc 'Create the database' task :create do - ActiveRecord::Base.establish_connection(admin_database_config) - puts "Database created." + # SQLite3 creates the database file automatically, just ensure directory exists + db_file = database_config.fetch(:database) + FileUtils.mkdir_p(File.dirname(db_file)) unless File.dirname(db_file) == '.' + puts 'Database ready (SQLite3).' end - desc "Migrate the database" + desc 'Migrate the database' task :migrate do ActiveRecord::Base.establish_connection(database_config) - if defined?(ActiveRecord::MigrationContext) - migration_context = ActiveRecord::MigrationContext.new(migration_path, ActiveRecord::SchemaMigration) - migration_context.migrate - else - ActiveRecord::Migrator.migrate(migration_path) - end - Rake::Task["db:schema"].invoke - puts "Database migrated." + ActiveRecord::MigrationContext.new(migration_path).migrate + Rake::Task['db:schema'].invoke + puts 'Database migrated.' end - desc "Drop the database" + desc 'Drop the database' task :drop do - ActiveRecord::Base.establish_connection(admin_database_config) + # For SQLite3, just delete the file db_file = database_config.fetch(:database) File.delete(db_file) if File.exist?(db_file) - puts "Database deleted." + puts 'Database deleted.' end - desc "Reset the database" + desc 'Reset the database' task reset: [:drop, :create, :migrate] - desc 'Create a db/schema.rb file that is portable against any DB supported by AR' + desc 'Create a db/schema.rb file that is portable against any DB supported by AR' task :schema do # Noop to make ActiveRecord happy diff --git a/gemfiles/Gemfile.rails-6.1-stable b/gemfiles/Gemfile.rails-6.1-stable deleted file mode 100644 index 5056859..0000000 --- a/gemfiles/Gemfile.rails-6.1-stable +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -source "https://rubygems.org" - -gemspec path: ".." - -gem "activerecord", github: "rails/rails", branch: "6-1-stable" -gem "sqlite3", "~> 1.4" diff --git a/gemfiles/Gemfile.rails-8.0-stable b/gemfiles/Gemfile.rails-8.0-stable new file mode 100644 index 0000000..c486345 --- /dev/null +++ b/gemfiles/Gemfile.rails-8.0-stable @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gemspec path: ".." + +gem "activerecord", github: "rails/rails", branch: "8-0-stable" diff --git a/gemfiles/Gemfile.rails-8.1-stable b/gemfiles/Gemfile.rails-8.1-stable new file mode 100644 index 0000000..b6f721a --- /dev/null +++ b/gemfiles/Gemfile.rails-8.1-stable @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gemspec path: ".." + +gem "activerecord", github: "rails/rails", branch: "8-1-stable" diff --git a/lib/polymorphic_integer_type.rb b/lib/polymorphic_integer_type.rb index 5dbcb40..b5bf33d 100644 --- a/lib/polymorphic_integer_type.rb +++ b/lib/polymorphic_integer_type.rb @@ -4,7 +4,6 @@ require "polymorphic_integer_type/extensions" require "polymorphic_integer_type/mapping" require "polymorphic_integer_type/module_generator" -require "polymorphic_integer_type/belongs_to_valid_options_extension" require "polymorphic_integer_type/belongs_to_polymorphic_association_extension" require "polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension" require "polymorphic_integer_type/polymorphic_foreign_association_extension" diff --git a/lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb b/lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb index df57836..b45df40 100644 --- a/lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb +++ b/lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb @@ -10,10 +10,14 @@ module PolymorphicArrayValueExtension # end def type_to_ids_mapping - if ACTIVE_RECORD_VERSION < Gem::Version.new("6.1") - association = @associated_table.send(:association) + # Rails 8.1 changed `PredicateBuilder::PolymorphicArrayValue#initialize` + # from `(associated_table, values)` to `(reflection, values)`, dropping + # the `@associated_table` ivar. Read whichever ivar is available so this + # gem works across Rails 6.1–8.1. + association = if instance_variable_defined?(:@reflection) && @reflection + @reflection else - association = @associated_table.send(:reflection) + @associated_table.send(:reflection) end name = association.name diff --git a/lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb b/lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb index 8d4b7c8..a7930ba 100644 --- a/lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb +++ b/lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb @@ -1,25 +1,37 @@ -module PolymorphicIntegerType - module BelongsToPolymorphicAssociationExtension - private +module ActiveRecord + module Associations + class BelongsToPolymorphicAssociation < BelongsToAssociation + private - if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("6.1") - def replace_keys(record) - super - - if reflection.options[:integer_type] || reflection.options[:polymorphic].is_a?(Hash) - owner[reflection.foreign_type] = record.class.base_class unless record.nil? - end - end - else def replace_keys(record, force: false) super + return if record.nil? - if reflection.options[:integer_type] || reflection.options[:polymorphic].is_a?(Hash) - owner[reflection.foreign_type] = record.class.base_class unless record.nil? - end + # FCM fork delta -- RE-APPLY after any upstream sync! + # + # This gem *reopens* (does not prepend) `BelongsToPolymorphicAssociation`, + # so the `super` above is BelongsToAssociation#replace_keys, which sets + # the foreign key but NOT the polymorphic type, so this method is + # responsible for the `_type`. + # + # Upstream sets it unconditionally to the target's `base_class`, which + # clobbers a model's custom `polymorphic_name` on plain `polymorphic: true` + # associations. + # + # The rma app relies on custom `polymorphic_name` (e.g. + # Enrollment => 'Patient::Segment'), so use `base_class` ONLY for this + # gem's integer-type associations (detected via the generated + # `_mapping` class method) and fall back to Rails' + # `polymorphic_name` for plain polymorphic associations. + # + # Regression is tested in spec/fcm_polymorphic_name_guard_spec.rb. + owner[reflection.foreign_type] = + if owner.class.respond_to?("#{reflection.foreign_type}_mapping") + record.class.base_class + else + record.class.polymorphic_name + end end end end end - -ActiveRecord::Associations::BelongsToPolymorphicAssociation.prepend(PolymorphicIntegerType::BelongsToPolymorphicAssociationExtension) diff --git a/lib/polymorphic_integer_type/belongs_to_valid_options_extension.rb b/lib/polymorphic_integer_type/belongs_to_valid_options_extension.rb deleted file mode 100644 index 67dd805..0000000 --- a/lib/polymorphic_integer_type/belongs_to_valid_options_extension.rb +++ /dev/null @@ -1,11 +0,0 @@ -module PolymorphicIntegerType - module BelongsToValidOptionsExtension - def valid_options(options) - valid = super - valid << :integer_type if options[:polymorphic] - valid - end - end -end - -ActiveRecord::Associations::Builder::BelongsTo.singleton_class.prepend(PolymorphicIntegerType::BelongsToValidOptionsExtension) diff --git a/lib/polymorphic_integer_type/extensions.rb b/lib/polymorphic_integer_type/extensions.rb index 47f3611..8e2144f 100644 --- a/lib/polymorphic_integer_type/extensions.rb +++ b/lib/polymorphic_integer_type/extensions.rb @@ -9,14 +9,15 @@ module ClassMethods def belongs_to(name, scope = nil, **options) options = scope if scope.kind_of? Hash + integer_type = options.delete :integer_type super - if options[:polymorphic] && (options[:integer_type] || options[:polymorphic].is_a?(Hash)) + if options[:polymorphic] && (integer_type || options[:polymorphic].is_a?(Hash)) mapping = - case options[:integer_type] + case integer_type when true then PolymorphicIntegerType::Mapping[name] when nil then options[:polymorphic] else - raise ArgumentError, "Unknown integer_type value: #{options[:integer_type].inspect}" + raise ArgumentError, "Unknown integer_type value: #{integer_type.inspect}" end.dup foreign_type = reflections[name.to_s].foreign_type @@ -117,12 +118,7 @@ def remove_integer_type_and_set_attributes_and_extension(integer_type_values, re if is_polymorphic_integer reflection.foreign_integer_type = foreign_integer_type reflection.integer_type = integer_type - - if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("6.1") - ActiveRecord::Associations::Association.prepend(PolymorphicIntegerType::PolymorphicForeignAssociationExtension) - else - ActiveRecord::Associations::ForeignAssociation.prepend(PolymorphicIntegerType::PolymorphicForeignAssociationExtension) - end + ActiveRecord::Associations::ForeignAssociation.prepend(PolymorphicIntegerType::PolymorphicForeignAssociationExtension) end end diff --git a/lib/polymorphic_integer_type/version.rb b/lib/polymorphic_integer_type/version.rb index febae78..27b1ad4 100644 --- a/lib/polymorphic_integer_type/version.rb +++ b/lib/polymorphic_integer_type/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module PolymorphicIntegerType - VERSION = "3.3.0" + VERSION = '3.5.0' end diff --git a/polymorphic_integer_type.gemspec b/polymorphic_integer_type.gemspec index 52bb61a..babacda 100644 --- a/polymorphic_integer_type.gemspec +++ b/polymorphic_integer_type.gemspec @@ -1,27 +1,30 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'polymorphic_integer_type/version' Gem::Specification.new do |spec| - spec.name = "polymorphic_integer_type" + spec.name = 'polymorphic_integer_type' spec.version = PolymorphicIntegerType::VERSION - spec.authors = ["Kyle d'Oliveira"] - spec.email = ["kyle@goclio.com"] - spec.description = %q{Allows the *_type field in the DB to be an integer rather than a string} - spec.summary = %q{Use integers rather than strings for the _type field} - spec.homepage = "" - spec.license = "MIT" + spec.authors = ['Kyle d\'Oliveira'] + spec.email = ['kyle@goclio.com'] + spec.description = 'Allows the *_type field in the DB to be an integer rather than a string' + spec.summary = 'Use integers rather than strings for the _type field' + spec.homepage = '' + spec.license = 'MIT' + + spec.required_ruby_version = '>= 3.0' spec.files = `git ls-files -- . ':!.github/'`.split($/) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] - spec.add_dependency "activerecord", "< 8" - spec.add_development_dependency "bundler" - spec.add_development_dependency "rake" - spec.add_development_dependency "rspec" - spec.add_development_dependency "sqlite3" - spec.add_development_dependency "pry-byebug" + spec.add_dependency 'activerecord', '< 9.0' + spec.add_development_dependency 'bundler' + spec.add_development_dependency 'pry-byebug' + spec.add_development_dependency 'rake' + spec.add_development_dependency 'rspec' + spec.add_development_dependency 'sqlite3' end diff --git a/spec/fcm_polymorphic_name_guard_spec.rb b/spec/fcm_polymorphic_name_guard_spec.rb new file mode 100644 index 0000000..0fa94bf --- /dev/null +++ b/spec/fcm_polymorphic_name_guard_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +# FCM fork regression test +# +# This fork of clio/polymorphic_integer_type carries exactly ONE intentional +# difference over upstream (see the "FCM Annotations" section of README.md and +# the guard in lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb): +# +# Upstream unconditionally rewrites a polymorphic association's stored `_type` +# to the target's `base_class`. That clobbers a model's custom `polymorphic_name` +# on PLAIN `polymorphic: true` associations. The rma app depends on custom +# `polymorphic_name` (e.g. Enrollment.polymorphic_name => 'Patient::Segment'), +# so the guard restricts that rewrite to this gem's integer-type associations only. +# +# If a future upstream re-sync drops the guard, these specs fail - which is the point. +RSpec.describe 'FCM: polymorphic_name on plain polymorphic associations' do + let(:country) { Country.create!(name: 'Canada') } + + it "stores the target's polymorphic_name (not its base_class) on a plain polymorphic belongs_to" do + link = Link.create!(legacy_source: country) + + # Pure upstream (no guard) would store 'Country' (base_class) here. + expect(link.legacy_source_type).to eq('Nation') + end + + it 'reads the plain polymorphic association back via polymorphic_class_for' do + link = Link.create!(legacy_source: country) + + expect(link.reload.legacy_source).to eq(country) + end + + it 'guards plain polymorphic associations only, leaving integer-type ones to the gem' do + # `source` is integer-type (the gem defines `source_type_mapping`); `legacy_source` is plain. + expect(Link).to respond_to(:source_type_mapping) + expect(Link).not_to respond_to(:legacy_source_type_mapping) + end +end diff --git a/spec/polymorphic_integer_type_spec.rb b/spec/polymorphic_integer_type_spec.rb index 08a25c0..73a4cdd 100644 --- a/spec/polymorphic_integer_type_spec.rb +++ b/spec/polymorphic_integer_type_spec.rb @@ -136,6 +136,11 @@ expect(Link.where(source: [source])).to eq [link] end + it "properly finds objects when passing an array of mixed-type sources" do + link_for_dog = Link.create(source: dog) + expect(Link.where(source: [cat, dog])).to match_array [link, link_for_dog] + end + it "properly finds the object with a find_by" do expect(Link.find_by(source: source, id: link.id)).to eql link end @@ -179,7 +184,6 @@ end end end - context "When a link is given polymorphic record" do let(:link) { Link.create(source: source) } let(:source) { cat } @@ -194,17 +198,6 @@ end end - context "When a link is given polymorphic record via a non-integer type association" do - let(:link) { Link.create(legacy_source: source) } - let(:source) { Place.create(name: "Main Street") } - - it "appropriately sets the source_id and source_type to the polymorphic_name" do - expect(link.legacy_source_id).to eql source.id - expect(link.legacy_source_type).to eql Place.polymorphic_name - expect(link.legacy_source).to eql source - end - end - context "When a link is given polymorphic id and type" do let(:link) { Link.create(source_id: source.id, source_type: source.class.to_s) } let(:source) { cat } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c802cb9..26774ac 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,7 @@ require 'polymorphic_integer_type' require 'support/configuration' require 'support/link' +require 'support/country' require 'support/animal' require 'support/namespaced_animal' require 'support/namespaced_plant' @@ -13,7 +14,6 @@ require 'support/profile' require 'support/profile_history' require 'support/namespaced_activity' -require 'support/place' require 'byebug' require 'pry' @@ -21,17 +21,10 @@ config.before(:suite) do database_config = YAML.load(File.open("#{File.dirname(__FILE__)}/support/database.yml")) migrations_path = "#{File.dirname(__FILE__)}/support/migrations" - active_record_version = Gem::Version.new(ActiveRecord::VERSION::STRING) ActiveRecord::Base.establish_connection(database_config) - - if active_record_version >= Gem::Version.new("6.1") && active_record_version < Gem::Version.new("7.0") - ActiveRecord::MigrationContext.new(migrations_path, ActiveRecord::SchemaMigration).migrate - end - if active_record_version >= Gem::Version.new("7.0") - ActiveRecord::MigrationContext.new(migrations_path).migrate - end + ActiveRecord::MigrationContext.new(migrations_path).migrate end config.around do |example| diff --git a/spec/support/country.rb b/spec/support/country.rb new file mode 100644 index 0000000..15f36ac --- /dev/null +++ b/spec/support/country.rb @@ -0,0 +1,12 @@ +# FCM regression fixture (see spec/fcm_polymorphic_name_guard_spec.rb). +# +# A plain (non-integer-type) polymorphic target whose `polymorphic_name` differs +# from its class name. This mirrors the rma app's real case (Enrollment.polymorphic_name => +# 'Patient::Segment') and is used to prove the fork's guard leaves plain +# polymorphic associations to Rails so the custom polymorphic_name is stored - +# rather than upstream's unconditional base_class rewrite. +class Country < ActiveRecord::Base + def self.polymorphic_name + 'Nation' + end +end diff --git a/spec/support/link.rb b/spec/support/link.rb index 00deb6f..3be89ca 100644 --- a/spec/support/link.rb +++ b/spec/support/link.rb @@ -1,12 +1,17 @@ class Link < ActiveRecord::Base include PolymorphicIntegerType::Extensions - def self.polymorphic_class_for(name) - name == 'Country' ? Place : super - end - belongs_to :source, polymorphic: true, integer_type: true belongs_to :target, polymorphic: true, integer_type: true + # FCM regression fixture (see spec/fcm_polymorphic_name_guard_spec.rb): a + # plain (non-integer-type) polymorphic association whose target (Country) + # overrides `polymorphic_name`. Exercises the fork's guard that leaves plain + # polymorphic associations to Rails instead of forcing the target's base_class. belongs_to :legacy_source, polymorphic: true + + # Resolve the custom polymorphic_name ('Nation') back to Country on read. + def self.polymorphic_class_for(name) + name == 'Nation' ? Country : super + end end diff --git a/spec/support/migrations/10_create_country_table_and_legacy_source_reference.rb b/spec/support/migrations/10_create_country_table_and_legacy_source_reference.rb new file mode 100644 index 0000000..893164b --- /dev/null +++ b/spec/support/migrations/10_create_country_table_and_legacy_source_reference.rb @@ -0,0 +1,23 @@ +# FCM regression fixture - supports spec/fcm_polymorphic_name_guard_spec.rb and +# the fork delta documented in lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb. +# +# Adds a plain (string-typed) polymorphic `legacy_source` to `links`, plus a +# `countries` table whose model (Country) overrides `polymorphic_name`. +class CreateCountryTableAndLegacySourceReference < ActiveRecord::Migration[5.0] + + def up + create_table :countries do |t| + t.string :name + end + + add_column :links, :legacy_source_id, :integer + add_column :links, :legacy_source_type, :string + end + + def down + remove_column :links, :legacy_source_type + remove_column :links, :legacy_source_id + drop_table :countries + end + +end diff --git a/spec/support/migrations/11_add_legacy_source_reference_to_links_table.rb b/spec/support/migrations/11_add_legacy_source_reference_to_links_table.rb deleted file mode 100644 index 5f67911..0000000 --- a/spec/support/migrations/11_add_legacy_source_reference_to_links_table.rb +++ /dev/null @@ -1,7 +0,0 @@ -class AddLegacySourceReferenceToLinksTable < ActiveRecord::Migration[5.0] - def change - add_reference :links, :legacy_source, polymorphic: true - end -end - - diff --git a/spec/support/place.rb b/spec/support/place.rb deleted file mode 100644 index fc6b981..0000000 --- a/spec/support/place.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Place < ActiveRecord::Base - has_many :source_links, as: :target, inverse_of: :legacy_source, class_name: "Link" - - def self.polymorphic_name - 'Country' - end -end