sequel 4.22.0 → 4.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +22 -0
  3. data/README.rdoc +6 -0
  4. data/Rakefile +59 -81
  5. data/doc/migration.rdoc +2 -0
  6. data/doc/release_notes/4.23.0.txt +65 -0
  7. data/doc/sharding.rdoc +16 -14
  8. data/doc/testing.rdoc +61 -77
  9. data/lib/sequel/adapters/jdbc.rb +1 -0
  10. data/lib/sequel/adapters/mock.rb +0 -1
  11. data/lib/sequel/adapters/postgres.rb +1 -0
  12. data/lib/sequel/adapters/postgresql.rb +1 -0
  13. data/lib/sequel/adapters/shared/postgres.rb +3 -3
  14. data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
  15. data/lib/sequel/connection_pool/threaded.rb +9 -1
  16. data/lib/sequel/database/connecting.rb +1 -1
  17. data/lib/sequel/database/transactions.rb +2 -1
  18. data/lib/sequel/dataset/prepared_statements.rb +1 -1
  19. data/lib/sequel/extensions/constraint_validations.rb +12 -12
  20. data/lib/sequel/extensions/date_arithmetic.rb +0 -4
  21. data/lib/sequel/extensions/pagination.rb +14 -2
  22. data/lib/sequel/extensions/pg_enum.rb +2 -2
  23. data/lib/sequel/extensions/pg_hstore.rb +1 -1
  24. data/lib/sequel/extensions/pg_json_ops.rb +2 -2
  25. data/lib/sequel/plugins/csv_serializer.rb +2 -0
  26. data/lib/sequel/plugins/delay_add_association.rb +50 -0
  27. data/lib/sequel/plugins/list.rb +2 -2
  28. data/lib/sequel/plugins/nested_attributes.rb +8 -28
  29. data/lib/sequel/plugins/update_refresh.rb +50 -0
  30. data/lib/sequel/plugins/validate_associated.rb +55 -0
  31. data/lib/sequel/version.rb +1 -1
  32. data/spec/adapters/db2_spec.rb +29 -29
  33. data/spec/adapters/firebird_spec.rb +97 -103
  34. data/spec/adapters/informix_spec.rb +25 -25
  35. data/spec/adapters/mssql_spec.rb +156 -172
  36. data/spec/adapters/mysql_spec.rb +334 -359
  37. data/spec/adapters/oracle_spec.rb +67 -69
  38. data/spec/adapters/postgres_spec.rb +1298 -1249
  39. data/spec/adapters/spec_helper.rb +2 -35
  40. data/spec/adapters/sqlanywhere_spec.rb +39 -39
  41. data/spec/adapters/sqlite_spec.rb +203 -200
  42. data/spec/bin_spec.rb +57 -59
  43. data/spec/core/connection_pool_spec.rb +402 -401
  44. data/spec/core/database_spec.rb +953 -944
  45. data/spec/core/dataset_spec.rb +2178 -2168
  46. data/spec/core/deprecated_spec.rb +19 -19
  47. data/spec/core/expression_filters_spec.rb +415 -415
  48. data/spec/core/mock_adapter_spec.rb +212 -212
  49. data/spec/core/object_graph_spec.rb +73 -73
  50. data/spec/core/placeholder_literalizer_spec.rb +71 -71
  51. data/spec/core/schema_generator_spec.rb +44 -44
  52. data/spec/core/schema_spec.rb +470 -472
  53. data/spec/core/spec_helper.rb +5 -20
  54. data/spec/core/version_spec.rb +2 -2
  55. data/spec/core_extensions_spec.rb +320 -320
  56. data/spec/extensions/accessed_columns_spec.rb +12 -12
  57. data/spec/extensions/active_model_spec.rb +3 -3
  58. data/spec/extensions/after_initialize_spec.rb +2 -2
  59. data/spec/extensions/arbitrary_servers_spec.rb +23 -23
  60. data/spec/extensions/association_dependencies_spec.rb +34 -34
  61. data/spec/extensions/association_pks_spec.rb +98 -98
  62. data/spec/extensions/association_proxies_spec.rb +33 -33
  63. data/spec/extensions/auto_validations_spec.rb +46 -46
  64. data/spec/extensions/blacklist_security_spec.rb +19 -18
  65. data/spec/extensions/blank_spec.rb +36 -36
  66. data/spec/extensions/boolean_readers_spec.rb +36 -36
  67. data/spec/extensions/caching_spec.rb +82 -82
  68. data/spec/extensions/class_table_inheritance_spec.rb +72 -72
  69. data/spec/extensions/column_conflicts_spec.rb +19 -14
  70. data/spec/extensions/column_select_spec.rb +19 -19
  71. data/spec/extensions/columns_introspection_spec.rb +43 -43
  72. data/spec/extensions/composition_spec.rb +64 -64
  73. data/spec/extensions/connection_validator_spec.rb +92 -90
  74. data/spec/extensions/constraint_validations_plugin_spec.rb +92 -92
  75. data/spec/extensions/constraint_validations_spec.rb +80 -80
  76. data/spec/extensions/core_refinements_spec.rb +220 -220
  77. data/spec/extensions/csv_serializer_spec.rb +44 -44
  78. data/spec/extensions/current_datetime_timestamp_spec.rb +8 -8
  79. data/spec/extensions/dataset_associations_spec.rb +65 -65
  80. data/spec/extensions/dataset_source_alias_spec.rb +16 -16
  81. data/spec/extensions/date_arithmetic_spec.rb +51 -58
  82. data/spec/extensions/defaults_setter_spec.rb +19 -19
  83. data/spec/extensions/delay_add_association_spec.rb +52 -0
  84. data/spec/extensions/dirty_spec.rb +51 -51
  85. data/spec/extensions/eager_each_spec.rb +8 -8
  86. data/spec/extensions/empty_array_ignore_nulls_spec.rb +10 -10
  87. data/spec/extensions/error_splitter_spec.rb +2 -2
  88. data/spec/extensions/error_sql_spec.rb +4 -4
  89. data/spec/extensions/eval_inspect_spec.rb +3 -3
  90. data/spec/extensions/filter_having_spec.rb +8 -8
  91. data/spec/extensions/force_encoding_spec.rb +30 -30
  92. data/spec/extensions/from_block_spec.rb +7 -7
  93. data/spec/extensions/graph_each_spec.rb +19 -19
  94. data/spec/extensions/hash_aliases_spec.rb +5 -5
  95. data/spec/extensions/hook_class_methods_spec.rb +100 -100
  96. data/spec/extensions/inflector_spec.rb +54 -54
  97. data/spec/extensions/input_transformer_spec.rb +10 -10
  98. data/spec/extensions/insert_returning_select_spec.rb +8 -8
  99. data/spec/extensions/instance_filters_spec.rb +26 -26
  100. data/spec/extensions/instance_hooks_spec.rb +85 -85
  101. data/spec/extensions/json_serializer_spec.rb +68 -68
  102. data/spec/extensions/lazy_attributes_spec.rb +49 -49
  103. data/spec/extensions/list_spec.rb +77 -75
  104. data/spec/extensions/looser_typecasting_spec.rb +16 -16
  105. data/spec/extensions/many_through_many_spec.rb +627 -627
  106. data/spec/extensions/meta_def_spec.rb +7 -7
  107. data/spec/extensions/migration_spec.rb +217 -217
  108. data/spec/extensions/modification_detection_spec.rb +20 -20
  109. data/spec/extensions/mssql_optimistic_locking_spec.rb +21 -21
  110. data/spec/extensions/named_timezones_spec.rb +18 -18
  111. data/spec/extensions/nested_attributes_spec.rb +107 -107
  112. data/spec/extensions/null_dataset_spec.rb +24 -24
  113. data/spec/extensions/optimistic_locking_spec.rb +21 -21
  114. data/spec/extensions/pagination_spec.rb +52 -52
  115. data/spec/extensions/pg_array_associations_spec.rb +273 -273
  116. data/spec/extensions/pg_array_ops_spec.rb +52 -52
  117. data/spec/extensions/pg_array_spec.rb +152 -152
  118. data/spec/extensions/pg_enum_spec.rb +13 -13
  119. data/spec/extensions/pg_hstore_ops_spec.rb +63 -63
  120. data/spec/extensions/pg_hstore_spec.rb +84 -84
  121. data/spec/extensions/pg_inet_spec.rb +15 -15
  122. data/spec/extensions/pg_interval_spec.rb +29 -29
  123. data/spec/extensions/pg_json_ops_spec.rb +86 -84
  124. data/spec/extensions/pg_json_spec.rb +104 -104
  125. data/spec/extensions/pg_loose_count_spec.rb +6 -6
  126. data/spec/extensions/pg_range_ops_spec.rb +24 -24
  127. data/spec/extensions/pg_range_spec.rb +143 -143
  128. data/spec/extensions/pg_row_ops_spec.rb +14 -14
  129. data/spec/extensions/pg_row_plugin_spec.rb +12 -12
  130. data/spec/extensions/pg_row_spec.rb +118 -118
  131. data/spec/extensions/pg_static_cache_updater_spec.rb +28 -28
  132. data/spec/extensions/pg_typecast_on_load_spec.rb +21 -21
  133. data/spec/extensions/prepared_statements_associations_spec.rb +42 -42
  134. data/spec/extensions/prepared_statements_safe_spec.rb +18 -18
  135. data/spec/extensions/prepared_statements_spec.rb +28 -28
  136. data/spec/extensions/prepared_statements_with_pk_spec.rb +11 -11
  137. data/spec/extensions/pretty_table_spec.rb +16 -16
  138. data/spec/extensions/query_literals_spec.rb +37 -37
  139. data/spec/extensions/query_spec.rb +32 -32
  140. data/spec/extensions/rcte_tree_spec.rb +141 -141
  141. data/spec/extensions/round_timestamps_spec.rb +21 -21
  142. data/spec/extensions/schema_caching_spec.rb +8 -8
  143. data/spec/extensions/schema_dumper_spec.rb +78 -78
  144. data/spec/extensions/schema_spec.rb +31 -27
  145. data/spec/extensions/scissors_spec.rb +3 -3
  146. data/spec/extensions/select_remove_spec.rb +14 -14
  147. data/spec/extensions/sequel_3_dataset_methods_spec.rb +28 -28
  148. data/spec/extensions/serialization_modification_detection_spec.rb +33 -33
  149. data/spec/extensions/serialization_spec.rb +79 -78
  150. data/spec/extensions/server_block_spec.rb +17 -17
  151. data/spec/extensions/set_overrides_spec.rb +30 -30
  152. data/spec/extensions/sharding_spec.rb +65 -65
  153. data/spec/extensions/shared_caching_spec.rb +29 -29
  154. data/spec/extensions/single_table_inheritance_spec.rb +79 -79
  155. data/spec/extensions/skip_create_refresh_spec.rb +3 -3
  156. data/spec/extensions/spec_helper.rb +4 -29
  157. data/spec/extensions/split_array_nil_spec.rb +9 -9
  158. data/spec/extensions/split_values_spec.rb +7 -7
  159. data/spec/extensions/sql_expr_spec.rb +32 -32
  160. data/spec/extensions/static_cache_spec.rb +123 -123
  161. data/spec/extensions/string_date_time_spec.rb +34 -34
  162. data/spec/extensions/string_stripper_spec.rb +15 -15
  163. data/spec/extensions/subclasses_spec.rb +31 -31
  164. data/spec/extensions/table_select_spec.rb +15 -15
  165. data/spec/extensions/tactical_eager_loading_spec.rb +23 -23
  166. data/spec/extensions/thread_local_timezones_spec.rb +13 -13
  167. data/spec/extensions/timestamps_spec.rb +40 -40
  168. data/spec/extensions/to_dot_spec.rb +34 -34
  169. data/spec/extensions/touch_spec.rb +52 -52
  170. data/spec/extensions/tree_spec.rb +72 -72
  171. data/spec/extensions/typecast_on_load_spec.rb +25 -25
  172. data/spec/extensions/unlimited_update_spec.rb +2 -2
  173. data/spec/extensions/update_or_create_spec.rb +36 -36
  174. data/spec/extensions/update_primary_key_spec.rb +35 -35
  175. data/spec/extensions/update_refresh_spec.rb +41 -0
  176. data/spec/extensions/validate_associated_spec.rb +52 -0
  177. data/spec/extensions/validation_class_methods_spec.rb +314 -317
  178. data/spec/extensions/validation_helpers_spec.rb +195 -195
  179. data/spec/extensions/xml_serializer_spec.rb +48 -48
  180. data/spec/guards_helper.rb +55 -0
  181. data/spec/integration/associations_test.rb +1089 -1088
  182. data/spec/integration/database_test.rb +29 -29
  183. data/spec/integration/dataset_test.rb +661 -661
  184. data/spec/integration/eager_loader_test.rb +147 -147
  185. data/spec/integration/migrator_test.rb +122 -122
  186. data/spec/integration/model_test.rb +70 -70
  187. data/spec/integration/plugin_test.rb +682 -640
  188. data/spec/integration/prepared_statement_test.rb +172 -172
  189. data/spec/integration/schema_test.rb +245 -245
  190. data/spec/integration/spec_helper.rb +1 -64
  191. data/spec/integration/timezone_test.rb +17 -17
  192. data/spec/integration/transaction_test.rb +87 -87
  193. data/spec/integration/type_test.rb +33 -33
  194. data/spec/model/association_reflection_spec.rb +130 -121
  195. data/spec/model/associations_spec.rb +1112 -1113
  196. data/spec/model/base_spec.rb +197 -196
  197. data/spec/model/class_dataset_methods_spec.rb +118 -118
  198. data/spec/model/dataset_methods_spec.rb +49 -49
  199. data/spec/model/eager_loading_spec.rb +705 -702
  200. data/spec/model/hooks_spec.rb +169 -168
  201. data/spec/model/inflector_spec.rb +5 -5
  202. data/spec/model/model_spec.rb +287 -297
  203. data/spec/model/plugins_spec.rb +47 -47
  204. data/spec/model/record_spec.rb +534 -535
  205. data/spec/model/spec_helper.rb +3 -21
  206. data/spec/model/validations_spec.rb +72 -70
  207. data/spec/spec_config.rb +8 -0
  208. metadata +41 -9
  209. data/lib/sequel/adapters/fdbsql.rb +0 -286
  210. data/lib/sequel/adapters/jdbc/fdbsql.rb +0 -66
  211. data/lib/sequel/adapters/openbase.rb +0 -54
  212. data/lib/sequel/adapters/shared/fdbsql.rb +0 -550
  213. data/spec/adapters/fdbsql_spec.rb +0 -429
  214. data/spec/rspec_helper.rb +0 -22
