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,75 +10,75 @@ describe "Supported types" do
10
10
  DB.drop_table?(:items)
11
11
  end
12
12
 
13
- specify "should support casting correctly" do
13
+ it "should support casting correctly" do
14
14
  ds = create_items_table_with_column(:number, Integer)
15
15
  ds.insert(:number => 1)
16
- ds.select(Sequel.cast(:number, String).as(:n)).map(:n).should == %w'1'
16
+ ds.select(Sequel.cast(:number, String).as(:n)).map(:n).must_equal %w'1'
17
17
  ds = create_items_table_with_column(:name, String)
18
18
  ds.insert(:name=> '1')
19
- ds.select(Sequel.cast(:name, Integer).as(:n)).map(:n).should == [1]
19
+ ds.select(Sequel.cast(:name, Integer).as(:n)).map(:n).must_equal [1]
20
20
  end
21
21
 
22
- specify "should support NULL correctly" do
22
+ it "should support NULL correctly" do
23
23
  ds = create_items_table_with_column(:number, Integer)
24
24
  ds.insert(:number => nil)
25
- ds.all.should == [{:number=>nil}]
25
+ ds.all.must_equal [{:number=>nil}]
26
26
  end
27
27
 
28
- specify "should support generic integer type" do
28
+ it "should support generic integer type" do
29
29
  ds = create_items_table_with_column(:number, Integer)
30
30
  ds.insert(:number => 2)
31
- ds.all.should == [{:number=>2}]
31
+ ds.all.must_equal [{:number=>2}]
32
32
  end
33
33
 
34
- specify "should support generic fixnum type" do
34
+ it "should support generic fixnum type" do
35
35
  ds = create_items_table_with_column(:number, Fixnum)
36
36
  ds.insert(:number => 2)
37
- ds.all.should == [{:number=>2}]
37
+ ds.all.must_equal [{:number=>2}]
38
38
  end
39
39
 
40
- specify "should support generic bignum type" do
40
+ it "should support generic bignum type" do
41
41
  ds = create_items_table_with_column(:number, Bignum)
42
42
  ds.insert(:number => 2**34)
43
- ds.all.should == [{:number=>2**34}]
43
+ ds.all.must_equal [{:number=>2**34}]
44
44
  end
45
45
 
46
46
  cspecify "should support generic float type", [:swift, :sqlite] do
47
47
  ds = create_items_table_with_column(:number, Float)
48
48
  ds.insert(:number => 2.1)
49
- ds.all.should == [{:number=>2.1}]
49
+ ds.all.must_equal [{:number=>2.1}]
50
50
  end
51
51
 
52
52
  cspecify "should support generic numeric type", [:odbc, :mssql], [:swift, :sqlite] do
53
53
  ds = create_items_table_with_column(:number, Numeric, :size=>[15, 10])
54
54
  ds.insert(:number => BigDecimal.new('2.123456789'))
55
- ds.all.should == [{:number=>BigDecimal.new('2.123456789')}]
55
+ ds.all.must_equal [{:number=>BigDecimal.new('2.123456789')}]
56
56
  ds = create_items_table_with_column(:number, BigDecimal, :size=>[15, 10])
57
57
  ds.insert(:number => BigDecimal.new('2.123456789'))
58
- ds.all.should == [{:number=>BigDecimal.new('2.123456789')}]
58
+ ds.all.must_equal [{:number=>BigDecimal.new('2.123456789')}]
59
59
  end
60
60
 
61
- specify "should support generic string type" do
61
+ it "should support generic string type" do
62
62
  ds = create_items_table_with_column(:name, String)
63
63
  ds.insert(:name => 'Test User')
64
- ds.all.should == [{:name=>'Test User'}]
64
+ ds.all.must_equal [{:name=>'Test User'}]
65
65
  end
66
66
 
67
- specify "should support generic text type" do
67
+ it "should support generic text type" do
68
68
  ds = create_items_table_with_column(:name, String, :text=>true)
69
69
  ds.insert(:name => 'Test User'*100)
70
- ds.all.should == [{:name=>'Test User'*100}]
70
+ ds.all.must_equal [{:name=>'Test User'*100}]
71
71
 
72
72
  ds.update(:name=>ds.get(:name))
73
- ds.all.should == [{:name=>'Test User'*100}]
73
+ ds.all.must_equal [{:name=>'Test User'*100}]
74
74
  end
75
75
 
76
76
  cspecify "should support generic date type", [:do, :sqlite], [:jdbc, :sqlite], [:tinytds], [:jdbc, :mssql], :oracle do
77
77
  ds = create_items_table_with_column(:dat, Date)
78
78
  d = Date.today
79
79
  ds.insert(:dat => d)
80
- ds.first[:dat].should be_a_kind_of(Date)
81
- ds.first[:dat].to_s.should == d.to_s
80
+ ds.first[:dat].must_be_kind_of(Date)
81
+ ds.first[:dat].to_s.must_equal d.to_s
82
82
  end
83
83
 
84
84
  cspecify "should support generic time type", [:do], [:swift], [:odbc], [:jdbc, :mssql], [:jdbc, :sqlite], [:mysql2], [:tinytds], :oracle do
@@ -86,48 +86,48 @@ describe "Supported types" do
86
86
  t = Sequel::SQLTime.now
87
87
  ds.insert(:tim => t)
88
88
  v = ds.first[:tim]
