spec/integration/plugin_test.rb in sequel-5.19.0 vs spec/integration/plugin_test.rb in sequel-5.20.0
- old
+ new
@@ -28,10 +28,11 @@
class ::Employee < Sequel::Model(@db)
plugin :class_table_inheritance, :key=>:kind, :table_map=>{:Staff=>:staff}
end
class ::Manager < Employee
one_to_many :staff_members, :class=>:Staff
+ one_to_one :first_staff_member, :clone=>:staff_members, :order=>:id
end
class ::Executive < Manager
end
class ::Ceo < Executive
end
@@ -148,10 +149,12 @@
it "should handle many_to_one relationships" do
m = Staff.first.manager
m.must_equal Manager[@i4]
m.must_be_kind_of(Executive)
+ Staff.first.update(:manager => Manager[@i3])
+ Staff.first.manager.must_equal Manager[@i3]
end
it "should handle eagerly loading many_to_one relationships" do
Staff.limit(1).eager(:manager).all.map{|x| x.manager}.must_equal [Manager[@i4]]
end
@@ -162,9 +165,21 @@
ss.map{|x| x.manager}.must_equal [Manager[@i4]]
end
it "should handle one_to_many relationships" do
Executive.first(:name=>'Ex').staff_members.must_equal [Staff[@i2]]
+ i6 = @db[:employees].insert(:name=>'S2', :kind=>'Staff')
+ @db[:staff].insert(:id=>i6, :manager_id=>@i4)
+ Executive.first(:name=>'Ex').add_staff_member(i6)
+ Executive.first(:name=>'Ex').staff_members{|ds| ds.order(:id)}.must_equal [Staff[@i2], Staff[i6]]
+ end
+
+ it "should handle one_to_many relationships" do
+ Executive.first(:name=>'Ex').first_staff_member.must_equal Staff[@i2]
+ i6 = @db[:employees].insert(:name=>'S2', :kind=>'Staff')
+ @db[:staff].insert(:id=>i6, :manager_id=>@i4)
+ Executive.first(:name=>'Ex').first_staff_member = Staff[i6]
+ Executive.first(:name=>'Ex').staff_members.must_equal [Staff[i6]]
end
it "should handle eagerly loading one_to_many relationships" do
Executive.where(:name=>'Ex').eager(:staff_members).first.staff_members.must_equal [Staff[@i2]]
end