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
@@ -10,42 +10,42 @@ describe "accessed_columns plugin" do
10
10
  end
11
11
 
12
12
  it "should record columns accessed" do
13
- @o.accessed_columns.should == []
13
+ @o.accessed_columns.must_equal []
14
14
  @o.name
15
- @o.accessed_columns.should == [:name]
15
+ @o.accessed_columns.must_equal [:name]
16
16
  @o.name
17
- @o.accessed_columns.should == [:name]
17
+ @o.accessed_columns.must_equal [:name]
18
18
  @o.b
19
- @o.accessed_columns.sort_by{|s| s.to_s}.should == [:b, :name]
19
+ @o.accessed_columns.sort_by{|s| s.to_s}.must_equal [:b, :name]
20
20
  end
21
21
 
22
22
  it "should clear accessed columns when refreshing" do
23
23
  @o.name
24
24
  @o.refresh
25
- @o.accessed_columns.should == []
25
+ @o.accessed_columns.must_equal []
26
26
  end
27
27
 
28
28
  it "should clear accessed columns when saving" do
29
29
  @o.name
30
30
  @o.save
31
- @o.accessed_columns.should == []
31
+ @o.accessed_columns.must_equal []
32
32
  end
33
33
 
34
34
  it "should work when duping and cloning instances" do
35
35
  @o.name
36
36
  o = @o.dup
37
- @o.accessed_columns.should == [:name]
37
+ @o.accessed_columns.must_equal [:name]
38
38
  @o.b
39
- @o.accessed_columns.sort_by{|s| s.to_s}.should == [:b, :name]
40
- o.accessed_columns.should == [:name]
39
+ @o.accessed_columns.sort_by{|s| s.to_s}.must_equal [:b, :name]
40
+ o.accessed_columns.must_equal [:name]
41
41
  o2 = o.clone
42
42
  o2.refresh
43
- o.accessed_columns.should == [:name]
44
- o2.accessed_columns.should == []
43
+ o.accessed_columns.must_equal [:name]
44
+ o2.accessed_columns.must_equal []
45
45
  end
46
46
 
47
47
  it "should not raise exceptions when object is frozen" do
48
48
  @o.freeze
49
- proc{@o.name}.should_not raise_error
49
+ @o.name
50
50
  end
51
51
  end
@@ -24,7 +24,7 @@ rescue LoadError => e
24
24
  skip_warn "active_model plugin: can't load active_model (#{e.class}: #{e})"
25
25
  else
26
26
  describe "ActiveModel plugin" do
27
- specify "should be compliant to the ActiveModel spec" do
27
+ it "should be compliant to the ActiveModel spec" do
28
28
  tc = Class.new(test_class)
29
29
  tc.class_eval do
30
30
  define_method(:setup) do
@@ -53,7 +53,7 @@ describe "ActiveModel plugin" do
53
53
 
54
54
  # Should return self, not a proxy object
55
55
  def test__to_model
56
- assert_equal @m.to_model.object_id.should, @m.object_id
56
+ assert_equal @m.to_model.object_id, @m.object_id
57
57
  end
58
58
 
59
59
  def test__to_key
@@ -116,7 +116,7 @@ describe "ActiveModel plugin" do
116
116
  if res.failure_count > 0
117
117
  puts res.instance_variable_get(:@failures)
118
118
  end
119
- res.failure_count.should == 0
119
+ res.failure_count.must_equal 0
120
120
  end
121
121
  end
122
122
  end
@@ -15,10 +15,10 @@ describe "Sequel::Plugins::AfterInitialize" do
15
15
  end
16
16
 
17
17
  it "should have after_initialize hook be called for new objects" do
18
- @c.new(:name=>'foo').values.should == {:name=>'foofoo'}
18
+ @c.new(:name=>'foo').values.must_equal(:name=>'foofoo')
19
19
  end
20
20
 
21
21
  it "should have after_initialize hook be called for objects loaded from the database" do
22
- @c.call(:id=>1, :name=>'foo').values.should == {:id=>3, :name=>'foofoo'}
22
+ @c.call(:id=>1, :name=>'foo').values.must_equal(:id=>3, :name=>'foofoo')
23
23
  end
24
24
  end
@@ -6,78 +6,78 @@ describe "arbtirary servers" do
6
6
  @db.extension :arbitrary_servers
7
7
  end
8
8
 
9
- specify "should allow arbitrary server options using a hash" do
9
+ it "should allow arbitrary server options using a hash" do
10
10
  @db.synchronize(:host=>'host1', :database=>'db1') do |c|
11
- c.opts[:host].should == 'host1'
12
- c.opts[:database].should == 'db1'
11
+ c.opts[:host].must_equal 'host1'
12
+ c.opts[:database].must_equal 'db1'
13
13
  end
14
14
  end
15
15
 
16
- specify "should not cache connections to arbitrary servers" do
16
+ it "should not cache connections to arbitrary servers" do
17
17
  x = nil
18
18
  @db.synchronize(:host=>'host1', :database=>'db1') do |c|
19
19
  x = c
20
20
  end
21
21
  @db.synchronize(:host=>'host1', :database=>'db1') do |c2|
22
- c2.should_not equal(x)
22
+ c2.wont_be_same_as(x)
23
23
  end
24
24
  end
25
25
 
26
- specify "should yield same connection correctly when nesting" do
26
+ it "should yield same connection correctly when nesting" do
27
27
  @db.synchronize(:host=>'host1', :database=>'db1') do |c|
28
28
  @db.synchronize(:host=>'host1', :database=>'db1') do |c2|
29
- c2.should equal(c)
29
+ c2.must_be_same_as(c)
30
30
  end
31
31
  end
32
32
  end
33
33
 
34
- specify "should disconnect when connection is finished" do
34
+ it "should disconnect when connection is finished" do
35
35
  x, x1 = nil, nil
36
36
  @db.meta_def(:disconnect_connection){|c| x = c}
37
37
  @db.synchronize(:host=>'host1', :database=>'db1') do |c|
38
38
  x1 = c
39
39
  @db.synchronize(:host=>'host1', :database=>'db1') do |c2|
40
- c2.should equal(c)
40
+ c2.must_be_same_as(c)
41
41
  end
42
- x.should equal(nil)
42
+ x.must_be_same_as(nil)
43
43
  end
