sequel 4.22.0 → 4.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +22 -0
- data/README.rdoc +6 -0
- data/Rakefile +59 -81
- data/doc/migration.rdoc +2 -0
- data/doc/release_notes/4.23.0.txt +65 -0
- data/doc/sharding.rdoc +16 -14
- data/doc/testing.rdoc +61 -77
- data/lib/sequel/adapters/jdbc.rb +1 -0
- data/lib/sequel/adapters/mock.rb +0 -1
- data/lib/sequel/adapters/postgres.rb +1 -0
- data/lib/sequel/adapters/postgresql.rb +1 -0
- data/lib/sequel/adapters/shared/postgres.rb +3 -3
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
- data/lib/sequel/connection_pool/threaded.rb +9 -1
- data/lib/sequel/database/connecting.rb +1 -1
- data/lib/sequel/database/transactions.rb +2 -1
- data/lib/sequel/dataset/prepared_statements.rb +1 -1
- data/lib/sequel/extensions/constraint_validations.rb +12 -12
- data/lib/sequel/extensions/date_arithmetic.rb +0 -4
- data/lib/sequel/extensions/pagination.rb +14 -2
- data/lib/sequel/extensions/pg_enum.rb +2 -2
- data/lib/sequel/extensions/pg_hstore.rb +1 -1
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +2 -0
- data/lib/sequel/plugins/delay_add_association.rb +50 -0
- data/lib/sequel/plugins/list.rb +2 -2
- data/lib/sequel/plugins/nested_attributes.rb +8 -28
- data/lib/sequel/plugins/update_refresh.rb +50 -0
- data/lib/sequel/plugins/validate_associated.rb +55 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +29 -29
- data/spec/adapters/firebird_spec.rb +97 -103
- data/spec/adapters/informix_spec.rb +25 -25
- data/spec/adapters/mssql_spec.rb +156 -172
- data/spec/adapters/mysql_spec.rb +334 -359
- data/spec/adapters/oracle_spec.rb +67 -69
- data/spec/adapters/postgres_spec.rb +1298 -1249
- data/spec/adapters/spec_helper.rb +2 -35
- data/spec/adapters/sqlanywhere_spec.rb +39 -39
- data/spec/adapters/sqlite_spec.rb +203 -200
- data/spec/bin_spec.rb +57 -59
- data/spec/core/connection_pool_spec.rb +402 -401
- data/spec/core/database_spec.rb +953 -944
- data/spec/core/dataset_spec.rb +2178 -2168
- data/spec/core/deprecated_spec.rb +19 -19
- data/spec/core/expression_filters_spec.rb +415 -415
- data/spec/core/mock_adapter_spec.rb +212 -212
- data/spec/core/object_graph_spec.rb +73 -73
- data/spec/core/placeholder_literalizer_spec.rb +71 -71
- data/spec/core/schema_generator_spec.rb +44 -44
- data/spec/core/schema_spec.rb +470 -472
- data/spec/core/spec_helper.rb +5 -20
- data/spec/core/version_spec.rb +2 -2
- data/spec/core_extensions_spec.rb +320 -320
- data/spec/extensions/accessed_columns_spec.rb +12 -12
- data/spec/extensions/active_model_spec.rb +3 -3
- data/spec/extensions/after_initialize_spec.rb +2 -2
- data/spec/extensions/arbitrary_servers_spec.rb +23 -23
- data/spec/extensions/association_dependencies_spec.rb +34 -34
- data/spec/extensions/association_pks_spec.rb +98 -98
- data/spec/extensions/association_proxies_spec.rb +33 -33
- data/spec/extensions/auto_validations_spec.rb +46 -46
- data/spec/extensions/blacklist_security_spec.rb +19 -18
- data/spec/extensions/blank_spec.rb +36 -36
- data/spec/extensions/boolean_readers_spec.rb +36 -36
- data/spec/extensions/caching_spec.rb +82 -82
- data/spec/extensions/class_table_inheritance_spec.rb +72 -72
- data/spec/extensions/column_conflicts_spec.rb +19 -14
- data/spec/extensions/column_select_spec.rb +19 -19
- data/spec/extensions/columns_introspection_spec.rb +43 -43
- data/spec/extensions/composition_spec.rb +64 -64
- data/spec/extensions/connection_validator_spec.rb +92 -90
- data/spec/extensions/constraint_validations_plugin_spec.rb +92 -92
- data/spec/extensions/constraint_validations_spec.rb +80 -80
- data/spec/extensions/core_refinements_spec.rb +220 -220
- data/spec/extensions/csv_serializer_spec.rb +44 -44
- data/spec/extensions/current_datetime_timestamp_spec.rb +8 -8
- data/spec/extensions/dataset_associations_spec.rb +65 -65
- data/spec/extensions/dataset_source_alias_spec.rb +16 -16
- data/spec/extensions/date_arithmetic_spec.rb +51 -58
- data/spec/extensions/defaults_setter_spec.rb +19 -19
- data/spec/extensions/delay_add_association_spec.rb +52 -0
- data/spec/extensions/dirty_spec.rb +51 -51
- data/spec/extensions/eager_each_spec.rb +8 -8
- data/spec/extensions/empty_array_ignore_nulls_spec.rb +10 -10
- data/spec/extensions/error_splitter_spec.rb +2 -2
- data/spec/extensions/error_sql_spec.rb +4 -4
- data/spec/extensions/eval_inspect_spec.rb +3 -3
- data/spec/extensions/filter_having_spec.rb +8 -8
- data/spec/extensions/force_encoding_spec.rb +30 -30
- data/spec/extensions/from_block_spec.rb +7 -7
- data/spec/extensions/graph_each_spec.rb +19 -19
- data/spec/extensions/hash_aliases_spec.rb +5 -5
- data/spec/extensions/hook_class_methods_spec.rb +100 -100
- data/spec/extensions/inflector_spec.rb +54 -54
- data/spec/extensions/input_transformer_spec.rb +10 -10
- data/spec/extensions/insert_returning_select_spec.rb +8 -8
- data/spec/extensions/instance_filters_spec.rb +26 -26
- data/spec/extensions/instance_hooks_spec.rb +85 -85
- data/spec/extensions/json_serializer_spec.rb +68 -68
- data/spec/extensions/lazy_attributes_spec.rb +49 -49
- data/spec/extensions/list_spec.rb +77 -75
- data/spec/extensions/looser_typecasting_spec.rb +16 -16
- data/spec/extensions/many_through_many_spec.rb +627 -627
- data/spec/extensions/meta_def_spec.rb +7 -7
- data/spec/extensions/migration_spec.rb +217 -217
- data/spec/extensions/modification_detection_spec.rb +20 -20
- data/spec/extensions/mssql_optimistic_locking_spec.rb +21 -21
- data/spec/extensions/named_timezones_spec.rb +18 -18
- data/spec/extensions/nested_attributes_spec.rb +107 -107
- data/spec/extensions/null_dataset_spec.rb +24 -24
- data/spec/extensions/optimistic_locking_spec.rb +21 -21
- data/spec/extensions/pagination_spec.rb +52 -52
- data/spec/extensions/pg_array_associations_spec.rb +273 -273
- data/spec/extensions/pg_array_ops_spec.rb +52 -52
- data/spec/extensions/pg_array_spec.rb +152 -152
- data/spec/extensions/pg_enum_spec.rb +13 -13
- data/spec/extensions/pg_hstore_ops_spec.rb +63 -63
- data/spec/extensions/pg_hstore_spec.rb +84 -84
- data/spec/extensions/pg_inet_spec.rb +15 -15
- data/spec/extensions/pg_interval_spec.rb +29 -29
- data/spec/extensions/pg_json_ops_spec.rb +86 -84
- data/spec/extensions/pg_json_spec.rb +104 -104
- data/spec/extensions/pg_loose_count_spec.rb +6 -6
- data/spec/extensions/pg_range_ops_spec.rb +24 -24
- data/spec/extensions/pg_range_spec.rb +143 -143
- data/spec/extensions/pg_row_ops_spec.rb +14 -14
- data/spec/extensions/pg_row_plugin_spec.rb +12 -12
- data/spec/extensions/pg_row_spec.rb +118 -118
- data/spec/extensions/pg_static_cache_updater_spec.rb +28 -28
- data/spec/extensions/pg_typecast_on_load_spec.rb +21 -21
- data/spec/extensions/prepared_statements_associations_spec.rb +42 -42
- data/spec/extensions/prepared_statements_safe_spec.rb +18 -18
- data/spec/extensions/prepared_statements_spec.rb +28 -28
- data/spec/extensions/prepared_statements_with_pk_spec.rb +11 -11
- data/spec/extensions/pretty_table_spec.rb +16 -16
- data/spec/extensions/query_literals_spec.rb +37 -37
- data/spec/extensions/query_spec.rb +32 -32
- data/spec/extensions/rcte_tree_spec.rb +141 -141
- data/spec/extensions/round_timestamps_spec.rb +21 -21
- data/spec/extensions/schema_caching_spec.rb +8 -8
- data/spec/extensions/schema_dumper_spec.rb +78 -78
- data/spec/extensions/schema_spec.rb +31 -27
- data/spec/extensions/scissors_spec.rb +3 -3
- data/spec/extensions/select_remove_spec.rb +14 -14
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +28 -28
- data/spec/extensions/serialization_modification_detection_spec.rb +33 -33
- data/spec/extensions/serialization_spec.rb +79 -78
- data/spec/extensions/server_block_spec.rb +17 -17
- data/spec/extensions/set_overrides_spec.rb +30 -30
- data/spec/extensions/sharding_spec.rb +65 -65
- data/spec/extensions/shared_caching_spec.rb +29 -29
- data/spec/extensions/single_table_inheritance_spec.rb +79 -79
- data/spec/extensions/skip_create_refresh_spec.rb +3 -3
- data/spec/extensions/spec_helper.rb +4 -29
- data/spec/extensions/split_array_nil_spec.rb +9 -9
- data/spec/extensions/split_values_spec.rb +7 -7
- data/spec/extensions/sql_expr_spec.rb +32 -32
- data/spec/extensions/static_cache_spec.rb +123 -123
- data/spec/extensions/string_date_time_spec.rb +34 -34
- data/spec/extensions/string_stripper_spec.rb +15 -15
- data/spec/extensions/subclasses_spec.rb +31 -31
- data/spec/extensions/table_select_spec.rb +15 -15
- data/spec/extensions/tactical_eager_loading_spec.rb +23 -23
- data/spec/extensions/thread_local_timezones_spec.rb +13 -13
- data/spec/extensions/timestamps_spec.rb +40 -40
- data/spec/extensions/to_dot_spec.rb +34 -34
- data/spec/extensions/touch_spec.rb +52 -52
- data/spec/extensions/tree_spec.rb +72 -72
- data/spec/extensions/typecast_on_load_spec.rb +25 -25
- data/spec/extensions/unlimited_update_spec.rb +2 -2
- data/spec/extensions/update_or_create_spec.rb +36 -36
- data/spec/extensions/update_primary_key_spec.rb +35 -35
- data/spec/extensions/update_refresh_spec.rb +41 -0
- data/spec/extensions/validate_associated_spec.rb +52 -0
- data/spec/extensions/validation_class_methods_spec.rb +314 -317
- data/spec/extensions/validation_helpers_spec.rb +195 -195
- data/spec/extensions/xml_serializer_spec.rb +48 -48
- data/spec/guards_helper.rb +55 -0
- data/spec/integration/associations_test.rb +1089 -1088
- data/spec/integration/database_test.rb +29 -29
- data/spec/integration/dataset_test.rb +661 -661
- data/spec/integration/eager_loader_test.rb +147 -147
- data/spec/integration/migrator_test.rb +122 -122
- data/spec/integration/model_test.rb +70 -70
- data/spec/integration/plugin_test.rb +682 -640
- data/spec/integration/prepared_statement_test.rb +172 -172
- data/spec/integration/schema_test.rb +245 -245
- data/spec/integration/spec_helper.rb +1 -64
- data/spec/integration/timezone_test.rb +17 -17
- data/spec/integration/transaction_test.rb +87 -87
- data/spec/integration/type_test.rb +33 -33
- data/spec/model/association_reflection_spec.rb +130 -121
- data/spec/model/associations_spec.rb +1112 -1113
- data/spec/model/base_spec.rb +197 -196
- data/spec/model/class_dataset_methods_spec.rb +118 -118
- data/spec/model/dataset_methods_spec.rb +49 -49
- data/spec/model/eager_loading_spec.rb +705 -702
- data/spec/model/hooks_spec.rb +169 -168
- data/spec/model/inflector_spec.rb +5 -5
- data/spec/model/model_spec.rb +287 -297
- data/spec/model/plugins_spec.rb +47 -47
- data/spec/model/record_spec.rb +534 -535
- data/spec/model/spec_helper.rb +3 -21
- data/spec/model/validations_spec.rb +72 -70
- data/spec/spec_config.rb +8 -0
- metadata +41 -9
- data/lib/sequel/adapters/fdbsql.rb +0 -286
- data/lib/sequel/adapters/jdbc/fdbsql.rb +0 -66
- data/lib/sequel/adapters/openbase.rb +0 -54
- data/lib/sequel/adapters/shared/fdbsql.rb +0 -550
- data/spec/adapters/fdbsql_spec.rb +0 -429
- data/spec/rspec_helper.rb +0 -22
@@ -74,47 +74,47 @@ describe "Eagerly loading a tree structure" do
|
|
74
74
|
|
75
75
|
it "#descendants should get all descendants in one call" do
|
76
76
|
nodes = Node.filter(:id=>1).eager(:descendants).all
|
77
|
-
nodes.length.
|
77
|
+
nodes.length.must_equal 1
|
78
78
|
node = nodes.first
|
79
|
-
node.pk.
|
80
|
-
node.children.length.
|
81
|
-
node.children.collect{|x| x.pk}.sort.
|
82
|
-
node.children.collect{|x| x.parent}.
|
79
|
+
node.pk.must_equal 1
|
80
|
+
node.children.length.must_equal 2
|
81
|
+
node.children.collect{|x| x.pk}.sort.must_equal [2, 3]
|
82
|
+
node.children.collect{|x| x.parent}.must_equal [node, node]
|
83
83
|
node = nodes.first.children.find{|x| x.pk == 2}
|
84
|
-
node.children.length.
|
85
|
-
node.children.first.pk.
|
86
|
-
node.children.first.parent.
|
84
|
+
node.children.length.must_equal 1
|
85
|
+
node.children.first.pk.must_equal 4
|
86
|
+
node.children.first.parent.must_equal node
|
87
87
|
node = node.children.first
|
88
|
-
node.children.length.
|
89
|
-
node.children.first.pk.
|
90
|
-
node.children.first.parent.
|
88
|
+
node.children.length.must_equal 1
|
89
|
+
node.children.first.pk.must_equal 5
|
90
|
+
node.children.first.parent.must_equal node
|
91
91
|
node = node.children.first
|
92
|
-
node.children.length.
|
93
|
-
node.children.first.pk.
|
94
|
-
node.children.first.parent.
|
92
|
+
node.children.length.must_equal 1
|
93
|
+
node.children.first.pk.must_equal 6
|
94
|
+
node.children.first.parent.must_equal node
|
95
95
|
node = node.children.first
|
96
|
-
node.children.length.
|
97
|
-
node.children.first.pk.
|
98
|
-
node.children.first.parent.
|
96
|
+
node.children.length.must_equal 1
|
97
|
+
node.children.first.pk.must_equal 7
|
98
|
+
node.children.first.parent.must_equal node
|
99
99
|
end
|
100
100
|
|
101
101
|
it "#ancestors should get all ancestors in one call" do
|
102
102
|
nodes = Node.filter(:id=>[7,3]).order(:id).eager(:ancestors).all
|
103
|
-
nodes.length.
|
104
|
-
nodes.collect{|x| x.pk}.
|
105
|
-
nodes.first.parent.pk.
|
106
|
-
nodes.first.parent.parent.
|
103
|
+
nodes.length.must_equal 2
|
104
|
+
nodes.collect{|x| x.pk}.must_equal [3, 7]
|
105
|
+
nodes.first.parent.pk.must_equal 1
|
106
|
+
nodes.first.parent.parent.must_equal nil
|
107
107
|
node = nodes.last
|
108
|
-
node.parent.pk.
|
108
|
+
node.parent.pk.must_equal 6
|
109
109
|
node = node.parent
|
110
|
-
node.parent.pk.
|
110
|
+
node.parent.pk.must_equal 5
|
111
111
|
node = node.parent
|
112
|
-
node.parent.pk.
|
112
|
+
node.parent.pk.must_equal 4
|
113
113
|
node = node.parent
|
114
|
-
node.parent.pk.
|
114
|
+
node.parent.pk.must_equal 2
|
115
115
|
node = node.parent
|
116
|
-
node.parent.pk.
|
117
|
-
node.parent.parent.
|
116
|
+
node.parent.pk.must_equal 1
|
117
|
+
node.parent.parent.must_equal nil
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -152,20 +152,20 @@ describe "Association Extensions" do
|
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should allow methods to be called on the dataset method" do
|
155
|
-
Authorship.count.
|
155
|
+
Authorship.count.must_equal 0
|
156
156
|
authorship = @author.authorships_dataset.find_or_create_by_name('Bob')
|
157
|
-
Authorship.count.
|
158
|
-
Authorship.first.
|
159
|
-
authorship.name.
|
160
|
-
authorship.author_id.
|
161
|
-
@author.authorships_dataset.find_or_create_by_name('Bob').
|
162
|
-
Authorship.count.
|
157
|
+
Authorship.count.must_equal 1
|
158
|
+
Authorship.first.must_equal authorship
|
159
|
+
authorship.name.must_equal 'Bob'
|
160
|
+
authorship.author_id.must_equal @author.id
|
161
|
+
@author.authorships_dataset.find_or_create_by_name('Bob').must_equal authorship
|
162
|
+
Authorship.count.must_equal 1
|
163
163
|
authorship2 = @author.authorships_dataset.find_or_create(:name=>'Jim')
|
164
|
-
Authorship.count.
|
165
|
-
Authorship.order(:name).map(:name).
|
166
|
-
authorship2.name.
|
167
|
-
authorship2.author_id.
|
168
|
-
@author.authorships_dataset.find_or_create(:name=>'Jim').
|
164
|
+
Authorship.count.must_equal 2
|
165
|
+
Authorship.order(:name).map(:name).must_equal ['Bob', 'Jim']
|
166
|
+
authorship2.name.must_equal 'Jim'
|
167
|
+
authorship2.author_id.must_equal @author.id
|
168
|
+
@author.authorships_dataset.find_or_create(:name=>'Jim').must_equal authorship2
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
@@ -259,64 +259,64 @@ describe "has_many :through has_many and has_one :through belongs_to" do
|
|
259
259
|
|
260
260
|
it "should return has_many :through has_many records for a single object" do
|
261
261
|
invs = @firm1.invoices.sort_by{|x| x.pk}
|
262
|
-
invs.
|
263
|
-
invs[0].client.
|
264
|
-
invs[1].client.
|
265
|
-
invs[2].client.
|
266
|
-
invs.collect{|i| i.firm}.
|
267
|
-
invs.collect{|i| i.client.firm}.
|
262
|
+
invs.must_equal [@invoice1, @invoice2, @invoice3]
|
263
|
+
invs[0].client.must_equal @client1
|
264
|
+
invs[1].client.must_equal @client1
|
265
|
+
invs[2].client.must_equal @client2
|
266
|
+
invs.collect{|i| i.firm}.must_equal [@firm1, @firm1, @firm1]
|
267
|
+
invs.collect{|i| i.client.firm}.must_equal [@firm1, @firm1, @firm1]
|
268
268
|
end
|
269
269
|
|
270
270
|
it "should eagerly load has_many :through has_many records for multiple objects" do
|
271
271
|
firms = Firm.order(:id).eager(:invoices).all
|
272
|
-
firms.
|
272
|
+
firms.must_equal [@firm1, @firm2]
|
273
273
|
firm1, firm2 = firms
|
274
274
|
invs1 = firm1.invoices.sort_by{|x| x.pk}
|
275
275
|
invs2 = firm2.invoices.sort_by{|x| x.pk}
|
276
|
-
invs1.
|
277
|
-
invs2.
|
278
|
-
invs1[0].client.
|
279
|
-
invs1[1].client.
|
280
|
-
invs1[2].client.
|
281
|
-
invs2[0].client.
|
282
|
-
invs2[1].client.
|
283
|
-
invs1.collect{|i| i.firm}.
|
284
|
-
invs2.collect{|i| i.firm}.
|
285
|
-
invs1.collect{|i| i.client.firm}.
|
286
|
-
invs2.collect{|i| i.client.firm}.
|
276
|
+
invs1.must_equal [@invoice1, @invoice2, @invoice3]
|
277
|
+
invs2.must_equal [@invoice4, @invoice5]
|
278
|
+
invs1[0].client.must_equal @client1
|
279
|
+
invs1[1].client.must_equal @client1
|
280
|
+
invs1[2].client.must_equal @client2
|
281
|
+
invs2[0].client.must_equal @client3
|
282
|
+
invs2[1].client.must_equal @client3
|
283
|
+
invs1.collect{|i| i.firm}.must_equal [@firm1, @firm1, @firm1]
|
284
|
+
invs2.collect{|i| i.firm}.must_equal [@firm2, @firm2]
|
285
|
+
invs1.collect{|i| i.client.firm}.must_equal [@firm1, @firm1, @firm1]
|
286
|
+
invs2.collect{|i| i.client.firm}.must_equal [@firm2, @firm2]
|
287
287
|
end
|
288
288
|
|
289
289
|
it "should return has_one :through belongs_to records for a single object" do
|
290
290
|
firm = @invoice1.firm
|
291
|
-
firm.
|
292
|
-
@invoice1.client.
|
293
|
-
@invoice1.client.firm.
|
294
|
-
firm.associations[:clients].
|
291
|
+
firm.must_equal @firm1
|
292
|
+
@invoice1.client.must_equal @client1
|
293
|
+
@invoice1.client.firm.must_equal @firm1
|
294
|
+
firm.associations[:clients].must_equal nil
|
295
295
|
end
|
296
296
|
|
297
297
|
it "should eagerly load has_one :through belongs_to records for multiple objects" do
|
298
298
|
invs = Invoice.order(:id).eager(:firm).all
|
299
|
-
invs.
|
300
|
-
invs[0].firm.
|
301
|
-
invs[0].client.
|
302
|
-
invs[0].client.firm.
|
303
|
-
invs[0].firm.associations[:clients].
|
304
|
-
invs[1].firm.
|
305
|
-
invs[1].client.
|
306
|
-
invs[1].client.firm.
|
307
|
-
invs[1].firm.associations[:clients].
|
308
|
-
invs[2].firm.
|
309
|
-
invs[2].client.
|
310
|
-
invs[2].client.firm.
|
311
|
-
invs[2].firm.associations[:clients].
|
312
|
-
invs[3].firm.
|
313
|
-
invs[3].client.
|
314
|
-
invs[3].client.firm.
|
315
|
-
invs[3].firm.associations[:clients].
|
316
|
-
invs[4].firm.
|
317
|
-
invs[4].client.
|
318
|
-
invs[4].client.firm.
|
319
|
-
invs[4].firm.associations[:clients].
|
299
|
+
invs.must_equal [@invoice1, @invoice2, @invoice3, @invoice4, @invoice5]
|
300
|
+
invs[0].firm.must_equal @firm1
|
301
|
+
invs[0].client.must_equal @client1
|
302
|
+
invs[0].client.firm.must_equal @firm1
|
303
|
+
invs[0].firm.associations[:clients].must_equal nil
|
304
|
+
invs[1].firm.must_equal @firm1
|
305
|
+
invs[1].client.must_equal @client1
|
306
|
+
invs[1].client.firm.must_equal @firm1
|
307
|
+
invs[1].firm.associations[:clients].must_equal nil
|
308
|
+
invs[2].firm.must_equal @firm1
|
309
|
+
invs[2].client.must_equal @client2
|
310
|
+
invs[2].client.firm.must_equal @firm1
|
311
|
+
invs[2].firm.associations[:clients].must_equal nil
|
312
|
+
invs[3].firm.must_equal @firm2
|
313
|
+
invs[3].client.must_equal @client3
|
314
|
+
invs[3].client.firm.must_equal @firm2
|
315
|
+
invs[3].firm.associations[:clients].must_equal nil
|
316
|
+
invs[4].firm.must_equal @firm2
|
317
|
+
invs[4].client.must_equal @client3
|
318
|
+
invs[4].client.firm.must_equal @firm2
|
319
|
+
invs[4].firm.associations[:clients].must_equal nil
|
320
320
|
end
|
321
321
|
end
|
322
322
|
|
@@ -394,55 +394,55 @@ describe "Polymorphic Associations" do
|
|
394
394
|
end
|
395
395
|
|
396
396
|
it "should load the correct associated object for a single object" do
|
397
|
-
@asset1.attachable.
|
398
|
-
@asset2.attachable.
|
397
|
+
@asset1.attachable.must_equal @post
|
398
|
+
@asset2.attachable.must_equal @note
|
399
399
|
end
|
400
400
|
|
401
401
|
it "should eagerly load the correct associated object for a group of objects" do
|
402
402
|
assets = Asset.order(:id).eager(:attachable).all
|
403
|
-
assets.
|
404
|
-
assets[0].attachable.
|
405
|
-
assets[1].attachable.
|
403
|
+
assets.must_equal [@asset1, @asset2]
|
404
|
+
assets[0].attachable.must_equal @post
|
405
|
+
assets[1].attachable.must_equal @note
|
406
406
|
end
|
407
407
|
|
408
408
|
it "should set items correctly" do
|
409
409
|
@asset1.attachable = @note
|
410
410
|
@asset2.attachable = @post
|
411
|
-
@asset1.attachable.
|
412
|
-
@asset1.attachable_id.
|
413
|
-
@asset1.attachable_type.
|
414
|
-
@asset2.attachable.
|
415
|
-
@asset2.attachable_id.
|
416
|
-
@asset2.attachable_type.
|
411
|
+
@asset1.attachable.must_equal @note
|
412
|
+
@asset1.attachable_id.must_equal @note.pk
|
413
|
+
@asset1.attachable_type.must_equal 'Note'
|
414
|
+
@asset2.attachable.must_equal @post
|
415
|
+
@asset2.attachable_id.must_equal @post.pk
|
416
|
+
@asset2.attachable_type.must_equal 'Post'
|
417
417
|
@asset1.attachable = nil
|
418
|
-
@asset1.attachable.
|
419
|
-
@asset1.attachable_id.
|
420
|
-
@asset1.attachable_type.
|
418
|
+
@asset1.attachable.must_equal nil
|
419
|
+
@asset1.attachable_id.must_equal nil
|
420
|
+
@asset1.attachable_type.must_equal nil
|
421
421
|
end
|
422
422
|
|
423
423
|
it "should add items correctly" do
|
424
|
-
@post.assets.
|
424
|
+
@post.assets.must_equal [@asset1]
|
425
425
|
@post.add_asset(@asset2)
|
426
|
-
@post.assets.
|
427
|
-
@asset2.attachable.
|
428
|
-
@asset2.attachable_id.
|
429
|
-
@asset2.attachable_type.
|
426
|
+
@post.assets.must_equal [@asset1, @asset2]
|
427
|
+
@asset2.attachable.must_equal @post
|
428
|
+
@asset2.attachable_id.must_equal @post.pk
|
429
|
+
@asset2.attachable_type.must_equal 'Post'
|
430
430
|
end
|
431
431
|
|
432
432
|
it "should remove items correctly" do
|
433
|
-
@note.assets.
|
433
|
+
@note.assets.must_equal [@asset2]
|
434
434
|
@note.remove_asset(@asset2)
|
435
|
-
@note.assets.
|
436
|
-
@asset2.attachable.
|
437
|
-
@asset2.attachable_id.
|
438
|
-
@asset2.attachable_type.
|
435
|
+
@note.assets.must_equal []
|
436
|
+
@asset2.attachable.must_equal nil
|
437
|
+
@asset2.attachable_id.must_equal nil
|
438
|
+
@asset2.attachable_type.must_equal nil
|
439
439
|
end
|
440
440
|
|
441
441
|
it "should remove all items correctly" do
|
442
442
|
@post.remove_all_assets
|
443
443
|
@note.remove_all_assets
|
444
|
-
@asset1.reload.attachable.
|
445
|
-
@asset2.reload.attachable.
|
444
|
+
@asset1.reload.attachable.must_equal nil
|
445
|
+
@asset2.reload.attachable.must_equal nil
|
446
446
|
end
|
447
447
|
end
|
448
448
|
|
@@ -511,65 +511,65 @@ describe "many_to_one/one_to_many not referencing primary key" do
|
|
511
511
|
|
512
512
|
it "should load all associated one_to_many objects for a single object" do
|
513
513
|
invs = @client1.invoices
|
514
|
-
invs.
|
515
|
-
invs[0].client.
|
516
|
-
invs[1].client.
|
514
|
+
invs.must_equal [@invoice1, @invoice2]
|
515
|
+
invs[0].client.must_equal @client1
|
516
|
+
invs[1].client.must_equal @client1
|
517
517
|
end
|
518
518
|
|
519
519
|
it "should load the associated many_to_one object for a single object" do
|
520
520
|
client = @invoice1.client
|
521
|
-
client.
|
521
|
+
client.must_equal @client1
|
522
522
|
end
|
523
523
|
|
524
524
|
it "should eagerly load all associated one_to_many objects for a group of objects" do
|
525
525
|
clients = Client.order(:id).eager(:invoices).all
|
526
|
-
clients.
|
527
|
-
clients[1].invoices.
|
526
|
+
clients.must_equal [@client1, @client2]
|
527
|
+
clients[1].invoices.must_equal []
|
528
528
|
invs = clients[0].invoices.sort_by{|x| x.pk}
|
529
|
-
invs.
|
530
|
-
invs[0].client.
|
531
|
-
invs[1].client.
|
529
|
+
invs.must_equal [@invoice1, @invoice2]
|
530
|
+
invs[0].client.must_equal @client1
|
531
|
+
invs[1].client.must_equal @client1
|
532
532
|
end
|
533
533
|
|
534
534
|
it "should eagerly load the associated many_to_one object for a group of objects" do
|
535
535
|
invoices = Invoice.order(:id).eager(:client).all
|
536
|
-
invoices.
|
537
|
-
invoices[0].client.
|
538
|
-
invoices[1].client.
|
536
|
+
invoices.must_equal [@invoice1, @invoice2]
|
537
|
+
invoices[0].client.must_equal @client1
|
538
|
+
invoices[1].client.must_equal @client1
|
539
539
|
end
|
540
540
|
|
541
541
|
it "should set the associated object correctly" do
|
542
542
|
@invoice1.client = @client2
|
543
|
-
@invoice1.client.
|
544
|
-
@invoice1.client_name.
|
543
|
+
@invoice1.client.must_equal @client2
|
544
|
+
@invoice1.client_name.must_equal 'Y'
|
545
545
|
@invoice1.client = nil
|
546
|
-
@invoice1.client_name.
|
546
|
+
@invoice1.client_name.must_equal nil
|
547
547
|
end
|
548
548
|
|
549
549
|
it "should add the associated object correctly" do
|
550
|
-
@client2.invoices.
|
550
|
+
@client2.invoices.must_equal []
|
551
551
|
@client2.add_invoice(@invoice1)
|
552
|
-
@client2.invoices.
|
553
|
-
@invoice1.client_name.
|
552
|
+
@client2.invoices.must_equal [@invoice1]
|
553
|
+
@invoice1.client_name.must_equal 'Y'
|
554
554
|
@invoice1.client = nil
|
555
|
-
@invoice1.client_name.
|
555
|
+
@invoice1.client_name.must_equal nil
|
556
556
|
end
|
557
557
|
|
558
558
|
it "should remove the associated object correctly" do
|
559
559
|
invs = @client1.invoices.sort_by{|x| x.pk}
|
560
|
-
invs.
|
560
|
+
invs.must_equal [@invoice1, @invoice2]
|
561
561
|
@client1.remove_invoice(@invoice1)
|
562
|
-
@client1.invoices.
|
563
|
-
@invoice1.client_name.
|
564
|
-
@invoice1.client.
|
562
|
+
@client1.invoices.must_equal [@invoice2]
|
563
|
+
@invoice1.client_name.must_equal nil
|
564
|
+
@invoice1.client.must_equal nil
|
565
565
|
end
|
566
566
|
|
567
567
|
it "should remove all associated objects correctly" do
|
568
568
|
@client1.remove_all_invoices
|
569
|
-
@invoice1.refresh.client.
|
570
|
-
@invoice1.client_name.
|
571
|
-
@invoice2.refresh.client.
|
572
|
-
@invoice2.client_name.
|
569
|
+
@invoice1.refresh.client.must_equal nil
|
570
|
+
@invoice1.client_name.must_equal nil
|
571
|
+
@invoice2.refresh.client.must_equal nil
|
572
|
+
@invoice2.client_name.must_equal nil
|
573
573
|
end
|
574
574
|
end
|
575
575
|
|
@@ -622,14 +622,14 @@ describe "statistics associations" do
|
|
622
622
|
end
|
623
623
|
|
624
624
|
it "should give the correct sum of ticket hours for each project" do
|
625
|
-
@project1.ticket_hours.to_i.
|
626
|
-
@project2.ticket_hours.to_i.
|
625
|
+
@project1.ticket_hours.to_i.must_equal 11
|
626
|
+
@project2.ticket_hours.to_i.must_equal 22
|
627
627
|
end
|
628
628
|
|
629
629
|
it "should give the correct sum of ticket hours for each project when eager loading" do
|
630
630
|
p1, p2 = Project.order(:name).eager(:ticket_hours).all
|
631
|
-
p1.ticket_hours.to_i.
|
632
|
-
p2.ticket_hours.to_i.
|
631
|
+
p1.ticket_hours.to_i.must_equal 11
|
632
|
+
p2.ticket_hours.to_i.must_equal 22
|
633
633
|
end
|
634
634
|
end
|
635
635
|
|
@@ -667,21 +667,21 @@ describe "one to one associations" do
|
|
667
667
|
|
668
668
|
it "should be eager loadable" do
|
669
669
|
bk1, bk2 = Book.filter(:books__id=>[1,2]).eager(:first_page).all
|
670
|
-
bk1.first_page.
|
671
|
-
bk2.first_page.
|
670
|
+
bk1.first_page.must_equal @page1
|
671
|
+
bk2.first_page.must_equal @page3
|
672
672
|
end
|
673
673
|
|
674
674
|
it "should be eager graphable" do
|
675
675
|
bk1, bk2 = Book.filter(:books__id=>[1,2]).eager_graph(:first_page).all
|
676
|
-
bk1.first_page.
|
677
|
-
bk2.first_page.
|
676
|
+
bk1.first_page.must_equal @page1
|
677
|
+
bk2.first_page.must_equal @page3
|
678
678
|
end
|
679
679
|
|
680
680
|
it "should be eager graphable two at once" do
|
681
681
|
bk1, bk2 = Book.filter(:books__id=>[1,2]).eager_graph(:first_page, :second_page).all
|
682
|
-
bk1.first_page.
|
683
|
-
bk1.second_page.
|
684
|
-
bk2.first_page.
|
685
|
-
bk2.second_page.
|
682
|
+
bk1.first_page.must_equal @page1
|
683
|
+
bk1.second_page.must_equal @page2
|
684
|
+
bk2.first_page.must_equal @page3
|
685
|
+
bk2.second_page.must_equal @page4
|
686
686
|
end
|
687
687
|
end
|
@@ -10,231 +10,231 @@ describe Sequel::Migrator do
|
|
10
10
|
@db.drop_table?(:schema_info, :schema_migrations, :sm1111, :sm1122, :sm2222, :sm2233, :sm3333, :sm11111, :sm22222)
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
it "should be able to migrate up and down all the way successfully" do
|
14
14
|
@dir = 'spec/files/integer_migrations'
|
15
15
|
@m.apply(@db, @dir)
|
16
|
-
[:schema_info, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
17
|
-
@db[:schema_info].get(:version).
|
16
|
+
[:schema_info, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
17
|
+
@db[:schema_info].get(:version).must_equal 3
|
18
18
|
@m.apply(@db, @dir, 0)
|
19
|
-
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
20
|
-
@db[:schema_info].get(:version).
|
19
|
+
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
20
|
+
@db[:schema_info].get(:version).must_equal 0
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
it "should be able to migrate up and down to specific versions successfully" do
|
24
24
|
@dir = 'spec/files/integer_migrations'
|
25
25
|
@m.apply(@db, @dir, 2)
|
26
|
-
[:schema_info, :sm1111, :sm2222].each{|n| @db.table_exists?(n).
|
27
|
-
@db.table_exists?(:sm3333).
|
28
|
-
@db[:schema_info].get(:version).
|
26
|
+
[:schema_info, :sm1111, :sm2222].each{|n| @db.table_exists?(n).must_equal true}
|
27
|
+
@db.table_exists?(:sm3333).must_equal false
|
28
|
+
@db[:schema_info].get(:version).must_equal 2
|
29
29
|
@m.apply(@db, @dir, 1)
|
30
|
-
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
31
|
-
@db.table_exists?(:sm1111).
|
32
|
-
@db[:schema_info].get(:version).
|
30
|
+
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
31
|
+
@db.table_exists?(:sm1111).must_equal true
|
32
|
+
@db[:schema_info].get(:version).must_equal 1
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
it "should correctly set migration version to the last successful migration if the migration raises an error when migrating up" do
|
36
36
|
@dir = 'spec/files/bad_up_migration'
|
37
|
-
proc{@m.apply(@db, @dir)}.
|
38
|
-
[:schema_info, :sm11111].each{|n| @db.table_exists?(n).
|
39
|
-
@db.table_exists?(:sm22222).
|
40
|
-
@db[:schema_info].get(:version).
|
37
|
+
proc{@m.apply(@db, @dir)}.must_raise Sequel::DatabaseError
|
38
|
+
[:schema_info, :sm11111].each{|n| @db.table_exists?(n).must_equal true}
|
39
|
+
@db.table_exists?(:sm22222).must_equal false
|
40
|
+
@db[:schema_info].get(:version).must_equal 1
|
41
41
|
@m.apply(@db, @dir, 0)
|
42
|
-
[:sm11111, :sm22222].each{|n| @db.table_exists?(n).
|
43
|
-
@db[:schema_info].get(:version).
|
42
|
+
[:sm11111, :sm22222].each{|n| @db.table_exists?(n).must_equal false}
|
43
|
+
@db[:schema_info].get(:version).must_equal 0
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
it "should correctly set migration version to the last successful migration if the migration raises an error when migrating down" do
|
47
47
|
@dir = 'spec/files/bad_down_migration'
|
48
48
|
@m.apply(@db, @dir)
|
49
|
-
[:schema_info, :sm11111, :sm22222].each{|n| @db.table_exists?(n).
|
50
|
-
@db[:schema_info].get(:version).
|
51
|
-
proc{@m.apply(@db, @dir, 0)}.
|
52
|
-
[:sm22222].each{|n| @db.table_exists?(n).
|
53
|
-
@db.table_exists?(:sm11111).
|
54
|
-
@db[:schema_info].get(:version).
|
49
|
+
[:schema_info, :sm11111, :sm22222].each{|n| @db.table_exists?(n).must_equal true}
|
50
|
+
@db[:schema_info].get(:version).must_equal 2
|
51
|
+
proc{@m.apply(@db, @dir, 0)}.must_raise Sequel::DatabaseError
|
52
|
+
[:sm22222].each{|n| @db.table_exists?(n).must_equal false}
|
53
|
+
@db.table_exists?(:sm11111).must_equal true
|
54
|
+
@db[:schema_info].get(:version).must_equal 1
|
55
55
|
end
|
56
56
|
|
57
|
-
|
57
|
+
it "should handle migrating up or down all the way with timestamped migrations" do
|
58
58
|
@dir = 'spec/files/timestamped_migrations'
|
59
59
|
@m.apply(@db, @dir)
|
60
|
-
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
61
|
-
@db[:schema_migrations].select_order_map(:filename).
|
60
|
+
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
61
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253851_create_nodes.rb 1273253853_3_create_users.rb'
|
62
62
|
@m.apply(@db, @dir, 0)
|
63
|
-
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
64
|
-
@db[:schema_migrations].select_order_map(:filename).
|
63
|
+
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
64
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal []
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
it "should handle migrating up or down to specific timestamps with timestamped migrations" do
|
68
68
|
@dir = 'spec/files/timestamped_migrations'
|
69
69
|
@m.apply(@db, @dir, 1273253851)
|
70
|
-
[:schema_migrations, :sm1111, :sm2222].each{|n| @db.table_exists?(n).
|
71
|
-
@db.table_exists?(:sm3333).
|
72
|
-
@db[:schema_migrations].select_order_map(:filename).
|
70
|
+
[:schema_migrations, :sm1111, :sm2222].each{|n| @db.table_exists?(n).must_equal true}
|
71
|
+
@db.table_exists?(:sm3333).must_equal false
|
72
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253851_create_nodes.rb'
|
73
73
|
@m.apply(@db, @dir, 1273253849)
|
74
|
-
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
75
|
-
@db.table_exists?(:sm1111).
|
76
|
-
@db[:schema_migrations].select_order_map(:filename).
|
74
|
+
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
75
|
+
@db.table_exists?(:sm1111).must_equal true
|
76
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb'
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
it "should apply all missing files when migrating up with timestamped migrations" do
|
80
80
|
@dir = 'spec/files/timestamped_migrations'
|
81
81
|
@m.apply(@db, @dir)
|
82
82
|
@dir = 'spec/files/interleaved_timestamped_migrations'
|
83
83
|
@m.apply(@db, @dir)
|
84
|
-
[:schema_migrations, :sm1111, :sm1122, :sm2222, :sm2233, :sm3333].each{|n| @db.table_exists?(n).
|
85
|
-
@db[:schema_migrations].select_order_map(:filename).
|
84
|
+
[:schema_migrations, :sm1111, :sm1122, :sm2222, :sm2233, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
85
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253850_create_artists.rb 1273253851_create_nodes.rb 1273253852_create_albums.rb 1273253853_3_create_users.rb'
|
86
86
|
end
|
87
87
|
|
88
|
-
|
88
|
+
it "should not apply down action to migrations where up action hasn't been applied" do
|
89
89
|
@dir = 'spec/files/timestamped_migrations'
|
90
90
|
@m.apply(@db, @dir)
|
91
91
|
@dir = 'spec/files/interleaved_timestamped_migrations'
|
92
92
|
@m.apply(@db, @dir, 0)
|
93
|
-
[:sm1111, :sm1122, :sm2222, :sm2233, :sm3333].each{|n| @db.table_exists?(n).
|
94
|
-
@db[:schema_migrations].select_order_map(:filename).
|
93
|
+
[:sm1111, :sm1122, :sm2222, :sm2233, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
94
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal []
|
95
95
|
end
|
96
96
|
|
97
|
-
|
97
|
+
it "should handle updating to a specific timestamp when interleaving migrations with timestamps" do
|
98
98
|
@dir = 'spec/files/timestamped_migrations'
|
99
99
|
@m.apply(@db, @dir)
|
100
100
|
@dir = 'spec/files/interleaved_timestamped_migrations'
|
101
101
|
@m.apply(@db, @dir, 1273253851)
|
102
|
-
[:schema_migrations, :sm1111, :sm1122, :sm2222].each{|n| @db.table_exists?(n).
|
103
|
-
[:sm2233, :sm3333].each{|n| @db.table_exists?(n).
|
104
|
-
@db[:schema_migrations].select_order_map(:filename).
|
102
|
+
[:schema_migrations, :sm1111, :sm1122, :sm2222].each{|n| @db.table_exists?(n).must_equal true}
|
103
|
+
[:sm2233, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
104
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253850_create_artists.rb 1273253851_create_nodes.rb'
|
105
105
|
end
|
106
106
|
|
107
|
-
|
107
|
+
it "should correctly update schema_migrations table when an error occurs when migrating up or down using timestamped migrations" do
|
108
108
|
@dir = 'spec/files/bad_timestamped_migrations'
|
109
|
-
proc{@m.apply(@db, @dir)}.
|
110
|
-
[:schema_migrations, :sm1111, :sm2222].each{|n| @db.table_exists?(n).
|
111
|
-
@db.table_exists?(:sm3333).
|
112
|
-
@db[:schema_migrations].select_order_map(:filename).
|
113
|
-
proc{@m.apply(@db, @dir, 0)}.
|
114
|
-
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
115
|
-
@db.table_exists?(:sm1111).
|
116
|
-
@db[:schema_migrations].select_order_map(:filename).
|
109
|
+
proc{@m.apply(@db, @dir)}.must_raise Sequel::DatabaseError
|
110
|
+
[:schema_migrations, :sm1111, :sm2222].each{|n| @db.table_exists?(n).must_equal true}
|
111
|
+
@db.table_exists?(:sm3333).must_equal false
|
112
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253851_create_nodes.rb'
|
113
|
+
proc{@m.apply(@db, @dir, 0)}.must_raise Sequel::DatabaseError
|
114
|
+
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
115
|
+
@db.table_exists?(:sm1111).must_equal true
|
116
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb'
|
117
117
|
end
|
118
118
|
|
119
|
-
|
119
|
+
it "should handle multiple migrations with the same timestamp correctly" do
|
120
120
|
@dir = 'spec/files/duplicate_timestamped_migrations'
|
121
121
|
@m.apply(@db, @dir)
|
122
|
-
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
123
|
-
@db[:schema_migrations].select_order_map(:filename).
|
122
|
+
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
123
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253853_create_nodes.rb 1273253853_create_users.rb'
|
124
124
|
@m.apply(@db, @dir, 1273253853)
|
125
|
-
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
126
|
-
@db[:schema_migrations].select_order_map(:filename).
|
125
|
+
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
126
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253853_create_nodes.rb 1273253853_create_users.rb'
|
127
127
|
@m.apply(@db, @dir, 1273253849)
|
128
|
-
[:sm1111].each{|n| @db.table_exists?(n).
|
129
|
-
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
130
|
-
@db[:schema_migrations].select_order_map(:filename).
|
128
|
+
[:sm1111].each{|n| @db.table_exists?(n).must_equal true}
|
129
|
+
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
130
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb'
|
131
131
|
@m.apply(@db, @dir, 1273253848)
|
132
|
-
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
133
|
-
@db[:schema_migrations].select_order_map(:filename).
|
132
|
+
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
133
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal []
|
134
134
|
end
|
135
135
|
|
136
|
-
|
136
|
+
it "should convert schema_info table to schema_migrations table" do
|
137
137
|
@dir = 'spec/files/integer_migrations'
|
138
138
|
@m.apply(@db, @dir)
|
139
|
-
[:schema_info, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
140
|
-
[:schema_migrations, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
139
|
+
[:schema_info, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
140
|
+
[:schema_migrations, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
141
141
|
|
142
142
|
@dir = 'spec/files/convert_to_timestamp_migrations'
|
143
143
|
@m.apply(@db, @dir)
|
144
|
-
[:schema_info, :sm1111, :sm2222, :sm3333, :schema_migrations, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
145
|
-
@db[:schema_migrations].select_order_map(:filename).
|
144
|
+
[:schema_info, :sm1111, :sm2222, :sm3333, :schema_migrations, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal true}
|
145
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'001_create_sessions.rb 002_create_nodes.rb 003_3_create_users.rb 1273253850_create_artists.rb 1273253852_create_albums.rb'
|
146
146
|
|
147
147
|
@m.apply(@db, @dir, 4)
|
148
|
-
[:schema_info, :schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
149
|
-
[:sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
150
|
-
@db[:schema_migrations].select_order_map(:filename).
|
148
|
+
[:schema_info, :schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
149
|
+
[:sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
150
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'001_create_sessions.rb 002_create_nodes.rb 003_3_create_users.rb'
|
151
151
|
|
152
152
|
@m.apply(@db, @dir, 0)
|
153
|
-
[:schema_info, :schema_migrations].each{|n| @db.table_exists?(n).
|
154
|
-
[:sm1111, :sm2222, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
155
|
-
@db[:schema_migrations].select_order_map(:filename).
|
153
|
+
[:schema_info, :schema_migrations].each{|n| @db.table_exists?(n).must_equal true}
|
154
|
+
[:sm1111, :sm2222, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
155
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal []
|
156
156
|
end
|
157
157
|
|
158
|
-
|
158
|
+
it "should handle unapplied migrations when migrating schema_info table to schema_migrations table" do
|
159
159
|
@dir = 'spec/files/integer_migrations'
|
160
160
|
@m.apply(@db, @dir, 2)
|
161
|
-
[:schema_info, :sm1111, :sm2222].each{|n| @db.table_exists?(n).
|
162
|
-
[:schema_migrations, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
161
|
+
[:schema_info, :sm1111, :sm2222].each{|n| @db.table_exists?(n).must_equal true}
|
162
|
+
[:schema_migrations, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
163
163
|
|
164
164
|
@dir = 'spec/files/convert_to_timestamp_migrations'
|
165
165
|
@m.apply(@db, @dir, 1273253850)
|
166
|
-
[:schema_info, :sm1111, :sm2222, :sm3333, :schema_migrations, :sm1122].each{|n| @db.table_exists?(n).
|
167
|
-
[:sm2233].each{|n| @db.table_exists?(n).
|
168
|
-
@db[:schema_migrations].select_order_map(:filename).
|
166
|
+
[:schema_info, :sm1111, :sm2222, :sm3333, :schema_migrations, :sm1122].each{|n| @db.table_exists?(n).must_equal true}
|
167
|
+
[:sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
168
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'001_create_sessions.rb 002_create_nodes.rb 003_3_create_users.rb 1273253850_create_artists.rb'
|
169
169
|
end
|
170
170
|
|
171
|
-
|
171
|
+
it "should handle unapplied migrations when migrating schema_info table to schema_migrations table and target is less than last integer migration version" do
|
172
172
|
@dir = 'spec/files/integer_migrations'
|
173
173
|
@m.apply(@db, @dir, 1)
|
174
|
-
[:schema_info, :sm1111].each{|n| @db.table_exists?(n).
|
175
|
-
[:schema_migrations, :sm2222, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
174
|
+
[:schema_info, :sm1111].each{|n| @db.table_exists?(n).must_equal true}
|
175
|
+
[:schema_migrations, :sm2222, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
176
176
|
|
177
177
|
@dir = 'spec/files/convert_to_timestamp_migrations'
|
178
178
|
@m.apply(@db, @dir, 2)
|
179
|
-
[:schema_info, :sm1111, :sm2222, :schema_migrations].each{|n| @db.table_exists?(n).
|
180
|
-
[:sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
181
|
-
@db[:schema_migrations].select_order_map(:filename).
|
179
|
+
[:schema_info, :sm1111, :sm2222, :schema_migrations].each{|n| @db.table_exists?(n).must_equal true}
|
180
|
+
[:sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
181
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'001_create_sessions.rb 002_create_nodes.rb'
|
182
182
|
|
183
183
|
@m.apply(@db, @dir)
|
184
|
-
[:schema_info, :sm1111, :sm2222, :schema_migrations, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
185
|
-
@db[:schema_migrations].select_order_map(:filename).
|
184
|
+
[:schema_info, :sm1111, :sm2222, :schema_migrations, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal true}
|
185
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'001_create_sessions.rb 002_create_nodes.rb 003_3_create_users.rb 1273253850_create_artists.rb 1273253852_create_albums.rb'
|
186
186
|
end
|
187
187
|
|
188
|
-
|
188
|
+
it "should handle reversible migrations" do
|
189
189
|
@dir = 'spec/files/reversible_migrations'
|
190
190
|
@db.drop_table?(:a, :b)
|
191
191
|
@m.apply(@db, @dir, 1)
|
192
|
-
[:schema_info, :a].each{|n| @db.table_exists?(n).
|
193
|
-
[:schema_migrations, :b].each{|n| @db.table_exists?(n).
|
194
|
-
@db[:a].columns.
|
192
|
+
[:schema_info, :a].each{|n| @db.table_exists?(n).must_equal true}
|
193
|
+
[:schema_migrations, :b].each{|n| @db.table_exists?(n).must_equal false}
|
194
|
+
@db[:a].columns.must_equal [:a]
|
195
195
|
|
196
196
|
@m.apply(@db, @dir, 2)
|
197
|
-
[:schema_info, :a].each{|n| @db.table_exists?(n).
|
198
|
-
[:schema_migrations, :b].each{|n| @db.table_exists?(n).
|
199
|
-
@db[:a].columns.
|
197
|
+
[:schema_info, :a].each{|n| @db.table_exists?(n).must_equal true}
|
198
|
+
[:schema_migrations, :b].each{|n| @db.table_exists?(n).must_equal false}
|
199
|
+
@db[:a].columns.must_equal [:a, :b]
|
200
200
|
|
201
201
|
@m.apply(@db, @dir, 3)
|
202
|
-
[:schema_info, :a].each{|n| @db.table_exists?(n).
|
203
|
-
[:schema_migrations, :b].each{|n| @db.table_exists?(n).
|
204
|
-
@db[:a].columns.
|
202
|
+
[:schema_info, :a].each{|n| @db.table_exists?(n).must_equal true}
|
203
|
+
[:schema_migrations, :b].each{|n| @db.table_exists?(n).must_equal false}
|
204
|
+
@db[:a].columns.must_equal [:a, :c]
|
205
205
|
|
206
206
|
@m.apply(@db, @dir, 4)
|
207
|
-
[:schema_info, :b].each{|n| @db.table_exists?(n).
|
208
|
-
[:schema_migrations, :a].each{|n| @db.table_exists?(n).
|
209
|
-
@db[:b].columns.
|
207
|
+
[:schema_info, :b].each{|n| @db.table_exists?(n).must_equal true}
|
208
|
+
[:schema_migrations, :a].each{|n| @db.table_exists?(n).must_equal false}
|
209
|
+
@db[:b].columns.must_equal [:a, :c]
|
210
210
|
|
211
211
|
@m.apply(@db, @dir, 5)
|
212
|
-
[:schema_info, :b].each{|n| @db.table_exists?(n).
|
213
|
-
[:schema_migrations, :a].each{|n| @db.table_exists?(n).
|
214
|
-
@db[:b].columns.
|
212
|
+
[:schema_info, :b].each{|n| @db.table_exists?(n).must_equal true}
|
213
|
+
[:schema_migrations, :a].each{|n| @db.table_exists?(n).must_equal false}
|
214
|
+
@db[:b].columns.must_equal [:a, :c, :e]
|
215
215
|
|
216
216
|
@m.apply(@db, @dir, 4)
|
217
|
-
[:schema_info, :b].each{|n| @db.table_exists?(n).
|
218
|
-
[:schema_migrations, :a].each{|n| @db.table_exists?(n).
|
219
|
-
@db[:b].columns.
|
217
|
+
[:schema_info, :b].each{|n| @db.table_exists?(n).must_equal true}
|
218
|
+
[:schema_migrations, :a].each{|n| @db.table_exists?(n).must_equal false}
|
219
|
+
@db[:b].columns.must_equal [:a, :c]
|
220
220
|
|
221
221
|
@m.apply(@db, @dir, 3)
|
222
|
-
[:schema_info, :a].each{|n| @db.table_exists?(n).
|
223
|
-
[:schema_migrations, :b].each{|n| @db.table_exists?(n).
|
224
|
-
@db[:a].columns.
|
222
|
+
[:schema_info, :a].each{|n| @db.table_exists?(n).must_equal true}
|
223
|
+
[:schema_migrations, :b].each{|n| @db.table_exists?(n).must_equal false}
|
224
|
+
@db[:a].columns.must_equal [:a, :c]
|
225
225
|
|
226
226
|
@m.apply(@db, @dir, 2)
|
227
|
-
[:schema_info, :a].each{|n| @db.table_exists?(n).
|
228
|
-
[:schema_migrations, :b].each{|n| @db.table_exists?(n).
|
229
|
-
@db[:a].columns.
|
227
|
+
[:schema_info, :a].each{|n| @db.table_exists?(n).must_equal true}
|
228
|
+
[:schema_migrations, :b].each{|n| @db.table_exists?(n).must_equal false}
|
229
|
+
@db[:a].columns.must_equal [:a, :b]
|
230
230
|
|
231
231
|
@m.apply(@db, @dir, 1)
|
232
|
-
[:schema_info, :a].each{|n| @db.table_exists?(n).
|
233
|
-
[:schema_migrations, :b].each{|n| @db.table_exists?(n).
|
234
|
-
@db[:a].columns.
|
232
|
+
[:schema_info, :a].each{|n| @db.table_exists?(n).must_equal true}
|
233
|
+
[:schema_migrations, :b].each{|n| @db.table_exists?(n).must_equal false}
|
234
|
+
@db[:a].columns.must_equal [:a]
|
235
235
|
|
236
236
|
@m.apply(@db, @dir, 0)
|
237
|
-
[:schema_info].each{|n| @db.table_exists?(n).
|
238
|
-
[:schema_migrations, :a, :b].each{|n| @db.table_exists?(n).
|
237
|
+
[:schema_info].each{|n| @db.table_exists?(n).must_equal true}
|
238
|
+
[:schema_migrations, :a, :b].each{|n| @db.table_exists?(n).must_equal false}
|
239
239
|
end
|
240
240
|
end
|