Skip to content

Commit

Permalink
Add spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Genki Sugawara committed Sep 23, 2014
1 parent 2c9881f commit 3b92ed9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
43 changes: 43 additions & 0 deletions spec/migrate/migrate_drop_fk_spec.rb
Expand Up @@ -67,4 +67,47 @@
expect(subject.dump.each_line.select {|i| i !~ /\A\Z/ }.join).to eq expected_dsl.strip_heredoc.strip.each_line.select {|i| i !~ /\A\Z/ }.join
}
end

context 'when drop fk when drop table' do
let(:dsl) {
<<-RUBY
create_table "parent", force: true do |t|
end
create_table "child", force: true do |t|
t.integer "parent_id", unsigned: true
end
add_index "child", ["parent_id"], name: "par_ind", using: :btree
add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
RUBY
}

let(:sorted_dsl) {
<<-RUBY
create_table "child", force: true do |t|
t.integer "parent_id", unsigned: true
end
add_index "child", ["parent_id"], name: "par_ind", using: :btree
create_table "parent", force: true do |t|
end
add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
RUBY
}

before { subject.diff(dsl).migrate }
subject { client(enable_foreigner: true) }

it {
delta = subject.diff('')
expect(delta.differ?).to be_truthy
expect(subject.dump).to eq sorted_dsl.strip_heredoc.strip
delta.migrate
expect(subject.dump.strip).to eq ''
}
end
end
12 changes: 10 additions & 2 deletions spec/spec_helper.rb
Expand Up @@ -20,8 +20,15 @@

TEST_SCHEMA = 'ridgepole_test'

ActiveRecord::Migration.verbose = false
Ridgepole::Logger.instance.level = ::Logger::ERROR
if ENV['DEBUG']
ActiveRecord::Migration.verbose = true
logger = Ridgepole::Logger.instance
logger.level = ::Logger::DEBUG
ActiveRecord::Base.logger = logger
else
ActiveRecord::Migration.verbose = false
Ridgepole::Logger.instance.level = ::Logger::ERROR
end

RSpec.configure do |config|
config.before(:each) do
Expand All @@ -44,6 +51,7 @@ def client(options = {}, config = {})

options = {
:enable_mysql_unsigned => true,
:debug => !!ENV['DEBUG'],
}.merge(options)

Ridgepole::Client.new(config, options)
Expand Down

0 comments on commit 3b92ed9

Please sign in to comment.