Skip to content

Commit

Permalink
Follow up to rails-api#1535
Browse files Browse the repository at this point in the history
- One test was renamed because it contained `__`
- The ActiveModelSerializers::Deserialization module now call Adater
  instead of ActiveModelSerializers::Adapter.
- The changelog was added for rails-api#1535
  • Loading branch information
Yohan Robert committed Feb 28, 2016
1 parent 8a04005 commit c54adab
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 48 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 0.10.x

Breaking changes:
- [#1535](https://github.com/rails-api/active_model_serializers/pull/1535) Moved the adapter and adapter folder to
active_model_serializers folder and changed the module namespace. (@domitian @bf4)

Features:
- [#1515](https://github.com/rails-api/active_model_serializers/pull/1515) Adds support for symbols to the
Expand Down
4 changes: 2 additions & 2 deletions lib/active_model_serializers/deserialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module Deserialization
module_function

def jsonapi_parse(*args)
ActiveModelSerializers::Adapter::JsonApi::Deserialization.parse(*args)
Adapter::JsonApi::Deserialization.parse(*args)
end

def jsonapi_parse!(*args)
ActiveModelSerializers::Adapter::JsonApi::Deserialization.parse!(*args)
Adapter::JsonApi::Deserialization.parse!(*args)
end
end
end
95 changes: 49 additions & 46 deletions test/active_model_serializers/adapter_for_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,88 +2,82 @@ module ActiveModelSerializers
class AdapterForTest < ActiveSupport::TestCase
UnknownAdapterError = ::ActiveModelSerializers::Adapter::UnknownAdapterError

def setup
@previous_adapter = ActiveModelSerializers.config.adapter
end

def teardown
ActiveModelSerializers.config.adapter = @previous_adapter
end

def test_serializer_adapter_returns_configured__adapter
def test_serializer_adapter_returns_configured_adapter
assert_output(nil, /ActiveModelSerializers::configured_adapter/) do
assert_equal ActiveModelSerializers::Adapter.configured_adapter, ActiveModel::Serializer.adapter
end
end

def test_returns_default_adapter
adapter = ActiveModelSerializers::Adapter.configured_adapter
assert_equal ActiveModelSerializers::Adapter::Attributes, adapter
with_adapter_config_setup do
adapter = ActiveModelSerializers::Adapter.configured_adapter
assert_equal ActiveModelSerializers::Adapter::Attributes, adapter
end
end

def test_overwrite_adapter_with_symbol
ActiveModelSerializers.config.adapter = :null
with_adapter_config_setup do
ActiveModelSerializers.config.adapter = :null

adapter = ActiveModelSerializers::Adapter.configured_adapter
assert_equal ActiveModelSerializers::Adapter::Null, adapter
ensure
ActiveModelSerializers.config.adapter = @previous_adapter
adapter = ActiveModelSerializers::Adapter.configured_adapter
assert_equal ActiveModelSerializers::Adapter::Null, adapter
end
end

def test_overwrite_adapter_with_camelcased_symbol
ActiveModelSerializers.config.adapter = :JsonApi
with_adapter_config_setup do
ActiveModelSerializers.config.adapter = :JsonApi

adapter = ActiveModelSerializers::Adapter.configured_adapter
assert_equal ActiveModelSerializers::Adapter::JsonApi, adapter
ensure
ActiveModelSerializers.config.adapter = @previous_adapter
adapter = ActiveModelSerializers::Adapter.configured_adapter
assert_equal ActiveModelSerializers::Adapter::JsonApi, adapter
end
end

def test_overwrite_adapter_with_string
ActiveModelSerializers.config.adapter = 'json_api'
with_adapter_config_setup do
ActiveModelSerializers.config.adapter = 'json_api'

adapter = ActiveModelSerializers::Adapter.configured_adapter
assert_equal ActiveModelSerializers::Adapter::JsonApi, adapter
ensure
ActiveModelSerializers.config.adapter = @previous_adapter
adapter = ActiveModelSerializers::Adapter.configured_adapter
assert_equal ActiveModelSerializers::Adapter::JsonApi, adapter
end
end

def test_overwrite_adapter_with_a_camelcased_string
ActiveModelSerializers.config.adapter = 'JsonApi'
with_adapter_config_setup do
ActiveModelSerializers.config.adapter = 'JsonApi'

adapter = ActiveModelSerializers::Adapter.configured_adapter
assert_equal ActiveModelSerializers::Adapter::JsonApi, adapter
ensure
ActiveModelSerializers.config.adapter = @previous_adapter
adapter = ActiveModelSerializers::Adapter.configured_adapter
assert_equal ActiveModelSerializers::Adapter::JsonApi, adapter
end
end

def test_overwrite_adapter_with_class
ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::Null
with_adapter_config_setup do
ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::Null

adapter = ActiveModelSerializers::Adapter.configured_adapter
assert_equal ActiveModelSerializers::Adapter::Null, adapter
ensure
ActiveModelSerializers.config.adapter = @previous_adapter
adapter = ActiveModelSerializers::Adapter.configured_adapter
assert_equal ActiveModelSerializers::Adapter::Null, adapter
end
end

def test_raises_exception_if_invalid_symbol_given
ActiveModelSerializers.config.adapter = :unknown
with_adapter_config_setup do
ActiveModelSerializers.config.adapter = :unknown

assert_raises UnknownAdapterError do
ActiveModelSerializers::Adapter.configured_adapter
assert_raises UnknownAdapterError do
ActiveModelSerializers::Adapter.configured_adapter
end
end
ensure
ActiveModelSerializers.config.adapter = @previous_adapter
end

def test_raises_exception_if_it_does_not_know_hot_to_infer_adapter
ActiveModelSerializers.config.adapter = 42
with_adapter_config_setup do
ActiveModelSerializers.config.adapter = 42

assert_raises UnknownAdapterError do
ActiveModelSerializers::Adapter.configured_adapter
assert_raises UnknownAdapterError do
ActiveModelSerializers::Adapter.configured_adapter
end
end
ensure
ActiveModelSerializers.config.adapter = @previous_adapter
end

def test_adapter_class_for_known_adapter
Expand Down Expand Up @@ -199,5 +193,14 @@ def test_inherited_adapter_hooks_register_subclass_of_registered_adapter
Object.send(:remove_const, :MyAdapter)
Object.send(:remove_const, :MySubclassedAdapter)
end

private

def with_adapter_config_setup
previous_adapter = ActiveModelSerializers.config.adapter
yield
ensure
ActiveModelSerializers.config.adapter = previous_adapter
end
end
end

0 comments on commit c54adab

Please sign in to comment.