test/replica_test.rb in replica-1.1.0 vs test/replica_test.rb in replica-1.2.0

- old
+ new

@@ -34,11 +34,10 @@ assert_using_master_db(Account) Account.create! assert_not_equal Account.count, ActiveRecord::Base.with_slave { Account.count } assert_not_equal Account.count, Account.with_slave { Account.count } - assert_not_equal Account.count, Account.with_slave.count assert_equal Account.count, Ticket.with_slave { Account.count } end should "support model specific with_slave blocks" do assert_using_master_db(Account) @@ -109,7 +108,27 @@ assert_using_master_db(Account) assert_using_master_db(Ticket) end + end + + context "replica proxy" do + should "successfully execute queries" do + assert_using_master_db(Account) + Account.create! + + assert_not_equal Account.count, Account.with_slave.count + end + + should "work association collections" do + assert_using_master_db(Account) + account = Account.create! + + Ticket.connection.expects(:select_all).with("SELECT * FROM `tickets` WHERE (`tickets`.account_id = #{account.id}) LIMIT 1", anything).returns([]) + Ticket.with_slave.connection.expects(:select_all).with("SELECT * FROM `tickets` WHERE (`tickets`.account_id = #{account.id}) LIMIT 1", anything).returns([]) + + account.tickets.first + account.tickets.with_slave.first + end end end