Extract test to new file: ar_id_map_test.rb
This test is quite strange, and has very little explanation. In an effort to understand it better, move it and its context to a new file. In particular, reopening the ActiveRecord::IdentityMap module inside a test is unusual. More importantly, it's not clear why we're testing a method that we do not implement.
This commit is contained in:
parent
a550f60b54
commit
3a446c14bb
|
@ -59,7 +59,7 @@ Style/ClassAndModuleChildren:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'test/functional/sinatra_test.rb'
|
- 'test/functional/sinatra_test.rb'
|
||||||
- 'test/test_helper.rb'
|
- 'test/test_helper.rb'
|
||||||
- 'test/unit/model_test.rb'
|
- 'test/unit/ar_id_map_test.rb'
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ARIdMapTest < ActiveSupport::TestCase
|
||||||
|
setup do
|
||||||
|
@widget = Widget.new
|
||||||
|
@widget.update_attributes :name => 'Henry', :created_at => Time.now - 1.day
|
||||||
|
@widget.update_attributes :name => 'Harry'
|
||||||
|
end
|
||||||
|
|
||||||
|
if defined?(ActiveRecord::IdentityMap) && ActiveRecord::IdentityMap.respond_to?(:without)
|
||||||
|
should 'not clobber the IdentityMap when reifying' do
|
||||||
|
module ActiveRecord::IdentityMap
|
||||||
|
class << self
|
||||||
|
alias __without without
|
||||||
|
def without(&block)
|
||||||
|
@unclobbered = true
|
||||||
|
__without(&block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@widget.versions.last.reify
|
||||||
|
assert ActiveRecord::IdentityMap.instance_variable_get("@unclobbered")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -342,23 +342,6 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
||||||
assert_equal ['Henry', 'Harry'], @widget.versions.last.changeset['name']
|
assert_equal ['Henry', 'Harry'], @widget.versions.last.changeset['name']
|
||||||
end
|
end
|
||||||
|
|
||||||
if defined?(ActiveRecord::IdentityMap) && ActiveRecord::IdentityMap.respond_to?(:without)
|
|
||||||
should 'not clobber the IdentityMap when reifying' do
|
|
||||||
module ActiveRecord::IdentityMap
|
|
||||||
class << self
|
|
||||||
alias :__without :without
|
|
||||||
def without(&block)
|
|
||||||
@unclobbered = true
|
|
||||||
__without(&block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@widget.versions.last.reify
|
|
||||||
assert ActiveRecord::IdentityMap.instance_variable_get("@unclobbered")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'and has one associated object' do
|
context 'and has one associated object' do
|
||||||
setup do
|
setup do
|
||||||
@wotsit = @widget.create_wotsit :name => 'John'
|
@wotsit = @widget.create_wotsit :name => 'John'
|
||||||
|
@ -381,7 +364,6 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
context 'and has many associated objects' do
|
context 'and has many associated objects' do
|
||||||
setup do
|
setup do
|
||||||
@f0 = @widget.fluxors.create :name => 'f-zero'
|
@f0 = @widget.fluxors.create :name => 'f-zero'
|
||||||
|
|
Loading…
Reference in New Issue