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
@@ -11,90 +11,90 @@ describe "Sequel::Plugins::UpdatePrimaryKey" do
11
11
  DB.reset
12
12
  end
13
13
 
14
- specify "should handle regular updates" do
14
+ it "should handle regular updates" do
15
15
  @ds._fetch = [[{:a=>1, :b=>3}], [{:a=>1, :b=>4}], [{:a=>1, :b=>4}], [{:a=>1, :b=>5}], [{:a=>1, :b=>5}], [{:a=>1, :b=>6}], [{:a=>1, :b=>6}]]
16
16
  @c.first.update(:b=>4)
17
- @c.all.should == [@c.load(:a=>1, :b=>4)]
18
- DB.sqls.should == ["SELECT * FROM a LIMIT 1", "UPDATE a SET b = 4 WHERE (a = 1)", "SELECT * FROM a"]
17
+ @c.all.must_equal [@c.load(:a=>1, :b=>4)]
18
+ DB.sqls.must_equal ["SELECT * FROM a LIMIT 1", "UPDATE a SET b = 4 WHERE (a = 1)", "SELECT * FROM a"]
19
19
  @c.first.set(:b=>5).save
20
- @c.all.should == [@c.load(:a=>1, :b=>5)]
21
- DB.sqls.should == ["SELECT * FROM a LIMIT 1", "UPDATE a SET b = 5 WHERE (a = 1)", "SELECT * FROM a"]
20
+ @c.all.must_equal [@c.load(:a=>1, :b=>5)]
21
+ DB.sqls.must_equal ["SELECT * FROM a LIMIT 1", "UPDATE a SET b = 5 WHERE (a = 1)", "SELECT * FROM a"]
22
22
  @c.first.set(:b=>6).save(:columns=>:b)
23
- @c.all.should == [@c.load(:a=>1, :b=>6)]
24
- DB.sqls.should == ["SELECT * FROM a LIMIT 1", "UPDATE a SET b = 6 WHERE (a = 1)", "SELECT * FROM a"]
23
+ @c.all.must_equal [@c.load(:a=>1, :b=>6)]
24
+ DB.sqls.must_equal ["SELECT * FROM a LIMIT 1", "UPDATE a SET b = 6 WHERE (a = 1)", "SELECT * FROM a"]
25
25
  end
26
26
 
27
- specify "should handle updating the primary key field with another field" do
27
+ it "should handle updating the primary key field with another field" do
28
28
  @ds._fetch = [[{:a=>1, :b=>3}], [{:a=>2, :b=>4}]]
29
29
  @c.first.update(:a=>2, :b=>4)
30
- @c.all.should == [@c.load(:a=>2, :b=>4)]
30
+ @c.all.must_equal [@c.load(:a=>2, :b=>4)]
31
31
  sqls = DB.sqls
32
- ["UPDATE a SET a = 2, b = 4 WHERE (a = 1)", "UPDATE a SET b = 4, a = 2 WHERE (a = 1)"].should include(sqls.slice!(1))
33
- sqls.should == ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
32
+ ["UPDATE a SET a = 2, b = 4 WHERE (a = 1)", "UPDATE a SET b = 4, a = 2 WHERE (a = 1)"].must_include(sqls.slice!(1))
33
+ sqls.must_equal ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
34
34
  end
35
35
 
36
- specify "should handle updating just the primary key field when saving changes" do
36
+ it "should handle updating just the primary key field when saving changes" do
37
37
  @ds._fetch = [[{:a=>1, :b=>3}], [{:a=>2, :b=>3}], [{:a=>2, :b=>3}], [{:a=>3, :b=>3}]]
38
38
  @c.first.update(:a=>2)
39
- @c.all.should == [@c.load(:a=>2, :b=>3)]
40
- DB.sqls.should == ["SELECT * FROM a LIMIT 1", "UPDATE a SET a = 2 WHERE (a = 1)", "SELECT * FROM a"]
39
+ @c.all.must_equal [@c.load(:a=>2, :b=>3)]
40
+ DB.sqls.must_equal ["SELECT * FROM a LIMIT 1", "UPDATE a SET a = 2 WHERE (a = 1)", "SELECT * FROM a"]
41
41
  @c.first.set(:a=>3).save(:columns=>:a)
42
- @c.all.should == [@c.load(:a=>3, :b=>3)]
43
- DB.sqls.should == ["SELECT * FROM a LIMIT 1", "UPDATE a SET a = 3 WHERE (a = 2)", "SELECT * FROM a"]
42
+ @c.all.must_equal [@c.load(:a=>3, :b=>3)]
43
+ DB.sqls.must_equal ["SELECT * FROM a LIMIT 1", "UPDATE a SET a = 3 WHERE (a = 2)", "SELECT * FROM a"]
44
44
  end
45
45
 
46
- specify "should handle saving after modifying the primary key field with another field" do
46
+ it "should handle saving after modifying the primary key field with another field" do
47
47
  @ds._fetch = [[{:a=>1, :b=>3}], [{:a=>2, :b=>4}]]
48
48
  @c.first.set(:a=>2, :b=>4).save
49
- @c.all.should == [@c.load(:a=>2, :b=>4)]
49
+ @c.all.must_equal [@c.load(:a=>2, :b=>4)]
50
50
  sqls = DB.sqls
51
- ["UPDATE a SET a = 2, b = 4 WHERE (a = 1)", "UPDATE a SET b = 4, a = 2 WHERE (a = 1)"].should include(sqls.slice!(1))
52
- sqls.should == ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
51
+ ["UPDATE a SET a = 2, b = 4 WHERE (a = 1)", "UPDATE a SET b = 4, a = 2 WHERE (a = 1)"].must_include(sqls.slice!(1))
52
+ sqls.must_equal ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
53
53
  end
54
54
 
55
- specify "should handle saving after modifying just the primary key field" do
55
+ it "should handle saving after modifying just the primary key field" do
56
56
  @ds._fetch = [[{:a=>1, :b=>3}], [{:a=>2, :b=>3}]]
57
57
  @c.first.set(:a=>2).save
58
- @c.all.should == [@c.load(:a=>2, :b=>3)]
58
+ @c.all.must_equal [@c.load(:a=>2, :b=>3)]
59
59
  sqls = DB.sqls
60
- ["UPDATE a SET a = 2, b = 3 WHERE (a = 1)", "UPDATE a SET b = 3, a = 2 WHERE (a = 1)"].should include(sqls.slice!(1))
61
- sqls.should == ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
60
+ ["UPDATE a SET a = 2, b = 3 WHERE (a = 1)", "UPDATE a SET b = 3, a = 2 WHERE (a = 1)"].must_include(sqls.slice!(1))
61
+ sqls.must_equal ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
62
62
  end
63
63
 
64
- specify "should handle saving after updating the primary key" do
64
+ it "should handle saving after updating the primary key" do
65
65
  @ds._fetch = [[{:a=>1, :b=>3}], [{:a=>2, :b=>5}]]
66
66
  @c.first.update(:a=>2).update(:b=>4).set(:b=>5).save
67
- @c.all.should == [@c.load(:a=>2, :b=>5)]
68
- DB.sqls.should == ["SELECT * FROM a LIMIT 1", "UPDATE a SET a = 2 WHERE (a = 1)", "UPDATE a SET b = 4 WHERE (a = 2)", "UPDATE a SET b = 5 WHERE (a = 2)", "SELECT * FROM a"]
67
+ @c.all.must_equal [@c.load(:a=>2, :b=>5)]
68
+ DB.sqls.must_equal ["SELECT * FROM a LIMIT 1", "UPDATE a SET a = 2 WHERE (a = 1)", "UPDATE a SET b = 4 WHERE (a = 2)", "UPDATE a SET b = 5 WHERE (a = 2)", "SELECT * FROM a"]
69
69
  end
70
70
 