89
- ds.literal(v).should == ds.literal(t)
90
- v.should be_a_kind_of(Sequel::SQLTime)
89
+ ds.literal(v).must_equal ds.literal(t)
90
+ v.must_be_kind_of(Sequel::SQLTime)
91
91
  ds.delete
92
92
  ds.insert(:tim => v)
93
93
  v2 = ds.first[:tim]
94
- ds.literal(v2).should == ds.literal(t)
95
- v2.should be_a_kind_of(Sequel::SQLTime)
94
+ ds.literal(v2).must_equal ds.literal(t)
95
+ v2.must_be_kind_of(Sequel::SQLTime)
96
96
  end
97
97
 
98
98
  cspecify "should support generic datetime type", [:do, :sqlite], [:jdbc, :sqlite] do
99
99
  ds = create_items_table_with_column(:tim, DateTime)
100
100
  t = DateTime.now
101
101
  ds.insert(:tim => t)
102
- ds.first[:tim].strftime('%Y%m%d%H%M%S').should == t.strftime('%Y%m%d%H%M%S')
102
+ ds.first[:tim].strftime('%Y%m%d%H%M%S').must_equal t.strftime('%Y%m%d%H%M%S')
103
103
  ds = create_items_table_with_column(:tim, Time)
104
104
  t = Time.now
105
105
  ds.insert(:tim => t)
106
- ds.first[:tim].strftime('%Y%m%d%H%M%S').should == t.strftime('%Y%m%d%H%M%S')
106
+ ds.first[:tim].strftime('%Y%m%d%H%M%S').must_equal t.strftime('%Y%m%d%H%M%S')
107
107
  end
108
108
 
109
109
  cspecify "should support generic file type", [:do], [:odbc, :mssql], [:mysql2], [:tinytds] do
110
110
  ds = create_items_table_with_column(:name, File)
111
111
  ds.insert(:name =>Sequel.blob("a\0"*300))
112
- ds.all.should == [{:name=>Sequel.blob("a\0"*300)}]
113
- ds.first[:name].should be_a_kind_of(::Sequel::SQL::Blob)
112
+ ds.all.must_equal [{:name=>Sequel.blob("a\0"*300)}]
113
+ ds.first[:name].must_be_kind_of(::Sequel::SQL::Blob)
114
114
  end
115
115
 
116
116
  cspecify "should support generic boolean type", [:do, :sqlite], [:jdbc, :sqlite], [:jdbc, :db2], :oracle do
117
117
  ds = create_items_table_with_column(:number, TrueClass)
118
118
  ds.insert(:number => true)
119
- ds.all.should == [{:number=>true}]
119
+ ds.all.must_equal [{:number=>true}]
120
120
  ds = create_items_table_with_column(:number, FalseClass)
121
121
  ds.insert(:number => true)
122
- ds.all.should == [{:number=>true}]
122
+ ds.all.must_equal [{:number=>true}]
123
123
  end
124
124
 
125
125
  cspecify "should support generic boolean type with defaults", [:do, :sqlite], [:jdbc, :sqlite], [:jdbc, :db2], :oracle do
126
126
  ds = create_items_table_with_column(:number, TrueClass, :default=>true)
127
127
  ds.insert
128
- ds.all.should == [{:number=>true}]
128
+ ds.all.must_equal [{:number=>true}]
129
129
  ds = create_items_table_with_column(:number, FalseClass, :default=>false)
130
130
  ds.insert
131
- ds.all.should == [{:number=>false}]
131
+ ds.all.must_equal [{:number=>false}]
132
132
  end
133
133
  end
@@ -11,14 +11,14 @@ describe Sequel::Model::Associations::AssociationReflection, "#associated_class"
11
11
 
12
12
  it "should use the :class value if present" do
13
13
  @c.many_to_one :c, :class=>ParParent
14
- @c.association_reflection(:c).keys.should include(:class)
15
- @c.association_reflection(:c).associated_class.should == ParParent
14
+ @c.association_reflection(:c).keys.must_include(:class)
15
+ @c.association_reflection(:c).associated_class.must_equal ParParent
16
16
  end
17
17
 
18
18
  it "should figure out the class if the :class value is not present" do
19
19
  @c.many_to_one :c, :class=>'ParParent'
20
- @c.association_reflection(:c).keys.should_not include(:class)
21
- @c.association_reflection(:c).associated_class.should == ParParent
20
+ @c.association_reflection(:c).keys.wont_include(:class)
21
+ @c.association_reflection(:c).associated_class.must_equal ParParent
22
22
  end
23
23
  end
24
24
 
@@ -33,14 +33,23 @@ describe Sequel::Model::Associations::AssociationReflection, "#primary_key" do
33
33
 
34
34
  it "should use the :primary_key value if present" do
35
35
  @c.many_to_one :c, :class=>ParParent, :primary_key=>:blah__blah
36
- @c.association_reflection(:c).keys.should include(:primary_key)
37
- @c.association_reflection(:c).primary_key.should == :blah__blah
36
+ @c.association_reflection(:c).keys.must_include(:primary_key)
37
+ @c.association_reflection(:c).primary_key.must_equal :blah__blah
38
38
  end
39
39
 
40
40
  it "should use the associated table's primary key if :primary_key is not present" do
41
41
  @c.many_to_one :c, :class=>'ParParent'
