2008-05-18 06:22:34 +02:00
|
|
|
require "cases/helper"
|
|
|
|
require 'models/entrant'
|
2007-01-22 14:43:50 +01:00
|
|
|
|
|
|
|
# So we can test whether Course.connection survives a reload.
|
2008-05-18 06:22:34 +02:00
|
|
|
require_dependency 'models/course'
|
2007-01-22 14:43:50 +01:00
|
|
|
|
2008-05-18 06:22:34 +02:00
|
|
|
class MultipleDbTest < ActiveRecord::TestCase
|
2007-01-22 14:43:50 +01:00
|
|
|
self.use_transactional_fixtures = false
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@courses = create_fixtures("courses") { Course.retrieve_connection }
|
|
|
|
@entrants = create_fixtures("entrants")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_connected
|
|
|
|
assert_not_nil Entrant.connection
|
|
|
|
assert_not_nil Course.connection
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_proper_connection
|
|
|
|
assert_not_equal(Entrant.connection, Course.connection)
|
|
|
|
assert_equal(Entrant.connection, Entrant.retrieve_connection)
|
|
|
|
assert_equal(Course.connection, Course.retrieve_connection)
|
|
|
|
assert_equal(ActiveRecord::Base.connection, Entrant.connection)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_find
|
|
|
|
c1 = Course.find(1)
|
|
|
|
assert_equal "Ruby Development", c1.name
|
|
|
|
c2 = Course.find(2)
|
|
|
|
assert_equal "Java Development", c2.name
|
|
|
|
e1 = Entrant.find(1)
|
|
|
|
assert_equal "Ruby Developer", e1.name
|
|
|
|
e2 = Entrant.find(2)
|
|
|
|
assert_equal "Ruby Guru", e2.name
|
|
|
|
e3 = Entrant.find(3)
|
|
|
|
assert_equal "Java Lover", e3.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_associations
|
|
|
|
c1 = Course.find(1)
|
2007-02-09 09:04:31 +01:00
|
|
|
assert_equal 2, c1.entrants.count
|
2007-01-22 14:43:50 +01:00
|
|
|
e1 = Entrant.find(1)
|
|
|
|
assert_equal e1.course.id, c1.id
|
|
|
|
c2 = Course.find(2)
|
2007-02-09 09:04:31 +01:00
|
|
|
assert_equal 1, c2.entrants.count
|
2007-01-22 14:43:50 +01:00
|
|
|
e3 = Entrant.find(3)
|
|
|
|
assert_equal e3.course.id, c2.id
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_course_connection_should_survive_dependency_reload
|
|
|
|
assert Course.connection
|
|
|
|
|
2008-09-07 07:54:05 +02:00
|
|
|
ActiveSupport::Dependencies.clear
|
2007-01-22 14:43:50 +01:00
|
|
|
Object.send(:remove_const, :Course)
|
2008-05-18 06:22:34 +02:00
|
|
|
require_dependency 'models/course'
|
2007-01-22 14:43:50 +01:00
|
|
|
|
|
|
|
assert Course.connection
|
|
|
|
end
|
|
|
|
end
|