-
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.
Merge pull request #63 from ruby-grape/adapter-options
Pass adapter options through calls to render.
- Loading branch information
Showing
6 changed files
with
187 additions
and
9 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
129 changes: 129 additions & 0 deletions
129
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,129 @@ | ||
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 'does not include meta_key' do | ||
expect(options.keys).not_to include(:meta_key) | ||
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' => 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 | ||
|
||
context 'each_serializer' do | ||
let(:adapter_options) { { each_serializer: each_serializer } } | ||
let(:each_serializer) { V2::UserSerializer } | ||
|
||
it 'includes each_serializer as top-level option' do | ||
expect(options[:each_serializer]).to eq(each_serializer) | ||
end | ||
end | ||
end | ||
|
||
context 'extra options' do | ||
let(:env) { super().merge('ams_extra' => extra_options) } | ||
|
||
context 'hash' do | ||
let(:extra_options) { { extra: 'info' } } | ||
|
||
it 'includes extra options in top-level options' do | ||
expect(options.keys).to include(:extra) | ||
end | ||
end | ||
|
||
context 'not a hash' do | ||
let(:extra_options) { 'extra' } | ||
|
||
it 'raises an exception' do | ||
expect { | ||
options | ||
}.to raise_exception( | ||
'Extra options must be a hash' | ||
) | ||
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: | ||
|