summaryrefslogtreecommitdiff
path: root/spec/hashie/trash_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/hashie/trash_spec.rb')
-rw-r--r--spec/hashie/trash_spec.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/spec/hashie/trash_spec.rb b/spec/hashie/trash_spec.rb
index 9998c8d..aaabe70 100644
--- a/spec/hashie/trash_spec.rb
+++ b/spec/hashie/trash_spec.rb
@@ -157,6 +157,23 @@ describe Hashie::Trash do
end
end
+ describe 'translating multiple properties from the same source hash key' do
+ class AnotherDataModel < Hashie::Trash
+ property :first_name, transform_with: ->(n) { n.upcase }
+ property :first_name_short, from: :first_name, transform_with: ->(n) { n[0, 3] }
+ end
+
+ subject { AnotherDataModel.new(first_name: 'Cathy') }
+
+ it 'translates the first key with the given lambda' do
+ expect(subject.first_name).to eq('CATHY')
+ end
+
+ it 'translates the second key with the given lambda and the initial value of the first key' do
+ expect(subject.first_name_short).to eq('Cat')
+ end
+ end
+
describe 'uses with or transform_with interchangeably' do
class TrashLambdaTestTransformWith < Hashie::Trash
property :first_name, from: :firstName, transform_with: ->(value) { value.reverse }