@@ -18,27 +18,27 @@ describe "Sequel::Plugins::AssociationProxies" do
18
18
  end
19
19
 
20
20
  it "should send method calls to the associated object array if sent an array method" do
21
- @i.associations.has_key?(:tags).should == false
22
- @t.select{|x| false}.should == []
23
- @i.associations.has_key?(:tags).should == true
21
+ @i.associations.has_key?(:tags).must_equal false
22
+ @t.select{|x| false}.must_equal []
23
+ @i.associations.has_key?(:tags).must_equal true
24
24
  end
25
25
 
26
26
  it "should send method calls to the association dataset if sent a non-array method" do
27
- @i.associations.has_key?(:tags).should == false
28
- @t.filter(:a=>1).sql.should == "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
29
- @i.associations.has_key?(:tags).should == false
27
+ @i.associations.has_key?(:tags).must_equal false
28
+ @t.filter(:a=>1).sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
29
+ @i.associations.has_key?(:tags).must_equal false
30
30
  end
31
31
 
32
32
  it "should accept block to plugin to specify which methods to proxy to dataset" do
33
33
  Item.plugin :association_proxies do |opts|
34
34
  opts[:method] == :where || opts[:arguments].length == 2 || opts[:block]
35
35
  end
36
- @i.associations.has_key?(:tags).should == false
37
- @t.where(:a=>1).sql.should == "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
38
- @t.filter('a = ?', 1).sql.should == "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
39
- @t.filter{{:a=>1}}.sql.should == "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
36
+ @i.associations.has_key?(:tags).must_equal false
37
+ @t.where(:a=>1).sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
38
+ @t.filter('a = ?', 1).sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
39
+ @t.filter{{:a=>1}}.sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
40
40
 