71
- specify "should work correctly when using the prepared_statements plugin" do
71
+ it "should work correctly when using the prepared_statements plugin" do
72
72
  @c.plugin :prepared_statements
73
73
  @ds._fetch = [[{:a=>1, :b=>3}], [{:a=>2, :b=>4}]]
74
74
  o = @c.first
75
75
  o.update(:a=>2, :b=>4)
76
- @c.all.should == [@c.load(:a=>2, :b=>4)]
76
+ @c.all.must_equal [@c.load(:a=>2, :b=>4)]
77
77
  sqls = DB.sqls
78
- ["UPDATE a SET a = 2, b = 4 WHERE (a = 1)", "UPDATE a SET b = 4, a = 2 WHERE (a = 1)"].should include(sqls.slice!(1))
79
- sqls.should == ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
78
+ ["UPDATE a SET a = 2, b = 4 WHERE (a = 1)", "UPDATE a SET b = 4, a = 2 WHERE (a = 1)"].must_include(sqls.slice!(1))
79
+ sqls.must_equal ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
80
80
 
81
81
  o.delete
82
82
  end
83
83
 
84
- specify "should clear the associations cache of non-many_to_one associations when changing the primary key" do
84
+ it "should clear the associations cache of non-many_to_one associations when changing the primary key" do
85
85
  @c.one_to_many :cs, :class=>@c
86
86
  @c.many_to_one :c, :class=>@c
87
87
  o = @c.new(:a=>1)
88
88
  o.associations[:cs] = @c.new
89
89
  o.associations[:c] = o2 = @c.new
90
90
  o.a = 2
91
- o.associations.should == {:c=>o2}
91
+ o.associations.must_equal(:c=>o2)
92
92
  end
93
93
 
94
- specify "should handle frozen instances" do
94
+ it "should handle frozen instances" do
95
95
  o = @c.new
96
96
  o.a = 1
97
97
  o.freeze
98
- o.pk_hash.should == {:a=>1}
98
+ o.pk_hash.must_equal(:a=>1)
99
99
  end
100
100
  end
@@ -0,0 +1,41 @@
1
+ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
+
3
+ describe "Sequel::Plugins::UpdateRefresh" do
4
+ before do
5
+ @db = Sequel.mock(:numrows=>1, :fetch=>{:id=>1, :name=>'b'})
6
+ @c = Class.new(Sequel::Model(@db[:test]))
7
+ @ds = @c.dataset
8
+ @c.columns :id, :name
9
+ @c.plugin :update_refresh
10
+ @db.sqls
11
+ end
12
+
13
+ it "should refresh the instance after updating" do
14
+ o = @c.load(:id=>1, :name=>'a')
15
+ o.save
16
+ @db.sqls.must_equal ["UPDATE test SET name = 'a' WHERE (id = 1)", "SELECT * FROM test WHERE (id = 1) LIMIT 1"]
17
+ o.name.must_equal 'b'
18
+ end
19
+
20
+ it "should refresh the instance after updating" do
21
+ @db.extend_datasets{def supports_returning?(x) true end; def update_sql(*); sql = super; update_returning_sql(sql); sql end}
22
+ @c.dataset = @db[:test]
23
+ @db.sqls
24
+ o = @c.load(:id=>1, :name=>'a')
25
+ o.save
26
+ @db.sqls.must_equal ["UPDATE test SET name = 'a' WHERE (id = 1) RETURNING *"]
27
+ o.name.must_equal 'b'
28
+ end
29
+
30
+ it "should refresh the instance after updating when returning specific columns" do
31
+ @db.extend_datasets{def supports_returning?(x) true end; def update_sql(*); sql = super; update_returning_sql(sql); sql end}
32
+ @c.plugin :insert_returning_select
33
+ @c.dataset = @db[:test].select(:id, :name)
34
+ @db.sqls
35
+ o = @c.load(:id=>1, :name=>'a')
36
+ o.this.opts[:returning] = [:id, :name]
37
+ o.save
38
+ @db.sqls.must_equal ["UPDATE test SET name = 'a' WHERE (id = 1) RETURNING id, name"]
39
+ o.name.must_equal 'b'
40
+ end
41
+ end
@@ -0,0 +1,52 @@
1
+ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
+
3
+ describe "ValidatesAssociated plugin" do
4
+ before do
5
+ @db = Sequel.mock(:autoid=>1, :numrows=>1, :fetch=>{:id=>1, :name=>'a', :c_id=>nil})
6
+ @c = Class.new(Sequel::Model(@db[:cs]))
7
+ @c.plugin :validate_associated
8
+ @c.columns :id, :name, :c_id
9
+ @c.one_to_many :cs, :class=>@c, :key=>:c_id
10
+ @o = @c.load(:id=>1, :name=>'a')
11
+ @db.sqls
12
+ end
13
+
14
+ it "should return nil when saving if the associated object is invalid when raise_on_save_failure is false" do
15
+ @c.raise_on_save_failure = false
16
+ @c.send(:define_method, :validate){|*| errors.add(:name, 'is b') if name == 'b'}
17
+ o = @c.load(:id=>2, :name=>'b')
18
+ @o.send(:delay_validate_associated_object, @c.association_reflection(:cs), o)
19
+ @o.save.must_equal nil
20
+ @o.errors[:cs].must_equal ["name is b"]
21
+ o.errors[:name].must_equal ['is b']
22
+ end
23
+
24
+ it "should support creating new one_to_many and one_to_one objects with presence validations on the foreign key" do
25
+ @c.class_eval do
26
+ plugin :validation_helpers
27
+ def validate
28
+ validates_integer :c_id
29
+ super
30
+ end
31
+ end
32
+ @o.c_id = 5
33
+ @o.send(:delay_validate_associated_object, @c.association_reflection(:cs), @c.load(:id=>2, :name=>'b', :c_id=>2))
34
+ @o.valid?.must_equal true
35
+ end
36
+
37
+ it "should should not remove existing values from object when validating" do
38
+ o = @c.load(:id=>2, :name=>'b', :c_id=>3)
39
+ @o.send(:delay_validate_associated_object, @c.association_reflection(:cs), o)
40
+ @o.valid?.must_equal true
41
+ o.c_id.must_equal 3
42
+ end
43
+
44
+ it "should not attempt to validate associated_object if the :validate=>false option is passed to save" do
45
+ @c.one_to_many :cs, :class=>@c, :key=>:c_id
46
+ @c.send(:define_method, :validate){|*| errors.add(:name, 'is b') if name == 'b'}
47
+ o = @c.load(:id=>2, :name=>'b', :c_id=>3)
48
+ @o.send(:delay_validate_associated_object, @c.association_reflection(:cs), o)
49
+ @o.save(:validate=>false).must_equal @o
50
+ @db.sqls.must_equal ["UPDATE cs SET name = 'a' WHERE (id = 1)"]
51
+ end
52
+ end
@@ -16,46 +16,46 @@ describe Sequel::Model do
16
16
  end
17
17
  end
18
18
 
19
- specify "should respond to validations, has_validations?, and validation_reflections" do
20
- @c.should respond_to(:validations)
21
- @c.should respond_to(:has_validations?)
22
- @c.should respond_to(:validation_reflections)
19
+ it "should respond to validations, has_validations?, and validation_reflections" do
20
+ @c.must_respond_to(:validations)
21
+ @c.must_respond_to(:has_validations?)
22
+ @c.must_respond_to(:validation_reflections)
23
23
  end
24
24
 
25
- specify "should be able to reflect on validations" do
26
- @c.validation_reflections.should == {}
25
+ it "should be able to reflect on validations" do
26
+ @c.validation_reflections.must_equal({})
27
27
  @c.validates_acceptance_of(:a)
