Skip to content

Commit

Permalink
Fix tests for Rails 4
Browse files Browse the repository at this point in the history
  • Loading branch information
matthuhiggins committed Jul 24, 2013
1 parent 38b4f25 commit 108a59c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -3,6 +3,7 @@ source "http://rubygems.org"
gemspec

group :test do
gem 'rails', '~> 4'
gem 'mocha', require: false
gem 'rake'
end
5 changes: 2 additions & 3 deletions foreigner.gemspec
Expand Up @@ -6,16 +6,15 @@ Gem::Specification.new do |s|
s.summary = 'Foreign Keys for Rails'
s.description = 'Adds helpers to migrations and dumps foreign keys to schema.rb'

s.required_ruby_version = '>= 1.8.7'
s.required_ruby_version = '>= 1.9.2'
s.required_rubygems_version = '>= 1.3.5'

s.author = 'Matthew Higgins'
s.email = 'developer@matthewhiggins.com'
s.homepage = 'http://github.com/matthuhiggins/foreigner'
s.rubyforge_project = 'foreigner'

s.extra_rdoc_files = %w(README.rdoc)
s.files = %w(MIT-LICENSE Rakefile README.rdoc) + Dir['lib/**/*.rb'] + Dir['test/**/*.rb']
s.files = %w(MIT-LICENSE Rakefile README.md) + Dir['lib/**/*.rb'] + Dir['test/**/*.rb']
s.add_dependency('activerecord', '>= 3.0.0')
s.add_development_dependency('activerecord', '>= 3.1.0')
end
1 change: 1 addition & 0 deletions lib/foreigner.rb
@@ -1,4 +1,5 @@
require 'active_support/all'
require 'active_record'

module Foreigner
extend ActiveSupport::Autoload
Expand Down
43 changes: 27 additions & 16 deletions test/foreigner/migration/command_recorder_test.rb
Expand Up @@ -5,36 +5,47 @@
end

class Foreigner::CommandRecorderTest < Foreigner::UnitTest
def setup
setup do
@recorder = ActiveRecord::Migration::CommandRecorder.new
end

test 'invert_add_foreign_key' do
@recorder.add_foreign_key(:employees, :companies)
remove = @recorder.inverse.first
assert_equal [:remove_foreign_key, [:employees, :companies]], remove
@recorder.revert do
@recorder.add_foreign_key(:employees, :companies)
end

assert_equal [
[:remove_foreign_key, [:employees, :companies]]
], @recorder.commands
end

test 'invert_add_foreign_key with column' do
@recorder.add_foreign_key(:employees, :companies, :column => :place_id)
remove = @recorder.inverse.first
assert_equal [:remove_foreign_key, [:employees, {:column => :place_id}]], remove
@recorder.revert do
@recorder.add_foreign_key(:employees, :companies, :column => :place_id)
end

assert_equal [
[:remove_foreign_key, [:employees, {:column => :place_id}]]
], @recorder.commands
end

test 'invert_add_foreign_key with name' do
@recorder.add_foreign_key(:employees, :companies, :name => 'the_best_fk', :column => :place_id)
remove = @recorder.inverse.first
assert_equal [:remove_foreign_key, [:employees, {:name => 'the_best_fk'}]], remove
@recorder.record :rename_table, [:old, :new]
rename = @recorder.inverse.first
assert_equal [:rename_table, [:new, :old]], rename
@recorder.revert do
@recorder.add_foreign_key(:employees, :companies, :name => 'the_best_fk', :column => :place_id)
end

assert_equal [
[:remove_foreign_key, [:employees, {:name => 'the_best_fk'}]]
], @recorder.commands
end

test 'remove_foreign_key is irreversible' do
@recorder.remove_foreign_key(:employees, :companies)
assert_raise ActiveRecord::IrreversibleMigration do
@recorder.inverse
@recorder.revert do
@recorder.remove_foreign_key(:employees, :companies)
end
end
# @recorder.inverse
# end
end
end
12 changes: 6 additions & 6 deletions test/helper.rb
@@ -1,9 +1,9 @@
require 'bundler/setup'
Bundler.require(:default)
Bundler.require :default, :test

require 'test/unit'
require 'active_record'
require 'mocha'
require 'active_support/test_case'
require 'minitest/autorun'
require 'mocha/setup'

# Foreigner::Adapter.registered.values.each do |file_name|
# require file_name
Expand All @@ -14,7 +14,7 @@ def execute(sql, name = nil)
sql_statements << sql
sql
end

def quote_table_name(name)
quote_column_name(name).gsub('.', '`.`')
end
Expand All @@ -27,7 +27,7 @@ def sql_statements
@sql_statements ||= []
end

def drop_table(name, options = {})
def drop_table(name, options = {})
end

def disable_referential_integrity
Expand Down

0 comments on commit 108a59c

Please sign in to comment.