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
@@ -12,84 +12,84 @@ describe "Sequel::Plugins::ValidationHelpers" do
12
12
  @m = @c.new
13
13
  end
14
14
 
15
- specify "should take an :allow_blank option" do
15
+ it "should take an :allow_blank option" do
16
16
  @c.set_validations{validates_format(/.+_.+/, :value, :allow_blank=>true)}
17
17
  @m.value = 'abc_'
18
- @m.should_not be_valid
18
+ @m.wont_be :valid?
19
19
  @m.value = '1_1'
20
- @m.should be_valid
20
+ @m.must_be :valid?
21
21
  o = Object.new
22
22
  @m.value = o
23
- @m.should_not be_valid
23
+ @m.wont_be :valid?
24
24
  def o.blank?
25
25
  true
26
26
  end
27
- @m.should be_valid
27
+ @m.must_be :valid?
28
28
  end
29
29
 
30
- specify "should take an :allow_missing option" do
30
+ it "should take an :allow_missing option" do
31
31
  @c.set_validations{validates_format(/.+_.+/, :value, :allow_missing=>true)}
32
32
  @m.values.clear
33
- @m.should be_valid
33
+ @m.must_be :valid?
34
34
  @m.value = nil
35
- @m.should_not be_valid
35
+ @m.wont_be :valid?
36
36
  @m.value = '1_1'
37
- @m.should be_valid
37
+ @m.must_be :valid?
38
38
  end
39
39
 
40
- specify "should take an :allow_nil option" do
40
+ it "should take an :allow_nil option" do
41
41
  @c.set_validations{validates_format(/.+_.+/, :value, :allow_nil=>true)}
42
42
  @m.value = 'abc_'
43
- @m.should_not be_valid
43
+ @m.wont_be :valid?
44
44
  @m.value = '1_1'
45
- @m.should be_valid
45
+ @m.must_be :valid?
46
46
  @m.value = nil
47
- @m.should be_valid
47
+ @m.must_be :valid?
48
48
  end
49
49
 
50
- specify "should take a :message option" do
50
+ it "should take a :message option" do
51
51
  @c.set_validations{validates_format(/.+_.+/, :value, :message=>"is so blah")}
52
52
  @m.value = 'abc_'
53
- @m.should_not be_valid
54
- @m.errors.full_messages.should == ['value is so blah']
53
+ @m.wont_be :valid?
54
+ @m.errors.full_messages.must_equal ['value is so blah']
55
55
  @m.value = '1_1'
56
- @m.should be_valid
56
+ @m.must_be :valid?
57
57
  end
58
58
 
59
- specify "should allow a proc for the :message option" do
59
+ it "should allow a proc for the :message option" do
60
60
  @c.set_validations{validates_format(/.+_.+/, :value, :message=>proc{|f| "doesn't match #{f.inspect}"})}
61
61
  @m.value = 'abc_'
62
- @m.should_not be_valid
63
- @m.errors.should == {:value=>["doesn't match /.+_.+/"]}
62
+ @m.wont_be :valid?
63
+ @m.errors.must_equal(:value=>["doesn't match /.+_.+/"])
64
64
  end
65
65
 
66
- specify "should take multiple attributes in the same call" do
66
+ it "should take multiple attributes in the same call" do
67
67
  @c.columns :value, :value2
68
68
  @c.set_validations{validates_presence([:value, :value2])}
69
- @m.should_not be_valid
69
+ @m.wont_be :valid?
70
70
  @m.value = 1
71
- @m.should_not be_valid
71
+ @m.wont_be :valid?
72
72
  @m.value2 = 1
73
- @m.should be_valid
73
+ @m.must_be :valid?
74
74
  end
75
75
 
76
- specify "should support modifying default options for all models" do
76
+ it "should support modifying default options for all models" do
77
77
  @c.set_validations{validates_presence(:value)}
78
- @m.should_not be_valid
79
- @m.errors.should == {:value=>['is not present']}
78
+ @m.wont_be :valid?
79
+ @m.errors.must_equal(:value=>['is not present'])
80
80
  o = Sequel::Plugins::ValidationHelpers::DEFAULT_OPTIONS[:presence].dup
81
81
  Sequel::Plugins::ValidationHelpers::DEFAULT_OPTIONS[:presence][:message] = lambda{"was not entered"}
