sequel 4.26.0 → 4.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
+
3
+ describe "Sequel::Plugins::BeforeAfterSave" do
4
+ before do
5
+ @db = Sequel.mock(:numrows=>1, :fetch=>{:id=>1, :name=>'b'})
6
+ @c = Class.new(Sequel::Model(@db[:test]))
7
+ @ds = @c.dataset
8
+ @c.columns :id, :name
9
+ @c.plugin :before_after_save
10
+ @c.plugin :instance_hooks
11
+ @o = @c.new
12
+ @db.sqls
13
+ end
14
+
15
+ it "should reset modified flag before calling after hooks" do
16
+ a = []
17
+ @o.after_create_hook{@o.modified?.must_equal false; a << 1}
18
+ @o.after_save_hook{@o.modified?.must_equal false; a << 2}
19
+
20
+ @o.modified!
21
+ @o.save
22
+ a.must_equal [1, 2]
23
+
24
+ @o.after_save_hook{@o.modified?.must_equal false; a << 2}
25
+ @o.after_update_hook{@o.modified?.must_equal false; a << 3}
26
+ a = []
27
+ @o.modified!
28
+ @o.save
29
+ a.must_equal [3, 2]
30
+ end
31
+
32
+ it "should refresh the instance before calling after hooks" do
33
+ a = []
34
+ @o.after_create_hook{@o.values.must_equal(:id=>1, :name=>'b'); a << 1}
35
+ @o.after_save_hook{@o.values.must_equal(:id=>1, :name=>'b'); a << 2}
36
+
37
+ @o.save
38
+ a.must_equal [1, 2]
39
+ end
40
+ end
@@ -108,6 +108,11 @@ describe "Sequel::Postgres::JSONOp" do
108
108
  @l[@jb.array_elements_text].must_equal "jsonb_array_elements_text(j)"
109
109
  end
110
110
 
111
+ it "should have #strip_nulls use the json_strip_nulls function" do
112
+ @l[@j.strip_nulls].must_equal "json_strip_nulls(j)"
113
+ @l[@jb.strip_nulls].must_equal "jsonb_strip_nulls(j)"
114
+ end
115
+
111
116
  it "should have #typeof use the json_typeof function" do
112
117
  @l[@j.typeof].must_equal "json_typeof(j)"
113
118
  @l[@jb.typeof].must_equal "jsonb_typeof(j)"
@@ -173,6 +178,47 @@ describe "Sequel::Postgres::JSONOp" do
173
178
  @l[@jb.contained_by([1, 2])].must_equal "(j <@ '[1,2]'::jsonb)"
174
179
  end
175
180
 
181
+ it "#concat should use the || operator" do
182
+ @l[@jb.concat(:h1)].must_equal "(j || h1)"
183
+ end
184
+
185
+ it "#concat should handle hashes" do
186
+ @l[@jb.concat('a'=>'b')].must_equal "(j || '{\"a\":\"b\"}'::jsonb)"
187
+ end
188
+
189
+ it "#concat should handle arrays" do
190
+ @l[@jb.concat([1, 2])].must_equal "(j || '[1,2]'::jsonb)"
191
+ end
192
+
193
+ it "#set should use the jsonb_set function" do
194
+ @l[@jb.set(:a, :h)].must_equal "jsonb_set(j, a, h, true)"
195
+ @l[@jb.set(:a, :h, false)].must_equal "jsonb_set(j, a, h, false)"
196
+ end
197
+
198
+ it "#set should handle hashes" do
199
+ @l[@jb.set(:a, 'a'=>'b')].must_equal "jsonb_set(j, a, '{\"a\":\"b\"}'::jsonb, true)"
200
+ end
201
+
202
+ it "#set should handle arrays" do
203
+ @l[@jb.set(%w'a b', [1, 2])].must_equal "jsonb_set(j, ARRAY['a','b'], '[1,2]'::jsonb, true)"
204
+ end
205
+
206
+ it "#pretty should use the jsonb_pretty function" do
207
+ @l[@jb.pretty].must_equal "jsonb_pretty(j)"
208
+ end
209
+
210
+ it "#- should use the - operator" do
211
+ @l[@jb - 1].must_equal "(j - 1)"
212
+ end
213
+
214
+ it "#delete_path should use the #- operator" do
215
+ @l[@jb.delete_path(:a)].must_equal "(j #- a)"
216
+ end
217
+
218
+ it "#delete_path should handle arrays" do
219
+ @l[@jb.delete_path(['a'])].must_equal "(j #- ARRAY['a'])"
220
+ end
221
+
176
222
  it "#has_key? and aliases should use the ? operator" do
