sequel 4.44.0 → 4.45.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.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +110 -0
  3. data/README.rdoc +8 -9
  4. data/doc/active_record.rdoc +2 -3
  5. data/doc/model_plugins.rdoc +1 -1
  6. data/doc/opening_databases.rdoc +0 -46
  7. data/doc/release_notes/4.45.0.txt +370 -0
  8. data/lib/sequel/adapters/cubrid.rb +2 -0
  9. data/lib/sequel/adapters/do.rb +2 -0
  10. data/lib/sequel/adapters/jdbc/as400.rb +2 -0
  11. data/lib/sequel/adapters/jdbc/cubrid.rb +2 -0
  12. data/lib/sequel/adapters/jdbc/firebirdsql.rb +2 -0
  13. data/lib/sequel/adapters/jdbc/informix-sqli.rb +2 -0
  14. data/lib/sequel/adapters/jdbc/jdbcprogress.rb +2 -0
  15. data/lib/sequel/adapters/jdbc/mysql.rb +1 -0
  16. data/lib/sequel/adapters/jdbc/postgresql.rb +5 -0
  17. data/lib/sequel/adapters/mysql.rb +1 -0
  18. data/lib/sequel/adapters/mysql2.rb +1 -0
  19. data/lib/sequel/adapters/odbc/oracle.rb +11 -0
  20. data/lib/sequel/adapters/odbc/progress.rb +2 -0
  21. data/lib/sequel/adapters/postgres.rb +0 -2
  22. data/lib/sequel/adapters/shared/cubrid.rb +2 -0
  23. data/lib/sequel/adapters/shared/firebird.rb +2 -0
  24. data/lib/sequel/adapters/shared/informix.rb +2 -0
  25. data/lib/sequel/adapters/shared/mssql.rb +47 -7
  26. data/lib/sequel/adapters/shared/mysql.rb +16 -1
  27. data/lib/sequel/adapters/shared/postgres.rb +9 -1
  28. data/lib/sequel/adapters/shared/progress.rb +2 -0
  29. data/lib/sequel/adapters/shared/sqlanywhere.rb +1 -1
  30. data/lib/sequel/adapters/swift.rb +2 -0
  31. data/lib/sequel/ast_transformer.rb +13 -6
  32. data/lib/sequel/core.rb +13 -16
  33. data/lib/sequel/database/connecting.rb +25 -10
  34. data/lib/sequel/database/dataset.rb +6 -1
  35. data/lib/sequel/database/dataset_defaults.rb +9 -2
  36. data/lib/sequel/database/misc.rb +10 -3
  37. data/lib/sequel/database/schema_methods.rb +4 -0
  38. data/lib/sequel/dataset/mutation.rb +8 -20
  39. data/lib/sequel/dataset/prepared_statements.rb +2 -0
  40. data/lib/sequel/dataset/query.rb +32 -7
  41. data/lib/sequel/dataset/sql.rb +13 -3
  42. data/lib/sequel/deprecated.rb +9 -1
  43. data/lib/sequel/exceptions.rb +37 -8
  44. data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +117 -0
  45. data/lib/sequel/extensions/date_arithmetic.rb +1 -0
  46. data/lib/sequel/extensions/identifier_mangling.rb +3 -2
  47. data/lib/sequel/extensions/pg_hstore.rb +1 -5
  48. data/lib/sequel/extensions/schema_dumper.rb +3 -1
  49. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +2 -2
  50. data/lib/sequel/extensions/string_agg.rb +1 -0
  51. data/lib/sequel/model.rb +23 -10
  52. data/lib/sequel/model/associations.rb +17 -5
  53. data/lib/sequel/model/base.rb +115 -62
  54. data/lib/sequel/model/dataset_module.rb +10 -3
  55. data/lib/sequel/model/exceptions.rb +7 -5
  56. data/lib/sequel/plugins/association_pks.rb +13 -1
  57. data/lib/sequel/plugins/association_proxies.rb +8 -1
  58. data/lib/sequel/plugins/before_after_save.rb +1 -0
  59. data/lib/sequel/plugins/class_table_inheritance.rb +7 -3
  60. data/lib/sequel/plugins/columns_updated.rb +42 -0
  61. data/lib/sequel/plugins/composition.rb +10 -5
  62. data/lib/sequel/plugins/error_splitter.rb +1 -1
  63. data/lib/sequel/plugins/hook_class_methods.rb +39 -5
  64. data/lib/sequel/plugins/instance_hooks.rb +58 -5
  65. data/lib/sequel/plugins/lazy_attributes.rb +10 -5
  66. data/lib/sequel/plugins/nested_attributes.rb +10 -5
  67. data/lib/sequel/plugins/prepared_statements.rb +7 -0
  68. data/lib/sequel/plugins/prepared_statements_associations.rb +2 -0
  69. data/lib/sequel/plugins/prepared_statements_with_pk.rb +2 -0
  70. data/lib/sequel/plugins/schema.rb +2 -0
  71. data/lib/sequel/plugins/scissors.rb +2 -0
  72. data/lib/sequel/plugins/serialization.rb +10 -5
  73. data/lib/sequel/plugins/split_values.rb +5 -1
  74. data/lib/sequel/plugins/static_cache.rb +2 -2
  75. data/lib/sequel/plugins/tactical_eager_loading.rb +1 -1
  76. data/lib/sequel/plugins/validation_contexts.rb +49 -0
  77. data/lib/sequel/plugins/validation_helpers.rb +1 -0
  78. data/lib/sequel/sql.rb +1 -1
  79. data/lib/sequel/version.rb +1 -1
  80. data/spec/adapters/mssql_spec.rb +31 -0
  81. data/spec/adapters/mysql_spec.rb +20 -2
  82. data/spec/adapters/postgres_spec.rb +43 -12
  83. data/spec/adapters/spec_helper.rb +5 -8
  84. data/spec/core/database_spec.rb +47 -12
  85. data/spec/core/dataset_mutation_spec.rb +22 -22
  86. data/spec/core/dataset_spec.rb +88 -20
  87. data/spec/core/deprecated_spec.rb +1 -1
  88. data/spec/core/expression_filters_spec.rb +1 -1
  89. data/spec/core/mock_adapter_spec.rb +0 -3
  90. data/spec/core/placeholder_literalizer_spec.rb +1 -1
  91. data/spec/core/schema_spec.rb +8 -1
  92. data/spec/core/spec_helper.rb +6 -1
  93. data/spec/core_extensions_spec.rb +4 -0
  94. data/spec/deprecation_helper.rb +17 -0
  95. data/spec/extensions/_deprecated_identifier_mangling_spec.rb +314 -0
  96. data/spec/extensions/association_pks_spec.rb +61 -13
  97. data/spec/extensions/association_proxies_spec.rb +3 -3
  98. data/spec/extensions/class_table_inheritance_spec.rb +39 -0
  99. data/spec/extensions/columns_updated_spec.rb +35 -0
  100. data/spec/extensions/composition_spec.rb +6 -1
  101. data/spec/extensions/hook_class_methods_spec.rb +114 -26
  102. data/spec/extensions/identifier_mangling_spec.rb +107 -73
  103. data/spec/extensions/instance_hooks_spec.rb +78 -14
  104. data/spec/extensions/lazy_attributes_spec.rb +8 -2
  105. data/spec/extensions/many_through_many_spec.rb +2 -2
  106. data/spec/extensions/mssql_optimistic_locking_spec.rb +1 -1
  107. data/spec/extensions/nested_attributes_spec.rb +8 -2
  108. data/spec/extensions/pg_array_spec.rb +18 -4
  109. data/spec/extensions/prepared_statements_associations_spec.rb +48 -39
  110. data/spec/extensions/prepared_statements_with_pk_spec.rb +13 -11
  111. data/spec/extensions/query_spec.rb +1 -1
  112. data/spec/extensions/schema_dumper_spec.rb +34 -6
  113. data/spec/extensions/schema_spec.rb +13 -7
  114. data/spec/extensions/scissors_spec.rb +3 -1
  115. data/spec/extensions/sequel_3_dataset_methods_spec.rb +4 -4
  116. data/spec/extensions/serialization_spec.rb +7 -1
  117. data/spec/extensions/set_overrides_spec.rb +2 -2
  118. data/spec/extensions/shared_caching_spec.rb +19 -15
  119. data/spec/extensions/spec_helper.rb +7 -3
  120. data/spec/extensions/split_values_spec.rb +45 -10
  121. data/spec/extensions/string_agg_spec.rb +2 -2
  122. data/spec/extensions/subset_conditions_spec.rb +3 -3
  123. data/spec/extensions/tactical_eager_loading_spec.rb +1 -1
  124. data/spec/extensions/validation_contexts_spec.rb +31 -0
  125. data/spec/guards_helper.rb +2 -0
  126. data/spec/integration/associations_test.rb +22 -20
  127. data/spec/integration/dataset_test.rb +25 -2
  128. data/spec/integration/model_test.rb +1 -1
  129. data/spec/integration/plugin_test.rb +11 -16
  130. data/spec/integration/prepared_statement_test.rb +40 -32
  131. data/spec/integration/spec_helper.rb +5 -8
  132. data/spec/model/association_reflection_spec.rb +4 -0
  133. data/spec/model/associations_spec.rb +37 -10
  134. data/spec/model/base_spec.rb +6 -0
  135. data/spec/model/hooks_spec.rb +56 -35
  136. data/spec/model/model_spec.rb +21 -5
  137. data/spec/model/record_spec.rb +14 -11
  138. data/spec/model/spec_helper.rb +7 -1
  139. data/spec/sequel_warning.rb +11 -0
  140. metadata +13 -3
