spec/integration/plugin_test.rb in sequel-3.15.0 vs spec/integration/plugin_test.rb in sequel-3.16.0

- old
+ new

@@ -411,17 +411,26 @@ @album.updated_at.should == nil @album.touch @album.updated_at.to_i.should be_close(Time.now.to_i, 2) end - cspecify "should update the timestamp column for associated records when the record is updated or destroyed", [:do], [:jdbc, :sqlite] do + cspecify "should update the timestamp column for associated records when the record is updated or destroyed", [:do, :sqlite], [:jdbc, :sqlite] do @artist.updated_at.should == nil @album.update(:name=>'B') - @artist.reload.updated_at.to_i.should be_close(Time.now.to_i, 2) + ua = @artist.reload.updated_at + if ua.is_a?(Time) + ua.to_i.should be_close(Time.now.to_i, 2) + else + (DateTime.now - ua).should be_close(0, 2.0/86400) + end @artist.update(:updated_at=>nil) @album.destroy - @artist.reload.updated_at.to_i.should be_close(Time.now.to_i, 2) + if ua.is_a?(Time) + ua.to_i.should be_close(Time.now.to_i, 2) + else + (DateTime.now - ua).should be_close(0, 2.0/86400) + end end end describe "Serialization plugin" do before do @@ -641,9 +650,19 @@ nodes[1].descendants.should == [@aaaa, @aaaaa, @aaab] nodes[2].descendants.should == [@ba, @bb] nodes[0].ancestors.should == [] nodes[1].ancestors.should == [@a, @aa] nodes[2].ancestors.should == [] + end + + specify "should work correctly if not all columns are selected" do + Node.plugin :lazy_attributes, :name + @aaaa.descendants.should == [Node.load(:parent_id=>11, :id=>13)] + @aa.ancestors.should == [Node.load(:parent_id=>nil, :id=>1)] + nodes = Node.filter(:id=>[@a.id, @b.id, @aaa.id]).order(:name).eager(:ancestors, :descendants).all + nodes.should == [{:parent_id=>nil, :id=>1}, {:parent_id=>3, :id=>7}, {:parent_id=>nil, :id=>2}].map{|x| Node.load(x)} + nodes[2].descendants.should == [{:parent_id=>2, :id=>5}, {:parent_id=>2, :id=>6}].map{|x| Node.load(x)} + nodes[1].ancestors.should == [{:parent_id=>nil, :id=>1}, {:parent_id=>1, :id=>3}].map{|x| Node.load(x)} end specify "should eagerly load descendants to a given level" do nodes = Node.filter(:id=>[@a.id, @b.id, @aaa.id]).order(:name).eager(:descendants=>1).all nodes.should == [@a, @aaa, @b]