diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/statement_cache_test.rb | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/activerecord/test/cases/statement_cache_test.rb b/activerecord/test/cases/statement_cache_test.rb index 76da49707f..ae34b174db 100644 --- a/activerecord/test/cases/statement_cache_test.rb +++ b/activerecord/test/cases/statement_cache_test.rb @@ -10,6 +10,49 @@ module ActiveRecord @connection = ActiveRecord::Base.connection end + #Cache v 1.1 tests + def test_statement_cache + Book.create(name: "my book") + Book.create(name: "my other book") + + cache = StatementCache.new do + Book.where(:name => "my book") + end + + b = cache.execute name: "my book" + assert_equal "my book", b[0].name + b = cache.execute name: "my other book" + assert_equal "my other book", b[0].name + end + + + #Validate primary key binding + def test_statement_cache_id + Book.create(name: "my book") + Book.create(name: "my other book") + + cache = StatementCache.new do + Book.where(id: "1") + end + + b = cache.execute id: "1" + assert_equal "my book", b[0].name + b = cache.execute id: "2" + assert_equal "my other book", b[0].name + end + + def test_find_or_create_by + Book.create(name: "my book") + + a = Book.find_or_create_by(name: "my book") + b = Book.find_or_create_by(name: "my other book") + + assert_equal("my book", a.name) + assert_equal("my other book", b.name) + end + + #End + def test_statement_cache_with_simple_statement cache = ActiveRecord::StatementCache.new do Book.where(name: "my book").where("author_id > 3") @@ -61,4 +104,4 @@ module ActiveRecord assert first_books != additional_books end end -end +end
\ No newline at end of file |