Skip to content

Commit

Permalink
Merge pull request #111 from Shopify/activesupport-7.2
Browse files Browse the repository at this point in the history
Fix support for ActiveSupport 7.2 without Rails
  • Loading branch information
etiennebarrie authored Aug 23, 2024
2 parents b69aa43 + 6bd37cf commit 3324600
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ jobs:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }} / ${{ matrix.gemfile }}
strategy:
fail-fast: false
matrix:
gemfile:
- Gemfile
- gemfiles/activesupport_6.1.gemfile
- gemfiles/activesupport_7.0.gemfile
- gemfiles/activesupport_7.1.gemfile
- gemfiles/activesupport_7.2.gemfile
- gemfiles/activesupport_edge.gemfile
ruby: ["3.0", "3.1", "3.2", "3.3"]
exclude:
- gemfile: gemfiles/activesupport_7.2.gemfile
ruby: "3.0"
- gemfile: gemfiles/activesupport_edge.gemfile
ruby: "3.0"
env:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ It's possible to record deprecations while running your specs by adding an ENV['
DEPRECATION_BEHAVIOR="record" bundle exec rspec path/to/file_spec.rb
```

## Usage without Rails

Without Rails, you'll need to make sure your `ActiveSupport::Deprecation` instances use the [`:notify` behavior](https://api.rubyonrails.org/classes/ActiveSupport/Deprecation/Behavior.html#method-i-behavior-3D).

## License

Deprecation Toolkit is licensed under the [MIT license](LICENSE.txt).
5 changes: 5 additions & 0 deletions gemfiles/activesupport_7.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

@activesupport_gem_requirement = "~> 7.2.0"

eval_gemfile "../Gemfile"
2 changes: 1 addition & 1 deletion lib/deprecation_toolkit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def attach_subscriber
def each_deprecator(&block)
if defined?(Rails.application) && Rails.application.respond_to?(:deprecators)
Rails.application.deprecators.each(&block)
else
elsif ActiveSupport::Deprecation.respond_to?(:behavior)
block.call(ActiveSupport::Deprecation)
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/deprecation_toolkit/behaviors/raise_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class RaiseTest < ActiveSupport::TestCase
end

teardown do
# ensure we don't get warnings for missing assertions
pass # we have assertions in trigger_deprecation_toolkit_behavior
Configuration.behavior = @previous_configuration
end

Expand Down
10 changes: 10 additions & 0 deletions test/minitest/deprecation_toolkit_plugin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ def deprecators
end
end

if ActiveSupport.gem_version >= Gem::Version.new("7.2.0")
test ".plugin_deprecation_toolkit_init doesn't try to set behavior on ActiveSupport::Deprecation if Rails isn't defined" do
stub_const(Object, :Rails, Object.new) do
assert_nothing_raised do
Minitest.plugin_deprecation_toolkit_init({})
end
end
end
end

test ".plugin_deprecation_toolkit_init add `notify` behavior to the deprecations behavior list with Rails.application.deprecators" do
behavior = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:notify]

Expand Down

0 comments on commit 3324600

Please sign in to comment.