82
- @m.should_not be_valid
83
- @m.errors.should == {:value=>["was not entered"]}
82
+ @m.wont_be :valid?
83
+ @m.errors.must_equal(:value=>["was not entered"])
84
84
  @m.value = 1
85
- @m.should be_valid
85
+ @m.must_be :valid?
86
86
 
87
87
  @m.values.clear
88
88
  Sequel::Plugins::ValidationHelpers::DEFAULT_OPTIONS[:presence][:allow_missing] = true
89
- @m.should be_valid
89
+ @m.must_be :valid?
90
90
  @m.value = nil
91
- @m.should_not be_valid
92
- @m.errors.should == {:value=>["was not entered"]}
91
+ @m.wont_be :valid?
92
+ @m.errors.must_equal(:value=>["was not entered"])
93
93
 
94
94
 
95
95
  c = Class.new(Sequel::Model)
@@ -101,28 +101,28 @@ describe "Sequel::Plugins::ValidationHelpers" do
101
101
  end
102
102
  end
103
103
  m = c.new(:value=>nil)
104
- m.should_not be_valid
105
- m.errors.should == {:value=>["was not entered"]}
104
+ m.wont_be :valid?
105
+ m.errors.must_equal(:value=>["was not entered"])
106
106
  Sequel::Plugins::ValidationHelpers::DEFAULT_OPTIONS[:presence] = o
107
107
  end
108
108
 
109
- specify "should support modifying default validation options for a particular model" do
109
+ it "should support modifying default validation options for a particular model" do
110
110
  @c.set_validations{validates_presence(:value)}
111
- @m.should_not be_valid
112
- @m.errors.should == {:value=>['is not present']}
111
+ @m.wont_be :valid?
112
+ @m.errors.must_equal(:value=>['is not present'])
113
113
  @c.class_eval do
114
114
  def default_validation_helpers_options(type)
115
115
  {:allow_missing=>true, :message=>proc{'was not entered'}}
116
116
  end
117
117
  end
118
118
  @m.value = nil
119
- @m.should_not be_valid
120
- @m.errors.should == {:value=>["was not entered"]}
119
+ @m.wont_be :valid?
120
+ @m.errors.must_equal(:value=>["was not entered"])
121
121
  @m.value = 1
122
- @m.should be_valid
122
+ @m.must_be :valid?
123
123
 
124
124
  @m.values.clear
125
- @m.should be_valid
125
+ @m.must_be :valid?
126
126
 
127
127
  c = Class.new(Sequel::Model)
128
128
  c.class_eval do
@@ -133,225 +133,225 @@ describe "Sequel::Plugins::ValidationHelpers" do
133
133
  end
134
134
  end
135
135
  m = c.new
136
- m.should_not be_valid
137
- m.errors.should == {:value=>['is not present']}
136
+ m.wont_be :valid?
137
+ m.errors.must_equal(:value=>['is not present'])
138
138
  end
139
139
 
140
- specify "should support validates_exact_length" do
140
+ it "should support validates_exact_length" do
141
141
  @c.set_validations{validates_exact_length(3, :value)}
142
- @m.should_not be_valid
142
+ @m.wont_be :valid?
143
143
  @m.value = '123'
144
- @m.should be_valid
144
+ @m.must_be :valid?
145
145
  @m.value = '12'
146
- @m.should_not be_valid
146
+ @m.wont_be :valid?
147
147
  @m.value = '1234'
148
- @m.should_not be_valid
148
+ @m.wont_be :valid?
149
149
  end
150
150
 
151
- specify "should support validate_format" do
151
+ it "should support validate_format" do
152
152
  @c.set_validations{validates_format(/.+_.+/, :value)}
153
153
  @m.value = 'abc_'
154
- @m.should_not be_valid
154
+ @m.wont_be :valid?
155
155
  @m.value = 'abc_def'
156
- @m.should be_valid
156
+ @m.must_be :valid?
157
157
  end
158
158
 
159
- specify "should support validates_includes with an array" do
159
+ it "should support validates_includes with an array" do
160
160
  @c.set_validations{validates_includes([1,2], :value)}
161
- @m.should_not be_valid
161
+ @m.wont_be :valid?
162
162
  @m.value = 1
163
- @m.should be_valid
163
+ @m.must_be :valid?
164
164
  @m.value = 1.5
165
- @m.should_not be_valid
165
+ @m.wont_be :valid?
166
166
  @m.value = 2
167
- @m.should be_valid
167
+ @m.must_be :valid?
168
168
  @m.value = 3
