diff --git a/CHANGELOG.md b/CHANGELOG.md index b16cddbc..67faf03b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Changed + +- Explicitly require less of `active_support` (#837) + ## 2.4.0 (2024-08-26) ## Changed diff --git a/lib/pundit.rb b/lib/pundit.rb index a7263b39..0bb9e88c 100644 --- a/lib/pundit.rb +++ b/lib/pundit.rb @@ -1,12 +1,9 @@ # frozen_string_literal: true +require "active_support" + require "pundit/version" require "pundit/policy_finder" -require "active_support/concern" -require "active_support/core_ext/string/inflections" -require "active_support/core_ext/object/blank" -require "active_support/core_ext/module/introspection" -require "active_support/dependencies/autoload" require "pundit/authorization" require "pundit/context" require "pundit/cache_store/null_store" diff --git a/lib/pundit/policy_finder.rb b/lib/pundit/policy_finder.rb index ecc6e9bb..a2150080 100644 --- a/lib/pundit/policy_finder.rb +++ b/lib/pundit/policy_finder.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +# String#safe_constantize, String#demodulize, String#underscore, String#camelize +require "active_support/core_ext/string/inflections" + module Pundit # Finds policy and scope classes for given object. # @api public diff --git a/lib/pundit/rspec.rb b/lib/pundit/rspec.rb index fb44ba60..cafc5913 100644 --- a/lib/pundit/rspec.rb +++ b/lib/pundit/rspec.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +# Array#to_sentence +require "active_support/core_ext/array/conversions" + module Pundit module RSpec module Matchers diff --git a/pundit.gemspec b/pundit.gemspec index 18a97bf7..a5b54b0f 100644 --- a/pundit.gemspec +++ b/pundit.gemspec @@ -22,11 +22,10 @@ Gem::Specification.new do |gem| gem.metadata = { "rubygems_mfa_required" => "true" } gem.add_dependency "activesupport", ">= 3.0.0" - gem.add_development_dependency "actionpack", ">= 3.0.0" - gem.add_development_dependency "activemodel", ">= 3.0.0" + gem.add_development_dependency "actionpack", ">= 3.0.0" # Used to test strong parameters. + gem.add_development_dependency "activemodel", ">= 3.0.0" # Used to test ActiveModel::Naming. gem.add_development_dependency "bundler" - gem.add_development_dependency "pry" - gem.add_development_dependency "railties", ">= 3.0.0" + gem.add_development_dependency "railties", ">= 3.0.0" # Used to test generators. gem.add_development_dependency "rake" gem.add_development_dependency "rspec", ">= 3.0.0" gem.add_development_dependency "rubocop" diff --git a/spec/authorization_spec.rb b/spec/authorization_spec.rb index 8bfa3fcb..ca291f9a 100644 --- a/spec/authorization_spec.rb +++ b/spec/authorization_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "spec_helper" +require "action_controller/metal/strong_parameters" describe Pundit::Authorization do def to_params(*args, **kwargs, &block) @@ -157,7 +158,7 @@ def to_params(*args, **kwargs, &block) end it "allows policy to be injected" do - new_policy = OpenStruct.new + new_policy = double controller.policies[post] = new_policy expect(controller.policy(post)).to eq new_policy @@ -182,7 +183,7 @@ def to_params(*args, **kwargs, &block) end it "allows policy_scope to be injected" do - new_scope = OpenStruct.new + new_scope = double controller.policy_scopes[Post] = new_scope expect(controller.policy_scope(Post)).to eq new_scope diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6d63c514..4b932571 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,14 +20,7 @@ require "pundit" require "pundit/rspec" - -require "rack" -require "rack/test" -require "pry" -require "active_support" -require "active_support/core_ext" require "active_model/naming" -require "action_controller/metal/strong_parameters" # Load all supporting files: models, policies, etc. require "zeitwerk" diff --git a/spec/support/models/customer/post.rb b/spec/support/models/customer/post.rb index 0b08c654..3562e127 100644 --- a/spec/support/models/customer/post.rb +++ b/spec/support/models/customer/post.rb @@ -2,9 +2,7 @@ module Customer class Post < ::Post - def model_name - OpenStruct.new(param_key: "customer_post") - end + extend ActiveModel::Naming def self.policy_class PostPolicy