diff --git a/Gemfile.lock b/Gemfile.lock index 111e59b..50c8ee4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/lib/decanter.rb b/lib/decanter.rb index d46610f..b189d72 100644 --- a/lib/decanter.rb +++ b/lib/decanter.rb @@ -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 @@ -62,4 +62,4 @@ def config require 'decanter/extensions' require 'decanter/exceptions' require 'decanter/parser' -require 'decanter/railtie' if defined?(::Rails) \ No newline at end of file +require 'decanter/railtie' if defined?(::Rails) diff --git a/lib/decanter/version.rb b/lib/decanter/version.rb index fe4c702..48e7177 100644 --- a/lib/decanter/version.rb +++ b/lib/decanter/version.rb @@ -1,3 +1,3 @@ module Decanter - VERSION = '3.4.1'.freeze + VERSION = '3.4.2'.freeze end diff --git a/spec/decanter/decanter_spec.rb b/spec/decanter/decanter_spec.rb index dd2f2d3..5e1532e 100644 --- a/spec/decanter/decanter_spec.rb +++ b/spec/decanter/decanter_spec.rb @@ -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 @@ -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