Sha256: eaef301c7c798b7ef2416175f33bb1dbc863a32cb97e2e1d69b5b738cb86be54
Contents?: true
Size: 1.12 KB
Versions: 12
Compression:
Stored size: 1.12 KB
Contents
require 'spec_helper' require 'rom/memory' describe 'Mappers / deeply embedded tuples' do let(:setup) { ROM.setup(:memory) } let(:rom) { setup.finalize } it 'allows mapping embedded tuples' do setup.relation(:users) setup.mappers do define(:users) do model name: 'Test::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.relations.users << { 'name' => 'Jane', 'tasks' => [ { 'title' => 'Task One', 'priority' => { 'value' => 1, 'desc' => 'high' } }, { 'title' => 'Task Two', 'priority' => { 'value' => 3, 'desc' => 'low' } } ] } jane = rom.relation(:users).as(:users).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
12 entries across 12 versions & 1 rubygems