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
@@ -30,8 +30,8 @@ describe "Sequel::Plugins::JsonSerializer" do
30
30
  end
31
31
 
32
32
  it "should round trip successfully" do
33
- Artist.from_json(@artist.to_json).should == @artist
34
- Album.from_json(@album.to_json).should == @album
33
+ Artist.from_json(@artist.to_json).must_equal @artist
34
+ Album.from_json(@album.to_json).must_equal @album
35
35
  end
36
36
 
37
37
  it "should handle ruby objects in values" do
@@ -40,31 +40,31 @@ describe "Sequel::Plugins::JsonSerializer" do
40
40
  super(Date.parse(v))
41
41
  end
42
42
  end
43
- Artist.from_json(Artist.load(:name=>Date.today).to_json).should == Artist.load(:name=>Date.today)
43
+ Artist.from_json(Artist.load(:name=>Date.today).to_json).must_equal Artist.load(:name=>Date.today)
44
44
  end
45
45
 
46
46
  it "should handle the :only option" do
47
- Artist.from_json(@artist.to_json(:only=>:name)).should == Artist.load(:name=>@artist.name)
48
- Album.from_json(@album.to_json(:only=>[:id, :name])).should == Album.load(:id=>@album.id, :name=>@album.name)
47
+ Artist.from_json(@artist.to_json(:only=>:name)).must_equal Artist.load(:name=>@artist.name)
48
+ Album.from_json(@album.to_json(:only=>[:id, :name])).must_equal Album.load(:id=>@album.id, :name=>@album.name)
49
49
  end
50
50
 
51
51
  it "should handle the :except option" do
52
- Artist.from_json(@artist.to_json(:except=>:id)).should == Artist.load(:name=>@artist.name)
53
- Album.from_json(@album.to_json(:except=>[:id, :artist_id])).should == Album.load(:name=>@album.name)
52
+ Artist.from_json(@artist.to_json(:except=>:id)).must_equal Artist.load(:name=>@artist.name)
53
+ Album.from_json(@album.to_json(:except=>[:id, :artist_id])).must_equal Album.load(:name=>@album.name)
54
54
  end
55
55
 
56
56
  it "should handle the :include option for associations" do
57
- Artist.from_json(@artist.to_json(:include=>:albums), :associations=>:albums).albums.should == [@album]
58
- Album.from_json(@album.to_json(:include=>:artist), :associations=>:artist).artist.should == @artist
57
+ Artist.from_json(@artist.to_json(:include=>:albums), :associations=>:albums).albums.must_equal [@album]
58
+ Album.from_json(@album.to_json(:include=>:artist), :associations=>:artist).artist.must_equal @artist
59
59
  end
60
60
 
61
61
  it "should raise an error if attempting to parse json when providing array to non-array association or vice-versa" do
62
- proc{Artist.from_json('{"albums":{"id":1,"name":"RF","artist_id":2,"json_class":"Album"},"id":2,"name":"YJM"}', :associations=>:albums)}.should raise_error(Sequel::Error)
63
- proc{Album.from_json('{"artist":[{"id":2,"name":"YJM","json_class":"Artist"}],"id":1,"name":"RF","artist_id":2}', :associations=>:artist)}.should raise_error(Sequel::Error)
62
+ proc{Artist.from_json('{"albums":{"id":1,"name":"RF","artist_id":2,"json_class":"Album"},"id":2,"name":"YJM"}', :associations=>:albums)}.must_raise(Sequel::Error)
63
+ proc{Album.from_json('{"artist":[{"id":2,"name":"YJM","json_class":"Artist"}],"id":1,"name":"RF","artist_id":2}', :associations=>:artist)}.must_raise(Sequel::Error)
64
64
  end
65
65
 
66
66
  it "should raise an error if attempting to parse an array containing non-hashes" do
67
- proc{Artist.from_json('[{"id":2,"name":"YJM","json_class":"Artist"}, 2]')}.should raise_error(Sequel::Error)
67
+ proc{Artist.from_json('[{"id":2,"name":"YJM","json_class":"Artist"}, 2]')}.must_raise(Sequel::Error)
68
68
  end
69
69
 
70
70
  it "should raise an error if attempting to parse invalid JSON" do
@@ -75,7 +75,7 @@ describe "Sequel::Plugins::JsonSerializer" do
75
75
  v
76
76
  end
77
77
  end
78
- proc{Album.from_json('1')}.should raise_error(Sequel::Error)
78
+ proc{Album.from_json('1')}.must_raise(Sequel::Error)
79
79
  ensure
