-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename NullAdapter to SimpleAdapter
* Introduce abstract Adapter class * Organaze test structure to match convemtions
- Loading branch information
Tema Bolshakov
committed
Aug 27, 2014
1 parent
0c13956
commit f00fe55
Showing
7 changed files
with
52 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module ActiveModel | ||
class Serializer | ||
class Adapter | ||
extend ActiveSupport::Autoload | ||
autoload :SimpleAdapter | ||
|
||
def initialize(serializer) | ||
@attributes = serializer.attributes | ||
end | ||
|
||
def serializable_hash(options = {}) | ||
raise NotImplementedError, 'This is abstract method. Should be implemented at concrete adapter.' | ||
end | ||
|
||
def to_json(options = {}) | ||
raise NotImplementedError, 'This is abstract method. Should be implemented at concrete adapter.' | ||
end | ||
end | ||
end | ||
end |
6 changes: 1 addition & 5 deletions
6
..._model/serializer/adapter/null_adapter.rb → ...odel/serializer/adapter/simple_adapter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'test_helper' | ||
|
||
module ActiveModel | ||
class Serializer | ||
class AdapterTest < Minitest::Test | ||
def setup | ||
profile = Profile.new | ||
serializer = ProfileSerializer.new(profile) | ||
@adapter = ActiveModel::Serializer::Adapter.new(serializer) | ||
end | ||
|
||
def test_serializable_hash_is_abstract_method | ||
assert_raises(NotImplementedError) do | ||
@adapter.serializable_hash(only: [:name]) | ||
end | ||
end | ||
|
||
def test_serializable_hash_is_abstract_method | ||
assert_raises(NotImplementedError) do | ||
@adapter.to_json(only: [:name]) | ||
end | ||
end | ||
end | ||
end | ||
end |