42
- @c.association_reflection(:c).keys.should_not include(:primary_key)
43
- @c.association_reflection(:c).primary_key.should == :id
42
+ @c.association_reflection(:c).keys.wont_include(:primary_key)
43
+ @c.association_reflection(:c).primary_key.must_equal :id
44
+ end
45
+ end
46
+
47
+ describe Sequel::Model::Associations::AssociationReflection, "#reciprocal_type" do
48
+ it "should include a specific type if only one matches" do
49
+ c = Class.new(Sequel::Model(:a))
50
+ c.one_to_many :cs, :class=>c, :key=>:c_id
51
+ c.many_to_one :c, :class=>c, :key=>:c_id
52
+ c.association_reflection(:c).send(:reciprocal_type).must_equal :one_to_many
44
53
  end
45
54
  end
46
55
 
@@ -60,15 +69,15 @@ describe Sequel::Model::Associations::AssociationReflection, "#reciprocal" do
60
69
  @c = Class.new(Sequel::Model(:foo))
61
70
  @d = Class.new(Sequel::Model(:foo))
62
71
  @c.many_to_one :c, :class=>@d, :reciprocal=>:xx
63
- @c.association_reflection(:c).keys.should include(:reciprocal)
64
- @c.association_reflection(:c).reciprocal.should == :xx
72
+ @c.association_reflection(:c).keys.must_include(:reciprocal)
73
+ @c.association_reflection(:c).reciprocal.must_equal :xx
65
74
  end
66
75
 
67
76
  it "should not raise an error if some reciprocal associations have invalid associated classes" do
68
77
  @c = Class.new(Sequel::Model(:foo))
69
78
  @c.one_to_many :sadfakloasdfioas
70
79
  @c.many_to_one :c, :class=>@c
71
- proc{@c.association_reflection(:c).reciprocal}.should_not raise_error
80
+ @c.association_reflection(:c).reciprocal
72
81
  end
73
82
 
74
83
  it "should require the associated class is the current class to be a reciprocal" do
@@ -77,16 +86,16 @@ describe Sequel::Model::Associations::AssociationReflection, "#reciprocal" do
77
86
  ParParentTwo.one_to_many :par_parents, :key=>:blah
78
87
  ParParentThree.one_to_many :par_parents, :key=>:blah
79
88
 
80
- ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_two
81
- ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_three
89
+ ParParentTwo.association_reflection(:par_parents).reciprocal.must_equal :par_parent_two
90
+ ParParentThree.association_reflection(:par_parents).reciprocal.must_equal :par_parent_three
82
91
 
83
92
  ParParent.many_to_many :par_parent_twos, :left_key=>:l, :right_key=>:r, :join_table=>:jt
84
93
  ParParent.many_to_many :par_parent_threes, :left_key=>:l, :right_key=>:r, :join_table=>:jt
85
94
  ParParentTwo.many_to_many :par_parents, :right_key=>:l, :left_key=>:r, :join_table=>:jt
86
95
  ParParentThree.many_to_many :par_parents, :right_key=>:l, :left_key=>:r, :join_table=>:jt
87
96
 
88
- ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_twos
89
- ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_threes
97
+ ParParentTwo.association_reflection(:par_parents).reciprocal.must_equal :par_parent_twos
98
+ ParParentThree.association_reflection(:par_parents).reciprocal.must_equal :par_parent_threes
90
99
  end
91
100
 
92
101
  it "should handle composite keys" do
@@ -95,16 +104,16 @@ describe Sequel::Model::Associations::AssociationReflection, "#reciprocal" do
95
104
  ParParentTwo.one_to_many :par_parents, :primary_key=>[:c, :b], :key=>[:a, :b]
96
105
  ParParentThree.one_to_many :par_parents, :primary_key=>[:c, :b], :key=>[:d, :e]
97
106
 
98
- ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_two
99
- ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_three
107
+ ParParentTwo.association_reflection(:par_parents).reciprocal.must_equal :par_parent_two
108
+ ParParentThree.association_reflection(:par_parents).reciprocal.must_equal :par_parent_three
100
109
 
101
110
  ParParent.many_to_many :par_parent_twos, :left_key=>[:l1, :l2], :right_key=>[:r1, :r2], :left_primary_key=>[:pl1, :pl2], :right_primary_key=>[:pr1, :pr2], :join_table=>:jt
102
111
  ParParent.many_to_many :par_parent_threes, :right_key=>[:l1, :l2], :left_key=>[:r1, :r2], :left_primary_key=>[:pl1, :pl2], :right_primary_key=>[:pr1, :pr2], :join_table=>:jt
103
112
  ParParentTwo.many_to_many :par_parents, :right_key=>[:l1, :l2], :left_key=>[:r1, :r2], :right_primary_key=>[:pl1, :pl2], :left_primary_key=>[:pr1, :pr2], :join_table=>:jt
104
113
  ParParentThree.many_to_many :par_parents, :left_key=>[:l1, :l2], :right_key=>[:r1, :r2], :right_primary_key=>[:pl1, :pl2], :left_primary_key=>[:pr1, :pr2], :join_table=>:jt
105
114
 
106
- ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_twos
107
- ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_threes
115
+ ParParentTwo.association_reflection(:par_parents).reciprocal.must_equal :par_parent_twos
116
+ ParParentThree.association_reflection(:par_parents).reciprocal.must_equal :par_parent_threes
108
117
  end
109
118
 
110
119
  it "should figure out the reciprocal if the :reciprocal value is not present" do
@@ -113,14 +122,14 @@ describe Sequel::Model::Associations::AssociationReflection, "#reciprocal" do
113
122
  ParParent.many_to_many :par_parent_threes
114
123
  ParParentThree.many_to_many :par_parents
115
124
 