169
- @m.should_not be_valid
169
+ @m.wont_be :valid?
170
170
  end
171
171
 
172
- specify "should support validates_includes with a range" do
172
+ it "should support validates_includes with a range" do
173
173
  @c.set_validations{validates_includes(1..4, :value)}
174
- @m.should_not be_valid
174
+ @m.wont_be :valid?
175
175
  @m.value = 1
176
- @m.should be_valid
176
+ @m.must_be :valid?
177
177
  @m.value = 1.5
178
- @m.should be_valid
178
+ @m.must_be :valid?
179
179
  @m.value = 0
180
- @m.should_not be_valid
180
+ @m.wont_be :valid?
181
181
  @m.value = 5
182
- @m.should_not be_valid
182
+ @m.wont_be :valid?
183
183
  end
184
184
 
185
- specify "should supports validates_integer" do
185
+ it "should supports validates_integer" do
186
186
  @c.set_validations{validates_integer(:value)}
187
187
  @m.value = 'blah'
188
- @m.should_not be_valid
188
+ @m.wont_be :valid?
189
189
  @m.value = '123'
190
- @m.should be_valid
190
+ @m.must_be :valid?
191
191
  @m.value = '123.1231'
192
- @m.should_not be_valid
192
+ @m.wont_be :valid?
193
193
  end
194
194
 
195
- specify "should support validates_length_range" do
195
+ it "should support validates_length_range" do
196
196
  @c.set_validations{validates_length_range(2..5, :value)}
197
- @m.should_not be_valid
197
+ @m.wont_be :valid?
198
198
  @m.value = '12345'
199
- @m.should be_valid
199
+ @m.must_be :valid?
200
200
  @m.value = '1'
201
- @m.should_not be_valid
201
+ @m.wont_be :valid?
202
202
  @m.value = '123456'
203
- @m.should_not be_valid
203
+ @m.wont_be :valid?
204
204
  end
205
205
 
206
- specify "should support validates_max_length" do
206
+ it "should support validates_max_length" do
207
207
  @c.set_validations{validates_max_length(5, :value)}
208
- @m.should_not be_valid
208
+ @m.wont_be :valid?
209
209
  @m.value = '12345'
210
- @m.should be_valid
210
+ @m.must_be :valid?
211
211
  @m.value = '123456'
212
- @m.should_not be_valid
213
- @m.errors[:value].should == ['is longer than 5 characters']
212
+ @m.wont_be :valid?
213
+ @m.errors[:value].must_equal ['is longer than 5 characters']
214
214
  @m.value = nil
215
- @m.should_not be_valid
216
- @m.errors[:value].should == ['is not present']
215
+ @m.wont_be :valid?
216
+ @m.errors[:value].must_equal ['is not present']
217
217
  end
218
218
 
219
- specify "should support validates_max_length with nil value" do
219
+ it "should support validates_max_length with nil value" do
220
220
  @c.set_validations{validates_max_length(5, :value, :message=>'tl', :nil_message=>'np')}
221
221
  @m.value = '123456'
222
- @m.should_not be_valid
223
- @m.errors[:value].should == ['tl']
222
+ @m.wont_be :valid?
223
+ @m.errors[:value].must_equal ['tl']
224
224
  @m.value = nil
225
- @m.should_not be_valid
226
- @m.errors[:value].should == ['np']
225
+ @m.wont_be :valid?
226
+ @m.errors[:value].must_equal ['np']
227
227
  end
228
228
 
229
- specify "should support validates_min_length" do
229
+ it "should support validates_min_length" do
230
230
  @c.set_validations{validates_min_length(5, :value)}
231
- @m.should_not be_valid
231
+ @m.wont_be :valid?
232
232
  @m.value = '12345'
233
- @m.should be_valid
233
+ @m.must_be :valid?
234
234
  @m.value = '1234'
235
- @m.should_not be_valid
235
+ @m.wont_be :valid?
236
236
  end
237
237
 
238
- specify "should support validates_schema_types" do
238
+ it "should support validates_schema_types" do
239
239
  @c.set_validations{validates_schema_types}
240
240
  @m.value = 123
241
- @m.should be_valid
241
+ @m.must_be :valid?
242
242
  @m.value = '123'
243
- @m.should be_valid
243
+ @m.must_be :valid?
244
244
  @m.meta_def(:db_schema){{:value=>{:type=>:integer}}}
