From e6b8ee00e94bec78a8f728f7fa15335a21aacacf Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Fri, 15 Jan 2016 07:32:24 -0600 Subject: [PATCH 1/8] Upgrade to rubocop 0.36.0 Also be more specific about the version we want. This is to avoid breaking the build by accidentally introducing new cops. --- active_interaction.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_interaction.gemspec b/active_interaction.gemspec index f18b03f2..ec6c5584 100644 --- a/active_interaction.gemspec +++ b/active_interaction.gemspec @@ -43,7 +43,7 @@ Gem::Specification.new do |gem| 'kramdown' => ['~> 1.9'], 'rake' => ['~> 10.4'], 'rspec' => ['~> 3.4'], - 'rubocop' => ['~> 0.35'], + 'rubocop' => ['~> 0.36.0'], 'yard' => ['~> 0.8'] }.each do |name, versions| gem.add_development_dependency name, *versions From 5ffd85e1162b54468d541f8bf0a59f9c05cb7f01 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Fri, 15 Jan 2016 07:40:28 -0600 Subject: [PATCH 2/8] Fix Performance/RedundantMerge offenses --- spec/active_interaction/base_spec.rb | 23 ++++++++++--------- .../filters/date_filter_spec.rb | 12 ++++------ .../filters/date_time_filter_spec.rb | 18 +++++++-------- .../filters/decimal_filter_spec.rb | 2 +- .../filters/hash_filter_spec.rb | 4 ++-- .../filters/object_filter_spec.rb | 8 +++---- .../filters/string_filter_spec.rb | 2 +- .../filters/time_filter_spec.rb | 18 +++++++-------- .../integration/array_interaction_spec.rb | 2 +- .../integration/hash_interaction_spec.rb | 2 +- .../integration/time_interaction_spec.rb | 2 +- spec/support/filters.rb | 8 +++---- spec/support/interactions.rb | 8 +++---- 13 files changed, 52 insertions(+), 57 deletions(-) diff --git a/spec/active_interaction/base_spec.rb b/spec/active_interaction/base_spec.rb index c0ec9eed..1723d86a 100644 --- a/spec/active_interaction/base_spec.rb +++ b/spec/active_interaction/base_spec.rb @@ -36,7 +36,7 @@ def execute describe '.new(inputs = {})' do it 'does not allow :_interaction_* as an option' do key = :"_interaction_#{SecureRandom.hex}" - inputs.merge!(key => nil) + inputs[key] = nil expect do interaction end.to raise_error ActiveInteraction::InvalidValueError @@ -44,7 +44,7 @@ def execute it 'does not allow "_interaction_*" as an option' do key = "_interaction_#{SecureRandom.hex}" - inputs.merge!(key => nil) + inputs[key] = nil expect do interaction end.to raise_error ActiveInteraction::InvalidValueError @@ -75,7 +75,7 @@ def execute end context 'passing' do - before { inputs.merge!(thing: SecureRandom.hex) } + before { inputs[:thing] = SecureRandom.hex } it 'returns a valid outcome' do expect(interaction).to be_valid @@ -85,7 +85,7 @@ def execute context 'with a single input' do let(:thing) { SecureRandom.hex } - before { inputs.merge!(thing: thing) } + before { inputs[:thing] = thing } it 'sets the attribute' do expect(interaction.thing).to eql thing @@ -98,7 +98,7 @@ def execute context 'validation' do context 'failing' do - before { inputs.merge!(thing: thing) } + before { inputs[:thing] = thing } context 'with an invalid value' do let(:thing) { 'a' } @@ -118,7 +118,7 @@ def execute end context 'passing' do - before { inputs.merge!(thing: 1) } + before { inputs[:thing] = 1 } it 'returns a valid outcome' do expect(interaction).to be_valid @@ -127,7 +127,7 @@ def execute end context 'with a single input' do - before { inputs.merge!(thing: 1) } + before { inputs[:thing] = 1 } it 'sets the attribute to the filtered value' do expect(interaction.thing).to eql 1.0 @@ -248,7 +248,7 @@ def execute end context 'passing validations' do - before { inputs.merge!(thing: thing) } + before { inputs[:thing] = thing } context 'failing runtime validations' do before do @@ -311,7 +311,7 @@ def execute end context 'passing validations' do - before { inputs.merge!(thing: thing) } + before { inputs[:thing] = thing } it 'returns the result' do expect(result[:thing]).to eql thing @@ -341,7 +341,8 @@ def execute context 'with valid composition' do before do - inputs.merge!(x: x, z: z) + inputs[:x] = x + inputs[:z] = z end it 'is valid' do @@ -485,7 +486,7 @@ def filters(klass) let(:thing) { rand } before do - inputs.merge!(thing: thing) + inputs[:thing] = thing end it 'returns true' do diff --git a/spec/active_interaction/filters/date_filter_spec.rb b/spec/active_interaction/filters/date_filter_spec.rb index ca4289fe..73bbb429 100644 --- a/spec/active_interaction/filters/date_filter_spec.rb +++ b/spec/active_interaction/filters/date_filter_spec.rb @@ -10,7 +10,7 @@ let(:format) { '%d/%m/%Y' } before do - options.merge!(format: format) + options[:format] = format end end @@ -116,12 +116,10 @@ describe '#default' do context 'with a GroupedInput' do before do - options.merge!( - default: ActiveInteraction::GroupedInput.new( - '1' => '2012', - '2' => '1', - '3' => '2' - ) + options[:default] = ActiveInteraction::GroupedInput.new( + '1' => '2012', + '2' => '1', + '3' => '2' ) end diff --git a/spec/active_interaction/filters/date_time_filter_spec.rb b/spec/active_interaction/filters/date_time_filter_spec.rb index eb78a9f0..15e20712 100644 --- a/spec/active_interaction/filters/date_time_filter_spec.rb +++ b/spec/active_interaction/filters/date_time_filter_spec.rb @@ -10,7 +10,7 @@ let(:format) { '%d/%m/%Y %H:%M:%S %:z' } before do - options.merge!(format: format) + options[:format] = format end end @@ -124,15 +124,13 @@ describe '#default' do context 'with a GroupedInput' do before do - options.merge!( - default: ActiveInteraction::GroupedInput.new( - '1' => '2012', - '2' => '1', - '3' => '2', - '4' => '3', - '5' => '4', - '6' => '5' - ) + options[:default] = ActiveInteraction::GroupedInput.new( + '1' => '2012', + '2' => '1', + '3' => '2', + '4' => '3', + '5' => '4', + '6' => '5' ) end diff --git a/spec/active_interaction/filters/decimal_filter_spec.rb b/spec/active_interaction/filters/decimal_filter_spec.rb index 5f3a457d..0bc414d4 100644 --- a/spec/active_interaction/filters/decimal_filter_spec.rb +++ b/spec/active_interaction/filters/decimal_filter_spec.rb @@ -10,7 +10,7 @@ let(:digits) { 4 } before do - options.merge!(digits: digits) + options[:digits] = digits end end diff --git a/spec/active_interaction/filters/hash_filter_spec.rb b/spec/active_interaction/filters/hash_filter_spec.rb index 45a74b3c..9f7da3a1 100644 --- a/spec/active_interaction/filters/hash_filter_spec.rb +++ b/spec/active_interaction/filters/hash_filter_spec.rb @@ -80,7 +80,7 @@ describe '#default' do context 'with a Hash' do before do - options.merge!(default: {}) + options[:default] = {} end it 'returns the Hash' do @@ -90,7 +90,7 @@ context 'with a non-empty Hash' do before do - options.merge!(default: { a: {} }) + options[:default] = { a: {} } end it 'raises an error' do diff --git a/spec/active_interaction/filters/object_filter_spec.rb b/spec/active_interaction/filters/object_filter_spec.rb index efc712d0..6f08ed31 100644 --- a/spec/active_interaction/filters/object_filter_spec.rb +++ b/spec/active_interaction/filters/object_filter_spec.rb @@ -10,7 +10,7 @@ class Things; end it_behaves_like 'a filter' before do - options.merge!(class: Thing) + options[:class] = Thing end describe '#cast' do @@ -101,7 +101,7 @@ def self.name context 'with class as a superclass' do before do - options.merge!(class: Thing.superclass) + options[:class] = Thing.superclass end it 'returns the instance' do @@ -111,7 +111,7 @@ def self.name context 'with class as a String' do before do - options.merge!(class: Thing.name) + options[:class] = Thing.name end it 'returns the instance' do @@ -131,7 +131,7 @@ def self.name context 'with class as an invalid String' do before do - options.merge!(class: 'invalid') + options[:class] = 'invalid' end it 'raises an error' do diff --git a/spec/active_interaction/filters/string_filter_spec.rb b/spec/active_interaction/filters/string_filter_spec.rb index aa7920b0..d72beaf5 100644 --- a/spec/active_interaction/filters/string_filter_spec.rb +++ b/spec/active_interaction/filters/string_filter_spec.rb @@ -8,7 +8,7 @@ shared_context 'without strip' do before do - options.merge!(strip: false) + options[:strip] = false end end diff --git a/spec/active_interaction/filters/time_filter_spec.rb b/spec/active_interaction/filters/time_filter_spec.rb index 67e5a465..b6594980 100644 --- a/spec/active_interaction/filters/time_filter_spec.rb +++ b/spec/active_interaction/filters/time_filter_spec.rb @@ -10,7 +10,7 @@ let(:format) { '%d/%m/%Y %H:%M:%S %z' } before do - options.merge!(format: format) + options[:format] = format end end @@ -146,15 +146,13 @@ describe '#default' do context 'with a GroupedInput' do before do - options.merge!( - default: ActiveInteraction::GroupedInput.new( - '1' => '2012', - '2' => '1', - '3' => '2', - '4' => '3', - '5' => '4', - '6' => '5' - ) + options[:default] = ActiveInteraction::GroupedInput.new( + '1' => '2012', + '2' => '1', + '3' => '2', + '4' => '3', + '5' => '4', + '6' => '5' ) end diff --git a/spec/active_interaction/integration/array_interaction_spec.rb b/spec/active_interaction/integration/array_interaction_spec.rb index 147e155f..b61016da 100644 --- a/spec/active_interaction/integration/array_interaction_spec.rb +++ b/spec/active_interaction/integration/array_interaction_spec.rb @@ -31,7 +31,7 @@ class CollectionProxy context 'with inputs[:a]' do let(:a) { [[]] } - before { inputs.merge!(a: a) } + before { inputs[:a] = a } it 'returns the correct value for :a' do expect(result[:a]).to eql a diff --git a/spec/active_interaction/integration/hash_interaction_spec.rb b/spec/active_interaction/integration/hash_interaction_spec.rb index 5b351780..0de0e935 100644 --- a/spec/active_interaction/integration/hash_interaction_spec.rb +++ b/spec/active_interaction/integration/hash_interaction_spec.rb @@ -18,7 +18,7 @@ context 'with inputs[:a]' do let(:a) { { x: {} } } - before { inputs.merge!(a: a) } + before { inputs[:a] = a } it 'returns the correct value for :a' do expect(result[:a]).to eql a.with_indifferent_access diff --git a/spec/active_interaction/integration/time_interaction_spec.rb b/spec/active_interaction/integration/time_interaction_spec.rb index 135864d1..025d9194 100644 --- a/spec/active_interaction/integration/time_interaction_spec.rb +++ b/spec/active_interaction/integration/time_interaction_spec.rb @@ -37,7 +37,7 @@ def ==(other) let(:a) { nil } before do - inputs.merge!(a: a) + inputs[:a] = a allow(Time).to receive(:zone).and_return(TimeZone) end diff --git a/spec/support/filters.rb b/spec/support/filters.rb index 64297c74..027be9b8 100644 --- a/spec/support/filters.rb +++ b/spec/support/filters.rb @@ -9,7 +9,7 @@ shared_context 'optional' do before do - options.merge!(default: nil) + options[:default] = nil end end @@ -112,7 +112,7 @@ context 'with an invalid default' do before do - options.merge!(default: Object.new) + options[:default] = Object.new end it 'raises an error' do @@ -144,7 +144,7 @@ context 'with an invalid default' do before do - options.merge!(default: Object.new) + options[:default] = Object.new end it 'raises an error' do @@ -177,7 +177,7 @@ let(:desc) { SecureRandom.hex } before do - options.merge!(desc: desc) + options[:desc] = desc end it 'returns the description' do diff --git a/spec/support/interactions.rb b/spec/support/interactions.rb index d05395eb..6a6a0dd6 100644 --- a/spec/support/interactions.rb +++ b/spec/support/interactions.rb @@ -54,7 +54,7 @@ def execute context 'with inputs[:required]' do let(:required) { generator.call } - before { inputs.merge!(required: required) } + before { inputs[:required] = required } it 'is valid' do expect(outcome).to be_valid @@ -73,7 +73,7 @@ def execute end it 'does not return nil for :default when given nil' do - inputs.merge!(default: nil) + inputs[:default] = nil expect(result[:default]).to_not be_nil end @@ -92,7 +92,7 @@ def execute context 'with inputs[:optional]' do let(:optional) { generator.call } - before { inputs.merge!(optional: optional) } + before { inputs[:optional] = optional } it 'returns the correct value for :optional' do expect(result[:optional]).to eql optional @@ -102,7 +102,7 @@ def execute context 'with inputs[:default]' do let(:default) { generator.call } - before { inputs.merge!(default: default) } + before { inputs[:default] = default } it 'returns the correct value for :default' do expect(result[:default]).to eql default From bb4367dc835597d01565484f3ae071499c3892dd Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Fri, 15 Jan 2016 07:45:51 -0600 Subject: [PATCH 3/8] Fix a Style/MutableConstant offense --- benchmarks/filters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/filters.rb b/benchmarks/filters.rb index 93135bfc..fd463640 100644 --- a/benchmarks/filters.rb +++ b/benchmarks/filters.rb @@ -18,7 +18,7 @@ string: '', symbol: :'', time: Time.at(0) -} +}.freeze Benchmark.ips do |bm| bm.report('lambda') { -> {}.call } From 754d09e6f1b4c2636805f8b1c7972de08dab9d32 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Fri, 15 Jan 2016 07:46:24 -0600 Subject: [PATCH 4/8] Fix Style/NestedParenthesizedCalls offenses --- spec/active_interaction/concerns/runnable_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/active_interaction/concerns/runnable_spec.rb b/spec/active_interaction/concerns/runnable_spec.rb index 8fd7184c..851c3687 100644 --- a/spec/active_interaction/concerns/runnable_spec.rb +++ b/spec/active_interaction/concerns/runnable_spec.rb @@ -90,7 +90,7 @@ let(:result) { double } it 'returns the result' do - expect(instance.result = result).to eql result + expect((instance.result = result)).to eql result end it 'sets the result' do From 6b39f868c82a0763d6a2eb0e67a0b8caf5d1bcaf Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Fri, 15 Jan 2016 07:48:19 -0600 Subject: [PATCH 5/8] Enable Lint/HandleExceptions and fix offenses --- .rubocop.yml | 2 -- lib/active_interaction/base.rb | 2 +- spec/active_interaction/integration/time_interaction_spec.rb | 1 + 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 88ea3886..d4d5c425 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,8 +13,6 @@ Documentation: FileName: Exclude: - gemfiles/* -HandleExceptions: - Enabled: false MultilineOperationIndentation: Enabled: false PercentLiteralDelimiters: diff --git a/lib/active_interaction/base.rb b/lib/active_interaction/base.rb index 94660589..04c9ecdf 100644 --- a/lib/active_interaction/base.rb +++ b/lib/active_interaction/base.rb @@ -254,7 +254,7 @@ def populate_filters(inputs) begin public_send("#{name}=", filter.clean(inputs[name], self)) rescue InvalidValueError, MissingValueError, NoDefaultError - # #type_check will add errors if appropriate. + nil # #type_check will add errors if appropriate. end end end diff --git a/spec/active_interaction/integration/time_interaction_spec.rb b/spec/active_interaction/integration/time_interaction_spec.rb index 025d9194..1cf668ba 100644 --- a/spec/active_interaction/integration/time_interaction_spec.rb +++ b/spec/active_interaction/integration/time_interaction_spec.rb @@ -10,6 +10,7 @@ def self.at(*args) def self.parse(*args) TimeWithZone.new(Time.parse(*args)) rescue ArgumentError + nil end end From 217616f7992127333f4ad0850e282cc0469fc9c1 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Fri, 15 Jan 2016 07:54:35 -0600 Subject: [PATCH 6/8] Fix Style/MultilineMethodCallIndentation offenses --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index d4d5c425..7140528f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,6 +13,8 @@ Documentation: FileName: Exclude: - gemfiles/* +MultilineMethodCallIndentation: + EnforcedStyle: indented MultilineOperationIndentation: Enabled: false PercentLiteralDelimiters: From 94824d129b419272f5c9b8ba647b12dafe4bf041 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Fri, 15 Jan 2016 07:58:19 -0600 Subject: [PATCH 7/8] Fix Style/Alias offenses --- lib/active_interaction/filters/abstract_date_time_filter.rb | 2 +- lib/active_interaction/filters/abstract_numeric_filter.rb | 2 +- lib/active_interaction/filters/time_filter.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_interaction/filters/abstract_date_time_filter.rb b/lib/active_interaction/filters/abstract_date_time_filter.rb index ba0c4827..451476d1 100644 --- a/lib/active_interaction/filters/abstract_date_time_filter.rb +++ b/lib/active_interaction/filters/abstract_date_time_filter.rb @@ -9,7 +9,7 @@ module ActiveInteraction # # @private class AbstractDateTimeFilter < AbstractFilter - alias_method :_cast, :cast + alias _cast cast private :_cast def cast(value, context) diff --git a/lib/active_interaction/filters/abstract_numeric_filter.rb b/lib/active_interaction/filters/abstract_numeric_filter.rb index b08ce038..cbea5299 100644 --- a/lib/active_interaction/filters/abstract_numeric_filter.rb +++ b/lib/active_interaction/filters/abstract_numeric_filter.rb @@ -8,7 +8,7 @@ module ActiveInteraction # # @private class AbstractNumericFilter < AbstractFilter - alias_method :_cast, :cast + alias _cast cast private :_cast def cast(value, context) diff --git a/lib/active_interaction/filters/time_filter.rb b/lib/active_interaction/filters/time_filter.rb index 4d0ffb2c..aa8e5105 100644 --- a/lib/active_interaction/filters/time_filter.rb +++ b/lib/active_interaction/filters/time_filter.rb @@ -24,7 +24,7 @@ class Base class TimeFilter < AbstractDateTimeFilter register :time - alias_method :_klass, :klass + alias _klass klass private :_klass def initialize(name, options = {}, &block) From 3d3897c6079fbef16982ad9ffb282c6c78ec6f69 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Fri, 15 Jan 2016 13:02:52 -0600 Subject: [PATCH 8/8] Use pragma to disable mutable constant --- lib/active_interaction/filter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_interaction/filter.rb b/lib/active_interaction/filter.rb index db86bde4..f458c81f 100644 --- a/lib/active_interaction/filter.rb +++ b/lib/active_interaction/filter.rb @@ -14,7 +14,7 @@ module ActiveInteraction # Describes an input filter for an interaction. class Filter # @return [Hash{Symbol => Class}] - CLASSES = {} + CLASSES = {} # rubocop:disable Style/MutableConstant private_constant :CLASSES # @return [Hash{Symbol => Filter}]