Skip to content

Commit

Permalink
Require Active Support as is intended
Browse files Browse the repository at this point in the history
> In order to have the smallest default footprint possible, Active Support loads the minimum dependencies by default. It is broken in small pieces so that only the desired extensions can be loaded.

https://guides.rubyonrails.org/active_support_core_extensions.html#stand-alone-active-support

This was changed in Rails 3, released 2010-08-29.

- We're not using anything from `core_ext/module/introspection`
- We're not using blank or present from `core_ext/object/blank`
- We're not using `autoload`
  • Loading branch information
Burgestrand committed Oct 11, 2024
1 parent e296e83 commit c00d2e7
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Changed

- Explicitly require less of `active_support` (#837)

## 2.4.0 (2024-08-26)

## Changed
Expand Down
7 changes: 2 additions & 5 deletions lib/pundit.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 3 additions & 0 deletions lib/pundit/policy_finder.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/pundit/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

# Array#to_sentence
require "active_support/core_ext/array/conversions"

module Pundit
module RSpec
module Matchers
Expand Down
7 changes: 3 additions & 4 deletions pundit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions spec/authorization_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 0 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions spec/support/models/customer/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c00d2e7

Please sign in to comment.