spec/integration/plugin_test.rb in sequel-3.31.0 vs spec/integration/plugin_test.rb in sequel-3.32.0

- old
+ new

@@ -98,12 +98,11 @@ specify "should handle associations only defined in subclasses" do Employee.filter(:id=>@i2).all.first.manager.id.should == @i4 end - # See http://www.sqlite.org/src/tktview/3338b3fa19ac4abee6c475126a2e6d9d61f26ab1 - cspecify "should insert rows into all tables", :sqlite do + cspecify "should insert rows into all tables", [:amalgalite], [:jdbc, :sqlite] do e = Executive.create(:name=>'Ex2', :num_managers=>8, :num_staff=>9) i = e.id @db[:employees][:id=>i].should == {:id=>i, :name=>'Ex2', :kind=>'Executive'} @db[:managers][:id=>i].should == {:id=>i, :num_staff=>9} @db[:executives][:id=>i].should == {:id=>i, :num_managers=>8} @@ -138,11 +137,11 @@ specify "should handle eagerly loading one_to_many relationships" do Executive.limit(1).eager(:staff_members).first.staff_members.should == [Staff[@i2]] end - cspecify "should handle eagerly graphing one_to_many relationships", :sqlite do + cspecify "should handle eagerly graphing one_to_many relationships", [:amalgalite], [:jdbc, :sqlite] do es = Executive.limit(1).eager_graph(:staff_members).all es.should == [Executive[@i4]] es.map{|x| x.staff_members}.should == [[Staff[@i2]]] end end @@ -197,10 +196,14 @@ end after(:all) do @db.drop_table :albums_artists, :albums, :artists end + def self_join(c) + c.join(c.table_name.as(:b), Array(c.primary_key).zip(Array(c.primary_key))).select_all(c.table_name) + end + specify "should handle super simple case with 1 join table" do Artist.many_through_many :albums, [[:albums_artists, :artist_id, :album_id]] Artist[@artist1.id].albums.map{|x| x.name}.sort.should == %w'A D' Artist[@artist2.id].albums.map{|x| x.name}.sort.should == %w'A C' Artist[@artist3.id].albums.map{|x| x.name}.sort.should == %w'B C' @@ -238,10 +241,30 @@ Artist.exclude(:albums=>[@album1, @album3]).all.map{|a| a.name}.sort.should == %w'4' Artist.exclude(:albums=>[@album2, @album4]).all.map{|a| a.name}.sort.should == %w'2' Artist.filter(:albums=>Album.filter(:id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.should == %w'1 2 3' Artist.exclude(:albums=>Album.filter(:id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.should == %w'4' + + c = self_join(Artist) + c.filter(:albums=>@album1).all.map{|a| a.name}.sort.should == %w'1 2' + c.filter(:albums=>@album2).all.map{|a| a.name}.sort.should == %w'3 4' + c.filter(:albums=>@album3).all.map{|a| a.name}.sort.should == %w'2 3' + c.filter(:albums=>@album4).all.map{|a| a.name}.sort.should == %w'1 4' + + c.exclude(:albums=>@album1).all.map{|a| a.name}.sort.should == %w'3 4' + c.exclude(:albums=>@album2).all.map{|a| a.name}.sort.should == %w'1 2' + c.exclude(:albums=>@album3).all.map{|a| a.name}.sort.should == %w'1 4' + c.exclude(:albums=>@album4).all.map{|a| a.name}.sort.should == %w'2 3' + + c.filter(:albums=>[@album1, @album3]).all.map{|a| a.name}.sort.should == %w'1 2 3' + c.filter(:albums=>[@album2, @album4]).all.map{|a| a.name}.sort.should == %w'1 3 4' + + c.exclude(:albums=>[@album1, @album3]).all.map{|a| a.name}.sort.should == %w'4' + c.exclude(:albums=>[@album2, @album4]).all.map{|a| a.name}.sort.should == %w'2' + + c.filter(:albums=>self_join(Album).filter(:albums__id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.should == %w'1 2 3' + c.exclude(:albums=>self_join(Album).filter(:albums__id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.should == %w'4' end specify "should handle typical case with 3 join tables" do Artist.many_through_many :related_artists, [[:albums_artists, :artist_id, :album_id], [:albums, :id, :id], [:albums_artists, :album_id, :artist_id]], :class=>Artist, :distinct=>true Artist[@artist1.id].related_artists.map{|x| x.name}.sort.should == %w'1 2 4' @@ -278,10 +301,27 @@ Artist.filter(:related_artists=>[@artist1, @artist4]).all.map{|a| a.name}.sort.should == %w'1 2 3 4' Artist.exclude(:related_artists=>[@artist1, @artist4]).all.map{|a| a.name}.sort.should == %w'' Artist.filter(:related_artists=>Artist.filter(:id=>@artist1.id)).all.map{|a| a.name}.sort.should == %w'1 2 4' Artist.exclude(:related_artists=>Artist.filter(:id=>@artist1.id)).all.map{|a| a.name}.sort.should == %w'3' + + c = self_join(Artist) + c.filter(:related_artists=>@artist1).all.map{|a| a.name}.sort.should == %w'1 2 4' + c.filter(:related_artists=>@artist2).all.map{|a| a.name}.sort.should == %w'1 2 3' + c.filter(:related_artists=>@artist3).all.map{|a| a.name}.sort.should == %w'2 3 4' + c.filter(:related_artists=>@artist4).all.map{|a| a.name}.sort.should == %w'1 3 4' + + c.exclude(:related_artists=>@artist1).all.map{|a| a.name}.sort.should == %w'3' + c.exclude(:related_artists=>@artist2).all.map{|a| a.name}.sort.should == %w'4' + c.exclude(:related_artists=>@artist3).all.map{|a| a.name}.sort.should == %w'1' + c.exclude(:related_artists=>@artist4).all.map{|a| a.name}.sort.should == %w'2' + + c.filter(:related_artists=>[@artist1, @artist4]).all.map{|a| a.name}.sort.should == %w'1 2 3 4' + c.exclude(:related_artists=>[@artist1, @artist4]).all.map{|a| a.name}.sort.should == %w'' + + c.filter(:related_artists=>c.filter(:artists__id=>@artist1.id)).all.map{|a| a.name}.sort.should == %w'1 2 4' + c.exclude(:related_artists=>c.filter(:artists__id=>@artist1.id)).all.map{|a| a.name}.sort.should == %w'3' end specify "should handle extreme case with 5 join tables" do Artist.many_through_many :related_albums, [[:albums_artists, :artist_id, :album_id], [:albums, :id, :id], [:albums_artists, :album_id, :artist_id], [:artists, :id, :id], [:albums_artists, :artist_id, :album_id]], :class=>Album, :distinct=>true @db[:albums_artists].delete @@ -330,9 +370,29 @@ Artist.exclude(:related_albums=>[@album1, @album3]).all.map{|a| a.name}.sort.should == %w'4' Artist.exclude(:related_albums=>[@album2, @album4]).all.map{|a| a.name}.sort.should == %w'' Artist.filter(:related_albums=>Album.filter(:id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.should == %w'1 2 3' Artist.exclude(:related_albums=>Album.filter(:id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.should == %w'4' + + c = self_join(Artist) + c.filter(:related_albums=>@album1).all.map{|a| a.name}.sort.should == %w'1 2 3' + c.filter(:related_albums=>@album2).all.map{|a| a.name}.sort.should == %w'1 2 3 4' + c.filter(:related_albums=>@album3).all.map{|a| a.name}.sort.should == %w'1 2' + c.filter(:related_albums=>@album4).all.map{|a| a.name}.sort.should == %w'2 3 4' + + c.exclude(:related_albums=>@album1).all.map{|a| a.name}.sort.should == %w'4' + c.exclude(:related_albums=>@album2).all.map{|a| a.name}.sort.should == %w'' + c.exclude(:related_albums=>@album3).all.map{|a| a.name}.sort.should == %w'3 4' + c.exclude(:related_albums=>@album4).all.map{|a| a.name}.sort.should == %w'1' + + c.filter(:related_albums=>[@album1, @album3]).all.map{|a| a.name}.sort.should == %w'1 2 3' + c.filter(:related_albums=>[@album3, @album4]).all.map{|a| a.name}.sort.should == %w'1 2 3 4' + + c.exclude(:related_albums=>[@album1, @album3]).all.map{|a| a.name}.sort.should == %w'4' + c.exclude(:related_albums=>[@album2, @album4]).all.map{|a| a.name}.sort.should == %w'' + + c.filter(:related_albums=>self_join(Album).filter(:albums__id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.should == %w'1 2 3' + c.exclude(:related_albums=>self_join(Album).filter(:albums__id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.should == %w'4' end end describe "Lazy Attributes plugin" do before(:all) do