spec/integration/read_spec.rb in rom-sql-0.6.1 vs spec/integration/read_spec.rb in rom-sql-0.7.0.beta1

- old
+ new

@@ -32,16 +32,20 @@ attribute :name, String attribute :goal_count, Integer end end - setup.relation(:goals) do + configuration.relation(:goals) do + use :assoc_macros + register_as :goals dataset :tasks end - setup.relation(:users) do + configuration.relation(:users) do + use :assoc_macros + one_to_many :goals, key: :user_id def by_name(name) where(name: name) end @@ -53,11 +57,13 @@ def all select(:id, :name) end end - setup.relation(:user_goal_counts) do + configuration.relation(:user_goal_counts) do + use :assoc_macros + dataset :users register_as :user_goal_counts one_to_many :goals, key: :user_id def all @@ -69,11 +75,11 @@ def with_goals association_left_join(:goals, select: [:id, :title]) end end - setup.mappers do + configuration.mappers do define(:users) do model User group :goals do model Goal @@ -88,21 +94,21 @@ end end end it 'loads domain objects' do - user = rom.relation(:users).as(:users).with_goals.by_name('Piotr').to_a.first + user = container.relation(:users).as(:users).with_goals.by_name('Piotr').to_a.first expect(user).to eql( User.new( id: 1, name: 'Piotr', goals: [Goal.new(id: 1, title: 'Finish ROM')] )) end it 'works with grouping and aggregates' do - rom.relations[:goals].insert(id: 2, user_id: 1, title: 'Get Milk') + container.relations[:goals].insert(id: 2, user_id: 1, title: 'Get Milk') - users_with_goal_count = rom.relation(:user_goal_counts).as(:user_goal_counts).all + users_with_goal_count = container.relation(:user_goal_counts).as(:user_goal_counts).all expect(users_with_goal_count.to_a).to eq([ UserGoalCount.new(id: 1, name: "Piotr", goal_count: 2) ]) end