Skip to content

Commit

Permalink
fix a couple tests in rails <= 4.0
Browse files Browse the repository at this point in the history
since key validation is stricter (we now check the existence of both
tables), the mock connection needs to know about more tables. it wasn't a
problem in rails >= 4.1, because it creates an anonymous class for the
HABTM join table
  • Loading branch information
jenseng committed May 18, 2015
1 parent 2b32c42 commit adf6aaa
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/immigrant_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def connection
end
})
end
if ActiveRecord::VERSION::STRING < '4.1'
# make sure habtms create a model class so that MockConnection.tables works
extend(Module.new{
define_method :has_and_belongs_to_many do |assoc, options = {}|
join_table = options[:join_table] || [table_name, assoc.to_s].sort.join("_")
Class.new(ActiveRecord::Base) do
self.table_name = join_table
end
super assoc, options
end
})
end
end

class MockConnection
Expand Down

0 comments on commit adf6aaa

Please sign in to comment.