41
- @i.associations.has_key?(:tags).should == false
41
+ @i.associations.has_key?(:tags).must_equal false
42
42
  Item.plugin :association_proxies do |opts|
43
43
  proxy_arg = opts[:proxy_argument]
44
44
  proxy_block = opts[:proxy_block]
@@ -46,41 +46,41 @@ describe "Sequel::Plugins::AssociationProxies" do
46
46
  is_size = opts[:method] == :size
47
47
  is_size && !cached && !proxy_arg && !proxy_block
48
48
  end
49
- @t.size.should == 1
50
- Item.db.sqls.should == ["SELECT count(*) AS count FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE (items_tags.item_id = 1) LIMIT 1"]
51
- @i.tags{|ds| ds}.size.should == 1
52
- Item.db.sqls.should == ["SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE (items_tags.item_id = 1)"]
53
- @i.tags(true).size.should == 1
54
- Item.db.sqls.should == ["SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE (items_tags.item_id = 1)"]
55
- @t.size.should == 1
56
- Item.db.sqls.should == []
49
+ @t.size.must_equal 1
50
+ Item.db.sqls.must_equal ["SELECT count(*) AS count FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE (items_tags.item_id = 1) LIMIT 1"]
51
+ @i.tags{|ds| ds}.size.must_equal 1
52
+ Item.db.sqls.must_equal ["SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE (items_tags.item_id = 1)"]
53
+ @i.tags(true).size.must_equal 1
54
+ Item.db.sqls.must_equal ["SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE (items_tags.item_id = 1)"]
55
+ @t.size.must_equal 1
56
+ Item.db.sqls.must_equal []
57
57
  end
