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
@@ -20,66 +20,66 @@ describe Sequel::Model, "tree plugin" do
20
20
  end
21
21
 
22
22
  it "should define the correct associations" do
23
- @c.associations.sort_by{|x| x.to_s}.should == [:children, :parent]
23
+ @c.associations.sort_by{|x| x.to_s}.must_equal [:children, :parent]
24
24
  end
25
25
 
26
26
  it "should define the correct reciprocals" do
27
- @c.associations.sort_by{|x| x.to_s}.map{|x| @c.association_reflection(x).reciprocal}.should == [:parent, :children]
27
+ @c.associations.sort_by{|x| x.to_s}.map{|x| @c.association_reflection(x).reciprocal}.must_equal [:parent, :children]
28
28
  end
29
29
 
30
30
  it "should define the correct associations when giving options" do
31
- klass(:children=>{:name=>:cs}, :parent=>{:name=>:p}).associations.sort_by{|x| x.to_s}.should == [:cs, :p]
31
+ klass(:children=>{:name=>:cs}, :parent=>{:name=>:p}).associations.sort_by{|x| x.to_s}.must_equal [:cs, :p]
32
32
  end
33
33
 
34
34
  it "should use the correct SQL for lazy associations" do
35
- @o.parent_dataset.sql.should == 'SELECT * FROM nodes WHERE (nodes.id = 1) LIMIT 1'
36
- @o.children_dataset.sql.should == 'SELECT * FROM nodes WHERE (nodes.parent_id = 2)'
35
+ @o.parent_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.id = 1) LIMIT 1'
36
+ @o.children_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.parent_id = 2)'
37
37
  end
38
38
 
39
39
  it "should use the correct SQL for lazy associations when giving options" do
40
40
  o = klass(:primary_key=>:i, :key=>:pi, :order=>:name, :children=>{:name=>:cs}, :parent=>{:name=>:p}).load(:id=>2, :parent_id=>1, :name=>'AA', :i=>3, :pi=>4)
41
- o.p_dataset.sql.should == 'SELECT * FROM nodes WHERE (nodes.i = 4) ORDER BY name LIMIT 1'
42
- o.cs_dataset.sql.should == 'SELECT * FROM nodes WHERE (nodes.pi = 3) ORDER BY name'
41
+ o.p_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.i = 4) ORDER BY name LIMIT 1'
42
+ o.cs_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.pi = 3) ORDER BY name'
43
43
  end
44
44
 
45
45
  it "should have parent_column give the symbol of the parent column" do
46
- @c.parent_column.should == :parent_id
47
- klass(:key=>:p_id).parent_column.should == :p_id
46
+ @c.parent_column.must_equal :parent_id
47
+ klass(:key=>:p_id).parent_column.must_equal :p_id
48
48
  end
49
49
 
50
50
  it "should have tree_order give the order of the association" do
51
- @c.tree_order.should == nil
52
- klass(:order=>:name).tree_order.should == :name
53
- klass(:order=>[:parent_id, :name]).tree_order.should == [:parent_id, :name]
51
+ @c.tree_order.must_equal nil
52
+ klass(:order=>:name).tree_order.must_equal :name
53
+ klass(:order=>[:parent_id, :name]).tree_order.must_equal [:parent_id, :name]
54
54
  end
55
55
 
56
56
  it "should work correctly in subclasses" do
57
57
  o = Class.new(klass(:primary_key=>:i, :key=>:pi, :order=>:name, :children=>{:name=>:cs}, :parent=>{:name=>:p})).load(:id=>2, :parent_id=>1, :name=>'AA', :i=>3, :pi=>4)
58
- o.p_dataset.sql.should == 'SELECT * FROM nodes WHERE (nodes.i = 4) ORDER BY name LIMIT 1'
59
- o.cs_dataset.sql.should == 'SELECT * FROM nodes WHERE (nodes.pi = 3) ORDER BY name'
58
+ o.p_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.i = 4) ORDER BY name LIMIT 1'
59
+ o.cs_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.pi = 3) ORDER BY name'
60
60
  end
61
61
 
62
62
  it "should have roots return an array of the tree's roots" do
63
63
  @ds._fetch = [{:id=>1, :parent_id=>nil, :name=>'r'}]
64
- @c.roots.should == [@c.load(:id=>1, :parent_id=>nil, :name=>'r')]
65
- @db.sqls.should == ["SELECT * FROM nodes WHERE (parent_id IS NULL)"]
64
+ @c.roots.must_equal [@c.load(:id=>1, :parent_id=>nil, :name=>'r')]
65
+ @db.sqls.must_equal ["SELECT * FROM nodes WHERE (parent_id IS NULL)"]
66
66
  end
67
67
 
68
68
  it "should have roots_dataset be a dataset representing the tree's roots" do
69
- @c.roots_dataset.sql.should == "SELECT * FROM nodes WHERE (parent_id IS NULL)"
69
+ @c.roots_dataset.sql.must_equal "SELECT * FROM nodes WHERE (parent_id IS NULL)"
70
70
  end
71
71
 
72
72
  it "should have ancestors return the ancestors of the current node" do
73
73
  @ds._fetch = [[{:id=>1, :parent_id=>5, :name=>'r'}], [{:id=>5, :parent_id=>nil, :name=>'r2'}]]