@@ -2,34 +2,36 @@ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
2
 
3
3
  describe "prepared_statements_with_pk plugin" do
4
4
  before do
5
- @db = Sequel.mock(:fetch=>{:id=>1, :name=>'foo', :i=>2}, :autoid=>proc{|sql| 1}, :numrows=>1, :servers=>{:read_only=>{}})
6
- @c = Class.new(Sequel::Model(@db[:people]))
7
- @c.columns :id, :name, :i
8
- @c.plugin :prepared_statements_with_pk
9
- @p = @c.load(:id=>1, :name=>'foo', :i=>2)
10
- @db.sqls
5
+ deprecated do
6
+ @db = Sequel.mock(:fetch=>{:id=>1, :name=>'foo', :i=>2}, :autoid=>proc{|sql| 1}, :numrows=>1, :servers=>{:read_only=>{}})
7
+ @c = Class.new(Sequel::Model(@db[:people]))
8
+ @c.columns :id, :name, :i
9
+ @c.plugin :prepared_statements_with_pk
10
+ @p = @c.load(:id=>1, :name=>'foo', :i=>2)
11
+ @db.sqls
12
+ end
11
13
  end
12
14
 
13
- it "should load the prepared_statements plugin" do
15
+ deprecated "should load the prepared_statements plugin" do
14
16
  @c.plugins.must_include(Sequel::Plugins::PreparedStatements)
