spec/grape_entity/entity_spec.rb in grape-entity-1.0.0 vs spec/grape_entity/entity_spec.rb in grape-entity-1.0.1

- old
+ new

@@ -28,13 +28,15 @@ expect { subject.expose :name, as: :foo }.not_to raise_error end it 'makes sure that :format_with as a proc cannot be used with a block' do # rubocop:disable Style/BlockDelimiters - # rubocop:disable Lint/Debugger - expect { subject.expose :name, format_with: proc {} do p 'hi' end }.to raise_error ArgumentError - # rubocop:enable Lint/Debugger + expect { + subject.expose :name, format_with: proc {} do + p 'hi' + end + }.to raise_error ArgumentError # rubocop:enable Style/BlockDelimiters end it 'makes sure unknown options are not silently ignored' do expect { subject.expose :name, unknown: nil }.to raise_error ArgumentError @@ -129,24 +131,24 @@ end end context 'when expose_nil option is false and block passed' do it 'does not expose if block returns nil' do - subject.expose(:a, expose_nil: false) do |_obj, _options| - nil + subject.expose(:a, expose_nil: false) do |_obj, options| + options[:option_a] end subject.expose(:b) subject.expose(:c) expect(subject.represent(model).serializable_hash).to eq(b: nil, c: 'value') end it 'exposes is block returns a value' do - subject.expose(:a, expose_nil: false) do |_obj, _options| - 100 + subject.expose(:a, expose_nil: false) do |_obj, options| + options[:option_a] end subject.expose(:b) subject.expose(:c) - expect(subject.represent(model).serializable_hash).to eq(a: 100, b: nil, c: 'value') + expect(subject.represent(model, option_a: 100).serializable_hash).to eq(a: 100, b: nil, c: 'value') end end end context 'when model is a hash' do