sequel 5.9.0 → 5.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,7 @@ if ENV['COVERAGE']
5
5
  SimpleCov.sequel_coverage(:filter=>%r{lib/sequel/(extensions|plugins)/\w+\.rb\z})
6
6
  end
7
7
 
8
+ ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
8
9
  gem 'minitest'
9
10
  require 'minitest/autorun'
10
11
  require 'minitest/hooks/default'
@@ -115,6 +115,46 @@ describe Sequel::Model, "tree plugin" do
115
115
  "SELECT * FROM nodes WHERE (nodes.parent_id = 1)"]
116
116
  end
117
117
 
118
+ it "should have methods work correctly with custom association names" do
119
+ o = klass(:primary_key=>:i, :key=>:pi, :order=>:name, :children=>{:name=>:cs}, :parent=>{:name=>:p}).load(:id=>2, :parent_id=>1, :name=>'AA', :i=>3, :pi=>4)
120
+
121
+ o.model.parent_association_name.must_equal :p
122
+ o.model.children_association_name.must_equal :cs
123
+ o.model.dataset = o.model.dataset.with_fetch(lambda do |sql|
124
+ case sql
125
+ when "SELECT * FROM nodes WHERE (nodes.i = 4) ORDER BY name LIMIT 1"
126
+ {:id=>7, :parent_id=>8, :name=>'r2', :i=>4, :pi=>5}
127
+ when "SELECT * FROM nodes WHERE (nodes.i = 5) ORDER BY name LIMIT 1"
128
+ {:id=>10, :parent_id=>11, :name=>'r3', :i=>5, :pi=>nil}
129
+ when 'SELECT * FROM nodes WHERE (nodes.pi = 3) ORDER BY name'
130
+ {:id=>12, :parent_id=>13, :name=>'r4', :i=>7, :pi=>3}
131
+ when 'SELECT * FROM nodes WHERE (nodes.pi = 7) ORDER BY name'
132
+ {:id=>14, :parent_id=>15, :name=>'r5', :i=>8, :pi=>7}
133
+ when 'SELECT * FROM nodes WHERE (nodes.pi = 8) ORDER BY name'
134
+ []
135
+ when 'SELECT * FROM nodes WHERE (nodes.pi = 4) ORDER BY name'
136
+ [{:id=>2, :parent_id=>1, :name=>'AA', :i=>3, :pi=>4}, {:id=>20, :parent_id=>21, :name=>'r6', :i=>9, :pi=>4}]
137
+ else
138
+ raise sql
139
+ end
140
+ end)
141
+ o.db.sqls.must_equal []
142
+
143
+ o.ancestors.must_equal [o.model.load(:id=>7, :parent_id=>8, :name=>'r2', :i=>4, :pi=>5),
144
+ o.model.load(:id=>10, :parent_id=>11, :name=>'r3', :i=>5, :pi=>nil)]
145
+ o.db.sqls.must_equal ["SELECT * FROM nodes WHERE (nodes.i = 4) ORDER BY name LIMIT 1",
146
+ "SELECT * FROM nodes WHERE (nodes.i = 5) ORDER BY name LIMIT 1"]
147
+
148
+ o.descendants.must_equal [o.model.load(:id=>12, :parent_id=>13, :name=>'r4', :i=>7, :pi=>3),
149
+ o.model.load(:id=>14, :parent_id=>15, :name=>'r5', :i=>8, :pi=>7)]
150
+ o.db.sqls.must_equal ["SELECT * FROM nodes WHERE (nodes.pi = 3) ORDER BY name",
151
+ "SELECT * FROM nodes WHERE (nodes.pi = 7) ORDER BY name",
152
+ "SELECT * FROM nodes WHERE (nodes.pi = 8) ORDER BY name"]
153
+
154
+ o.siblings.must_equal [o.model.load(:id=>20, :parent_id=>21, :name=>'r6', :i=>9, :pi=>4)]
155
+ o.db.sqls.must_equal ["SELECT * FROM nodes WHERE (nodes.pi = 4) ORDER BY name"]
156
+ end
157
+
118
158
  describe ":single_root option" do
