Skip to content

Commit

Permalink
Use camelize instead of classify to safe_constantize (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmallen committed Feb 10, 2020
1 parent 72b8a00 commit 76036ba
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning].

## [Unreleased]

### Fixed

- [\#168](https://github.com/aaronmallen/activeinteractor/issues/168) `#classify` is called on const arguments

## [v1.0.2] - 2020-02-04

### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/active_interactor/context/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Loader
# @param interactor_class [Const] an {ActiveInteractor::Base interactor} class
# @return [Const] a class that inherits from {Base}
def self.create(context_class_name, interactor_class)
interactor_class.const_set(context_class_name.to_s.classify, Class.new(BASE_CONTEXT))
interactor_class.const_set(context_class_name.to_s.camelize, Class.new(BASE_CONTEXT))
end

# Find or create a {Base context} class for a given {ActiveInteractor::Base interactor}. If a class exists
Expand Down
2 changes: 1 addition & 1 deletion lib/active_interactor/interactor/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def context_class
# @return [Const] the {Base interactor} class' {ActiveInteractor::Context::Base context} class
def contextualize_with(klass)
@context_class = begin
context_class = klass.to_s.classify.safe_constantize
context_class = klass.to_s.camelize.safe_constantize
raise(ActiveInteractor::Error::InvalidContextClass, klass) unless context_class

context_class
Expand Down
2 changes: 1 addition & 1 deletion lib/active_interactor/organizer/interactor_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class InteractorInterface
# {Interactor::Perform::ClassMethods#perform .perform}. See {Interactor::Perform::Options}.
# @return [InteractorInterface] a new instance of {InteractorInterface}
def initialize(interactor_class, options = {})
@interactor_class = interactor_class.to_s.classify.safe_constantize
@interactor_class = interactor_class.to_s.camelize.safe_constantize
@filters = options.select { |key, _value| CONDITIONAL_FILTERS.include?(key) }
@perform_options = options.reject { |key, _value| CONDITIONAL_FILTERS.include?(key) }
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rails/generators/templates/organizer.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class <%= class_name %> < ApplicationOrganizer
<%- end -%>
<%- if interactors.any? -%>
organize <%= interactors.map(&:classify).join(", ") %>
organize <%= interactors.join(", ") %>
<%- else -%>
# organize Interactor1, Interactor2
# organize :interactor_1, :interactor_2
<%- end -%>
end
33 changes: 33 additions & 0 deletions spec/active_interactor/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
subject
expect(described_class.context_class).to eq TestContext
end

# https://github.com/aaronmallen/activeinteractor/issues/168
context 'when singularized' do
let!(:singularized_class) { build_context('PlaceData') }
let(:klass) { 'PlaceData' }

it 'is expected to assign the appropriate context class' do
subject
expect(described_class.context_class).to eq PlaceData
end
end
end

context 'when passed as a symbol' do
Expand All @@ -36,6 +47,17 @@
subject
expect(described_class.context_class).to eq TestContext
end

# https://github.com/aaronmallen/activeinteractor/issues/168
context 'when singularized' do
let!(:singularized_class) { build_context('PlaceData') }
let(:klass) { :place_data }

it 'is expected to assign the appropriate context class' do
subject
expect(described_class.context_class).to eq PlaceData
end
end
end

context 'when passed as a constant' do
Expand All @@ -45,6 +67,17 @@
subject
expect(described_class.context_class).to eq TestContext
end

# https://github.com/aaronmallen/activeinteractor/issues/168
context 'when singularized' do
let!(:singularized_class) { build_context('PlaceData') }
let(:klass) { PlaceData }

it 'is expected to assign the appropriate context class' do
subject
expect(described_class.context_class).to eq PlaceData
end
end
end
end
end
Expand Down

0 comments on commit 76036ba

Please sign in to comment.