116
- ParParent.association_reflection(:par_parent_two).keys.should_not include(:reciprocal)
117
- ParParent.association_reflection(:par_parent_two).reciprocal.should == :par_parents
118
- ParParentTwo.association_reflection(:par_parents).keys.should_not include(:reciprocal)
119
- ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_two
120
- ParParent.association_reflection(:par_parent_threes).keys.should_not include(:reciprocal)
121
- ParParent.association_reflection(:par_parent_threes).reciprocal.should == :par_parents
122
- ParParentThree.association_reflection(:par_parents).keys.should_not include(:reciprocal)
123
- ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_threes
125
+ ParParent.association_reflection(:par_parent_two).keys.wont_include(:reciprocal)
126
+ ParParent.association_reflection(:par_parent_two).reciprocal.must_equal :par_parents
127
+ ParParentTwo.association_reflection(:par_parents).keys.wont_include(:reciprocal)
128
+ ParParentTwo.association_reflection(:par_parents).reciprocal.must_equal :par_parent_two
129
+ ParParent.association_reflection(:par_parent_threes).keys.wont_include(:reciprocal)
130
+ ParParent.association_reflection(:par_parent_threes).reciprocal.must_equal :par_parents
131
+ ParParentThree.association_reflection(:par_parents).keys.wont_include(:reciprocal)
132
+ ParParentThree.association_reflection(:par_parents).reciprocal.must_equal :par_parent_threes
124
133
  end
125
134
 
126
135
  it "should handle ambiguous reciprocals where only one doesn't have conditions/blocks" do
@@ -133,8 +142,8 @@ describe Sequel::Model::Associations::AssociationReflection, "#reciprocal" do
133
142
  end
134
143
  ParParentThree.many_to_many :par_parents
135
144
 
136
- ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_two
137
- ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_threes
145
+ ParParentTwo.association_reflection(:par_parents).reciprocal.must_equal :par_parent_two
146
+ ParParentThree.association_reflection(:par_parents).reciprocal.must_equal :par_parent_threes
138
147
  end
139
148
 
140
149
  it "should handle ambiguous reciprocals where only one has matching primary keys" do
@@ -147,14 +156,14 @@ describe Sequel::Model::Associations::AssociationReflection, "#reciprocal" do
147
156
  ParParent.many_to_many :par_parent_threes3, :clone=>:par_parent_threes, :left_primary_key=>:foo
148
157
  ParParentThree.many_to_many :par_parents
149
158
 
150
- ParParent.association_reflection(:par_parent_two).reciprocal.should == :par_parents
151
- ParParent.association_reflection(:par_parent_two2).reciprocal.should == :par_parents2
152
- ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_two
153
- ParParentTwo.association_reflection(:par_parents2).reciprocal.should == :par_parent_two2
154
- ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_threes
159
+ ParParent.association_reflection(:par_parent_two).reciprocal.must_equal :par_parents
160
+ ParParent.association_reflection(:par_parent_two2).reciprocal.must_equal :par_parents2
161
+ ParParentTwo.association_reflection(:par_parents).reciprocal.must_equal :par_parent_two
162
+ ParParentTwo.association_reflection(:par_parents2).reciprocal.must_equal :par_parent_two2
163
+ ParParentThree.association_reflection(:par_parents).reciprocal.must_equal :par_parent_threes
155
164
  end
156
165
 
157
- specify "should handle reciprocals where current association has conditions/block" do
166
+ it "should handle reciprocals where current association has conditions/block" do
158
167
  ParParent.many_to_one :par_parent_two, :conditions=>{:id=>:id}
159
168
  ParParentTwo.one_to_many :par_parents
160
169
  ParParent.many_to_many :par_parent_threes do |ds|
@@ -162,8 +171,8 @@ describe Sequel::Model::Associations::AssociationReflection, "#reciprocal" do
162
171
  end
163
172
  ParParentThree.many_to_many :par_parents
164
173
 
165
- ParParent.association_reflection(:par_parent_two).reciprocal.should == :par_parents
166
- ParParent.association_reflection(:par_parent_threes).reciprocal.should == :par_parents
174
+ ParParent.association_reflection(:par_parent_two).reciprocal.must_equal :par_parents
175
+ ParParent.association_reflection(:par_parent_threes).reciprocal.must_equal :par_parents
167
176
  end
168
177
  end
169
178
 
@@ -178,27 +187,27 @@ describe Sequel::Model::Associations::AssociationReflection, "#select" do
178
187
 
179
188
  it "should use the :select value if present" do
180
189
  @c.many_to_one :c, :class=>ParParent, :select=>[:par_parents__id]
181
- @c.association_reflection(:c).keys.should include(:select)
182
- @c.association_reflection(:c).select.should == [:par_parents__id]
190
+ @c.association_reflection(:c).keys.must_include(:select)
191
+ @c.association_reflection(:c).select.must_equal [:par_parents__id]
183
192
  end
184
193
  it "should be the associated_table.* if :select is not present for a many_to_many associaiton" do
185
194
  @c.many_to_many :cs, :class=>'ParParent'
186
- @c.association_reflection(:cs).keys.should_not include(:select)
187
- @c.association_reflection(:cs).select.should == Sequel::SQL::ColumnAll.new(:par_parents)
195
+ @c.association_reflection(:cs).keys.wont_include(:select)
196
+ @c.association_reflection(:cs).select.must_equal Sequel::SQL::ColumnAll.new(:par_parents)
188
197
  end
189
198
  it "should be blank if :select is not present for a many_to_one and one_to_many associaiton" do
