From de7175fbe44f4357917dd6dd55aa7f2c63421541 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 13 Mar 2016 19:55:12 -0400 Subject: [PATCH 1/9] Fix Style/MethodDefParentheses --- .rubocop_todo.yml | 7 ------- lib/paper_trail/config.rb | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a76ef000..a9e6be15 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -116,13 +116,6 @@ Style/LineEndConcatenation: - 'lib/paper_trail/config.rb' - 'lib/paper_trail/has_paper_trail.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline -Style/MethodDefParentheses: - Enabled: false - # Offense count: 2 Style/ModuleFunction: Exclude: diff --git a/lib/paper_trail/config.rb b/lib/paper_trail/config.rb index 86c17bb0..ec94c591 100644 --- a/lib/paper_trail/config.rb +++ b/lib/paper_trail/config.rb @@ -44,7 +44,7 @@ module PaperTrail @mutex.synchronize { !!@enabled } end - def enabled= enable + def enabled=(enable) @mutex.synchronize { @enabled = enable } end end From 7b2a805e4959e574ff45c4af2ba47d94d73b68ed Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 13 Mar 2016 19:57:17 -0400 Subject: [PATCH 2/9] Fix Style/NestedParenthesizedCalls --- .rubocop_todo.yml | 5 ----- lib/paper_trail/has_paper_trail.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a9e6be15..307e6381 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -149,11 +149,6 @@ Style/MutableConstant: - 'test/dummy/app/models/widget.rb' - 'test/unit/associations_test.rb' -# Offense count: 1 -Style/NestedParenthesizedCalls: - Exclude: - - 'lib/paper_trail/has_paper_trail.rb' - # Offense count: 3 # Cop supports --auto-correct. Style/RescueModifier: diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index 80fd4d2e..2ba0e2ca 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -216,7 +216,7 @@ module PaperTrail # add a deprecation warning if someone tries to use it. def versions_between(start_time, end_time, _reify_options = {}) versions = send(self.class.versions_association_name).between(start_time, end_time) - versions.collect { |version| version_at(version.send PaperTrail.timestamp_field) } + versions.collect { |version| version_at(version.send(PaperTrail.timestamp_field)) } end # Returns the object (not a Version) as it was most recently. From 6fb88dd4ee81b211bbe1a0bf3134611eb3baa956 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 13 Mar 2016 19:58:36 -0400 Subject: [PATCH 3/9] Fix Style/LeadingCommentSpace --- .rubocop_todo.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 307e6381..5c92af1a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -101,12 +101,6 @@ Style/Lambda: - 'test/dummy/app/models/widget.rb' - 'test/unit/model_test.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/LeadingCommentSpace: - Exclude: - - 'test/unit/model_test.rb' - # Offense count: 6 # Cop supports --auto-correct. Style/LineEndConcatenation: From 18d74690c6fa042b9b90cc89a01a02ff9dd01ee2 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 13 Mar 2016 19:59:24 -0400 Subject: [PATCH 4/9] Fix Style/IndentationWidth --- .rubocop_todo.yml | 8 -------- lib/paper_trail/has_paper_trail.rb | 6 +++--- spec/models/widget_spec.rb | 6 +++--- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5c92af1a..9bbbc2b8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -84,14 +84,6 @@ Style/IfUnlessModifier: Style/IndentHash: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: Width. -Style/IndentationWidth: - Exclude: - - 'lib/paper_trail/has_paper_trail.rb' - - 'spec/models/widget_spec.rb' - # Offense count: 4 # Cop supports --auto-correct. Style/Lambda: diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index 2ba0e2ca..ce343619 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -459,9 +459,9 @@ module PaperTrail def set_transaction_id(version) return unless self.class.paper_trail_version_class.column_names.include?("transaction_id") if PaperTrail.transaction? && PaperTrail.transaction_id.nil? - PaperTrail.transaction_id = version.id - version.transaction_id = version.id - version.save + PaperTrail.transaction_id = version.id + version.transaction_id = version.id + version.save end end diff --git a/spec/models/widget_spec.rb b/spec/models/widget_spec.rb index c5d64da4..1a619755 100644 --- a/spec/models/widget_spec.rb +++ b/spec/models/widget_spec.rb @@ -15,9 +15,9 @@ describe Widget, type: :model do end it "is possible to do assertions on versions" do - expect(widget).to have_a_version_with name: "Leonard", an_integer: 1 - expect(widget).to have_a_version_with an_integer: 1 - expect(widget).to have_a_version_with name: "Tom" + expect(widget).to have_a_version_with name: "Leonard", an_integer: 1 + expect(widget).to have_a_version_with an_integer: 1 + expect(widget).to have_a_version_with name: "Tom" end end From df42beecab4e2bb87448e6ae8cd33a2d986ebb66 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 13 Mar 2016 20:00:15 -0400 Subject: [PATCH 5/9] Fix Style/IndentHash --- .rubocop_todo.yml | 7 ------- lib/paper_trail/has_paper_trail.rb | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9bbbc2b8..58621ec8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -77,13 +77,6 @@ Style/IfUnlessModifier: Exclude: - 'test/dummy/config/application.rb' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_braces -Style/IndentHash: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. Style/Lambda: diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index ce343619..23c79f6d 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -437,8 +437,8 @@ module PaperTrail return unless PaperTrail.config.track_associations? self.class.reflect_on_all_associations(:belongs_to).each do |assoc| assoc_version_args = { - version_id: version.id, - foreign_key_name: assoc.foreign_key + version_id: version.id, + foreign_key_name: assoc.foreign_key } if assoc.options[:polymorphic] From 4b3fbab08ae95862a92c40b25c515810c67331e8 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 13 Mar 2016 20:02:46 -0400 Subject: [PATCH 6/9] Fix Style/IfUnlessModifier --- .rubocop_todo.yml | 7 ------- test/dummy/config/application.rb | 4 +--- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 58621ec8..20116c8a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -70,13 +70,6 @@ Style/FirstParameterIndentation: Exclude: - 'lib/paper_trail/serializers/json.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: MaxLineLength. -Style/IfUnlessModifier: - Exclude: - - 'test/dummy/config/application.rb' - # Offense count: 4 # Cop supports --auto-correct. Style/Lambda: diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index af4e9469..c16ae612 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -54,9 +54,7 @@ module Dummy end # `config.assets` is a `NoMethodError` in rails 5. - if config.respond_to?(:assets) - config.assets.enabled = false - end + config.assets.enabled = false if config.respond_to?(:assets) # Version of your assets, change this if you want to expire all your assets # config.assets.version = '1.0' From 9ec7bb82afd4f2eaa9c3083bc90b7c50d9e0ed3b Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 13 Mar 2016 20:04:08 -0400 Subject: [PATCH 7/9] Fix Style/FirstParameterIndentation --- .rubocop_todo.yml | 8 -------- lib/paper_trail/serializers/json.rb | 3 +-- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 20116c8a..ecce77e7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -62,14 +62,6 @@ Style/ClassAndModuleChildren: Style/Documentation: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses -Style/FirstParameterIndentation: - Exclude: - - 'lib/paper_trail/serializers/json.rb' - # Offense count: 4 # Cop supports --auto-correct. Style/Lambda: diff --git a/lib/paper_trail/serializers/json.rb b/lib/paper_trail/serializers/json.rb index 77ba6724..1667800a 100644 --- a/lib/paper_trail/serializers/json.rb +++ b/lib/paper_trail/serializers/json.rb @@ -25,8 +25,7 @@ module PaperTrail # 123. if value.is_a? Numeric arel_field.matches("%\"#{field}\":#{json_value},%"). - or( - arel_field.matches("%\"#{field}\":#{json_value}}%")) + or(arel_field.matches("%\"#{field}\":#{json_value}}%")) else arel_field.matches("%\"#{field}\":#{json_value}%") end From 9143dc84344d5c3ca87b41f98c99385e6c870317 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 13 Mar 2016 20:22:55 -0400 Subject: [PATCH 8/9] Fix Style/Lambda --- .rubocop_todo.yml | 9 --------- lib/paper_trail/has_paper_trail.rb | 2 +- lib/paper_trail/version_concern.rb | 2 +- test/dummy/app/models/widget.rb | 2 +- test/unit/model_test.rb | 2 +- 5 files changed, 4 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ecce77e7..b4950ab3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -62,15 +62,6 @@ Style/ClassAndModuleChildren: Style/Documentation: Enabled: false -# Offense count: 4 -# Cop supports --auto-correct. -Style/Lambda: - Exclude: - - 'lib/paper_trail/has_paper_trail.rb' - - 'lib/paper_trail/version_concern.rb' - - 'test/dummy/app/models/widget.rb' - - 'test/unit/model_test.rb' - # Offense count: 6 # Cop supports --auto-correct. Style/LineEndConcatenation: diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index 23c79f6d..d9d90a9e 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -93,7 +93,7 @@ module PaperTrail # `has_many` syntax for specifying order uses a lambda in Rails 4 if ::ActiveRecord::VERSION::MAJOR >= 4 has_many versions_association_name, - lambda { order(model.timestamp_sort_order) }, + -> { order(model.timestamp_sort_order) }, class_name: version_class_name, as: :item else has_many versions_association_name, diff --git a/lib/paper_trail/version_concern.rb b/lib/paper_trail/version_concern.rb index a49b9e06..2640115f 100644 --- a/lib/paper_trail/version_concern.rb +++ b/lib/paper_trail/version_concern.rb @@ -32,7 +32,7 @@ module PaperTrail after_create :enforce_version_limit! - scope :within_transaction, lambda { |id| where transaction_id: id } + scope :within_transaction, ->(id) { where transaction_id: id } end module ClassMethods diff --git a/test/dummy/app/models/widget.rb b/test/dummy/app/models/widget.rb index c4c25b92..2516cbb4 100644 --- a/test/dummy/app/models/widget.rb +++ b/test/dummy/app/models/widget.rb @@ -9,7 +9,7 @@ class Widget < ActiveRecord::Base # `has_many` syntax for specifying order uses a lambda in Rails 4 if ::ActiveRecord::VERSION::MAJOR >= 4 - has_many :fluxors, lambda { order(:name) } + has_many :fluxors, -> { order(:name) } else has_many :fluxors, order: :name end diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index ff4bc7c4..f43719b8 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -698,7 +698,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase # In rails 5, `capture` is deprecated in favor of `capture_io`. # should "not generate warning" do - assert_update_raises_nothing = -> { + assert_update_raises_nothing = lambda { assert_nothing_raised { @wotsit.update_attributes! name: "changed" } From f09f49aa5c2bbf477236acbc36d54ffcc9682f2f Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 13 Mar 2016 20:24:04 -0400 Subject: [PATCH 9/9] Fix Style/LineEndConcatenation --- .rubocop_todo.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b4950ab3..afec321c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -62,15 +62,6 @@ Style/ClassAndModuleChildren: Style/Documentation: Enabled: false -# Offense count: 6 -# Cop supports --auto-correct. -Style/LineEndConcatenation: - Exclude: - - 'lib/generators/paper_trail/install_generator.rb' - - 'lib/paper_trail.rb' - - 'lib/paper_trail/config.rb' - - 'lib/paper_trail/has_paper_trail.rb' - # Offense count: 2 Style/ModuleFunction: Exclude: