aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/statement_cache_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/statement_cache_test.rb')
-rw-r--r--activerecord/test/cases/statement_cache_test.rb50
1 files changed, 42 insertions, 8 deletions
diff --git a/activerecord/test/cases/statement_cache_test.rb b/activerecord/test/cases/statement_cache_test.rb
index 76da49707f..88ac2cf2eb 100644
--- a/activerecord/test/cases/statement_cache_test.rb
+++ b/activerecord/test/cases/statement_cache_test.rb
@@ -10,6 +10,48 @@ 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 |name|
+ Book.where(:name => name)
+ end
+
+ b = cache.execute "my book"
+ assert_equal "my book", b[0].name
+ b = cache.execute "my other book"
+ assert_equal "my other book", b[0].name
+ end
+
+
+ def test_statement_cache_id
+ b1 = Book.create(name: "my book")
+ b2 = Book.create(name: "my other book")
+
+ cache = StatementCache.new do |id|
+ Book.where(id: id)
+ end
+
+ b = cache.execute b1.id
+ assert_equal b1.name, b[0].name
+ b = cache.execute b2.id
+ assert_equal b2.name, 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")
@@ -21,14 +63,6 @@ module ActiveRecord
assert_equal "my book", books[0].name
end
- def test_statement_cache_with_nil_statement_raises_error
- assert_raise(ArgumentError) do
- ActiveRecord::StatementCache.new do
- nil
- end
- end
- end
-
def test_statement_cache_with_complex_statement
cache = ActiveRecord::StatementCache.new do
Liquid.joins(:molecules => :electrons).where('molecules.name' => 'dioxane', 'electrons.name' => 'lepton')