74
- @o.ancestors.should == [@c.load(:id=>1, :parent_id=>5, :name=>'r'), @c.load(:id=>5, :parent_id=>nil, :name=>'r2')]
75
- @db.sqls.should == ["SELECT * FROM nodes WHERE id = 1",
74
+ @o.ancestors.must_equal [@c.load(:id=>1, :parent_id=>5, :name=>'r'), @c.load(:id=>5, :parent_id=>nil, :name=>'r2')]
75
+ @db.sqls.must_equal ["SELECT * FROM nodes WHERE id = 1",
76
76
  "SELECT * FROM nodes WHERE id = 5"]
77
77
  end
78
78
 
79
79
  it "should have descendants return the descendants of the current node" do
80
80
  @ds._fetch = [[{:id=>3, :parent_id=>2, :name=>'r'}, {:id=>4, :parent_id=>2, :name=>'r2'}], [{:id=>5, :parent_id=>4, :name=>'r3'}], []]
81
- @o.descendants.should == [@c.load(:id=>3, :parent_id=>2, :name=>'r'), @c.load(:id=>4, :parent_id=>2, :name=>'r2'), @c.load(:id=>5, :parent_id=>4, :name=>'r3')]
82
- @db.sqls.should == ["SELECT * FROM nodes WHERE (nodes.parent_id = 2)",
81
+ @o.descendants.must_equal [@c.load(:id=>3, :parent_id=>2, :name=>'r'), @c.load(:id=>4, :parent_id=>2, :name=>'r2'), @c.load(:id=>5, :parent_id=>4, :name=>'r3')]
82
+ @db.sqls.must_equal ["SELECT * FROM nodes WHERE (nodes.parent_id = 2)",
83
83
  "SELECT * FROM nodes WHERE (nodes.parent_id = 3)",
84
84
  "SELECT * FROM nodes WHERE (nodes.parent_id = 5)",
85
85
  "SELECT * FROM nodes WHERE (nodes.parent_id = 4)"]
@@ -87,31 +87,31 @@ describe Sequel::Model, "tree plugin" do
87
87
 
88
88
  it "should have root return the root of the current node" do
89
89
  @ds._fetch = [[{:id=>1, :parent_id=>5, :name=>'r'}], [{:id=>5, :parent_id=>nil, :name=>'r2'}]]
90
- @o.root.should == @c.load(:id=>5, :parent_id=>nil, :name=>'r2')
91
- @db.sqls.should == ["SELECT * FROM nodes WHERE id = 1",
90
+ @o.root.must_equal @c.load(:id=>5, :parent_id=>nil, :name=>'r2')
91
+ @db.sqls.must_equal ["SELECT * FROM nodes WHERE id = 1",
92
92
  "SELECT * FROM nodes WHERE id = 5"]
93
93
  end
94
94
 
95
95
  it "should have root? return true for a root node and false for a child node" do
96
- @c.load(:parent_id => nil).root?.should == true
97
- @c.load(:parent_id => 1).root?.should == false
96
+ @c.load(:parent_id => nil).root?.must_equal true
97
+ @c.load(:parent_id => 1).root?.must_equal false
98
98
  end
99
99
 
100
100
  it "should have root? return false for an new node" do
101
- @c.new.root?.should == false
101
+ @c.new.root?.must_equal false
102
102
  end
103
103
 
104
104
  it "should have self_and_siblings return the children of the current node's parent" do
105
105
  @ds._fetch = [[{:id=>1, :parent_id=>3, :name=>'r'}], [{:id=>7, :parent_id=>1, :name=>'r2'}, @o.values.dup]]
106
- @o.self_and_siblings.should == [@c.load(:id=>7, :parent_id=>1, :name=>'r2'), @o]
107
- @db.sqls.should == ["SELECT * FROM nodes WHERE id = 1",
106
+ @o.self_and_siblings.must_equal [@c.load(:id=>7, :parent_id=>1, :name=>'r2'), @o]
107
+ @db.sqls.must_equal ["SELECT * FROM nodes WHERE id = 1",
108
108
  "SELECT * FROM nodes WHERE (nodes.parent_id = 1)"]
109
109
  end
110
110
 
111
111
  it "should have siblings return the children of the current node's parent, except for the current node" do
112
112
  @ds._fetch = [[{:id=>1, :parent_id=>3, :name=>'r'}], [{:id=>7, :parent_id=>1, :name=>'r2'}, @o.values.dup]]
113
- @o.siblings.should == [@c.load(:id=>7, :parent_id=>1, :name=>'r2')]
114
- @db.sqls.should == ["SELECT * FROM nodes WHERE id = 1",
113
+ @o.siblings.must_equal [@c.load(:id=>7, :parent_id=>1, :name=>'r2')]
114
+ @db.sqls.must_equal ["SELECT * FROM nodes WHERE id = 1",
115
115
  "SELECT * FROM nodes WHERE (nodes.parent_id = 1)"]
116
116
  end
117
117
 
@@ -122,23 +122,23 @@ describe Sequel::Model, "tree plugin" do
122
122
 
123
123
  it "should have root class method return the root" do
124
124
  @c.dataset._fetch = [{:id=>1, :parent_id=>nil, :name=>'r'}]
125
- @c.root.should == @c.load(:id=>1, :parent_id=>nil, :name=>'r')
125
+ @c.root.must_equal @c.load(:id=>1, :parent_id=>nil, :name=>'r')
126
126
  end
127
127
 
128
128
  it "prevents creating a second root" do
129
129
  @c.dataset._fetch = [{:id=>1, :parent_id=>nil, :name=>'r'}]
130
- lambda { @c.create }.should raise_error(Sequel::Plugins::Tree::TreeMultipleRootError)
130
+ lambda { @c.create }.must_raise(Sequel::Plugins::Tree::TreeMultipleRootError)
131
131
  end
132
132
 
133
133
  it "errors when promoting an existing record to a second root" do
134
134
  @c.dataset._fetch = [{:id=>1, :parent_id=>nil, :name=>'r'}]
135
135
  n = @c.load(:id => 2, :parent_id => 1)
136
- lambda { n.update(:parent_id => nil) }.should raise_error(Sequel::Plugins::Tree::TreeMultipleRootError)
136
+ lambda { n.update(:parent_id => nil) }.must_raise(Sequel::Plugins::Tree::TreeMultipleRootError)
137
137
  end
138
138
 
139
139
  it "allows updating existing root" do
140
140
  @c.dataset._fetch = [{:id=>1, :parent_id=>nil, :name=>'r'}]
141
- lambda { @c.root.update(:name => 'fdsa') }.should_not raise_error
141
+ @c.root.update(:name => 'fdsa')
142
142
  end
143
143
  end
144
144
  end
@@ -165,37 +165,37 @@ describe Sequel::Model, "tree plugin with composite keys" do
165
165
 
166
166
 
167
167
  it "should use the correct SQL for lazy associations" do
168
- @o.parent_dataset.sql.should == 'SELECT * FROM nodes WHERE ((nodes.id = 1) AND (nodes.id2 = 6)) LIMIT 1'
169
- @o.children_dataset.sql.should == 'SELECT * FROM nodes WHERE ((nodes.parent_id = 2) AND (nodes.parent_id2 = 5))'
168
+ @o.parent_dataset.sql.must_equal 'SELECT * FROM nodes WHERE ((nodes.id = 1) AND (nodes.id2 = 6)) LIMIT 1'
169
+ @o.children_dataset.sql.must_equal 'SELECT * FROM nodes WHERE ((nodes.parent_id = 2) AND (nodes.parent_id2 = 5))'
170
170
  end
171
171
 
172
172
  it "should have parent_column give an array of symbols of the parent column" do
173
- @c.parent_column.should == [:parent_id, :parent_id2]
173
+ @c.parent_column.must_equal [:parent_id, :parent_id2]
174
174
  end
175
175
 
176
176
  it "should have roots return an array of the tree's roots" do
177
177
  @ds._fetch = [{:id=>1, :parent_id=>nil, :parent_id2=>nil, :name=>'r'}]
178
- @c.roots.should == [@c.load(:id=>1, :parent_id=>nil, :parent_id2=>nil, :name=>'r')]
179
- @db.sqls.should == ["SELECT * FROM nodes WHERE ((parent_id IS NULL) OR (parent_id2 IS NULL))"]
178
+ @c.roots.must_equal [@c.load(:id=>1, :parent_id=>nil, :parent_id2=>nil, :name=>'r')]
179
+ @db.sqls.must_equal ["SELECT * FROM nodes WHERE ((parent_id IS NULL) OR (parent_id2 IS NULL))"]
180
180
  end
181
181
 
182
182
  it "should have roots_dataset be a dataset representing the tree's roots" do
183
- @c.roots_dataset.sql.should == "SELECT * FROM nodes WHERE ((parent_id IS NULL) OR (parent_id2 IS NULL))"
183
+ @c.roots_dataset.sql.must_equal "SELECT * FROM nodes WHERE ((parent_id IS NULL) OR (parent_id2 IS NULL))"
184
184
  end
185
185
 
186
186
  it "should have ancestors return the ancestors of the current node" do
187
187
  @ds._fetch = [[{:id=>1, :id2=>6, :parent_id=>5, :parent_id2=>7, :name=>'r'}], [{:id=>5, :id2=>7, :parent_id=>nil, :parent_id2=>nil, :name=>'r2'}]]
188
- @o.ancestors.should == [@c.load(:id=>1, :id2=>6, :parent_id=>5, :parent_id2=>7, :name=>'r'), @c.load(:id=>5, :id2=>7, :parent_id=>nil, :parent_id2=>nil, :name=>'r2')]
188
+ @o.ancestors.must_equal [@c.load(:id=>1, :id2=>6, :parent_id=>5, :parent_id2=>7, :name=>'r'), @c.load(:id=>5, :id2=>7, :parent_id=>nil, :parent_id2=>nil, :name=>'r2')]
189
189
  sqls = @db.sqls
190
- sqls.length.should == 2
191
- ["SELECT * FROM nodes WHERE ((id = 1) AND (id2 = 6)) LIMIT 1", "SELECT * FROM nodes WHERE ((id2 = 6) AND (id = 1)) LIMIT 1"].should include(sqls[0])
192
- ["SELECT * FROM nodes WHERE ((id = 5) AND (id2 = 7)) LIMIT 1", "SELECT * FROM nodes WHERE ((id2 = 7) AND (id = 5)) LIMIT 1"].should include(sqls[1])
190
+ sqls.length.must_equal 2
191
+ ["SELECT * FROM nodes WHERE ((id = 1) AND (id2 = 6)) LIMIT 1", "SELECT * FROM nodes WHERE ((id2 = 6) AND (id = 1)) LIMIT 1"].must_include(sqls[0])
192
+ ["SELECT * FROM nodes WHERE ((id = 5) AND (id2 = 7)) LIMIT 1", "SELECT * FROM nodes WHERE ((id2 = 7) AND (id = 5)) LIMIT 1"].must_include(sqls[1])
193
193
  end
194
194
 
195
195
  it "should have descendants return the descendants of the current node" do
196
196
  @ds._fetch = [[{:id=>3, :id2=>7, :parent_id=>2, :parent_id2=>5, :name=>'r'}, {:id=>4, :id2=>8, :parent_id=>2, :parent_id2=>5, :name=>'r2'}], [{:id=>5, :id2=>9, :parent_id=>4, :parent_id2=>8, :name=>'r3'}], []]
197
- @o.descendants.should == [@c.load(:id=>3, :id2=>7, :parent_id=>2, :parent_id2=>5, :name=>'r'), @c.load(:id=>4, :id2=>8, :parent_id=>2, :parent_id2=>5, :name=>'r2'), @c.load(:id=>5, :id2=>9, :parent_id=>4, :parent_id2=>8, :name=>'r3')]
198
- @db.sqls.should == ["SELECT * FROM nodes WHERE ((nodes.parent_id = 2) AND (nodes.parent_id2 = 5))",
197
+ @o.descendants.must_equal [@c.load(:id=>3, :id2=>7, :parent_id=>2, :parent_id2=>5, :name=>'r'), @c.load(:id=>4, :id2=>8, :parent_id=>2, :parent_id2=>5, :name=>'r2'), @c.load(:id=>5, :id2=>9, :parent_id=>4, :parent_id2=>8, :name=>'r3')]
198
+ @db.sqls.must_equal ["SELECT * FROM nodes WHERE ((nodes.parent_id = 2) AND (nodes.parent_id2 = 5))",
199
199
  "SELECT * FROM nodes WHERE ((nodes.parent_id = 3) AND (nodes.parent_id2 = 7))",
200
200
  "SELECT * FROM nodes WHERE ((nodes.parent_id = 5) AND (nodes.parent_id2 = 9))",
201
201
  "SELECT * FROM nodes WHERE ((nodes.parent_id = 4) AND (nodes.parent_id2 = 8))"]
@@ -203,40 +203,40 @@ describe Sequel::Model, "tree plugin with composite keys" do
203
203
 
204
204
  it "should have root return the root of the current node" do
205
205
  @ds._fetch = [[{:id=>1, :id2=>6, :parent_id=>5, :parent_id2=>7, :name=>'r'}], [{:id=>5, :id2=>7, :parent_id=>nil, :parent_id2=>nil, :name=>'r2'}]]
206
- @o.root.should == @c.load(:id=>5, :id2=>7, :parent_id=>nil, :parent_id2=>nil, :name=>'r2')
206
+ @o.root.must_equal @c.load(:id=>5, :id2=>7, :parent_id=>nil, :parent_id2=>nil, :name=>'r2')
207
207
  sqls = @db.sqls
208
- sqls.length.should == 2
209
- ["SELECT * FROM nodes WHERE ((id = 1) AND (id2 = 6)) LIMIT 1", "SELECT * FROM nodes WHERE ((id2 = 6) AND (id = 1)) LIMIT 1"].should include(sqls[0])
210
- ["SELECT * FROM nodes WHERE ((id = 5) AND (id2 = 7)) LIMIT 1", "SELECT * FROM nodes WHERE ((id2 = 7) AND (id = 5)) LIMIT 1"].should include(sqls[1])
208
+ sqls.length.must_equal 2
209
+ ["SELECT * FROM nodes WHERE ((id = 1) AND (id2 = 6)) LIMIT 1", "SELECT * FROM nodes WHERE ((id2 = 6) AND (id = 1)) LIMIT 1"].must_include(sqls[0])
210
+ ["SELECT * FROM nodes WHERE ((id = 5) AND (id2 = 7)) LIMIT 1", "SELECT * FROM nodes WHERE ((id2 = 7) AND (id = 5)) LIMIT 1"].must_include(sqls[1])
211
211
  end
212
212
 
213
213
  it "should have root? return true for a root node and false for a child node" do
214
- @c.load(:parent_id => nil, :parent_id2=>nil).root?.should == true
215
- @c.load(:parent_id => 1, :parent_id2=>nil).root?.should == true
216
- @c.load(:parent_id => nil, :parent_id2=>2).root?.should == true
217
- @c.load(:parent_id => 1, :parent_id2=>2).root?.should == false
214
+ @c.load(:parent_id => nil, :parent_id2=>nil).root?.must_equal true
215
+ @c.load(:parent_id => 1, :parent_id2=>nil).root?.must_equal true
216
+ @c.load(:parent_id => nil, :parent_id2=>2).root?.must_equal true
217
+ @c.load(:parent_id => 1, :parent_id2=>2).root?.must_equal false
218
218
  end
219
219
 
220
220
  it "should have root? return false for an new node" do
221
- @c.new.root?.should == false
221
+ @c.new.root?.must_equal false
222
222
  end
223
223
 
224
224
  it "should have self_and_siblings return the children of the current node's parent" do
225
225
  @ds._fetch = [[{:id=>1, :id2=>6, :parent_id=>3, :parent_id2=>7, :name=>'r'}], [{:id=>7, :id2=>9, :parent_id=>1, :parent_id2=>6, :name=>'r2'}, @o.values.dup]]
226
- @o.self_and_siblings.should == [@c.load(:id=>7, :id2=>9, :parent_id=>1, :parent_id2=>6, :name=>'r2'), @o]
226
+ @o.self_and_siblings.must_equal [@c.load(:id=>7, :id2=>9, :parent_id=>1, :parent_id2=>6, :name=>'r2'), @o]
227
227
  sqls = @db.sqls
228
- sqls.length.should == 2
229
- ["SELECT * FROM nodes WHERE ((id = 1) AND (id2 = 6)) LIMIT 1", "SELECT * FROM nodes WHERE ((id2 = 6) AND (id = 1)) LIMIT 1"].should include(sqls[0])
230
- sqls[1].should == "SELECT * FROM nodes WHERE ((nodes.parent_id = 1) AND (nodes.parent_id2 = 6))"
228
+ sqls.length.must_equal 2
229
+ ["SELECT * FROM nodes WHERE ((id = 1) AND (id2 = 6)) LIMIT 1", "SELECT * FROM nodes WHERE ((id2 = 6) AND (id = 1)) LIMIT 1"].must_include(sqls[0])
230
+ sqls[1].must_equal "SELECT * FROM nodes WHERE ((nodes.parent_id = 1) AND (nodes.parent_id2 = 6))"
231
231
  end
232
232
 
233
233
  it "should have siblings return the children of the current node's parent, except for the current node" do
234
234
  @ds._fetch = [[{:id=>1, :id2=>6, :parent_id=>3, :parent_id2=>7, :name=>'r'}], [{:id=>7, :id2=>9, :parent_id=>1, :parent_id2=>6, :name=>'r2'}, @o.values.dup]]
235
- @o.siblings.should == [@c.load(:id=>7, :id2=>9, :parent_id=>1, :parent_id2=>6, :name=>'r2')]
235
+ @o.siblings.must_equal [@c.load(:id=>7, :id2=>9, :parent_id=>1, :parent_id2=>6, :name=>'r2')]
236
236
  sqls = @db.sqls
237
- sqls.length.should == 2
238
- ["SELECT * FROM nodes WHERE ((id = 1) AND (id2 = 6)) LIMIT 1", "SELECT * FROM nodes WHERE ((id2 = 6) AND (id = 1)) LIMIT 1"].should include(sqls[0])
239
- sqls[1].should == "SELECT * FROM nodes WHERE ((nodes.parent_id = 1) AND (nodes.parent_id2 = 6))"
237
+ sqls.length.must_equal 2
238
+ ["SELECT * FROM nodes WHERE ((id = 1) AND (id2 = 6)) LIMIT 1", "SELECT * FROM nodes WHERE ((id2 = 6) AND (id = 1)) LIMIT 1"].must_include(sqls[0])
239
+ sqls[1].must_equal "SELECT * FROM nodes WHERE ((nodes.parent_id = 1) AND (nodes.parent_id2 = 6))"
240
240
  end
241
241
 
242
242
  describe ":single_root option" do
@@ -246,29 +246,29 @@ describe Sequel::Model, "tree plugin with composite keys" do
246
246
 
247
247
  it "prevents creating a second root" do
248
248
  @c.dataset._fetch = [{:id=>1, :id2=>6, :parent_id=>nil, :parent_id2=>nil, :name=>'r'}]
249
- lambda { @c.create }.should raise_error(Sequel::Plugins::Tree::TreeMultipleRootError)
249
+ lambda { @c.create }.must_raise(Sequel::Plugins::Tree::TreeMultipleRootError)
250
250
  @c.dataset._fetch = [{:id=>1, :id2=>6, :parent_id=>1, :parent_id2=>nil, :name=>'r'}]
251
- lambda { @c.create(:parent_id2=>1) }.should raise_error(Sequel::Plugins::Tree::TreeMultipleRootError)
251
+ lambda { @c.create(:parent_id2=>1) }.must_raise(Sequel::Plugins::Tree::TreeMultipleRootError)
252
252
  @c.dataset._fetch = [{:id=>1, :id2=>6, :parent_id=>nil, :parent_id2=>2, :name=>'r'}]
253
- lambda { @c.create(:parent_id=>2) }.should raise_error(Sequel::Plugins::Tree::TreeMultipleRootError)
253
+ lambda { @c.create(:parent_id=>2) }.must_raise(Sequel::Plugins::Tree::TreeMultipleRootError)
254
254
  end
255
255
 
256
256
  it "errors when promoting an existing record to a second root" do
257
257
  @c.dataset._fetch = [{:id=>1, :id2=>6, :parent_id=>nil, :parent_id2=>nil, :name=>'r'}]
258
- lambda { @c.load(:id => 2, :id2=>7, :parent_id => 1, :parent_id2=>2).update(:parent_id => nil, :parent_id2=>nil) }.should raise_error(Sequel::Plugins::Tree::TreeMultipleRootError)
258
+ lambda { @c.load(:id => 2, :id2=>7, :parent_id => 1, :parent_id2=>2).update(:parent_id => nil, :parent_id2=>nil) }.must_raise(Sequel::Plugins::Tree::TreeMultipleRootError)
259
259
  @c.dataset._fetch = [{:id=>1, :id2=>6, :parent_id=>1, :parent_id2=>nil, :name=>'r'}]
260
- lambda { @c.load(:id => 2, :id2=>7, :parent_id => 1, :parent_id2=>2).update(:parent_id => nil) }.should raise_error(Sequel::Plugins::Tree::TreeMultipleRootError)
260
+ lambda { @c.load(:id => 2, :id2=>7, :parent_id => 1, :parent_id2=>2).update(:parent_id => nil) }.must_raise(Sequel::Plugins::Tree::TreeMultipleRootError)
261
261
  @c.dataset._fetch = [{:id=>1, :id2=>6, :parent_id=>nil, :parent_id2=>2, :name=>'r'}]
262
- lambda { @c.load(:id => 2, :id2=>7, :parent_id => 1, :parent_id2=>2).update(:parent_id2 => nil) }.should raise_error(Sequel::Plugins::Tree::TreeMultipleRootError)
262
+ lambda { @c.load(:id => 2, :id2=>7, :parent_id => 1, :parent_id2=>2).update(:parent_id2 => nil) }.must_raise(Sequel::Plugins::Tree::TreeMultipleRootError)
263
263
  end
264
264
 
265
265
  it "allows updating existing root" do
266
266
  @c.dataset._fetch = {:id=>1, :id2=>6, :parent_id=>nil, :parent_id2=>nil, :name=>'r'}
267
- lambda { @c.root.update(:name => 'fdsa') }.should_not raise_error
267
+ @c.root.update(:name => 'fdsa')
268
268
  @c.dataset._fetch = {:id=>1, :id2=>6, :parent_id=>1, :parent_id2=>nil, :name=>'r'}
269
- lambda { @c.root.update(:name => 'fdsa') }.should_not raise_error
269
+ @c.root.update(:name => 'fdsa')
270
270
  @c.dataset._fetch = {:id=>1, :id2=>6, :parent_id=>nil, :parent_id2=>2, :name=>'r'}
271
- lambda { @c.root.update(:name => 'fdsa') }.should_not raise_error
271
+ @c.root.update(:name => 'fdsa')
272
272
  end
273
273
  end
274
274
  end
@@ -16,65 +16,65 @@ describe Sequel::Model, "TypecastOnLoad plugin" do
16
16
  end
17
17
  end
18
18
 
19
- specify "should call setter method with value when loading the object, for all given columns" do
19
+ it "should call setter method with value when loading the object, for all given columns" do
20
20
  @c.plugin :typecast_on_load, :b
21
21
  o = @c.load(:id=>1, :b=>"1", :y=>"0")
22
- o.values.should == {:id=>1, :b=>1, :y=>"0"}
23
- o.bset.should == true
22
+ o.values.must_equal(:id=>1, :b=>1, :y=>"0")
23
+ o.bset.must_equal true
24
24
  end
25
25
 
26
- specify "should call setter method with value when reloading the object, for all given columns" do
26
+ it "should call setter method with value when reloading the object, for all given columns" do
27
27
  @c.plugin :typecast_on_load, :b
28
28
  o = @c.load(:id=>1, :b=>"1", :y=>"0")
29
29
  o.refresh
30
- o.values.should == {:id=>1, :b=>1, :y=>"0"}
31
- o.bset.should == true
30
+ o.values.must_equal(:id=>1, :b=>1, :y=>"0")
31
+ o.bset.must_equal true
32
32
  end
33
33
 
34
- specify "should call setter method with value when automatically reloading the object on creation" do
34
+ it "should call setter method with value when automatically reloading the object on creation" do
35
35
  @c.plugin :typecast_on_load, :b
36
36
  o = @c.new(:b=>"1", :y=>"0")
37
- o.save.values.should == {:id=>1, :b=>1, :y=>"0"}
38
- o.bset.should == true
37
+ o.save.values.must_equal(:id=>1, :b=>1, :y=>"0")
38
+ o.bset.must_equal true
39
39
  end
40
40
 
41
- specify "should call setter method with value when automatically reloading the object on creation via insert_select" do
41
+ it "should call setter method with value when automatically reloading the object on creation via insert_select" do
42
42
  @c.plugin :typecast_on_load, :b
43
43
  @c.dataset.meta_def(:insert_select){|h| insert(h); first}
44
44
  o = @c.new(:b=>"1", :y=>"0")
45
- o.save.values.should == {:id=>1, :b=>1, :y=>"0"}
46
- o.bset.should == true
45
+ o.save.values.must_equal(:id=>1, :b=>1, :y=>"0")
46
+ o.bset.must_equal true
47
47
  end
48
48
 
49
- specify "should allowing setting columns separately via add_typecast_on_load_columns" do
49
+ it "should allowing setting columns separately via add_typecast_on_load_columns" do
50
50
  @c.plugin :typecast_on_load
51
- @c.load(:id=>1, :b=>"1", :y=>"0").values.should == {:id=>1, :b=>"1", :y=>"0"}
51
+ @c.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>"1", :y=>"0")
52
52
  @c.add_typecast_on_load_columns :b
53
- @c.load(:id=>1, :b=>"1", :y=>"0").values.should == {:id=>1, :b=>1, :y=>"0"}
53
+ @c.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>1, :y=>"0")
54
54
  @c.add_typecast_on_load_columns :y
55
- @c.load(:id=>1, :b=>"1", :y=>"0").values.should == {:id=>1, :b=>1, :y=>false}
55
+ @c.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>1, :y=>false)
56
56
  end
57
57
 
58
- specify "should work with subclasses" do
58
+ it "should work with subclasses" do
59
59
  @c.plugin :typecast_on_load
60
- @c.load(:id=>1, :b=>"1", :y=>"0").values.should == {:id=>1, :b=>"1", :y=>"0"}
60
+ @c.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>"1", :y=>"0")
61
61
 
62
62
  c1 = Class.new(@c)
63
63
  @c.add_typecast_on_load_columns :b
64
- @c.load(:id=>1, :b=>"1", :y=>"0").values.should == {:id=>1, :b=>1, :y=>"0"}
65
- c1.load(:id=>1, :b=>"1", :y=>"0").values.should == {:id=>1, :b=>"1", :y=>"0"}
64
+ @c.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>1, :y=>"0")
65
+ c1.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>"1", :y=>"0")
66
66
 
