sequel 4.22.0 → 4.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +22 -0
  3. data/README.rdoc +6 -0
  4. data/Rakefile +59 -81
  5. data/doc/migration.rdoc +2 -0
  6. data/doc/release_notes/4.23.0.txt +65 -0
  7. data/doc/sharding.rdoc +16 -14
  8. data/doc/testing.rdoc +61 -77
  9. data/lib/sequel/adapters/jdbc.rb +1 -0
  10. data/lib/sequel/adapters/mock.rb +0 -1
  11. data/lib/sequel/adapters/postgres.rb +1 -0
  12. data/lib/sequel/adapters/postgresql.rb +1 -0
  13. data/lib/sequel/adapters/shared/postgres.rb +3 -3
  14. data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
  15. data/lib/sequel/connection_pool/threaded.rb +9 -1
  16. data/lib/sequel/database/connecting.rb +1 -1
  17. data/lib/sequel/database/transactions.rb +2 -1
  18. data/lib/sequel/dataset/prepared_statements.rb +1 -1
  19. data/lib/sequel/extensions/constraint_validations.rb +12 -12
  20. data/lib/sequel/extensions/date_arithmetic.rb +0 -4
  21. data/lib/sequel/extensions/pagination.rb +14 -2
  22. data/lib/sequel/extensions/pg_enum.rb +2 -2
  23. data/lib/sequel/extensions/pg_hstore.rb +1 -1
  24. data/lib/sequel/extensions/pg_json_ops.rb +2 -2
  25. data/lib/sequel/plugins/csv_serializer.rb +2 -0
  26. data/lib/sequel/plugins/delay_add_association.rb +50 -0
  27. data/lib/sequel/plugins/list.rb +2 -2
  28. data/lib/sequel/plugins/nested_attributes.rb +8 -28
  29. data/lib/sequel/plugins/update_refresh.rb +50 -0
  30. data/lib/sequel/plugins/validate_associated.rb +55 -0
  31. data/lib/sequel/version.rb +1 -1
  32. data/spec/adapters/db2_spec.rb +29 -29
  33. data/spec/adapters/firebird_spec.rb +97 -103
  34. data/spec/adapters/informix_spec.rb +25 -25
  35. data/spec/adapters/mssql_spec.rb +156 -172
  36. data/spec/adapters/mysql_spec.rb +334 -359
  37. data/spec/adapters/oracle_spec.rb +67 -69
  38. data/spec/adapters/postgres_spec.rb +1298 -1249
  39. data/spec/adapters/spec_helper.rb +2 -35
  40. data/spec/adapters/sqlanywhere_spec.rb +39 -39
  41. data/spec/adapters/sqlite_spec.rb +203 -200
  42. data/spec/bin_spec.rb +57 -59
  43. data/spec/core/connection_pool_spec.rb +402 -401
  44. data/spec/core/database_spec.rb +953 -944
  45. data/spec/core/dataset_spec.rb +2178 -2168
  46. data/spec/core/deprecated_spec.rb +19 -19
  47. data/spec/core/expression_filters_spec.rb +415 -415
  48. data/spec/core/mock_adapter_spec.rb +212 -212
  49. data/spec/core/object_graph_spec.rb +73 -73
  50. data/spec/core/placeholder_literalizer_spec.rb +71 -71
  51. data/spec/core/schema_generator_spec.rb +44 -44
  52. data/spec/core/schema_spec.rb +470 -472
  53. data/spec/core/spec_helper.rb +5 -20
  54. data/spec/core/version_spec.rb +2 -2
  55. data/spec/core_extensions_spec.rb +320 -320
  56. data/spec/extensions/accessed_columns_spec.rb +12 -12
  57. data/spec/extensions/active_model_spec.rb +3 -3
  58. data/spec/extensions/after_initialize_spec.rb +2 -2
  59. data/spec/extensions/arbitrary_servers_spec.rb +23 -23
  60. data/spec/extensions/association_dependencies_spec.rb +34 -34
  61. data/spec/extensions/association_pks_spec.rb +98 -98
  62. data/spec/extensions/association_proxies_spec.rb +33 -33
  63. data/spec/extensions/auto_validations_spec.rb +46 -46
  64. data/spec/extensions/blacklist_security_spec.rb +19 -18
  65. data/spec/extensions/blank_spec.rb +36 -36
  66. data/spec/extensions/boolean_readers_spec.rb +36 -36
  67. data/spec/extensions/caching_spec.rb +82 -82
  68. data/spec/extensions/class_table_inheritance_spec.rb +72 -72
  69. data/spec/extensions/column_conflicts_spec.rb +19 -14
  70. data/spec/extensions/column_select_spec.rb +19 -19
  71. data/spec/extensions/columns_introspection_spec.rb +43 -43
  72. data/spec/extensions/composition_spec.rb +64 -64
  73. data/spec/extensions/connection_validator_spec.rb +92 -90
  74. data/spec/extensions/constraint_validations_plugin_spec.rb +92 -92
  75. data/spec/extensions/constraint_validations_spec.rb +80 -80
  76. data/spec/extensions/core_refinements_spec.rb +220 -220
  77. data/spec/extensions/csv_serializer_spec.rb +44 -44
  78. data/spec/extensions/current_datetime_timestamp_spec.rb +8 -8
  79. data/spec/extensions/dataset_associations_spec.rb +65 -65
  80. data/spec/extensions/dataset_source_alias_spec.rb +16 -16
  81. data/spec/extensions/date_arithmetic_spec.rb +51 -58
  82. data/spec/extensions/defaults_setter_spec.rb +19 -19
  83. data/spec/extensions/delay_add_association_spec.rb +52 -0
  84. data/spec/extensions/dirty_spec.rb +51 -51
  85. data/spec/extensions/eager_each_spec.rb +8 -8
  86. data/spec/extensions/empty_array_ignore_nulls_spec.rb +10 -10
  87. data/spec/extensions/error_splitter_spec.rb +2 -2
  88. data/spec/extensions/error_sql_spec.rb +4 -4
  89. data/spec/extensions/eval_inspect_spec.rb +3 -3
  90. data/spec/extensions/filter_having_spec.rb +8 -8
  91. data/spec/extensions/force_encoding_spec.rb +30 -30
  92. data/spec/extensions/from_block_spec.rb +7 -7
  93. data/spec/extensions/graph_each_spec.rb +19 -19
  94. data/spec/extensions/hash_aliases_spec.rb +5 -5
  95. data/spec/extensions/hook_class_methods_spec.rb +100 -100
  96. data/spec/extensions/inflector_spec.rb +54 -54
  97. data/spec/extensions/input_transformer_spec.rb +10 -10
  98. data/spec/extensions/insert_returning_select_spec.rb +8 -8
  99. data/spec/extensions/instance_filters_spec.rb +26 -26
  100. data/spec/extensions/instance_hooks_spec.rb +85 -85
  101. data/spec/extensions/json_serializer_spec.rb +68 -68
  102. data/spec/extensions/lazy_attributes_spec.rb +49 -49
  103. data/spec/extensions/list_spec.rb +77 -75
  104. data/spec/extensions/looser_typecasting_spec.rb +16 -16
  105. data/spec/extensions/many_through_many_spec.rb +627 -627
  106. data/spec/extensions/meta_def_spec.rb +7 -7
  107. data/spec/extensions/migration_spec.rb +217 -217
  108. data/spec/extensions/modification_detection_spec.rb +20 -20
  109. data/spec/extensions/mssql_optimistic_locking_spec.rb +21 -21
  110. data/spec/extensions/named_timezones_spec.rb +18 -18
  111. data/spec/extensions/nested_attributes_spec.rb +107 -107
  112. data/spec/extensions/null_dataset_spec.rb +24 -24
  113. data/spec/extensions/optimistic_locking_spec.rb +21 -21
  114. data/spec/extensions/pagination_spec.rb +52 -52
  115. data/spec/extensions/pg_array_associations_spec.rb +273 -273
  116. data/spec/extensions/pg_array_ops_spec.rb +52 -52
  117. data/spec/extensions/pg_array_spec.rb +152 -152
  118. data/spec/extensions/pg_enum_spec.rb +13 -13
  119. data/spec/extensions/pg_hstore_ops_spec.rb +63 -63
  120. data/spec/extensions/pg_hstore_spec.rb +84 -84
  121. data/spec/extensions/pg_inet_spec.rb +15 -15
  122. data/spec/extensions/pg_interval_spec.rb +29 -29
  123. data/spec/extensions/pg_json_ops_spec.rb +86 -84
  124. data/spec/extensions/pg_json_spec.rb +104 -104
  125. data/spec/extensions/pg_loose_count_spec.rb +6 -6
  126. data/spec/extensions/pg_range_ops_spec.rb +24 -24
  127. data/spec/extensions/pg_range_spec.rb +143 -143
  128. data/spec/extensions/pg_row_ops_spec.rb +14 -14
  129. data/spec/extensions/pg_row_plugin_spec.rb +12 -12
  130. data/spec/extensions/pg_row_spec.rb +118 -118
  131. data/spec/extensions/pg_static_cache_updater_spec.rb +28 -28
  132. data/spec/extensions/pg_typecast_on_load_spec.rb +21 -21
  133. data/spec/extensions/prepared_statements_associations_spec.rb +42 -42
  134. data/spec/extensions/prepared_statements_safe_spec.rb +18 -18
  135. data/spec/extensions/prepared_statements_spec.rb +28 -28
  136. data/spec/extensions/prepared_statements_with_pk_spec.rb +11 -11
  137. data/spec/extensions/pretty_table_spec.rb +16 -16
  138. data/spec/extensions/query_literals_spec.rb +37 -37
  139. data/spec/extensions/query_spec.rb +32 -32
  140. data/spec/extensions/rcte_tree_spec.rb +141 -141
  141. data/spec/extensions/round_timestamps_spec.rb +21 -21
  142. data/spec/extensions/schema_caching_spec.rb +8 -8
  143. data/spec/extensions/schema_dumper_spec.rb +78 -78
  144. data/spec/extensions/schema_spec.rb +31 -27
  145. data/spec/extensions/scissors_spec.rb +3 -3
  146. data/spec/extensions/select_remove_spec.rb +14 -14
  147. data/spec/extensions/sequel_3_dataset_methods_spec.rb +28 -28
  148. data/spec/extensions/serialization_modification_detection_spec.rb +33 -33
  149. data/spec/extensions/serialization_spec.rb +79 -78
  150. data/spec/extensions/server_block_spec.rb +17 -17
  151. data/spec/extensions/set_overrides_spec.rb +30 -30
  152. data/spec/extensions/sharding_spec.rb +65 -65
  153. data/spec/extensions/shared_caching_spec.rb +29 -29
  154. data/spec/extensions/single_table_inheritance_spec.rb +79 -79
  155. data/spec/extensions/skip_create_refresh_spec.rb +3 -3
  156. data/spec/extensions/spec_helper.rb +4 -29
  157. data/spec/extensions/split_array_nil_spec.rb +9 -9
  158. data/spec/extensions/split_values_spec.rb +7 -7
  159. data/spec/extensions/sql_expr_spec.rb +32 -32
  160. data/spec/extensions/static_cache_spec.rb +123 -123
  161. data/spec/extensions/string_date_time_spec.rb +34 -34
  162. data/spec/extensions/string_stripper_spec.rb +15 -15
  163. data/spec/extensions/subclasses_spec.rb +31 -31
  164. data/spec/extensions/table_select_spec.rb +15 -15
  165. data/spec/extensions/tactical_eager_loading_spec.rb +23 -23
  166. data/spec/extensions/thread_local_timezones_spec.rb +13 -13
  167. data/spec/extensions/timestamps_spec.rb +40 -40
  168. data/spec/extensions/to_dot_spec.rb +34 -34
  169. data/spec/extensions/touch_spec.rb +52 -52
  170. data/spec/extensions/tree_spec.rb +72 -72
  171. data/spec/extensions/typecast_on_load_spec.rb +25 -25
  172. data/spec/extensions/unlimited_update_spec.rb +2 -2
  173. data/spec/extensions/update_or_create_spec.rb +36 -36
  174. data/spec/extensions/update_primary_key_spec.rb +35 -35
  175. data/spec/extensions/update_refresh_spec.rb +41 -0
  176. data/spec/extensions/validate_associated_spec.rb +52 -0
  177. data/spec/extensions/validation_class_methods_spec.rb +314 -317
  178. data/spec/extensions/validation_helpers_spec.rb +195 -195
  179. data/spec/extensions/xml_serializer_spec.rb +48 -48
  180. data/spec/guards_helper.rb +55 -0
  181. data/spec/integration/associations_test.rb +1089 -1088
  182. data/spec/integration/database_test.rb +29 -29
  183. data/spec/integration/dataset_test.rb +661 -661
  184. data/spec/integration/eager_loader_test.rb +147 -147
  185. data/spec/integration/migrator_test.rb +122 -122
  186. data/spec/integration/model_test.rb +70 -70
  187. data/spec/integration/plugin_test.rb +682 -640
  188. data/spec/integration/prepared_statement_test.rb +172 -172
  189. data/spec/integration/schema_test.rb +245 -245
  190. data/spec/integration/spec_helper.rb +1 -64
  191. data/spec/integration/timezone_test.rb +17 -17
  192. data/spec/integration/transaction_test.rb +87 -87
  193. data/spec/integration/type_test.rb +33 -33
  194. data/spec/model/association_reflection_spec.rb +130 -121
  195. data/spec/model/associations_spec.rb +1112 -1113
  196. data/spec/model/base_spec.rb +197 -196
  197. data/spec/model/class_dataset_methods_spec.rb +118 -118
  198. data/spec/model/dataset_methods_spec.rb +49 -49
  199. data/spec/model/eager_loading_spec.rb +705 -702
  200. data/spec/model/hooks_spec.rb +169 -168
  201. data/spec/model/inflector_spec.rb +5 -5
  202. data/spec/model/model_spec.rb +287 -297
  203. data/spec/model/plugins_spec.rb +47 -47
  204. data/spec/model/record_spec.rb +534 -535
  205. data/spec/model/spec_helper.rb +3 -21
  206. data/spec/model/validations_spec.rb +72 -70
  207. data/spec/spec_config.rb +8 -0
  208. metadata +41 -9
  209. data/lib/sequel/adapters/fdbsql.rb +0 -286
  210. data/lib/sequel/adapters/jdbc/fdbsql.rb +0 -66
  211. data/lib/sequel/adapters/openbase.rb +0 -54
  212. data/lib/sequel/adapters/shared/fdbsql.rb +0 -550
  213. data/spec/adapters/fdbsql_spec.rb +0 -429
  214. data/spec/rspec_helper.rb +0 -22