80
80
  Sequel.instance_eval do
81
81
  alias parse_json pj
@@ -91,7 +91,7 @@ describe "Sequel::Plugins::JsonSerializer" do
91
91
  Album.load(:id=>3)
92
92
  end
93
93
  end
94
- ::Album.from_json('1').should == Album.load(:id=>3)
94
+ ::Album.from_json('1').must_equal Album.load(:id=>3)
95
95
  ensure
96
96
  Sequel.instance_eval do
97
97
  alias parse_json pj
@@ -100,91 +100,91 @@ describe "Sequel::Plugins::JsonSerializer" do
100
100
  end
101
101
 
102
102
  it "should handle the :include option for arbitrary attributes" do
103
- Album.from_json(@album.to_json(:include=>:blah)).blah.should == @album.blah
103
+ Album.from_json(@album.to_json(:include=>:blah)).blah.must_equal @album.blah
104
104
  end
105
105
 
106
106
  it "should handle multiple inclusions using an array for the :include option" do
107
107
  a = Album.from_json(@album.to_json(:include=>[:blah, :artist]), :associations=>:artist)
108
- a.blah.should == @album.blah
109
- a.artist.should == @artist
108
+ a.blah.must_equal @album.blah
109
+ a.artist.must_equal @artist
110
110
  end
111
111
 
112
112
  it "should handle cascading using a hash for the :include option" do
113
- Artist.from_json(@artist.to_json(:include=>{:albums=>{:include=>:artist}}), :associations=>{:albums=>{:associations=>:artist}}).albums.map{|a| a.artist}.should == [@artist]
114
- Album.from_json(@album.to_json(:include=>{:artist=>{:include=>:albums}}), :associations=>{:artist=>{:associations=>:albums}}).artist.albums.should == [@album]
113
+ Artist.from_json(@artist.to_json(:include=>{:albums=>{:include=>:artist}}), :associations=>{:albums=>{:associations=>:artist}}).albums.map{|a| a.artist}.must_equal [@artist]
114
+ Album.from_json(@album.to_json(:include=>{:artist=>{:include=>:albums}}), :associations=>{:artist=>{:associations=>:albums}}).artist.albums.must_equal [@album]
115
115
 
116
- Artist.from_json(@artist.to_json(:include=>{:albums=>{:only=>:name}}), :associations=>[:albums]).albums.should == [Album.load(:name=>@album.name)]
117
- Album.from_json(@album.to_json(:include=>{:artist=>{:except=>:name}}), :associations=>[:artist]).artist.should == Artist.load(:id=>@artist.id)
116
+ Artist.from_json(@artist.to_json(:include=>{:albums=>{:only=>:name}}), :associations=>[:albums]).albums.must_equal [Album.load(:name=>@album.name)]
117
+ Album.from_json(@album.to_json(:include=>{:artist=>{:except=>:name}}), :associations=>[:artist]).artist.must_equal Artist.load(:id=>@artist.id)
118
118
 
119
- Artist.from_json(@artist.to_json(:include=>{:albums=>{:include=>{:artist=>{:include=>:albums}}}}), :associations=>{:albums=>{:associations=>{:artist=>{:associations=>:albums}}}}).albums.map{|a| a.artist.albums}.should == [[@album]]
120
- Album.from_json(@album.to_json(:include=>{:artist=>{:include=>{:albums=>{:only=>:name}}}}), :associations=>{:artist=>{:associations=>:albums}}).artist.albums.should == [Album.load(:name=>@album.name)]
119
+ Artist.from_json(@artist.to_json(:include=>{:albums=>{:include=>{:artist=>{:include=>:albums}}}}), :associations=>{:albums=>{:associations=>{:artist=>{:associations=>:albums}}}}).albums.map{|a| a.artist.albums}.must_equal [[@album]]
120
+ Album.from_json(@album.to_json(:include=>{:artist=>{:include=>{:albums=>{:only=>:name}}}}), :associations=>{:artist=>{:associations=>:albums}}).artist.albums.must_equal [Album.load(:name=>@album.name)]
121
121
  end
122
122
 
123
123
  it "should handle the :include option cascading with an empty hash" do
124
- Album.from_json(@album.to_json(:include=>{:artist=>{}}), :associations=>:artist).artist.should == @artist
125
- Album.from_json(@album.to_json(:include=>{:blah=>{}})).blah.should == @album.blah
124
+ Album.from_json(@album.to_json(:include=>{:artist=>{}}), :associations=>:artist).artist.must_equal @artist
125
+ Album.from_json(@album.to_json(:include=>{:blah=>{}})).blah.must_equal @album.blah
126
126
  end