67
67
  c2 = Class.new(@c)
68
68
  @c.add_typecast_on_load_columns :y
69
- @c.load(:id=>1, :b=>"1", :y=>"0").values.should == {:id=>1, :b=>1, :y=>false}
70
- c2.load(:id=>1, :b=>"1", :y=>"0").values.should == {:id=>1, :b=>1, :y=>"0"}
69
+ @c.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>1, :y=>false)
70
+ c2.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>1, :y=>"0")
71
71
 
72
72
  c1.add_typecast_on_load_columns :y
73
- c1.load(:id=>1, :b=>"1", :y=>"0").values.should == {:id=>1, :b=>"1", :y=>false}
73
+ c1.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>"1", :y=>false)
74
74
  end
75
75
 
76
- specify "should not mark the object as modified" do
76
+ it "should not mark the object as modified" do
77
77
  @c.plugin :typecast_on_load, :b
78
- @c.load(:id=>1, :b=>"1", :y=>"0").modified?.should == false
78
+ @c.load(:id=>1, :b=>"1", :y=>"0").modified?.must_equal false
79
79
  end
80
80
  end
@@ -11,10 +11,10 @@ describe "Sequel::Plugins::UnlimitedUpdate" do
11
11
 
12
12
  it "should remove limit from update dataset" do