58
58
 
59
59
  it "should reload the cached association if sent an array method and the reload flag was given" do
60
- @t.select{|x| false}.should == []
61
- Item.db.sqls.length.should == 1
62
- @t.select{|x| false}.should == []
63
- Item.db.sqls.length.should == 0
64
- @i.tags(true).select{|x| false}.should == []
65
- Item.db.sqls.length.should == 1
66
- @t.filter(:a=>1).sql.should == "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
67
- Item.db.sqls.length.should == 0
60
+ @t.select{|x| false}.must_equal []
61
+ Item.db.sqls.length.must_equal 1
62
+ @t.select{|x| false}.must_equal []
63
+ Item.db.sqls.length.must_equal 0
64
+ @i.tags(true).select{|x| false}.must_equal []
65
+ Item.db.sqls.length.must_equal 1
66
+ @t.filter(:a=>1).sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
67
+ Item.db.sqls.length.must_equal 0
68
68
  end
69
69
 
70
70
  it "should not return a proxy object for associations that do not return an array" do
71
71
  Item.many_to_one :tag
72
- proc{@i.tag.filter(:a=>1)}.should raise_error(NoMethodError)
72
+ proc{@i.tag.filter(:a=>1)}.must_raise(NoMethodError)
73
73
 
74
74
  Tag.one_to_one :item
