aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2011-04-03 20:09:00 -0300
committerJosé Valim <jose.valim@gmail.com>2011-04-04 10:48:12 +0200
commitb35617235d43bdb32016a623044e7f4005879969 (patch)
tree6a007f2bf9678fa1c1c5c64c8980032934fbefb0 /activerecord/test
parent16e5d158c23af1c7ca2c7aa32d964db97cb9a4f7 (diff)
downloadrails-b35617235d43bdb32016a623044e7f4005879969.tar.gz
rails-b35617235d43bdb32016a623044e7f4005879969.tar.bz2
rails-b35617235d43bdb32016a623044e7f4005879969.zip
Use IM when trying to load records using ID.
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/base_test.rb10
-rw-r--r--activerecord/test/cases/identity_map_test.rb13
-rw-r--r--activerecord/test/cases/query_cache_test.rb2
3 files changed, 16 insertions, 9 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index aeb0b28bab..b3facf50b8 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -172,7 +172,7 @@ class BasicsTest < ActiveRecord::TestCase
with_active_record_default_timezone :utc do
time = Time.local(2000)
topic = Topic.create('written_on' => time)
- saved_time = Topic.find(topic.id).written_on
+ saved_time = Topic.find(topic.id).reload.written_on
assert_equal time, saved_time
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "EST"], time.to_a
assert_equal [0, 0, 5, 1, 1, 2000, 6, 1, false, "UTC"], saved_time.to_a
@@ -186,7 +186,7 @@ class BasicsTest < ActiveRecord::TestCase
Time.use_zone 'Central Time (US & Canada)' do
time = Time.zone.local(2000)
topic = Topic.create('written_on' => time)
- saved_time = Topic.find(topic.id).written_on
+ saved_time = Topic.find(topic.id).reload.written_on
assert_equal time, saved_time
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "CST"], time.to_a
assert_equal [0, 0, 6, 1, 1, 2000, 6, 1, false, "UTC"], saved_time.to_a
@@ -199,7 +199,7 @@ class BasicsTest < ActiveRecord::TestCase
with_env_tz 'America/New_York' do
time = Time.utc(2000)
topic = Topic.create('written_on' => time)
- saved_time = Topic.find(topic.id).written_on
+ saved_time = Topic.find(topic.id).reload.written_on
assert_equal time, saved_time
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "UTC"], time.to_a
assert_equal [0, 0, 19, 31, 12, 1999, 5, 365, false, "EST"], saved_time.to_a
@@ -212,7 +212,7 @@ class BasicsTest < ActiveRecord::TestCase
Time.use_zone 'Central Time (US & Canada)' do
time = Time.zone.local(2000)
topic = Topic.create('written_on' => time)
- saved_time = Topic.find(topic.id).written_on
+ saved_time = Topic.find(topic.id).reload.written_on
assert_equal time, saved_time
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "CST"], time.to_a
assert_equal [0, 0, 1, 1, 1, 2000, 6, 1, false, "EST"], saved_time.to_a
@@ -1048,7 +1048,7 @@ class BasicsTest < ActiveRecord::TestCase
topic = Topic.new(:content => myobj)
assert topic.save
Topic.serialize(:content, Hash)
- assert_raise(ActiveRecord::SerializationTypeMismatch) { Topic.find(topic.id).content }
+ assert_raise(ActiveRecord::SerializationTypeMismatch) { Topic.find(topic.id).reload.content }
ensure
Topic.serialize(:content)
end
diff --git a/activerecord/test/cases/identity_map_test.rb b/activerecord/test/cases/identity_map_test.rb
index 89f7b92d09..9cf3db7f87 100644
--- a/activerecord/test/cases/identity_map_test.rb
+++ b/activerecord/test/cases/identity_map_test.rb
@@ -90,6 +90,13 @@ class IdentityMapTest < ActiveRecord::TestCase
)
end
+ def test_queries_are_not_executed_when_finding_by_id
+ Post.find 1
+ assert_no_queries do
+ Post.find 1
+ end
+ end
+
##############################################################################
# Tests checking if IM is functioning properly on more advanced finds #
# and associations #
@@ -144,7 +151,7 @@ class IdentityMapTest < ActiveRecord::TestCase
s = Subscriber.find('swistak')
- assert_equal({'name' => ["Raczkowski Marcin", "Swistak Sreberkowiec"]}, swistak.changes)
+ assert_equal({"name"=>["Marcin Raczkowski", "Swistak Sreberkowiec"]}, swistak.changes)
assert_equal("Swistak Sreberkowiec", swistak.name)
end
@@ -159,8 +166,8 @@ class IdentityMapTest < ActiveRecord::TestCase
s = Subscriber.find('swistak')
assert_equal("Swistak Sreberkowiec", swistak.name)
- assert_equal({}, swistak.changes)
- assert !swistak.name_changed?
+ assert_equal({"name"=>["Marcin Raczkowski", "Swistak Sreberkowiec"]}, swistak.changes)
+ assert swistak.name_changed?
end
def test_has_many_associations
diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb
index 53aefc7b58..287f7e255b 100644
--- a/activerecord/test/cases/query_cache_test.rb
+++ b/activerecord/test/cases/query_cache_test.rb
@@ -13,7 +13,7 @@ class QueryCacheTest < ActiveRecord::TestCase
end
def test_find_queries
- assert_queries(2) { Task.find(1); Task.find(1) }
+ assert_queries(ActiveRecord::IdentityMap.enabled? ? 1 : 2) { Task.find(1); Task.find(1) }
end
def test_find_queries_with_cache