13
13
  @o.save
14
- @db.sqls.should == ["UPDATE test SET name = 'a' WHERE (id = 1) LIMIT 1"]
14
+ @db.sqls.must_equal ["UPDATE test SET name = 'a' WHERE (id = 1) LIMIT 1"]
15
15
 
16
16
  @c.plugin :unlimited_update
17
17
  @o.save
18
- @db.sqls.should == ["UPDATE test SET name = 'a' WHERE (id = 1)"]
18
+ @db.sqls.must_equal ["UPDATE test SET name = 'a' WHERE (id = 1)"]
19
19
  end
20
20
  end
@@ -11,77 +11,77 @@ describe "Sequel::Plugins::UpdateOrCreate" do
11
11
 
12
12
  it ".update_or_create should update an existing record if one exists" do
13
13
  @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
14
- @c.update_or_create(:a=>2){|t| t.b = 4}.should == @c.load(:id=>1, :a=>2, :b=>4)
15
- @db.sqls.should == ["SELECT * FROM test WHERE (a = 2) LIMIT 1", "UPDATE test SET b = 4 WHERE (id = 1)"]
14
+ @c.update_or_create(:a=>2){|t| t.b = 4}.must_equal @c.load(:id=>1, :a=>2, :b=>4)
15
+ @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1", "UPDATE test SET b = 4 WHERE (id = 1)"]
16
16
 