@@ -1,429 +0,0 @@
1
- SEQUEL_ADAPTER_TEST = :fdbsql
2
-
3
- require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
4
-
5
- describe 'Fdbsql' do
6
- describe 'Database' do
7
- before(:all) do
8
- @db = DB
9
- end
10
-
11
- describe 'schema_parsing' do
12
- after do
13
- @db.drop_table?(:test)
14
- end
15
-
16
- specify 'without primary key' do
17
- @db.create_table(:test) do
18
- text :name
19
- int :value
20
- end
21
- schema = DB.schema(:test, :reload => true)
22
- schema.count.should == 2
23
- schema[0][0].should == :name
24
- schema[1][0].should == :value
25
- schema.each {|col| col[1][:primary_key].should == nil}
26
- end
27
-
28
- specify 'with one primary key' do
29
- @db.create_table(:test) do
30
- text :name
31
- primary_key :id
32
- end
33
- schema = DB.schema(:test, :reload => true)
34
- schema.count.should == 2
35
- id_col = schema[0]
36
- name_col = schema[1]
37
- name_col[0].should == :name
38
- id_col[0].should == :id
39
- name_col[1][:primary_key].should == nil
40
- id_col[1][:primary_key].should == true
41
- end
42
-
43
- specify 'with multiple primary keys' do
44
- @db.create_table(:test) do
45
- Integer :id
46
- Integer :id2
47
- primary_key [:id, :id2]
48
- end
49
- schema = DB.schema(:test, :reload => true)
50
- schema.count.should == 2
51
- id_col = schema[0]
52
- id2_col = schema[1]
53
- id_col[0].should == :id
54
- id2_col[0].should == :id2
55
- id_col[1][:primary_key].should == true
56
- id2_col[1][:primary_key].should == true
57
- end
58
-
59
- specify 'with other constraints' do
60
- @db.create_table(:test) do
61
- primary_key :id
62
- Integer :unique, :unique => true
63
- end
64
- schema = DB.schema(:test, :reload => true)
65
- schema.count.should == 2
66
- id_col = schema[0]
67
- unique_col = schema[1]
68
- id_col[0].should == :id
69
- unique_col[0].should == :unique
70
- id_col[1][:primary_key].should == true
71
- unique_col[1][:primary_key].should == nil
72
- end
73
- after do
74
- @db.drop_table?(:other_table)
75
- end
76
- specify 'with other tables' do
77
- @db.create_table(:test) do
78
- Integer :id
79
- text :name
80
- end
81
- @db.create_table(:other_table) do
82
- primary_key :id
83
- varchar :name, :unique => true
84
- end
85
- schema = DB.schema(:test, :reload => true)
86
- schema.count.should == 2
87
- schema.each {|col| col[1][:primary_key].should == nil}
88
- end
89
-
90
- describe 'with explicit schema' do
91
- before do
92
- @db.create_table(:test) do
93
- primary_key :id
94
- end
95
- @schema = @db['SELECT CURRENT_SCHEMA'].first.values.first
96
- @second_schema = @schema + "--2"
97
- @db.create_table(Sequel.qualify(@second_schema,:test)) do
98
- primary_key :id2
99
- Integer :id
100
- end
101
- end
102
- after do
103
- @db.drop_table?(Sequel.qualify(@second_schema,:test))
104
- @db.drop_table?(:test)
105
- end
106
-
107
- specify 'gets info for correct table' do
108
- schema = DB.schema(:test, :reload => true, :schema => @second_schema)
109
- schema.count.should == 2
110
- id2_col = schema[0]
111
- id_col = schema[1]
112
- id_col[0].should == :id
113
- id2_col[0].should == :id2
114
- id_col[1][:primary_key].should == nil
115
- id2_col[1][:primary_key].should == true
116
- end
117
- end
118
- end
119
-
120
- describe 'primary_key' do
121
- after do
122
- @db.drop_table?(:test)
123
- @db.drop_table?(:other_table)
124
- end
125
-
126
- specify 'without primary key' do
127
- @db.create_table(:test) do
128
- text :name
129
- int :value
130
- end
131
- DB.primary_key(:test).should == nil
132
- end
133
-
134
- specify 'with one primary key' do
135
- @db.create_table(:test) do
136
- text :name
137
- primary_key :id
138
- end
139
- DB.primary_key(:test).should == :id
140
- end
141
-
142
- specify 'with multiple primary keys' do
143
- @db.create_table(:test) do
144
- Integer :id
145
- Integer :id2
146
- primary_key [:id, :id2]
147
- end
148
- DB.primary_key(:test).should == [:id, :id2]
149
- end
150
-
151
- specify 'with other constraints' do
152
- @db.create_table(:test) do
153
- primary_key :id
154
- Integer :unique, :unique => true
155
- end
156
- DB.primary_key(:test).should == :id
157
- end
158
-
159
- specify 'with other tables' do
160
- @db.create_table(:test) do
161
- Integer :id
162
- text :name
163
- end
164
- @db.create_table(:other_table) do
165
- primary_key :id
166
- varchar :name, :unique => true
167
- end
168
- DB.primary_key(:other_table).should == :id
169
- end
170
-
171
- specify 'responds to alter table' do
172
- @db.create_table(:test) do
173
- Integer :id
174
- text :name
175
- end
176
- @db.alter_table(:test) do
177
- add_primary_key :quid
178
- end
179
- DB.primary_key(:test).should == :quid
180
- end
181
-
182
- describe 'with explicit schema' do
183
- before do
184
- @db.create_table(:test) do
185
- primary_key :id
186
- end
187
- @schema = @db['SELECT CURRENT_SCHEMA'].first.values.first
188
- @second_schema = @schema + "--2"
189
- @db.create_table(Sequel.qualify(@second_schema,:test)) do
190
- primary_key :id2
191
- end
192
- end
193
- after do
194
- @db.drop_table?(Sequel.qualify(@second_schema,:test))
195
- @db.drop_table?(:test)
196
- end
197
-
198
- specify 'gets correct primary key' do
199
- DB.primary_key(:test, :schema => @second_schema).should == :id2
200
- end
201
- end
202
- end
203
-
204
- describe '#tables' do
205
- before do
206
- @schema = @db['SELECT CURRENT_SCHEMA'].first.values.first
207
- @second_schema = @schema + "--2"
208
- @db.create_table(:test) do
209
- primary_key :id
210
- end
211
- @db.create_table(Sequel.qualify(@second_schema,:test2)) do
212
- primary_key :id
213
- end
214
- end
215
- after do
216
- @db.drop_table?(Sequel.qualify(@second_schema,:test2))
217
- @db.drop_table?(:test)
218
- end
219
- specify 'on explicit schema' do
220
- tables = @db.tables(:schema => @second_schema)
221
- tables.should include(:test2)
222
- tables.should_not include(:test)
223
- end
224
- specify 'qualified' do
225
- tables = @db.tables(:qualify => true)
226
- tables.should include(Sequel::SQL::QualifiedIdentifier.new(@schema.to_sym, :test))
227
- tables.should_not include(:test)
228
- end
229
- end
230
-
231
- describe '#views' do
232
- def drop_things
233
- @db.drop_view(Sequel.qualify(@second_schema,:test_view2), :if_exists => true)
234
- @db.drop_table?(Sequel.qualify(@second_schema,:test_table))
235
- @db.drop_view(:test_view, :if_exists => true)
236
- @db.drop_table?(:test_table)
237
- end
238
- before do
239
- @schema = @db['SELECT CURRENT_SCHEMA'].single_value
240
- @second_schema = @schema + "--2"
241
- drop_things
242
- @db.create_table(:test_table){Integer :a}
243
- @db.create_view :test_view, @db[:test_table]
244
- @db.create_table(Sequel.qualify(@second_schema,:test_table)) do
245
- Integer :b
246
- end
247
- @db.create_view(Sequel.qualify(@second_schema, :test_view2),
248
- @db[Sequel.qualify(@second_schema, :test_table)])
249
- end
250
- after do
251
- drop_things
252
- end
253
- specify 'on explicit schema' do
254
- views = @db.views(:schema => @second_schema)
255
- views.should include(:test_view2)
256
- views.should_not include(:test_view)
257
- end
258
- specify 'qualified' do
259
- views = @db.views(:qualify => true)
260
- views.should include(Sequel::SQL::QualifiedIdentifier.new(@schema.to_sym, :test_view))
261
- views.should_not include(:test)
262
- end
263
- end
264
-
265
- describe 'prepared statements' do
266
- def create_table
267
- @db.create_table!(:test) {Integer :a; Text :b}
268
- @db[:test].insert(1, 'blueberries')
269
- @db[:test].insert(2, 'trucks')
270
- @db[:test].insert(3, 'foxes')
271
- end
272
- def drop_table
273
- @db.drop_table?(:test)
274
- end
275
- before do
276
- create_table
277
- end
278
- after do
279
- drop_table
280
- end
281
-
282
- it 're-prepares on stale statement' do
283
- @db[:test].filter(:a=>:$n).prepare(:all, :select_a).call(:n=>2).to_a.should == [{:a => 2, :b => 'trucks'}]
284
- drop_table
285
- create_table
286
- @db[:test].filter(:a=>:$n).prepare(:all, :select_a).call(:n=>2).to_a.should == [{:a => 2, :b => 'trucks'}]
287
- end
288
-
289
- it 'can call already prepared' do
290
- @db[:test].filter(:a=>:$n).prepare(:all, :select_a).call(:n=>2).to_a.should == [{:a => 2, :b => 'trucks'}]
291
- drop_table
292
- create_table
293
- @db.call(:select_a, :n=>2).to_a.should == [{:a => 2, :b => 'trucks'}]
294
- end
295
- end
296
-
297
- describe 'Database schema modifiers' do
298
- # this test was copied from sequel's integration/schema_test because that one drops a serial primary key which is not
299
- # currently supported in fdbsql
300
- specify "should be able to specify constraint names for column constraints" do
301
- @db.create_table!(:items2){Integer :id, :primary_key=>true, :primary_key_constraint_name=>:foo_pk}
302
- @db.create_table!(:items){foreign_key :id, :items2, :unique=>true, :foreign_key_constraint_name => :foo_fk, :unique_constraint_name => :foo_uk, :null=>false}
303
- @db.alter_table(:items){drop_constraint :foo_fk, :type=>:foreign_key; drop_constraint :foo_uk, :type=>:unique}
304
- @db.alter_table(:items2){drop_constraint :foo_pk, :type=>:primary_key}
305
- end
306
- end
307
- end
308
-
309
- describe 'Dataset' do
310
- before(:all) do
311
- @db = DB
312
- end
313
-
314
- describe 'provides_accurate_rows_matched' do
315
- before do
316
- DB.create_table!(:test) {Integer :a}
317
- DB[:test].insert(1)
318
- DB[:test].insert(2)
319
- DB[:test].insert(3)
320
- DB[:test].insert(4)
321
- DB[:test].insert(5)
322
- end
323
-
324
- after do
325
- DB.drop_table?(:test)
326
- end
327
-
328
- specify '#delete' do
329
- DB[:test].where(:a => 8..10).delete.should == 0
330
- DB[:test].where(:a => 5).delete.should == 1
331
- DB[:test].where(:a => 1..3).delete.should == 3
332
- end
333
-
334
- specify '#update' do
335
- DB[:test].where(:a => 8..10).update(:a => Sequel.+(:a, 10)).should == 0
336
- DB[:test].where(:a => 5).update(:a => Sequel.+(:a, 1000)).should == 1
337
- DB[:test].where(:a => 1..3).update(:a => Sequel.+(:a, 100)).should == 3
338
- end
339
-
340
- end
341
-
342
- describe 'intersect and except ALL' do
343
- before do
344
- DB.create_table!(:test) {Integer :a; Integer :b}
345
- DB[:test].insert(1, 10)
346
- DB[:test].insert(2, 10)
347
- DB[:test].insert(8, 15)
348
- DB[:test].insert(2, 10)
349
- DB[:test].insert(2, 10)
350
- DB[:test].insert(1, 10)
351
-
352
- DB.create_table!(:test2) {Integer :a; Integer :b}
353
- DB[:test2].insert(1, 10)
354
- DB[:test2].insert(2, 10)
355
- DB[:test2].insert(2, 12)
356
- DB[:test2].insert(3, 10)
357
- DB[:test2].insert(1, 10)
358
- end
359
-
360
- after do
361
- DB.drop_table?(:test)
362
- DB.drop_table?(:test2)
363
- end
364
-
365
- specify 'intersect all' do
366
- @db[:test].intersect(@db[:test2], :all => true).map{|r| [r[:a],r[:b]]}.to_a.sort.should == [[1, 10], [1,10], [2, 10]]
367
- end
368
-
369
- specify 'except all' do
370
- @db[:test].except(@db[:test2], :all => true).map{|r| [r[:a],r[:b]]}.to_a.sort.should == [[2,10], [2, 10], [8,15]]
371
- end
372
- end
373
-
374
- describe 'is' do
375
- before do
376
- DB.create_table!(:test) {Integer :a; Boolean :b}
377
- DB[:test].insert(1, nil)
378
- DB[:test].insert(2, true)
379
- DB[:test].insert(3, false)
380
- end
381
- after do
382
- DB.drop_table?(:test)
383
- end
384
-
385
- specify 'true' do
386
- DB[:test].select(:a).where(Sequel::SQL::ComplexExpression.new(:IS, :b, true)).map{|r| r[:a]}.should == [2]
387
- end
388
-
389
- specify 'not true' do
390
- DB[:test].select(:a).where(Sequel::SQL::ComplexExpression.new(:'IS NOT', :b, true)).map{|r| r[:a]}.should == [1, 3]
391
- end
392
- end
393
-
394
- describe 'insert empty values' do
395
- before do
396
- DB.create_table!(:test) {primary_key :a}
397
- end
398
- after do
399
- DB.drop_table?(:test)
400
- end
401
-
402
- specify 'inserts defaults and returns pk' do
403
- DB[:test].insert().should == 1 # 1 should be the pk
404
- end
405
- end
406
-
407
- describe 'function names' do
408
- before do
409
- DB.create_table!(:test) {Text :a; Text :b}
410
- DB[:test].insert('1', '')
411
- DB[:test].insert('2', 'trucks')
412
- DB[:test].insert('3', 'foxes')
413
- end
414
- after do
415
- DB.drop_table?(:test)
416
- end
417
-
418
- specify 'evaluate' do
419
- DB[:test].select(Sequel.function(:now)).count == 1
420
- DB[:test].select(Sequel.as(Sequel.function(:concat, :a, :b), :c)).map{|r| r[:c]}.should == ['1','2trucks','3foxes']
421
- end
422
-
423
- specify 'get quoted' do
424
- DB[:test].select(Sequel.function(:now).quoted).sql.should =~ /"now"\(\)/
425
- DB[:test].select(Sequel.as(Sequel.function(:concat, :a, :b).quoted, :c)).sql.should =~ /"concat"\("a", "b"\)/
426
- end
427
- end
428
- end
429
- end
@@ -1,22 +0,0 @@
1
- unless defined?(RSPEC_EXAMPLE_GROUP)
2
- if defined?(RSpec)
3
- require 'rspec/version'
4
- if RSpec::Version::STRING >= '3.0.0'
5
- skip_pending = true
6
- end
7
- if RSpec::Version::STRING >= '2.11.0'
8
- RSpec.configure do |config|
9
- config.expect_with :rspec do |c|
10
- c.syntax = :should
11
- end
12
- config.mock_with :rspec do |c|
13
- c.syntax = :should
14
- end
15
- end
16
- end
17
- RSPEC_EXAMPLE_GROUP = RSpec::Core::ExampleGroup
18
- else
19
- RSPEC_EXAMPLE_GROUP = Spec::Example::ExampleGroup
20
- end
21
- RSPEC_SKIP_PENDING = skip_pending
22
- end