127
127
 
128
128
  it "should accept a :naked option to not include the JSON.create_id, so parsing yields a plain hash" do
129
- Sequel.parse_json(@album.to_json(:naked=>true)).should == @album.values.inject({}){|h, (k, v)| h[k.to_s] = v; h}
129
+ Sequel.parse_json(@album.to_json(:naked=>true)).must_equal @album.values.inject({}){|h, (k, v)| h[k.to_s] = v; h}
130
130
  end
131
131
 
132
132
  it "should support #from_json to set column values" do
133
133
  @artist.from_json('{"name": "AS"}')
134
- @artist.name.should == 'AS'
135
- @artist.id.should == 2
134
+ @artist.name.must_equal 'AS'
135
+ @artist.id.must_equal 2
136
136
  end
137
137
 
138
138
  it "should support #from_json to support specific :fields" do
139
139
  @album.from_json('{"name": "AS", "artist_id": 3}', :fields=>['name'])
140
- @album.name.should == 'AS'
141
- @album.artist_id.should == 2
140
+ @album.name.must_equal 'AS'
141
+ @album.artist_id.must_equal 2
142
142
  end
143
143
 
144
144
  it "should support #from_json to support :missing=>:skip option" do
145
145
  @album.from_json('{"artist_id": 3}', :fields=>['name'], :missing=>:skip)
146
- @album.name.should == 'RF'
147
- @album.artist_id.should == 2
146
+ @album.name.must_equal 'RF'
147
+ @album.artist_id.must_equal 2
148
148
  end
149
149
 
150
150
  it "should support #from_json to support :missing=>:raise option" do
151
- proc{@album.from_json('{"artist_id": 3}', :fields=>['name'], :missing=>:raise)}.should raise_error(Sequel::Error)
151
+ proc{@album.from_json('{"artist_id": 3}', :fields=>['name'], :missing=>:raise)}.must_raise(Sequel::Error)
152
152
  end
153
153
 
154
154
  it "should have #from_json raise an error if parsed json isn't a hash" do
155
- proc{@artist.from_json('[]')}.should raise_error(Sequel::Error)
155
+ proc{@artist.from_json('[]')}.must_raise(Sequel::Error)
156
156
  end
157
157
 
158
158
  it "should raise an exception for json keys that aren't associations, columns, or setter methods" do
159
159
  Album.send(:undef_method, :blah=)
160
- proc{Album.from_json(@album.to_json(:include=>:blah))}.should raise_error(Sequel::MassAssignmentRestriction)
160
+ proc{Album.from_json(@album.to_json(:include=>:blah))}.must_raise(Sequel::MassAssignmentRestriction)
161
161
  end
162
162
 
163
163
  it "should support a to_json class and dataset method" do
164
164
  Album.dataset._fetch = {:id=>1, :name=>'RF', :artist_id=>2}
165
165
  Artist.dataset._fetch = {:id=>2, :name=>'YJM'}
166
- Album.array_from_json(Album.to_json).should == [@album]
167
- Album.array_from_json(Album.to_json(:include=>:artist), :associations=>:artist).map{|x| x.artist}.should == [@artist]
168
- Album.array_from_json(Album.dataset.to_json(:only=>:name)).should == [Album.load(:name=>@album.name)]
166
+ Album.array_from_json(Album.to_json).must_equal [@album]
167
+ Album.array_from_json(Album.to_json(:include=>:artist), :associations=>:artist).map{|x| x.artist}.must_equal [@artist]
168
+ Album.array_from_json(Album.dataset.to_json(:only=>:name)).must_equal [Album.load(:name=>@album.name)]
169
169
  end
170
170
 
171
171
  it "should have dataset to_json method work with naked datasets" do
172
172
  ds = Album.dataset.naked
173
173
  ds._fetch = {:id=>1, :name=>'RF', :artist_id=>2}
174
- Sequel.parse_json(ds.to_json).should == [@album.values.inject({}){|h, (k, v)| h[k.to_s] = v; h}]
174
+ Sequel.parse_json(ds.to_json).must_equal [@album.values.inject({}){|h, (k, v)| h[k.to_s] = v; h}]
175
175
  end
176
176
 
177
177
  it "should have dataset to_json method respect :array option for the array to use" do
178
178
  a = Album.new(:name=>'RF', :artist_id=>3)
