spec/extensions/postgres/integration_spec.rb in rom-sql-1.2.2 vs spec/extensions/postgres/integration_spec.rb in rom-sql-1.3.0
- old
+ new
@@ -15,10 +15,11 @@
schema(:pg_people, infer: true)
end
conf.commands(:people) do
define(:create)
+ define(:update)
end
end
let(:people_relation) { relations[:people] }
@@ -31,8 +32,28 @@
end
it 'inserts empty arrays' do
people.create.call(name: 'John Doe', tags: [])
expect(people_relation.to_a).to eq([id: 1, name: 'John Doe', tags: []])
+ end
+ end
+
+ describe 'using retrurning' do
+ let(:create_person) { commands[:people].create }
+ let(:update_person) { commands[:people].update }
+ let(:composite_relation) { people_relation >> -> r { r.to_a.map { |x| x.fetch(:name).upcase } } }
+
+ context 'with pipeline' do
+ it 'works with create' do
+ mapped_people = create_person.new(composite_relation).call(name: 'John Doe', tags: ['foo'])
+ expect(mapped_people).to eql(['JOHN DOE'])
+ end
+
+ it 'works with update' do
+ create_person.call(name: 'John Doe', tags: ['foo'])
+
+ mapped_people = update_person.new(composite_relation).call(name: 'Jane Doe')
+ expect(mapped_people).to eql(['JANE DOE'])
+ end
end
end
end