28
- @c.validation_reflections.should == {:a=>[[:acceptance, {:tag=>:acceptance, :message=>"is not accepted", :allow_nil=>true, :accept=>"1"}]]}
28
+ @c.validation_reflections.must_equal(:a=>[[:acceptance, {:tag=>:acceptance, :message=>"is not accepted", :allow_nil=>true, :accept=>"1"}]])
29
29
  @c.validates_presence_of(:a)
30
- @c.validation_reflections[:a].length.should == 2
31
- @c.validation_reflections[:a].last.should == [:presence, {:tag=>:presence, :message=>"is not present"}]
30
+ @c.validation_reflections[:a].length.must_equal 2
31
+ @c.validation_reflections[:a].last.must_equal [:presence, {:tag=>:presence, :message=>"is not present"}]
32
32
  end
33
33
 
34
- specify "should handle validation reflections correctly when subclassing" do
34
+ it "should handle validation reflections correctly when subclassing" do
35
35
  @c.validates_acceptance_of(:a)
36
36
  c = Class.new(@c)
37
- c.validation_reflections.map{|k,v| k}.should == [:a]
37
+ c.validation_reflections.map{|k,v| k}.must_equal [:a]
38
38
  c.validates_presence_of(:a)
39
- @c.validation_reflections.should == {:a=>[[:acceptance, {:tag=>:acceptance, :message=>"is not accepted", :allow_nil=>true, :accept=>"1"}]]}
40
- c.validation_reflections[:a].last.should == [:presence, {:tag=>:presence, :message=>"is not present"}]
39
+ @c.validation_reflections.must_equal(:a=>[[:acceptance, {:tag=>:acceptance, :message=>"is not accepted", :allow_nil=>true, :accept=>"1"}]])
40
+ c.validation_reflections[:a].last.must_equal [:presence, {:tag=>:presence, :message=>"is not present"}]
41
41
  end
42
42
 
43
- specify "should acccept validation definitions using validates_each" do
43
+ it "should acccept validation definitions using validates_each" do
44
44
  @c.validates_each(:xx, :yy) {|o, a, v| o.errors.add(a, 'too low') if v < 50}
45
45
  o = @c.new
46
- o.should_receive(:xx).once.and_return(40)
47
- o.should_receive(:yy).once.and_return(60)
48
- o.valid?.should == false
49
- o.errors.full_messages.should == ['xx too low']
46
+ def o.xx; 40; end
47
+ def o.yy; 60; end
48
+ o.valid?.must_equal false
49
+ o.errors.full_messages.must_equal ['xx too low']
50
50
  end
51
51
 
52
- specify "should return true/false for has_validations?" do
53
- @c.has_validations?.should == false
52
+ it "should return true/false for has_validations?" do
53
+ @c.has_validations?.must_equal false
54
54
  @c.validates_each(:xx) {1}
55
- @c.has_validations?.should == true
55
+ @c.has_validations?.must_equal true
56
56
  end
57
57
 
58
- specify "should validate multiple attributes at once" do
58
+ it "should validate multiple attributes at once" do
59
59
  o = @c.new
60
60
  def o.xx
61
61
  1
@@ -67,11 +67,11 @@ describe Sequel::Model do
67
67
  atts = nil
68
68
  @c.validates_each([:xx, :yy]){|obj,a,v| atts=a; vals=v}
69
69
  o.valid?
70
- vals.should == [1,2]
71
- atts.should == [:xx, :yy]
70
+ vals.must_equal [1,2]
71
+ atts.must_equal [:xx, :yy]
72
72
  end
73
73
 
74
- specify "should respect allow_missing option when using multiple attributes" do
74
+ it "should respect allow_missing option when using multiple attributes" do
75
75
  o = @c.new
76
76
  def o.xx
77
77
  self[:xx]
@@ -85,26 +85,26 @@ describe Sequel::Model do
85
85
 
86
86
  o.values[:xx] = 1
87
87
  o.valid?
88
- vals.should == [1,nil]
89
- atts.should == [:xx, :yy]
88
+ vals.must_equal [1,nil]
89
+ atts.must_equal [:xx, :yy]
90
90
 
91
91
  vals = nil
92
92
  atts = nil
93
93
  o.values.clear
94
94
  o.values[:yy] = 2
95
95
  o.valid?
96
- vals.should == [nil, 2]
97
- atts.should == [:xx, :yy]
96
+ vals.must_equal [nil, 2]
97
+ atts.must_equal [:xx, :yy]
98
98
 
99
99
  vals = nil
100
100
  atts = nil
101
101
  o.values.clear
102
- o.valid?.should == true
103
- vals.should == nil
104
- atts.should == nil
102
+ o.valid?.must_equal true
103
+ vals.must_equal nil
104
+ atts.must_equal nil
105
105
  end
106
106
 
107
- specify "should overwrite existing validation with the same tag and attribute" do
107
+ it "should overwrite existing validation with the same tag and attribute" do
108
108
  @c.validates_each(:xx, :xx, :tag=>:low) {|o, a, v| o.xxx; o.errors.add(a, 'too low') if v < 50}
109
109
  @c.validates_each(:yy, :yy) {|o, a, v| o.yyy; o.errors.add(a, 'too low') if v < 50}
110
110
  @c.validates_presence_of(:zz, :zz)
@@ -118,33 +118,33 @@ describe Sequel::Model do
118
118
  @b ||= 0
119
119
  @b += 1
120
120
  end
121
- o.should_receive(:xx).once.and_return(40)
122
- o.should_receive(:yy).once.and_return(60)
123
- o.should_receive(:xxx).once
124
- o.should_receive(:yyy).twice
125
- o.valid?.should == false
126
- o.zz.should == 2
127
- o.aa.should == 2
128
- o.errors.full_messages.should == ['xx too low']
121
+ def o.xx; 40; end
122
+ def o.yy; 60; end
123
+ def o.xxx; end
124
+ def o.yyy; end
125
+ o.valid?.must_equal false
126
+ o.zz.must_equal 2
127
+ o.aa.must_equal 2
128
+ o.errors.full_messages.must_equal ['xx too low']
129
129
  end
130
130
 
131
- specify "should provide a validates method that takes block with validation definitions" do
131
+ it "should provide a validates method that takes block with validation definitions" do
132
132
  @c.validates do
133
133
  coolness_of :blah
134
134
  end
135
- @c.validations[:blah].should_not be_empty
135
+ @c.validations[:blah].wont_be :empty?
136
136
  o = @c.new
137
- o.should_receive(:blah).once.and_return(nil)
138
- o.valid?.should == false
139
- o.errors.full_messages.should == ['blah is not cool']
137
+ def o.blah; end
138
+ o.valid?.must_equal false
139
+ o.errors.full_messages.must_equal ['blah is not cool']
140
140
  end
141
141
 
142
- specify "should have the validates block have appropriate respond_to?" do
142
+ it "should have the validates block have appropriate respond_to?" do
143
143
  c = nil
144
144
  @c.validates{c = respond_to?(:foo)}
145
- c.should == false
145
+ c.must_equal false
146
146
  @c.validates{c = respond_to?(:length_of)}
147
- c.should == true
147
+ c.must_equal true
148
148
  end if RUBY_VERSION >= '1.9'
149
149
  end
150
150
 
@@ -160,22 +160,22 @@ describe Sequel::Model do
160
160
  @o = @c.new
161
161
  end
162
162
 
163
- specify "should supply a #valid? method that returns true if validations pass" do
163
+ it "should supply a #valid? method that returns true if validations pass" do
164
164
  @o.score = 50
165
- @o.should_not be_valid
165
+ @o.wont_be :valid?
166
166
  @o.score = 100
167
- @o.should be_valid
167
+ @o.must_be :valid?
168
168
  end
169
169
 
170
- specify "should provide an errors object" do
170
+ it "should provide an errors object" do
171
171
  @o.score = 100
172
- @o.should be_valid
173
- @o.errors.should be_empty
172
+ @o.must_be :valid?
173
+ @o.errors.must_be :empty?
174
174
 
