sequel 4.22.0 → 4.23.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 (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
@@ -5,27 +5,9 @@ unless Object.const_defined?('Sequel') && Sequel.const_defined?('Model')
5
5
  end
6
6
  Sequel::Deprecation.backtrace_filter = lambda{|line, lineno| lineno < 4 || line =~ /_spec\.rb/}
7
7
 
8
- require File.join(File.dirname(File.expand_path(__FILE__)), "../rspec_helper.rb")
9
-
10
- RSPEC_EXAMPLE_GROUP.class_eval do
11
- if ENV['SEQUEL_DEPRECATION_WARNINGS']
12
- class << self
13
- alias qspecify specify
14
- end
15
- else
16
- def self.qspecify(*a, &block)
17
- specify(*a) do
18
- begin
19
- output = Sequel::Deprecation.output
20
- Sequel::Deprecation.output = false
21
- instance_exec(&block)
22
- ensure
23
- Sequel::Deprecation.output = output
24
- end
25
- end
26
- end
27
- end
28
- end
8
+ gem 'minitest'
9
+ require 'minitest/autorun'
10
+ require 'minitest/hooks/default'
29
11
 
30
12
  Sequel.quote_identifiers = false
31
13
  Sequel.identifier_input_method = nil
@@ -5,81 +5,79 @@ describe Sequel::Model::Errors do
5
5
  @errors = Sequel::Model::Errors.new
6
6
  end
7
7
 
8
- specify "should be clearable using #clear" do
8
+ it "should be clearable using #clear" do
9
9
  @errors.add(:a, 'b')
10
- @errors.should == {:a=>['b']}
10
+ @errors.must_equal(:a=>['b'])
11
11
  @errors.clear
12
- @errors.should == {}
12
+ @errors.must_equal({})
13
13
  end
14
14
 
15
- specify "should be empty if there are no errors" do
16
- @errors.should be_empty
15
+ it "should be empty if there are no errors" do
16
+ @errors.must_be :empty?
17
17
  end
18
18
 
19
- specify "should not be empty if there are errors" do
19
+ it "should not be empty if there are errors" do
20
20
  @errors.add(:blah, "blah")
21
- @errors.should_not be_empty
21
+ @errors.wont_be :empty?
22
22
  end
23
23
 
24
- specify "should return an array of errors for a specific attribute using #on if there are errors" do
24
+ it "should return an array of errors for a specific attribute using #on if there are errors" do
25
25
  @errors.add(:blah, 'blah')
26
- @errors.on(:blah).should == ['blah']
26
+ @errors.on(:blah).must_equal ['blah']
27
27
  end
28
28
 
29
- specify "should return nil using #on if there are no errors for that attribute" do
30
- @errors.on(:blah).should == nil
29
+ it "should return nil using #on if there are no errors for that attribute" do
30
+ @errors.on(:blah).must_equal nil
31
31
  end
32
32
 
33
- specify "should accept errors using #add" do
33
+ it "should accept errors using #add" do
34
34
  @errors.add :blah, 'zzzz'
35
- @errors[:blah].should == ['zzzz']
35
+ @errors[:blah].must_equal ['zzzz']
36
36
  end
37
37
 
38
- specify "should return full messages using #full_messages" do
39
- @errors.full_messages.should == []
38
+ it "should return full messages using #full_messages" do
39
+ @errors.full_messages.must_equal []
40
40
 
41
41
  @errors.add(:blow, 'blieuh')
42
42
  @errors.add(:blow, 'blich')
43
43
  @errors.add(:blay, 'bliu')
44
44
  msgs = @errors.full_messages
45
- msgs.size.should == 3
46
- msgs.should include('blow blieuh', 'blow blich', 'blay bliu')
45
+ msgs.sort.must_equal ['blay bliu', 'blow blich', 'blow blieuh']
47
46
  end
48
47
 
49
- specify "should not add column names for LiteralStrings" do
50
- @errors.full_messages.should == []
48
+ it "should not add column names for LiteralStrings" do
49
+ @errors.full_messages.must_equal []
51
50
 
52
51
  @errors.add(:blow, 'blieuh')
53
52
  @errors.add(:blow, Sequel.lit('blich'))
54
53
  @errors.add(:blay, 'bliu')
55
54
  msgs = @errors.full_messages
56
- msgs.size.should == 3
57
- msgs.should include('blow blieuh', 'blich', 'blay bliu')
55
+ msgs.sort.must_equal ['blay bliu', 'blich', 'blow blieuh']
58
56
  end
59
57
 
60
- specify "should return the number of error messages using #count" do
61
- @errors.count.should == 0
58
+ it "should return the number of error messages using #count" do
59
+ @errors.count.must_equal 0
62
60
  @errors.add(:a, 'b')
63
- @errors.count.should == 1
61
+ @errors.count.must_equal 1
64
62
  @errors.add(:a, 'c')
65
- @errors.count.should == 2
63
+ @errors.count.must_equal 2
66
64
  @errors.add(:b, 'c')
67
- @errors.count.should == 3
65
+ @errors.count.must_equal 3
68
66
  end
69
67
 
70
- specify "should return the array of error messages for a given attribute using #on" do
68
+ it "should return the array of error messages for a given attribute using #on" do
71
69
  @errors.add(:a, 'b')
72
- @errors.on(:a).should == ['b']
70
+ @errors.on(:a).must_equal ['b']
73
71
  @errors.add(:a, 'c')
74
- @errors.on(:a).should == ['b', 'c']
72
+ @errors.on(:a).must_equal ['b', 'c']
75
73
  @errors.add(:b, 'c')
76
- @errors.on(:a).should == ['b', 'c']
74
+ @errors.on(:a).must_equal ['b', 'c']
77
75
  end
78
76
 
79
- specify "should return nil if there are no error messages for a given attribute using #on" do
80
- @errors.on(:a).should == nil
77
+ it "should return nil if there are no error messages for a given attribute using #on" do
78
+ @errors.on(:a).must_equal nil
81
79
  @errors.add(:b, 'b')
82
- @errors.on(:a).should == nil
80
+ @errors.on(:a).must_equal nil
83
81
  end
84
82
  end
85
83
 
@@ -95,48 +93,48 @@ describe Sequel::Model do
95
93
  @o = @c.new
96
94
  end
97
95
 
98
- specify "should supply a #valid? method that returns true if validations pass" do
96
+ it "should supply a #valid? method that returns true if validations pass" do
99
97
  @o.score = 50
100
- @o.should_not be_valid
98
+ @o.wont_be :valid?
101
99
  @o.score = 100
102
- @o.should be_valid
100
+ @o.must_be :valid?
103
101
  end
104
102
 
105
- specify "should provide an errors object" do
103
+ it "should provide an errors object" do
106
104
  @o.score = 100
107
- @o.should be_valid
108
- @o.errors.should be_empty
105
+ @o.must_be :valid?
106
+ @o.errors.must_be :empty?
109
107
 
110
108
  @o.score = 86
111
- @o.should_not be_valid
112
- @o.errors[:score].should == ['too low']
113
- @o.errors.on(:blah).should be_nil
109
+ @o.wont_be :valid?
110
+ @o.errors[:score].must_equal ['too low']
111
+ @o.errors.on(:blah).must_equal nil
114
112
  end
115
113
 
116
- specify "should allow raising of ValidationFailed with a Model instance with errors" do
114
+ it "should allow raising of ValidationFailed with a Model instance with errors" do
117
115
  @o.errors.add(:score, 'is too low')
118
116
  begin
119
117
  raise Sequel::ValidationFailed, @o
120
118
  rescue Sequel::ValidationFailed => e
121
119
  end
122
- e.model.should equal(@o)
123
- e.errors.should equal(@o.errors)
124
- e.message.should == 'score is too low'
120
+ e.model.must_be_same_as(@o)
121
+ e.errors.must_be_same_as(@o.errors)
122
+ e.message.must_equal 'score is too low'
125
123
  end
126
124
 
127
- specify "should allow raising of ValidationFailed with an Errors instance" do
125
+ it "should allow raising of ValidationFailed with an Errors instance" do
128
126
  @o.errors.add(:score, 'is too low')
129
127
  begin
130
128
  raise Sequel::ValidationFailed, @o.errors
131
129
  rescue Sequel::ValidationFailed => e
132
130
  end
133
- e.model.should be_nil
134
- e.errors.should equal(@o.errors)
135
- e.message.should == 'score is too low'
131
+ e.model.must_equal nil
132
+ e.errors.must_be_same_as(@o.errors)
133
+ e.message.must_equal 'score is too low'
136
134
  end
137
135
 
138
- specify "should allow raising of ValidationFailed with a string" do
139
- proc{raise Sequel::ValidationFailed, "no reason"}.should raise_error(Sequel::ValidationFailed, "no reason")
136
+ it "should allow raising of ValidationFailed with a string" do
137
+ proc{raise Sequel::ValidationFailed, "no reason"}.must_raise(Sequel::ValidationFailed, "no reason")
140
138
  end
141
139
  end
142
140
 
@@ -153,39 +151,43 @@ describe "Model#save" do
153
151
  DB.reset
154
152
  end
155
153
 
156
- specify "should save only if validations pass" do
154
+ it "should save only if validations pass" do
157
155
  @m.raise_on_save_failure = false
158
- @m.should_not be_valid
156
+ @m.wont_be :valid?
159
157
  @m.save
160
- DB.sqls.should be_empty
158
+ DB.sqls.must_be :empty?
161
159
 
162
160
  @m.x = 7
163
- @m.should be_valid
164
- @m.save.should_not == false
165
- DB.sqls.should == ['UPDATE people SET x = 7 WHERE (id = 4)']
161
+ @m.must_be :valid?
162
+ @m.save.wont_equal false
163
+ DB.sqls.must_equal ['UPDATE people SET x = 7 WHERE (id = 4)']
166
164
  end
167
165
 
168
- specify "should skip validations if the :validate=>false option is used" do
166
+ it "should skip validations if the :validate=>false option is used" do
169
167
  @m.raise_on_save_failure = false
170
- @m.should_not be_valid
168
+ @m.wont_be :valid?
171
169
  @m.save(:validate=>false)
172
- DB.sqls.should == ['UPDATE people SET x = 6 WHERE (id = 4)']
170
+ DB.sqls.must_equal ['UPDATE people SET x = 6 WHERE (id = 4)']
173
171
  end
174
172
 
175
- specify "should raise error if validations fail and raise_on_save_failure is true" do
176
- proc{@m.save}.should(raise_error(Sequel::ValidationFailed) do |e|
177
- e.model.should equal(@m)
178
- e.errors.should equal(@m.errors)
179
- end)
173
+ it "should raise error if validations fail and raise_on_save_failure is true" do
174
+ begin
175
+ @m.save
176
+ rescue Sequel::ValidationFailed => e
177
+ e.model.must_be_same_as(@m)
178
+ e.errors.must_be_same_as(@m.errors)
179
+ else
180
+ raise
181
+ end
180
182
  end
181
183
 
182
- specify "should raise error if validations fail and :raise_on_failure option is true" do
184
+ it "should raise error if validations fail and :raise_on_failure option is true" do
183
185
  @m.raise_on_save_failure = false
184
- proc{@m.save(:raise_on_failure => true)}.should raise_error(Sequel::ValidationFailed)
186
+ proc{@m.save(:raise_on_failure => true)}.must_raise(Sequel::ValidationFailed)
185
187
  end
186
188
 
187
- specify "should return nil if validations fail and raise_on_save_faiure is false" do
189
+ it "should return nil if validations fail and raise_on_save_faiure is false" do
188
190
  @m.raise_on_save_failure = false
189
- @m.save.should == nil
191
+ @m.save.must_equal nil
190
192
  end
191
193
  end
@@ -1,2 +1,10 @@
1
1
  ENV['SEQUEL_POSTGRES_URL'] ||= 'postgres:///sequel_test?user=sequel_test&password=2a9db12d8f993248'
2
2
  ENV['SEQUEL_SQLITE_URL'] ||= 'sqlite:/'
3
+ gem 'minitest'
4
+ require 'minitest'
5
+ if Minitest.respond_to?(:before_parallel_fork)
6
+ if SEQUEL_ADAPTER_TEST.to_s == 'postgres'
7
+ Minitest.before_parallel_fork{DB.disconnect}
8
+ Minitest.after_parallel_fork{|i|DB.opts[:database] += (i+1).to_s; DB.extension :pg_array, :pg_hstore}
9
+ end
10
+ end
metadata CHANGED
@@ -1,17 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.22.0
4
+ version: 4.23.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-05-01 00:00:00.000000000 Z
11
+ date: 2015-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.7.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.7.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest-hooks
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-shared_description
15
43
  requirement: !ruby/object:Gem::Requirement
16
44
  requirements:
17
45
  - - ">="
@@ -195,6 +223,7 @@ extra_rdoc_files:
195
223
  - doc/release_notes/4.20.0.txt
196
224
  - doc/release_notes/4.21.0.txt
197
225
  - doc/release_notes/4.22.0.txt
226
+ - doc/release_notes/4.23.0.txt
198
227
  files:
199
228
  - CHANGELOG
200
229
  - MIT-LICENSE
@@ -305,6 +334,7 @@ files:
305
334
  - doc/release_notes/4.20.0.txt
306
335
  - doc/release_notes/4.21.0.txt
307
336
  - doc/release_notes/4.22.0.txt
337
+ - doc/release_notes/4.23.0.txt
308
338
  - doc/release_notes/4.3.0.txt
309
339
  - doc/release_notes/4.4.0.txt
310
340
  - doc/release_notes/4.5.0.txt
@@ -333,7 +363,6 @@ files:
333
363
  - lib/sequel/adapters/do/mysql.rb
334
364
  - lib/sequel/adapters/do/postgres.rb
335
365
  - lib/sequel/adapters/do/sqlite3.rb
336
- - lib/sequel/adapters/fdbsql.rb
337
366
  - lib/sequel/adapters/firebird.rb
338
367
  - lib/sequel/adapters/ibmdb.rb
339
368
  - lib/sequel/adapters/informix.rb
@@ -342,7 +371,6 @@ files:
342
371
  - lib/sequel/adapters/jdbc/cubrid.rb
343
372
  - lib/sequel/adapters/jdbc/db2.rb
344
373
  - lib/sequel/adapters/jdbc/derby.rb
345
- - lib/sequel/adapters/jdbc/fdbsql.rb
346
374
  - lib/sequel/adapters/jdbc/firebirdsql.rb
347
375
  - lib/sequel/adapters/jdbc/h2.rb
348
376
  - lib/sequel/adapters/jdbc/hsqldb.rb
@@ -364,13 +392,12 @@ files:
364
392
  - lib/sequel/adapters/odbc/db2.rb
365
393
  - lib/sequel/adapters/odbc/mssql.rb
366
394
  - lib/sequel/adapters/odbc/progress.rb
367
- - lib/sequel/adapters/openbase.rb
368
395
  - lib/sequel/adapters/oracle.rb
369
396
  - lib/sequel/adapters/postgres.rb
397
+ - lib/sequel/adapters/postgresql.rb
370
398
  - lib/sequel/adapters/shared/access.rb
371
399
  - lib/sequel/adapters/shared/cubrid.rb
372
400
  - lib/sequel/adapters/shared/db2.rb
373
- - lib/sequel/adapters/shared/fdbsql.rb
374
401
  - lib/sequel/adapters/shared/firebird.rb
375
402
  - lib/sequel/adapters/shared/informix.rb
376
403
  - lib/sequel/adapters/shared/mssql.rb
@@ -510,6 +537,7 @@ files:
510
537
  - lib/sequel/plugins/csv_serializer.rb
511
538
  - lib/sequel/plugins/dataset_associations.rb
512
539
  - lib/sequel/plugins/defaults_setter.rb
540
+ - lib/sequel/plugins/delay_add_association.rb
513
541
  - lib/sequel/plugins/dirty.rb
514
542
  - lib/sequel/plugins/eager_each.rb
515
543
  - lib/sequel/plugins/error_splitter.rb
@@ -556,6 +584,8 @@ files:
556
584
  - lib/sequel/plugins/unlimited_update.rb
557
585
  - lib/sequel/plugins/update_or_create.rb
558
586
  - lib/sequel/plugins/update_primary_key.rb
587
+ - lib/sequel/plugins/update_refresh.rb
588
+ - lib/sequel/plugins/validate_associated.rb
559
589
  - lib/sequel/plugins/validation_class_methods.rb
560
590
  - lib/sequel/plugins/validation_helpers.rb
561
591
  - lib/sequel/plugins/xml_serializer.rb
@@ -563,7 +593,6 @@ files:
563
593
  - lib/sequel/timezones.rb
564
594
  - lib/sequel/version.rb
565
595
  - spec/adapters/db2_spec.rb
566
- - spec/adapters/fdbsql_spec.rb
567
596
  - spec/adapters/firebird_spec.rb
568
597
  - spec/adapters/informix_spec.rb
569
598
  - spec/adapters/mssql_spec.rb
@@ -614,6 +643,7 @@ files:
614
643
  - spec/extensions/dataset_source_alias_spec.rb
615
644
  - spec/extensions/date_arithmetic_spec.rb
616
645
  - spec/extensions/defaults_setter_spec.rb
646
+ - spec/extensions/delay_add_association_spec.rb
617
647
  - spec/extensions/dirty_spec.rb
618
648
  - spec/extensions/eager_each_spec.rb
619
649
  - spec/extensions/empty_array_ignore_nulls_spec.rb
@@ -705,6 +735,8 @@ files:
705
735
  - spec/extensions/unlimited_update_spec.rb
706
736
  - spec/extensions/update_or_create_spec.rb
707
737
  - spec/extensions/update_primary_key_spec.rb
738
+ - spec/extensions/update_refresh_spec.rb
739
+ - spec/extensions/validate_associated_spec.rb
708
740
  - spec/extensions/validation_class_methods_spec.rb
709
741
  - spec/extensions/validation_helpers_spec.rb
710
742
  - spec/extensions/xml_serializer_spec.rb
@@ -752,6 +784,7 @@ files:
752
784
  - spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB
753
785
  - spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB
754
786
  - spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB
787
+ - spec/guards_helper.rb
755
788
  - spec/integration/associations_test.rb
756
789
  - spec/integration/database_test.rb
757
790
  - spec/integration/dataset_test.rb
@@ -778,7 +811,6 @@ files:
778
811
  - spec/model/record_spec.rb
779
812
  - spec/model/spec_helper.rb
780
813
  - spec/model/validations_spec.rb
781
- - spec/rspec_helper.rb
782
814
  - spec/sequel_coverage.rb
783
815
  - spec/spec_config.rb
784
816
  homepage: http://sequel.jeremyevans.net
@@ -1,286 +0,0 @@
1
- require 'pg'
2
-
3
- Sequel.require 'adapters/utils/pg_types'
4
- Sequel.require 'adapters/shared/fdbsql'
5
- Sequel::Deprecation.deprecate 'The fdbsql adapter is deprecated and will be removed in a future version of Sequel.'
6
-
7
- module Sequel
8
- module Fdbsql
9
- CONVERTED_EXCEPTIONS << PGError
10
-
11
- # Database class for the FoundationDB SQL Layer used with Sequel and the
12
- # pg driver
13
- class Database < Sequel::Database
14
- include Sequel::Fdbsql::DatabaseMethods
15
-
16
- set_adapter_scheme :fdbsql
17
-
18
- # Connects to the database. In addition to the standard database options,
19
- # :connect_timeout is a connection timeout in seconds,
20
- # :sslmode sets whether to use ssl, and
21
- # :notice_receiver handles server notices in a proc.
22
- def connect(server)
23
- opts = server_opts(server)
24
- Connection.new(self, opts)
25
- end
26
-
27
- # Execute the given SQL with the given args on an available connection.
28
- def execute(sql, opts = {}, &block)
29
- res = nil
30
- synchronize(opts[:server]) do |conn|
31
- res = check_database_errors do
32
- if sql.is_a?(Symbol)
33
- execute_prepared_statement(conn, sql, opts, &block)
34
- else
35
- log_yield(sql) do
36
- conn.query(sql, opts[:arguments])
37
- end
38
- end
39
- end
40
- yield res if block_given?
41
- res.cmd_tuples
42
- end
43
- end
44
-
45
- def server_version
46
- return @server_version if @server_version
47
-
48
- version = get{VERSION{}}
49
- unless ver = version.match(/(\d+)\.(\d+)\.(\d+)/)
50
- raise Error, "No match when checking FDB SQL Layer version: #{version}"
51
- end
52
-
53
- @server_version = (100 * ver[1].to_i + ver[2].to_i) * 100 + ver[3].to_i
54
- end
55
-
56
- private
57
-
58
- def database_exception_sqlstate(exception, opts)
59
- if exception.respond_to?(:result) && (result = exception.result)
60
- result.error_field(::PGresult::PG_DIAG_SQLSTATE)
61
- end
62
- end
63
-
64
- def execute_prepared_statement(conn, name, opts=OPTS, &block)
65
- statement = prepared_statement(name)
66
- sql = statement.prepared_sql
67
- ps_name = name.to_s
68
- if args = opts[:arguments]
69
- args = args.map{|arg| bound_variable_arg(arg, conn)}
70
- end
71
- begin
72
- # create prepared statement if it doesn't exist, or has new sql
73
- unless conn.prepared_statements[ps_name] == sql
74
- conn.execute("DEALLOCATE #{ps_name}") if conn.prepared_statements.include?(ps_name)
75
- log_yield("PREPARE #{ps_name} AS #{sql}"){conn.prepare(ps_name, sql)}
76
- conn.prepared_statements[ps_name] = sql
77
- end
78
-
79
- log_sql = "EXECUTE #{ps_name}"
80
- if statement.log_sql
81
- log_sql << " ("
82
- log_sql << sql
83
- log_sql << ")"
84
- end
85
- log_yield(sql, args) do
86
- conn.execute_prepared_statement(ps_name, args)
87
- end
88
- rescue PGError => e
89
- if (database_exception_sqlstate(e, opts) == STALE_STATEMENT_SQLSTATE)
90
- conn.prepared_statements[ps_name] = nil
91
- retry
92
- end
93
- end
94
- end
95
- end
96
-
97
- # Dataset class for the FoundationDB SQL Layer that uses the pg driver.
98
- class Dataset < Sequel::Dataset
99
- include Sequel::Fdbsql::DatasetMethods
100
-
101
- Database::DatasetClass = self
102
-
103
- # Allow use of bind arguments for FDBSQL using the pg driver.
104
- module BindArgumentMethods
105
-
106
- include Sequel::Dataset::UnnumberedArgumentMapper
107
- include DatasetMethods::PreparedStatementMethods
108
-
109
- private
110
-
111
- # Execute the given SQL with the stored bind arguments.
112
- def execute(sql, opts=OPTS, &block)
113
- super(sql, {:arguments=>bind_arguments}.merge!(opts), &block)
114
- end
115
-
116
- # Same as execute, explicit due to intricacies of alias and super.
117
- def execute_dui(sql, opts=OPTS, &block)
118
- super(sql, {:arguments=>bind_arguments}.merge!(opts), &block)
119
- end
120
- end
121
-
122
- # Allow use of server side prepared statements for FDBSQL using the
123
- # pg driver.
124
- module PreparedStatementMethods
125
- include BindArgumentMethods
126
-
127
- # Raise a more obvious error if you attempt to call a unnamed prepared statement.
128
- def call(*)
129
- raise Error, "Cannot call prepared statement without a name" if prepared_statement_name.nil?
130
- super
131
- end
132
-
133
- private
134
-
135
- # Execute the stored prepared statement name and the stored bind
136
- # arguments instead of the SQL given.
137
- def execute(sql, opts=OPTS, &block)
138
- super(prepared_statement_name, opts, &block)
139
- end
140
-
141
- # Same as execute, explicit due to intricacies of alias and super.
142
- def execute_dui(sql, opts=OPTS, &block)
143
- super(prepared_statement_name, opts, &block)
144
- end
145
- end
146
-
147
-
148
- # Execute the given type of statement with the hash of values.
149
- def call(type, bind_vars=OPTS, *values, &block)
150
- ps = to_prepared_statement(type, values)
151
- ps.extend(BindArgumentMethods)
152
- ps.call(bind_vars, &block)
153
- end
154
-
155
- # Yield all rows returned by executing the given SQL and converting
156
- # the types.
157
- def fetch_rows(sql)
158
- execute(sql) do |res|
159
- columns = set_columns(res)
160
- yield_hash_rows(res, columns) {|h| yield h}
161
- end
162
- end
163
-
164
- # Prepare the given type of statement with the given name, and store
165
- # it in the database to be called later.
166
- def prepare(type, name=nil, *values)
167
- ps = to_prepared_statement(type, values)
168
- ps.extend(PreparedStatementMethods)
169
- if name
170
- ps.prepared_statement_name = name
171
- db.set_prepared_statement(name, ps)
172
- end
173
- ps
174
- end
175
-
176
- private
177
-
178
- def set_columns(res)
179
- cols = []
180
- procs = db.conversion_procs
181
- res.nfields.times do |fieldnum|
182
- cols << [fieldnum, procs[res.ftype(fieldnum)], output_identifier(res.fname(fieldnum))]
183
- end
184
- @columns = cols.map{|c| c[2]}
185
- cols
186
- end
187
-
188
- # For each row in the result set, yield a hash with column name symbol
189
- # keys and typecasted values.
190
- def yield_hash_rows(res, cols)
191
- res.ntuples.times do |recnum|
192
- converted_rec = {}
193
- cols.each do |fieldnum, type_proc, fieldsym|
194
- value = res.getvalue(recnum, fieldnum)
195
- converted_rec[fieldsym] = (value && type_proc) ? type_proc.call(value) : value
196
- end
197
- yield converted_rec
198
- end
199
- end
200
-
201
- end
202
-
203
- # Connection specific methods for Fdbsql with pg
204
- class Connection < PG::Connection
205
- # Regular expression for error messages that note that the connection is closed.
206
- DISCONNECT_ERROR_RE = /\A(?:could not receive data from server|no connection to the server|connection not open|connection is closed)/
207
-
208
- # Hash of prepared statements for this connection. Keys are
209
- # string names of the server side prepared statement, and values
210
- # are SQL strings.
211
- attr_accessor :prepared_statements
212
-
213
- # Create a new connection to the FoundationDB SQL Layer. See Database#connect.
214
- def initialize(db, opts)
215
- connect_opts = {
216
- :host => opts[:host] || 'localhost',
217
- :port => opts[:port] || 15432,
218
- :dbname => opts[:database],
219
- :user => opts[:user],
220
- :password => opts[:password],
221
- :hostaddr => opts[:hostaddr],
222
- :connect_timeout => opts[:connect_timeout] || 20,
223
- :sslmode => opts[:sslmode]
224
- }.delete_if{|key, value| value.nil? or (value.respond_to?(:empty?) and value.empty?)}
225
- super(connect_opts)
226
-
227
- @db = db
228
- @prepared_statements = {}
229
-
230
- if opts[:notice_receiver]
231
- set_notice_receiver(opts[:notice_receiver])
232
- else
233
- # Swallow warnings
234
- set_notice_receiver{|proc| }
235
- end
236
- end
237
-
238
- # Close the connection.
239
- def close
240
- super
241
- rescue PGError, IOError
242
- end
243
-
244
- # Execute the given SQL with this connection. If a block is given,
245
- # yield the results, otherwise, return the number of changed rows.
246
- def execute(sql, args=nil)
247
- q = query(sql, args)
248
- block_given? ? yield(q) : q.cmd_tuples
249
- end
250
-
251
- # Execute the prepared statement of the given name, binding the given
252
- # args.
253
- def execute_prepared_statement(name, args)
254
- check_disconnect_errors{exec_prepared(name, args)}
255
- end
256
-
257
- # Prepare a statement for later use.
258
- def prepare(name, sql)
259
- check_disconnect_errors{super}
260
- end
261
-
262
- # Execute the given query and return the results.
263
- def query(sql, args=nil)
264
- args = args.map{|v| @db.bound_variable_arg(v, self)} if args
265
- check_disconnect_errors{super}
266
- end
267
-
268
- private
269
-
270
- # Raise a Sequel::DatabaseDisconnectError if a PGError is raised and
271
- # the connection status cannot be determined or it is not OK.
272
- def check_disconnect_errors
273
- begin
274
- yield
275
- rescue PGError => e
276
- disconnect = false
277
- disconnect ||= e.message =~ DISCONNECT_ERROR_RE
278
- disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise
279
- rescue IOError, Errno::EPIPE, Errno::ECONNRESET => e
280
- disconnect = true
281
- raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError))
282
- end
283
- end
284
- end
285
- end
286
- end