Sha256: e908f7d923fe6ec896e8e1078f828cedd6dfdb5c828f06a5b38aef5db7e73659
Contents?: true
Size: 1.24 KB
Versions: 1
Compression:
Stored size: 1.24 KB
Contents
require 'spec_helper' describe 'Mappers / deeply embedded tuples' do let(:setup) { ROM.setup('memory://test') } let(:rom) { setup.finalize } it 'allows mapping embedded tuples' do setup.schema do base_relation(:users) do repository :default attribute 'name' attribute 'tasks' end end setup.relation(:users) setup.mappers do define(:users) do model name: 'User' attribute :name, from: 'name' embedded :tasks, from: 'tasks' do attribute :title, from: 'title' embedded :priority, from: 'priority', type: :hash do attribute :value, from: 'value' attribute :desc, from: 'desc' end end end end rom.schema.users << { 'name' => 'Jane', 'tasks' => [ { 'title' => 'Task One', 'priority' => { 'value' => 1, 'desc' => 'high' } }, { 'title' => 'Task Two', 'priority' => { 'value' => 3, 'desc' => 'low' } } ] } jane = rom.read(:users).to_a.first expect(jane.name).to eql('Jane') expect(jane.tasks).to eql([ { title: 'Task One', priority: { value: 1, desc: 'high' } }, { title: 'Task Two', priority: { value: 3, desc: 'low' } } ]) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rom-0.5.0 | spec/integration/mappers/deep_embedded_spec.rb |