diff options
Diffstat (limited to 'spec/hashie/trash_spec.rb')
-rw-r--r-- | spec/hashie/trash_spec.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/spec/hashie/trash_spec.rb b/spec/hashie/trash_spec.rb index e844093..7bb174f 100644 --- a/spec/hashie/trash_spec.rb +++ b/spec/hashie/trash_spec.rb @@ -29,7 +29,7 @@ describe Hashie::Trash do end it 'maintains translations hash mapping from the original to the translated name' do - expect(TrashTest.translations[:firstName]).to eq :first_name + expect(TrashTest.translations[:firstName]).to eq(:first_name) end it 'maintains inverse translations hash mapping from the translated to the original name' do @@ -134,6 +134,29 @@ describe Hashie::Trash do 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 + + it 'maintains translations hash mapping from the original to the translated name' do + expect(SomeDataModel.translations).to eq(config: [:value_a, :value_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 } |