Skip to content

Commit a160c88

Browse files
committed
Extract tests code out from AR's base_test.rb to integration_test.rb
`AR::Base#to_param` and `AR::Base#cache_key` is defined at active_record/integration.rb, so tests for those methods should be at integration_test.rb
1 parent 3064d64 commit a160c88

File tree

2 files changed

+82
-73
lines changed

2 files changed

+82
-73
lines changed

activerecord/test/cases/base_test.rb

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,16 +1228,6 @@ def test_assert_queries
12281228
assert_no_queries { assert true }
12291229
end
12301230

1231-
def test_to_param_should_return_string
1232-
assert_kind_of String, Client.first.to_param
1233-
end
1234-
1235-
def test_to_param_returns_id_even_if_not_persisted
1236-
client = Client.new
1237-
client.id = 1
1238-
assert_equal "1", client.to_param
1239-
end
1240-
12411231
def test_inspect_class
12421232
assert_equal 'ActiveRecord::Base', ActiveRecord::Base.inspect
12431233
assert_equal 'LoosePerson(abstract)', LoosePerson.inspect
@@ -1431,76 +1421,13 @@ def test_attribute_names_on_abstract_class
14311421
assert_equal [], AbstractCompany.attribute_names
14321422
end
14331423

1434-
def test_cache_key_for_existing_record_is_not_timezone_dependent
1435-
ActiveRecord::Base.time_zone_aware_attributes = true
1436-
1437-
Time.zone = "UTC"
1438-
utc_key = Developer.first.cache_key
1439-
1440-
Time.zone = "EST"
1441-
est_key = Developer.first.cache_key
1442-
1443-
assert_equal utc_key, est_key
1444-
end
1445-
1446-
def test_cache_key_format_for_existing_record_with_updated_at
1447-
dev = Developer.first
1448-
assert_equal "developers/#{dev.id}-#{dev.updated_at.utc.to_s(:nsec)}", dev.cache_key
1449-
end
1450-
1451-
def test_cache_key_format_for_existing_record_with_updated_at_and_custom_cache_timestamp_format
1452-
dev = CachedDeveloper.first
1453-
assert_equal "cached_developers/#{dev.id}-#{dev.updated_at.utc.to_s(:number)}", dev.cache_key
1454-
end
1455-
1456-
def test_cache_key_changes_when_child_touched
1457-
car = Car.create
1458-
Bulb.create(car: car)
1459-
1460-
key = car.cache_key
1461-
car.bulb.touch
1462-
car.reload
1463-
assert_not_equal key, car.cache_key
1464-
end
1465-
1466-
def test_cache_key_format_for_existing_record_with_nil_updated_timestamps
1467-
dev = Developer.first
1468-
dev.update_columns(updated_at: nil, updated_on: nil)
1469-
assert_match(/\/#{dev.id}$/, dev.cache_key)
1470-
end
1471-
1472-
def test_cache_key_for_updated_on
1473-
dev = Developer.first
1474-
dev.updated_at = nil
1475-
assert_equal "developers/#{dev.id}-#{dev.updated_on.utc.to_s(:nsec)}", dev.cache_key
1476-
end
1477-
1478-
def test_cache_key_for_newer_updated_at
1479-
dev = Developer.first
1480-
dev.updated_at += 3600
1481-
assert_equal "developers/#{dev.id}-#{dev.updated_at.utc.to_s(:nsec)}", dev.cache_key
1482-
end
1483-
1484-
def test_cache_key_for_newer_updated_on
1485-
dev = Developer.first
1486-
dev.updated_on += 3600
1487-
assert_equal "developers/#{dev.id}-#{dev.updated_on.utc.to_s(:nsec)}", dev.cache_key
1488-
end
1489-
14901424
def test_touch_should_raise_error_on_a_new_object
14911425
company = Company.new(:rating => 1, :name => "37signals", :firm_name => "37signals")
14921426
assert_raises(ActiveRecord::ActiveRecordError) do
14931427
company.touch :updated_at
14941428
end
14951429
end
14961430

1497-
def test_cache_key_format_is_precise_enough
1498-
dev = Developer.first
1499-
key = dev.cache_key
1500-
dev.touch
1501-
assert_not_equal key, dev.cache_key
1502-
end
1503-
15041431
def test_uniq_delegates_to_scoped
15051432
scope = stub
15061433
Bird.stubs(:all).returns(mock(:uniq => scope))
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
require 'cases/helper'
2+
require 'models/company'
3+
require 'models/developer'
4+
require 'models/car'
5+
require 'models/bulb'
6+
7+
class IntegrationTest < ActiveRecord::TestCase
8+
fixtures :companies, :developers
9+
10+
def test_to_param_should_return_string
11+
assert_kind_of String, Client.first.to_param
12+
end
13+
14+
def test_to_param_returns_id_even_if_not_persisted
15+
client = Client.new
16+
client.id = 1
17+
assert_equal '1', client.to_param
18+
end
19+
20+
def test_cache_key_for_existing_record_is_not_timezone_dependent
21+
ActiveRecord::Base.time_zone_aware_attributes = true
22+
23+
Time.zone = 'UTC'
24+
utc_key = Developer.first.cache_key
25+
26+
Time.zone = 'EST'
27+
est_key = Developer.first.cache_key
28+
29+
assert_equal utc_key, est_key
30+
end
31+
32+
def test_cache_key_format_for_existing_record_with_updated_at
33+
dev = Developer.first
34+
assert_equal "developers/#{dev.id}-#{dev.updated_at.utc.to_s(:nsec)}", dev.cache_key
35+
end
36+
37+
def test_cache_key_format_for_existing_record_with_updated_at_and_custom_cache_timestamp_format
38+
dev = CachedDeveloper.first
39+
assert_equal "cached_developers/#{dev.id}-#{dev.updated_at.utc.to_s(:number)}", dev.cache_key
40+
end
41+
42+
def test_cache_key_changes_when_child_touched
43+
car = Car.create
44+
Bulb.create(car: car)
45+
46+
key = car.cache_key
47+
car.bulb.touch
48+
car.reload
49+
assert_not_equal key, car.cache_key
50+
end
51+
52+
def test_cache_key_format_for_existing_record_with_nil_updated_timestamps
53+
dev = Developer.first
54+
dev.update_columns(updated_at: nil, updated_on: nil)
55+
assert_match(/\/#{dev.id}$/, dev.cache_key)
56+
end
57+
58+
def test_cache_key_for_updated_on
59+
dev = Developer.first
60+
dev.updated_at = nil
61+
assert_equal "developers/#{dev.id}-#{dev.updated_on.utc.to_s(:nsec)}", dev.cache_key
62+
end
63+
64+
def test_cache_key_for_newer_updated_at
65+
dev = Developer.first
66+
dev.updated_at += 3600
67+
assert_equal "developers/#{dev.id}-#{dev.updated_at.utc.to_s(:nsec)}", dev.cache_key
68+
end
69+
70+
def test_cache_key_for_newer_updated_on
71+
dev = Developer.first
72+
dev.updated_on += 3600
73+
assert_equal "developers/#{dev.id}-#{dev.updated_on.utc.to_s(:nsec)}", dev.cache_key
74+
end
75+
76+
def test_cache_key_format_is_precise_enough
77+
dev = Developer.first
78+
key = dev.cache_key
79+
dev.touch
80+
assert_not_equal key, dev.cache_key
81+
end
82+
end

0 commit comments

Comments
 (0)