spec/integration/relations/reading_spec.rb in rom-0.4.2 vs spec/integration/relations/reading_spec.rb in rom-0.5.0
- old
+ new
@@ -2,10 +2,12 @@
describe 'Reading relations' do
include_context 'users and tasks'
it 'exposes a relation reader' do
+ setup.relation(:tasks)
+
setup.relation(:users) do
def by_name(name)
restrict(name: name)
end
@@ -18,24 +20,22 @@
define(:users) do
model name: 'User'
end
end
- rom = setup.finalize
-
users = rom.read(:users).sorted.by_name('Jane')
user = users.first
expect(user).to be_an_instance_of(User)
expect(user.name).to eql 'Jane'
expect(user.email).to eql 'jane@doe.org'
end
it 'maps grouped relations' do
- setup.relation(:users) do
- include ROM::RA
+ setup.relation(:tasks)
+ setup.relation(:users) do
def with_tasks
join(tasks)
end
def sorted
@@ -58,18 +58,21 @@
rom = setup.finalize
User.send(:include, Equalizer.new(:name, :email))
UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
- expect(rom.read(:users).with_tasks.header.keys).to eql([:name, :email, :tasks])
+ keys = rom.read(:users).with_tasks.header.keys
+ expect(keys).to eql([:name, :email, :tasks])
user = rom.read(:users).sorted.first
expect(user).to eql(
User.new(name: "Jane", email: "jane@doe.org")
)
+ expect(rom.read(:users)).to_not respond_to(:join)
+
user = rom.read(:users).with_tasks.sorted.first
expect(user).to eql(
UserWithTasks.new(
name: "Jane",
@@ -77,13 +80,13 @@
tasks: [{ title: "be cool", priority: 2 }])
)
end
it 'maps wrapped relations' do
- setup.relation(:users) do
- include ROM::RA
+ setup.relation(:tasks)
+ setup.relation(:users) do
def with_task
join(tasks)
end
def sorted
@@ -106,10 +109,11 @@
rom = setup.finalize
User.send(:include, Equalizer.new(:name, :email))
UserWithTask.send(:include, Equalizer.new(:name, :email, :task))
- expect(rom.read(:users).with_task.header.keys).to eql([:name, :email, :task])
+ keys = rom.read(:users).with_task.header.keys
+ expect(keys).to eql([:name, :email, :task])
user = rom.read(:users).sorted.with_task.first
expect(user).to eql(
UserWithTask.new(name: "Jane", email: "jane@doe.org",