44
- x.should equal(x1)
44
+ x.must_be_same_as(x1)
45
45
  end
46
46
 
47
- specify "should yield different connection correctly when nesting" do
47
+ it "should yield different connection correctly when nesting" do
48
48
  @db.synchronize(:host=>'host1', :database=>'db1') do |c|
49
- c.opts[:host].should == 'host1'
49
+ c.opts[:host].must_equal 'host1'
50
50
  @db.synchronize(:host=>'host2', :database=>'db1') do |c2|
51
- c2.opts[:host].should == 'host2'
52
- c2.should_not equal(c)
51
+ c2.opts[:host].must_equal 'host2'
52
+ c2.wont_be_same_as(c)
53
53
  end
54
54
  end
55
55
  end
56
56
 
57
- specify "should respect multithreaded access" do
57
+ it "should respect multithreaded access" do
58
58
  @db.synchronize(:host=>'host1', :database=>'db1') do |c|
59
59
  Thread.new do
60
60
  @db.synchronize(:host=>'host1', :database=>'db1') do |c2|
61
- c2.should_not equal(c)
61
+ _(c2).wont_be_same_as(c)
62
62
  end
63
63
  end.join
64
64
  end
65
65
  end
66
66
 
67
- specify "should work correctly with server_block plugin" do
67
+ it "should work correctly with server_block plugin" do
68
68
  @db.extension :server_block
69
69
  @db.with_server(:host=>'host1', :database=>'db1') do
70
70
  @db.synchronize do |c|
71
- c.opts[:host].should == 'host1'
72
- c.opts[:database].should == 'db1'
71
+ c.opts[:host].must_equal 'host1'
72
+ c.opts[:database].must_equal 'db1'
73
73
  @db.synchronize do |c2|
74
- c2.should equal(c)
74
+ c2.must_be_same_as(c)
75
75
  end
76
76
  end
77
77
  end
78
78
  end
79
79
 
80
- specify "should respect multithreaded access with server block plugin" do
80
+ it "should respect multithreaded access with server block plugin" do
81
81
  @db.extension :server_block
82
82
  q, q1 = Queue.new, Queue.new
83
83
 
@@ -103,7 +103,7 @@ describe "arbtirary servers" do
103
103
  @db[:t].all
104
104
  q1.push nil
105
105
  t.join
