Skip to content

Commit

Permalink
Fix error with implicit decanter derivation via ActiveRecord class na…
Browse files Browse the repository at this point in the history
…me (#117)

* Add spec and fix for dynamically generating decanter names from an AR class

* Bump patch

* Add rails version to comment
  • Loading branch information
chawes13 authored Jan 5, 2021
1 parent 88af7fe commit 2f18945
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
decanter (3.4.1)
decanter (3.4.2)
actionpack (>= 4.2.10)
activesupport
rails-html-sanitizer (>= 1.0.4)
Expand Down
4 changes: 2 additions & 2 deletions lib/decanter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def decanter_for(klass_or_sym)
klass_or_sym.to_s.singularize.camelize
else
raise ArgumentError.new("cannot lookup decanter for #{klass_or_sym} with class #{klass_or_sym.class}")
end.concat('Decanter')
end + 'Decanter'
begin
decanter_name.constantize
rescue
Expand Down Expand Up @@ -62,4 +62,4 @@ def config
require 'decanter/extensions'
require 'decanter/exceptions'
require 'decanter/parser'
require 'decanter/railtie' if defined?(::Rails)
require 'decanter/railtie' if defined?(::Rails)
2 changes: 1 addition & 1 deletion lib/decanter/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Decanter
VERSION = '3.4.1'.freeze
VERSION = '3.4.2'.freeze
end
15 changes: 14 additions & 1 deletion spec/decanter/decanter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def self.name
end

context 'for a class' do

context 'when a corresponding decanter does not exist' do

let(:foo) do
Expand Down Expand Up @@ -132,6 +131,20 @@ def self.name
it 'returns the decanter' do
expect(Decanter::decanter_for(foo)).to eq FooDecanter
end

context 'and the class name is a frozen string' do
let(:foo) {
Class.new do
def self.name
'Foo'.freeze # ActiveRecord classes might have a frozen name (Rails 5.2.3)
end
end
}

it 'returns the decanter' do
expect(Decanter::decanter_for(foo)).to eq FooDecanter
end
end
end
end

Expand Down

0 comments on commit 2f18945

Please sign in to comment.