245
- @m.should_not be_valid
246
- @m.errors.full_messages.should == ['value is not a valid integer']
245
+ @m.wont_be :valid?
246
+ @m.errors.full_messages.must_equal ['value is not a valid integer']
247
247
 
248
248
  @c.set_validations{validates_schema_types(:value)}
249
249
  @m.meta_def(:db_schema){{:value=>{:type=>:integer}}}
250
- @m.should_not be_valid
251
- @m.errors.full_messages.should == ['value is not a valid integer']
250
+ @m.wont_be :valid?
251
+ @m.errors.full_messages.must_equal ['value is not a valid integer']
252
252
 
253
253
  @c.set_validations{validates_schema_types(:value, :message=>'is bad')}
254
254
  @m.meta_def(:db_schema){{:value=>{:type=>:integer}}}
255
- @m.should_not be_valid
256
- @m.errors.full_messages.should == ['value is bad']
255
+ @m.wont_be :valid?
256
+ @m.errors.full_messages.must_equal ['value is bad']
257
257
  end
258
258
 
259
- specify "should support validates_numeric" do
259
+ it "should support validates_numeric" do
260
260
  @c.set_validations{validates_numeric(:value)}
261
261
  @m.value = 'blah'
262
- @m.should_not be_valid
262
+ @m.wont_be :valid?
263
263
  @m.value = '123'
264
- @m.should be_valid
264
+ @m.must_be :valid?
265
265
  @m.value = '123.1231'
266
- @m.should be_valid
266
+ @m.must_be :valid?
267
267
  @m.value = '+1'
268
- @m.should be_valid
268
+ @m.must_be :valid?
269
269
  @m.value = '-1'
270
- @m.should be_valid
270
+ @m.must_be :valid?
271
271
  @m.value = '+1.123'
272
- @m.should be_valid
272
+ @m.must_be :valid?
273
273
  @m.value = '-0.123'
274
- @m.should be_valid
274
+ @m.must_be :valid?
275
275
  @m.value = '-0.123E10'
276
- @m.should be_valid
276
+ @m.must_be :valid?
277
277
  @m.value = '32.123e10'
278
- @m.should be_valid
278
+ @m.must_be :valid?
279
279
  @m.value = '+32.123E10'
280
- @m.should be_valid
281
- @m.should be_valid
280
+ @m.must_be :valid?
281
+ @m.must_be :valid?
282
282
  @m.value = '.0123'
283
283
  end
284
284
 
285
- specify "should support validates_type" do
285
+ it "should support validates_type" do
286
286
  @c.set_validations{validates_type(Integer, :value)}
287
287
  @m.value = 123
288
- @m.should be_valid
288
+ @m.must_be :valid?
289
289
  @m.value = '123'
290
- @m.should_not be_valid
291
- @m.errors.full_messages.should == ['value is not a valid integer']
290
+ @m.wont_be :valid?
291
+ @m.errors.full_messages.must_equal ['value is not a valid integer']
292
292
 
293
293
  @c.set_validations{validates_type(:String, :value)}
294
294
  @m.value = '123'
295
- @m.should be_valid
295
+ @m.must_be :valid?
296
296
  @m.value = 123
297
- @m.should_not be_valid
298
- @m.errors.full_messages.should == ['value is not a valid string']
297
+ @m.wont_be :valid?
298
+ @m.errors.full_messages.must_equal ['value is not a valid string']
299
299
 
300
300
  @c.set_validations{validates_type('Integer', :value)}
301
301
  @m.value = 123
302
- @m.should be_valid
302
+ @m.must_be :valid?
303
303
  @m.value = 123.05
304
- @m.should_not be_valid
305
- @m.errors.full_messages.should == ['value is not a valid integer']
304
+ @m.wont_be :valid?
305
+ @m.errors.full_messages.must_equal ['value is not a valid integer']
306
306
 
307
307
  @c.set_validations{validates_type(Integer, :value)}
308
308
  @m.value = 1
309
- @m.should be_valid
309
+ @m.must_be :valid?
310
310
  @m.value = false
311
- @m.should_not be_valid
311
+ @m.wont_be :valid?
312
312
 
313
313
  @c.set_validations{validates_type([Integer, Float], :value)}
314
314
  @m.value = 1
315
- @m.should be_valid
315
+ @m.must_be :valid?
316
316
  @m.value = 1.0