119
159
  before do
120
160
  @c = klass(:single_root => true)
@@ -1,3 +1,4 @@
1
+ ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
1
2
  gem 'minitest'
2
3
  require 'minitest/autorun'
3
4
  require 'minitest/hooks/default'
@@ -4149,6 +4149,11 @@ describe "Sequel::Model Associations with clashing column names" do
4149
4149
  @db.sqls.must_equal ["SELECT foos.id, foos.object_id, mtmbars.id AS mtmbars_id, mtmbars.object_id AS mtmbars_object_id FROM foos LEFT OUTER JOIN bars_foos ON (bars_foos.foo_id = foos.object_id) LEFT OUTER JOIN bars AS mtmbars ON (mtmbars.object_id = bars_foos.object_id)"]
4150
4150
  end
4151
4151
 
4152
+ it "should not have filter by associations code break if using IN/NOT in with a set-returning function" do
4153
+ @Bar.where(Sequel::SQL::BooleanExpression.new(:IN, :foo, Sequel.function(:srf))).sql.must_equal 'SELECT * FROM bars WHERE (foo IN srf())'
4154
+ @Bar.exclude(Sequel::SQL::BooleanExpression.new(:IN, :foo, Sequel.function(:srf))).sql.must_equal 'SELECT * FROM bars WHERE (foo NOT IN srf())'
4155
+ end
4156
+
4152
4157
  it "should have working filter by associations with model instances" do
4153
4158
  @Bar.first(:foo=>@foo).must_equal @bar
4154
4159
  @db.sqls.must_equal ["SELECT * FROM bars WHERE (bars.object_id = 2) LIMIT 1"]
@@ -4435,6 +4440,22 @@ describe "association autoreloading" do
4435
4440
  DB.reset
4436
4441
  end
4437
4442
 
4443
+ it "should not reload many_to_one association when foreign key is not modified" do
4444
+ album = @Album.load(:id => 1, :name=>'Al', :artist_id=>1)
4445
+ album.artist
4446
+ DB.sqls.must_equal ['SELECT * FROM artists WHERE id = 1']
4447
+ album.artist_id = 1
4448
+ album.artist
4449
+ DB.sqls.must_equal []
4450
+
4451
+ album = @Album.new(:name=>'Al', :artist_id=>1)
4452
+ album.artist
4453
+ DB.sqls.must_equal ['SELECT * FROM artists WHERE id = 1']
4454
+ album.artist_id = 1
4455
+ album.artist
4456
+ DB.sqls.must_equal []
4457
+ end
4458
+
4438
4459
  it "should reload many_to_one association when foreign key is modified" do
4439
4460
  album = @Album.load(:id => 1, :name=>'Al', :artist_id=>2)
4440
4461
  album.artist
@@ -5,6 +5,7 @@ require_relative "../../lib/sequel"
5
5
 
6
6
  Sequel::Deprecation.backtrace_filter = lambda{|line, lineno| lineno < 4 || line =~ /_spec\.rb/}
7
7
 
8
+ ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
8
9
  gem 'minitest'
9
10
  require 'minitest/autorun'
10
11
  require 'minitest/hooks/default'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.9.0
4
+ version: 5.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-01 00:00:00.000000000 Z
11
+ date: 2018-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -193,6 +193,7 @@ extra_rdoc_files:
193
193
  - doc/release_notes/5.8.0.txt
194
194
  - doc/release_notes/5.7.0.txt
195
195
  - doc/release_notes/5.9.0.txt
196
+ - doc/release_notes/5.10.0.txt
196
197
  files:
197
198
  - CHANGELOG
198
199
  - MIT-LICENSE
@@ -272,6 +273,7 @@ files:
272
273
  - doc/release_notes/4.9.0.txt
273
274
  - doc/release_notes/5.0.0.txt
274
275
  - doc/release_notes/5.1.0.txt
276
+ - doc/release_notes/5.10.0.txt
275
277
  - doc/release_notes/5.2.0.txt
276
278
  - doc/release_notes/5.3.0.txt
277
279
  - doc/release_notes/5.4.0.txt