190
199
  @c.one_to_many :cs, :class=>'ParParent'
191
- @c.association_reflection(:cs).keys.should_not include(:select)
192
- @c.association_reflection(:cs).select.should == nil
200
+ @c.association_reflection(:cs).keys.wont_include(:select)
201
+ @c.association_reflection(:cs).select.must_equal nil
193
202
  @c.many_to_one :c, :class=>'ParParent'
194
- @c.association_reflection(:c).keys.should_not include(:select)
195
- @c.association_reflection(:c).select.should == nil
203
+ @c.association_reflection(:c).keys.wont_include(:select)
204
+ @c.association_reflection(:c).select.must_equal nil
196
205
  end
197
206
  end
198
207
 
199
208
  describe Sequel::Model::Associations::AssociationReflection, "#can_have_associated_objects?" do
200
209
  it "should be true for any given object (for backward compatibility)" do
201
- Sequel::Model::Associations::AssociationReflection.new.can_have_associated_objects?(Object.new).should == true
210
+ Sequel::Model::Associations::AssociationReflection.new.can_have_associated_objects?(Object.new).must_equal true
202
211
  end
203
212
  end
204
213
 
@@ -213,27 +222,27 @@ describe Sequel::Model::Associations::AssociationReflection, "#associated_object
213
222
 
214
223
  it "should use the primary keys for a many_to_one association" do
215
224
  @c.many_to_one :c, :class=>ParParent
216
- @c.association_reflection(:c).associated_object_keys.should == [:id]
225
+ @c.association_reflection(:c).associated_object_keys.must_equal [:id]
217
226
  @c.many_to_one :c, :class=>ParParent, :primary_key=>:d_id
218
- @c.association_reflection(:c).associated_object_keys.should == [:d_id]
227
+ @c.association_reflection(:c).associated_object_keys.must_equal [:d_id]
219
228
  @c.many_to_one :c, :class=>ParParent, :key=>[:c_id1, :c_id2], :primary_key=>[:id1, :id2]
220
- @c.association_reflection(:c).associated_object_keys.should == [:id1, :id2]
229
+ @c.association_reflection(:c).associated_object_keys.must_equal [:id1, :id2]
221
230
  end
222
231
  it "should use the keys for a one_to_many association" do
223
232
  ParParent.one_to_many :cs, :class=>ParParent
224
- ParParent.association_reflection(:cs).associated_object_keys.should == [:par_parent_id]
233
+ ParParent.association_reflection(:cs).associated_object_keys.must_equal [:par_parent_id]
225
234
  @c.one_to_many :cs, :class=>ParParent, :key=>:d_id
226
- @c.association_reflection(:cs).associated_object_keys.should == [:d_id]
235
+ @c.association_reflection(:cs).associated_object_keys.must_equal [:d_id]
227
236
  @c.one_to_many :cs, :class=>ParParent, :key=>[:c_id1, :c_id2], :primary_key=>[:id1, :id2]
228
- @c.association_reflection(:cs).associated_object_keys.should == [:c_id1, :c_id2]
237
+ @c.association_reflection(:cs).associated_object_keys.must_equal [:c_id1, :c_id2]
229
238
  end
230
239
  it "should use the right primary keys for a many_to_many association" do
231
240
  @c.many_to_many :cs, :class=>ParParent
232
- @c.association_reflection(:cs).associated_object_keys.should == [:id]
241
+ @c.association_reflection(:cs).associated_object_keys.must_equal [:id]
233
242
  @c.many_to_many :cs, :class=>ParParent, :right_primary_key=>:d_id
234
- @c.association_reflection(:cs).associated_object_keys.should == [:d_id]
243
+ @c.association_reflection(:cs).associated_object_keys.must_equal [:d_id]
235
244
  @c.many_to_many :cs, :class=>ParParent, :right_key=>[:c_id1, :c_id2], :right_primary_key=>[:id1, :id2]
236
- @c.association_reflection(:cs).associated_object_keys.should == [:id1, :id2]
245
+ @c.association_reflection(:cs).associated_object_keys.must_equal [:id1, :id2]
237
246
  end
238
247
  end
239
248
 
@@ -245,27 +254,27 @@ describe Sequel::Model::Associations::AssociationReflection do
245
254
 
246
255
  it "#eager_loading_predicate_key should be an alias of predicate_key for backwards compatibility" do
247
256
  @c.one_to_many :cs, :class=>@c
248
- @c.dataset.literal(@c.association_reflection(:cs).eager_loading_predicate_key).should == 'foo.c_id'
257
+ @c.dataset.literal(@c.association_reflection(:cs).eager_loading_predicate_key).must_equal 'foo.c_id'
249
258
  end
250
259
 
251
260
  it "one_to_many #qualified_primary_key should be a qualified version of the primary key" do
252
261
  @c.one_to_many :cs, :class=>@c
253
- @c.dataset.literal(@c.association_reflection(:cs).qualified_primary_key).should == 'foo.id'
262
+ @c.dataset.literal(@c.association_reflection(:cs).qualified_primary_key).must_equal 'foo.id'
254
263
  end
255
264
 
256
265
  it "many_to_many #associated_key_column should be the left key" do
257
266
  @c.many_to_many :cs, :class=>@c
258
- @c.association_reflection(:cs).associated_key_column.should == :c_id
267
+ @c.association_reflection(:cs).associated_key_column.must_equal :c_id
259
268
  end
260
269
 
261
270
  it "many_to_many #qualified_right_key should be a qualified version of the primary key" do
