-
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.
Allow overriding the adapter with render option
Make it easy to use multiple adapters in an app. use "adapter: false" to not use ams
- Loading branch information
Showing
8 changed files
with
100 additions
and
55 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
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,41 @@ | ||
require 'test_helper' | ||
|
||
module ActionController | ||
module Serialization | ||
class AdapterSelectorTest < ActionController::TestCase | ||
class MyController < ActionController::Base | ||
def render_using_default_adapter | ||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }) | ||
render json: @profile | ||
end | ||
|
||
def render_using_adapter_override | ||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }) | ||
render json: @profile, adapter: :json_api | ||
end | ||
|
||
def render_skipping_adapter | ||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }) | ||
render json: @profile, adapter: false | ||
end | ||
end | ||
|
||
tests MyController | ||
|
||
def test_render_using_default_adapter | ||
get :render_using_default_adapter | ||
assert_equal '{"name":"Name 1","description":"Description 1"}', response.body | ||
end | ||
|
||
def test_render_using_adapter_override | ||
get :render_using_adapter_override | ||
assert_equal '{"profiles":{"name":"Name 1","description":"Description 1"}}', response.body | ||
end | ||
|
||
def test_render_skipping_adapter | ||
get :render_skipping_adapter | ||
assert_equal '{"attributes":{"name":"Name 1","description":"Description 1","comments":"Comments 1"}}', response.body | ||
end | ||
end | ||
end | ||
end |
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