Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize the active_support requires #837

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Changed

- Deprecated `Pundit::SUFFIX`, moved it to `Pundit::PolicyFinder::SUFFIX` (#835)
- Explicitly require less of `active_support` (#837)

## 2.4.0 (2024-08-26)

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
Loading