175
175
  @o.score = 86
176
- @o.should_not be_valid
177
- @o.errors[:score].should == ['too low']
178
- @o.errors.on(:blah).should be_nil
176
+ @o.wont_be :valid?
177
+ @o.errors[:score].must_equal ['too low']
178
+ @o.errors.on(:blah).must_equal nil
179
179
  end
180
180
  end
181
181
 
@@ -190,11 +190,11 @@ describe "Sequel::Plugins::ValidationClassMethods::ClassMethods::Generator" do
190
190
  end
191
191
  end
192
192
 
193
- specify "should instance_eval the block, sending everything to its receiver" do
193
+ it "should instance_eval the block, sending everything to its receiver" do
194
194
  @c.validates do
195
195
  blah
196
196
  end
197
- @testit.should == [1324]
197
+ @testit.must_equal [1324]
198
198
  end
199
199
  end
200
200
 
@@ -215,379 +215,379 @@ describe Sequel::Model do
215
215
  @m = @c.new
216
216
  end
217
217
 
218
- specify "should validate acceptance_of" do
218
+ it "should validate acceptance_of" do
219
219
  @c.validates_acceptance_of :value
220
- @m.should be_valid
220
+ @m.must_be :valid?
221
221
  @m.value = '1'
222
- @m.should be_valid
222
+ @m.must_be :valid?
223
223
  end
224
224
 
225
- specify "should validate acceptance_of with accept" do
225
+ it "should validate acceptance_of with accept" do
226
226
  @c.validates_acceptance_of :value, :accept => 'true'
227
227
  @m.value = '1'
228
- @m.should_not be_valid
228
+ @m.wont_be :valid?
229
229
  @m.value = 'true'
230
- @m.should be_valid
230
+ @m.must_be :valid?
231
231
  end
232
232
 
233
- specify "should validate acceptance_of with allow_nil => false" do
233
+ it "should validate acceptance_of with allow_nil => false" do
234
234
  @c.validates_acceptance_of :value, :allow_nil => false
235
- @m.should_not be_valid
235
+ @m.wont_be :valid?
236
236
  end
237
237
 
238
- specify "should validate acceptance_of with allow_missing => true" do
238
+ it "should validate acceptance_of with allow_missing => true" do
239
239
  @c.validates_acceptance_of :value, :allow_missing => true
240
- @m.should be_valid
240
+ @m.must_be :valid?
241
241
  end
242
242
 
243
- specify "should validate acceptance_of with allow_missing => true and allow_nil => false" do
243
+ it "should validate acceptance_of with allow_missing => true and allow_nil => false" do
244
244
  @c.validates_acceptance_of :value, :allow_missing => true, :allow_nil => false
245
- @m.should be_valid
245
+ @m.must_be :valid?
246
246
  @m.value = nil
247
- @m.should_not be_valid
247
+ @m.wont_be :valid?
248
248
  end
249
249
 
250
- specify "should validate acceptance_of with if => true" do
250
+ it "should validate acceptance_of with if => true" do
251
251
  @c.validates_acceptance_of :value, :if => :dont_skip
252
252
  @m.value = '0'
253
- @m.should_not be_valid
253
+ @m.wont_be :valid?
254
254
  end
255
255
 
256
- specify "should validate acceptance_of with if => false" do
256
+ it "should validate acceptance_of with if => false" do
257
257
  @c.validates_acceptance_of :value, :if => :skip
258
258
  @m.value = '0'
259
- @m.should be_valid
259
+ @m.must_be :valid?
260
260
  end
261
261
 
262
- specify "should validate acceptance_of with if proc that evaluates to true" do
262
+ it "should validate acceptance_of with if proc that evaluates to true" do
263
263
  @c.validates_acceptance_of :value, :if => proc{true}
264
264
  @m.value = '0'
265
- @m.should_not be_valid
265
+ @m.wont_be :valid?
266
266
  end
267
267
 
268
- specify "should validate acceptance_of with if proc that evaluates to false" do
268
+ it "should validate acceptance_of with if proc that evaluates to false" do
269
269
  @c.validates_acceptance_of :value, :if => proc{false}
270
270
  @m.value = '0'
271
- @m.should be_valid
271
+ @m.must_be :valid?
272
272
  end
273
273
 
274
- specify "should raise an error if :if option is not a Symbol, Proc, or nil" do
274
+ it "should raise an error if :if option is not a Symbol, Proc, or nil" do
275
275
  @c.validates_acceptance_of :value, :if => 1
276
276
  @m.value = '0'
277
- proc{@m.valid?}.should raise_error(Sequel::Error)
277
+ proc{@m.valid?}.must_raise(Sequel::Error)
278
278
  end
279
279
 
280
- specify "should validate confirmation_of" do
280
+ it "should validate confirmation_of" do
281
281
  @c.send(:attr_accessor, :value_confirmation)
282
282
  @c.validates_confirmation_of :value
283
283
 
284
284
  @m.value = 'blah'
285
- @m.should_not be_valid
285
+ @m.wont_be :valid?
286
286
 
287
287
  @m.value_confirmation = 'blah'
288
- @m.should be_valid
288
+ @m.must_be :valid?
289
289
  end
290
290
 
291
- specify "should validate confirmation_of with if => true" do
291
+ it "should validate confirmation_of with if => true" do
292
292
  @c.send(:attr_accessor, :value_confirmation)
293
293
  @c.validates_confirmation_of :value, :if => :dont_skip
294
294
 
295
295
  @m.value = 'blah'
296
- @m.should_not be_valid
296
+ @m.wont_be :valid?
297
297
  end
298
298
 
299
- specify "should validate confirmation_of with if => false" do
299
+ it "should validate confirmation_of with if => false" do
300
300
  @c.send(:attr_accessor, :value_confirmation)
301
301
  @c.validates_confirmation_of :value, :if => :skip
302
302
 
303
303
  @m.value = 'blah'
304
- @m.should be_valid
304
+ @m.must_be :valid?
305
305
  end
306
306
 
307
- specify "should validate confirmation_of with allow_missing => true" do
307
+ it "should validate confirmation_of with allow_missing => true" do
308
308
  @c.send(:attr_accessor, :value_confirmation)
309
309
  @c.validates_acceptance_of :value, :allow_missing => true
310
- @m.should be_valid
310
+ @m.must_be :valid?
311
311
  @m.value_confirmation = 'blah'
312
- @m.should be_valid
312
+ @m.must_be :valid?
313
313
  @m.value = nil
314
- @m.should_not be_valid
314
+ @m.wont_be :valid?
315
315
  end
316
316
 
317
- specify "should validate format_of" do
317
+ it "should validate format_of" do
318
318
  @c.validates_format_of :value, :with => /.+_.+/
319
319
  @m.value = 'abc_'
320
- @m.should_not be_valid
320
+ @m.wont_be :valid?
321
321
  @m.value = 'abc_def'
322
- @m.should be_valid
322
+ @m.must_be :valid?
323
323
  end
324
324
 
325
- specify "should raise for validate_format_of without regexp" do
326
- proc {@c.validates_format_of :value}.should raise_error(ArgumentError)
327
- proc {@c.validates_format_of :value, :with => :blah}.should raise_error(ArgumentError)
325
+ it "should raise for validate_format_of without regexp" do
326
+ proc {@c.validates_format_of :value}.must_raise(ArgumentError)
327
+ proc {@c.validates_format_of :value, :with => :blah}.must_raise(ArgumentError)
328
328
  end
329
329
 
330
- specify "should validate format_of with if => true" do
330
+ it "should validate format_of with if => true" do
331
331
  @c.validates_format_of :value, :with => /_/, :if => :dont_skip
332
332
 
333
333
  @m.value = 'a'
334
- @m.should_not be_valid
334
+ @m.wont_be :valid?
335
335
  end