179
- Album.array_from_json(Album.to_json(:array=>[a])).should == [a]
179
+ Album.array_from_json(Album.to_json(:array=>[a])).must_equal [a]
180
180
 
181
181
  a.associations[:artist] = artist = Artist.load(:id=>3, :name=>'YJM')
182
- Album.array_from_json(Album.to_json(:array=>[a], :include=>:artist), :associations=>:artist).first.artist.should == artist
182
+ Album.array_from_json(Album.to_json(:array=>[a], :include=>:artist), :associations=>:artist).first.artist.must_equal artist
183
183
 
184
184
  artist.associations[:albums] = [a]
185
185
  x = Artist.array_from_json(Artist.to_json(:array=>[artist], :include=>:albums), :associations=>[:albums])
186
- x.should == [artist]
187
- x.first.albums.should == [a]
186
+ x.must_equal [artist]
187
+ x.first.albums.must_equal [a]
188
188
  end
189
189
 
190
190
  it "should propagate class default options to instance to_json output" do
@@ -197,14 +197,14 @@ describe "Sequel::Plugins::JsonSerializer" do
197
197
  @album2 = Album2.load(:id=>2, :name=>'JK')
198
198
  @album2.artist = @artist
199
199
  @album2.blah = 'Gak'
200
- JSON.parse(@album2.to_json).should == @album2.values.reject{|k,v| k.to_s == 'id'}.inject({}){|h, (k, v)| h[k.to_s] = v; h}
201
- JSON.parse(@album2.to_json(:only => :name)).should == @album2.values.reject{|k,v| k.to_s != 'name'}.inject({}){|h, (k, v)| h[k.to_s] = v; h}
202
- JSON.parse(@album2.to_json(:except => :artist_id)).should == @album2.values.reject{|k,v| k.to_s == 'artist_id'}.inject({}){|h, (k, v)| h[k.to_s] = v; h}
200
+ JSON.parse(@album2.to_json).must_equal @album2.values.reject{|k,v| k.to_s == 'id'}.inject({}){|h, (k, v)| h[k.to_s] = v; h}
201
+ JSON.parse(@album2.to_json(:only => :name)).must_equal @album2.values.reject{|k,v| k.to_s != 'name'}.inject({}){|h, (k, v)| h[k.to_s] = v; h}
202
+ JSON.parse(@album2.to_json(:except => :artist_id)).must_equal @album2.values.reject{|k,v| k.to_s == 'artist_id'}.inject({}){|h, (k, v)| h[k.to_s] = v; h}
203
203
  end
204
204
 
205
205
  it "should handle the :root option to qualify single records" do
206
- @album.to_json(:root=>true, :except => [:name, :artist_id]).to_s.should == '{"album":{"id":1}}'
207
- @album.to_json(:root=>true, :only => :name).to_s.should == '{"album":{"name":"RF"}}'
206
+ @album.to_json(:root=>true, :except => [:name, :artist_id]).to_s.must_equal '{"album":{"id":1}}'
207
+ @album.to_json(:root=>true, :only => :name).to_s.must_equal '{"album":{"name":"RF"}}'
208
208
  end
209
209
 
210
210
  it "should handle the :root option to qualify single records of namespaced models" do
@@ -213,79 +213,79 @@ describe "Sequel::Plugins::JsonSerializer" do
213
213
  plugin :json_serializer, :naked=>true
214
214
  end
215
215
  end
216
- Namespace::Album.new({}).to_json(:root=>true).to_s.should == '{"album":{}}'
216
+ Namespace::Album.new({}).to_json(:root=>true).to_s.must_equal '{"album":{}}'
217
217
  Namespace::Album.dataset._fetch = [{}]
218
- Namespace::Album.dataset.to_json(:root=>:collection).to_s.should == '{"albums":[{}]}'
219
- Namespace::Album.dataset.to_json(:root=>:both).to_s.should == '{"albums":[{"album":{}}]}'
218
+ Namespace::Album.dataset.to_json(:root=>:collection).to_s.must_equal '{"albums":[{}]}'
219
+ Namespace::Album.dataset.to_json(:root=>:both).to_s.must_equal '{"albums":[{"album":{}}]}'
220
220
  Object.send(:remove_const, :Namespace)
221
221
  end
222
222
 
223
223
  it "should handle the :root option with a string to qualify single records using the string as the key" do
