mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Merge pull request #373 from phoet/patch-1
some remarks on testing in the readme
This commit is contained in:
commit
db086794c6
28
README.md
28
README.md
@ -686,6 +686,34 @@ for the current user, the advantage of this approach is that, by setting
|
|||||||
`serialization_scope` to `nil`, the `index` action no longer will need to make
|
`serialization_scope` to `nil`, the `index` action no longer will need to make
|
||||||
that query, only the `show` action will.
|
that query, only the `show` action will.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
In order to test a Serializer, you can just call `.new` on it, passing the object to serialize:
|
||||||
|
|
||||||
|
### MiniTest
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
class TestPostSerializer < Minitest::Test
|
||||||
|
def setup
|
||||||
|
@serializer = PostSerializer.new Post.new(id: 123, title: 'some title', body: 'some text')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_special_json_for_api
|
||||||
|
assert_equal '{"post":{"id":123,"title":"some title","body":"some text"}}', @serializer.to_json
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
### RSpec
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
describe PostSerializer do
|
||||||
|
it "creates special JSON for the API" do
|
||||||
|
serializer = PostSerializer.new Post.new(id: 123, title: 'some title', body: 'some text')
|
||||||
|
expect(serializer.to_json).to eql('{"post":{"id":123,"title":"some title","body":"some text"}}')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
## Caching
|
## Caching
|
||||||
|
|
||||||
NOTE: This functionality was removed from AMS and it's in the TODO list.
|
NOTE: This functionality was removed from AMS and it's in the TODO list.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user