177
223
  @l[@jb.has_key?('a')].must_equal "(j ? 'a')"
178
224
  @l[@jb.include?('a')].must_equal "(j ? 'a')"
@@ -36,6 +36,17 @@ describe "Sequel::Schema::Generator dump methods" do
36
36
  g.indexes.must_equal g2.indexes
37
37
  end
38
38
 
39
+ it "should respect :keep_order option to primary_key" do
40
+ g = @g.new(@d) do
41
+ Integer :a
42
+ primary_key :c, :keep_order=>true
43
+ end
44
+ g2 = @g.new(@d) do
45
+ instance_eval(g.dump_columns, __FILE__, __LINE__)
46
+ end
47
+ g.columns.must_equal g2.columns
48
+ end
49
+
39
50
  it "should allow dumping indexes as separate add_index and drop_index methods" do
40
51
  g = @g.new(@d) do
41
52
  index :a
@@ -73,6 +84,9 @@ describe "Sequel::Database dump methods" do
73
84
  when :t2
74
85
  [[:c1, {:db_type=>'integer', :primary_key=>true, :allow_null=>false}],
75
86
  [:c2, {:db_type=>'numeric', :primary_key=>true, :allow_null=>false}]]
87
+ when :t3
88
+ [[:c2, {:db_type=>'varchar(20)', :allow_null=>true}],
89
+ [:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true, :allow_null=>false}]]
76
90
  when :t5
77
91
  [[:c1, {:db_type=>'blahblah', :allow_null=>true}]]
78
92
  end
@@ -96,6 +110,10 @@ describe "Sequel::Database dump methods" do
96
110
  @d.dump_table_schema(:t6).must_equal "create_table(:t6) do\n primary_key :c1, :type=>Bignum\nend"
97
111
  end
98
112
 
113
+ it "should dump auto incrementing primary keys with :keep_order option if they are not first" do
114
+ @d.dump_table_schema(:t3).must_equal "create_table(:t3) do\n String :c2, :size=>20\n primary_key :c1, :keep_order=>true\nend"
115
+ end
116
+
99
117
  it "should handle foreign keys" do
100
118
  @d.meta_def(:schema){|*s| [[:c1, {:db_type=>'integer', :allow_null=>true}]]}
101
119
  @d.meta_def(:supports_foreign_key_parsing?){true}
@@ -173,6 +173,20 @@ describe "Simple Dataset operations" do
173
173
 
174
174
  it "should fetch a single row correctly" do
175
175
  @ds.first.must_equal(:id=>1, :number=>10)
176
+ @ds.single_record.must_equal(:id=>1, :number=>10)
177
+ @ds.single_record!.must_equal(:id=>1, :number=>10)
178
+ end
179
+
180
+ it "should work correctly when returning from each without iterating over the whole result set" do
181
+ @ds.insert(:number=>20)
182
+ @ds.order(:id).each{|v| break v}.must_equal(:id=>1, :number=>10)
183
+ @ds.reverse(:id).each{|v| break v}.must_equal(:id=>2, :number=>20)
184
+ end
185
+
186
+ it "should fetch a single value correctly" do
187
+ @ds.get(:id).must_equal 1
188
+ @ds.select(:id).single_value.must_equal 1
189
+ @ds.select(:id).single_value!.must_equal 1
176
190
  end
177
191
 
178
192
  it "should have distinct work with limit" do
@@ -259,6 +259,12 @@ describe "Database foreign key parsing" do
259
259
  @db.create_table!(:b, :engine=>:InnoDB){Integer :e, :null=>false; Integer :f, :null=>false; Integer :g, :null=>false; foreign_key [:e, :f], :a; foreign_key [:g, :f], :a, :key=>[:d, :c]}
260
260
  @pr[:b, [[:e, :f], :a, [:pk, :b, :c]], [[:g, :f], :a, [:d, :c]]]
261
261
  end