336
336
 
337
- specify "should validate format_of with if => false" do
337
+ it "should validate format_of with if => false" do
338
338
  @c.validates_format_of :value, :with => /_/, :if => :skip
339
339
 
340
340
  @m.value = 'a'
341
- @m.should be_valid
341
+ @m.must_be :valid?
342
342
  end
343
343
 
344
- specify "should validate format_of with allow_missing => true" do
344
+ it "should validate format_of with allow_missing => true" do
345
345
  @c.validates_format_of :value, :allow_missing => true, :with=>/./
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
  end
350
350
 
351
- specify "should validate length_of with maximum" do
351
+ it "should validate length_of with maximum" do
352
352
  @c.validates_length_of :value, :maximum => 5
353
- @m.should_not be_valid
353
+ @m.wont_be :valid?
354
354
  @m.value = '12345'
355
- @m.should be_valid
355
+ @m.must_be :valid?
356
356
  @m.value = '123456'
357
- @m.should_not be_valid
358
- @m.errors[:value].should == ['is too long']
357
+ @m.wont_be :valid?
358
+ @m.errors[:value].must_equal ['is too long']
359
359
  @m.value = nil
360
- @m.should_not be_valid
361
- @m.errors[:value].should == ['is not present']
360
+ @m.wont_be :valid?
361
+ @m.errors[:value].must_equal ['is not present']
362
362
  end
363
363
 
364
- specify "should validate length_of with maximum using customized error messages" do
364
+ it "should validate length_of with maximum using customized error messages" do
365
365
  @c.validates_length_of :value, :maximum => 5, :too_long=>'tl', :nil_message=>'np'
366
366
  @m.value = '123456'
367
- @m.should_not be_valid
368
- @m.errors[:value].should == ['tl']
367
+ @m.wont_be :valid?
368
+ @m.errors[:value].must_equal ['tl']
369
369
  @m.value = nil
370
- @m.should_not be_valid
371
- @m.errors[:value].should == ['np']
370
+ @m.wont_be :valid?
371
+ @m.errors[:value].must_equal ['np']
372
372
  end
373
373
 
374
- specify "should validate length_of with minimum" do
374
+ it "should validate length_of with minimum" do
375
375
  @c.validates_length_of :value, :minimum => 5
376
- @m.should_not be_valid
376
+ @m.wont_be :valid?
377
377
  @m.value = '12345'
378
- @m.should be_valid
378
+ @m.must_be :valid?
379
379
  @m.value = '1234'
380
- @m.should_not be_valid
380
+ @m.wont_be :valid?
381
381
  end
382
382
 
383
- specify "should validate length_of with within" do
383
+ it "should validate length_of with within" do
384
384
  @c.validates_length_of :value, :within => 2..5
385
- @m.should_not be_valid
385
+ @m.wont_be :valid?
386
386
  @m.value = '12345'
387
- @m.should be_valid
387
+ @m.must_be :valid?
388
388
  @m.value = '1'
389
- @m.should_not be_valid
389
+ @m.wont_be :valid?
390
390
  @m.value = '123456'
391
- @m.should_not be_valid
391
+ @m.wont_be :valid?
392
392
  end
393
393
 
394
- specify "should validate length_of with is" do
394
+ it "should validate length_of with is" do
395
395
  @c.validates_length_of :value, :is => 3
396
- @m.should_not be_valid
396
+ @m.wont_be :valid?
397
397
  @m.value = '123'
398
- @m.should be_valid
398
+ @m.must_be :valid?
399
399
  @m.value = '12'
400
- @m.should_not be_valid
400
+ @m.wont_be :valid?
401
401
  @m.value = '1234'
402
- @m.should_not be_valid
402
+ @m.wont_be :valid?
403
403
  end
404
404
 
405
- specify "should validate length_of with allow_nil" do
405
+ it "should validate length_of with allow_nil" do
406
406
  @c.validates_length_of :value, :is => 3, :allow_nil => true
407
- @m.should be_valid
407
+ @m.must_be :valid?
408
408
  end
409
409
 
410
- specify "should validate length_of with if => true" do
410
+ it "should validate length_of with if => true" do
411
411
  @c.validates_length_of :value, :is => 3, :if => :dont_skip
412
412
 
413
413
  @m.value = 'a'
414
- @m.should_not be_valid
414
+ @m.wont_be :valid?
415
415
  end
416
416
 
417
- specify "should validate length_of with if => false" do
417
+ it "should validate length_of with if => false" do
418
418
  @c.validates_length_of :value, :is => 3, :if => :skip
419
419
 
420
420
  @m.value = 'a'
421
- @m.should be_valid
421
+ @m.must_be :valid?
422
422
  end
423
423
 
424
- specify "should validate length_of with allow_missing => true" do
424
+ it "should validate length_of with allow_missing => true" do
425
425
  @c.validates_length_of :value, :allow_missing => true, :minimum => 5
426
- @m.should be_valid
426
+ @m.must_be :valid?
427
427
  @m.value = nil
428
- @m.should_not be_valid
428
+ @m.wont_be :valid?
429
429
  end
430
430
 
431
- specify "should allow multiple calls to validates_length_of with different options without overwriting" do
431
+ it "should allow multiple calls to validates_length_of with different options without overwriting" do
432
432
  @c.validates_length_of :value, :maximum => 5
433
433
  @c.validates_length_of :value, :minimum => 5
434
- @m.should_not be_valid
434
+ @m.wont_be :valid?
435
435
  @m.value = '12345'
436
- @m.should be_valid
436
+ @m.must_be :valid?
437
437
  @m.value = '123456'
438
- @m.should_not be_valid
438
+ @m.wont_be :valid?
439
439
  @m.value = '12345'
440
- @m.should be_valid
440
+ @m.must_be :valid?
441
441
  @m.value = '1234'
442
- @m.should_not be_valid
442
+ @m.wont_be :valid?
443
443
  end
444
444
 
445
- specify "should validate numericality_of" do
445
+ it "should validate numericality_of" do
446
446
  @c.validates_numericality_of :value
447
447
  @m.value = 'blah'
448
- @m.should_not be_valid
448
+ @m.wont_be :valid?
449
449
  @m.value = '123'
450
- @m.should be_valid
450
+ @m.must_be :valid?
451
451
  @m.value = '123.1231'
452
- @m.should be_valid
452
+ @m.must_be :valid?
453
453
  @m.value = '+1'
454
- @m.should be_valid
454
+ @m.must_be :valid?
455
455
  @m.value = '-1'
456
- @m.should be_valid
456
+ @m.must_be :valid?
457
457
  @m.value = '+1.123'
458
- @m.should be_valid
458
+ @m.must_be :valid?
459
459
  @m.value = '-0.123'
460
- @m.should be_valid
460
+ @m.must_be :valid?
461
461
  @m.value = '-0.123E10'
462
- @m.should be_valid
462
+ @m.must_be :valid?
463
463
  @m.value = '32.123e10'
464
- @m.should be_valid
464
+ @m.must_be :valid?
465
465
  @m.value = '+32.123E10'
466
- @m.should be_valid
467
- @m.should be_valid
466
+ @m.must_be :valid?
467
+ @m.must_be :valid?
468
468
  @m.value = '.0123'
469
469
  end
470
470
 
471
- specify "should validate numericality_of with only_integer" do
471
+ it "should validate numericality_of with only_integer" do
472
472
  @c.validates_numericality_of :value, :only_integer => true
473
473
  @m.value = 'blah'
474
- @m.should_not be_valid
474
+ @m.wont_be :valid?
475
475
  @m.value = '123'
476
- @m.should be_valid
476
+ @m.must_be :valid?
477
477
  @m.value = '123.1231'
478
- @m.should_not be_valid
478
+ @m.wont_be :valid?
479
479
  end
480
480
 