17
17
  @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
18
- @c.update_or_create({:a=>2}, :b=>4).should == @c.load(:id=>1, :a=>2, :b=>4)
19
- @db.sqls.should == ["SELECT * FROM test WHERE (a = 2) LIMIT 1", "UPDATE test SET b = 4 WHERE (id = 1)"]
18
+ @c.update_or_create({:a=>2}, :b=>4).must_equal @c.load(:id=>1, :a=>2, :b=>4)
19
+ @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1", "UPDATE test SET b = 4 WHERE (id = 1)"]
20
20
 
21
21
  @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
22
- @c.update_or_create({:a=>2}, :a=>3){|t| t.b = 4}.should == @c.load(:id=>1, :a=>3, :b=>4)
22
+ @c.update_or_create({:a=>2}, :a=>3){|t| t.b = 4}.must_equal @c.load(:id=>1, :a=>3, :b=>4)
23
23
  sqls = @db.sqls
24
- sqls.shift.should == "SELECT * FROM test WHERE (a = 2) LIMIT 1"
25
- sqls.shift.should =~ /UPDATE test SET [ab] = [34], [ab] = [34] WHERE \(id = 1\)/
24
+ sqls.shift.must_equal "SELECT * FROM test WHERE (a = 2) LIMIT 1"
25
+ sqls.shift.must_match(/UPDATE test SET [ab] = [34], [ab] = [34] WHERE \(id = 1\)/)
26
26
  end