262
271
  @c.many_to_many :cs, :class=>@c, :right_key=>:c2_id
263
- @c.dataset.literal(@c.association_reflection(:cs).qualified_right_key).should == 'cs_cs.c2_id'
272
+ @c.dataset.literal(@c.association_reflection(:cs).qualified_right_key).must_equal 'cs_cs.c2_id'
264
273
  end
265
274
 
266
275
  it "many_to_many #qualified_right_primary_key should be a qualified version of the primary key" do
267
276
  @c.many_to_many :cs, :class=>@c
268
- @c.dataset.literal(@c.association_reflection(:cs).qualified_right_primary_key).should == 'foo.id'
277
+ @c.dataset.literal(@c.association_reflection(:cs).qualified_right_primary_key).must_equal 'foo.id'
269
278
  end
270
279
  end
271
280
 
@@ -276,16 +285,16 @@ describe Sequel::Model::Associations::AssociationReflection, "#remove_before_des
276
285
 
277
286
  it "should be true for many_to_one and many_to_many associations" do
278
287
  @c.many_to_one :c, :class=>@c
279
- @c.association_reflection(:c).remove_before_destroy?.should == true
288
+ @c.association_reflection(:c).remove_before_destroy?.must_equal true
280
289
  @c.many_to_many :cs, :class=>@c
281
- @c.association_reflection(:cs).remove_before_destroy?.should == true
290
+ @c.association_reflection(:cs).remove_before_destroy?.must_equal true
282
291
  end
283
292
 
284
293
  it "should be false for one_to_one and one_to_many associations" do
285
294
  @c.one_to_one :c, :class=>@c
286
- @c.association_reflection(:c).remove_before_destroy?.should == false
295
+ @c.association_reflection(:c).remove_before_destroy?.must_equal false
287
296
  @c.one_to_many :cs, :class=>@c
288
- @c.association_reflection(:cs).remove_before_destroy?.should == false
297
+ @c.association_reflection(:cs).remove_before_destroy?.must_equal false
289
298
  end
290
299
  end
291
300
 
@@ -300,110 +309,110 @@ describe Sequel::Model::Associations::AssociationReflection, "#filter_by_associa
300
309
 
301
310
  it "should be nil by default for *_one associations" do
302
311
  @c.many_to_one :c, :class=>@c
303
- @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).should be_nil
312
+ @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal nil
304
313
  @c.one_to_one :c, :class=>@c
305
- @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).should be_nil
314
+ @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal nil
306
315
  @c.one_through_one :c, :class=>@c
307
- @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).should be_nil
316
+ @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal nil
308
317
  end
309
318
 
310
319
  it "should be :correlated_subquery by default for one_to_many and one_to_one with :order associations" do
311
320
  @c.one_to_one :c, :class=>@c, :order=>:a
312
- @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).should == :correlated_subquery
321
+ @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal :correlated_subquery
313
322
  @c.one_to_many :cs, :class=>@c, :limit=>1
314
- @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :correlated_subquery
323
+ @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :correlated_subquery
315
324
  end
316
325
 
317
326
  it "should be :ruby by default for many_to_many and one_through_one with :order associations" do
318
327
  @c.one_through_one :c, :class=>@c, :order=>:a
319
- @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).should == :ruby
328
+ @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal :ruby
320
329
  @c.many_to_many :cs, :class=>@c, :limit=>1
321
- @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :ruby
330
+ @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :ruby
322
331
  end
323
332
 
324
333
  it "should be nil for many_to_one associations even if :eager_limit_strategy or :filter_limit_strategy is used" do
325
334
  @c.many_to_one :c, :class=>@c, :eager_limit_strategy=>true
326
- @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).should be_nil
335
+ @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal nil
327
336
  @c.many_to_one :c, :class=>@c, :eager_limit_strategy=>:distinct_on
328
- @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).should be_nil
337
+ @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal nil
329
338
  @c.many_to_one :c, :class=>@c, :filter_limit_strategy=>true
330
- @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).should be_nil
339
+ @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal nil
331
340
  end
332
341
 
333
342
  it "should be a symbol for other associations if given a symbol" do
334
343
  @c.one_to_one :c, :class=>@c, :eager_limit_strategy=>:distinct_on
335
- @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).should == :distinct_on
344
+ @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal :distinct_on
336
345
  @c.one_to_many :cs, :class=>@c, :eager_limit_strategy=>:window_function, :limit=>1
337
- @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :window_function
346
+ @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :window_function
338
347
  end
339
348
 
340
349
  it "should use :distinct_on for one_to_one associations if picking and the association dataset supports ordered distinct on" do
341
350
  def (@c.dataset).supports_ordered_distinct_on?() true end
342
351
  @c.one_to_one :c, :class=>@c, :eager_limit_strategy=>true
343
- @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).should == :distinct_on
352
+ @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal :distinct_on
344
353
  end
345
354
 
346
355
  it "should use :window_function for associations if picking and the association dataset supports window functions" do
347
356
  def (@c.dataset).supports_window_functions?() true end
348
357
  @c.one_to_one :c, :class=>@c, :eager_limit_strategy=>true
349
- @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).should == :window_function
358
+ @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal :window_function
350
359
  @c.one_to_many :cs, :class=>@c, :eager_limit_strategy=>true, :limit=>1
351
- @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :window_function
360
+ @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :window_function
352
361
  @c.many_to_many :cs, :class=>@c, :eager_limit_strategy=>true, :limit=>1
353
- @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :window_function
362
+ @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :window_function
354
363
  end