481
- specify "should validate numericality_of with if => true" do
481
+ it "should validate numericality_of with if => true" do
482
482
  @c.validates_numericality_of :value, :if => :dont_skip
483
483
 
484
484
  @m.value = 'a'
485
- @m.should_not be_valid
485
+ @m.wont_be :valid?
486
486
  end
487
487
 
488
- specify "should validate numericality_of with if => false" do
488
+ it "should validate numericality_of with if => false" do
489
489
  @c.validates_numericality_of :value, :if => :skip
490
490
 
491
491
  @m.value = 'a'
492
- @m.should be_valid
492
+ @m.must_be :valid?
493
493
  end
494
494
 
495
- specify "should validate numericality_of with allow_missing => true" do
495
+ it "should validate numericality_of with allow_missing => true" do
496
496
  @c.validates_numericality_of :value, :allow_missing => true
497
- @m.should be_valid
497
+ @m.must_be :valid?
498
498
  @m.value = nil
499
- @m.should_not be_valid
499
+ @m.wont_be :valid?
500
500
  end
501
501
 
502
- specify "should validate presence_of" do
502
+ it "should validate presence_of" do
503
503
  @c.validates_presence_of :value
504
- @m.should_not be_valid
504
+ @m.wont_be :valid?
505
505
  @m.value = ''
506
- @m.should_not be_valid
506
+ @m.wont_be :valid?
507
507
  @m.value = 1234
508
- @m.should be_valid
508
+ @m.must_be :valid?
509
509
  @m.value = nil
510
- @m.should_not be_valid
510
+ @m.wont_be :valid?
511
511
  @m.value = true
512
- @m.should be_valid
512
+ @m.must_be :valid?
513
513
  @m.value = false
514
- @m.should be_valid
514
+ @m.must_be :valid?
515
515
  end
516
516
 
517
- specify "should validate inclusion_of with an array" do
517
+ it "should validate inclusion_of with an array" do
518
518
  @c.validates_inclusion_of :value, :in => [1,2]
519
- @m.should_not be_valid
519
+ @m.wont_be :valid?
520
520
  @m.value = 1
521
- @m.should be_valid
521
+ @m.must_be :valid?
522
522
  @m.value = 1.5
523
- @m.should_not be_valid
523
+ @m.wont_be :valid?
524
524
  @m.value = 2
525
- @m.should be_valid
525
+ @m.must_be :valid?
526
526
  @m.value = 3
527
- @m.should_not be_valid
527
+ @m.wont_be :valid?
528
528
  end
529
529
 
530
- specify "should validate inclusion_of with a range" do
530
+ it "should validate inclusion_of with a range" do
531
531
  @c.validates_inclusion_of :value, :in => 1..4
532
- @m.should_not be_valid
532
+ @m.wont_be :valid?
533
533
  @m.value = 1
534
- @m.should be_valid
534
+ @m.must_be :valid?
535
535
  @m.value = 1.5
536
- @m.should be_valid
536
+ @m.must_be :valid?
537
537
  @m.value = 0
538
- @m.should_not be_valid
538
+ @m.wont_be :valid?
539
539
  @m.value = 5
540
- @m.should_not be_valid
540
+ @m.wont_be :valid?
541
541
  end
542
542
 
543
- specify "should raise an error if inclusion_of doesn't receive a valid :in option" do
544
- lambda{@c.validates_inclusion_of :value}.should raise_error(ArgumentError)
545
- lambda{@c.validates_inclusion_of :value, :in => 1}.should raise_error(ArgumentError)
543
+ it "should raise an error if inclusion_of doesn't receive a valid :in option" do
544
+ lambda{@c.validates_inclusion_of :value}.must_raise(ArgumentError)
545
+ lambda{@c.validates_inclusion_of :value, :in => 1}.must_raise(ArgumentError)
546
546
  end
547
547
 
548
- specify "should raise an error if inclusion_of handles :allow_nil too" do
548
+ it "should raise an error if inclusion_of handles :allow_nil too" do
549
549
  @c.validates_inclusion_of :value, :in => 1..4, :allow_nil => true
550
550
  @m.value = nil
551
- @m.should be_valid
551
+ @m.must_be :valid?
552
552
  @m.value = 0
553
- @m.should_not be_valid
553
+ @m.wont_be :valid?
554
554
  end
555
555
 
556
- specify "should validate presence_of with if => true" do
556
+ it "should validate presence_of with if => true" do
557
557
  @c.validates_presence_of :value, :if => :dont_skip
558
- @m.should_not be_valid
558
+ @m.wont_be :valid?
559
559
  end
560
560
 
561
- specify "should validate presence_of with if => false" do
561
+ it "should validate presence_of with if => false" do
562
562
  @c.validates_presence_of :value, :if => :skip
563
- @m.should be_valid
563
+ @m.must_be :valid?
564
564
  end
565
565
 
566
- specify "should validate presence_of with allow_missing => true" do
566
+ it "should validate presence_of with allow_missing => true" do
567
567
  @c.validates_presence_of :value, :allow_missing => true
568
- @m.should be_valid
568
+ @m.must_be :valid?
569
569
  @m.value = nil
570
- @m.should_not be_valid
570
+ @m.wont_be :valid?
571
571
  end
572
572
 
573
- specify "should validate uniqueness_of with if => true" do
573
+ it "should validate uniqueness_of with if => true" do
574
574
  @c.validates_uniqueness_of :value, :if => :dont_skip
575
575
 
576
576
  @m.value = 'a'
577
- @m.should_not be_valid
577
+ @m.wont_be :valid?
578
578
  end
579
579
 
580
- specify "should validate uniqueness_of with if => false" do
580
+ it "should validate uniqueness_of with if => false" do
581
581
  @c.validates_uniqueness_of :value, :if => :skip
582
582
  @m.value = 'a'
583
- @m.should be_valid
583
+ @m.must_be :valid?
584
584
  end
585
585
 
586
- specify "should validate uniqueness_of with allow_missing => true" do
586
+ it "should validate uniqueness_of with allow_missing => true" do
587
587
  @c.validates_uniqueness_of :value, :allow_missing => true
588
- @m.should be_valid
588
+ @m.must_be :valid?
589
589
  @m.value = 1
590
- @m.should_not be_valid
590
+ @m.wont_be :valid?
591
591
  end
592
592
  end
593
593
 
@@ -605,44 +605,44 @@ describe "Superclass validations" do
605
605
  end
606
606
  end
607
607
 
608
- specify "should be checked when validating" do
608
+ it "should be checked when validating" do
609
609
  o = @c2.new
610
610
  o.value = 'ab'
611
- o.valid?.should == false
612
- o.errors.full_messages.should == ['value is too short']
611
+ o.valid?.must_equal false
612
+ o.errors.full_messages.must_equal ['value is too short']
613
613
 
614
614
  o.value = '12'
615
- o.valid?.should == false
616
- o.errors.full_messages.should == ['value is too short', 'value is invalid']
615
+ o.valid?.must_equal false
616
+ o.errors.full_messages.must_equal ['value is too short', 'value is invalid']
617
617
 
618
618
  o.value = 'abcde'
619
- o.valid?.should == true
619
+ o.valid?.must_equal true
620
620
  end
621
621
 
622
- specify "should have skip_superclass_validations? return whether superclass validations were skipped" do
623
- @c2.skip_superclass_validations?.should == nil
622
+ it "should have skip_superclass_validations? return whether superclass validations were skipped" do
623
+ @c2.skip_superclass_validations?.must_equal nil
624
624
  @c2.skip_superclass_validations
625
- @c2.skip_superclass_validations?.should == true
625
+ @c2.skip_superclass_validations?.must_equal true
626
626
  end
627
627
 
628
- specify "should be skipped if skip_superclass_validations is called" do
628
+ it "should be skipped if skip_superclass_validations is called" do
629
629
  @c2.skip_superclass_validations