317
- @m.should be_valid
317
+ @m.must_be :valid?
318
318
  @m.value = BigDecimal.new('1.0')
319
- @m.should_not be_valid
320
- @m.errors.full_messages.should == ['value is not a valid integer or float']
319
+ @m.wont_be :valid?
320
+ @m.errors.full_messages.must_equal ['value is not a valid integer or float']
321
321
  end
322
322
 
323
- specify "should support validates_not_null" do
323
+ it "should support validates_not_null" do
324
324
  @c.set_validations{validates_not_null(:value)}
325
- @m.should_not be_valid
325
+ @m.wont_be :valid?
326
326
  @m.value = ''
327
- @m.should be_valid
327
+ @m.must_be :valid?
328
328
  @m.value = 1234
329
- @m.should be_valid
329
+ @m.must_be :valid?
330
330
  @m.value = nil
331
- @m.should_not be_valid
331
+ @m.wont_be :valid?
332
332
  @m.value = true
333
- @m.should be_valid
333
+ @m.must_be :valid?
334
334
  @m.value = false
335
- @m.should be_valid
335
+ @m.must_be :valid?
336
336
  @m.value = Time.now
337
- @m.should be_valid
337
+ @m.must_be :valid?
338
338
  end
339
339
 
340
- specify "should support validates_presence" do
340
+ it "should support validates_presence" do
341
341
  @c.set_validations{validates_presence(:value)}
342
- @m.should_not be_valid
342
+ @m.wont_be :valid?
343
343
  @m.value = ''
344
- @m.should_not be_valid
344
+ @m.wont_be :valid?
345
345
  @m.value = 1234
346
- @m.should be_valid
346
+ @m.must_be :valid?
347
347
  @m.value = nil
348
- @m.should_not be_valid
348
+ @m.wont_be :valid?
349
349
  @m.value = true
350
- @m.should be_valid
350
+ @m.must_be :valid?
351
351
  @m.value = false
352
- @m.should be_valid
352
+ @m.must_be :valid?
353
353
  @m.value = Time.now
354
- @m.should be_valid
354
+ @m.must_be :valid?
355
355
  end
356
356
 
357
357
  it "should support validates_unique with a single attribute" do
@@ -368,28 +368,28 @@ describe "Sequel::Plugins::ValidationHelpers" do
368
368
  end
369
369
 
370
370
  @user = @c.new(:username => "0records", :password => "anothertest")
371
- @user.should be_valid
371
+ @user.must_be :valid?
372
372
  @user = @c.load(:id=>3, :username => "0records", :password => "anothertest")
373
- @user.should be_valid
373
+ @user.must_be :valid?
374
374
 
375
375
  DB.sqls
376
376
  @user = @c.new(:password => "anothertest")
377
- @user.should be_valid
378
- DB.sqls.should == []
377
+ @user.must_be :valid?
378
+ DB.sqls.must_equal []
379
379
 
380
380
  @user = @c.new(:username => "1record", :password => "anothertest")
381
- @user.should_not be_valid
382
- @user.errors.full_messages.should == ['username is already taken']
381
+ @user.wont_be :valid?
382
+ @user.errors.full_messages.must_equal ['username is already taken']
383
383
  @user = @c.load(:id=>4, :username => "1record", :password => "anothertest")
384
- @user.should_not be_valid
385
- @user.errors.full_messages.should == ['username is already taken']
384
+ @user.wont_be :valid?
385
+ @user.errors.full_messages.must_equal ['username is already taken']
386
386
 
387
387
  @user = @c.load(:id=>1, :username => "0records", :password => "anothertest")
388
- @user.should be_valid
389
- DB.sqls.last.should == "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (id != 1)) LIMIT 1"
388
+ @user.must_be :valid?
389
+ DB.sqls.last.must_equal "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (id != 1)) LIMIT 1"
390
390
  @user = @c.new(:username => "0records", :password => "anothertest")
391
- @user.should be_valid
392
- DB.sqls.last.should == "SELECT count(*) AS count FROM items WHERE (username = '0records') LIMIT 1"
391
+ @user.must_be :valid?
392
+ DB.sqls.last.must_equal "SELECT count(*) AS count FROM items WHERE (username = '0records') LIMIT 1"
393
393
  end
394
394
 
395
395
  it "should support validates_unique with multiple attributes" do
@@ -406,35 +406,35 @@ describe "Sequel::Plugins::ValidationHelpers" do
406
406
  end
407
407
 