27
27
 
28
28
  it ".update_or_create should create a record if an existing record does not exist" do
29
29
  @db.fetch = [[], [{:id=>1, :a=>1, :b=>4}]]
30
- @c.update_or_create(:a=>1){|t| t.b = 4}.should == @c.load(:id=>1, :a=>1, :b=>4)
30
+ @c.update_or_create(:a=>1){|t| t.b = 4}.must_equal @c.load(:id=>1, :a=>1, :b=>4)
31
31
  sqls = @db.sqls
32
- sqls.shift.should == "SELECT * FROM test WHERE (a = 1) LIMIT 1"
33
- sqls.shift.should =~ /INSERT INTO test \([ab], [ab]\) VALUES \([14], [14]\)/
34
- sqls.shift.should == "SELECT * FROM test WHERE (id = 1) LIMIT 1"
32
+ sqls.shift.must_equal "SELECT * FROM test WHERE (a = 1) LIMIT 1"
33
+ sqls.shift.must_match(/INSERT INTO test \([ab], [ab]\) VALUES \([14], [14]\)/)
34
+ sqls.shift.must_equal "SELECT * FROM test WHERE (id = 1) LIMIT 1"
35
35
 
36
36
  @db.fetch = [[], [{:id=>1, :a=>1, :b=>4}]]
