Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trash: multiple properties #69

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions spec/hashie/trash_spec.rb
Expand Up @@ -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: lambda { |value| value.reverse }
Expand Down