224
- @album.to_json(:root=>"foo", :except => [:name, :artist_id]).to_s.should == '{"foo":{"id":1}}'
225
- @album.to_json(:root=>"bar", :only => :name).to_s.should == '{"bar":{"name":"RF"}}'
224
+ @album.to_json(:root=>"foo", :except => [:name, :artist_id]).to_s.must_equal '{"foo":{"id":1}}'
225
+ @album.to_json(:root=>"bar", :only => :name).to_s.must_equal '{"bar":{"name":"RF"}}'
226
226
  end
227
227
 
228
228
  it "should handle the :root=>:both option to qualify a dataset of records" do
229
229
  Album.dataset._fetch = [{:id=>1, :name=>'RF'}, {:id=>1, :name=>'RF'}]
230
- Album.dataset.to_json(:root=>:both, :only => :id).to_s.should == '{"albums":[{"album":{"id":1}},{"album":{"id":1}}]}'
230
+ Album.dataset.to_json(:root=>:both, :only => :id).to_s.must_equal '{"albums":[{"album":{"id":1}},{"album":{"id":1}}]}'
231
231
  end
232
232
 
233
233
  it "should handle the :root=>:collection option to qualify just the collection" do
234
234
  Album.dataset._fetch = [{:id=>1, :name=>'RF'}, {:id=>1, :name=>'RF'}]
235
- Album.dataset.to_json(:root=>:collection, :only => :id).to_s.should == '{"albums":[{"id":1},{"id":1}]}'
236
- Album.dataset.to_json(:root=>true, :only => :id).to_s.should == '{"albums":[{"id":1},{"id":1}]}'
235
+ Album.dataset.to_json(:root=>:collection, :only => :id).to_s.must_equal '{"albums":[{"id":1},{"id":1}]}'
236
+ Album.dataset.to_json(:root=>true, :only => :id).to_s.must_equal '{"albums":[{"id":1},{"id":1}]}'
237
237
  end
238
238
 
239
239
  it "should handle the :root=>:instance option to qualify just the instances" do
240
240
  Album.dataset._fetch = [{:id=>1, :name=>'RF'}, {:id=>1, :name=>'RF'}]
241
- Album.dataset.to_json(:root=>:instance, :only => :id).to_s.should == '[{"album":{"id":1}},{"album":{"id":1}}]'
241
+ Album.dataset.to_json(:root=>:instance, :only => :id).to_s.must_equal '[{"album":{"id":1}},{"album":{"id":1}}]'
242
242
  end
243
243
 
244
244
  it "should handle the :root=>string option to qualify just the collection using the string as the key" do
245
245
  Album.dataset._fetch = [{:id=>1, :name=>'RF'}, {:id=>1, :name=>'RF'}]
246
- Album.dataset.to_json(:root=>"foos", :only => :id).to_s.should == '{"foos":[{"id":1},{"id":1}]}'
247
- Album.dataset.to_json(:root=>"bars", :only => :id).to_s.should == '{"bars":[{"id":1},{"id":1}]}'
246
+ Album.dataset.to_json(:root=>"foos", :only => :id).to_s.must_equal '{"foos":[{"id":1},{"id":1}]}'
247
+ Album.dataset.to_json(:root=>"bars", :only => :id).to_s.must_equal '{"bars":[{"id":1},{"id":1}]}'
248
248
  end
249
249
 
250
250
  it "should store the default options in json_serializer_opts" do
251
- Album.json_serializer_opts.should == {:naked=>true}
251
+ Album.json_serializer_opts.must_equal(:naked=>true)
252
252
  c = Class.new(Album)
253
253
  c.plugin :json_serializer, :naked=>false
254
- c.json_serializer_opts.should == {:naked=>false}
254
+ c.json_serializer_opts.must_equal(:naked=>false)
255
255
  end
256
256
 
257
257
  it "should work correctly when subclassing" do
258
258
  class ::Artist2 < Artist
259
259
  plugin :json_serializer, :only=>:name
260
260
  end
261
- Artist2.from_json(Artist2.load(:id=>2, :name=>'YYY').to_json).should == Artist2.load(:name=>'YYY')
261
+ Artist2.from_json(Artist2.load(:id=>2, :name=>'YYY').to_json).must_equal Artist2.load(:name=>'YYY')
262
262
  class ::Artist3 < Artist2
263
263
  plugin :json_serializer, :naked=>:true
264
264
  end
265
- Sequel.parse_json(Artist3.load(:id=>2, :name=>'YYY').to_json).should == {"name"=>'YYY'}
265
+ Sequel.parse_json(Artist3.load(:id=>2, :name=>'YYY').to_json).must_equal("name"=>'YYY')
266
266
  Object.send(:remove_const, :Artist2)