37
- @c.update_or_create({:a=>1}, :b=>4).should == @c.load(:id=>1, :a=>1, :b=>4)
37
+ @c.update_or_create({:a=>1}, :b=>4).must_equal @c.load(:id=>1, :a=>1, :b=>4)
38
38
  sqls = @db.sqls
39
- sqls.shift.should == "SELECT * FROM test WHERE (a = 1) LIMIT 1"
40
- sqls.shift.should =~ /INSERT INTO test \([ab], [ab]\) VALUES \([14], [14]\)/
41
- sqls.shift.should == "SELECT * FROM test WHERE (id = 1) LIMIT 1"
39
+ sqls.shift.must_equal "SELECT * FROM test WHERE (a = 1) LIMIT 1"
40
+ sqls.shift.must_match(/INSERT INTO test \([ab], [ab]\) VALUES \([14], [14]\)/)
41
+ sqls.shift.must_equal "SELECT * FROM test WHERE (id = 1) LIMIT 1"
42
42
 
43
43
  @db.fetch = [[], [{:id=>1, :a=>3, :b=>4}]]
44
- @c.update_or_create({:a=>1}, :a=>3){|t| t.b = 4}.should == @c.load(:id=>1, :a=>3, :b=>4)
44
+ @c.update_or_create({:a=>1}, :a=>3){|t| t.b = 4}.must_equal @c.load(:id=>1, :a=>3, :b=>4)
45
45
  sqls = @db.sqls