106
- @db.sqls.should == ['SELECT * FROM t', 'SELECT * FROM t -- {:host=>"a"}', 'SELECT * FROM t', 'SELECT * FROM t -- {:host=>"c"}', 'SELECT * FROM t -- {:host=>"d"}',
106
+ @db.sqls.must_equal ['SELECT * FROM t', 'SELECT * FROM t -- {:host=>"a"}', 'SELECT * FROM t', 'SELECT * FROM t -- {:host=>"c"}', 'SELECT * FROM t -- {:host=>"d"}',
107
107
  'SELECT * FROM t -- {:host=>"b"}', 'SELECT * FROM t -- {:host=>"a"}', 'SELECT * FROM t', 'SELECT * FROM t -- {:host=>"c"}', 'SELECT * FROM t']
108
108
  end
109
109
  end
@@ -18,100 +18,100 @@ describe "AssociationDependencies plugin" do
18
18
  DB.reset
19
19
  end
20
20
 
21
- specify "should allow destroying associated many_to_one associated object" do
21
+ it "should allow destroying associated many_to_one associated object" do
22
22
  @Album.add_association_dependencies :artist=>:destroy
23
23
  @Album.load(:id=>1, :name=>'Al', :artist_id=>2).destroy
24
- DB.sqls.should == ['DELETE FROM albums WHERE id = 1', 'SELECT * FROM artists WHERE (artists.id = 2) LIMIT 1', 'DELETE FROM artists WHERE id = 2']
24
+ DB.sqls.must_equal ['DELETE FROM albums WHERE id = 1', 'SELECT * FROM artists WHERE (artists.id = 2) LIMIT 1', 'DELETE FROM artists WHERE id = 2']
25
25
  end
26
26
 
27
- specify "should allow deleting associated many_to_one associated object" do
27
+ it "should allow deleting associated many_to_one associated object" do
28
28
  @Album.add_association_dependencies :artist=>:delete
29
29
  @Album.load(:id=>1, :name=>'Al', :artist_id=>2).destroy
30
- DB.sqls.should == ['DELETE FROM albums WHERE id = 1', 'DELETE FROM artists WHERE (artists.id = 2)']
30
+ DB.sqls.must_equal ['DELETE FROM albums WHERE id = 1', 'DELETE FROM artists WHERE (artists.id = 2)']
31
31
  end
32
32
 
33
- specify "should allow destroying associated one_to_one associated object" do
33
+ it "should allow destroying associated one_to_one associated object" do
34
34
  @Artist.add_association_dependencies :first_album=>:destroy
35
35
  @Artist.load(:id=>2, :name=>'Ar').destroy
36
- DB.sqls.should == ['SELECT * FROM albums WHERE ((position = 1) AND (albums.artist_id = 2)) LIMIT 1', 'DELETE FROM albums WHERE id = 1', 'DELETE FROM artists WHERE id = 2']
36
+ DB.sqls.must_equal ['SELECT * FROM albums WHERE ((position = 1) AND (albums.artist_id = 2)) LIMIT 1', 'DELETE FROM albums WHERE id = 1', 'DELETE FROM artists WHERE id = 2']
37
37
  end
38
38
 
39
- specify "should allow deleting associated one_to_one associated object" do
39
+ it "should allow deleting associated one_to_one associated object" do
40
40
  @Artist.add_association_dependencies :first_album=>:delete
41
41
  @Artist.load(:id=>2, :name=>'Ar').destroy
42
- DB.sqls.should == ['DELETE FROM albums WHERE ((position = 1) AND (albums.artist_id = 2))', 'DELETE FROM artists WHERE id = 2']
42
+ DB.sqls.must_equal ['DELETE FROM albums WHERE ((position = 1) AND (albums.artist_id = 2))', 'DELETE FROM artists WHERE id = 2']
43
43
  end
44
44
 
45
- specify "should allow destroying associated one_to_many objects" do
45
+ it "should allow destroying associated one_to_many objects" do
46
46
  @Artist.add_association_dependencies :albums=>:destroy
47
47
  @Artist.load(:id=>2, :name=>'Ar').destroy
48
- DB.sqls.should == ['SELECT * FROM albums WHERE (albums.artist_id = 2)', 'DELETE FROM albums WHERE id = 1', 'DELETE FROM artists WHERE id = 2']
48
+ DB.sqls.must_equal ['SELECT * FROM albums WHERE (albums.artist_id = 2)', 'DELETE FROM albums WHERE id = 1', 'DELETE FROM artists WHERE id = 2']
49
49
  end
50
50
 
51
- specify "should allow deleting associated one_to_many objects" do
51
+ it "should allow deleting associated one_to_many objects" do
52
52
  @Artist.add_association_dependencies :albums=>:delete
53
53
  @Artist.load(:id=>2, :name=>'Ar').destroy
54
- DB.sqls.should == ['DELETE FROM albums WHERE (albums.artist_id = 2)', 'DELETE FROM artists WHERE id = 2']
54
+ DB.sqls.must_equal ['DELETE FROM albums WHERE (albums.artist_id = 2)', 'DELETE FROM artists WHERE id = 2']
55
55
  end
56
56
 
57
- specify "should allow nullifying associated one_to_one objects" do
57
+ it "should allow nullifying associated one_to_one objects" do
58
58
  @Artist.add_association_dependencies :first_album=>:nullify
59
59
  @Artist.load(:id=>2, :name=>'Ar').destroy
60
- DB.sqls.should == ['UPDATE albums SET artist_id = NULL WHERE ((position = 1) AND (artist_id = 2))', 'DELETE FROM artists WHERE id = 2']
60
+ DB.sqls.must_equal ['UPDATE albums SET artist_id = NULL WHERE ((position = 1) AND (artist_id = 2))', 'DELETE FROM artists WHERE id = 2']
61
61
  end
62
62
 
63
- specify "should allow nullifying associated one_to_many objects" do
63
+ it "should allow nullifying associated one_to_many objects" do
64
64
  @Artist.add_association_dependencies :albums=>:nullify
65
65
  @Artist.load(:id=>2, :name=>'Ar').destroy
66
- DB.sqls.should == ['UPDATE albums SET artist_id = NULL WHERE (artist_id = 2)', 'DELETE FROM artists WHERE id = 2']
66
+ DB.sqls.must_equal ['UPDATE albums SET artist_id = NULL WHERE (artist_id = 2)', 'DELETE FROM artists WHERE id = 2']
67
67
  end
68
68
 
69
- specify "should allow nullifying associated many_to_many associations" do
69
+ it "should allow nullifying associated many_to_many associations" do
70
70
  @Artist.add_association_dependencies :other_artists=>:nullify
71
71
  @Artist.load(:id=>2, :name=>'Ar').destroy
72
- DB.sqls.should == ['DELETE FROM aoa WHERE (l = 2)', 'DELETE FROM artists WHERE id = 2']
72
+ DB.sqls.must_equal ['DELETE FROM aoa WHERE (l = 2)', 'DELETE FROM artists WHERE id = 2']
73
73
  end
74
74
 
75
- specify "should raise an error if attempting to nullify a many_to_one association" do
76
- proc{@Album.add_association_dependencies :artist=>:nullify}.should raise_error(Sequel::Error)
75
+ it "should raise an error if attempting to nullify a many_to_one association" do
76
+ proc{@Album.add_association_dependencies :artist=>:nullify}.must_raise(Sequel::Error)
77
77
  end
78
78
 
79
- specify "should raise an error if using an unrecognized dependence action" do
80
- proc{@Album.add_association_dependencies :artist=>:blah}.should raise_error(Sequel::Error)
79
+ it "should raise an error if using an unrecognized dependence action" do
80
+ proc{@Album.add_association_dependencies :artist=>:blah}.must_raise(Sequel::Error)
81
81
  end
82
82
 
83
- specify "should raise an error if a nonexistent association is used" do
84
- proc{@Album.add_association_dependencies :blah=>:delete}.should raise_error(Sequel::Error)
83
+ it "should raise an error if a nonexistent association is used" do
84
+ proc{@Album.add_association_dependencies :blah=>:delete}.must_raise(Sequel::Error)
85
85
  end
86
86
 
87
- specify "should raise an error if a invalid association type is used" do
87
+ it "should raise an error if a invalid association type is used" do
88
88
  @Artist.plugin :many_through_many
89
89
  @Artist.many_through_many :other_albums, [[:id, :id, :id]]
90
- proc{@Artist.add_association_dependencies :other_albums=>:nullify}.should raise_error(Sequel::Error)
90
+ proc{@Artist.add_association_dependencies :other_albums=>:nullify}.must_raise(Sequel::Error)
91
91
  end
92
92
 
93
- specify "should raise an error if using a many_to_many association type without nullify" do
94
- proc{@Artist.add_association_dependencies :other_artists=>:delete}.should raise_error(Sequel::Error)
93
+ it "should raise an error if using a many_to_many association type without nullify" do
94
+ proc{@Artist.add_association_dependencies :other_artists=>:delete}.must_raise(Sequel::Error)
95
95
  end
96
96
 
97
- specify "should allow specifying association dependencies in the plugin call" do
97
+ it "should allow specifying association dependencies in the plugin call" do
98
98
  @Album.plugin :association_dependencies, :artist=>:destroy
99
99
  @Album.load(:id=>1, :name=>'Al', :artist_id=>2).destroy
100
- DB.sqls.should == ['DELETE FROM albums WHERE id = 1', 'SELECT * FROM artists WHERE (artists.id = 2) LIMIT 1', 'DELETE FROM artists WHERE id = 2']
100
+ DB.sqls.must_equal ['DELETE FROM albums WHERE id = 1', 'SELECT * FROM artists WHERE (artists.id = 2) LIMIT 1', 'DELETE FROM artists WHERE id = 2']
101
101
  end
102
102
 
103
- specify "should work with subclasses" do
103
+ it "should work with subclasses" do
104
104
  c = Class.new(@Album)
105
105
  c.add_association_dependencies :artist=>:destroy
106
106
  c.load(:id=>1, :name=>'Al', :artist_id=>2).destroy
107
- DB.sqls.should == ['DELETE FROM albums WHERE id = 1', 'SELECT * FROM artists WHERE (artists.id = 2) LIMIT 1', 'DELETE FROM artists WHERE id = 2']
107
+ DB.sqls.must_equal ['DELETE FROM albums WHERE id = 1', 'SELECT * FROM artists WHERE (artists.id = 2) LIMIT 1', 'DELETE FROM artists WHERE id = 2']
108
108
 
109
109
  @Album.load(:id=>1, :name=>'Al', :artist_id=>2).destroy
110
- DB.sqls.should == ['DELETE FROM albums WHERE id = 1']
110
+ DB.sqls.must_equal ['DELETE FROM albums WHERE id = 1']
111
111
 
112
112
  @Album.add_association_dependencies :artist=>:destroy
113
113
  c2 = Class.new(@Album)
114
114
  c2.load(:id=>1, :name=>'Al', :artist_id=>2).destroy
115
- DB.sqls.should == ['DELETE FROM albums WHERE id = 1', 'SELECT * FROM artists WHERE (artists.id = 2) LIMIT 1', 'DELETE FROM artists WHERE id = 2']
115
+ DB.sqls.must_equal ['DELETE FROM albums WHERE id = 1', 'SELECT * FROM artists WHERE (artists.id = 2) LIMIT 1', 'DELETE FROM artists WHERE id = 2']
116
116
  end
117
117
  end
@@ -60,143 +60,143 @@ describe "Sequel::Plugins::AssociationPks" do
60
60
  @db.sqls
61
61
  end
62
62
 
63
- specify "should return correct associated pks for one_to_many associations" do
64
- @Artist.load(:id=>1).album_pks.should == [1,2,3]
65
- @Artist.load(:id=>2).album_pks.should == []
63
+ it "should return correct associated pks for one_to_many associations" do
64
+ @Artist.load(:id=>1).album_pks.must_equal [1,2,3]
65
+ @Artist.load(:id=>2).album_pks.must_equal []
66
66
  end
67
67
 
68
- specify "should return correct associated pks for many_to_many associations" do
69
- @Album.load(:id=>1).tag_pks.should == [1, 2]
70
- @Album.load(:id=>2).tag_pks.should == [2, 3]
71
- @Album.load(:id=>3).tag_pks.should == []
68
+ it "should return correct associated pks for many_to_many associations" do
69
+ @Album.load(:id=>1).tag_pks.must_equal [1, 2]
70
+ @Album.load(:id=>2).tag_pks.must_equal [2, 3]
71
+ @Album.load(:id=>3).tag_pks.must_equal []
72
72
  end
73
73
 
74
- specify "should set associated pks correctly for a one_to_many association" do
74
+ it "should set associated pks correctly for a one_to_many association" do
75
75
  @Artist.load(:id=>1).album_pks = [1, 2]
76
- @db.sqls.should == ["UPDATE albums SET artist_id = 1 WHERE (id IN (1, 2))",
76
+ @db.sqls.must_equal ["UPDATE albums SET artist_id = 1 WHERE (id IN (1, 2))",
77
77
  "UPDATE albums SET artist_id = NULL WHERE ((albums.artist_id = 1) AND (id NOT IN (1, 2)))"]
78
78
  end
79
79
 
80
- specify "should use associated class's primary key for a one_to_many association" do
80
+ it "should use associated class's primary key for a one_to_many association" do
81
81
  @Album.set_primary_key :foo
82
82
  @Artist.load(:id=>1).album_pks = [1, 2]
83
- @db.sqls.should == ["UPDATE albums SET artist_id = 1 WHERE (foo IN (1, 2))",
83
+ @db.sqls.must_equal ["UPDATE albums SET artist_id = 1 WHERE (foo IN (1, 2))",
84
84
  "UPDATE albums SET artist_id = NULL WHERE ((albums.artist_id = 1) AND (foo NOT IN (1, 2)))"]
85
85
  end
86
86
 
87
- specify "should set associated pks correctly for a many_to_many association" do
87
+ it "should set associated pks correctly for a many_to_many association" do
88
88
  @Album.load(:id=>2).tag_pks = [1, 3]
89
89
  sqls = @db.sqls
90
- sqls[0].should == "DELETE FROM albums_tags WHERE ((album_id = 2) AND (tag_id NOT IN (1, 3)))"
91
- sqls[1].should == 'SELECT tag_id FROM albums_tags WHERE (album_id = 2)'
92
- sqls[2].should == 'BEGIN'
93
- sqls[3].should =~ /INSERT INTO albums_tags \((album_id, tag_id|tag_id, album_id)\) VALUES \((2, 1|1, 2)\)/
94
- sqls[4].should == 'COMMIT'
95
- sqls.length.should == 5
90
+ sqls[0].must_equal "DELETE FROM albums_tags WHERE ((album_id = 2) AND (tag_id NOT IN (1, 3)))"
91
+ sqls[1].must_equal 'SELECT tag_id FROM albums_tags WHERE (album_id = 2)'
92
+ sqls[2].must_equal 'BEGIN'
93
+ sqls[3].must_match(/INSERT INTO albums_tags \((album_id, tag_id|tag_id, album_id)\) VALUES \((2, 1|1, 2)\)/)
94
+ sqls[4].must_equal 'COMMIT'
95
+ sqls.length.must_equal 5
96
96
  end
97
97
 
98
- specify "should return correct right-side associated cpks for one_to_many associations" do
98
+ it "should return correct right-side associated cpks for one_to_many associations" do
99
99
  @Album.one_to_many :vocalists, :class=>@Vocalist, :key=>:album_id
100
- @Album.load(:id=>1).vocalist_pks.should == [["F1", "L1"], ["F2", "L2"]]
101
- @Album.load(:id=>2).vocalist_pks.should == []
100
+ @Album.load(:id=>1).vocalist_pks.must_equal [["F1", "L1"], ["F2", "L2"]]
101
+ @Album.load(:id=>2).vocalist_pks.must_equal []
102
102
  end
103
103
 
104
- specify "should return correct right-side associated cpks for many_to_many associations" do
104
+ it "should return correct right-side associated cpks for many_to_many associations" do
105
105
  @Album.many_to_many :vocalists, :class=>@Vocalist, :join_table=>:albums_vocalists, :left_key=>:album_id, :right_key=>[:first, :last]
106
- @Album.load(:id=>1).vocalist_pks.should == [["F1", "L1"], ["F2", "L2"]]
107
- @Album.load(:id=>2).vocalist_pks.should == [["F2", "L2"], ["F3", "L3"]]
108
- @Album.load(:id=>3).vocalist_pks.should == []
106
+ @Album.load(:id=>1).vocalist_pks.must_equal [["F1", "L1"], ["F2", "L2"]]
107
+ @Album.load(:id=>2).vocalist_pks.must_equal [["F2", "L2"], ["F3", "L3"]]
108
+ @Album.load(:id=>3).vocalist_pks.must_equal []
109
109
  end
110
110
 
111
- specify "should set associated right-side cpks correctly for a one_to_many association" do
111
+ it "should set associated right-side cpks correctly for a one_to_many association" do
112
112
  @Album.one_to_many :vocalists, :class=>@Vocalist, :key=>:album_id
113
113
  @Album.load(:id=>1).vocalist_pks = [["F1", "L1"], ["F2", "L2"]]
114
- @db.sqls.should == ["UPDATE vocalists SET album_id = 1 WHERE ((first, last) IN (('F1', 'L1'), ('F2', 'L2')))",
114
+ @db.sqls.must_equal ["UPDATE vocalists SET album_id = 1 WHERE ((first, last) IN (('F1', 'L1'), ('F2', 'L2')))",
115
115
  "UPDATE vocalists SET album_id = NULL WHERE ((vocalists.album_id = 1) AND ((first, last) NOT IN (('F1', 'L1'), ('F2', 'L2'))))"]
116
116
  end
117
117
 
118
- specify "should set associated right-side cpks correctly for a many_to_many association" do
118
+ it "should set associated right-side cpks correctly for a many_to_many association" do
119
119
  @Album.many_to_many :vocalists, :class=>@Vocalist, :join_table=>:albums_vocalists, :left_key=>:album_id, :right_key=>[:first, :last]
120
120
  @Album.load(:id=>2).vocalist_pks = [["F1", "L1"], ["F2", "L2"]]
121
121
  sqls = @db.sqls
122
- sqls[0].should == "DELETE FROM albums_vocalists WHERE ((album_id = 2) AND ((first, last) NOT IN (('F1', 'L1'), ('F2', 'L2'))))"
123
- sqls[1].should == 'SELECT first, last FROM albums_vocalists WHERE (album_id = 2)'
122
+ sqls[0].must_equal "DELETE FROM albums_vocalists WHERE ((album_id = 2) AND ((first, last) NOT IN (('F1', 'L1'), ('F2', 'L2'))))"
123
+ sqls[1].must_equal 'SELECT first, last FROM albums_vocalists WHERE (album_id = 2)'
124
124
  match = sqls[3].match(/INSERT INTO albums_vocalists \((.*)\) VALUES \((.*)\)/)
125
- Hash[match[1].split(', ').zip(match[2].split(', '))].should == {"first"=>"'F1'", "last"=>"'L1'", "album_id"=>"2"}
126
- sqls.length.should == 5
125
+ Hash[match[1].split(', ').zip(match[2].split(', '))].must_equal("first"=>"'F1'", "last"=>"'L1'", "album_id"=>"2")
126
+ sqls.length.must_equal 5
127
127
  end
128
128
 
129
- specify "should return correct associated pks for left-side cpks for one_to_many associations" do
129
+ it "should return correct associated pks for left-side cpks for one_to_many associations" do
130
130
  @Vocalist.one_to_many :instruments, :class=>@Instrument, :key=>[:first, :last]
131
- @Vocalist.load(:first=>'F1', :last=>'L1').instrument_pks.should == [1, 2]
132
- @Vocalist.load(:first=>'F2', :last=>'L2').instrument_pks.should == []
131
+ @Vocalist.load(:first=>'F1', :last=>'L1').instrument_pks.must_equal [1, 2]
132
+ @Vocalist.load(:first=>'F2', :last=>'L2').instrument_pks.must_equal []
133
133
  end
134
134
 
135
- specify "should return correct associated pks for left-side cpks for many_to_many associations" do
135
+ it "should return correct associated pks for left-side cpks for many_to_many associations" do
136
136
  @Vocalist.many_to_many :instruments, :class=>@Instrument, :join_table=>:vocalists_instruments, :left_key=>[:first, :last]
137
- @Vocalist.load(:first=>'F1', :last=>'L1').instrument_pks.should == [1, 2]
138
- @Vocalist.load(:first=>'F2', :last=>'L2').instrument_pks.should == [2, 3]
139
- @Vocalist.load(:first=>'F3', :last=>'L3').instrument_pks.should == []
137
+ @Vocalist.load(:first=>'F1', :last=>'L1').instrument_pks.must_equal [1, 2]
138
+ @Vocalist.load(:first=>'F2', :last=>'L2').instrument_pks.must_equal [2, 3]
139
+ @Vocalist.load(:first=>'F3', :last=>'L3').instrument_pks.must_equal []
140
140
  end
141
141
 
142
- specify "should set associated pks correctly for left-side cpks for a one_to_many association" do
142
+ it "should set associated pks correctly for left-side cpks for a one_to_many association" do
143
143
  @Vocalist.one_to_many :instruments, :class=>@Instrument, :key=>[:first, :last]
144
144
  @Vocalist.load(:first=>'F1', :last=>'L1').instrument_pks = [1, 2]
145
145
  sqls = @db.sqls
146
- sqls[0].should =~ /UPDATE instruments SET (first = 'F1', last = 'L1'|last = 'L1', first = 'F1') WHERE \(id IN \(1, 2\)\)/
147
- sqls[1].should =~ /UPDATE instruments SET (first = NULL, last = NULL|last = NULL, first = NULL) WHERE \(\(instruments.first = 'F1'\) AND \(instruments.last = 'L1'\) AND \(id NOT IN \(1, 2\)\)\)/
148
- sqls.length.should == 2
146
+ sqls[0].must_match(/UPDATE instruments SET (first = 'F1', last = 'L1'|last = 'L1', first = 'F1') WHERE \(id IN \(1, 2\)\)/)
147
+ sqls[1].must_match(/UPDATE instruments SET (first = NULL, last = NULL|last = NULL, first = NULL) WHERE \(\(instruments.first = 'F1'\) AND \(instruments.last = 'L1'\) AND \(id NOT IN \(1, 2\)\)\)/)
148
+ sqls.length.must_equal 2
149
149
  end
150
150
 
151
- specify "should set associated pks correctly for left-side cpks for a many_to_many association" do
151
+ it "should set associated pks correctly for left-side cpks for a many_to_many association" do
152
152
  @Vocalist.many_to_many :instruments, :class=>@Instrument, :join_table=>:vocalists_instruments, :left_key=>[:first, :last]
153
153
  @Vocalist.load(:first=>'F2', :last=>'L2').instrument_pks = [1, 2]
154
154
  sqls = @db.sqls
155
- sqls[0].should == "DELETE FROM vocalists_instruments WHERE ((first = 'F2') AND (last = 'L2') AND (instrument_id NOT IN (1, 2)))"
156
- sqls[1].should == "SELECT instrument_id FROM vocalists_instruments WHERE ((first = 'F2') AND (last = 'L2'))"
155
+ sqls[0].must_equal "DELETE FROM vocalists_instruments WHERE ((first = 'F2') AND (last = 'L2') AND (instrument_id NOT IN (1, 2)))"
156
+ sqls[1].must_equal "SELECT instrument_id FROM vocalists_instruments WHERE ((first = 'F2') AND (last = 'L2'))"
157
157
  match = sqls[3].match(/INSERT INTO vocalists_instruments \((.*)\) VALUES \((.*)\)/)
158
- Hash[match[1].split(', ').zip(match[2].split(', '))].should == {"first"=>"'F2'", "last"=>"'L2'", "instrument_id"=>"1"}
159
- sqls.length.should == 5
158
+ Hash[match[1].split(', ').zip(match[2].split(', '))].must_equal("first"=>"'F2'", "last"=>"'L2'", "instrument_id"=>"1")
159
+ sqls.length.must_equal 5
160
160
  end
161
161
 
162
- specify "should return correct right-side associated cpks for left-side cpks for one_to_many associations" do
162
+ it "should return correct right-side associated cpks for left-side cpks for one_to_many associations" do
163
163
  @Vocalist.one_to_many :hits, :class=>@Hit, :key=>[:first, :last]
164
- @Vocalist.load(:first=>'F1', :last=>'L1').hit_pks.should == [[1997, 1], [1997, 2]]
165
- @Vocalist.load(:first=>'F2', :last=>'L2').hit_pks.should == []
164
+ @Vocalist.load(:first=>'F1', :last=>'L1').hit_pks.must_equal [[1997, 1], [1997, 2]]
165
+ @Vocalist.load(:first=>'F2', :last=>'L2').hit_pks.must_equal []
166
166
  end
167
167
 
168
- specify "should return correct right-side associated cpks for left-side cpks for many_to_many associations" do
168
+ it "should return correct right-side associated cpks for left-side cpks for many_to_many associations" do
169
169
  @Vocalist.many_to_many :hits, :class=>@Hit, :join_table=>:vocalists_hits, :left_key=>[:first, :last], :right_key=>[:year, :week]
170
- @Vocalist.load(:first=>'F1', :last=>'L1').hit_pks.should == [[1997, 1], [1997, 2]]
171
- @Vocalist.load(:first=>'F2', :last=>'L2').hit_pks.should == [[1997, 2], [1997, 3]]
172
- @Vocalist.load(:first=>'F3', :last=>'L3').hit_pks.should == []
170
+ @Vocalist.load(:first=>'F1', :last=>'L1').hit_pks.must_equal [[1997, 1], [1997, 2]]
171
+ @Vocalist.load(:first=>'F2', :last=>'L2').hit_pks.must_equal [[1997, 2], [1997, 3]]
172
+ @Vocalist.load(:first=>'F3', :last=>'L3').hit_pks.must_equal []
173
173
  end
174
174
 
175
- specify "should set associated right-side cpks correctly for left-side cpks for a one_to_many association" do
175
+ it "should set associated right-side cpks correctly for left-side cpks for a one_to_many association" do
176
176
  @Vocalist.one_to_many :hits, :class=>@Hit, :key=>[:first, :last], :order=>:week
177
177
  @Vocalist.load(:first=>'F1', :last=>'L1').hit_pks = [[1997, 1], [1997, 2]]
178
178
  sqls = @db.sqls
179
- sqls[0].should =~ /UPDATE hits SET (first = 'F1', last = 'L1'|last = 'L1', first = 'F1') WHERE \(\(year, week\) IN \(\(1997, 1\), \(1997, 2\)\)\)/
180
- sqls[1].should =~ /UPDATE hits SET (first = NULL, last = NULL|last = NULL, first = NULL) WHERE \(\(hits.first = 'F1'\) AND \(hits.last = 'L1'\) AND \(\(year, week\) NOT IN \(\(1997, 1\), \(1997, 2\)\)\)\)/
181
- sqls.length.should == 2
179
+ sqls[0].must_match(/UPDATE hits SET (first = 'F1', last = 'L1'|last = 'L1', first = 'F1') WHERE \(\(year, week\) IN \(\(1997, 1\), \(1997, 2\)\)\)/)
180
+ sqls[1].must_match(/UPDATE hits SET (first = NULL, last = NULL|last = NULL, first = NULL) WHERE \(\(hits.first = 'F1'\) AND \(hits.last = 'L1'\) AND \(\(year, week\) NOT IN \(\(1997, 1\), \(1997, 2\)\)\)\)/)
181
+ sqls.length.must_equal 2
182
182
  end
183
183
 
184
- specify "should set associated right-side cpks correctly for left-side cpks for a many_to_many association" do
184
+ it "should set associated right-side cpks correctly for left-side cpks for a many_to_many association" do
185
185
  @Vocalist.many_to_many :hits, :class=>@Hit, :join_table=>:vocalists_hits, :left_key=>[:first, :last], :right_key=>[:year, :week]
186
186
  @Vocalist.load(:first=>'F2', :last=>'L2').hit_pks = [[1997, 1], [1997, 2]]
187
187
  sqls = @db.sqls
188
- sqls[0].should == "DELETE FROM vocalists_hits WHERE ((first = 'F2') AND (last = 'L2') AND ((year, week) NOT IN ((1997, 1), (1997, 2))))"
189
- sqls[1].should == "SELECT year, week FROM vocalists_hits WHERE ((first = 'F2') AND (last = 'L2'))"
188
+ sqls[0].must_equal "DELETE FROM vocalists_hits WHERE ((first = 'F2') AND (last = 'L2') AND ((year, week) NOT IN ((1997, 1), (1997, 2))))"
189
+ sqls[1].must_equal "SELECT year, week FROM vocalists_hits WHERE ((first = 'F2') AND (last = 'L2'))"
190
190
  match = sqls[3].match(/INSERT INTO vocalists_hits \((.*)\) VALUES \((.*)\)/)
191
- Hash[match[1].split(', ').zip(match[2].split(', '))].should == {"first"=>"'F2'", "last"=>"'L2'", "year"=>"1997", "week"=>"1"}
192
- sqls.length.should == 5
191
+ Hash[match[1].split(', ').zip(match[2].split(', '))].must_equal("first"=>"'F2'", "last"=>"'L2'", "year"=>"1997", "week"=>"1")
192
+ sqls.length.must_equal 5
193
193
  end
194
194
 
195
- specify "should use transactions if the object is configured to use transactions" do
195
+ it "should use transactions if the object is configured to use transactions" do
196
196
  artist = @Artist.load(:id=>1)
197
197
  artist.use_transactions = true
198
198
  artist.album_pks = [1, 2]
199
- @db.sqls.should == ["BEGIN",
199
+ @db.sqls.must_equal ["BEGIN",
200
200
  "UPDATE albums SET artist_id = 1 WHERE (id IN (1, 2))",
201
201
  "UPDATE albums SET artist_id = NULL WHERE ((albums.artist_id = 1) AND (id NOT IN (1, 2)))",
202
202
  "COMMIT"]
@@ -205,77 +205,77 @@ describe "Sequel::Plugins::AssociationPks" do
205
205
  album.use_transactions = true
206
206
  album.tag_pks = [1, 3]
207
207
  sqls = @db.sqls
208
- sqls[0].should == "BEGIN"
209
- sqls[1].should == "DELETE FROM albums_tags WHERE ((album_id = 2) AND (tag_id NOT IN (1, 3)))"
210
- sqls[2].should == 'SELECT tag_id FROM albums_tags WHERE (album_id = 2)'
211
- sqls[3].should =~ /INSERT INTO albums_tags \((album_id, tag_id|tag_id, album_id)\) VALUES \((2, 1|1, 2)\)/
212
- sqls[4].should == "COMMIT"
213
- sqls.length.should == 5
208
+ sqls[0].must_equal "BEGIN"
209
+ sqls[1].must_equal "DELETE FROM albums_tags WHERE ((album_id = 2) AND (tag_id NOT IN (1, 3)))"
210
+ sqls[2].must_equal 'SELECT tag_id FROM albums_tags WHERE (album_id = 2)'
211
+ sqls[3].must_match(/INSERT INTO albums_tags \((album_id, tag_id|tag_id, album_id)\) VALUES \((2, 1|1, 2)\)/)
212
+ sqls[4].must_equal "COMMIT"
213
+ sqls.length.must_equal 5
214
214
  end
215
215
 
216
- specify "should automatically convert keys to numbers if the primary key is an integer for one_to_many associations" do
216
+ it "should automatically convert keys to numbers if the primary key is an integer for one_to_many associations" do
217
217
  @Album.db_schema[:id][:type] = :integer
218
218
  @Artist.load(:id=>1).album_pks = %w'1 2'
219
- @db.sqls.should == ["UPDATE albums SET artist_id = 1 WHERE (id IN (1, 2))",
219
+ @db.sqls.must_equal ["UPDATE albums SET artist_id = 1 WHERE (id IN (1, 2))",
220
220
  "UPDATE albums SET artist_id = NULL WHERE ((albums.artist_id = 1) AND (id NOT IN (1, 2)))"]
221
221
  end
222
222
 
223
- specify "should not automatically convert keys if the primary key is not an integer for one_to_many associations" do
223
+ it "should not automatically convert keys if the primary key is not an integer for one_to_many associations" do
224
224
  @Album.db_schema[:id][:type] = :string
225
225
  @Artist.load(:id=>1).album_pks = %w'1 2'
226
- @db.sqls.should == ["UPDATE albums SET artist_id = 1 WHERE (id IN ('1', '2'))",
226
+ @db.sqls.must_equal ["UPDATE albums SET artist_id = 1 WHERE (id IN ('1', '2'))",
227
227
  "UPDATE albums SET artist_id = NULL WHERE ((albums.artist_id = 1) AND (id NOT IN ('1', '2')))"]
228
228
  end
229
229
 
230
- specify "should automatically convert keys to numbers if the primary key is an integer for many_to_many associations" do
230
+ it "should automatically convert keys to numbers if the primary key is an integer for many_to_many associations" do
231
231
  @Tag.db_schema[:id][:type] = :integer
232
232
  @Album.load(:id=>2).tag_pks = %w'1 3'
233
233
  sqls = @db.sqls
234
- sqls[0].should == "DELETE FROM albums_tags WHERE ((album_id = 2) AND (tag_id NOT IN (1, 3)))"
235
- sqls[1].should == 'SELECT tag_id FROM albums_tags WHERE (album_id = 2)'
236
- sqls[3].should =~ /INSERT INTO albums_tags \((album_id, tag_id|tag_id, album_id)\) VALUES \((2, 1|1, 2)\)/
237
- sqls.length.should == 5
234
+ sqls[0].must_equal "DELETE FROM albums_tags WHERE ((album_id = 2) AND (tag_id NOT IN (1, 3)))"
235
+ sqls[1].must_equal 'SELECT tag_id FROM albums_tags WHERE (album_id = 2)'
236
+ sqls[3].must_match(/INSERT INTO albums_tags \((album_id, tag_id|tag_id, album_id)\) VALUES \((2, 1|1, 2)\)/)
237
+ sqls.length.must_equal 5
238
238
  end
239
239
 
240
- specify "should not automatically convert keys to numbers if the primary key is an integer for many_to_many associations" do
240
+ it "should not automatically convert keys to numbers if the primary key is an integer for many_to_many associations" do
241
241
  @Tag.db_schema[:id][:type] = :string
242
242
  @Album.load(:id=>2).tag_pks = %w'1 3'
243
243
  sqls = @db.sqls
244
- sqls[0].should == "DELETE FROM albums_tags WHERE ((album_id = 2) AND (tag_id NOT IN ('1', '3')))"
245
- sqls[1].should == 'SELECT tag_id FROM albums_tags WHERE (album_id = 2)'
246
- sqls[3].should =~ /INSERT INTO albums_tags \((album_id, tag_id|tag_id, album_id)\) VALUES \((2, '1'|'1', 2)\)/
247
- sqls[4].should =~ /INSERT INTO albums_tags \((album_id, tag_id|tag_id, album_id)\) VALUES \((2, '3'|'3', 2)\)/
248
- sqls.length.should == 6
244
+ sqls[0].must_equal "DELETE FROM albums_tags WHERE ((album_id = 2) AND (tag_id NOT IN ('1', '3')))"
245
+ sqls[1].must_equal 'SELECT tag_id FROM albums_tags WHERE (album_id = 2)'
246
+ sqls[3].must_match(/INSERT INTO albums_tags \((album_id, tag_id|tag_id, album_id)\) VALUES \((2, '1'|'1', 2)\)/)
247
+ sqls[4].must_match(/INSERT INTO albums_tags \((album_id, tag_id|tag_id, album_id)\) VALUES \((2, '3'|'3', 2)\)/)
248
+ sqls.length.must_equal 6
249
249
  end
250
250
 
251
- specify "should automatically convert keys to numbers for appropriate integer primary key for composite key associations" do
251
+ it "should automatically convert keys to numbers for appropriate integer primary key for composite key associations" do
252
252
  @Hit.db_schema[:year][:type] = :integer
253
253
  @Hit.db_schema[:week][:type] = :integer
254
254
  @Vocalist.many_to_many :hits, :class=>@Hit, :join_table=>:vocalists_hits, :left_key=>[:first, :last], :right_key=>[:year, :week]
255
255
  @Vocalist.load(:first=>'F2', :last=>'L2').hit_pks = [['1997', '1'], ['1997', '2']]
256
256
  sqls = @db.sqls
257
- sqls[0].should == "DELETE FROM vocalists_hits WHERE ((first = 'F2') AND (last = 'L2') AND ((year, week) NOT IN ((1997, 1), (1997, 2))))"
258
- sqls[1].should == "SELECT year, week FROM vocalists_hits WHERE ((first = 'F2') AND (last = 'L2'))"
257
+ sqls[0].must_equal "DELETE FROM vocalists_hits WHERE ((first = 'F2') AND (last = 'L2') AND ((year, week) NOT IN ((1997, 1), (1997, 2))))"
258
+ sqls[1].must_equal "SELECT year, week FROM vocalists_hits WHERE ((first = 'F2') AND (last = 'L2'))"
259
259
  match = sqls[3].match(/INSERT INTO vocalists_hits \((.*)\) VALUES \((.*)\)/)
260
- Hash[match[1].split(', ').zip(match[2].split(', '))].should == {"first"=>"'F2'", "last"=>"'L2'", "year"=>"1997", "week"=>"1"}
261
- sqls.length.should == 5
260
+ Hash[match[1].split(', ').zip(match[2].split(', '))].must_equal("first"=>"'F2'", "last"=>"'L2'", "year"=>"1997", "week"=>"1")
261
+ sqls.length.must_equal 5
262
262
 
263
263
  @Vocalist.db_schema[:first][:type] = :integer
264
264
  @Vocalist.db_schema[:last][:type] = :integer
265
265
  @Album.one_to_many :vocalists, :class=>@Vocalist, :key=>:album_id
266
266
  @Album.load(:id=>1).vocalist_pks = [["11", "11"], ["12", "12"]]
267
- @db.sqls.should == ["UPDATE vocalists SET album_id = 1 WHERE ((first, last) IN ((11, 11), (12, 12)))",
267
+ @db.sqls.must_equal ["UPDATE vocalists SET album_id = 1 WHERE ((first, last) IN ((11, 11), (12, 12)))",
268
268
  "UPDATE vocalists SET album_id = NULL WHERE ((vocalists.album_id = 1) AND ((first, last) NOT IN ((11, 11), (12, 12))))"]
269
269
 
270
270
  @Album.many_to_many :vocalists, :class=>@Vocalist, :join_table=>:albums_vocalists, :left_key=>:album_id, :right_key=>[:first, :last]
271
271
  @Album.load(:id=>2).vocalist_pks = [["11", "11"], ["12", "12"]]
272
272
  sqls = @db.sqls
273
- sqls[0].should == "DELETE FROM albums_vocalists WHERE ((album_id = 2) AND ((first, last) NOT IN ((11, 11), (12, 12))))"
274
- sqls[1].should == 'SELECT first, last FROM albums_vocalists WHERE (album_id = 2)'
273
+ sqls[0].must_equal "DELETE FROM albums_vocalists WHERE ((album_id = 2) AND ((first, last) NOT IN ((11, 11), (12, 12))))"
274
+ sqls[1].must_equal 'SELECT first, last FROM albums_vocalists WHERE (album_id = 2)'
275
275
  match = sqls[3].match(/INSERT INTO albums_vocalists \((.*)\) VALUES \((.*)\)/)
276
- Hash[match[1].split(', ').zip(match[2].split(', '))].should == {"first"=>"11", "last"=>"11", "album_id"=>"2"}
276
+ Hash[match[1].split(', ').zip(match[2].split(', '))].must_equal("first"=>"11", "last"=>"11", "album_id"=>"2")
277
277
  match = sqls[4].match(/INSERT INTO albums_vocalists \((.*)\) VALUES \((.*)\)/)
278
- Hash[match[1].split(', ').zip(match[2].split(', '))].should == {"first"=>"12", "last"=>"12", "album_id"=>"2"}
279
- sqls.length.should == 6
278
+ Hash[match[1].split(', ').zip(match[2].split(', '))].must_equal("first"=>"12", "last"=>"12", "album_id"=>"2")
279
+ sqls.length.must_equal 6
280
280
  end
281
281
  end