267
267
  Object.send(:remove_const, :Artist3)
268
268
  end
269
269
 
270
270
  it "should raise an error if attempting to set a restricted column and :all_columns is not used" do
271
271
  Artist.restrict_primary_key
272
- proc{Artist.from_json(@artist.to_json)}.should raise_error(Sequel::MassAssignmentRestriction)
272
+ proc{Artist.from_json(@artist.to_json)}.must_raise(Sequel::MassAssignmentRestriction)
273
273
  end
274
274
 
275
275
  it "should raise an error if an unsupported association is passed in the :associations option" do
276
276
  Artist.association_reflections.delete(:albums)
277
- proc{Artist.from_json(@artist.to_json(:include=>:albums), :associations=>:albums)}.should raise_error(Sequel::Error)
277
+ proc{Artist.from_json(@artist.to_json(:include=>:albums), :associations=>:albums)}.must_raise(Sequel::Error)
278
278
  end
279
279
 
280
280
  it "should raise an error if using from_json and JSON parsing returns an array" do
281
- proc{Artist.from_json([@artist].to_json)}.should raise_error(Sequel::Error)
281
+ proc{Artist.from_json([@artist].to_json)}.must_raise(Sequel::Error)
282
282
  end
283
283
 
284
284
  it "should raise an error if using array_from_json and JSON parsing does not return an array" do
285
- proc{Artist.array_from_json(@artist.to_json)}.should raise_error(Sequel::Error)
285
+ proc{Artist.array_from_json(@artist.to_json)}.must_raise(Sequel::Error)
286
286
  end
287
287
 
288
288
  it "should raise an error if using an unsupported :associations option" do
289
- proc{Artist.from_json(@artist.to_json, :associations=>'')}.should raise_error(Sequel::Error)
289
+ proc{Artist.from_json(@artist.to_json, :associations=>'')}.must_raise(Sequel::Error)
290
290
  end
291
291
  end
@@ -44,90 +44,90 @@ describe "Sequel::Plugins::LazyAttributes" do
44
44
 
45
45
  it "should allowing adding additional lazy attributes via plugin :lazy_attributes" do
46
46
  @c.set_dataset(@ds.select(:id, :blah))
47
- @c.dataset.sql.should == 'SELECT id, blah FROM la'
47
+ @c.dataset.sql.must_equal 'SELECT id, blah FROM la'
48
48
  @c.plugin :lazy_attributes, :blah
49
- @c.dataset.sql.should == 'SELECT id FROM la'
49
+ @c.dataset.sql.must_equal 'SELECT id FROM la'
50
50
  end
51
51
 
52
52
  it "should allowing adding additional lazy attributes via lazy_attributes" do
53
53
  @c.set_dataset(@ds.select(:id, :blah))
54
- @c.dataset.sql.should == 'SELECT id, blah FROM la'
54
+ @c.dataset.sql.must_equal 'SELECT id, blah FROM la'
55
55
  @c.lazy_attributes :blah
56
- @c.dataset.sql.should == 'SELECT id FROM la'
56
+ @c.dataset.sql.must_equal 'SELECT id FROM la'
57
57
  end
58
58
 
59
59
  it "should handle lazy attributes that are qualified in the selection" do
60
60
  @c.set_dataset(@ds.select(:la__id, :la__blah))
61
- @c.dataset.sql.should == 'SELECT la.id, la.blah FROM la'
61
+ @c.dataset.sql.must_equal 'SELECT la.id, la.blah FROM la'
62
62
  @c.plugin :lazy_attributes, :blah
63
- @c.dataset.sql.should == 'SELECT la.id FROM la'
63
+ @c.dataset.sql.must_equal 'SELECT la.id FROM la'
64
64
  end
65
65
 
66
66
  it "should remove the attributes given from the SELECT columns of the model's dataset" do
67
- @ds.sql.should == 'SELECT la.id FROM la'
67
+ @ds.sql.must_equal 'SELECT la.id FROM la'
68
68
  end
69
69
 
70
70
  it "should still typecast correctly in lazy loaded column setters" do
71
71
  m = @c.new
72
72
  m.name = 1
73
- m.name.should == '1'
73
+ m.name.must_equal '1'
74
74
  end
75
75
 
76
76
  it "should raise error if the model has no primary key" do
77
77
  m = @c.first
78
78
  @c.no_primary_key
79
- proc{m.name}.should raise_error(Sequel::Error)
79
+ proc{m.name}.must_raise(Sequel::Error)
80
80
  end