15
17
  end
16
18
 
17
- it "should correctly lookup by primary key from dataset" do
19
+ deprecated "should correctly lookup by primary key from dataset" do
18
20
  @c.dataset.filter(:name=>'foo')[1].must_equal @p
19
21
  @c.db.sqls.must_equal ["SELECT * FROM people WHERE ((name = 'foo') AND (people.id = 1)) LIMIT 1 -- read_only"]
20
22
  end
21
23
 
22
- it "should still work correctly if there are multiple conflicting variables" do
24
+ deprecated "should still work correctly if there are multiple conflicting variables" do
23
25
  @c.dataset.filter(:name=>'foo').or(:name=>'bar')[1].must_equal @p
24
26
  @c.db.sqls.must_equal ["SELECT * FROM people WHERE (((name = 'foo') OR (name = 'bar')) AND (people.id = 1)) LIMIT 1 -- read_only"]
25
27
  end
26
28
 
27
- it "should still work correctly if the primary key is used elsewhere in the query" do
29
+ deprecated "should still work correctly if the primary key is used elsewhere in the query" do
28
30
  @c.dataset.filter{id > 2}[1].must_equal @p
29
31
  @c.db.sqls.must_equal ["SELECT * FROM people WHERE ((id > 2) AND (people.id = 1)) LIMIT 1 -- read_only"]
30
32
  end
31
33
 
32
- it "should respect explicitly set server" do
34
+ deprecated "should respect explicitly set server" do
33
35
  @c.dataset.filter(:name=>'foo')[1].must_equal @p
