Sha256: 9a24e04500fe5dea304879b77d549a7a79c3f685ae5cf0176cf581fc0251b20c
Contents?: true
Size: 1.2 KB
Versions: 7
Compression:
Stored size: 1.2 KB
Contents
require 'spec_helper' describe 'Relation registration DSL' do include_context 'container' include_context 'users and tasks' it 'allows to expose chainable relations' do configuration.relation(:tasks) do def high_priority restrict { |tuple| tuple[:priority] < 2 } end def by_title(title) restrict(title: title) end end configuration.relation(:users) do def with_tasks join(tasks) end end tasks = container.relations.tasks expect(tasks.class.name).to eql("ROM::Relation[Tasks]") expect(tasks.high_priority.inspect).to include("#<ROM::Relation[Tasks]") expect(tasks.high_priority.by_title("be nice")).to match_array( [name: "Joe", title: "be nice", priority: 1] ) expect(tasks.by_title("be cool")).to match_array( [name: "Jane", title: "be cool", priority: 2] ) users = container.relations.users expect(users.with_tasks).to match_array( [{ name: "Joe", email: "joe@doe.org", title: "be nice", priority: 1 }, { name: "Joe", email: "joe@doe.org", title: "sleep well", priority: 2 }, { name: "Jane", email: "jane@doe.org", title: "be cool", priority: 2 }] ) end end
Version data entries
7 entries across 7 versions & 1 rubygems