75
- proc{Tag.load(:id=>1, :item_id=>2).item.filter(:a=>1)}.should raise_error(NoMethodError)
75
+ proc{Tag.load(:id=>1, :item_id=>2).item.filter(:a=>1)}.must_raise(NoMethodError)
76
76
  end
77
77
 
78
78
  it "should work correctly in subclasses" do
79
79
  i = Class.new(Item).load(:id=>1)
80
- i.associations.has_key?(:tags).should == false
81
- i.tags.select{|x| false}.should == []
82
- i.associations.has_key?(:tags).should == true
83
- i.tags.filter(:a=>1).sql.should == "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
80
+ i.associations.has_key?(:tags).must_equal false
81
+ i.tags.select{|x| false}.must_equal []
82
+ i.associations.has_key?(:tags).must_equal true
83
+ i.tags.filter(:a=>1).sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
84
84
  end
85
85
 
86
86
  end
@@ -28,131 +28,131 @@ describe "Sequel::Plugins::AutoValidations" do
28
28
  end
29
29
 
30
30
  it "should have automatically created validations" do
31
- @m.valid?.should == false
32
- @m.errors.should == {:d=>["is not present"], :name=>["is not present"]}
31
+ @m.valid?.must_equal false
32
+ @m.errors.must_equal(:d=>["is not present"], :name=>["is not present"])
33
33
 
34
34
  @m.name = ''
35
- @m.valid?.should == false
36
- @m.errors.should == {:d=>["is not present"]}
35
+ @m.valid?.must_equal false
36
+ @m.errors.must_equal(:d=>["is not present"])
37
37
 
38
38
  @m.set(:d=>'/', :num=>'a', :name=>'1')
39
- @m.valid?.should == false
40
- @m.errors.should == {:d=>["is not a valid date"], :num=>["is not a valid integer"]}
39
+ @m.valid?.must_equal false
40
+ @m.errors.must_equal(:d=>["is not a valid date"], :num=>["is not a valid integer"])
41
41
 
42
42
  @m.set(:d=>Date.today, :num=>1)
43
- @m.valid?.should == false
44
- @m.errors.should == {[:name, :num]=>["is already taken"]}
43
+ @m.valid?.must_equal false
44
+ @m.errors.must_equal([:name, :num]=>["is already taken"])
45
45
 
46
46
  @m.set(:name=>'a'*51)
47
- @m.valid?.should == false
48
- @m.errors.should == {:name=>["is longer than 50 characters"]}
47
+ @m.valid?.must_equal false
48
+ @m.errors.must_equal(:name=>["is longer than 50 characters"])
49
49
  end
50
50
 
51
51
  it "should handle databases that don't support index parsing" do
52
52
  def (@m.db).supports_index_parsing?() false end
53
53
  @m.model.send(:setup_auto_validations)
54
54
  @m.set(:d=>Date.today, :num=>1, :name=>'1')
55
- @m.valid?.should == true
55
+ @m.valid?.must_equal true
56
56
  end
57
57
 
58
58
  it "should handle models that select from subqueries" do
59
59
  @c.set_dataset @c.dataset.from_self
60
- proc{@c.send(:setup_auto_validations)}.should_not raise_error
60
+ @c.send(:setup_auto_validations)
61
61
  end
62
62
 
63
63
  it "should support :not_null=>:presence option" do
64
64
  @c.plugin :auto_validations, :not_null=>:presence
65
65
  @m.set(:d=>Date.today, :num=>'')
66
- @m.valid?.should == false
67
- @m.errors.should == {:name=>["is not present"]}
66
+ @m.valid?.must_equal false
67
+ @m.errors.must_equal(:name=>["is not present"])
68
68
  end
69
69
 
70
70
  it "should automatically validate explicit nil values for columns with not nil defaults" do
71
71
  @m.set(:d=>Date.today, :name=>1, :nnd=>nil)
72
72
  @m.id = nil
73
- @m.valid?.should == false
74
- @m.errors.should == {:id=>["is not present"], :nnd=>["is not present"]}
73
+ @m.valid?.must_equal false
74
+ @m.errors.must_equal(:id=>["is not present"], :nnd=>["is not present"])
75
75
  end
76
76
 
77
77
  it "should allow skipping validations by type" do
78
78
  @c = Class.new(@c)
79
79
  @m = @c.new
80
80
  @c.skip_auto_validations(:not_null)
81
- @m.valid?.should == true
81
+ @m.valid?.must_equal true
82
82
 
83
83
  @m.set(:d=>'/', :num=>'a', :name=>'1')
84
- @m.valid?.should == false
85
- @m.errors.should == {:d=>["is not a valid date"], :num=>["is not a valid integer"]}
84
+ @m.valid?.must_equal false
85
+ @m.errors.must_equal(:d=>["is not a valid date"], :num=>["is not a valid integer"])
86
86
 
