spec/grape_entity/entity_spec.rb in grape-entity-0.4.7 vs spec/grape_entity/entity_spec.rb in grape-entity-0.4.8
- old
+ new
@@ -276,11 +276,31 @@
object = {}
subject.expose(:size, format_with: :size_formatter)
expect(subject.represent(object).send(:value_for, :size)).to eq object.class.to_s
end
+
+ it 'works global on Grape::Entity' do
+ Grape::Entity.format_with :size_formatter do |_date|
+ self.object.class.to_s
+ end
+ object = {}
+
+ subject.expose(:size, format_with: :size_formatter)
+ expect(subject.represent(object).send(:value_for, :size)).to eq object.class.to_s
+ end
end
+
+ it 'works global on Grape::Entity' do
+ Grape::Entity.expose :a
+ object = { a: 11, b: 22 }
+ expect(Grape::Entity.represent(object).send(:value_for, :a)).to eq 11
+ subject.expose :b
+ expect(subject.represent(object).send(:value_for, :a)).to eq 11
+ expect(subject.represent(object).send(:value_for, :b)).to eq 22
+ Grape::Entity.unexpose :a
+ end
end
describe '.unexpose' do
it 'is able to remove exposed attributes' do
subject.expose :name, :email
@@ -307,9 +327,16 @@
expect(subject.exposures).to eq(name: {})
expect(child_class.exposures).to eq(name: {}, email: {})
end
end
+ end
+
+ it 'works global on Grape::Entity' do
+ Grape::Entity.expose :a
+ expect(Grape::Entity.exposures).to eq(a: {})
+ Grape::Entity.unexpose :a
+ expect(Grape::Entity.exposures).to eq({})
end
end
describe '.with_options' do
it 'raises an error for unknown options' do