diff options
author | Noemj <olli.rissanen@helsinki.fi> | 2013-04-10 17:40:01 +0300 |
---|---|---|
committer | Olli Rissanen <olli.rissanen@helsinki.fi> | 2013-04-10 21:20:58 +0300 |
commit | af1a4bdc564864e80b234755651303dac68ae82e (patch) | |
tree | 2345aada72f625bf1ce2a582625ae9fbef715bb6 /activerecord/test | |
parent | 45321a69b3c01ce8a4cfef6cdf13381d73e10cd3 (diff) | |
download | rails-af1a4bdc564864e80b234755651303dac68ae82e.tar.gz rails-af1a4bdc564864e80b234755651303dac68ae82e.tar.bz2 rails-af1a4bdc564864e80b234755651303dac68ae82e.zip |
Added statement cache
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/statement_cache_test.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/activerecord/test/cases/statement_cache_test.rb b/activerecord/test/cases/statement_cache_test.rb new file mode 100644 index 0000000000..6ed4e5effd --- /dev/null +++ b/activerecord/test/cases/statement_cache_test.rb @@ -0,0 +1,64 @@ +require 'cases/helper' +require 'models/book' +require 'models/liquid' +require 'models/molecule' +require 'models/electron' + +module ActiveRecord + class StatementCacheTest < ActiveRecord::TestCase + def setup + @connection = ActiveRecord::Base.connection + end + + def test_statement_cache_with_simple_statement + cache = ActiveRecord::StatementCache.new do + Book.where(name: "my book").where("author_id > 3") + end + + Book.create(name: "my book", author_id: 4) + + books = cache.execute + assert_equal "my book", books[0].name + end + + def test_statement_cache_with_nil_statement_raises_error + assert_raise(ArgumentError) do + cache = 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') + end + + salty = Liquid.create(name: 'salty') + molecule = salty.molecules.create(name: 'dioxane') + electron = molecule.electrons.create(name: 'lepton') + + liquids = cache.execute + assert_equal "salty", liquids[0].name + end + + def test_statement_cache_values_differ + cache = ActiveRecord::StatementCache.new do + Book.where(name: "my book") + end + + for i in 0..2 do + Book.create(name: "my book") + end + + first_books = cache.execute + + for i in 0..2 do + Book.create(name: "my book") + end + + additional_books = cache.execute + assert first_books != additional_books + end + end +end |