34
36
  @c.db.sqls.must_equal ["SELECT * FROM people WHERE ((name = 'foo') AND (people.id = 1)) LIMIT 1 -- read_only"]
35
37
  @c.dataset.server(:default).filter(:name=>'foo')[1].must_equal @p
@@ -89,7 +89,7 @@ describe "Dataset#query" do
89
89
 
90
90
  # SEQUEL5: Remove
91
91
  unless Sequel.mock.dataset.frozen?
92
- it "should have an appropriate mutation method" do
92
+ deprecated "should have an appropriate mutation method" do
93
93
  @d.query! do
94
94
  select :a, :b___mongo
95
95
  from :yyy
@@ -75,9 +75,9 @@ end
75
75
  describe "Sequel::Database dump methods" do
76
76
  before do
77
77
  @d = Sequel::Database.new.extension(:schema_dumper)
78
- @d.meta_def(:tables){|o| [:t1, :t2]}
78
+ @d.meta_def(:tables){|o| o[:schema] ? [o[:schema]] : [:t1, :t2]}
79
79
  @d.meta_def(:schema) do |t, *o|
80
- case t
80
+ v = case t
81
81
  when :t1, 't__t1', Sequel.identifier(:t__t1)
82
82
  [[:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true, :allow_null=>false}],
83
83
  [:c2, {:db_type=>'varchar(20)', :allow_null=>true}]]
@@ -90,9 +90,19 @@ describe "Sequel::Database dump methods" do
90
90
  when :t5
91
91
  [[:c1, {:db_type=>'blahblah', :allow_null=>true}]]
92
92
  end
93
+
94
+ if o.first.is_a?(Hash) && o.first[:schema]
95
+ v.last.last[:db_type] = o.first[:schema]
96
+ end
97
+
98
+ v
93
99
  end
94
100
  end
95
101
 
102
+ it "should support dumping table with :schema option" do
103
+ @d.dump_table_schema(:t1, :schema=>'varchar(15)').must_equal "create_table(:t1) do\n primary_key :c1\n String :c2, :size=>15\nend"
104
+ end
105
+
96
106
  it "should support dumping table schemas as create_table method calls" do
97
107
  @d.dump_table_schema(:t1).must_equal "create_table(:t1) do\n primary_key :c1\n String :c2, :size=>20\nend"
98
108
  end
@@ -110,6 +120,11 @@ describe "Sequel::Database dump methods" do
110
120
  @d.dump_table_schema(:t6).must_equal "create_table(:t6) do\n primary_key :c1, :type=>:Bignum\nend"
111
121
  end
112
122
 
123
+ it "should dump non-Integer primary key columns with explicit :type when using :same_db=>true" do
124
+ @d.meta_def(:schema){|*s| [[:c1, {:db_type=>'bigint', :primary_key=>true, :allow_null=>true, :auto_increment=>true}]]}
125
+ @d.dump_table_schema(:t6, :same_db=>true).must_equal "create_table(:t6) do\n primary_key :c1, :type=>:Bignum\nend"
126
+ end
127
+
113
128
  it "should dump auto incrementing primary keys with :keep_order option if they are not first" do
114
129
  @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
130
  end
@@ -206,6 +221,19 @@ describe "Sequel::Database dump methods" do
206
221
  @d.dump_table_schema(:t1).must_equal "create_table(:t1, :ignore_index_errors=>true) do\n primary_key :c1\n String :c2, :size=>20\n \n index [:c1], :name=>:i1\n index [:c2, :c1], :unique=>true\nend"
207
222
  end
208
223
 
224
+ it "should support dumping the whole database as a migration with a :schema option" do
225
+ @d.dump_schema_migration(:schema=>'t__t1').must_equal <<-END_MIG
226
+ Sequel.migration do
227
+ change do
228
+ create_table("t__t1") do
229
+ primary_key :c1
230
+ String :c2
231
+ end
232
+ end
233
+ end
234
+ END_MIG
235
+ end
236
+
209
237
  it "should support dumping the whole database as a migration" do
210
238
  @d.dump_schema_migration.must_equal <<-END_MIG
211
239
  Sequel.migration do
@@ -249,7 +277,7 @@ END_MIG
249
277
 
