Sha256: 576adafc0b580722f3e4b6e36c049338b64337c0893e85616d58f9c37edb955f
Contents?: true
Size: 1.44 KB
Versions: 2
Compression:
Stored size: 1.44 KB
Contents
# frozen_string_literal: true require 'rails' begin require 'mysql2' rescue LoadError end RSpec.describe 'DeclareSchema Migration Generator interactive primary key' do before do load File.expand_path('prepare_testapp.rb', __dir__) end it "allows alternate primary keys" do class Foo < ActiveRecord::Base fields do end self.primary_key = "foo_id" end generate_migrations '-n', '-m' expect(Foo._defined_primary_key).to eq('foo_id') ### migrate from # rename from custom primary_key class Foo < ActiveRecord::Base fields do end self.primary_key = "id" end puts "\n\e[45m Please enter 'id' (no quotes) at the next prompt \e[0m" generate_migrations '-n', '-m' expect(Foo._defined_primary_key).to eq('id') nuke_model_class(Foo) ### migrate to if Rails::VERSION::MAJOR >= 5 && !defined?(Mysql2) # TODO TECH-4814 Put this test back for Mysql2 # replace custom primary_key class Foo < ActiveRecord::Base fields do end self.primary_key = "foo_id" end puts "\n\e[45m Please enter 'drop id' (no quotes) at the next prompt \e[0m" generate_migrations '-n', '-m' expect(Foo._defined_primary_key).to eq('foo_id') ### ensure it doesn't cause further migrations # check no further migrations up = Generators::DeclareSchema::Migration::Migrator.run.first expect(up).to eq("") end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
declare_schema-0.9.0 | spec/lib/declare_schema/interactive_primary_key_spec.rb |
declare_schema-0.8.0 | spec/lib/declare_schema/interactive_primary_key_spec.rb |