46
- sqls.shift.should == "SELECT * FROM test WHERE (a = 1) LIMIT 1"
47
- sqls.shift.should =~ /INSERT INTO test \([ab], [ab]\) VALUES \([34], [34]\)/
48
- sqls.shift.should == "SELECT * FROM test WHERE (id = 1) LIMIT 1"
46
+ sqls.shift.must_equal "SELECT * FROM test WHERE (a = 1) LIMIT 1"
47
+ sqls.shift.must_match(/INSERT INTO test \([ab], [ab]\) VALUES \([34], [34]\)/)
48
+ sqls.shift.must_equal "SELECT * FROM test WHERE (id = 1) LIMIT 1"
49
49
  end
50
50
 
51
51
  it ".update_or_create should return an existing record even if no changes necessary" do
52
52
  @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
53
- @c.update_or_create(:a=>2){|t| t.b = 3}.should == @c.load(:id=>1, :a=>2, :b=>3)
54
- @db.sqls.should == ["SELECT * FROM test WHERE (a = 2) LIMIT 1"]
53
+ @c.update_or_create(:a=>2){|t| t.b = 3}.must_equal @c.load(:id=>1, :a=>2, :b=>3)
54
+ @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1"]
55
55
  end
56
56
 
57
57
  it ".find_or_new should return an existing record" do
58
58
  @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
59
- @c.find_or_new(:a=>2){|t| t.b = 4}.should == @c.load(:id=>1, :a=>2, :b=>4)
60
- @db.sqls.should == ["SELECT * FROM test WHERE (a = 2) LIMIT 1"]
59
+ @c.find_or_new(:a=>2){|t| t.b = 4}.must_equal @c.load(:id=>1, :a=>2, :b=>4)
60
+ @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1"]
61
61
 
62
62
  @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
63
- @c.find_or_new({:a=>2}, :b=>4).should == @c.load(:id=>1, :a=>2, :b=>4)
64
- @db.sqls.should == ["SELECT * FROM test WHERE (a = 2) LIMIT 1"]
63
+ @c.find_or_new({:a=>2}, :b=>4).must_equal @c.load(:id=>1, :a=>2, :b=>4)
64
+ @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1"]
65
65
 
66
66
  @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
67
- @c.find_or_new({:a=>2}, :a=>3){|t| t.b = 4}.should == @c.load(:id=>1, :a=>3, :b=>4)
68
- @db.sqls.should == ["SELECT * FROM test WHERE (a = 2) LIMIT 1"]
67
+ @c.find_or_new({:a=>2}, :a=>3){|t| t.b = 4}.must_equal @c.load(:id=>1, :a=>3, :b=>4)
68
+ @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1"]
69
69
  end
70
70
 
71
71
  it ".find_or_new should return a new record if no record exists" do
72
72
  o = @c.find_or_new(:a=>1){|t| t.b = 4}
73
- o.should == @c.load(:a=>1, :b=>4)
74
- o.new?.should == true
75
- @db.sqls.should == ["SELECT * FROM test WHERE (a = 1) LIMIT 1"]
73
+ o.must_equal @c.load(:a=>1, :b=>4)
74
+ o.new?.must_equal true
75
+ @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 1) LIMIT 1"]
76
76
 
77
77
  o = @c.find_or_new({:a=>1}, :b=>4)
78
- o.should == @c.load(:a=>1, :b=>4)
79
- o.new?.should == true
80
- @db.sqls.should == ["SELECT * FROM test WHERE (a = 1) LIMIT 1"]
78
+ o.must_equal @c.load(:a=>1, :b=>4)
79
+ o.new?.must_equal true
80
+ @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 1) LIMIT 1"]
81
81
 
82
82
  o = @c.find_or_new({:a=>1}, :a=>3){|t| t.b = 4}
83
- o.should == @c.load(:a=>3, :b=>4)
84
- o.new?.should == true
85
- @db.sqls.should == ["SELECT * FROM test WHERE (a = 1) LIMIT 1"]
83
+ o.must_equal @c.load(:a=>3, :b=>4)
84
+ o.new?.must_equal true
85
+ @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 1) LIMIT 1"]
86
86
  end
87
87
  end