87
87
  @c.skip_auto_validations(:types)
88
- @m.valid?.should == false
89
- @m.errors.should == {[:name, :num]=>["is already taken"]}
88
+ @m.valid?.must_equal false
89
+ @m.errors.must_equal([:name, :num]=>["is already taken"])
90
90
 
91
91
  @c.skip_auto_validations(:unique)
92
- @m.valid?.should == true
92
+ @m.valid?.must_equal true
93
93
 
94
94
  @m.set(:name=>'a'*51)
95
- @m.valid?.should == false
96
- @m.errors.should == {:name=>["is longer than 50 characters"]}
95
+ @m.valid?.must_equal false
96
+ @m.errors.must_equal(:name=>["is longer than 50 characters"])
97
97
 
98
98
  @c.skip_auto_validations(:max_length)
99
- @m.valid?.should == true
99
+ @m.valid?.must_equal true
100
100
  end
101
101
 
102
102
  it "should allow skipping all auto validations" do
103
103
  @c = Class.new(@c)
104
104
  @m = @c.new
105
105
  @c.skip_auto_validations(:all)
106
- @m.valid?.should == true
106
+ @m.valid?.must_equal true
107
107
  @m.set(:d=>'/', :num=>'a', :name=>'1')
108
- @m.valid?.should == true
108
+ @m.valid?.must_equal true
109
109
  @m.set(:name=>'a'*51)
110
- @m.valid?.should == true
110
+ @m.valid?.must_equal true
111
111
  end
112
112
 
113
113
  it "should work correctly in subclasses" do
114
114
  @c = Class.new(@c)
115
115
  @m = @c.new
116
- @m.valid?.should == false
117
- @m.errors.should == {:d=>["is not present"], :name=>["is not present"]}
116
+ @m.valid?.must_equal false
117
+ @m.errors.must_equal(:d=>["is not present"], :name=>["is not present"])
118
118
 
119
119
  @m.set(:d=>'/', :num=>'a', :name=>'1')
120
- @m.valid?.should == false
121
- @m.errors.should == {:d=>["is not a valid date"], :num=>["is not a valid integer"]}
120
+ @m.valid?.must_equal false
121
+ @m.errors.must_equal(:d=>["is not a valid date"], :num=>["is not a valid integer"])
122
122
 
123
123
  @m.set(:d=>Date.today, :num=>1)
124
- @m.valid?.should == false
125
- @m.errors.should == {[:name, :num]=>["is already taken"]}
124
+ @m.valid?.must_equal false
125
+ @m.errors.must_equal([:name, :num]=>["is already taken"])
126
126
 
127
127
  @m.set(:name=>'a'*51)
128
- @m.valid?.should == false
129
- @m.errors.should == {:name=>["is longer than 50 characters"]}
128
+ @m.valid?.must_equal false
129
+ @m.errors.must_equal(:name=>["is longer than 50 characters"])
130
130
  end
131
131
 
132
132
  it "should work correctly in STI subclasses" do
133
133
  @c.plugin(:single_table_inheritance, :num, :model_map=>{1=>@c}, :key_map=>proc{[1, 2]})
134
134
  sc = Class.new(@c)
135
135
  @m = sc.new
136
- @m.valid?.should == false
137
- @m.errors.should == {:d=>["is not present"], :name=>["is not present"]}
136
+ @m.valid?.must_equal false
137
+ @m.errors.must_equal(:d=>["is not present"], :name=>["is not present"])
138
138
 
139
139
  @m.set(:d=>'/', :num=>'a', :name=>'1')
140
- @m.valid?.should == false
141
- @m.errors.should == {:d=>["is not a valid date"], :num=>["is not a valid integer"]}
140
+ @m.valid?.must_equal false
141
+ @m.errors.must_equal(:d=>["is not a valid date"], :num=>["is not a valid integer"])
142
142
 
143
143
  @m.db.sqls
144
144
  @m.set(:d=>Date.today, :num=>1)
145
- @m.valid?.should == false
146
- @m.errors.should == {[:name, :num]=>["is already taken"]}
147
- @m.db.sqls.should == ["SELECT count(*) AS count FROM test WHERE ((name = '1') AND (num = 1)) LIMIT 1"]
145
+ @m.valid?.must_equal false
146
+ @m.errors.must_equal([:name, :num]=>["is already taken"])
147
+ @m.db.sqls.must_equal ["SELECT count(*) AS count FROM test WHERE ((name = '1') AND (num = 1)) LIMIT 1"]
148
148
 
149
149
  @m.set(:name=>'a'*51)
150
- @m.valid?.should == false
151
- @m.errors.should == {:name=>["is longer than 50 characters"]}
150
+ @m.valid?.must_equal false
151
+ @m.errors.must_equal(:name=>["is longer than 50 characters"])
152
152
  end
