1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00

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:
Jared Beck 2016-02-15 22:00:56 -05:00
parent a550f60b54
commit 3a446c14bb
3 changed files with 27 additions and 19 deletions

View file

@ -59,7 +59,7 @@ Style/ClassAndModuleChildren:
Exclude:
- 'test/functional/sinatra_test.rb'
- 'test/test_helper.rb'
- 'test/unit/model_test.rb'
- 'test/unit/ar_id_map_test.rb'
# Offense count: 1
# Cop supports --auto-correct.

View file

@ -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

View file

@ -342,23 +342,6 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
assert_equal ['Henry', 'Harry'], @widget.versions.last.changeset['name']
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
setup do
@wotsit = @widget.create_wotsit :name => 'John'
@ -381,7 +364,6 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
end
end
context 'and has many associated objects' do
setup do
@f0 = @widget.fluxors.create :name => 'f-zero'