spec/praxis/extensions/field_expansion_spec.rb in praxis-2.0.pre.18 vs spec/praxis/extensions/field_expansion_spec.rb in praxis-2.0.pre.19
- old
+ new
@@ -1,11 +1,12 @@
+# frozen_string_literal: true
+
require 'spec_helper'
require 'praxis/extensions/field_selection'
describe Praxis::Extensions::FieldExpansion do
-
# include the ActionDefinitionExtension module directly, as that's where the
# bulk of lies, and by including this instead of the base FieldExpansion module
# we avoid the side-effect of injecting the ActionDefinitionExtension into
# the base Praxis::ActionDefinition.
let(:test_class) do
@@ -22,48 +23,45 @@
let(:test_instance) { test_class.new(test_params) }
let(:request_params) do
double('params',
- fields: Praxis::Extensions::FieldSelection::FieldSelector.for(Person).load(fields)
- )
+ fields: Praxis::Extensions::FieldSelection::FieldSelector.for(Person).load(fields))
end
let(:request) { double('Praxis::Request', params: request_params) }
let(:media_type) { Person }
let(:fields) { nil }
- let(:test_attributes) { }
+ let(:test_attributes) {}
let(:test_params) { double('test_params', attributes: test_attributes) }
- subject(:expansion) { test_instance.expanded_fields(request, media_type)}
+ subject(:expansion) { test_instance.expanded_fields(request, media_type) }
context '#expanded_fields' do
-
context 'with fields and view params defined' do
let(:test_attributes) { {} }
context 'with no fields provided' do
it 'returns the fields for the default view' do
- expect(expansion).to eq({id: true, name: true})
+ expect(expansion).to eq({ id: true, name: true })
end
end
context 'with a set of fields provided' do
let(:fields) { 'id,name,owner{name}' }
it 'returns the subset of fields' do
- expected = {id: true, name: true }
+ expected = { id: true, name: true }
expect(expansion).to eq expected
end
end
end
context 'with an action with no params' do
let(:test_params) { nil }
it 'ignores incoming parameters and expands for the default fieldset' do
- expect(expansion).to eq({id: true, name: true})
+ expect(expansion).to eq({ id: true, name: true })
end
end
end
-
end