81
81
 
82
82
  it "should lazily load the attribute for a single model object" do
83
83
  m = @c.first
84
- m.values.should == {:id=>1}
85
- m.name.should == '1'
86
- m.values.should == {:id=>1, :name=>'1'}
87
- @db.sqls.should == ['SELECT la.id FROM la LIMIT 1', 'SELECT la.name FROM la WHERE (id = 1) LIMIT 1']
84
+ m.values.must_equal(:id=>1)
85
+ m.name.must_equal '1'
86
+ m.values.must_equal(:id=>1, :name=>'1')
87
+ @db.sqls.must_equal ['SELECT la.id FROM la LIMIT 1', 'SELECT la.name FROM la WHERE (id = 1) LIMIT 1']
88
88
  end
89
89
 
90
90
  it "should lazily load the attribute for a frozen model object" do
91
91
  m = @c.first
92
92
  m.freeze
93
- m.name.should == '1'
94
- @db.sqls.should == ['SELECT la.id FROM la LIMIT 1', 'SELECT la.name FROM la WHERE (id = 1) LIMIT 1']
95
- m.name.should == '1'
96
- @db.sqls.should == ['SELECT la.name FROM la WHERE (id = 1) LIMIT 1']
93
+ m.name.must_equal '1'
94
+ @db.sqls.must_equal ['SELECT la.id FROM la LIMIT 1', 'SELECT la.name FROM la WHERE (id = 1) LIMIT 1']
95
+ m.name.must_equal '1'
96
+ @db.sqls.must_equal ['SELECT la.name FROM la WHERE (id = 1) LIMIT 1']
97
97
  end
98
98
 
99
99
  it "should not lazily load the attribute for a single model object if the value already exists" do
100
100
  m = @c.first
101
- m.values.should == {:id=>1}
101
+ m.values.must_equal(:id=>1)
102
102
  m[:name] = '1'
103
- m.name.should == '1'
104
- m.values.should == {:id=>1, :name=>'1'}
105
- @db.sqls.should == ['SELECT la.id FROM la LIMIT 1']
103
+ m.name.must_equal '1'
104
+ m.values.must_equal(:id=>1, :name=>'1')
105
+ @db.sqls.must_equal ['SELECT la.id FROM la LIMIT 1']
106
106
  end
107
107
 
108
108
  it "should not lazily load the attribute for a single model object if it is a new record" do
109
109
  m = @c.new
110
- m.values.should == {}
111
- m.name.should == nil
112
- @db.sqls.should == []
110
+ m.values.must_equal({})
111
+ m.name.must_equal nil
112
+ @db.sqls.must_equal []
113
113
  end
114
114
 
115
115
  it "should eagerly load the attribute for all model objects reteived with it" do
116
116
  ms = @c.all
117
- ms.map{|m| m.values}.should == [{:id=>1}, {:id=>2}]
118
- ms.map{|m| m.name}.should == %w'1 2'
119
- ms.map{|m| m.values}.should == [{:id=>1, :name=>'1'}, {:id=>2, :name=>'2'}]
117
+ ms.map{|m| m.values}.must_equal [{:id=>1}, {:id=>2}]
118
+ ms.map{|m| m.name}.must_equal %w'1 2'
119
+ ms.map{|m| m.values}.must_equal [{:id=>1, :name=>'1'}, {:id=>2, :name=>'2'}]
120
120
  sqls = @db.sqls
121
121
  ['SELECT la.id, la.name FROM la WHERE (la.id IN (1, 2))',
122
- 'SELECT la.id, la.name FROM la WHERE (la.id IN (2, 1))'].should include(sqls.pop)
123
- sqls.should == ['SELECT la.id FROM la']
122
+ 'SELECT la.id, la.name FROM la WHERE (la.id IN (2, 1))'].must_include(sqls.pop)
123
+ sqls.must_equal ['SELECT la.id FROM la']
124
124
  end
125
125
 
126
126
  it "should not eagerly load the attribute if model instance is frozen, and deal with other frozen instances if not frozen" do
127
127
  ms = @c.all
128
128
  ms.first.freeze
129
- ms.map{|m| m.name}.should == %w'1 2'
130
- @db.sqls.should == ['SELECT la.id FROM la', 'SELECT la.name FROM la WHERE (id = 1) LIMIT 1', 'SELECT la.id, la.name FROM la WHERE (la.id IN (2))']
129
+ ms.map{|m| m.name}.must_equal %w'1 2'
130
+ @db.sqls.must_equal ['SELECT la.id FROM la', 'SELECT la.name FROM la WHERE (id = 1) LIMIT 1', 'SELECT la.id, la.name FROM la WHERE (la.id IN (2))']
131
131
  end
