spec/integration/mappers/wrap_spec.rb in rom-0.5.0 vs spec/integration/mappers/wrap_spec.rb in rom-0.6.0.beta1
- old
+ new
@@ -3,18 +3,10 @@
describe 'Mapper definition DSL' do
include_context 'users and tasks'
let(:header) { mapper.header }
- before do
- setup.relation(:users) do
- def email_index
- project(:email)
- end
- end
- end
-
describe 'wrapped relation mapper' do
before do
setup.relation(:tasks) do
def with_user
join(users)
@@ -23,49 +15,49 @@
setup.relation(:users)
setup.mappers do
define(:tasks) do
- model name: 'Task'
+ model name: 'Test::Task'
attribute :title
attribute :priority
end
end
end
it 'allows defining wrapped attributes via options hash' do
setup.mappers do
define(:with_user, parent: :tasks) do
- model name: 'TaskWithUser'
+ model name: 'Test::TaskWithUser'
attribute :title
attribute :priority
wrap user: [:email]
end
end
rom = setup.finalize
- TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
+ Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
jane = rom.read(:tasks).with_user.to_a.last
expect(jane).to eql(
- TaskWithUser.new(
+ Test::TaskWithUser.new(
title: 'be cool',
priority: 2,
user: { email: 'jane@doe.org' }
)
)
end
it 'allows defining wrapped attributes via options block' do
setup.mappers do
define(:with_user, parent: :tasks) do
- model name: 'TaskWithUser'
+ model name: 'Test::TaskWithUser'
attribute :title
attribute :priority
wrap :user do
@@ -74,88 +66,88 @@
end
end
rom = setup.finalize
- TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
+ Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
jane = rom.read(:tasks).with_user.to_a.last
expect(jane).to eql(
- TaskWithUser.new(
+ Test::TaskWithUser.new(
title: 'be cool',
priority: 2,
user: { email: 'jane@doe.org' }
)
)
end
it 'allows defining nested wrapped attributes via a block' do
setup.mappers do
define(:with_user, parent: :tasks, inherit_header: false) do
- model name: 'TaskWithUser'
+ model name: 'Test::TaskWithUser'
attribute :title
attribute :priority
wrap :user do
- model name: 'TaskUser'
+ model name: 'Test::TaskUser'
attribute :name
wrap :contact do
- model name: 'Contact'
+ model name: 'Test::Contact'
attribute :email
end
end
end
end
rom = setup.finalize
- TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
- TaskUser.send(:include, Equalizer.new(:name, :contact))
- Contact.send(:include, Equalizer.new(:email))
+ Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
+ Test::TaskUser.send(:include, Equalizer.new(:name, :contact))
+ Test::Contact.send(:include, Equalizer.new(:email))
jane = rom.read(:tasks).with_user.to_a.last
expect(jane).to eql(
- TaskWithUser.new(
+ Test::TaskWithUser.new(
title: 'be cool',
priority: 2,
- user: TaskUser.new(
- name: 'Jane', contact: Contact.new(email: 'jane@doe.org')
+ user: Test::TaskUser.new(
+ name: 'Jane', contact: Test::Contact.new(email: 'jane@doe.org')
)
)
)
end
it 'allows defining wrapped attributes mapped to a model' do
setup.mappers do
define(:with_user, parent: :tasks) do
- model name: 'TaskWithUser'
+ model name: 'Test::TaskWithUser'
attribute :title
attribute :priority
wrap :user do
- model name: 'User'
+ model name: 'Test::User'
attribute :email
end
end
end
rom = setup.finalize
- TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
- User.send(:include, Equalizer.new(:email))
+ Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
+ Test::User.send(:include, Equalizer.new(:email))
jane = rom.read(:tasks).with_user.to_a.last
expect(jane).to eql(
- TaskWithUser.new(
+ Test::TaskWithUser.new(
title: 'be cool',
priority: 2,
- user: User.new(email: 'jane@doe.org')
+ user: Test::User.new(email: 'jane@doe.org')
)
)
end
end
end