408
408
  @user = @c.new(:username => "0records", :password => "anothertest")
409
- @user.should be_valid
409
+ @user.must_be :valid?
410
410
  @user = @c.load(:id=>3, :username => "0records", :password => "anothertest")
411
- @user.should be_valid
411
+ @user.must_be :valid?
412
412
 
413
413
  DB.sqls
414
414
  @user = @c.new(:password => "anothertest")
415
- @user.should be_valid
416
- @user.errors.full_messages.should == []
415
+ @user.must_be :valid?
416
+ @user.errors.full_messages.must_equal []
417
417
  @user = @c.new(:username => "0records")
418
- @user.should be_valid
419
- @user.errors.full_messages.should == []
418
+ @user.must_be :valid?
419
+ @user.errors.full_messages.must_equal []
420
420
  @user = @c.new
421
- @user.should be_valid
422
- @user.errors.full_messages.should == []
423
- DB.sqls.should == []
421
+ @user.must_be :valid?
422
+ @user.errors.full_messages.must_equal []
423
+ DB.sqls.must_equal []
424
424
 
425
425
  @user = @c.new(:username => "1record", :password => "anothertest")
426
- @user.should_not be_valid
427
- @user.errors.full_messages.should == ['username and password is already taken']
426
+ @user.wont_be :valid?
427
+ @user.errors.full_messages.must_equal ['username and password is already taken']
428
428
  @user = @c.load(:id=>4, :username => "1record", :password => "anothertest")
429
- @user.should_not be_valid
430
- @user.errors.full_messages.should == ['username and password is already taken']
429
+ @user.wont_be :valid?
430
+ @user.errors.full_messages.must_equal ['username and password is already taken']
431
431
 
432
432
  @user = @c.load(:id=>1, :username => "0records", :password => "anothertest")
433
- @user.should be_valid
434
- DB.sqls.last.should == "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = 'anothertest') AND (id != 1)) LIMIT 1"
433
+ @user.must_be :valid?
434
+ DB.sqls.last.must_equal "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = 'anothertest') AND (id != 1)) LIMIT 1"
435
435
  @user = @c.new(:username => "0records", :password => "anothertest")
436
- @user.should be_valid
437
- DB.sqls.last.should == "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = 'anothertest')) LIMIT 1"
436
+ @user.must_be :valid?
437
+ DB.sqls.last.must_equal "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = 'anothertest')) LIMIT 1"
438
438
  end
439
439
 
440
440
  it "should support validates_unique with a block" do
@@ -444,9 +444,9 @@ describe "Sequel::Plugins::ValidationHelpers" do
444
444
  @c.dataset._fetch = {:v=>0}
445
445
 
446
446
  DB.reset
447
- @c.new(:username => "0records", :password => "anothertest").should be_valid
448
- @c.load(:id=>3, :username => "0records", :password => "anothertest").should be_valid
449
- DB.sqls.should == ["SELECT count(*) AS count FROM items WHERE ((username = '0records') AND active) LIMIT 1",
447
+ @c.new(:username => "0records", :password => "anothertest").must_be :valid?
448
+ @c.load(:id=>3, :username => "0records", :password => "anothertest").must_be :valid?
449
+ DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '0records') AND active) LIMIT 1",
450
450
  "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND active AND (id != 3)) LIMIT 1"]
451
451
  end
452
452
 
@@ -457,9 +457,9 @@ describe "Sequel::Plugins::ValidationHelpers" do
457
457
  @c.dataset._fetch = {:v=>0}
458
458
 
459
459
  DB.reset
460
- @c.new(:username => "0RECORDS", :password => "anothertest").should be_valid
461
- @c.load(:id=>3, :username => "0RECORDS", :password => "anothertest").should be_valid
462
- DB.sqls.should == ["SELECT count(*) AS count FROM items WHERE (lower(username) = '0records') LIMIT 1",
460
+ @c.new(:username => "0RECORDS", :password => "anothertest").must_be :valid?
461
+ @c.load(:id=>3, :username => "0RECORDS", :password => "anothertest").must_be :valid?
462
+ DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE (lower(username) = '0records') LIMIT 1",
463
463
  "SELECT count(*) AS count FROM items WHERE ((lower(username) = '0records') AND (id != 3)) LIMIT 1"]
464
464
  end
465
465
 
@@ -471,9 +471,9 @@ describe "Sequel::Plugins::ValidationHelpers" do
471
471
  @c.dataset._fetch = {:v=>0}
