From de6f488a30e83bbf00fe9d5f53ccf28a98281d0d Mon Sep 17 00:00:00 2001 From: Owen Rodda Date: Mon, 11 Jan 2016 22:06:49 -0500 Subject: [PATCH 1/3] Use #capture_io instead of #capture when available (to handle deprecation) --- test/unit/model_test.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index f86e79e8..ade26159 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -648,11 +648,20 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase should 'not generate warning' do # Tests that it doesn't try to write created_on as an attribute just because a created_on # method exists. - warnings = capture(:stderr) { # Deprecation warning in Rails 3.2 - assert_nothing_raised { # ActiveModel::MissingAttributeError in Rails 4 - @wotsit.update_attributes! :name => 'changed' - } - } + warnings = + if respond_to?(:capture_io) + capture_io { + assert_nothing_raised { + @wotsit.update_attributes! :name => 'changed' + } + }.last + else + capture(:stderr) { # Deprecation warning in Rails 3.2 + assert_nothing_raised { # ActiveModel::MissingAttributeError in Rails 4 + @wotsit.update_attributes! :name => 'changed' + } + } + end assert_equal '', warnings end From ebf639087513f08619d437734c0272c38e66a024 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Thu, 14 Jan 2016 23:34:06 -0500 Subject: [PATCH 2/3] Reduce duplication in test by using lambda --- test/unit/model_test.rb | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index ade26159..c40e4ff7 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -645,26 +645,28 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase assert_not_nil @wotsit.versions.last.reify.updated_at end + # Tests that it doesn't try to write created_on as an attribute just because + # a created_on method exists. + # + # - Deprecation warning in Rails 3.2 + # - ActiveModel::MissingAttributeError in Rails 4 + # + # In rails 5, `capture` is deprecated in favor of `capture_io`. + # should 'not generate warning' do - # Tests that it doesn't try to write created_on as an attribute just because a created_on - # method exists. + assert_update_raises_nothing = -> { + assert_nothing_raised { + @wotsit.update_attributes! :name => 'changed' + } + } warnings = if respond_to?(:capture_io) - capture_io { - assert_nothing_raised { - @wotsit.update_attributes! :name => 'changed' - } - }.last + capture_io { assert_update_raises_nothing.call }.last else - capture(:stderr) { # Deprecation warning in Rails 3.2 - assert_nothing_raised { # ActiveModel::MissingAttributeError in Rails 4 - @wotsit.update_attributes! :name => 'changed' - } - } + capture(:stderr) { assert_update_raises_nothing.call } end assert_equal '', warnings end - end From 72fc13de047ca41b4c3fd02dad5473ac02af32ea Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Thu, 14 Jan 2016 23:36:48 -0500 Subject: [PATCH 3/3] Add .rbenv-gemsets to gitignore I've seen rubymine adding this file recently. Since it's not something we already use, it should be safe to ignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ace5640e..17ef9ac2 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ vendor/* .tags_sorted_by_file .ruby-version .ruby-gemset +.rbenv-gemsets