mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
* Merge pull request #1990 from mxie/mx-result-typo Fix typos and capitalization in Relationship Links docs [ci skip] * Merge pull request #1992 from ojiry/bump_ruby_versions Run tests by Ruby 2.2.6 and 2.3.3 * Merge pull request #1994 from bf4/promote_architecture Promote important architecture description that answers a lot of questions we get Conflicts: docs/ARCHITECTURE.md * Merge pull request #1999 from bf4/typos Fix typos [ci skip] * Merge pull request #2000 from berfarah/patch-1 Link to 0.10.3 tag instead of `master` branch * Merge pull request #2007 from bf4/check_ci Test was failing due to change in JSON exception message when parsing empty string * Swap out KeyTransform for CaseTransform (#1993) * delete KeyTransform, use CaseTransform * added changelog Conflicts: CHANGELOG.md * Merge pull request #2005 from kofronpi/support-ruby-2.4 Update jsonapi runtime dependency to 0.1.1.beta6 * Bump to v0.10.4 * Merge pull request #2018 from rails-api/bump_version Bump to v0.10.4 [ci skip] Conflicts: CHANGELOG.md * Merge pull request #2019 from bf4/fix_method_redefined_warning Fix AMS warnings * Merge pull request #2020 from bf4/silence_grape_warnings Silence Grape warnings * Merge pull request #2017 from bf4/remove_warnings Fix mt6 assert_nil warnings * Updated isolated tests to assert correct behavior. (#2010) * Updated isolated tests to assert correct behavior. * Added check to get unsafe params if rails version is great than 5 * Merge pull request #2012 from bf4/cleanup_isolated_jsonapi_renderer_tests_a_bit Cleanup assertions in isolated jsonapi renderer tests a bit * Add Model#attributes helper; make test attributes explicit * Fix model attributes accessors * Fix typos * Randomize testing of compatibility layer against regressions * Test bugfix * Add CHANGELOG * Merge pull request #1981 from groyoh/link_doc Fix relationship links doc Conflicts: CHANGELOG.md
63 lines
1.9 KiB
Ruby
63 lines
1.9 KiB
Ruby
require 'test_helper'
|
|
|
|
module ActionController
|
|
module Serialization
|
|
class AdapterSelectorTest < ActionController::TestCase
|
|
class Profile < Model
|
|
attributes :id, :name, :description
|
|
associations :comments
|
|
end
|
|
class ProfileSerializer < ActiveModel::Serializer
|
|
type 'profiles'
|
|
attributes :name, :description
|
|
end
|
|
|
|
class AdapterSelectorTestController < 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(id: 'render_skipping_adapter_id', name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
|
render json: @profile, adapter: false
|
|
end
|
|
end
|
|
|
|
tests AdapterSelectorTestController
|
|
|
|
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
|
|
|
|
expected = {
|
|
data: {
|
|
id: @controller.instance_variable_get(:@profile).id.to_s,
|
|
type: 'profiles',
|
|
attributes: {
|
|
name: 'Name 1',
|
|
description: 'Description 1'
|
|
}
|
|
}
|
|
}
|
|
|
|
assert_equal expected.to_json, response.body
|
|
end
|
|
|
|
def test_render_skipping_adapter
|
|
get :render_skipping_adapter
|
|
assert_equal '{"id":"render_skipping_adapter_id","name":"Name 1","description":"Description 1"}', response.body
|
|
end
|
|
end
|
|
end
|
|
end
|