class MultipleDbTest
Public Instance Methods
setup()
click to toggle source
# File activerecord/test/cases/multiple_db_test.rb, line 11 def setup @courses = create_fixtures("courses") { Course.retrieve_connection } @colleges = create_fixtures("colleges") { College.retrieve_connection } @entrants = create_fixtures("entrants") end
test_associations()
click to toggle source
# File activerecord/test/cases/multiple_db_test.rb, line 49 def test_associations c1 = Course.find(1) assert_equal 2, c1.entrants.count e1 = Entrant.find(1) assert_equal e1.course.id, c1.id c2 = Course.find(2) assert_equal 1, c2.entrants.count e3 = Entrant.find(3) assert_equal e3.course.id, c2.id end
test_associations_should_work_when_model_has_no_connection()
click to toggle source
# File activerecord/test/cases/multiple_db_test.rb, line 108 def test_associations_should_work_when_model_has_no_connection begin ActiveRecord::Base.remove_connection assert_nothing_raised do College.first.courses.first end ensure ActiveRecord::Base.establish_connection :arunit end end
test_connected()
click to toggle source
# File activerecord/test/cases/multiple_db_test.rb, line 17 def test_connected assert_not_nil Entrant.connection assert_not_nil Course.connection end
test_connection()
click to toggle source
# File activerecord/test/cases/multiple_db_test.rb, line 95 def test_connection assert_same Entrant.connection, Bird.connection assert_not_same Entrant.connection, Course.connection end
test_count_on_custom_connection()
click to toggle source
# File activerecord/test/cases/multiple_db_test.rb, line 101 def test_count_on_custom_connection ActiveRecord::Base.remove_connection assert_equal 1, College.count ensure ActiveRecord::Base.establish_connection :arunit end
test_course_connection_should_survive_dependency_reload()
click to toggle source
# File activerecord/test/cases/multiple_db_test.rb, line 60 def test_course_connection_should_survive_dependency_reload assert Course.connection ActiveSupport::Dependencies.clear Object.send(:remove_const, :Course) require_dependency "models/course" assert Course.connection end
test_find()
click to toggle source
# File activerecord/test/cases/multiple_db_test.rb, line 36 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
test_proper_connection()
click to toggle source
# File activerecord/test/cases/multiple_db_test.rb, line 22 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
test_swapping_the_connection()
click to toggle source
# File activerecord/test/cases/multiple_db_test.rb, line 29 def test_swapping_the_connection old_spec_name, Course.connection_specification_name = Course.connection_specification_name, "primary" assert_equal(Entrant.connection, Course.connection) ensure Course.connection_specification_name = old_spec_name end
test_transactions_across_databases()
click to toggle source
# File activerecord/test/cases/multiple_db_test.rb, line 70 def test_transactions_across_databases c1 = Course.find(1) e1 = Entrant.find(1) begin Course.transaction do Entrant.transaction do c1.name = "Typo" e1.name = "Typo" c1.save e1.save raise "No I messed up." end end rescue # Yup caught it end assert_equal "Typo", c1.name assert_equal "Typo", e1.name assert_equal "Ruby Development", Course.find(1).name assert_equal "Ruby Developer", Entrant.find(1).name end