250
278
  it "should sort table names topologically when dumping a migration with foreign keys" do
251
279
  @d.meta_def(:tables){|o| [:t1, :t2]}
252
- @d.meta_def(:schema) do |t|
280
+ @d.meta_def(:schema) do |t, *o|
253
281
  t == :t1 ? [[:c2, {:db_type=>'integer'}]] : [[:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true}]]
254
282
  end
255
283
  @d.meta_def(:supports_foreign_key_parsing?){true}
@@ -273,7 +301,7 @@ END_MIG
273
301
 
274
302
  it "should handle circular dependencies when dumping a migration with foreign keys" do
275
303
  @d.meta_def(:tables){|o| [:t1, :t2]}
276
- @d.meta_def(:schema) do |t|
304
+ @d.meta_def(:schema) do |t, *o|
277
305
  t == :t1 ? [[:c2, {:db_type=>'integer'}]] : [[:c1, {:db_type=>'integer'}]]
278
306
  end
279
307
  @d.meta_def(:supports_foreign_key_parsing?){true}
@@ -301,7 +329,7 @@ END_MIG
301
329
 
302
330
  it "should sort topologically even if the database raises an error when trying to parse foreign keys for a non-existent table" do
303
331
  @d.meta_def(:tables){|o| [:t1, :t2]}
304
- @d.meta_def(:schema) do |t|
332
+ @d.meta_def(:schema) do |t, *o|
305
333
  t == :t1 ? [[:c2, {:db_type=>'integer'}]] : [[:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true}]]
306
334
  end
307
335
  @d.meta_def(:supports_foreign_key_parsing?){true}
@@ -582,7 +610,7 @@ END_MIG
582
610
 
583
611
  it "should support dumping just foreign_keys as a migration" do
584
612
  @d.meta_def(:tables){|o| [:t1, :t2, :t3]}
585
- @d.meta_def(:schema) do |t|
613
+ @d.meta_def(:schema) do |t, *o|
586
614
  t == :t1 ? [[:c2, {:db_type=>'integer'}]] : [[:c1, {:db_type=>'integer'}]]
587
615
  end
588
616
  @d.meta_def(:supports_foreign_key_parsing?){true}
@@ -3,7 +3,9 @@ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
3
3
  describe Sequel::Model, "set_schema" do
4
4
  before do
5
5
  @model = Class.new(Sequel::Model(:items))
6
- @model.plugin :schema
6
+ deprecated do
7
+ @model.plugin :schema
8
+ end
7
9
  end
8
10
 
9
11
  it "sets schema with implicit table name" do
@@ -26,11 +28,13 @@ end
26
28
  describe Sequel::Model, "create_table and schema" do
27
29
  before do
28
30
  @model = Class.new(Sequel::Model)
29
- @model.class_eval do
30
- plugin :schema
31
- set_schema(:items) do
32
- text :name
33
- float :price, :null => false
31
+ deprecated do
32
+ @model.class_eval do
33
+ plugin :schema
34
+ set_schema(:items) do
35
+ text :name
36
+ float :price, :null => false
37
+ end
34
38
  end
35
39
  end
36
40
  DB.reset
@@ -76,7 +80,9 @@ end
76
80
  describe Sequel::Model, "schema methods" do
77
81
  before do
78
82
  @model = Class.new(Sequel::Model(:items))
79
- @model.plugin :schema
83
+ deprecated do
84
+ @model.plugin :schema
85
+ end
80
86
  DB.reset
81
87
  end
82
88
 
@@ -4,7 +4,9 @@ describe "scissors plugin" do
4
4
  before do
5
5
  @m = Class.new(Sequel::Model(:items))
6
6
  @m.use_transactions = true
7
- @m.plugin :scissors
7
+ deprecated do
8
+ @m.plugin :scissors
9
+ end
8
10
  @m.db.sqls
9
11
  end
10
12
 
@@ -59,7 +59,7 @@ end
59
59
  # SEQUEL5: Remove
60
60
  unless Sequel.mock.dataset.frozen?
61
61
  describe "Dataset#db=" do
62
- it "should change the dataset's database" do
62
+ deprecated "should change the dataset's database" do
63
63
  db = Sequel.mock
