From 9691355fca4b20978543d7832e1eeebcf59df7ae Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Fri, 17 Mar 2017 17:31:58 +0100 Subject: [PATCH] Travis build change: Fix build, use latest JRuby - Lint only 1 time, on modern Ruby --- .rubocop.yml | 13 +++++++++++-- .rubocop_todo.yml | 13 +++++++++++++ .travis.yml | 28 ++++++++++++++++++---------- Gemfile | 14 +++++++++++++- Rakefile | 1 - lib/pundit/rspec.rb | 1 + pundit.gemspec | 8 -------- spec/pundit_spec.rb | 15 +++++++++++---- 8 files changed, 67 insertions(+), 26 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 24abed3..73e92be 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,14 +1,23 @@ +inherit_from: .rubocop_todo.yml AllCops: + DisplayCopNames: true + TargetRubyVersion: 1.9 Exclude: - "gemfiles/**/*" - "vendor/**/*" - "lib/generators/**/*" +Metrics/BlockLength: + Exclude: + - "**/*_spec.rb" + Metrics/MethodLength: Max: 40 Metrics/ModuleLength: Max: 200 + Exclude: + - "**/*_spec.rb" Metrics/LineLength: Max: 120 @@ -50,7 +59,7 @@ Documentation: Enabled: false # TODO: Enable again once we have more docs Style/CaseIndentation: - IndentWhenRelativeTo: case + EnforcedStyle: case SupportedStyles: - case - end @@ -74,7 +83,7 @@ Style/TrivialAccessors: ExactNameMatch: true Lint/EndAlignment: - AlignWith: variable + EnforcedStyleAlignWith: variable Lint/DefEndAlignment: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..ba3be04 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,13 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2016-12-06 09:57:39 +0100 using RuboCop version 0.41.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/UnneededDisable: + Exclude: + - 'lib/pundit/rspec.rb' diff --git a/.travis.yml b/.travis.yml index aa0ea19..44a1528 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,20 @@ language: ruby sudo: false -rvm: - - 2.0.0 - - 2.1 - - 2.2 - - 2.3.0 - - jruby-19mode - - rbx-2 -env: - - RSPEC_VERSION="<2.99" - - RSPEC_VERSION="~>3.0 +before_install: + - gem update --system + - gem install bundler + +matrix: + include: + - rvm: 2.4.0 + script: bundle exec rake rubocop # ONLY lint once, first + - rvm: 2.1 + - rvm: 2.2 + - rvm: 2.3.3 + - rvm: 2.4.0 + - rvm: jruby-1.7.26 + env: + - JRUBY_OPTS="--debug" + - rvm: jruby-9.1.8.0 + env: + - JRUBY_OPTS="--debug" diff --git a/Gemfile b/Gemfile index 29805b6..e10b28d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,16 @@ source "https://rubygems.org" -gem "rspec", ENV["RSPEC_VERSION"] unless ENV["RSPEC_VERSION"].to_s.empty? +ruby RUBY_VERSION + gemspec + +group :development, :test do + gem "actionpack" + gem "activemodel" + gem "bundler" + gem "pry" + gem "rake" + gem "rspec" + gem "rubocop" + gem "yard" +end diff --git a/Rakefile b/Rakefile index 02430fb..0710298 100644 --- a/Rakefile +++ b/Rakefile @@ -16,4 +16,3 @@ YARD::Rake::YardocTask.new do |t| end task default: :spec -task default: :rubocop unless RUBY_ENGINE == "rbx" diff --git a/lib/pundit/rspec.rb b/lib/pundit/rspec.rb index bec6c8c..a310230 100644 --- a/lib/pundit/rspec.rb +++ b/lib/pundit/rspec.rb @@ -5,6 +5,7 @@ module Pundit module Matchers extend ::RSpec::Matchers::DSL + # rubocop:disable Metrics/BlockLength matcher :permit do |user, record| match_proc = lambda do |policy| @violating_permissions = permissions.find_all do |permission| diff --git a/pundit.gemspec b/pundit.gemspec index f9bf154..aac0fee 100644 --- a/pundit.gemspec +++ b/pundit.gemspec @@ -19,12 +19,4 @@ Gem::Specification.new do |gem| gem.require_paths = ["lib"] gem.add_dependency "activesupport", ">= 3.0.0" - gem.add_development_dependency "activemodel", ">= 3.0.0" - gem.add_development_dependency "actionpack", ">= 3.0.0" - gem.add_development_dependency "bundler", "~> 1.3" - gem.add_development_dependency "rspec", ">=2.0.0" - gem.add_development_dependency "pry" - gem.add_development_dependency "rake" - gem.add_development_dependency "yard" - gem.add_development_dependency "rubocop" end diff --git a/spec/pundit_spec.rb b/spec/pundit_spec.rb index 0b752ad..ad63d90 100644 --- a/spec/pundit_spec.rb +++ b/spec/pundit_spec.rb @@ -431,8 +431,8 @@ describe Pundit do admin: true }) - expect(Controller.new(user, params).permitted_attributes(post)).to eq("title" => "Hello", "votes" => 5) - expect(Controller.new(double, params).permitted_attributes(post)).to eq("votes" => 5) + expect(Controller.new(user, params).permitted_attributes(post).to_h).to eq("title" => "Hello", "votes" => 5) + expect(Controller.new(double, params).permitted_attributes(post).to_h).to eq("votes" => 5) end it "checks policy for permitted attributes for record of a ActiveModel type" do @@ -444,6 +444,13 @@ describe Pundit do expect(Controller.new(user, params).permitted_attributes(customer_post)).to eq("title" => "Hello", "votes" => 5) expect(Controller.new(double, params).permitted_attributes(customer_post)).to eq("votes" => 5) + expect(Controller.new(user, params).permitted_attributes(customer_post).to_h).to eq( + "title" => "Hello", + "votes" => 5 + ) + expect(Controller.new(double, params).permitted_attributes(customer_post).to_h).to eq( + "votes" => 5 + ) end end @@ -456,7 +463,7 @@ describe Pundit do admin: true }) - expect(Controller.new(user, params).permitted_attributes(post)).to eq("body" => "blah") + expect(Controller.new(user, params).permitted_attributes(post).to_h).to eq("body" => "blah") end it "can be explicitly set" do @@ -467,7 +474,7 @@ describe Pundit do admin: true }) - expect(Controller.new(user, params).permitted_attributes(post, :revise)).to eq("body" => "blah") + expect(Controller.new(user, params).permitted_attributes(post, :revise).to_h).to eq("body" => "blah") end end