From 3a446c14bba115c32f058cdbb003f89b47128567 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Mon, 15 Feb 2016 22:00:56 -0500 Subject: [PATCH] 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. --- .rubocop_todo.yml | 2 +- test/unit/ar_id_map_test.rb | 26 ++++++++++++++++++++++++++ test/unit/model_test.rb | 18 ------------------ 3 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 test/unit/ar_id_map_test.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5b73ab6e..011ede3c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. diff --git a/test/unit/ar_id_map_test.rb b/test/unit/ar_id_map_test.rb new file mode 100644 index 00000000..098dc4da --- /dev/null +++ b/test/unit/ar_id_map_test.rb @@ -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 diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index 492c90db..d2d4b327 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -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'