262
+
263
+ it "should handle self-referential composite foreign and primary keys" do
264
+ @db.create_table!(:a, :engine=>:InnoDB){Integer :b, :null=>false; Integer :c, :null=>false; Integer :d, :null=>false; primary_key [:b, :c]; unique [:d, :b]}
265
+ @db.alter_table(:a){add_foreign_key [:b, :d], :a; add_foreign_key [:d, :c], :a; add_foreign_key [:c, :b], :a, :key=>[:d, :b]}
266
+ @pr[:a, [[:b, :d], :a, [:pk, :b, :c]], [[:c, :b], :a, [:d, :b]], [[:d, :c], :a, [:pk, :b, :c]]]
267
+ end
262
268
  end if DB.supports_foreign_key_parsing?
263
269
 
264
270
  describe "Database schema modifiers" do
@@ -110,8 +110,12 @@ describe Sequel::Model, "class dataset methods" do
110
110
  @c.set_graph_aliases(:a=>:b).opts[:graph_aliases].must_equal(:a=>[:b, :a])
111
111
  @c.single_record.must_equal @c.load(:id=>1)
112
112
  @db.sqls.must_equal ["SELECT * FROM items LIMIT 1"]
113
+ @c.single_record!.must_equal @c.load(:id=>1)
114
+ @db.sqls.must_equal ["SELECT * FROM items"]
113
115
  @c.single_value.must_equal 1
114
116
  @db.sqls.must_equal ["SELECT * FROM items LIMIT 1"]
117
+ @c.single_value!.must_equal 1
118
+ @db.sqls.must_equal ["SELECT * FROM items"]
115
119
  @c.sum(:id).must_equal 1
116
120
  @db.sqls.must_equal ["SELECT sum(id) AS sum FROM items LIMIT 1"]
117
121
  @c.to_hash(:id, :id).must_equal(1=>1)
@@ -474,7 +474,7 @@ describe Sequel::Model, ".finder" do
474
474
  @c.each_foo(3, 4){|r| a << r}
475
475
  a.must_equal [@o]
476
476
 
477
- @c.get_foo(5, 6).must_equal [:id, 1]
477
+ @c.get_foo(5, 6).must_equal 1
478
478
 
479
479
  @db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4", "SELECT * FROM items WHERE (bar = 5) ORDER BY 6 LIMIT 1"]
480
480
  end
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: 4.26.0
4
+ version: 4.27.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: 2015-09-01 00:00:00.000000000 Z
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -227,6 +227,7 @@ extra_rdoc_files:
227
227
  - doc/release_notes/4.24.0.txt
228
228
  - doc/release_notes/4.25.0.txt
229
229
  - doc/release_notes/4.26.0.txt
230
+ - doc/release_notes/4.27.0.txt
230
231
  files:
231
232
  - CHANGELOG
232
233
  - MIT-LICENSE
@@ -341,6 +342,7 @@ files:
341
342
  - doc/release_notes/4.24.0.txt
342
343
  - doc/release_notes/4.25.0.txt
343
344
  - doc/release_notes/4.26.0.txt
345
+ - doc/release_notes/4.27.0.txt
344
346
  - doc/release_notes/4.3.0.txt
345
347
  - doc/release_notes/4.4.0.txt
346
348
  - doc/release_notes/4.5.0.txt
@@ -530,6 +532,7 @@ files:
530
532
  - lib/sequel/plugins/association_pks.rb
531
533
  - lib/sequel/plugins/association_proxies.rb
532
534
  - lib/sequel/plugins/auto_validations.rb
535
+ - lib/sequel/plugins/before_after_save.rb
533
536
  - lib/sequel/plugins/blacklist_security.rb
534
537
  - lib/sequel/plugins/boolean_readers.rb
535
538
  - lib/sequel/plugins/caching.rb
@@ -630,6 +633,7 @@ files:
630
633
  - spec/extensions/association_pks_spec.rb
631
634
  - spec/extensions/association_proxies_spec.rb
632
635
  - spec/extensions/auto_validations_spec.rb
636
+ - spec/extensions/before_after_save_spec.rb
633
637
  - spec/extensions/blacklist_security_spec.rb
634
638
  - spec/extensions/blank_spec.rb
635
639
  - spec/extensions/boolean_readers_spec.rb
@@ -854,3 +858,4 @@ signing_key:
854
858
  specification_version: 4
855
859
  summary: The Database Toolkit for Ruby
856
860
  test_files: []
861
+ has_rdoc: true