-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass adapter options through calls to render.
- Loading branch information
Showing
5 changed files
with
108 additions
and
4 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
97 changes: 97 additions & 0 deletions
97
spec/grape/active_model_serializers/options_builder_spec.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
require 'spec_helper' | ||
|
||
describe Grape::ActiveModelSerializers::OptionsBuilder do | ||
let(:resolver) { described_class.new(resource, env) } | ||
let(:resource) { User.new } | ||
let(:env) { { 'api.endpoint' => UsersApi.endpoints.first } } | ||
|
||
context '#options' do | ||
let(:options) { resolver.options } | ||
|
||
context 'meta options' do | ||
let(:env) { super().merge('ams_meta' => meta_options) } | ||
let(:meta_options) { | ||
{ | ||
meta: meta, | ||
meta_key: meta_key | ||
} | ||
} | ||
let(:meta) { { sample: 'metadata' } } | ||
let(:meta_key) { 'specified_key' } | ||
|
||
context 'meta option set' do | ||
context 'meta_key set' do | ||
it 'includes meta' do | ||
expect(options[:meta]).to eq(meta) | ||
end | ||
|
||
it 'includes meta_key' do | ||
expect(options[:meta_key]).to eq(meta_key) | ||
end | ||
end | ||
|
||
context 'meta_key unset' do | ||
let(:meta_key) { nil } | ||
|
||
it 'includes meta' do | ||
expect(options[:meta]).to eq(meta) | ||
end | ||
|
||
it 'defaults meta_key to meta' do | ||
expect(options[:meta_key]).to eq('meta') | ||
end | ||
end | ||
end | ||
|
||
context 'meta option unset' do | ||
let(:meta) { nil } | ||
|
||
context 'meta_key set' do | ||
it 'does not include meta' do | ||
expect(options.keys).not_to include(:meta) | ||
end | ||
|
||
it 'does not include meta_key' do | ||
expect(options.keys).not_to include(:meta_key) | ||
end | ||
end | ||
|
||
context 'meta_key unset' do | ||
let(:meta_key) { nil } | ||
|
||
it 'does not include meta' do | ||
expect(options.keys).not_to include(:meta) | ||
end | ||
|
||
it 'does not include meta_key' do | ||
expect(options.keys).not_to include(:meta_key) | ||
end | ||
end | ||
end | ||
end | ||
|
||
context 'adapter options' do | ||
let(:env) { super().merge('ams_adapter_options' => adapter_options) } | ||
let(:adapter_options) { {} } | ||
|
||
context 'adapter' do | ||
let(:adapter_options) { { adapter: adapter } } | ||
let(:adapter) { :attributes } | ||
|
||
it 'includes adapter as top-level option' do | ||
expect(options[:adapter]).to eq(adapter) | ||
end | ||
end | ||
|
||
context 'serializer' do | ||
let(:adapter_options) { { serializer: serializer } } | ||
let(:serializer) { V2::UserSerializer } | ||
|
||
it 'includes serializer as top-level option' do | ||
expect(options[:serializer]).to eq(serializer) | ||
end | ||
end | ||
end | ||
end | ||
|
||
end |
1 change: 0 additions & 1 deletion
1
spec/grape/active_model_serializers/serializer_resolver_spec.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require 'pry' | ||
require 'spec_helper' | ||
|
||
# asserts serializer resolution order: | ||
|