153
153
 
154
154
  it "should work correctly when changing the dataset" do
155
155
  @c.set_dataset(@c.db[:foo])
156
- @c.new.valid?.should == true
156
+ @c.new.valid?.must_equal true
157
157
  end
158
158
  end
@@ -16,24 +16,24 @@ describe Sequel::Model, "#(set|update)_except" do
16
16
 
17
17
  it "should raise errors if not all hash fields can be set and strict_param_setting is true" do
18
18
  @c.strict_param_setting = true
19
- proc{@c.new.set_except({:x => 1, :y => 2, :z=>3, :id=>4}, :x, :y)}.should raise_error(Sequel::MassAssignmentRestriction)
20
- proc{@c.new.set_except({:x => 1, :y => 2, :z=>3}, :x, :y)}.should raise_error(Sequel::MassAssignmentRestriction)
19
+ proc{@c.new.set_except({:x => 1, :y => 2, :z=>3, :id=>4}, :x, :y)}.must_raise(Sequel::MassAssignmentRestriction)
20
+ proc{@c.new.set_except({:x => 1, :y => 2, :z=>3}, :x, :y)}.must_raise(Sequel::MassAssignmentRestriction)
21
21
  (o = @c.new).set_except({:z => 3}, :x, :y)
22
- o.values.should == {:z=>3}
22
+ o.values.must_equal(:z=>3)
23
23
  end
24
24
 
25
25
  it "#set_except should not set given attributes or the primary key" do
26
26
  @o1.set_except({:x => 1, :y => 2, :z=>3, :id=>4}, [:y, :z])
27
- @o1.values.should == {:x => 1}
27
+ @o1.values.must_equal(:x => 1)
28
28
  @o1.set_except({:x => 4, :y => 2, :z=>3, :id=>4}, :y, :z)
29
- @o1.values.should == {:x => 4}
29
+ @o1.values.must_equal(:x => 4)
30
30
  end
31
31
 
32
32
  it "#update_except should not update given attributes" do
33
33
  @o1.update_except({:x => 1, :y => 2, :z=>3, :id=>4}, [:y, :z])
34
- DB.sqls.should == ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
34
+ DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
35
35
  @c.new.update_except({:x => 1, :y => 2, :z=>3, :id=>4}, :y, :z)
36
- DB.sqls.should == ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
36
+ DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
37
37
  end
38
38
  end
39
39
 
@@ -46,42 +46,43 @@ describe Sequel::Model, ".restricted_columns " do
46
46
  end
47
47
  @c.strict_param_setting = false
48
48
  @c.instance_variable_set(:@columns, [:x, :y, :z])
49
+ DB.sqls
49
50
  end
50
51
 
51
52
  it "should set the restricted columns correctly" do
52
- @c.restricted_columns.should == nil
53
+ @c.restricted_columns.must_equal nil
53
54
  @c.set_restricted_columns :x
54
- @c.restricted_columns.should == [:x]
55
+ @c.restricted_columns.must_equal [:x]
55
56
  @c.set_restricted_columns :x, :y
56
- @c.restricted_columns.should == [:x, :y]
57
+ @c.restricted_columns.must_equal [:x, :y]
57
58
  end
58
59
 
59
60
  it "should not set restricted columns by default" do
60
61
  @c.set_restricted_columns :z
61
62
  i = @c.new(:x => 1, :y => 2, :z => 3)
62
- i.values.should == {:x => 1, :y => 2}
63
+ i.values.must_equal(:x => 1, :y => 2)
63
64
  i.set(:x => 4, :y => 5, :z => 6)
64
- i.values.should == {:x => 4, :y => 5}
65
+ i.values.must_equal(:x => 4, :y => 5)
65
66
 
66
67
  @c.instance_dataset._fetch = @c.dataset._fetch = {:x => 7}
67
68
  i = @c.new
68
69
  i.update(:x => 7, :z => 9)
69
- i.values.should == {:x => 7}
70
- DB.sqls.should == ["INSERT INTO blahblah (x) VALUES (7)", "SELECT * FROM blahblah WHERE (id = 10) LIMIT 1"]
70
+ i.values.must_equal(:x => 7)
71
+ DB.sqls.must_equal ["INSERT INTO blahblah (x) VALUES (7)", "SELECT * FROM blahblah WHERE (id = 10) LIMIT 1"]
71
72
  end
72
73
 
73
74
  it "should have allowed take precedence over restricted" do
74
75
  @c.set_allowed_columns :x, :y
75
76
  @c.set_restricted_columns :y, :z
76
77
  i = @c.new(:x => 1, :y => 2, :z => 3)
77
- i.values.should == {:x => 1, :y => 2}
78
+ i.values.must_equal(:x => 1, :y => 2)
78
79
  i.set(:x => 4, :y => 5, :z => 6)
79
- i.values.should == {:x => 4, :y => 5}
80
+ i.values.must_equal(:x => 4, :y => 5)
80
81
 
