Skip to content

Commit

Permalink
Merge pull request #1006 from bf4/inflector-testing
Browse files Browse the repository at this point in the history
Fix adapter inflection bug for api -> API
  • Loading branch information
joaomdmoura committed Jul 21, 2015
2 parents 4c31142 + 4359026 commit 6266b6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/active_model/serializer/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def self.create(resource, options = {})
end

def self.adapter_class(adapter)
"ActiveModel::Serializer::Adapter::#{adapter.to_s.classify}".safe_constantize
adapter_name = adapter.to_s.classify.sub("API", "Api")
"ActiveModel::Serializer::Adapter::#{adapter_name}".safe_constantize
end

def fragment_cache(*args)
Expand All @@ -42,7 +43,7 @@ def fragment_cache(*args)

private

def cache_check(serializer)
def cache_check(serializer)
@cached_serializer = serializer
@klass = @cached_serializer.class
if is_cached?
Expand Down
9 changes: 9 additions & 0 deletions test/adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def test_create_adapter_with_override
adapter = ActiveModel::Serializer::Adapter.create(@serializer, { adapter: :json_api})
assert_equal ActiveModel::Serializer::Adapter::JsonApi, adapter.class
end

def test_inflected_adapter_class_for_known_adapter
ActiveSupport::Inflector.inflections(:en){|inflect| inflect.acronym 'API' }
klass = ActiveModel::Serializer::Adapter.adapter_class(:json_api)

ActiveSupport::Inflector.inflections.acronyms.clear

assert_equal ActiveModel::Serializer::Adapter::JsonApi, klass
end
end
end
end

0 comments on commit 6266b6a

Please sign in to comment.