64
64
  ds = db[:items].extension(:sequel_3_dataset_methods)
65
65
  db2 = Sequel.mock
@@ -68,14 +68,14 @@ unless Sequel.mock.dataset.frozen?
68
68
  ds.db.wont_equal db
69
69
  end
70
70
 
71
- it "should raise error for frozen datasets" do
71
+ deprecated "should raise error for frozen datasets" do
72
72
  ds = Sequel.mock.dataset.extension(:sequel_3_dataset_methods).freeze
73
73
  proc{ds.db = ds.db}.must_raise RuntimeError
74
74
  end
75
75
  end
76
76
 
77
77
  describe "Dataset#opts=" do
78
- it "should change the dataset's opts" do
78
+ deprecated "should change the dataset's opts" do
79
79
  db = Sequel.mock
80
80
  ds = db[:items].extension(:sequel_3_dataset_methods)
81
81
  ds.sql.must_equal 'SELECT * FROM items'
@@ -84,7 +84,7 @@ unless Sequel.mock.dataset.frozen?
84
84
  ds.opts.must_equal({})
85
85
  end
86
86
 
87
- it "should raise error for frozen datasets" do
87
+ deprecated "should raise error for frozen datasets" do
88
88
  ds = Sequel.mock.dataset.extension(:sequel_3_dataset_methods).freeze
89
89
  proc{ds.opts = {}}.must_raise RuntimeError
90
90
  end
@@ -12,6 +12,13 @@ describe "Serialization plugin" do
12
12
  DB.reset
13
13
  end
14
14
 
15
+ deprecated "should allow access to serialization_module" do
16
+ @c.plugin :serialization, :yaml, :abc
17
+ @c.serialization_module.must_be_kind_of Module
18
+ @c.serialization_module = v = Module.new
19
+ @c.serialization_module.must_equal v
20
+ end
21
+
15
22
  it "should allow setting additional serializable attributes via plugin :serialization call" do
16
23
  @c.plugin :serialization, :yaml, :abc
17
24
  @c.create(:abc => 1, :def=> 2)
@@ -366,6 +373,5 @@ describe "Serialization plugin" do
366
373
  @c.freeze
367
374
  @c.serialization_map.frozen?.must_equal true
368
375
  @c.deserialization_map.frozen?.must_equal true
369
- @c.serialization_module.frozen?.must_equal true
370
376
  end
371
377
  end
@@ -27,7 +27,7 @@ describe "Sequel::Dataset #set_defaults" do
27
27
 
28
28
  # SEQUEL5: Remove
29
29
  unless Sequel.mock.dataset.frozen?
30
- it "should have working mutation method" do
30
+ deprecated "should have working mutation method" do
31
31
  @ds = Sequel.mock.dataset.from(:items).extension(:set_overrides)
32
32
  @ds.set_defaults!(:x=>1)
33
33
  @ds.insert_sql.must_equal "INSERT INTO items (x) VALUES (1)"
@@ -58,7 +58,7 @@ describe "Sequel::Dataset #set_overrides" do
58
58
 
59
59
  # SEQUEL5: Remove
60
60
  unless Sequel.mock.dataset.frozen?
61
- it "should have working mutation method" do
61
+ deprecated "should have working mutation method" do
62
62
  @ds = Sequel.mock.dataset.from(:items).extension(:set_overrides)
63
63
  @ds.set_overrides!(:x=>1)
64
64
  @ds.insert_sql.must_equal "INSERT INTO items (x) VALUES (1)"
@@ -93,26 +93,30 @@ describe "Shared caching behavior" do
93
93
  end
94
94
 
95
95
  it "should not use a simple primary key lookup if the prepared_statements_associations method is being used" do
96
- c2 = Class.new(Sequel::Model(@db[:not_caching_model].with_fetch(:id=>1)))
97
- c = Class.new(Sequel::Model(@db[:lookup_model]))
98
- c.class_eval do
99
- plugin :prepared_statements_associations
100
- columns :id, :caching_model_id
101
- many_to_one :caching_model, :class=>c2
96
+ deprecated do
97
+ c2 = Class.new(Sequel::Model(@db[:not_caching_model].with_fetch(:id=>1)))
98
+ c = Class.new(Sequel::Model(@db[:lookup_model]))
99
+ c.class_eval do
100
+ plugin :prepared_statements_associations
101
+ columns :id, :caching_model_id
102
+ many_to_one :caching_model, :class=>c2
103
+ end
104
+ c.load(:id=>3, :caching_model_id=>1).caching_model.must_equal c2.load(:id=>1)
105
+ @db.sqls.wont_equal []
102
106
  end