81
82
  @c.instance_dataset._fetch = @c.dataset._fetch = {:y => 7}
82
83
  i = @c.new
83
84
  i.update(:y => 7, :z => 9)
84
- i.values.should == {:y => 7}
85
- DB.sqls.should == ["INSERT INTO blahblah (y) VALUES (7)", "SELECT * FROM blahblah WHERE (id = 10) LIMIT 1"]
85
+ i.values.must_equal(:y => 7)
86
+ DB.sqls.must_equal ["INSERT INTO blahblah (y) VALUES (7)", "SELECT * FROM blahblah WHERE (id = 10) LIMIT 1"]
86
87
  end
87
88
  end
@@ -3,67 +3,67 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
3
3
  Sequel.extension :blank
4
4
 
5
5
  describe "Object#blank?" do
6
- specify "it should be true if the object responds true to empty?" do
7
- [].blank?.should == true
8
- {}.blank?.should == true
6
+ it "it should be true if the object responds true to empty?" do
7
+ [].blank?.must_equal true
8
+ {}.blank?.must_equal true
9
9
  o = Object.new
10
10
  def o.empty?; true; end
11
- o.blank?.should == true
11
+ o.blank?.must_equal true
12
12
  end
13
13
 
14
- specify "it should be false if the object doesn't respond true to empty?" do
15
- [2].blank?.should == false
16
- {1=>2}.blank?.should == false
17
- Object.new.blank?.should == false
14
+ it "it should be false if the object doesn't respond true to empty?" do
15
+ [2].blank?.must_equal false
16
+ {1=>2}.blank?.must_equal false
17
+ Object.new.blank?.must_equal false
18
18
  end
19
19
  end
20
20
 
21
21
  describe "Numeric#blank?" do
22
- specify "it should always be false" do
23
- 1.blank?.should == false
24
- 0.blank?.should == false
25
- -1.blank?.should == false
26
- 1.0.blank?.should == false
27
- 0.0.blank?.should == false
28
- -1.0.blank?.should == false
29
- 10000000000000000.blank?.should == false
30
- -10000000000000000.blank?.should == false
31
- 10000000000000000.0.blank?.should == false
32
- -10000000000000000.0.blank?.should == false
22
+ it "it should always be false" do
23
+ 1.blank?.must_equal false
24
+ 0.blank?.must_equal false
25
+ -1.blank?.must_equal false
26
+ 1.0.blank?.must_equal false
27
+ 0.0.blank?.must_equal false
28
+ -1.0.blank?.must_equal false
29
+ 10000000000000000.blank?.must_equal false
30
+ -10000000000000000.blank?.must_equal false
31
+ 10000000000000000.0.blank?.must_equal false
32
+ -10000000000000000.0.blank?.must_equal false
33
33
  end
34
34
  end
35
35
 
36
36
  describe "NilClass#blank?" do
37
- specify "it should always be true" do
38
- nil.blank?.should == true
37
+ it "it should always be true" do
38
+ nil.blank?.must_equal true
39
39
  end
40
40
  end
41
41
 
42
42
  describe "TrueClass#blank?" do
43
- specify "it should always be false" do
44
- true.blank?.should == false
43
+ it "it should always be false" do
44
+ true.blank?.must_equal false
45
45
  end
46
46
  end
47
47
 
48
48
  describe "FalseClass#blank?" do
49
- specify "it should always be true" do
50
- false.blank?.should == true
49
+ it "it should always be true" do
50
+ false.blank?.must_equal true
51
51
  end
52
52
  end
53
53
 
54
54
  describe "String#blank?" do
55
- specify "it should be true if the string is empty" do
56
- ''.blank?.should == true
55
+ it "it should be true if the string is empty" do
56
+ ''.blank?.must_equal true
57
57
  end
58
- specify "it should be true if the string is composed of just whitespace" do
59
- ' '.blank?.should == true
60
- "\r\n\t".blank?.should == true
61
- (' '*4000).blank?.should == true
62
- ("\r\n\t"*4000).blank?.should == true
58
+ it "it should be true if the string is composed of just whitespace" do
59
+ ' '.blank?.must_equal true
60
+ "\r\n\t".blank?.must_equal true
61
+ (' '*4000).blank?.must_equal true
62
+ ("\r\n\t"*4000).blank?.must_equal true
63
63
  end
64
- specify "it should be false if the string has any non whitespace characters" do
65
- '1'.blank?.should == false
66
- ("\r\n\t"*4000 + 'a').blank?.should == false
67
- ("\r\na\t"*4000).blank?.should == false
64
+ it "it should be false if the string has any non whitespace characters" do
65
+ '1'.blank?.must_equal false
66
+ ("\r\n\t"*4000 + 'a').blank?.must_equal false
67
+ ("\r\na\t"*4000).blank?.must_equal false
68
68
  end
69
69
  end