630
630
 
631
631
  o = @c2.new
632
632
  o.value = 'ab'
633
- o.valid?.should == true
633
+ o.valid?.must_equal true
634
634
 
635
635
  o.value = '12'
636
- o.valid?.should == false
637
- o.errors.full_messages.should == ['value is invalid']
636
+ o.valid?.must_equal false
637
+ o.errors.full_messages.must_equal ['value is invalid']
638
638
 
639
639
  o.value = 'abcde'
640
- o.valid?.should == true
640
+ o.valid?.must_equal true
641
641
  end
642
642
  end
643
643
 
644
644
  describe ".validates with block" do
645
- specify "should support calling .each" do
645
+ it "should support calling .each" do
646
646
  @c = model_class.call Sequel::Model do
647
647
  columns :vvv
648
648
  validates do
@@ -654,15 +654,14 @@ describe ".validates with block" do
654
654
 
655
655
  o = @c.new
656
656
  o.vvv = 1
657
- o.should be_valid
657
+ o.must_be :valid?
658
658
  o.vvv = -1
659
- o.should_not be_valid
659
+ o.wont_be :valid?
660
660
  end
661
661
  end
662
662
 
663
663
  describe Sequel::Model, "Validations" do
664
-
665
- before(:all) do
664
+ before do
666
665
  class ::Person < Sequel::Model
667
666
  plugin :validation_class_methods
668
667
  columns :id,:name,:first_name,:last_name,:middle_name,:initials,:age, :terms
@@ -691,7 +690,7 @@ describe Sequel::Model, "Validations" do
691
690
  columns :id, :zip_code
692
691
  end
693
692
  end
694
- after(:all) do
693
+ after do
695
694
  [:Person, :Smurf, :Cow, :User, :Address].each{|c| Object.send(:remove_const, c)}
696
695
  end
697
696
 
@@ -702,11 +701,11 @@ describe Sequel::Model, "Validations" do
702
701
  end
703
702
 
704
703
  @cow = Cow.new
705
- @cow.should_not be_valid
706
- @cow.errors.full_messages.should == ["got_milk is not accepted"]
704
+ @cow.wont_be :valid?
705
+ @cow.errors.full_messages.must_equal ["got_milk is not accepted"]
707
706
 
708
707
  @cow.got_milk = "blah"
709
- @cow.should be_valid
708
+ @cow.must_be :valid?
710
709
  end
711
710
 
712
711
  it "should validate the confirmation of a column" do
@@ -720,11 +719,11 @@ describe Sequel::Model, "Validations" do
720
719
  end
721
720
 
722
721
  @user = User.new
723
- @user.should_not be_valid
724
- @user.errors.full_messages.should == ["password is not confirmed"]
722
+ @user.wont_be :valid?
723
+ @user.errors.full_messages.must_equal ["password is not confirmed"]
725
724
 
726
725
  @user.password = "test"
727
- @user.should be_valid
726
+ @user.must_be :valid?
728
727
  end
729
728
 
730
729
  it "should validate format of column" do
@@ -733,9 +732,9 @@ describe Sequel::Model, "Validations" do
733
732
  end
734
733
 
735
734
  @person = Person.new :first_name => "Lancelot99"
736
- @person.valid?.should == false
735
+ @person.valid?.must_equal false
737
736
  @person = Person.new :first_name => "Anita"
738
- @person.valid?.should == true
737
+ @person.valid?.must_equal true
739
738
  end
740
739
 
741
740
  it "should validate length of column" do
@@ -754,20 +753,20 @@ describe Sequel::Model, "Validations" do
754
753
  :middle_name => "danger"
755
754
  )
756
755
 
757
- @person.should_not be_valid
758
- @person.errors.full_messages.size.should == 4
759
- @person.errors.full_messages.should include(
756
+ @person.wont_be :valid?
757
+ @person.errors.full_messages.size.must_equal 4
758
+ @person.errors.full_messages.sort.must_equal [
760
759
  'first_name is too long',
760
+ 'initials is the wrong length',
761
761
  'last_name is too short',
762
- 'middle_name is the wrong length',
763
- 'initials is the wrong length'
764
- )
762
+ 'middle_name is the wrong length'
763
+ ]
765
764
 
766
765
  @person.first_name = "Lancelot"
767
766
  @person.last_name = "1234567890123456789012345678901"
768
767
  @person.initials = "LC"
769
768
  @person.middle_name = "Will"
770
- @person.should be_valid
769
+ @person.must_be :valid?
771
770
  end
772
771
 
773
772
  it "should validate that a column has the correct type for the schema column" do
@@ -780,19 +779,19 @@ describe Sequel::Model, "Validations" do
780
779
  end
781
780
 
782
781
  @person = p.new
783
- @person.should be_valid
782
+ @person.must_be :valid?
784
783
 
785
784
  @person.age = 'a'
786
- @person.should_not be_valid
787
- @person.errors.full_messages.should == ['age is not a valid integer']
785
+ @person.wont_be :valid?
786
+ @person.errors.full_messages.must_equal ['age is not a valid integer']
788
787
  @person.age = 1
789
- @person.should be_valid
788
+ @person.must_be :valid?
790
789
 
791
790
  @person.d = 'a'
792
- @person.should_not be_valid
793
- @person.errors.full_messages.should == ['d is a bad choice']
791
+ @person.wont_be :valid?
792
+ @person.errors.full_messages.must_equal ['d is a bad choice']
794
793
  @person.d = Date.today
795
- @person.should be_valid
794
+ @person.must_be :valid?
796
795
  end
797
796
 
798
797
  it "should validate numericality of column" do
@@ -802,11 +801,11 @@ describe Sequel::Model, "Validations" do
802
801
  end
803
802
 
804
803
  @person = Person.new :age => "Twenty"
805
- @person.should_not be_valid
806
- @person.errors.full_messages.should == ['age is not a number']
804
+ @person.wont_be :valid?
805
+ @person.errors.full_messages.must_equal ['age is not a number']
807
806
 
808
807
  @person.age = 20
809
- @person.should be_valid
808
+ @person.must_be :valid?
810
809
  end
811
810
 
812
811
  it "should validate the presence of a column" do
@@ -816,11 +815,11 @@ describe Sequel::Model, "Validations" do
816
815
  end
817
816
 
818
817
  @cow = Cow.new
819
- @cow.should_not be_valid
820
- @cow.errors.full_messages.should == ['name is not present']
818
+ @cow.wont_be :valid?
819
+ @cow.errors.full_messages.must_equal ['name is not present']
821
820
 
822
821
  @cow.name = "Betsy"
823
- @cow.should be_valid
822
+ @cow.must_be :valid?
824
823
  end
825
824
 
826
825
  it "should validate the uniqueness of a column" do
@@ -844,30 +843,30 @@ describe Sequel::Model, "Validations" do
844
843
  end
845
844
 
846
845
  @user = User.new(:username => "2records", :password => "anothertest")
847
- @user.should_not be_valid
848
- @user.errors.full_messages.should == ['username is already taken']
846
+ @user.wont_be :valid?
847
+ @user.errors.full_messages.must_equal ['username is already taken']
849
848
 
850
849
  @user = User.new(:username => "1record", :password => "anothertest")
851
- @user.should_not be_valid
852
- @user.errors.full_messages.should == ['username is already taken']
850
+ @user.wont_be :valid?
851
+ @user.errors.full_messages.must_equal ['username is already taken']
853
852
 
854
853
  @user = User.load(:id=>4, :username => "1record", :password => "anothertest")
855
- @user.should_not be_valid
856
- @user.errors.full_messages.should == ['username is already taken']
854
+ @user.wont_be :valid?
855
+ @user.errors.full_messages.must_equal ['username is already taken']
857
856
 
858
857
  @user = User.load(:id=>3, :username => "1record", :password => "anothertest")