355
364
 
356
365
  it "should use :ruby for one_to_many associations if the database doesn't support limits in subqueries" do
357
366
  def (@c.dataset).supports_limits_in_correlated_subqueries?; false; end
358
367
  @c.one_to_many :cs, :class=>@c, :eager_limit_strategy=>true, :limit=>1
359
- @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :ruby
368
+ @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :ruby
360
369
  end
361
370
 
362
371
  it "should use :ruby for one_to_many associations if offset doesn't work in correlated subqueries and an offset is used" do
363
372
  def (@c.dataset).supports_offsets_in_correlated_subqueries?; false; end
364
373
  @c.one_to_many :cs, :class=>@c, :eager_limit_strategy=>true, :limit=>1
365
- @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :correlated_subquery
374
+ @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :correlated_subquery
366
375
  @c.one_to_many :cs, :class=>@c, :eager_limit_strategy=>true, :limit=>[1, 1]
367
- @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :ruby
376
+ @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :ruby
368
377
  end
369
378
 
370
379
  it "should use :ruby for one_to_many associations if composite primary key is used and database does not multiple columns in IN" do
371
380
  def (@c.dataset).supports_multiple_column_in?; false; end
372
381
  @c.set_primary_key [:id, :id2]
373
382
  @c.one_to_many :cs, :class=>@c, :eager_limit_strategy=>true, :limit=>1, :key=>[:id, :id2]
374
- @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :ruby
383
+ @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :ruby
375
384
  end
376
385
 
377
386
  it "should use :ruby for many_to_many associations if picking and the association dataset doesn't window functions" do
378
387
  @c.many_to_many :cs, :class=>@c, :eager_limit_strategy=>true, :limit=>1
379
- @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :ruby
388
+ @c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :ruby
380
389
  end
381
390
 
382
391
  it "should respect Model.default_eager_limit_strategy to *_many associations" do
383
392
  Sequel::Model.default_eager_limit_strategy = :window_function
384
- Sequel::Model.default_eager_limit_strategy.should == :window_function
393
+ Sequel::Model.default_eager_limit_strategy.must_equal :window_function
385
394
  c = Class.new(Sequel::Model)
386
395
  c.dataset = :a
387
- c.default_eager_limit_strategy.should == :window_function
396
+ c.default_eager_limit_strategy.must_equal :window_function
388
397
  c.one_to_many :cs, :class=>c, :limit=>1
389
- c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :window_function
398
+ c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :window_function
390
399
  c.many_to_many :cs, :class=>c, :limit=>1
391
- c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :window_function
400
+ c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :window_function
392
401
 
393
402
  Sequel::Model.default_eager_limit_strategy = true
394
403
  c = Class.new(Sequel::Model)
395
404
  c.dataset = :a
396
405
  c.one_to_many :cs, :class=>c, :limit=>1
397
- c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :correlated_subquery
406
+ c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :correlated_subquery
398
407
  def (c.dataset).supports_window_functions?() true end
399
408
  c.many_to_many :cs, :class=>c, :limit=>1
400
- c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).should == :window_function
409
+ c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :window_function
401
410
  end
402
411
 
403
412
  it "should ignore Model.default_eager_limit_strategy for one_to_one associations" do
404
413
  @c.default_eager_limit_strategy = :window_function
405
414
  @c.one_to_one :c, :class=>@c
406
- @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).should be_nil
415
+ @c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal nil
407
416
  end
408
417
  end
409
418
 
@@ -411,7 +420,7 @@ describe Sequel::Model::Associations::AssociationReflection, "#apply_eager_datas
411
420
  it "should apply the eager block as well as the association options to the dataset" do
412
421
  @c = Class.new(Sequel::Model(:foo))
413
422
  @c.one_to_many :cs, :class=>@c, :select=>:a, :order=>:b do |ds| ds.where(:c) end
414
- @c.association_reflection(:cs).apply_eager_dataset_changes(@c.dataset).sql.should == 'SELECT a FROM foo WHERE c ORDER BY b'
423
+ @c.association_reflection(:cs).apply_eager_dataset_changes(@c.dataset).sql.must_equal 'SELECT a FROM foo WHERE c ORDER BY b'
415
424
  end
416
425
  end
417
426
 
@@ -425,55 +434,55 @@ describe Sequel::Model, " association reflection methods" do
425
434
  end
426
435
 
427
436
  it "#all_association_reflections should include all association reflection hashes" do
428
- @c1.all_association_reflections.should == []
437
+ @c1.all_association_reflections.must_equal []
429
438
 
430
439
  @c1.associate :many_to_one, :parent, :class => @c1
431
- @c1.all_association_reflections.collect{|v| v[:name]}.should == [:parent]
432
- @c1.all_association_reflections.collect{|v| v[:type]}.should == [:many_to_one]
433
- @c1.all_association_reflections.collect{|v| v[:class]}.should == [@c1]
440
+ @c1.all_association_reflections.collect{|v| v[:name]}.must_equal [:parent]
441
+ @c1.all_association_reflections.collect{|v| v[:type]}.must_equal [:many_to_one]
442
+ @c1.all_association_reflections.collect{|v| v[:class]}.must_equal [@c1]
434
443
 
435
444
  @c1.associate :one_to_many, :children, :class => @c1
436
445
  @c1.all_association_reflections.sort_by{|x|x[:name].to_s}