472
472
 
473
473
  DB.reset
474
- @c.new(:username => "0records", :password => "anothertest").should be_valid
475
- @c.load(:id=>3, :username => "0records", :password => "anothertest").should be_valid
476
- DB.sqls.should == ["SELECT count(*) AS count FROM items WHERE ((a IN (1, 2, 3)) AND (username = '0records')) LIMIT 1",
474
+ @c.new(:username => "0records", :password => "anothertest").must_be :valid?
475
+ @c.load(:id=>3, :username => "0records", :password => "anothertest").must_be :valid?
476
+ DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((a IN (1, 2, 3)) AND (username = '0records')) LIMIT 1",
477
477
  "SELECT count(*) AS count FROM items WHERE ((a IN (1, 2, 3)) AND (username = '0records') AND (id != 3)) LIMIT 1"]
478
478
  end
479
479
 
@@ -485,9 +485,9 @@ describe "Sequel::Plugins::ValidationHelpers" do
485
485
  @c.dataset._fetch = {:v=>0}
486
486
 
487
487
  DB.reset
488
- @c.new(:username => "0records", :password => "anothertest").should be_valid
489
- @c.load(:id=>3, :username => "0records", :password => "anothertest").should be_valid
490
- DB.sqls.should == ["SELECT count(*) AS count FROM items CROSS JOIN a WHERE (username = '0records') LIMIT 1",
488
+ @c.new(:username => "0records", :password => "anothertest").must_be :valid?
489
+ @c.load(:id=>3, :username => "0records", :password => "anothertest").must_be :valid?
490
+ DB.sqls.must_equal ["SELECT count(*) AS count FROM items CROSS JOIN a WHERE (username = '0records') LIMIT 1",
491
491
  "SELECT count(*) AS count FROM items CROSS JOIN a WHERE ((username = '0records') AND (items.id != 3)) LIMIT 1"]
492
492
  end
493
493
 
@@ -498,26 +498,26 @@ describe "Sequel::Plugins::ValidationHelpers" do
498
498
  @c.dataset._fetch = {:v=>0}
499
499
 
500
500
  DB.reset
501
- @c.new(:username => "0records", :password => "anothertest").should be_valid
502
- DB.sqls.should == ["SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = 'anothertest')) LIMIT 1"]
501
+ @c.new(:username => "0records", :password => "anothertest").must_be :valid?
502
+ DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = 'anothertest')) LIMIT 1"]
503
503
  DB.reset
504
504
  m = @c.load(:id=>3, :username => "0records", :password => "anothertest")
505
- m.should be_valid
506
- DB.sqls.should == []
505
+ m.must_be :valid?
506
+ DB.sqls.must_equal []
507
507
 
508
508
  m.username = '1'
509
- m.should be_valid
510
- DB.sqls.should == ["SELECT count(*) AS count FROM items WHERE ((username = '1') AND (password = 'anothertest') AND (id != 3)) LIMIT 1"]
509
+ m.must_be :valid?
510
+ DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '1') AND (password = 'anothertest') AND (id != 3)) LIMIT 1"]
511
511
 
512
512
  m = @c.load(:id=>3, :username => "0records", :password => "anothertest")
513
513
  DB.reset
514
514
  m.password = '1'
515
- m.should be_valid
516
- DB.sqls.should == ["SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = '1') AND (id != 3)) LIMIT 1"]
515
+ m.must_be :valid?
516
+ DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = '1') AND (id != 3)) LIMIT 1"]
517
517
  DB.reset
518
518
  m.username = '2'
519
- m.should be_valid
520
- DB.sqls.should == ["SELECT count(*) AS count FROM items WHERE ((username = '2') AND (password = '1') AND (id != 3)) LIMIT 1"]
519
+ m.must_be :valid?
520
+ DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '2') AND (password = '1') AND (id != 3)) LIMIT 1"]
521
521
  end
522
522
 
523
523
  it "should not attempt a database query if the underlying columns have validation errors" do
@@ -528,7 +528,7 @@ describe "Sequel::Plugins::ValidationHelpers" do
528
528
 
529
529
  DB.reset
530
530
  m = @c.new(:username => "1", :password => "anothertest")
531
- m.should_not be_valid
532
- DB.sqls.should == []
531
+ m.wont_be :valid?
532
+ DB.sqls.must_equal []
533
533
  end
534
534
  end