From 32d5b0488145982bb0f35920ddb4f879e121d4d5 Mon Sep 17 00:00:00 2001 From: Michael Herold Date: Sat, 23 Aug 2014 20:24:44 -0400 Subject: [PATCH] Add failing spec for #69. --- spec/hashie/trash_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/hashie/trash_spec.rb b/spec/hashie/trash_spec.rb index e844093a..f85b09c5 100644 --- a/spec/hashie/trash_spec.rb +++ b/spec/hashie/trash_spec.rb @@ -134,6 +134,25 @@ class TrashLambdaTest < Hashie::Trash end end + describe 'translating multiple properties using a proc' do + class SomeDataModel < Hashie::Trash + property :value_a, from: :config, with: ->(config) { config.a } + property :value_b, from: :config, with: ->(config) { config.b } + end + + ConfigDataModel = Struct.new(:a, :b) + + subject { SomeDataModel.new(config: ConfigDataModel.new('value in a', 'value in b')) } + + it 'translates the first key' do + expect(subject.value_a).to eq 'value in a' + end + + it 'translates the second key' do + expect(subject.value_b).to eq 'value in b' + end + end + describe 'uses with or transform_with interchangeably' do class TrashLambdaTestTransformWith < Hashie::Trash property :first_name, from: :firstName, transform_with: ->(value) { value.reverse }