103
- c.load(:id=>3, :caching_model_id=>1).caching_model.must_equal c2.load(:id=>1)
104
- @db.sqls.wont_equal []
105
107
  end
106
108
 
107
109
  it "should use a simple primary key lookup if the prepared_statements_associations method is being used but associated model also uses caching" do
108
- c = Class.new(Sequel::Model(:lookup_model))
109
- c.class_eval do
110
- plugin :prepared_statements_associations
111
- columns :id, :caching_model_id
112
- many_to_one :caching_model
110
+ deprecated do
111
+ c = Class.new(Sequel::Model(:lookup_model))
112
+ c.class_eval do
113
+ plugin :prepared_statements_associations
114
+ columns :id, :caching_model_id
115
+ many_to_one :caching_model
116
+ end
117
+ c.load(:id=>3, :caching_model_id=>1).caching_model.must_be_same_as(@cm1)
118
+ @db.sqls.must_equal []
113
119
  end
114
- c.load(:id=>3, :caching_model_id=>1).caching_model.must_be_same_as(@cm1)
115
- @db.sqls.must_equal []
116
120
  end
117
121
  end
118
122
 
@@ -15,8 +15,8 @@ unless Object.const_defined?('Sequel') && Sequel.const_defined?('Model')
15
15
  $:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
16
16
  require 'sequel'
17
17
  end
18
- Sequel::Deprecation.backtrace_filter = lambda{|line, lineno| lineno < 4 || line =~ /_spec\.rb/}
19
- SEQUEL_EXTENSIONS_NO_DEPRECATION_WARNING = true
18
+
19
+ require "#{File.dirname(File.dirname(__FILE__))}/deprecation_helper.rb"
20
20
 
21
21
  begin
22
22
  # Attempt to load ActiveSupport blank extension and inflector first, so Sequel
@@ -35,9 +35,13 @@ def skip_warn(s)
35
35
  warn "Skipping test of #{s}" if ENV["SKIPPED_TEST_WARN"]
36
36
  end
37
37
 
38
+ # SEQUEL5: Remove
39
+ output = Sequel::Deprecation.output
40
+ Sequel::Deprecation.output = nil
38
41
  Sequel.quote_identifiers = false
39
42
  Sequel.identifier_input_method = nil
40
43
  Sequel.identifier_output_method = nil
44
+ Sequel::Deprecation.output = output
41
45
 
42
46
  class << Sequel::Model
43
47
  attr_writer :db_schema
@@ -54,7 +58,7 @@ class << Sequel::Model
54
58
  end
55
59
 
56
60
  Sequel::Model.use_transactions = false
57
- Sequel.cache_anonymous_models = false
61
+ Sequel::Model.cache_anonymous_models = false
58
62
 
59
63
  db = Sequel.mock(:fetch=>{:id => 1, :x => 1}, :numrows=>1, :autoid=>proc{|sql| 10})
60
64
  def db.schema(*) [[:id, {:primary_key=>true}]] end
@@ -1,22 +1,57 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
2
 
3
3
  describe "Sequel::Plugins::SplitValues" do
4
+ before do
5
+ @c = Class.new(Sequel::Model(:a))
6
+ @c.columns :id, :x
7
+ @c.plugin :split_values
8
+ end
9
+
4
10
  it "stores non-columns in a separate hash" do
5
- c = Class.new(Sequel::Model(:a))
6
- c.columns :id, :x
7
- c.plugin :split_values
8
- c.dataset = c.dataset.with_fetch(:id=>1, :x=>2, :y=>3)
9
- o = c.first
10
- c.db.reset
11
-
12
- o.must_equal c.load(:id=>1, :x=>2)
11
+ @c.dataset = @c.dataset.with_fetch(:id=>1, :x=>2, :y=>3)
12
+ o = @c.first
13
+ @c.db.reset
14
+
15
+ o.must_equal @c.load(:id=>1, :x=>2)
13
16
  o[:id].must_equal 1