437
- @c1.all_association_reflections.sort_by{|x|x[:name].to_s}.collect{|v| v[:name]}.should == [:children, :parent]
438
- @c1.all_association_reflections.sort_by{|x|x[:name].to_s}.collect{|v| v[:type]}.should == [:one_to_many, :many_to_one]
439
- @c1.all_association_reflections.sort_by{|x|x[:name].to_s}.collect{|v| v[:class]}.should == [@c1, @c1]
446
+ @c1.all_association_reflections.sort_by{|x|x[:name].to_s}.collect{|v| v[:name]}.must_equal [:children, :parent]
447
+ @c1.all_association_reflections.sort_by{|x|x[:name].to_s}.collect{|v| v[:type]}.must_equal [:one_to_many, :many_to_one]
448
+ @c1.all_association_reflections.sort_by{|x|x[:name].to_s}.collect{|v| v[:class]}.must_equal [@c1, @c1]
440
449
  end
441
450
 
442
451
  it "#association_reflection should return nil for nonexistent association" do
443
- @c1.association_reflection(:blah).should == nil
452
+ @c1.association_reflection(:blah).must_equal nil
444
453
  end
445
454
 
446
455
  it "#association_reflection should return association reflection hash if association exists" do
447
456
  @c1.associate :many_to_one, :parent, :class => @c1
448
- @c1.association_reflection(:parent).should be_a_kind_of(Sequel::Model::Associations::AssociationReflection)
449
- @c1.association_reflection(:parent)[:name].should == :parent
450
- @c1.association_reflection(:parent)[:type].should == :many_to_one
451
- @c1.association_reflection(:parent)[:class].should == @c1
457
+ @c1.association_reflection(:parent).must_be_kind_of(Sequel::Model::Associations::AssociationReflection)
458
+ @c1.association_reflection(:parent)[:name].must_equal :parent
459
+ @c1.association_reflection(:parent)[:type].must_equal :many_to_one
460
+ @c1.association_reflection(:parent)[:class].must_equal @c1
452
461
 
453
462
  @c1.associate :one_to_many, :children, :class => @c1
454
- @c1.association_reflection(:children).should be_a_kind_of(Sequel::Model::Associations::AssociationReflection)
455
- @c1.association_reflection(:children)[:name].should == :children
456
- @c1.association_reflection(:children)[:type].should == :one_to_many
457
- @c1.association_reflection(:children)[:class].should == @c1
463
+ @c1.association_reflection(:children).must_be_kind_of(Sequel::Model::Associations::AssociationReflection)
464
+ @c1.association_reflection(:children)[:name].must_equal :children
465
+ @c1.association_reflection(:children)[:type].must_equal :one_to_many
466
+ @c1.association_reflection(:children)[:class].must_equal @c1
458
467
  end
459
468
 
460
469
  it "#associations should include all association names" do
461
- @c1.associations.should == []
470
+ @c1.associations.must_equal []
462
471
  @c1.associate :many_to_one, :parent, :class => @c1
463
- @c1.associations.should == [:parent]
472
+ @c1.associations.must_equal [:parent]
464
473
  @c1.associate :one_to_many, :children, :class => @c1
465
- @c1.associations.sort_by{|x|x.to_s}.should == [:children, :parent]
474
+ @c1.associations.sort_by{|x|x.to_s}.must_equal [:children, :parent]
466
475
  end
467
476
 
468
477
  it "association reflections should be copied upon subclasing" do
469
478
  @c1.associate :many_to_one, :parent, :class => @c1
470
479
  c = Class.new(@c1)
471
- @c1.associations.should == [:parent]
472
- c.associations.should == [:parent]
480
+ @c1.associations.must_equal [:parent]
481
+ c.associations.must_equal [:parent]
473
482
  c.associate :many_to_one, :parent2, :class => @c1
474
- @c1.associations.should == [:parent]
475
- c.associations.sort_by{|x| x.to_s}.should == [:parent, :parent2]
476
- c.instance_methods.map{|x| x.to_s}.should include('parent')
483
+ @c1.associations.must_equal [:parent]
484
+ c.associations.sort_by{|x| x.to_s}.must_equal [:parent, :parent2]
485
+ c.instance_methods.map{|x| x.to_s}.must_include('parent')
477
486
  end
478
487
  end
479
488
 
@@ -490,11 +499,11 @@ describe Sequel::Model::Associations::AssociationReflection, "with caching disab
490
499
  class ::ParParent < Sequel::Model; end
491
500
  c = ParParent
492
501
  @c.many_to_one :c, :class=>:ParParent
493
- @c.association_reflection(:c).associated_class.should == c
502
+ @c.association_reflection(:c).associated_class.must_equal c
494
503
  Object.send(:remove_const, :ParParent)
495
504
  class ::ParParent < Sequel::Model; end
496
505
  c = ParParent
497
- @c.association_reflection(:c).associated_class.should == c
506
+ @c.association_reflection(:c).associated_class.must_equal c
498
507
  ensure
499
508
  Object.send(:remove_const, :ParParent)
500
509
  end
@@ -506,11 +515,11 @@ describe Sequel::Model::Associations::AssociationReflection, "with caching disab
506
515
  [[opts[:reload] ? :reload : :id, {}]]
507
516
  end
508
517
  @c.dataset = @db[:items]
509
- @c.columns.should == [:reload]
518
+ @c.columns.must_equal [:reload]
510
519
 
511
520
  @c.cache_associations = true
512
521
  @c.dataset = @db[:items]
513
- @c.columns.should == [:id]
522
+ @c.columns.must_equal [:id]
514
523
  end
515
524
  end
516
525