859
- @user.should be_valid
860
- @user.errors.full_messages.should == []
858
+ @user.must_be :valid?
859
+ @user.errors.full_messages.must_equal []
861
860
 
862
861
  @user = User.new(:username => "0records", :password => "anothertest")
863
- @user.should be_valid
864
- @user.errors.full_messages.should == []
862
+ @user.must_be :valid?
863
+ @user.errors.full_messages.must_equal []
865
864
 
866
865
  User.db.sqls
867
866
  @user = User.new(:password => "anothertest")
868
- @user.should be_valid
869
- @user.errors.full_messages.should == []
870
- User.db.sqls.should == []
867
+ @user.must_be :valid?
868
+ @user.errors.full_messages.must_equal []
869
+ User.db.sqls.must_equal []
871
870
  end
872
871
 
873
872
  it "should validate the uniqueness of multiple columns" do
@@ -895,40 +894,40 @@ describe Sequel::Model, "Validations" do
895
894
  end
896
895
 
897
896
  @user = User.new(:username => "2records", :password => "anothertest")
898
- @user.should_not be_valid
899
- @user.errors.full_messages.should == ['username and password is already taken']
897
+ @user.wont_be :valid?
898
+ @user.errors.full_messages.must_equal ['username and password is already taken']
900
899
 
901
900
  @user = User.new(:username => "1record", :password => "anothertest")
902
- @user.should_not be_valid
903
- @user.errors.full_messages.should == ['username and password is already taken']
901
+ @user.wont_be :valid?
902
+ @user.errors.full_messages.must_equal ['username and password is already taken']
904
903
 
905
904
  @user = User.load(:id=>4, :username => "1record", :password => "anothertest")
906
- @user.should_not be_valid
907
- @user.errors.full_messages.should == ['username and password is already taken']
905
+ @user.wont_be :valid?
906
+ @user.errors.full_messages.must_equal ['username and password is already taken']
908
907
 
909
908
  @user = User.load(:id=>3, :username => "1record", :password => "test")
910
- @user.should_not be_valid
911
- @user.errors.full_messages.should == ['username and password is already taken']
909
+ @user.wont_be :valid?
910
+ @user.errors.full_messages.must_equal ['username and password is already taken']
912
911
 
913
912
  @user = User.load(:id=>3, :username => "1record", :password => "anothertest")
914
- @user.should be_valid
915
- @user.errors.full_messages.should == []
913
+ @user.must_be :valid?
914
+ @user.errors.full_messages.must_equal []
916
915
 
917
916
  @user = User.new(:username => "0records", :password => "anothertest")
918
- @user.should be_valid
919
- @user.errors.full_messages.should == []
917
+ @user.must_be :valid?
918
+ @user.errors.full_messages.must_equal []
920
919
 
921
920
  User.db.sqls
922
921
  @user = User.new(:password => "anothertest")
923
- @user.should be_valid
924
- @user.errors.full_messages.should == []
922
+ @user.must_be :valid?
923
+ @user.errors.full_messages.must_equal []
925
924
  @user = User.new(:username => "0records")
926
- @user.should be_valid
927
- @user.errors.full_messages.should == []
925
+ @user.must_be :valid?
926
+ @user.errors.full_messages.must_equal []
928
927
  @user = User.new
929
- @user.should be_valid
930
- @user.errors.full_messages.should == []
931
- User.db.sqls.should == []
928
+ @user.must_be :valid?
929
+ @user.errors.full_messages.must_equal []
930
+ User.db.sqls.must_equal []
932
931
  end
933
932
 
934
933
  it "should have a validates block that contains multiple validations" do
@@ -940,23 +939,21 @@ describe Sequel::Model, "Validations" do
940
939
  end
941
940
  end
942
941
 
943
- Person.validations[:first_name].size.should == 2
942
+ Person.validations[:first_name].size.must_equal 2
944
943
 
945
944
  @person = Person.new :first_name => "Lancelot99"
946
- @person.valid?.should == false
945
+ @person.valid?.must_equal false
947
946
 
948
947
  @person2 = Person.new :first_name => "Wayne"
949
- @person2.valid?.should == true
948
+ @person2.valid?.must_equal true
950
949
  end
951
950
 
952
951
  it "should allow 'longhand' validations direcly within the model." do
953
- lambda {
954
- class ::Person < Sequel::Model
955
- validations.clear
956
- validates_length_of :first_name, :maximum => 30
957
- end
958
- }.should_not raise_error
959
- Person.validations.length.should eql(1)
952
+ class ::Person < Sequel::Model
953
+ validations.clear
954
+ validates_length_of :first_name, :maximum => 30
955
+ end
956
+ Person.validations.length.must_equal(1)
960
957
  end
961
958
 
962
959
  it "should define a has_validations? method which returns true if the model has validations, false otherwise" do
@@ -972,8 +969,8 @@ describe Sequel::Model, "Validations" do
972
969
  validations.clear
973
970
  end
974
971
 
975
- Person.should have_validations
976
- Smurf.should_not have_validations
972
+ Person.validations.wont_be :empty?
973
+ Smurf.validations.must_be :empty?
977
974
  end
978
975
 
979
976
  it "should validate correctly instances initialized with string keys" do
@@ -981,8 +978,8 @@ describe Sequel::Model, "Validations" do
981
978
  validates_length_of :name, :minimum => 4
982
979
  end
983
980
 
984
- Can.new('name' => 'ab').should_not be_valid
985
- Can.new('name' => 'abcd').should be_valid
981
+ Can.new('name' => 'ab').wont_be :valid?
982
+ Can.new('name' => 'abcd').must_be :valid?
986
983
  end
987
984
 
988
985
  end
@@ -1000,31 +997,31 @@ describe "Model#save" do
1000
997
  DB.reset
1001
998
  end
1002
999
 
1003
- specify "should save only if validations pass" do
1000
+ it "should save only if validations pass" do
1004
1001
  @m.raise_on_save_failure = false
1005
- @m.should_not be_valid
1002
+ @m.wont_be :valid?
1006
1003
  @m.save
1007
- DB.sqls.should be_empty
1004
+ DB.sqls.must_be :empty?
1008
1005
 
1009
1006
  @m.x = 7
1010
- @m.should be_valid
1011
- @m.save.should_not == false
1012
- DB.sqls.should == ['UPDATE people SET x = 7 WHERE (id = 4)']
1007
+ @m.must_be :valid?
1008
+ @m.save.wont_equal false
1009
+ DB.sqls.must_equal ['UPDATE people SET x = 7 WHERE (id = 4)']
1013
1010
  end
1014
1011
 
1015
- specify "should skip validations if the :validate=>false option is used" do
1012
+ it "should skip validations if the :validate=>false option is used" do
1016
1013
  @m.raise_on_save_failure = false
1017
- @m.should_not be_valid
1014
+ @m.wont_be :valid?
1018
1015
  @m.save(:validate=>false)
1019
- DB.sqls.should == ['UPDATE people SET x = 6 WHERE (id = 4)']
1016
+ DB.sqls.must_equal ['UPDATE people SET x = 6 WHERE (id = 4)']
1020
1017
  end
1021
1018
 
1022
- specify "should raise error if validations fail and raise_on_save_faiure is true" do
1023
- proc{@m.save}.should raise_error(Sequel::ValidationFailed)
1019
+ it "should raise error if validations fail and raise_on_save_faiure is true" do
1020
+ proc{@m.save}.must_raise(Sequel::ValidationFailed)
1024
1021
  end
1025
1022
 
1026
- specify "should return nil if validations fail and raise_on_save_faiure is false" do
1023
+ it "should return nil if validations fail and raise_on_save_faiure is false" do
1027
1024
  @m.raise_on_save_failure = false
1028
- @m.save.should == nil
1025
+ @m.save.must_equal nil
1029
1026
  end
1030
1027
  end