14
17
  o[:x].must_equal 2
15
18
  o[:y].must_equal 3
16
- {c.load(:id=>1, :x=>2)=>4}[o].must_equal 4
19
+ {@c.load(:id=>1, :x=>2)=>4}[o].must_equal 4
17
20
  o.values.must_equal(:id=>1, :x=>2)
18
21
 
19
22
  o.save
20
- c.db.sqls.must_equal ["UPDATE a SET x = 2 WHERE (id = 1)"]
23
+ @c.db.sqls.must_equal ["UPDATE a SET x = 2 WHERE (id = 1)"]
24
+ end
25
+
26
+ it "handles false values" do
27
+ @c.dataset = @c.dataset.with_fetch(:id=>1, :x=>false, :y=>3)
28
+ o = @c.first
29
+ @c.db.reset
30
+
31
+ o.must_equal @c.load(:id=>1, :x=>false)
32
+ o[:id].must_equal 1
33
+ o[:x].must_equal false
34
+ o[:y].must_equal 3
35
+ {@c.load(:id=>1, :x=>false)=>4}[o].must_equal 4
36
+ o.values.must_equal(:id=>1, :x=>false)
37
+
38
+ o.save
39
+ @c.db.sqls.must_equal ["UPDATE a SET x = 'f' WHERE (id = 1)"]
40
+ end
41
+
42
+ it "handles nil values" do
43
+ @c.dataset = @c.dataset.with_fetch(:id=>1, :x=>nil, :y=>3)
44
+ o = @c.first
45
+ @c.db.reset
46
+
47
+ o.must_equal @c.load(:id=>1, :x=>nil)
48
+ o[:id].must_equal 1
49
+ o[:x].must_be_nil
50
+ o[:y].must_equal 3
51
+ {@c.load(:id=>1, :x=>nil)=>4}[o].must_equal 4
52
+ o.values.must_equal(:id=>1, :x=>nil)
53
+
54
+ o.save
55
+ @c.db.sqls.must_equal ["UPDATE a SET x = NULL WHERE (id = 1)"]
21
56
  end
22
57
  end
@@ -45,8 +45,8 @@ describe "string_agg extension" do
45
45
  ds.literal(@sa4).must_equal "list(DISTINCT c, ',' ORDER BY o)"
46
46
  end
47
47
 
48
- it "should correctly literalize on MySQL, H2, HSQLDB, CUBRID" do
49
- [:mysql, :h2, :hsqldb, :cubrid].each do |type|
48
+ it "should correctly literalize on MySQL, H2, HSQLDB" do
49
+ [:mysql, :h2, :hsqldb].each do |type|
50
50
  db = dbf.call(type)
51
51
  db.meta_def(:database_type){type}
52
52
  ds = db.dataset.with_quote_identifiers(false).with_extend{def input_identifier(v) v.to_s end}
@@ -13,7 +13,7 @@ describe "subset_conditions plugin" do
13
13
  @c.subset(:active, :active)
14
14
  @c.where(@c.active_conditions).sql.must_equal @c.active.sql
15
15
 
16
- @c.subset(:active_published, :active, :published => true)
16
+ @c.subset(:active_published, Sequel.&(:active, :published => true))
17
17
  @c.where(@c.active_published_conditions).sql.must_equal @c.active_published.sql
18
18
  @c.where(Sequel.&(@c.active_conditions, @c.published_conditions)).sql.must_equal @c.active_published.sql
19
19
  @c.where(Sequel.|(@c.active_conditions, @c.published_conditions)).sql.must_equal "SELECT * FROM a WHERE (active OR (published IS TRUE))"
@@ -25,8 +25,8 @@ describe "subset_conditions plugin" do
25
25
  @c.subset(:published, &p1)
26
26
  @c.where(@c.published_conditions).sql.must_equal @c.published.sql
27
27
 
28
- p2 = proc{:active}
29
- @c.subset(:active, &p2)
28
+ p2 = :active
29
+ @c.subset(:active, p2)
30
30
  @c.where(@c.active_conditions).sql.must_equal @c.active.sql
31
31
 
32
32
  @c.subset(:active_published, p2, &p1)