132
132
 
133
133
  it "should add the accessors to a module included in the class, so they can be easily overridden" do
@@ -137,34 +137,34 @@ describe "Sequel::Plugins::LazyAttributes" do
137
137
  end
138
138
  end
139
139
  ms = @c.all
140
- ms.map{|m| m.values}.should == [{:id=>1}, {:id=>2}]
141
- ms.map{|m| m.name}.should == %w'1-blah 2-blah'
142
- ms.map{|m| m.values}.should == [{:id=>1, :name=>'1'}, {:id=>2, :name=>'2'}]
140
+ ms.map{|m| m.values}.must_equal [{:id=>1}, {:id=>2}]
141
+ ms.map{|m| m.name}.must_equal %w'1-blah 2-blah'
142
+ ms.map{|m| m.values}.must_equal [{:id=>1, :name=>'1'}, {:id=>2, :name=>'2'}]
143
143
  sqls = @db.sqls
144
144
  ['SELECT la.id, la.name FROM la WHERE (la.id IN (1, 2))',
145
- 'SELECT la.id, la.name FROM la WHERE (la.id IN (2, 1))'].should include(sqls.pop)
146
- sqls.should == ['SELECT la.id FROM la']
145
+ 'SELECT la.id, la.name FROM la WHERE (la.id IN (2, 1))'].must_include(sqls.pop)
146
+ sqls.must_equal ['SELECT la.id FROM la']
147
147
  end
148
148
 
149
149
  it "should work with the serialization plugin" do
150
150
  @c.plugin :serialization, :yaml, :name
151
151
  @c.instance_dataset._fetch = @ds._fetch = [[{:id=>1}, {:id=>2}], [{:id=>1, :name=>"--- 3\n"}, {:id=>2, :name=>"--- 6\n"}], [{:id=>1}], [{:name=>"--- 3\n"}]]
152
152
  ms = @ds.all
153
- ms.map{|m| m.values}.should == [{:id=>1}, {:id=>2}]
154
- ms.map{|m| m.name}.should == [3,6]
155
- ms.map{|m| m.values}.should == [{:id=>1, :name=>"--- 3\n"}, {:id=>2, :name=>"--- 6\n"}]
156
- ms.map{|m| m.deserialized_values}.should == [{:name=>3}, {:name=>6}]
157
- ms.map{|m| m.name}.should == [3,6]
153
+ ms.map{|m| m.values}.must_equal [{:id=>1}, {:id=>2}]
154
+ ms.map{|m| m.name}.must_equal [3,6]
155
+ ms.map{|m| m.values}.must_equal [{:id=>1, :name=>"--- 3\n"}, {:id=>2, :name=>"--- 6\n"}]
156
+ ms.map{|m| m.deserialized_values}.must_equal [{:name=>3}, {:name=>6}]
157
+ ms.map{|m| m.name}.must_equal [3,6]
158
158
  sqls = @db.sqls
159
159
  ['SELECT la.id, la.name FROM la WHERE (la.id IN (1, 2))',
160
- 'SELECT la.id, la.name FROM la WHERE (la.id IN (2, 1))'].should include(sqls.pop)
161
- sqls.should == ['SELECT la.id FROM la']
160
+ 'SELECT la.id, la.name FROM la WHERE (la.id IN (2, 1))'].must_include(sqls.pop)
161
+ sqls.must_equal ['SELECT la.id FROM la']
162
162
  m = @ds.first
163
- m.values.should == {:id=>1}
164
- m.name.should == 3
165
- m.values.should == {:id=>1, :name=>"--- 3\n"}
166
- m.deserialized_values.should == {:name=>3}
167
- m.name.should == 3
168
- @db.sqls.should == ["SELECT la.id FROM la LIMIT 1", "SELECT la.name FROM la WHERE (id = 1) LIMIT 1"]
163
+ m.values.must_equal(:id=>1)
164
+ m.name.must_equal 3
165
+ m.values.must_equal(:id=>1, :name=>"--- 3\n")
166
+ m.deserialized_values.must_equal(:name=>3)
167
+ m.name.must_equal 3
168
+ @db.sqls.must_equal ["SELECT la.id FROM la LIMIT 1", "SELECT la.name FROM la WHERE (id = 1) LIMIT 1"]
169
169
  end
170
170
  end