sequel 4.22.0 → 4.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -15,78 +15,78 @@ describe "Sequel::Model basic support" do
|
|
|
15
15
|
Object.send(:remove_const, :Item)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
Item.all.
|
|
20
|
-
Item.find(:name=>'J').
|
|
18
|
+
it ".find should return first matching item" do
|
|
19
|
+
Item.all.must_equal []
|
|
20
|
+
Item.find(:name=>'J').must_equal nil
|
|
21
21
|
Item.create(:name=>'J')
|
|
22
|
-
Item.find(:name=>'J').
|
|
22
|
+
Item.find(:name=>'J').must_equal Item.load(:id=>1, :name=>'J')
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
it ".finder should create method that returns first matching item" do
|
|
26
26
|
def Item.by_name(name) where(:name=>name) end
|
|
27
27
|
Item.finder :by_name
|
|
28
|
-
Item.first_by_name('J').
|
|
28
|
+
Item.first_by_name('J').must_equal nil
|
|
29
29
|
Item.create(:name=>'J')
|
|
30
|
-
Item.first_by_name('J').
|
|
31
|
-
Item.first_by_name(['J', 'K']).
|
|
30
|
+
Item.first_by_name('J').must_equal Item.load(:id=>1, :name=>'J')
|
|
31
|
+
Item.first_by_name(['J', 'K']).must_equal Item.load(:id=>1, :name=>'J')
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
it ".prepared_finder should create method that returns first matching item" do
|
|
35
35
|
def Item.by_name(name) where(:name=>name) end
|
|
36
36
|
Item.prepared_finder :by_name
|
|
37
|
-
Item.first_by_name('J').
|
|
37
|
+
Item.first_by_name('J').must_equal nil
|
|
38
38
|
Item.create(:name=>'J')
|
|
39
|
-
Item.first_by_name('J').
|
|
39
|
+
Item.first_by_name('J').must_equal Item.load(:id=>1, :name=>'J')
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
Item.all.
|
|
44
|
-
Item.find_or_create(:name=>'J').
|
|
45
|
-
Item.all.
|
|
46
|
-
Item.find_or_create(:name=>'J').
|
|
47
|
-
Item.all.
|
|
42
|
+
it ".find_or_create should return first matching item, or create it if it doesn't exist" do
|
|
43
|
+
Item.all.must_equal []
|
|
44
|
+
Item.find_or_create(:name=>'J').must_equal Item.load(:id=>1, :name=>'J')
|
|
45
|
+
Item.all.must_equal [Item.load(:id=>1, :name=>'J')]
|
|
46
|
+
Item.find_or_create(:name=>'J').must_equal Item.load(:id=>1, :name=>'J')
|
|
47
|
+
Item.all.must_equal [Item.load(:id=>1, :name=>'J')]
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
it "should not raise an error if the implied database table doesn't exist " do
|
|
51
51
|
class ::Item::Thing < Sequel::Model(@db)
|
|
52
52
|
set_dataset :items
|
|
53
53
|
end
|
|
54
54
|
Item.create(:name=>'J')
|
|
55
|
-
Item::Thing.first.
|
|
55
|
+
Item::Thing.first.must_equal Item::Thing.load(:id=>1, :name=>'J')
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
it "should create accessors for all table columns even if all dataset columns aren't selected" do
|
|
59
59
|
c = Class.new(Sequel::Model(@db[:items].select(:id)))
|
|
60
60
|
o = c.new
|
|
61
61
|
o.name = 'A'
|
|
62
|
-
o.save.
|
|
63
|
-
c.select_map(:name).
|
|
62
|
+
o.save.must_equal c.load(:id=>1)
|
|
63
|
+
c.select_map(:name).must_equal ['A']
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
it "should work correctly when a dataset restricts the colums it selects" do
|
|
67
67
|
class ::Item::Thing < Sequel::Model(@db[:items].select(:name))
|
|
68
68
|
end
|
|
69
69
|
Item.create(:name=>'J')
|
|
70
|
-
Item::Thing.first.
|
|
70
|
+
Item::Thing.first.must_equal Item::Thing.load(:name=>'J')
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
it "#delete should delete items correctly" do
|
|
74
74
|
i = Item.create(:name=>'J')
|
|
75
|
-
Item.count.
|
|
75
|
+
Item.count.must_equal 1
|
|
76
76
|
i.delete
|
|
77
|
-
Item.count.
|
|
77
|
+
Item.count.must_equal 0
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
it "#save should return nil if raise_on_save_failure is false and save isn't successful" do
|
|
81
81
|
i = Item.new(:name=>'J')
|
|
82
82
|
i.use_transactions = true
|
|
83
83
|
def i.after_save
|
|
84
84
|
raise Sequel::Rollback
|
|
85
85
|
end
|
|
86
|
-
i.save.
|
|
86
|
+
i.save.must_equal nil
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
it "#should respect after_commit, after_rollback, after_destroy_commit, and after_destroy_rollback hooks" do
|
|
90
90
|
i = Item.create(:name=>'J')
|
|
91
91
|
i.use_transactions = true
|
|
92
92
|
def i.hooks
|
|
@@ -118,35 +118,35 @@ describe "Sequel::Model basic support" do
|
|
|
118
118
|
end
|
|
119
119
|
i.name = 'K'
|
|
120
120
|
i.rb = true
|
|
121
|
-
i.save.
|
|
122
|
-
i.reload.name.
|
|
123
|
-
i.hooks.
|
|
121
|
+
i.save.must_equal nil
|
|
122
|
+
i.reload.name.must_equal 'J'
|
|
123
|
+
i.hooks.must_equal [:as, :ar]
|
|
124
124
|
|
|
125
125
|
i.rb = true
|
|
126
|
-
i.destroy.
|
|
127
|
-
i.exists?.
|
|
128
|
-
i.hooks.
|
|
126
|
+
i.destroy.must_equal nil
|
|
127
|
+
i.exists?.must_equal true
|
|
128
|
+
i.hooks.must_equal [:ad, :adr]
|
|
129
129
|
|
|
130
130
|
i.name = 'K'
|
|
131
131
|
i.rb = false
|
|
132
|
-
i.save.
|
|
133
|
-
i.reload.name.
|
|
134
|
-
i.hooks.
|
|
132
|
+
i.save.wont_equal nil
|
|
133
|
+
i.reload.name.must_equal 'K'
|
|
134
|
+
i.hooks.must_equal [:as, :ac]
|
|
135
135
|
|
|
136
136
|
i.rb = false
|
|
137
|
-
i.destroy.
|
|
138
|
-
i.exists?.
|
|
139
|
-
i.hooks.
|
|
137
|
+
i.destroy.wont_equal nil
|
|
138
|
+
i.exists?.must_equal false
|
|
139
|
+
i.hooks.must_equal [:ad, :adc]
|
|
140
140
|
end
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
it "#exists? should return whether the item is still in the database" do
|
|
143
143
|
i = Item.create(:name=>'J')
|
|
144
|
-
i.exists?.
|
|
144
|
+
i.exists?.must_equal true
|
|
145
145
|
Item.dataset.delete
|
|
146
|
-
i.exists?.
|
|
146
|
+
i.exists?.must_equal false
|
|
147
147
|
end
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
it "#save should only update specified columns when saving" do
|
|
150
150
|
@db.create_table!(:items) do
|
|
151
151
|
primary_key :id
|
|
152
152
|
String :name
|
|
@@ -154,60 +154,60 @@ describe "Sequel::Model basic support" do
|
|
|
154
154
|
end
|
|
155
155
|
Item.dataset = Item.dataset
|
|
156
156
|
i = Item.create(:name=>'J', :num=>1)
|
|
157
|
-
Item.all.
|
|
157
|
+
Item.all.must_equal [Item.load(:id=>1, :name=>'J', :num=>1)]
|
|
158
158
|
i.set(:name=>'K', :num=>2)
|
|
159
159
|
i.save(:columns=>:name)
|
|
160
|
-
Item.all.
|
|
160
|
+
Item.all.must_equal [Item.load(:id=>1, :name=>'K', :num=>1)]
|
|
161
161
|
i.set(:name=>'L')
|
|
162
162
|
i.save(:columns=>:num)
|
|
163
|
-
Item.all.
|
|
163
|
+
Item.all.must_equal [Item.load(:id=>1, :name=>'K', :num=>2)]
|
|
164
164
|
end
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
it "#save should check that the only a single row is modified, unless require_modification is false" do
|
|
167
167
|
i = Item.create(:name=>'a')
|
|
168
168
|
i.require_modification = true
|
|
169
169
|
i.delete
|
|
170
|
-
proc{i.save}.
|
|
171
|
-
proc{i.delete}.
|
|
170
|
+
proc{i.save}.must_raise(Sequel::NoExistingObject)
|
|
171
|
+
proc{i.delete}.must_raise(Sequel::NoExistingObject)
|
|
172
172
|
|
|
173
173
|
i.require_modification = false
|
|
174
174
|
i.save
|
|
175
175
|
i.delete
|
|
176
176
|
end
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
it ".to_hash should return a hash keyed on primary key if no argument provided" do
|
|
179
179
|
Item.create(:name=>'J')
|
|
180
|
-
Item.to_hash.
|
|
180
|
+
Item.to_hash.must_equal(1=>Item.load(:id=>1, :name=>'J'))
|
|
181
181
|
end
|
|
182
182
|
|
|
183
|
-
|
|
183
|
+
it ".to_hash should return a hash keyed on argument if one argument provided" do
|
|
184
184
|
Item.create(:name=>'J')
|
|
185
|
-
Item.to_hash(:name).
|
|
185
|
+
Item.to_hash(:name).must_equal('J'=>Item.load(:id=>1, :name=>'J'))
|
|
186
186
|
end
|
|
187
187
|
|
|
188
|
-
|
|
188
|
+
it "should be marshallable before and after saving if marshallable! is called" do
|
|
189
189
|
i = Item.new(:name=>'J')
|
|
190
190
|
s = nil
|
|
191
191
|
i2 = nil
|
|
192
192
|
i.marshallable!
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
i2.
|
|
193
|
+
s = Marshal.dump(i)
|
|
194
|
+
i2 = Marshal.load(s)
|
|
195
|
+
i2.must_equal i
|
|
196
196
|
|
|
197
197
|
i.save
|
|
198
198
|
i.marshallable!
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
i2.
|
|
199
|
+
s = Marshal.dump(i)
|
|
200
|
+
i2 = Marshal.load(s)
|
|
201
|
+
i2.must_equal i
|
|
202
202
|
|
|
203
203
|
i.save
|
|
204
204
|
i.marshallable!
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
i2.
|
|
205
|
+
s = Marshal.dump(i)
|
|
206
|
+
i2 = Marshal.load(s)
|
|
207
|
+
i2.must_equal i
|
|
208
208
|
end
|
|
209
209
|
|
|
210
|
-
|
|
210
|
+
it "#lock! should lock records" do
|
|
211
211
|
Item.db.transaction do
|
|
212
212
|
i = Item.create(:name=>'J')
|
|
213
213
|
i.lock!
|
|
@@ -217,10 +217,10 @@ describe "Sequel::Model basic support" do
|
|
|
217
217
|
end
|
|
218
218
|
|
|
219
219
|
describe "Sequel::Model with no existing table" do
|
|
220
|
-
|
|
220
|
+
it "should not raise an error when setting the dataset" do
|
|
221
221
|
db = DB
|
|
222
222
|
db.drop_table?(:items)
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
class ::Item < Sequel::Model(db); end; Object.send(:remove_const, :Item)
|
|
224
|
+
c = Class.new(Sequel::Model); c.set_dataset(db[:items])
|
|
225
225
|
end
|
|
226
226
|
end
|
|
@@ -53,8 +53,8 @@ describe "Class Table Inheritance Plugin" do
|
|
|
53
53
|
@db.drop_table? :staff, :executives, :managers, :employees
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
Employee.order(:id).all.
|
|
56
|
+
it "should return rows as subclass instances" do
|
|
57
|
+
Employee.order(:id).all.must_equal [
|
|
58
58
|
Employee.load(:id=>@i1, :name=>'E', :kind=>'Employee'),
|
|
59
59
|
Staff.load(:id=>@i2, :name=>'S', :kind=>'Staff'),
|
|
60
60
|
Manager.load(:id=>@i3, :name=>'M', :kind=>'Manager'),
|
|
@@ -62,100 +62,100 @@ describe "Class Table Inheritance Plugin" do
|
|
|
62
62
|
]
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
Employee[@i2][:manager_id].
|
|
67
|
-
Employee[@i2].manager_id.
|
|
68
|
-
Employee[@i3][:num_staff].
|
|
69
|
-
Employee[@i3].num_staff.
|
|
70
|
-
Employee[@i4][:num_staff].
|
|
71
|
-
Employee[@i4].num_staff.
|
|
72
|
-
Employee[@i4][:num_managers].
|
|
73
|
-
Employee[@i4].num_managers.
|
|
65
|
+
it "should lazily load columns in subclass tables" do
|
|
66
|
+
Employee[@i2][:manager_id].must_equal nil
|
|
67
|
+
Employee[@i2].manager_id.must_equal @i4
|
|
68
|
+
Employee[@i3][:num_staff].must_equal nil
|
|
69
|
+
Employee[@i3].num_staff.must_equal 7
|
|
70
|
+
Employee[@i4][:num_staff].must_equal nil
|
|
71
|
+
Employee[@i4].num_staff.must_equal 5
|
|
72
|
+
Employee[@i4][:num_managers].must_equal nil
|
|
73
|
+
Employee[@i4].num_managers.must_equal 6
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
it "should eagerly load columns in subclass tables when retrieving multiple objects" do
|
|
77
77
|
a = Employee.order(:id).all
|
|
78
|
-
a[1][:manager_id].
|
|
79
|
-
a[1].manager_id.
|
|
80
|
-
a[2][:num_staff].
|
|
81
|
-
a[2].num_staff.
|
|
82
|
-
a[3][:num_staff].
|
|
83
|
-
a[3].num_staff.
|
|
84
|
-
a[3][:num_managers].
|
|
85
|
-
a[3].num_managers.
|
|
78
|
+
a[1][:manager_id].must_equal nil
|
|
79
|
+
a[1].manager_id.must_equal @i4
|
|
80
|
+
a[2][:num_staff].must_equal nil
|
|
81
|
+
a[2].num_staff.must_equal 7
|
|
82
|
+
a[3][:num_staff].must_equal 5 # eagerly loaded by previous call
|
|
83
|
+
a[3].num_staff.must_equal 5
|
|
84
|
+
a[3][:num_managers].must_equal nil
|
|
85
|
+
a[3].num_managers.must_equal 6
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
Employee.db_schema.keys.sort_by{|x| x.to_s}.
|
|
90
|
-
Staff.db_schema.keys.sort_by{|x| x.to_s}.
|
|
91
|
-
Manager.db_schema.keys.sort_by{|x| x.to_s}.
|
|
92
|
-
Executive.db_schema.keys.sort_by{|x| x.to_s}.
|
|
88
|
+
it "should include schema for columns for tables for ancestor classes" do
|
|
89
|
+
Employee.db_schema.keys.sort_by{|x| x.to_s}.must_equal [:id, :kind, :name]
|
|
90
|
+
Staff.db_schema.keys.sort_by{|x| x.to_s}.must_equal [:id, :kind, :manager_id, :name]
|
|
91
|
+
Manager.db_schema.keys.sort_by{|x| x.to_s}.must_equal [:id, :kind, :name, :num_staff]
|
|
92
|
+
Executive.db_schema.keys.sort_by{|x| x.to_s}.must_equal [:id, :kind, :name, :num_managers, :num_staff]
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
Employee.columns.
|
|
97
|
-
Staff.columns.
|
|
98
|
-
Manager.columns.
|
|
99
|
-
Executive.columns.
|
|
95
|
+
it "should include columns for tables for ancestor classes" do
|
|
96
|
+
Employee.columns.must_equal [:id, :name, :kind]
|
|
97
|
+
Staff.columns.must_equal [:id, :name, :kind, :manager_id]
|
|
98
|
+
Manager.columns.must_equal [:id, :name, :kind, :num_staff]
|
|
99
|
+
Executive.columns.must_equal [:id, :name, :kind, :num_staff, :num_managers]
|
|
100
100
|
end
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
it "should delete rows from all tables" do
|
|
103
103
|
e = Executive.first
|
|
104
104
|
i = e.id
|
|
105
105
|
e.staff_members_dataset.destroy
|
|
106
106
|
e.destroy
|
|
107
|
-
@db[:executives][:id=>i].
|
|
108
|
-
@db[:managers][:id=>i].
|
|
109
|
-
@db[:employees][:id=>i].
|
|
107
|
+
@db[:executives][:id=>i].must_equal nil
|
|
108
|
+
@db[:managers][:id=>i].must_equal nil
|
|
109
|
+
@db[:employees][:id=>i].must_equal nil
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
Employee.filter(:employees__id=>@i2).all.first.manager.id.
|
|
112
|
+
it "should handle associations only defined in subclasses" do
|
|
113
|
+
Employee.filter(:employees__id=>@i2).all.first.manager.id.must_equal @i4
|
|
114
114
|
end
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
it "should insert rows into all tables" do
|
|
117
117
|
e = Executive.create(:name=>'Ex2', :num_managers=>8, :num_staff=>9)
|
|
118
118
|
i = e.id
|
|
119
|
-
@db[:employees][:id=>i].
|
|
120
|
-
@db[:managers][:id=>i].
|
|
121
|
-
@db[:executives][:id=>i].
|
|
119
|
+
@db[:employees][:id=>i].must_equal(:id=>i, :name=>'Ex2', :kind=>'Executive')
|
|
120
|
+
@db[:managers][:id=>i].must_equal(:id=>i, :num_staff=>9)
|
|
121
|
+
@db[:executives][:id=>i].must_equal(:id=>i, :num_managers=>8)
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
it "should update rows in all tables" do
|
|
125
125
|
Executive.first.update(:name=>'Ex2', :num_managers=>8, :num_staff=>9)
|
|
126
|
-
@db[:employees][:id=>@i4].
|
|
127
|
-
@db[:managers][:id=>@i4].
|
|
128
|
-
@db[:executives][:id=>@i4].
|
|
126
|
+
@db[:employees][:id=>@i4].must_equal(:id=>@i4, :name=>'Ex2', :kind=>'Executive')
|
|
127
|
+
@db[:managers][:id=>@i4].must_equal(:id=>@i4, :num_staff=>9)
|
|
128
|
+
@db[:executives][:id=>@i4].must_equal(:id=>@i4, :num_managers=>8)
|
|
129
129
|
end
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
it "should handle many_to_one relationships" do
|
|
132
132
|
m = Staff.first.manager
|
|
133
|
-
m.
|
|
134
|
-
m.
|
|
133
|
+
m.must_equal Manager[@i4]
|
|
134
|
+
m.must_be_kind_of(Executive)
|
|
135
135
|
end
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
Staff.limit(1).eager(:manager).all.map{|x| x.manager}.
|
|
137
|
+
it "should handle eagerly loading many_to_one relationships" do
|
|
138
|
+
Staff.limit(1).eager(:manager).all.map{|x| x.manager}.must_equal [Manager[@i4]]
|
|
139
139
|
end
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
it "should handle eagerly graphing many_to_one relationships" do
|
|
142
142
|
ss = Staff.eager_graph(:manager).all
|
|
143
|
-
ss.
|
|
144
|
-
ss.map{|x| x.manager}.
|
|
143
|
+
ss.must_equal [Staff[@i2]]
|
|
144
|
+
ss.map{|x| x.manager}.must_equal [Manager[@i4]]
|
|
145
145
|
end
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
Executive.first.staff_members.
|
|
147
|
+
it "should handle one_to_many relationships" do
|
|
148
|
+
Executive.first.staff_members.must_equal [Staff[@i2]]
|
|
149
149
|
end
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
Executive.limit(1).eager(:staff_members).first.staff_members.
|
|
151
|
+
it "should handle eagerly loading one_to_many relationships" do
|
|
152
|
+
Executive.limit(1).eager(:staff_members).first.staff_members.must_equal [Staff[@i2]]
|
|
153
153
|
end
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
it "should handle eagerly graphing one_to_many relationships" do
|
|
156
156
|
es = Executive.limit(1).eager_graph(:staff_members).all
|
|
157
|
-
es.
|
|
158
|
-
es.map{|x| x.staff_members}.
|
|
157
|
+
es.must_equal [Executive[@i4]]
|
|
158
|
+
es.map{|x| x.staff_members}.must_equal [[Staff[@i2]]]
|
|
159
159
|
end
|
|
160
160
|
end
|
|
161
161
|
|
|
@@ -209,132 +209,135 @@ describe "Many Through Many Plugin" do
|
|
|
209
209
|
after(:all) do
|
|
210
210
|
@db.drop_table? :albums_artists, :albums, :artists
|
|
211
211
|
end
|
|
212
|
+
def around
|
|
213
|
+
DB.transaction(:rollback=>:always){super}
|
|
214
|
+
end
|
|
212
215
|
|
|
213
216
|
def self_join(c)
|
|
214
217
|
c.join(Sequel.as(c.table_name, :b), Array(c.primary_key).zip(Array(c.primary_key))).select_all(c.table_name)
|
|
215
218
|
end
|
|
216
219
|
|
|
217
|
-
|
|
220
|
+
it "should handle super simple case with 1 join table" do
|
|
218
221
|
Artist.many_through_many :albums, [[:albums_artists, :artist_id, :album_id]]
|
|
219
|
-
Artist[@artist1.id].albums.map{|x| x.name}.sort.
|
|
220
|
-
Artist[@artist2.id].albums.map{|x| x.name}.sort.
|
|
221
|
-
Artist[@artist3.id].albums.map{|x| x.name}.sort.
|
|
222
|
-
Artist[@artist4.id].albums.map{|x| x.name}.sort.
|
|
222
|
+
Artist[@artist1.id].albums.map{|x| x.name}.sort.must_equal %w'A D'
|
|
223
|
+
Artist[@artist2.id].albums.map{|x| x.name}.sort.must_equal %w'A C'
|
|
224
|
+
Artist[@artist3.id].albums.map{|x| x.name}.sort.must_equal %w'B C'
|
|
225
|
+
Artist[@artist4.id].albums.map{|x| x.name}.sort.must_equal %w'B D'
|
|
223
226
|
|
|
224
227
|
Artist.plugin :prepared_statements_associations
|
|
225
|
-
Artist[@artist1.id].albums.map{|x| x.name}.sort.
|
|
226
|
-
Artist[@artist2.id].albums.map{|x| x.name}.sort.
|
|
227
|
-
Artist[@artist3.id].albums.map{|x| x.name}.sort.
|
|
228
|
-
Artist[@artist4.id].albums.map{|x| x.name}.sort.
|
|
229
|
-
|
|
230
|
-
Artist.filter(:id
|
|
231
|
-
Artist.filter(:id
|
|
232
|
-
Artist.filter(:id
|
|
233
|
-
Artist.filter(:id
|
|
228
|
+
Artist[@artist1.id].albums.map{|x| x.name}.sort.must_equal %w'A D'
|
|
229
|
+
Artist[@artist2.id].albums.map{|x| x.name}.sort.must_equal %w'A C'
|
|
230
|
+
Artist[@artist3.id].albums.map{|x| x.name}.sort.must_equal %w'B C'
|
|
231
|
+
Artist[@artist4.id].albums.map{|x| x.name}.sort.must_equal %w'B D'
|
|
232
|
+
|
|
233
|
+
Artist.filter(:id=>@artist1.id).eager(:albums).all.map{|x| x.albums.map{|a| a.name}}.flatten.sort.must_equal %w'A D'
|
|
234
|
+
Artist.filter(:id=>@artist2.id).eager(:albums).all.map{|x| x.albums.map{|a| a.name}}.flatten.sort.must_equal %w'A C'
|
|
235
|
+
Artist.filter(:id=>@artist3.id).eager(:albums).all.map{|x| x.albums.map{|a| a.name}}.flatten.sort.must_equal %w'B C'
|
|
236
|
+
Artist.filter(:id=>@artist4.id).eager(:albums).all.map{|x| x.albums.map{|a| a.name}}.flatten.sort.must_equal %w'B D'
|
|
234
237
|
|
|
235
|
-
Artist.filter(:artists__id
|
|
236
|
-
Artist.filter(:artists__id
|
|
237
|
-
Artist.filter(:artists__id
|
|
238
|
-
Artist.filter(:artists__id
|
|
238
|
+
Artist.filter(:artists__id=>@artist1.id).eager_graph(:albums).all.map{|x| x.albums.map{|a| a.name}}.flatten.sort.must_equal %w'A D'
|
|
239
|
+
Artist.filter(:artists__id=>@artist2.id).eager_graph(:albums).all.map{|x| x.albums.map{|a| a.name}}.flatten.sort.must_equal %w'A C'
|
|
240
|
+
Artist.filter(:artists__id=>@artist3.id).eager_graph(:albums).all.map{|x| x.albums.map{|a| a.name}}.flatten.sort.must_equal %w'B C'
|
|
241
|
+
Artist.filter(:artists__id=>@artist4.id).eager_graph(:albums).all.map{|x| x.albums.map{|a| a.name}}.flatten.sort.must_equal %w'B D'
|
|
239
242
|
|
|
240
|
-
Artist.filter(:albums=>@album1).all.map{|a| a.name}.sort.
|
|
241
|
-
Artist.filter(:albums=>@album2).all.map{|a| a.name}.sort.
|
|
242
|
-
Artist.filter(:albums=>@album3).all.map{|a| a.name}.sort.
|
|
243
|
-
Artist.filter(:albums=>@album4).all.map{|a| a.name}.sort.
|
|
243
|
+
Artist.filter(:albums=>@album1).all.map{|a| a.name}.sort.must_equal %w'1 2'
|
|
244
|
+
Artist.filter(:albums=>@album2).all.map{|a| a.name}.sort.must_equal %w'3 4'
|
|
245
|
+
Artist.filter(:albums=>@album3).all.map{|a| a.name}.sort.must_equal %w'2 3'
|
|
246
|
+
Artist.filter(:albums=>@album4).all.map{|a| a.name}.sort.must_equal %w'1 4'
|
|
244
247
|
|
|
245
|
-
Artist.exclude(:albums=>@album1).all.map{|a| a.name}.sort.
|
|
246
|
-
Artist.exclude(:albums=>@album2).all.map{|a| a.name}.sort.
|
|
247
|
-
Artist.exclude(:albums=>@album3).all.map{|a| a.name}.sort.
|
|
248
|
-
Artist.exclude(:albums=>@album4).all.map{|a| a.name}.sort.
|
|
248
|
+
Artist.exclude(:albums=>@album1).all.map{|a| a.name}.sort.must_equal %w'3 4'
|
|
249
|
+
Artist.exclude(:albums=>@album2).all.map{|a| a.name}.sort.must_equal %w'1 2'
|
|
250
|
+
Artist.exclude(:albums=>@album3).all.map{|a| a.name}.sort.must_equal %w'1 4'
|
|
251
|
+
Artist.exclude(:albums=>@album4).all.map{|a| a.name}.sort.must_equal %w'2 3'
|
|
249
252
|
|
|
250
|
-
Artist.filter(:albums=>[@album1, @album3]).all.map{|a| a.name}.sort.
|
|
251
|
-
Artist.filter(:albums=>[@album2, @album4]).all.map{|a| a.name}.sort.
|
|
253
|
+
Artist.filter(:albums=>[@album1, @album3]).all.map{|a| a.name}.sort.must_equal %w'1 2 3'
|
|
254
|
+
Artist.filter(:albums=>[@album2, @album4]).all.map{|a| a.name}.sort.must_equal %w'1 3 4'
|
|
252
255
|
|
|
253
|
-
Artist.exclude(:albums=>[@album1, @album3]).all.map{|a| a.name}.sort.
|
|
254
|
-
Artist.exclude(:albums=>[@album2, @album4]).all.map{|a| a.name}.sort.
|
|
256
|
+
Artist.exclude(:albums=>[@album1, @album3]).all.map{|a| a.name}.sort.must_equal %w'4'
|
|
257
|
+
Artist.exclude(:albums=>[@album2, @album4]).all.map{|a| a.name}.sort.must_equal %w'2'
|
|
255
258
|
|
|
256
|
-
Artist.filter(:albums=>Album.filter(:id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.
|
|
257
|
-
Artist.exclude(:albums=>Album.filter(:id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.
|
|
259
|
+
Artist.filter(:albums=>Album.filter(:id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.must_equal %w'1 2 3'
|
|
260
|
+
Artist.exclude(:albums=>Album.filter(:id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.must_equal %w'4'
|
|
258
261
|
|
|
259
262
|
c = self_join(Artist)
|
|
260
|
-
c.filter(:albums=>@album1).all.map{|a| a.name}.sort.
|
|
261
|
-
c.filter(:albums=>@album2).all.map{|a| a.name}.sort.
|
|
262
|
-
c.filter(:albums=>@album3).all.map{|a| a.name}.sort.
|
|
263
|
-
c.filter(:albums=>@album4).all.map{|a| a.name}.sort.
|
|
263
|
+
c.filter(:albums=>@album1).all.map{|a| a.name}.sort.must_equal %w'1 2'
|
|
264
|
+
c.filter(:albums=>@album2).all.map{|a| a.name}.sort.must_equal %w'3 4'
|
|
265
|
+
c.filter(:albums=>@album3).all.map{|a| a.name}.sort.must_equal %w'2 3'
|
|
266
|
+
c.filter(:albums=>@album4).all.map{|a| a.name}.sort.must_equal %w'1 4'
|
|
264
267
|
|
|
265
|
-
c.exclude(:albums=>@album1).all.map{|a| a.name}.sort.
|
|
266
|
-
c.exclude(:albums=>@album2).all.map{|a| a.name}.sort.
|
|
267
|
-
c.exclude(:albums=>@album3).all.map{|a| a.name}.sort.
|
|
268
|
-
c.exclude(:albums=>@album4).all.map{|a| a.name}.sort.
|
|
268
|
+
c.exclude(:albums=>@album1).all.map{|a| a.name}.sort.must_equal %w'3 4'
|
|
269
|
+
c.exclude(:albums=>@album2).all.map{|a| a.name}.sort.must_equal %w'1 2'
|
|
270
|
+
c.exclude(:albums=>@album3).all.map{|a| a.name}.sort.must_equal %w'1 4'
|
|
271
|
+
c.exclude(:albums=>@album4).all.map{|a| a.name}.sort.must_equal %w'2 3'
|
|
269
272
|
|
|
270
|
-
c.filter(:albums=>[@album1, @album3]).all.map{|a| a.name}.sort.
|
|
271
|
-
c.filter(:albums=>[@album2, @album4]).all.map{|a| a.name}.sort.
|
|
273
|
+
c.filter(:albums=>[@album1, @album3]).all.map{|a| a.name}.sort.must_equal %w'1 2 3'
|
|
274
|
+
c.filter(:albums=>[@album2, @album4]).all.map{|a| a.name}.sort.must_equal %w'1 3 4'
|
|
272
275
|
|
|
273
|
-
c.exclude(:albums=>[@album1, @album3]).all.map{|a| a.name}.sort.
|
|
274
|
-
c.exclude(:albums=>[@album2, @album4]).all.map{|a| a.name}.sort.
|
|
276
|
+
c.exclude(:albums=>[@album1, @album3]).all.map{|a| a.name}.sort.must_equal %w'4'
|
|
277
|
+
c.exclude(:albums=>[@album2, @album4]).all.map{|a| a.name}.sort.must_equal %w'2'
|
|
275
278
|
|
|
276
|
-
c.filter(:albums=>self_join(Album).filter(:albums__id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.
|
|
277
|
-
c.exclude(:albums=>self_join(Album).filter(:albums__id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.
|
|
279
|
+
c.filter(:albums=>self_join(Album).filter(:albums__id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.must_equal %w'1 2 3'
|
|
280
|
+
c.exclude(:albums=>self_join(Album).filter(:albums__id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.must_equal %w'4'
|
|
278
281
|
end
|
|
279
282
|
|
|
280
|
-
|
|
283
|
+
it "should handle typical case with 3 join tables" do
|
|
281
284
|
Artist.many_through_many :related_artists, [[:albums_artists, :artist_id, :album_id], [:albums, :id, :id], [:albums_artists, :album_id, :artist_id]], :class=>Artist, :distinct=>true
|
|
282
|
-
Artist[@artist1.id].related_artists.map{|x| x.name}.sort.
|
|
283
|
-
Artist[@artist2.id].related_artists.map{|x| x.name}.sort.
|
|
284
|
-
Artist[@artist3.id].related_artists.map{|x| x.name}.sort.
|
|
285
|
-
Artist[@artist4.id].related_artists.map{|x| x.name}.sort.
|
|
285
|
+
Artist[@artist1.id].related_artists.map{|x| x.name}.sort.must_equal %w'1 2 4'
|
|
286
|
+
Artist[@artist2.id].related_artists.map{|x| x.name}.sort.must_equal %w'1 2 3'
|
|
287
|
+
Artist[@artist3.id].related_artists.map{|x| x.name}.sort.must_equal %w'2 3 4'
|
|
288
|
+
Artist[@artist4.id].related_artists.map{|x| x.name}.sort.must_equal %w'1 3 4'
|
|
286
289
|
|
|
287
290
|
Artist.plugin :prepared_statements_associations
|
|
288
|
-
Artist[@artist1.id].related_artists.map{|x| x.name}.sort.
|
|
289
|
-
Artist[@artist2.id].related_artists.map{|x| x.name}.sort.
|
|
290
|
-
Artist[@artist3.id].related_artists.map{|x| x.name}.sort.
|
|
291
|
-
Artist[@artist4.id].related_artists.map{|x| x.name}.sort.
|
|
291
|
+
Artist[@artist1.id].related_artists.map{|x| x.name}.sort.must_equal %w'1 2 4'
|
|
292
|
+
Artist[@artist2.id].related_artists.map{|x| x.name}.sort.must_equal %w'1 2 3'
|
|
293
|
+
Artist[@artist3.id].related_artists.map{|x| x.name}.sort.must_equal %w'2 3 4'
|
|
294
|
+
Artist[@artist4.id].related_artists.map{|x| x.name}.sort.must_equal %w'1 3 4'
|
|
292
295
|
|
|
293
|
-
Artist.filter(:id=>@artist1.id).eager(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.
|
|
294
|
-
Artist.filter(:id=>@artist2.id).eager(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.
|
|
295
|
-
Artist.filter(:id=>@artist3.id).eager(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.
|
|
296
|
-
Artist.filter(:id=>@artist4.id).eager(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.
|
|
296
|
+
Artist.filter(:id=>@artist1.id).eager(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.must_equal %w'1 2 4'
|
|
297
|
+
Artist.filter(:id=>@artist2.id).eager(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.must_equal %w'1 2 3'
|
|
298
|
+
Artist.filter(:id=>@artist3.id).eager(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.must_equal %w'2 3 4'
|
|
299
|
+
Artist.filter(:id=>@artist4.id).eager(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.must_equal %w'1 3 4'
|
|
297
300
|
|
|
298
|
-
Artist.filter(:artists__id=>@artist1.id).eager_graph(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.
|
|
299
|
-
Artist.filter(:artists__id=>@artist2.id).eager_graph(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.
|
|
300
|
-
Artist.filter(:artists__id=>@artist3.id).eager_graph(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.
|
|
301
|
-
Artist.filter(:artists__id=>@artist4.id).eager_graph(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.
|
|
301
|
+
Artist.filter(:artists__id=>@artist1.id).eager_graph(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.must_equal %w'1 2 4'
|
|
302
|
+
Artist.filter(:artists__id=>@artist2.id).eager_graph(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.must_equal %w'1 2 3'
|
|
303
|
+
Artist.filter(:artists__id=>@artist3.id).eager_graph(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.must_equal %w'2 3 4'
|
|
304
|
+
Artist.filter(:artists__id=>@artist4.id).eager_graph(:related_artists).all.map{|x| x.related_artists.map{|a| a.name}}.flatten.sort.must_equal %w'1 3 4'
|
|
302
305
|
|
|
303
|
-
Artist.filter(:related_artists=>@artist1).all.map{|a| a.name}.sort.
|
|
304
|
-
Artist.filter(:related_artists=>@artist2).all.map{|a| a.name}.sort.
|
|
305
|
-
Artist.filter(:related_artists=>@artist3).all.map{|a| a.name}.sort.
|
|
306
|
-
Artist.filter(:related_artists=>@artist4).all.map{|a| a.name}.sort.
|
|
306
|
+
Artist.filter(:related_artists=>@artist1).all.map{|a| a.name}.sort.must_equal %w'1 2 4'
|
|
307
|
+
Artist.filter(:related_artists=>@artist2).all.map{|a| a.name}.sort.must_equal %w'1 2 3'
|
|
308
|
+
Artist.filter(:related_artists=>@artist3).all.map{|a| a.name}.sort.must_equal %w'2 3 4'
|
|
309
|
+
Artist.filter(:related_artists=>@artist4).all.map{|a| a.name}.sort.must_equal %w'1 3 4'
|
|
307
310
|
|
|
308
|
-
Artist.exclude(:related_artists=>@artist1).all.map{|a| a.name}.sort.
|
|
309
|
-
Artist.exclude(:related_artists=>@artist2).all.map{|a| a.name}.sort.
|
|
310
|
-
Artist.exclude(:related_artists=>@artist3).all.map{|a| a.name}.sort.
|
|
311
|
-
Artist.exclude(:related_artists=>@artist4).all.map{|a| a.name}.sort.
|
|
311
|
+
Artist.exclude(:related_artists=>@artist1).all.map{|a| a.name}.sort.must_equal %w'3'
|
|
312
|
+
Artist.exclude(:related_artists=>@artist2).all.map{|a| a.name}.sort.must_equal %w'4'
|
|
313
|
+
Artist.exclude(:related_artists=>@artist3).all.map{|a| a.name}.sort.must_equal %w'1'
|
|
314
|
+
Artist.exclude(:related_artists=>@artist4).all.map{|a| a.name}.sort.must_equal %w'2'
|
|
312
315
|
|
|
313
|
-
Artist.filter(:related_artists=>[@artist1, @artist4]).all.map{|a| a.name}.sort.
|
|
314
|
-
Artist.exclude(:related_artists=>[@artist1, @artist4]).all.map{|a| a.name}.sort.
|
|
316
|
+
Artist.filter(:related_artists=>[@artist1, @artist4]).all.map{|a| a.name}.sort.must_equal %w'1 2 3 4'
|
|
317
|
+
Artist.exclude(:related_artists=>[@artist1, @artist4]).all.map{|a| a.name}.sort.must_equal %w''
|
|
315
318
|
|
|
316
|
-
Artist.filter(:related_artists=>Artist.filter(:id=>@artist1.id)).all.map{|a| a.name}.sort.
|
|
317
|
-
Artist.exclude(:related_artists=>Artist.filter(:id=>@artist1.id)).all.map{|a| a.name}.sort.
|
|
319
|
+
Artist.filter(:related_artists=>Artist.filter(:id=>@artist1.id)).all.map{|a| a.name}.sort.must_equal %w'1 2 4'
|
|
320
|
+
Artist.exclude(:related_artists=>Artist.filter(:id=>@artist1.id)).all.map{|a| a.name}.sort.must_equal %w'3'
|
|
318
321
|
|
|
319
322
|
c = self_join(Artist)
|
|
320
|
-
c.filter(:related_artists=>@artist1).all.map{|a| a.name}.sort.
|
|
321
|
-
c.filter(:related_artists=>@artist2).all.map{|a| a.name}.sort.
|
|
322
|
-
c.filter(:related_artists=>@artist3).all.map{|a| a.name}.sort.
|
|
323
|
-
c.filter(:related_artists=>@artist4).all.map{|a| a.name}.sort.
|
|
323
|
+
c.filter(:related_artists=>@artist1).all.map{|a| a.name}.sort.must_equal %w'1 2 4'
|
|
324
|
+
c.filter(:related_artists=>@artist2).all.map{|a| a.name}.sort.must_equal %w'1 2 3'
|
|
325
|
+
c.filter(:related_artists=>@artist3).all.map{|a| a.name}.sort.must_equal %w'2 3 4'
|
|
326
|
+
c.filter(:related_artists=>@artist4).all.map{|a| a.name}.sort.must_equal %w'1 3 4'
|
|
324
327
|
|
|
325
|
-
c.exclude(:related_artists=>@artist1).all.map{|a| a.name}.sort.
|
|
326
|
-
c.exclude(:related_artists=>@artist2).all.map{|a| a.name}.sort.
|
|
327
|
-
c.exclude(:related_artists=>@artist3).all.map{|a| a.name}.sort.
|
|
328
|
-
c.exclude(:related_artists=>@artist4).all.map{|a| a.name}.sort.
|
|
328
|
+
c.exclude(:related_artists=>@artist1).all.map{|a| a.name}.sort.must_equal %w'3'
|
|
329
|
+
c.exclude(:related_artists=>@artist2).all.map{|a| a.name}.sort.must_equal %w'4'
|
|
330
|
+
c.exclude(:related_artists=>@artist3).all.map{|a| a.name}.sort.must_equal %w'1'
|
|
331
|
+
c.exclude(:related_artists=>@artist4).all.map{|a| a.name}.sort.must_equal %w'2'
|
|
329
332
|
|
|
330
|
-
c.filter(:related_artists=>[@artist1, @artist4]).all.map{|a| a.name}.sort.
|
|
331
|
-
c.exclude(:related_artists=>[@artist1, @artist4]).all.map{|a| a.name}.sort.
|
|
333
|
+
c.filter(:related_artists=>[@artist1, @artist4]).all.map{|a| a.name}.sort.must_equal %w'1 2 3 4'
|
|
334
|
+
c.exclude(:related_artists=>[@artist1, @artist4]).all.map{|a| a.name}.sort.must_equal %w''
|
|
332
335
|
|
|
333
|
-
c.filter(:related_artists=>c.filter(:artists__id=>@artist1.id)).all.map{|a| a.name}.sort.
|
|
334
|
-
c.exclude(:related_artists=>c.filter(:artists__id=>@artist1.id)).all.map{|a| a.name}.sort.
|
|
336
|
+
c.filter(:related_artists=>c.filter(:artists__id=>@artist1.id)).all.map{|a| a.name}.sort.must_equal %w'1 2 4'
|
|
337
|
+
c.exclude(:related_artists=>c.filter(:artists__id=>@artist1.id)).all.map{|a| a.name}.sort.must_equal %w'3'
|
|
335
338
|
end
|
|
336
339
|
|
|
337
|
-
|
|
340
|
+
it "should handle extreme case with 5 join tables" do
|
|
338
341
|
Artist.many_through_many :related_albums, [[:albums_artists, :artist_id, :album_id], [:albums, :id, :id], [:albums_artists, :album_id, :artist_id], [:artists, :id, :id], [:albums_artists, :artist_id, :album_id]], :class=>Album, :distinct=>true
|
|
339
342
|
@db[:albums_artists].delete
|
|
340
343
|
@album1.add_artist(@artist1)
|
|
@@ -345,65 +348,65 @@ describe "Many Through Many Plugin" do
|
|
|
345
348
|
@album4.add_artist(@artist3)
|
|
346
349
|
@album4.add_artist(@artist4)
|
|
347
350
|
|
|
348
|
-
Artist[@artist1.id].related_albums.map{|x| x.name}.sort.
|
|
349
|
-
Artist[@artist2.id].related_albums.map{|x| x.name}.sort.
|
|
350
|
-
Artist[@artist3.id].related_albums.map{|x| x.name}.sort.
|
|
351
|
-
Artist[@artist4.id].related_albums.map{|x| x.name}.sort.
|
|
351
|
+
Artist[@artist1.id].related_albums.map{|x| x.name}.sort.must_equal %w'A B C'
|
|
352
|
+
Artist[@artist2.id].related_albums.map{|x| x.name}.sort.must_equal %w'A B C D'
|
|
353
|
+
Artist[@artist3.id].related_albums.map{|x| x.name}.sort.must_equal %w'A B D'
|
|
354
|
+
Artist[@artist4.id].related_albums.map{|x| x.name}.sort.must_equal %w'B D'
|
|
352
355
|
|
|
353
356
|
Artist.plugin :prepared_statements_associations
|
|
354
|
-
Artist[@artist1.id].related_albums.map{|x| x.name}.sort.
|
|
355
|
-
Artist[@artist2.id].related_albums.map{|x| x.name}.sort.
|
|
356
|
-
Artist[@artist3.id].related_albums.map{|x| x.name}.sort.
|
|
357
|
-
Artist[@artist4.id].related_albums.map{|x| x.name}.sort.
|
|
357
|
+
Artist[@artist1.id].related_albums.map{|x| x.name}.sort.must_equal %w'A B C'
|
|
358
|
+
Artist[@artist2.id].related_albums.map{|x| x.name}.sort.must_equal %w'A B C D'
|
|
359
|
+
Artist[@artist3.id].related_albums.map{|x| x.name}.sort.must_equal %w'A B D'
|
|
360
|
+
Artist[@artist4.id].related_albums.map{|x| x.name}.sort.must_equal %w'B D'
|
|
358
361
|
|
|
359
|
-
Artist.filter(:id=>@artist1.id).eager(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.
|
|
360
|
-
Artist.filter(:id=>@artist2.id).eager(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.
|
|
361
|
-
Artist.filter(:id=>@artist3.id).eager(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.
|
|
362
|
-
Artist.filter(:id=>@artist4.id).eager(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.
|
|
362
|
+
Artist.filter(:id=>@artist1.id).eager(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.must_equal %w'A B C'
|
|
363
|
+
Artist.filter(:id=>@artist2.id).eager(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.must_equal %w'A B C D'
|
|
364
|
+
Artist.filter(:id=>@artist3.id).eager(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.must_equal %w'A B D'
|
|
365
|
+
Artist.filter(:id=>@artist4.id).eager(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.must_equal %w'B D'
|
|
363
366
|
|
|
364
|
-
Artist.filter(:artists__id=>@artist1.id).eager_graph(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.
|
|
365
|
-
Artist.filter(:artists__id=>@artist2.id).eager_graph(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.
|
|
366
|
-
Artist.filter(:artists__id=>@artist3.id).eager_graph(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.
|
|
367
|
-
Artist.filter(:artists__id=>@artist4.id).eager_graph(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.
|
|
367
|
+
Artist.filter(:artists__id=>@artist1.id).eager_graph(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.must_equal %w'A B C'
|
|
368
|
+
Artist.filter(:artists__id=>@artist2.id).eager_graph(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.must_equal %w'A B C D'
|
|
369
|
+
Artist.filter(:artists__id=>@artist3.id).eager_graph(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.must_equal %w'A B D'
|
|
370
|
+
Artist.filter(:artists__id=>@artist4.id).eager_graph(:related_albums).all.map{|x| x.related_albums.map{|a| a.name}}.flatten.sort.must_equal %w'B D'
|
|
368
371
|
|
|
369
|
-
Artist.filter(:related_albums=>@album1).all.map{|a| a.name}.sort.
|
|
370
|
-
Artist.filter(:related_albums=>@album2).all.map{|a| a.name}.sort.
|
|
371
|
-
Artist.filter(:related_albums=>@album3).all.map{|a| a.name}.sort.
|
|
372
|
-
Artist.filter(:related_albums=>@album4).all.map{|a| a.name}.sort.
|
|
372
|
+
Artist.filter(:related_albums=>@album1).all.map{|a| a.name}.sort.must_equal %w'1 2 3'
|
|
373
|
+
Artist.filter(:related_albums=>@album2).all.map{|a| a.name}.sort.must_equal %w'1 2 3 4'
|
|
374
|
+
Artist.filter(:related_albums=>@album3).all.map{|a| a.name}.sort.must_equal %w'1 2'
|
|
375
|
+
Artist.filter(:related_albums=>@album4).all.map{|a| a.name}.sort.must_equal %w'2 3 4'
|
|
373
376
|
|
|
374
|
-
Artist.exclude(:related_albums=>@album1).all.map{|a| a.name}.sort.
|
|
375
|
-
Artist.exclude(:related_albums=>@album2).all.map{|a| a.name}.sort.
|
|
376
|
-
Artist.exclude(:related_albums=>@album3).all.map{|a| a.name}.sort.
|
|
377
|
-
Artist.exclude(:related_albums=>@album4).all.map{|a| a.name}.sort.
|
|
377
|
+
Artist.exclude(:related_albums=>@album1).all.map{|a| a.name}.sort.must_equal %w'4'
|
|
378
|
+
Artist.exclude(:related_albums=>@album2).all.map{|a| a.name}.sort.must_equal %w''
|
|
379
|
+
Artist.exclude(:related_albums=>@album3).all.map{|a| a.name}.sort.must_equal %w'3 4'
|
|
380
|
+
Artist.exclude(:related_albums=>@album4).all.map{|a| a.name}.sort.must_equal %w'1'
|
|
378
381
|
|
|
379
|
-
Artist.filter(:related_albums=>[@album1, @album3]).all.map{|a| a.name}.sort.
|
|
380
|
-
Artist.filter(:related_albums=>[@album3, @album4]).all.map{|a| a.name}.sort.
|
|
382
|
+
Artist.filter(:related_albums=>[@album1, @album3]).all.map{|a| a.name}.sort.must_equal %w'1 2 3'
|
|
383
|
+
Artist.filter(:related_albums=>[@album3, @album4]).all.map{|a| a.name}.sort.must_equal %w'1 2 3 4'
|
|
381
384
|
|
|
382
|
-
Artist.exclude(:related_albums=>[@album1, @album3]).all.map{|a| a.name}.sort.
|
|
383
|
-
Artist.exclude(:related_albums=>[@album2, @album4]).all.map{|a| a.name}.sort.
|
|
385
|
+
Artist.exclude(:related_albums=>[@album1, @album3]).all.map{|a| a.name}.sort.must_equal %w'4'
|
|
386
|
+
Artist.exclude(:related_albums=>[@album2, @album4]).all.map{|a| a.name}.sort.must_equal %w''
|
|
384
387
|
|
|
385
|
-
Artist.filter(:related_albums=>Album.filter(:id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.
|
|
386
|
-
Artist.exclude(:related_albums=>Album.filter(:id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.
|
|
388
|
+
Artist.filter(:related_albums=>Album.filter(:id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.must_equal %w'1 2 3'
|
|
389
|
+
Artist.exclude(:related_albums=>Album.filter(:id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.must_equal %w'4'
|
|
387
390
|
|
|
388
391
|
c = self_join(Artist)
|
|
389
|
-
c.filter(:related_albums=>@album1).all.map{|a| a.name}.sort.
|
|
390
|
-
c.filter(:related_albums=>@album2).all.map{|a| a.name}.sort.
|
|
391
|
-
c.filter(:related_albums=>@album3).all.map{|a| a.name}.sort.
|
|
392
|
-
c.filter(:related_albums=>@album4).all.map{|a| a.name}.sort.
|
|
392
|
+
c.filter(:related_albums=>@album1).all.map{|a| a.name}.sort.must_equal %w'1 2 3'
|
|
393
|
+
c.filter(:related_albums=>@album2).all.map{|a| a.name}.sort.must_equal %w'1 2 3 4'
|
|
394
|
+
c.filter(:related_albums=>@album3).all.map{|a| a.name}.sort.must_equal %w'1 2'
|
|
395
|
+
c.filter(:related_albums=>@album4).all.map{|a| a.name}.sort.must_equal %w'2 3 4'
|
|
393
396
|
|
|
394
|
-
c.exclude(:related_albums=>@album1).all.map{|a| a.name}.sort.
|
|
395
|
-
c.exclude(:related_albums=>@album2).all.map{|a| a.name}.sort.
|
|
396
|
-
c.exclude(:related_albums=>@album3).all.map{|a| a.name}.sort.
|
|
397
|
-
c.exclude(:related_albums=>@album4).all.map{|a| a.name}.sort.
|
|
397
|
+
c.exclude(:related_albums=>@album1).all.map{|a| a.name}.sort.must_equal %w'4'
|
|
398
|
+
c.exclude(:related_albums=>@album2).all.map{|a| a.name}.sort.must_equal %w''
|
|
399
|
+
c.exclude(:related_albums=>@album3).all.map{|a| a.name}.sort.must_equal %w'3 4'
|
|
400
|
+
c.exclude(:related_albums=>@album4).all.map{|a| a.name}.sort.must_equal %w'1'
|
|
398
401
|
|
|
399
|
-
c.filter(:related_albums=>[@album1, @album3]).all.map{|a| a.name}.sort.
|
|
400
|
-
c.filter(:related_albums=>[@album3, @album4]).all.map{|a| a.name}.sort.
|
|
402
|
+
c.filter(:related_albums=>[@album1, @album3]).all.map{|a| a.name}.sort.must_equal %w'1 2 3'
|
|
403
|
+
c.filter(:related_albums=>[@album3, @album4]).all.map{|a| a.name}.sort.must_equal %w'1 2 3 4'
|
|
401
404
|
|
|
402
|
-
c.exclude(:related_albums=>[@album1, @album3]).all.map{|a| a.name}.sort.
|
|
403
|
-
c.exclude(:related_albums=>[@album2, @album4]).all.map{|a| a.name}.sort.
|
|
405
|
+
c.exclude(:related_albums=>[@album1, @album3]).all.map{|a| a.name}.sort.must_equal %w'4'
|
|
406
|
+
c.exclude(:related_albums=>[@album2, @album4]).all.map{|a| a.name}.sort.must_equal %w''
|
|
404
407
|
|
|
405
|
-
c.filter(:related_albums=>self_join(Album).filter(:albums__id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.
|
|
406
|
-
c.exclude(:related_albums=>self_join(Album).filter(:albums__id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.
|
|
408
|
+
c.filter(:related_albums=>self_join(Album).filter(:albums__id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.must_equal %w'1 2 3'
|
|
409
|
+
c.exclude(:related_albums=>self_join(Album).filter(:albums__id=>[@album1.id, @album3.id])).all.map{|a| a.name}.sort.must_equal %w'4'
|
|
407
410
|
end
|
|
408
411
|
end
|
|
409
412
|
|
|
@@ -426,28 +429,28 @@ describe "Lazy Attributes plugin" do
|
|
|
426
429
|
Object.send(:remove_const, :Item)
|
|
427
430
|
end
|
|
428
431
|
|
|
429
|
-
|
|
430
|
-
Item.first.
|
|
432
|
+
it "should not include lazy attribute columns by default" do
|
|
433
|
+
Item.first.must_equal Item.load(:id=>1, :name=>'J')
|
|
431
434
|
end
|
|
432
435
|
|
|
433
|
-
|
|
434
|
-
Item.first.num.
|
|
436
|
+
it "should load lazy attribute on access" do
|
|
437
|
+
Item.first.num.must_equal 1
|
|
435
438
|
end
|
|
436
439
|
|
|
437
|
-
|
|
440
|
+
it "should typecast lazy attribute in setter" do
|
|
438
441
|
i = Item.new
|
|
439
442
|
i.num = '1'
|
|
440
|
-
i.num.
|
|
443
|
+
i.num.must_equal 1
|
|
441
444
|
end
|
|
442
445
|
|
|
443
|
-
|
|
446
|
+
it "should load lazy attribute for all items returned when accessing any item if using identity map " do
|
|
444
447
|
Item.create(:name=>'K', :num=>2)
|
|
445
448
|
a = Item.order(:name).all
|
|
446
|
-
a.
|
|
447
|
-
a.map{|x| x[:num]}.
|
|
448
|
-
a.first.num.
|
|
449
|
-
a.map{|x| x[:num]}.
|
|
450
|
-
a.last.num.
|
|
449
|
+
a.must_equal [Item.load(:id=>1, :name=>'J'), Item.load(:id=>2, :name=>'K')]
|
|
450
|
+
a.map{|x| x[:num]}.must_equal [nil, nil]
|
|
451
|
+
a.first.num.must_equal 1
|
|
452
|
+
a.map{|x| x[:num]}.must_equal [1, 2]
|
|
453
|
+
a.last.num.must_equal 2
|
|
451
454
|
end
|
|
452
455
|
end
|
|
453
456
|
|
|
@@ -455,7 +458,7 @@ describe "Tactical Eager Loading Plugin" do
|
|
|
455
458
|
before(:all) do
|
|
456
459
|
@db = DB
|
|
457
460
|
@db.instance_variable_set(:@schemas, {})
|
|
458
|
-
@db.drop_table?(:albums_artists)
|
|
461
|
+
@db.drop_table?(:albums_artists)
|
|
459
462
|
@db.create_table!(:artists) do
|
|
460
463
|
primary_key :id
|
|
461
464
|
String :name
|
|
@@ -494,16 +497,16 @@ describe "Tactical Eager Loading Plugin" do
|
|
|
494
497
|
@db.drop_table? :albums, :artists
|
|
495
498
|
end
|
|
496
499
|
|
|
497
|
-
|
|
500
|
+
it "should eagerly load associations for all items when accessing any item" do
|
|
498
501
|
a = Artist.order(:name).all
|
|
499
|
-
a.map{|x| x.associations}.
|
|
500
|
-
a.first.albums.
|
|
501
|
-
a.map{|x| x.associations}.
|
|
502
|
+
a.map{|x| x.associations}.must_equal [{}, {}, {}, {}]
|
|
503
|
+
a.first.albums.must_equal [@album1, @album2]
|
|
504
|
+
a.map{|x| x.associations}.must_equal [{:albums=>[@album1, @album2]}, {:albums=>[@album3]}, {:albums=>[@album4]}, {:albums=>[]}]
|
|
502
505
|
|
|
503
506
|
a = Album.order(:name).all
|
|
504
|
-
a.map{|x| x.associations}.
|
|
505
|
-
a.first.artist.
|
|
506
|
-
a.map{|x| x.associations}.
|
|
507
|
+
a.map{|x| x.associations}.must_equal [{}, {}, {}, {}]
|
|
508
|
+
a.first.artist.must_equal @artist1
|
|
509
|
+
a.map{|x| x.associations}.must_equal [{:artist=>@artist1}, {:artist=>@artist1}, {:artist=>@artist2}, {:artist=>@artist3}]
|
|
507
510
|
end
|
|
508
511
|
end
|
|
509
512
|
|
|
@@ -541,44 +544,47 @@ describe "Touch plugin" do
|
|
|
541
544
|
after(:all) do
|
|
542
545
|
@db.drop_table? :albums_artists, :albums, :artists
|
|
543
546
|
end
|
|
547
|
+
def around
|
|
548
|
+
DB.transaction(:rollback=>:always){super}
|
|
549
|
+
end
|
|
544
550
|
|
|
545
|
-
|
|
551
|
+
it "should update the timestamp column when touching the record" do
|
|
546
552
|
Album.plugin :touch
|
|
547
|
-
@album.updated_at.
|
|
553
|
+
@album.updated_at.must_equal nil
|
|
548
554
|
@album.touch
|
|
549
|
-
@album.updated_at.to_i.
|
|
555
|
+
@album.updated_at.to_i.must_be_close_to Time.now.to_i, 2
|
|
550
556
|
end
|
|
551
557
|
|
|
552
558
|
cspecify "should update the timestamp column for many_to_one associated records when the record is updated or destroyed", [:do, :sqlite], [:jdbc, :sqlite], [:swift] do
|
|
553
559
|
Album.many_to_one :artist
|
|
554
560
|
Album.plugin :touch, :associations=>:artist
|
|
555
|
-
@artist.updated_at.
|
|
561
|
+
@artist.updated_at.must_equal nil
|
|
556
562
|
@album.update(:name=>'B')
|
|
557
563
|
ua = @artist.reload.updated_at
|
|
558
564
|
if ua.is_a?(Time)
|
|
559
|
-
ua.to_i.
|
|
565
|
+
ua.to_i.must_be_close_to Time.now.to_i, 60
|
|
560
566
|
else
|
|
561
|
-
(DateTime.now - ua).
|
|
567
|
+
(DateTime.now - ua).must_be_close_to 0, 60.0/86400
|
|
562
568
|
end
|
|
563
569
|
@artist.update(:updated_at=>nil)
|
|
564
570
|
@album.destroy
|
|
565
571
|
if ua.is_a?(Time)
|
|
566
|
-
ua.to_i.
|
|
572
|
+
ua.to_i.must_be_close_to Time.now.to_i, 60
|
|
567
573
|
else
|
|
568
|
-
(DateTime.now - ua).
|
|
574
|
+
(DateTime.now - ua).must_be_close_to 0, 60.0/86400
|
|
569
575
|
end
|
|
570
576
|
end
|
|
571
577
|
|
|
572
578
|
cspecify "should update the timestamp column for one_to_many associated records when the record is updated", [:do, :sqlite], [:jdbc, :sqlite], [:swift] do
|
|
573
579
|
Artist.one_to_many :albums
|
|
574
580
|
Artist.plugin :touch, :associations=>:albums
|
|
575
|
-
@album.updated_at.
|
|
581
|
+
@album.updated_at.must_equal nil
|
|
576
582
|
@artist.update(:name=>'B')
|
|
577
583
|
ua = @album.reload.updated_at
|
|
578
584
|
if ua.is_a?(Time)
|
|
579
|
-
ua.to_i.
|
|
585
|
+
ua.to_i.must_be_close_to Time.now.to_i, 60
|
|
580
586
|
else
|
|
581
|
-
(DateTime.now - ua).
|
|
587
|
+
(DateTime.now - ua).must_be_close_to 0, 60.0/86400
|
|
582
588
|
end
|
|
583
589
|
end
|
|
584
590
|
|
|
@@ -586,13 +592,13 @@ describe "Touch plugin" do
|
|
|
586
592
|
Artist.many_to_many :albums
|
|
587
593
|
Artist.plugin :touch, :associations=>:albums
|
|
588
594
|
@artist.add_album(@album)
|
|
589
|
-
@album.updated_at.
|
|
595
|
+
@album.updated_at.must_equal nil
|
|
590
596
|
@artist.update(:name=>'B')
|
|
591
597
|
ua = @album.reload.updated_at
|
|
592
598
|
if ua.is_a?(Time)
|
|
593
|
-
ua.to_i.
|
|
599
|
+
ua.to_i.must_be_close_to Time.now.to_i, 60
|
|
594
600
|
else
|
|
595
|
-
(DateTime.now - ua).
|
|
601
|
+
(DateTime.now - ua).must_be_close_to 0, 60.0/86400
|
|
596
602
|
end
|
|
597
603
|
end
|
|
598
604
|
end
|
|
@@ -613,14 +619,14 @@ describe "Serialization plugin" do
|
|
|
613
619
|
Object.send(:remove_const, :Item)
|
|
614
620
|
end
|
|
615
621
|
|
|
616
|
-
|
|
622
|
+
it "should serialize and deserialize items as needed" do
|
|
617
623
|
i = Item.create(:stuff=>{:a=>1})
|
|
618
|
-
i.stuff.
|
|
624
|
+
i.stuff.must_equal(:a=>1)
|
|
619
625
|
i.stuff = [1, 2, 3]
|
|
620
626
|
i.save
|
|
621
|
-
Item.first.stuff.
|
|
627
|
+
Item.first.stuff.must_equal [1, 2, 3]
|
|
622
628
|
i.update(:stuff=>Item.new)
|
|
623
|
-
Item.first.stuff.
|
|
629
|
+
Item.first.stuff.must_equal Item.new
|
|
624
630
|
end
|
|
625
631
|
end
|
|
626
632
|
|
|
@@ -645,24 +651,24 @@ describe "OptimisticLocking plugin" do
|
|
|
645
651
|
Object.send(:remove_const, :Person)
|
|
646
652
|
end
|
|
647
653
|
|
|
648
|
-
|
|
654
|
+
it "should raise an error when updating a stale record" do
|
|
649
655
|
p1 = Person[@p.id]
|
|
650
656
|
p2 = Person[@p.id]
|
|
651
657
|
p1.update(:name=>'Jim')
|
|
652
|
-
proc{p2.update(:name=>'Bob')}.
|
|
658
|
+
proc{p2.update(:name=>'Bob')}.must_raise(Sequel::Plugins::OptimisticLocking::Error)
|
|
653
659
|
end
|
|
654
660
|
|
|
655
|
-
|
|
661
|
+
it "should raise an error when destroying a stale record" do
|
|
656
662
|
p1 = Person[@p.id]
|
|
657
663
|
p2 = Person[@p.id]
|
|
658
664
|
p1.update(:name=>'Jim')
|
|
659
|
-
proc{p2.destroy}.
|
|
665
|
+
proc{p2.destroy}.must_raise(Sequel::Plugins::OptimisticLocking::Error)
|
|
660
666
|
end
|
|
661
667
|
|
|
662
|
-
|
|
668
|
+
it "should not raise an error when updating the same record twice" do
|
|
663
669
|
p1 = Person[@p.id]
|
|
664
670
|
p1.update(:name=>'Jim')
|
|
665
|
-
|
|
671
|
+
p1.update(:name=>'Bob')
|
|
666
672
|
end
|
|
667
673
|
end
|
|
668
674
|
|
|
@@ -696,212 +702,212 @@ describe "Composition plugin" do
|
|
|
696
702
|
Object.send(:remove_const, :Event)
|
|
697
703
|
end
|
|
698
704
|
|
|
699
|
-
|
|
700
|
-
@e1.date.
|
|
701
|
-
@e2.date.
|
|
705
|
+
it "should return a composed object if the underlying columns have a value" do
|
|
706
|
+
@e1.date.must_equal Date.civil(2010, 2, 15)
|
|
707
|
+
@e2.date.must_equal nil
|
|
702
708
|
end
|
|
703
709
|
|
|
704
|
-
|
|
710
|
+
it "should decompose the object when saving the record" do
|
|
705
711
|
@e1.date = Date.civil(2009, 1, 2)
|
|
706
712
|
@e1.save
|
|
707
|
-
@e1.year.
|
|
708
|
-
@e1.month.
|
|
709
|
-
@e1.day.
|
|
713
|
+
@e1.year.must_equal 2009
|
|
714
|
+
@e1.month.must_equal 1
|
|
715
|
+
@e1.day.must_equal 2
|
|
710
716
|
end
|
|
711
717
|
|
|
712
|
-
|
|
718
|
+
it "should save all columns when saving changes" do
|
|
713
719
|
@e2.date = Date.civil(2009, 10, 2)
|
|
714
720
|
@e2.save_changes
|
|
715
721
|
@e2.reload
|
|
716
|
-
@e2.year.
|
|
717
|
-
@e2.month.
|
|
718
|
-
@e2.day.
|
|
722
|
+
@e2.year.must_equal 2009
|
|
723
|
+
@e2.month.must_equal 10
|
|
724
|
+
@e2.day.must_equal 2
|
|
719
725
|
end
|
|
720
726
|
end
|
|
721
727
|
|
|
722
728
|
describe "RcteTree Plugin" do
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
@a.children.
|
|
726
|
-
@b.children.
|
|
727
|
-
@aa.children.
|
|
728
|
-
@ab.children.
|
|
729
|
-
@ba.children.
|
|
730
|
-
@bb.children.
|
|
731
|
-
@aaa.children.
|
|
732
|
-
@aab.children.
|
|
733
|
-
@aba.children.
|
|
734
|
-
@abb.children.
|
|
735
|
-
@aaaa.children.
|
|
736
|
-
@aaab.children.
|
|
737
|
-
@aaaaa.children.
|
|
729
|
+
RcteTreePluginSpecs = shared_description do
|
|
730
|
+
it "should load all standard (not-CTE) methods correctly" do
|
|
731
|
+
@a.children.must_equal [@aa, @ab]
|
|
732
|
+
@b.children.must_equal [@ba, @bb]
|
|
733
|
+
@aa.children.must_equal [@aaa, @aab]
|
|
734
|
+
@ab.children.must_equal [@aba, @abb]
|
|
735
|
+
@ba.children.must_equal []
|
|
736
|
+
@bb.children.must_equal []
|
|
737
|
+
@aaa.children.must_equal [@aaaa, @aaab]
|
|
738
|
+
@aab.children.must_equal []
|
|
739
|
+
@aba.children.must_equal []
|
|
740
|
+
@abb.children.must_equal []
|
|
741
|
+
@aaaa.children.must_equal [@aaaaa]
|
|
742
|
+
@aaab.children.must_equal []
|
|
743
|
+
@aaaaa.children.must_equal []
|
|
738
744
|
|
|
739
|
-
@a.parent.
|
|
740
|
-
@b.parent.
|
|
741
|
-
@aa.parent.
|
|
742
|
-
@ab.parent.
|
|
743
|
-
@ba.parent.
|
|
744
|
-
@bb.parent.
|
|
745
|
-
@aaa.parent.
|
|
746
|
-
@aab.parent.
|
|
747
|
-
@aba.parent.
|
|
748
|
-
@abb.parent.
|
|
749
|
-
@aaaa.parent.
|
|
750
|
-
@aaab.parent.
|
|
751
|
-
@aaaaa.parent.
|
|
745
|
+
@a.parent.must_equal nil
|
|
746
|
+
@b.parent.must_equal nil
|
|
747
|
+
@aa.parent.must_equal @a
|
|
748
|
+
@ab.parent.must_equal @a
|
|
749
|
+
@ba.parent.must_equal @b
|
|
750
|
+
@bb.parent.must_equal @b
|
|
751
|
+
@aaa.parent.must_equal @aa
|
|
752
|
+
@aab.parent.must_equal @aa
|
|
753
|
+
@aba.parent.must_equal @ab
|
|
754
|
+
@abb.parent.must_equal @ab
|
|
755
|
+
@aaaa.parent.must_equal @aaa
|
|
756
|
+
@aaab.parent.must_equal @aaa
|
|
757
|
+
@aaaaa.parent.must_equal @aaaa
|
|
752
758
|
end
|
|
753
759
|
|
|
754
|
-
|
|
755
|
-
@a.descendants.
|
|
756
|
-
@b.descendants.
|
|
757
|
-
@aa.descendants.
|
|
758
|
-
@ab.descendants.
|
|
759
|
-
@ba.descendants.
|
|
760
|
-
@bb.descendants.
|
|
761
|
-
@aaa.descendants.
|
|
762
|
-
@aab.descendants.
|
|
763
|
-
@aba.descendants.
|
|
764
|
-
@abb.descendants.
|
|
765
|
-
@aaaa.descendants.
|
|
766
|
-
@aaab.descendants.
|
|
767
|
-
@aaaaa.descendants.
|
|
760
|
+
it "should load all ancestors and descendants lazily for a given instance" do
|
|
761
|
+
@a.descendants.must_equal [@aa, @aaa, @aaaa, @aaaaa, @aaab, @aab, @ab, @aba, @abb]
|
|
762
|
+
@b.descendants.must_equal [@ba, @bb]
|
|
763
|
+
@aa.descendants.must_equal [@aaa, @aaaa, @aaaaa, @aaab, @aab]
|
|
764
|
+
@ab.descendants.must_equal [@aba, @abb]
|
|
765
|
+
@ba.descendants.must_equal []
|
|
766
|
+
@bb.descendants.must_equal []
|
|
767
|
+
@aaa.descendants.must_equal [@aaaa, @aaaaa, @aaab]
|
|
768
|
+
@aab.descendants.must_equal []
|
|
769
|
+
@aba.descendants.must_equal []
|
|
770
|
+
@abb.descendants.must_equal []
|
|
771
|
+
@aaaa.descendants.must_equal [@aaaaa]
|
|
772
|
+
@aaab.descendants.must_equal []
|
|
773
|
+
@aaaaa.descendants.must_equal []
|
|
768
774
|
|
|
769
|
-
@a.ancestors.
|
|
770
|
-
@b.ancestors.
|
|
771
|
-
@aa.ancestors.
|
|
772
|
-
@ab.ancestors.
|
|
773
|
-
@ba.ancestors.
|
|
774
|
-
@bb.ancestors.
|
|
775
|
-
@aaa.ancestors.
|
|
776
|
-
@aab.ancestors.
|
|
777
|
-
@aba.ancestors.
|
|
778
|
-
@abb.ancestors.
|
|
779
|
-
@aaaa.ancestors.
|
|
780
|
-
@aaab.ancestors.
|
|
781
|
-
@aaaaa.ancestors.
|
|
775
|
+
@a.ancestors.must_equal []
|
|
776
|
+
@b.ancestors.must_equal []
|
|
777
|
+
@aa.ancestors.must_equal [@a]
|
|
778
|
+
@ab.ancestors.must_equal [@a]
|
|
779
|
+
@ba.ancestors.must_equal [@b]
|
|
780
|
+
@bb.ancestors.must_equal [@b]
|
|
781
|
+
@aaa.ancestors.must_equal [@a, @aa]
|
|
782
|
+
@aab.ancestors.must_equal [@a, @aa]
|
|
783
|
+
@aba.ancestors.must_equal [@a, @ab]
|
|
784
|
+
@abb.ancestors.must_equal [@a, @ab]
|
|
785
|
+
@aaaa.ancestors.must_equal [@a, @aa, @aaa]
|
|
786
|
+
@aaab.ancestors.must_equal [@a, @aa, @aaa]
|
|
787
|
+
@aaaaa.ancestors.must_equal [@a, @aa, @aaa, @aaaa]
|
|
782
788
|
end
|
|
783
789
|
|
|
784
|
-
|
|
790
|
+
it "should eagerly load all ancestors and descendants for a dataset" do
|
|
785
791
|
nodes = @Node.filter(@Node.primary_key=>[@a.pk, @b.pk, @aaa.pk]).order(:name).eager(:ancestors, :descendants).all
|
|
786
|
-
nodes.
|
|
787
|
-
nodes[0].descendants.
|
|
788
|
-
nodes[1].descendants.
|
|
789
|
-
nodes[2].descendants.
|
|
790
|
-
nodes[0].ancestors.
|
|
791
|
-
nodes[1].ancestors.
|
|
792
|
-
nodes[2].ancestors.
|
|
792
|
+
nodes.must_equal [@a, @aaa, @b]
|
|
793
|
+
nodes[0].descendants.must_equal [@aa, @aaa, @aaaa, @aaaaa, @aaab, @aab, @ab, @aba, @abb]
|
|
794
|
+
nodes[1].descendants.must_equal [@aaaa, @aaaaa, @aaab]
|
|
795
|
+
nodes[2].descendants.must_equal [@ba, @bb]
|
|
796
|
+
nodes[0].ancestors.must_equal []
|
|
797
|
+
nodes[1].ancestors.must_equal [@a, @aa]
|
|
798
|
+
nodes[2].ancestors.must_equal []
|
|
793
799
|
end
|
|
794
800
|
|
|
795
|
-
|
|
801
|
+
it "should eagerly load descendants to a given level" do
|
|
796
802
|
nodes = @Node.filter(@Node.primary_key=>[@a.pk, @b.pk, @aaa.pk]).order(:name).eager(:descendants=>1).all
|
|
797
|
-
nodes.
|
|
798
|
-
nodes[0].descendants.
|
|
799
|
-
nodes[1].descendants.
|
|
800
|
-
nodes[2].descendants.
|
|
803
|
+
nodes.must_equal [@a, @aaa, @b]
|
|
804
|
+
nodes[0].descendants.must_equal [@aa, @ab]
|
|
805
|
+
nodes[1].descendants.must_equal [@aaaa, @aaab]
|
|
806
|
+
nodes[2].descendants.must_equal [@ba, @bb]
|
|
801
807
|
|
|
802
808
|
nodes = @Node.filter(@Node.primary_key=>[@a.pk, @b.pk, @aaa.pk]).order(:name).eager(:descendants=>2).all
|
|
803
|
-
nodes.
|
|
804
|
-
nodes[0].descendants.
|
|
805
|
-
nodes[1].descendants.
|
|
806
|
-
nodes[2].descendants.
|
|
809
|
+
nodes.must_equal [@a, @aaa, @b]
|
|
810
|
+
nodes[0].descendants.must_equal [@aa, @aaa, @aab, @ab, @aba, @abb]
|
|
811
|
+
nodes[1].descendants.must_equal [@aaaa, @aaaaa, @aaab]
|
|
812
|
+
nodes[2].descendants.must_equal [@ba, @bb]
|
|
807
813
|
end
|
|
808
814
|
|
|
809
|
-
|
|
815
|
+
it "should populate all :children associations when eagerly loading descendants for a dataset" do
|
|
810
816
|
nodes = @Node.filter(@Node.primary_key=>[@a.pk, @b.pk, @aaa.pk]).order(:name).eager(:descendants).all
|
|
811
|
-
nodes[0].associations[:children].
|
|
812
|
-
nodes[1].associations[:children].
|
|
813
|
-
nodes[2].associations[:children].
|
|
814
|
-
nodes[0].associations[:children].map{|c1| c1.associations[:children]}.
|
|
815
|
-
nodes[1].associations[:children].map{|c1| c1.associations[:children]}.
|
|
816
|
-
nodes[2].associations[:children].map{|c1| c1.associations[:children]}.
|
|
817
|
-
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.
|
|
818
|
-
nodes[1].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.
|
|
819
|
-
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:children]}}}.
|
|
820
|
-
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:children].map{|c4| c4.associations[:children]}}}}.
|
|
817
|
+
nodes[0].associations[:children].must_equal [@aa, @ab]
|
|
818
|
+
nodes[1].associations[:children].must_equal [@aaaa, @aaab]
|
|
819
|
+
nodes[2].associations[:children].must_equal [@ba, @bb]
|
|
820
|
+
nodes[0].associations[:children].map{|c1| c1.associations[:children]}.must_equal [[@aaa, @aab], [@aba, @abb]]
|
|
821
|
+
nodes[1].associations[:children].map{|c1| c1.associations[:children]}.must_equal [[@aaaaa], []]
|
|
822
|
+
nodes[2].associations[:children].map{|c1| c1.associations[:children]}.must_equal [[], []]
|
|
823
|
+
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.must_equal [[[@aaaa, @aaab], []], [[], []]]
|
|
824
|
+
nodes[1].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.must_equal [[[]], []]
|
|
825
|
+
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:children]}}}.must_equal [[[[@aaaaa], []], []], [[], []]]
|
|
826
|
+
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:children].map{|c4| c4.associations[:children]}}}}.must_equal [[[[[]], []], []], [[], []]]
|
|
821
827
|
end
|
|
822
828
|
|
|
823
|
-
|
|
829
|
+
it "should not populate :children associations for final level when loading descendants to a given level" do
|
|
824
830
|
nodes = @Node.filter(@Node.primary_key=>[@a.pk, @b.pk, @aaa.pk]).order(:name).eager(:descendants=>1).all
|
|
825
|
-
nodes[0].associations[:children].
|
|
826
|
-
nodes[0].associations[:children].map{|c1| c1.associations[:children]}.
|
|
827
|
-
nodes[1].associations[:children].
|
|
828
|
-
nodes[1].associations[:children].map{|c1| c1.associations[:children]}.
|
|
829
|
-
nodes[2].associations[:children].
|
|
830
|
-
nodes[2].associations[:children].map{|c1| c1.associations[:children]}.
|
|
831
|
+
nodes[0].associations[:children].must_equal [@aa, @ab]
|
|
832
|
+
nodes[0].associations[:children].map{|c1| c1.associations[:children]}.must_equal [nil, nil]
|
|
833
|
+
nodes[1].associations[:children].must_equal [@aaaa, @aaab]
|
|
834
|
+
nodes[1].associations[:children].map{|c1| c1.associations[:children]}.must_equal [nil, nil]
|
|
835
|
+
nodes[2].associations[:children].must_equal [@ba, @bb]
|
|
836
|
+
nodes[2].associations[:children].map{|c1| c1.associations[:children]}.must_equal [nil, nil]
|
|
831
837
|
|
|
832
|
-
nodes[0].associations[:children].map{|c1| c1.children}.
|
|
833
|
-
nodes[1].associations[:children].map{|c1| c1.children}.
|
|
834
|
-
nodes[2].associations[:children].map{|c1| c1.children}.
|
|
838
|
+
nodes[0].associations[:children].map{|c1| c1.children}.must_equal [[@aaa, @aab], [@aba, @abb]]
|
|
839
|
+
nodes[1].associations[:children].map{|c1| c1.children}.must_equal [[@aaaaa], []]
|
|
840
|
+
nodes[2].associations[:children].map{|c1| c1.children}.must_equal [[], []]
|
|
835
841
|
|
|
836
842
|
nodes = @Node.filter(@Node.primary_key=>[@a.pk, @b.pk, @aaa.pk]).order(:name).eager(:descendants=>2).all
|
|
837
|
-
nodes[0].associations[:children].
|
|
838
|
-
nodes[0].associations[:children].map{|c1| c1.associations[:children]}.
|
|
839
|
-
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.
|
|
840
|
-
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| (cc2 = c2.associations[:children]) ? cc2.map{|c3| c3.associations[:children]} : nil}}.
|
|
841
|
-
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| (cc2 = c2.associations[:children]) ? cc2.map{|c3| (cc3 = c3.associations[:children]) ? cc3.map{|c4| c4.associations[:children]} : nil} : nil}}.
|
|
843
|
+
nodes[0].associations[:children].must_equal [@aa, @ab]
|
|
844
|
+
nodes[0].associations[:children].map{|c1| c1.associations[:children]}.must_equal [[@aaa, @aab], [@aba, @abb]]
|
|
845
|
+
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.must_equal [[[@aaaa, @aaab], nil], [nil, nil]]
|
|
846
|
+
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| (cc2 = c2.associations[:children]) ? cc2.map{|c3| c3.associations[:children]} : nil}}.must_equal [[[[@aaaaa], []], nil], [nil, nil]]
|
|
847
|
+
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| (cc2 = c2.associations[:children]) ? cc2.map{|c3| (cc3 = c3.associations[:children]) ? cc3.map{|c4| c4.associations[:children]} : nil} : nil}}.must_equal [[[[nil], []], nil], [nil, nil]]
|
|
842
848
|
|
|
843
|
-
nodes[1].associations[:children].
|
|
844
|
-
nodes[1].associations[:children].map{|c1| c1.associations[:children]}.
|
|
845
|
-
nodes[1].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.
|
|
849
|
+
nodes[1].associations[:children].must_equal [@aaaa, @aaab]
|
|
850
|
+
nodes[1].associations[:children].map{|c1| c1.associations[:children]}.must_equal [[@aaaaa], []]
|
|
851
|
+
nodes[1].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.must_equal [[nil], []]
|
|
846
852
|
|
|
847
|
-
nodes[2].associations[:children].
|
|
848
|
-
nodes[2].associations[:children].map{|c1| c1.associations[:children]}.
|
|
853
|
+
nodes[2].associations[:children].must_equal [@ba, @bb]
|
|
854
|
+
nodes[2].associations[:children].map{|c1| c1.associations[:children]}.must_equal [[], []]
|
|
849
855
|
|
|
850
|
-
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.children}}.
|
|
851
|
-
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.children.map{|c3| c3.children}}}.
|
|
852
|
-
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.children.map{|c3| c3.children.map{|c4| c4.children}}}}.
|
|
853
|
-
nodes[1].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.children}}.
|
|
856
|
+
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.children}}.must_equal [[[@aaaa, @aaab], []], [[], []]]
|
|
857
|
+
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.children.map{|c3| c3.children}}}.must_equal [[[[@aaaaa], []], []], [[], []]]
|
|
858
|
+
nodes[0].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.children.map{|c3| c3.children.map{|c4| c4.children}}}}.must_equal [[[[[]], []], []], [[], []]]
|
|
859
|
+
nodes[1].associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.children}}.must_equal [[[]], []]
|
|
854
860
|
end
|
|
855
861
|
|
|
856
|
-
|
|
862
|
+
it "should populate all :children associations when lazily loading descendants" do
|
|
857
863
|
@a.descendants
|
|
858
|
-
@a.associations[:children].
|
|
859
|
-
@a.associations[:children].map{|c1| c1.associations[:children]}.
|
|
860
|
-
@a.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.
|
|
861
|
-
@a.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:children]}}}.
|
|
862
|
-
@a.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:children].map{|c4| c4.associations[:children]}}}}.
|
|
864
|
+
@a.associations[:children].must_equal [@aa, @ab]
|
|
865
|
+
@a.associations[:children].map{|c1| c1.associations[:children]}.must_equal [[@aaa, @aab], [@aba, @abb]]
|
|
866
|
+
@a.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.must_equal [[[@aaaa, @aaab], []], [[], []]]
|
|
867
|
+
@a.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:children]}}}.must_equal [[[[@aaaaa], []], []], [[], []]]
|
|
868
|
+
@a.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:children].map{|c4| c4.associations[:children]}}}}.must_equal [[[[[]], []], []], [[], []]]
|
|
863
869
|
|
|
864
870
|
@b.descendants
|
|
865
|
-
@b.associations[:children].
|
|
866
|
-
@b.associations[:children].map{|c1| c1.associations[:children]}.
|
|
871
|
+
@b.associations[:children].must_equal [@ba, @bb]
|
|
872
|
+
@b.associations[:children].map{|c1| c1.associations[:children]}.must_equal [[], []]
|
|
867
873
|
|
|
868
874
|
@aaa.descendants
|
|
869
|
-
@aaa.associations[:children].map{|c1| c1.associations[:children]}.
|
|
870
|
-
@aaa.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.
|
|
875
|
+
@aaa.associations[:children].map{|c1| c1.associations[:children]}.must_equal [[@aaaaa], []]
|
|
876
|
+
@aaa.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.must_equal [[[]], []]
|
|
871
877
|
end
|
|
872
878
|
|
|
873
|
-
|
|
879
|
+
it "should populate all :parent associations when eagerly loading ancestors for a dataset" do
|
|
874
880
|
nodes = @Node.filter(@Node.primary_key=>[@a.pk, @ba.pk, @aaa.pk, @aaaaa.pk]).order(:name).eager(:ancestors).all
|
|
875
|
-
nodes[0].associations.fetch(:parent, 1).
|
|
876
|
-
nodes[1].associations[:parent].
|
|
877
|
-
nodes[1].associations[:parent].associations[:parent].
|
|
878
|
-
nodes[1].associations[:parent].associations[:parent].associations.fetch(:parent, 1).
|
|
879
|
-
nodes[2].associations[:parent].
|
|
880
|
-
nodes[2].associations[:parent].associations[:parent].
|
|
881
|
-
nodes[2].associations[:parent].associations[:parent].associations[:parent].
|
|
882
|
-
nodes[2].associations[:parent].associations[:parent].associations[:parent].associations[:parent].
|
|
883
|
-
nodes[2].associations[:parent].associations[:parent].associations[:parent].associations[:parent].associations.fetch(:parent, 1).
|
|
884
|
-
nodes[3].associations[:parent].
|
|
885
|
-
nodes[3].associations[:parent].associations.fetch(:parent, 1).
|
|
881
|
+
nodes[0].associations.fetch(:parent, 1).must_equal nil
|
|
882
|
+
nodes[1].associations[:parent].must_equal @aa
|
|
883
|
+
nodes[1].associations[:parent].associations[:parent].must_equal @a
|
|
884
|
+
nodes[1].associations[:parent].associations[:parent].associations.fetch(:parent, 1).must_equal nil
|
|
885
|
+
nodes[2].associations[:parent].must_equal @aaaa
|
|
886
|
+
nodes[2].associations[:parent].associations[:parent].must_equal @aaa
|
|
887
|
+
nodes[2].associations[:parent].associations[:parent].associations[:parent].must_equal @aa
|
|
888
|
+
nodes[2].associations[:parent].associations[:parent].associations[:parent].associations[:parent].must_equal @a
|
|
889
|
+
nodes[2].associations[:parent].associations[:parent].associations[:parent].associations[:parent].associations.fetch(:parent, 1).must_equal nil
|
|
890
|
+
nodes[3].associations[:parent].must_equal @b
|
|
891
|
+
nodes[3].associations[:parent].associations.fetch(:parent, 1).must_equal nil
|
|
886
892
|
end
|
|
887
893
|
|
|
888
|
-
|
|
894
|
+
it "should populate all :parent associations when lazily loading ancestors" do
|
|
889
895
|
@a.reload
|
|
890
896
|
@a.ancestors
|
|
891
|
-
@a.associations[:parent].
|
|
897
|
+
@a.associations[:parent].must_equal nil
|
|
892
898
|
|
|
893
899
|
@ba.reload
|
|
894
900
|
@ba.ancestors
|
|
895
|
-
@ba.associations[:parent].
|
|
896
|
-
@ba.associations[:parent].associations.fetch(:parent, 1).
|
|
901
|
+
@ba.associations[:parent].must_equal @b
|
|
902
|
+
@ba.associations[:parent].associations.fetch(:parent, 1).must_equal nil
|
|
897
903
|
|
|
898
904
|
@ba.reload
|
|
899
905
|
@aaaaa.ancestors
|
|
900
|
-
@aaaaa.associations[:parent].
|
|
901
|
-
@aaaaa.associations[:parent].associations[:parent].
|
|
902
|
-
@aaaaa.associations[:parent].associations[:parent].associations[:parent].
|
|
903
|
-
@aaaaa.associations[:parent].associations[:parent].associations[:parent].associations[:parent].
|
|
904
|
-
@aaaaa.associations[:parent].associations[:parent].associations[:parent].associations[:parent].associations.fetch(:parent, 1).
|
|
906
|
+
@aaaaa.associations[:parent].must_equal @aaaa
|
|
907
|
+
@aaaaa.associations[:parent].associations[:parent].must_equal @aaa
|
|
908
|
+
@aaaaa.associations[:parent].associations[:parent].associations[:parent].must_equal @aa
|
|
909
|
+
@aaaaa.associations[:parent].associations[:parent].associations[:parent].associations[:parent].must_equal @a
|
|
910
|
+
@aaaaa.associations[:parent].associations[:parent].associations[:parent].associations[:parent].associations.fetch(:parent, 1).must_equal nil
|
|
905
911
|
end
|
|
906
912
|
end
|
|
907
913
|
|
|
@@ -938,18 +944,18 @@ describe "RcteTree Plugin" do
|
|
|
938
944
|
@db.drop_table? :nodes
|
|
939
945
|
end
|
|
940
946
|
|
|
941
|
-
|
|
947
|
+
include RcteTreePluginSpecs
|
|
942
948
|
|
|
943
|
-
|
|
949
|
+
it "should work correctly if not all columns are selected" do
|
|
944
950
|
c = Class.new(Sequel::Model(@db[:nodes]))
|
|
945
951
|
c.plugin :rcte_tree, :order=>:name
|
|
946
952
|
c.plugin :lazy_attributes, :name
|
|
947
|
-
c[:name=>'aaaa'].descendants.
|
|
948
|
-
c[:name=>'aa'].ancestors.
|
|
953
|
+
c[:name=>'aaaa'].descendants.must_equal [c.load(:parent_id=>11, :id=>13)]
|
|
954
|
+
c[:name=>'aa'].ancestors.must_equal [c.load(:parent_id=>nil, :id=>1)]
|
|
949
955
|
nodes = c.filter(:id=>[@a.id, @b.id, @aaa.id]).order(:name).eager(:ancestors, :descendants).all
|
|
950
|
-
nodes.
|
|
951
|
-
nodes[2].descendants.
|
|
952
|
-
nodes[1].ancestors.
|
|
956
|
+
nodes.must_equal [{:parent_id=>nil, :id=>1}, {:parent_id=>3, :id=>7}, {:parent_id=>nil, :id=>2}].map{|x| c.load(x)}
|
|
957
|
+
nodes[2].descendants.must_equal [{:parent_id=>2, :id=>5}, {:parent_id=>2, :id=>6}].map{|x| c.load(x)}
|
|
958
|
+
nodes[1].ancestors.must_equal [{:parent_id=>nil, :id=>1}, {:parent_id=>1, :id=>3}].map{|x| c.load(x)}
|
|
953
959
|
end
|
|
954
960
|
end
|
|
955
961
|
|
|
@@ -986,7 +992,7 @@ describe "RcteTree Plugin" do
|
|
|
986
992
|
@db.drop_table? :nodes
|
|
987
993
|
end
|
|
988
994
|
|
|
989
|
-
|
|
995
|
+
include RcteTreePluginSpecs
|
|
990
996
|
end
|
|
991
997
|
end if DB.dataset.supports_cte? and !Sequel.guarded?(:db2)
|
|
992
998
|
|
|
@@ -1014,42 +1020,42 @@ describe "Instance Filters plugin" do
|
|
|
1014
1020
|
Object.send(:remove_const, :Item)
|
|
1015
1021
|
end
|
|
1016
1022
|
|
|
1017
|
-
|
|
1023
|
+
it "should not raise an error if saving only updates one row" do
|
|
1018
1024
|
@i.save
|
|
1019
|
-
@i.refresh.name.
|
|
1025
|
+
@i.refresh.name.must_equal 'K'
|
|
1020
1026
|
end
|
|
1021
1027
|
|
|
1022
|
-
|
|
1028
|
+
it "should raise error if saving doesn't update a row" do
|
|
1023
1029
|
@i.this.update(:number=>2)
|
|
1024
|
-
proc{@i.save}.
|
|
1030
|
+
proc{@i.save}.must_raise(Sequel::NoExistingObject)
|
|
1025
1031
|
end
|
|
1026
1032
|
|
|
1027
|
-
|
|
1033
|
+
it "should apply all instance filters" do
|
|
1028
1034
|
@i.instance_filter{cost <= 2}
|
|
1029
1035
|
@i.this.update(:number=>2)
|
|
1030
|
-
proc{@i.save}.
|
|
1036
|
+
proc{@i.save}.must_raise(Sequel::NoExistingObject)
|
|
1031
1037
|
@i.this.update(:number=>1, :cost=>3)
|
|
1032
|
-
proc{@i.save}.
|
|
1038
|
+
proc{@i.save}.must_raise(Sequel::NoExistingObject)
|
|
1033
1039
|
@i.this.update(:cost=>2)
|
|
1034
1040
|
@i.save
|
|
1035
|
-
@i.refresh.name.
|
|
1041
|
+
@i.refresh.name.must_equal 'K'
|
|
1036
1042
|
end
|
|
1037
1043
|
|
|
1038
|
-
|
|
1044
|
+
it "should clear instance filters after successful save" do
|
|
1039
1045
|
@i.save
|
|
1040
1046
|
@i.this.update(:number=>2)
|
|
1041
1047
|
@i.update(:name=>'L')
|
|
1042
|
-
@i.refresh.name.
|
|
1048
|
+
@i.refresh.name.must_equal 'L'
|
|
1043
1049
|
end
|
|
1044
1050
|
|
|
1045
|
-
|
|
1051
|
+
it "should not raise an error if deleting only deletes one row" do
|
|
1046
1052
|
@i.destroy
|
|
1047
|
-
proc{@i.refresh}.
|
|
1053
|
+
proc{@i.refresh}.must_raise(Sequel::Error, 'Record not found')
|
|
1048
1054
|
end
|
|
1049
1055
|
|
|
1050
|
-
|
|
1056
|
+
it "should raise error if destroying doesn't delete a row" do
|
|
1051
1057
|
@i.this.update(:number=>2)
|
|
1052
|
-
proc{@i.destroy}.
|
|
1058
|
+
proc{@i.destroy}.must_raise(Sequel::NoExistingObject)
|
|
1053
1059
|
end
|
|
1054
1060
|
end
|
|
1055
1061
|
|
|
@@ -1074,40 +1080,40 @@ describe "UpdatePrimaryKey plugin" do
|
|
|
1074
1080
|
@db.drop_table?(:t)
|
|
1075
1081
|
end
|
|
1076
1082
|
|
|
1077
|
-
|
|
1083
|
+
it "should handle regular updates" do
|
|
1078
1084
|
@c.first.update(:b=>4)
|
|
1079
|
-
@db[:t].all.
|
|
1085
|
+
@db[:t].all.must_equal [{:a=>1, :b=>4}]
|
|
1080
1086
|
@c.first.set(:b=>5).save
|
|
1081
|
-
@db[:t].all.
|
|
1087
|
+
@db[:t].all.must_equal [{:a=>1, :b=>5}]
|
|
1082
1088
|
@c.first.set(:b=>6).save(:columns=>:b)
|
|
1083
|
-
@db[:t].all.
|
|
1089
|
+
@db[:t].all.must_equal [{:a=>1, :b=>6}]
|
|
1084
1090
|
end
|
|
1085
1091
|
|
|
1086
|
-
|
|
1092
|
+
it "should handle updating the primary key field with another field" do
|
|
1087
1093
|
@c.first.update(:a=>2, :b=>4)
|
|
1088
|
-
@db[:t].all.
|
|
1094
|
+
@db[:t].all.must_equal [{:a=>2, :b=>4}]
|
|
1089
1095
|
end
|
|
1090
1096
|
|
|
1091
|
-
|
|
1097
|
+
it "should handle updating just the primary key field when saving changes" do
|
|
1092
1098
|
@c.first.update(:a=>2)
|
|
1093
|
-
@db[:t].all.
|
|
1099
|
+
@db[:t].all.must_equal [{:a=>2, :b=>3}]
|
|
1094
1100
|
@c.first.set(:a=>3).save(:columns=>:a)
|
|
1095
|
-
@db[:t].all.
|
|
1101
|
+
@db[:t].all.must_equal [{:a=>3, :b=>3}]
|
|
1096
1102
|
end
|
|
1097
1103
|
|
|
1098
|
-
|
|
1104
|
+
it "should handle saving after modifying the primary key field with another field" do
|
|
1099
1105
|
@c.first.set(:a=>2, :b=>4).save
|
|
1100
|
-
@db[:t].all.
|
|
1106
|
+
@db[:t].all.must_equal [{:a=>2, :b=>4}]
|
|
1101
1107
|
end
|
|
1102
1108
|
|
|
1103
|
-
|
|
1109
|
+
it "should handle saving after modifying just the primary key field" do
|
|
1104
1110
|
@c.first.set(:a=>2).save
|
|
1105
|
-
@db[:t].all.
|
|
1111
|
+
@db[:t].all.must_equal [{:a=>2, :b=>3}]
|
|
1106
1112
|
end
|
|
1107
1113
|
|
|
1108
|
-
|
|
1114
|
+
it "should handle saving after updating the primary key" do
|
|
1109
1115
|
@c.first.update(:a=>2).update(:b=>4).set(:b=>5).save
|
|
1110
|
-
@db[:t].all.
|
|
1116
|
+
@db[:t].all.must_equal [{:a=>2, :b=>5}]
|
|
1111
1117
|
end
|
|
1112
1118
|
end
|
|
1113
1119
|
|
|
@@ -1236,203 +1242,203 @@ describe "AssociationPks plugin" do
|
|
|
1236
1242
|
[:Artist, :Album, :Tag, :Vocalist, :Instrument, :Hit].each{|s| Object.send(:remove_const, s)}
|
|
1237
1243
|
end
|
|
1238
1244
|
|
|
1239
|
-
|
|
1240
|
-
Artist.order(:id).all.map{|a| a.album_pks}.
|
|
1245
|
+
it "should return correct associated pks for one_to_many associations" do
|
|
1246
|
+
Artist.order(:id).all.map{|a| a.album_pks}.must_equal [[@al1, @al2, @al3], []]
|
|
1241
1247
|
end
|
|
1242
1248
|
|
|
1243
|
-
|
|
1244
|
-
Album.order(:id).all.map{|a| a.tag_pks.sort}.
|
|
1249
|
+
it "should return correct associated pks for many_to_many associations" do
|
|
1250
|
+
Album.order(:id).all.map{|a| a.tag_pks.sort}.must_equal [[@t1, @t2, @t3], [@t2], []]
|
|
1245
1251
|
end
|
|
1246
1252
|
|
|
1247
|
-
|
|
1253
|
+
it "should return correct associated right-side cpks for one_to_many associations" do
|
|
1248
1254
|
Album.one_to_many :vocalists, :order=>:first
|
|
1249
|
-
Album.order(:id).all.map{|a| a.vocalist_pks.sort}.
|
|
1255
|
+
Album.order(:id).all.map{|a| a.vocalist_pks.sort}.must_equal [[@v1, @v2, @v3], [], []]
|
|
1250
1256
|
end
|
|
1251
1257
|
|
|
1252
|
-
|
|
1258
|
+
it "should return correct associated right-side cpks for many_to_many associations" do
|
|
1253
1259
|
Album.many_to_many :vocalists, :join_table=>:albums_vocalists, :right_key=>[:first, :last], :order=>:first
|
|
1254
|
-
Album.order(:id).all.map{|a| a.vocalist_pks.sort}.
|
|
1260
|
+
Album.order(:id).all.map{|a| a.vocalist_pks.sort}.must_equal [[@v1, @v2, @v3], [@v2], []]
|
|
1255
1261
|
end
|
|
1256
1262
|
|
|
1257
|
-
|
|
1263
|
+
it "should return correct associated pks for left-side cpks for one_to_many associations" do
|
|
1258
1264
|
Vocalist.one_to_many :instruments, :key=>[:first, :last], :order=>:id
|
|
1259
|
-
Vocalist.order(:first, :last).all.map{|a| a.instrument_pks.sort}.
|
|
1265
|
+
Vocalist.order(:first, :last).all.map{|a| a.instrument_pks.sort}.must_equal [[@i1, @i2, @i3], [], []]
|
|
1260
1266
|
end
|
|
1261
1267
|
|
|
1262
|
-
|
|
1268
|
+
it "should return correct associated pks for left-side cpks for many_to_many associations" do
|
|
1263
1269
|
Vocalist.many_to_many :instruments, :join_table=>:vocalists_instruments, :left_key=>[:first, :last], :order=>:id
|
|
1264
|
-
Vocalist.order(:first, :last).all.map{|a| a.instrument_pks.sort}.
|
|
1270
|
+
Vocalist.order(:first, :last).all.map{|a| a.instrument_pks.sort}.must_equal [[@i1, @i2, @i3], [@i2], []]
|
|
1265
1271
|
end
|
|
1266
1272
|
|
|
1267
|
-
|
|
1273
|
+
it "should return correct associated right-side cpks for left-side cpks for one_to_many associations" do
|
|
1268
1274
|
Vocalist.one_to_many :hits, :key=>[:first, :last], :order=>:week
|
|
1269
|
-
Vocalist.order(:first, :last).all.map{|a| a.hit_pks.sort}.
|
|
1275
|
+
Vocalist.order(:first, :last).all.map{|a| a.hit_pks.sort}.must_equal [[@h1, @h2, @h3], [], []]
|
|
1270
1276
|
end
|
|
1271
1277
|
|
|
1272
|
-
|
|
1278
|
+
it "should return correct associated right-side cpks for left-side cpks for many_to_many associations" do
|
|
1273
1279
|
Vocalist.many_to_many :hits, :join_table=>:vocalists_hits, :left_key=>[:first, :last], :right_key=>[:year, :week], :order=>:week
|
|
1274
|
-
Vocalist.order(:first, :last).all.map{|a| a.hit_pks.sort}.
|
|
1280
|
+
Vocalist.order(:first, :last).all.map{|a| a.hit_pks.sort}.must_equal [[@h1, @h2, @h3], [@h2], []]
|
|
1275
1281
|
end
|
|
1276
1282
|
|
|
1277
|
-
|
|
1283
|
+
it "should set associated pks correctly for a one_to_many association" do
|
|
1278
1284
|
Artist.use_transactions = true
|
|
1279
|
-
Album.order(:id).select_map(:artist_id).
|
|
1285
|
+
Album.order(:id).select_map(:artist_id).must_equal [@ar1, @ar1, @ar1]
|
|
1280
1286
|
|
|
1281
1287
|
Artist[@ar2].album_pks = [@t1, @t3]
|
|
1282
|
-
Artist[@ar1].album_pks.
|
|
1283
|
-
Album.order(:id).select_map(:artist_id).
|
|
1288
|
+
Artist[@ar1].album_pks.must_equal [@t2]
|
|
1289
|
+
Album.order(:id).select_map(:artist_id).must_equal [@ar2, @ar1, @ar2]
|
|
1284
1290
|
|
|
1285
1291
|
Artist[@ar1].album_pks = [@t1]
|
|
1286
|
-
Artist[@ar2].album_pks.
|
|
1287
|
-
Album.order(:id).select_map(:artist_id).
|
|
1292
|
+
Artist[@ar2].album_pks.must_equal [@t3]
|
|
1293
|
+
Album.order(:id).select_map(:artist_id).must_equal [@ar1, nil, @ar2]
|
|
1288
1294
|
|
|
1289
1295
|
Artist[@ar1].album_pks = [@t1, @t2]
|
|
1290
|
-
Artist[@ar2].album_pks.
|
|
1291
|
-
Album.order(:id).select_map(:artist_id).
|
|
1296
|
+
Artist[@ar2].album_pks.must_equal [@t3]
|
|
1297
|
+
Album.order(:id).select_map(:artist_id).must_equal [@ar1, @ar1, @ar2]
|
|
1292
1298
|
end
|
|
1293
1299
|
|
|
1294
|
-
|
|
1300
|
+
it "should set associated pks correctly for a many_to_many association" do
|
|
1295
1301
|
Artist.use_transactions = true
|
|
1296
|
-
@db[:albums_tags].filter(:album_id=>@al1).select_order_map(:tag_id).
|
|
1302
|
+
@db[:albums_tags].filter(:album_id=>@al1).select_order_map(:tag_id).must_equal [@t1, @t2, @t3]
|
|
1297
1303
|
Album[@al1].tag_pks = [@t1, @t3]
|
|
1298
|
-
@db[:albums_tags].filter(:album_id=>@al1).select_order_map(:tag_id).
|
|
1304
|
+
@db[:albums_tags].filter(:album_id=>@al1).select_order_map(:tag_id).must_equal [@t1, @t3]
|
|
1299
1305
|
Album[@al1].tag_pks = []
|
|
1300
|
-
@db[:albums_tags].filter(:album_id=>@al1).select_order_map(:tag_id).
|
|
1306
|
+
@db[:albums_tags].filter(:album_id=>@al1).select_order_map(:tag_id).must_equal []
|
|
1301
1307
|
|
|
1302
|
-
@db[:albums_tags].filter(:album_id=>@al2).select_order_map(:tag_id).
|
|
1308
|
+
@db[:albums_tags].filter(:album_id=>@al2).select_order_map(:tag_id).must_equal [@t2]
|
|
1303
1309
|
Album[@al2].tag_pks = [@t1, @t2]
|
|
1304
|
-
@db[:albums_tags].filter(:album_id=>@al2).select_order_map(:tag_id).
|
|
1310
|
+
@db[:albums_tags].filter(:album_id=>@al2).select_order_map(:tag_id).must_equal [@t1, @t2]
|
|
1305
1311
|
Album[@al2].tag_pks = []
|
|
1306
|
-
@db[:albums_tags].filter(:album_id=>@al1).select_order_map(:tag_id).
|
|
1312
|
+
@db[:albums_tags].filter(:album_id=>@al1).select_order_map(:tag_id).must_equal []
|
|
1307
1313
|
|
|
1308
|
-
@db[:albums_tags].filter(:album_id=>@al3).select_order_map(:tag_id).
|
|
1314
|
+
@db[:albums_tags].filter(:album_id=>@al3).select_order_map(:tag_id).must_equal []
|
|
1309
1315
|
Album[@al3].tag_pks = [@t1, @t3]
|
|
1310
|
-
@db[:albums_tags].filter(:album_id=>@al3).select_order_map(:tag_id).
|
|
1316
|
+
@db[:albums_tags].filter(:album_id=>@al3).select_order_map(:tag_id).must_equal [@t1, @t3]
|
|
1311
1317
|
Album[@al3].tag_pks = []
|
|
1312
|
-
@db[:albums_tags].filter(:album_id=>@al1).select_order_map(:tag_id).
|
|
1318
|
+
@db[:albums_tags].filter(:album_id=>@al1).select_order_map(:tag_id).must_equal []
|
|
1313
1319
|
end
|
|
1314
1320
|
|
|
1315
|
-
|
|
1321
|
+
it "should set associated right-side cpks correctly for a one_to_many association" do
|
|
1316
1322
|
Album.use_transactions = true
|
|
1317
1323
|
Album.one_to_many :vocalists, :order=>:first
|
|
1318
|
-
Album.order(:id).all.map{|a| a.vocalist_pks.sort}.
|
|
1324
|
+
Album.order(:id).all.map{|a| a.vocalist_pks.sort}.must_equal [[@v1, @v2, @v3], [], []]
|
|
1319
1325
|
|
|
1320
1326
|
Album[@al2].vocalist_pks = [@v1, @v3]
|
|
1321
|
-
Album[@al1].vocalist_pks.
|
|
1322
|
-
Vocalist.order(:first, :last).select_map(:album_id).
|
|
1327
|
+
Album[@al1].vocalist_pks.must_equal [@v2]
|
|
1328
|
+
Vocalist.order(:first, :last).select_map(:album_id).must_equal [@al2, @al1, @al2]
|
|
1323
1329
|
|
|
1324
1330
|
Album[@al1].vocalist_pks = [@v1]
|
|
1325
|
-
Album[@al2].vocalist_pks.
|
|
1326
|
-
Vocalist.order(:first, :last).select_map(:album_id).
|
|
1331
|
+
Album[@al2].vocalist_pks.must_equal [@v3]
|
|
1332
|
+
Vocalist.order(:first, :last).select_map(:album_id).must_equal [@al1, nil, @al2]
|
|
1327
1333
|
|
|
1328
1334
|
Album[@al1].vocalist_pks = [@v1, @v2]
|
|
1329
|
-
Album[@al2].vocalist_pks.
|
|
1330
|
-
Vocalist.order(:first, :last).select_map(:album_id).
|
|
1335
|
+
Album[@al2].vocalist_pks.must_equal [@v3]
|
|
1336
|
+
Vocalist.order(:first, :last).select_map(:album_id).must_equal [@al1, @al1, @al2]
|
|
1331
1337
|
end
|
|
1332
1338
|
|
|
1333
|
-
|
|
1339
|
+
it "should set associated right-side cpks correctly for a many_to_many association" do
|
|
1334
1340
|
Album.use_transactions = true
|
|
1335
1341
|
Album.many_to_many :vocalists, :join_table=>:albums_vocalists, :right_key=>[:first, :last], :order=>:first
|
|
1336
1342
|
|
|
1337
|
-
@db[:albums_vocalists].filter(:album_id=>@al1).select_order_map([:first, :last]).
|
|
1343
|
+
@db[:albums_vocalists].filter(:album_id=>@al1).select_order_map([:first, :last]).must_equal [@v1, @v2, @v3]
|
|
1338
1344
|
Album[@al1].vocalist_pks = [@v1, @v3]
|
|
1339
|
-
@db[:albums_vocalists].filter(:album_id=>@al1).select_order_map([:first, :last]).
|
|
1345
|
+
@db[:albums_vocalists].filter(:album_id=>@al1).select_order_map([:first, :last]).must_equal [@v1, @v3]
|
|
1340
1346
|
Album[@al1].vocalist_pks = []
|
|
1341
|
-
@db[:albums_vocalists].filter(:album_id=>@al1).select_order_map([:first, :last]).
|
|
1347
|
+
@db[:albums_vocalists].filter(:album_id=>@al1).select_order_map([:first, :last]).must_equal []
|
|
1342
1348
|
|
|
1343
|
-
@db[:albums_vocalists].filter(:album_id=>@al2).select_order_map([:first, :last]).
|
|
1349
|
+
@db[:albums_vocalists].filter(:album_id=>@al2).select_order_map([:first, :last]).must_equal [@v2]
|
|
1344
1350
|
Album[@al2].vocalist_pks = [@v1, @v2]
|
|
1345
|
-
@db[:albums_vocalists].filter(:album_id=>@al2).select_order_map([:first, :last]).
|
|
1351
|
+
@db[:albums_vocalists].filter(:album_id=>@al2).select_order_map([:first, :last]).must_equal [@v1, @v2]
|
|
1346
1352
|
Album[@al2].vocalist_pks = []
|
|
1347
|
-
@db[:albums_vocalists].filter(:album_id=>@al1).select_order_map([:first, :last]).
|
|
1353
|
+
@db[:albums_vocalists].filter(:album_id=>@al1).select_order_map([:first, :last]).must_equal []
|
|
1348
1354
|
|
|
1349
|
-
@db[:albums_vocalists].filter(:album_id=>@al3).select_order_map([:first, :last]).
|
|
1355
|
+
@db[:albums_vocalists].filter(:album_id=>@al3).select_order_map([:first, :last]).must_equal []
|
|
1350
1356
|
Album[@al3].vocalist_pks = [@v1, @v3]
|
|
1351
|
-
@db[:albums_vocalists].filter(:album_id=>@al3).select_order_map([:first, :last]).
|
|
1357
|
+
@db[:albums_vocalists].filter(:album_id=>@al3).select_order_map([:first, :last]).must_equal [@v1, @v3]
|
|
1352
1358
|
Album[@al3].vocalist_pks = []
|
|
1353
|
-
@db[:albums_vocalists].filter(:album_id=>@al1).select_order_map([:first, :last]).
|
|
1359
|
+
@db[:albums_vocalists].filter(:album_id=>@al1).select_order_map([:first, :last]).must_equal []
|
|
1354
1360
|
end
|
|
1355
1361
|
|
|
1356
|
-
|
|
1362
|
+
it "should set associated pks correctly with left-side cpks for a one_to_many association" do
|
|
1357
1363
|
Vocalist.use_transactions = true
|
|
1358
1364
|
Vocalist.one_to_many :instruments, :key=>[:first, :last], :order=>:id
|
|
1359
|
-
Vocalist.order(:first, :last).all.map{|a| a.instrument_pks.sort}.
|
|
1365
|
+
Vocalist.order(:first, :last).all.map{|a| a.instrument_pks.sort}.must_equal [[@i1, @i2, @i3], [], []]
|
|
1360
1366
|
|
|
1361
1367
|
Vocalist[@v2].instrument_pks = [@i1, @i3]
|
|
1362
|
-
Vocalist[@v1].instrument_pks.
|
|
1363
|
-
Instrument.order(:id).select_map([:first, :last]).
|
|
1368
|
+
Vocalist[@v1].instrument_pks.must_equal [@i2]
|
|
1369
|
+
Instrument.order(:id).select_map([:first, :last]).must_equal [@v2, @v1, @v2]
|
|
1364
1370
|
|
|
1365
1371
|
Vocalist[@v1].instrument_pks = [@i1]
|
|
1366
|
-
Vocalist[@v2].instrument_pks.
|
|
1367
|
-
Instrument.order(:id).select_map([:first, :last]).
|
|
1372
|
+
Vocalist[@v2].instrument_pks.must_equal [@i3]
|
|
1373
|
+
Instrument.order(:id).select_map([:first, :last]).must_equal [@v1, [nil, nil], @v2]
|
|
1368
1374
|
|
|
1369
1375
|
Vocalist[@v1].instrument_pks = [@i1, @i2]
|
|
1370
|
-
Vocalist[@v2].instrument_pks.
|
|
1371
|
-
Instrument.order(:id).select_map([:first, :last]).
|
|
1376
|
+
Vocalist[@v2].instrument_pks.must_equal [@i3]
|
|
1377
|
+
Instrument.order(:id).select_map([:first, :last]).must_equal [@v1, @v1, @v2]
|
|
1372
1378
|
end
|
|
1373
1379
|
|
|
1374
|
-
|
|
1380
|
+
it "should set associated pks correctly with left-side cpks for a many_to_many association" do
|
|
1375
1381
|
Vocalist.use_transactions = true
|
|
1376
1382
|
Vocalist.many_to_many :instruments, :join_table=>:vocalists_instruments, :left_key=>[:first, :last], :order=>:id
|
|
1377
1383
|
|
|
1378
|
-
@db[:vocalists_instruments].filter([:first, :last]=>[@v1]).select_order_map(:instrument_id).
|
|
1384
|
+
@db[:vocalists_instruments].filter([:first, :last]=>[@v1]).select_order_map(:instrument_id).must_equal [@i1, @i2, @i3]
|
|
1379
1385
|
Vocalist[@v1].instrument_pks = [@i1, @i3]
|
|
1380
|
-
@db[:vocalists_instruments].filter([:first, :last]=>[@v1]).select_order_map(:instrument_id).
|
|
1386
|
+
@db[:vocalists_instruments].filter([:first, :last]=>[@v1]).select_order_map(:instrument_id).must_equal [@i1, @i3]
|
|
1381
1387
|
Vocalist[@v1].instrument_pks = []
|
|
1382
|
-
@db[:vocalists_instruments].filter([:first, :last]=>[@v1]).select_order_map(:instrument_id).
|
|
1388
|
+
@db[:vocalists_instruments].filter([:first, :last]=>[@v1]).select_order_map(:instrument_id).must_equal []
|
|
1383
1389
|
|
|
1384
|
-
@db[:vocalists_instruments].filter([:first, :last]=>[@v2]).select_order_map(:instrument_id).
|
|
1390
|
+
@db[:vocalists_instruments].filter([:first, :last]=>[@v2]).select_order_map(:instrument_id).must_equal [@i2]
|
|
1385
1391
|
Vocalist[@v2].instrument_pks = [@i1, @i2]
|
|
1386
|
-
@db[:vocalists_instruments].filter([:first, :last]=>[@v2]).select_order_map(:instrument_id).
|
|
1392
|
+
@db[:vocalists_instruments].filter([:first, :last]=>[@v2]).select_order_map(:instrument_id).must_equal [@i1, @i2]
|
|
1387
1393
|
Vocalist[@v2].instrument_pks = []
|
|
1388
|
-
@db[:vocalists_instruments].filter([:first, :last]=>[@v1]).select_order_map(:instrument_id).
|
|
1394
|
+
@db[:vocalists_instruments].filter([:first, :last]=>[@v1]).select_order_map(:instrument_id).must_equal []
|
|
1389
1395
|
|
|
1390
|
-
@db[:vocalists_instruments].filter([:first, :last]=>[@v3]).select_order_map(:instrument_id).
|
|
1396
|
+
@db[:vocalists_instruments].filter([:first, :last]=>[@v3]).select_order_map(:instrument_id).must_equal []
|
|
1391
1397
|
Vocalist[@v3].instrument_pks = [@i1, @i3]
|
|
1392
|
-
@db[:vocalists_instruments].filter([:first, :last]=>[@v3]).select_order_map(:instrument_id).
|
|
1398
|
+
@db[:vocalists_instruments].filter([:first, :last]=>[@v3]).select_order_map(:instrument_id).must_equal [@i1, @i3]
|
|
1393
1399
|
Vocalist[@v3].instrument_pks = []
|
|
1394
|
-
@db[:vocalists_instruments].filter([:first, :last]=>[@v1]).select_order_map(:instrument_id).
|
|
1400
|
+
@db[:vocalists_instruments].filter([:first, :last]=>[@v1]).select_order_map(:instrument_id).must_equal []
|
|
1395
1401
|
end
|
|
1396
1402
|
|
|
1397
|
-
|
|
1403
|
+
it "should set associated right-side cpks correctly with left-side cpks for a one_to_many association" do
|
|
1398
1404
|
Vocalist.use_transactions = true
|
|
1399
1405
|
Vocalist.one_to_many :hits, :key=>[:first, :last], :order=>:week
|
|
1400
|
-
Vocalist.order(:first, :last).all.map{|a| a.hit_pks.sort}.
|
|
1406
|
+
Vocalist.order(:first, :last).all.map{|a| a.hit_pks.sort}.must_equal [[@h1, @h2, @h3], [], []]
|
|
1401
1407
|
|
|
1402
1408
|
Vocalist[@v2].hit_pks = [@h1, @h3]
|
|
1403
|
-
Vocalist[@v1].hit_pks.
|
|
1404
|
-
Hit.order(:year, :week).select_map([:first, :last]).
|
|
1409
|
+
Vocalist[@v1].hit_pks.must_equal [@h2]
|
|
1410
|
+
Hit.order(:year, :week).select_map([:first, :last]).must_equal [@v2, @v1, @v2]
|
|
1405
1411
|
|
|
1406
1412
|
Vocalist[@v1].hit_pks = [@h1]
|
|
1407
|
-
Vocalist[@v2].hit_pks.
|
|
1408
|
-
Hit.order(:year, :week).select_map([:first, :last]).
|
|
1413
|
+
Vocalist[@v2].hit_pks.must_equal [@h3]
|
|
1414
|
+
Hit.order(:year, :week).select_map([:first, :last]).must_equal [@v1, [nil, nil], @v2]
|
|
1409
1415
|
|
|
1410
1416
|
Vocalist[@v1].hit_pks = [@h1, @h2]
|
|
1411
|
-
Vocalist[@v2].hit_pks.
|
|
1412
|
-
Hit.order(:year, :week).select_map([:first, :last]).
|
|
1417
|
+
Vocalist[@v2].hit_pks.must_equal [@h3]
|
|
1418
|
+
Hit.order(:year, :week).select_map([:first, :last]).must_equal [@v1, @v1, @v2]
|
|
1413
1419
|
end
|
|
1414
1420
|
|
|
1415
|
-
|
|
1421
|
+
it "should set associated right-side cpks correctly with left-side cpks for a many_to_many association" do
|
|
1416
1422
|
Vocalist.use_transactions = true
|
|
1417
1423
|
Vocalist.many_to_many :hits, :join_table=>:vocalists_hits, :left_key=>[:first, :last], :right_key=>[:year, :week], :order=>:week
|
|
1418
1424
|
|
|
1419
|
-
@db[:vocalists_hits].filter([:first, :last]=>[@v1]).select_order_map([:year, :week]).
|
|
1425
|
+
@db[:vocalists_hits].filter([:first, :last]=>[@v1]).select_order_map([:year, :week]).must_equal [@h1, @h2, @h3]
|
|
1420
1426
|
Vocalist[@v1].hit_pks = [@h1, @h3]
|
|
1421
|
-
@db[:vocalists_hits].filter([:first, :last]=>[@v1]).select_order_map([:year, :week]).
|
|
1427
|
+
@db[:vocalists_hits].filter([:first, :last]=>[@v1]).select_order_map([:year, :week]).must_equal [@h1, @h3]
|
|
1422
1428
|
Vocalist[@v1].hit_pks = []
|
|
1423
|
-
@db[:vocalists_hits].filter([:first, :last]=>[@v1]).select_order_map([:year, :week]).
|
|
1429
|
+
@db[:vocalists_hits].filter([:first, :last]=>[@v1]).select_order_map([:year, :week]).must_equal []
|
|
1424
1430
|
|
|
1425
|
-
@db[:vocalists_hits].filter([:first, :last]=>[@v2]).select_order_map([:year, :week]).
|
|
1431
|
+
@db[:vocalists_hits].filter([:first, :last]=>[@v2]).select_order_map([:year, :week]).must_equal [@h2]
|
|
1426
1432
|
Vocalist[@v2].hit_pks = [@h1, @h2]
|
|
1427
|
-
@db[:vocalists_hits].filter([:first, :last]=>[@v2]).select_order_map([:year, :week]).
|
|
1433
|
+
@db[:vocalists_hits].filter([:first, :last]=>[@v2]).select_order_map([:year, :week]).must_equal [@h1, @h2]
|
|
1428
1434
|
Vocalist[@v2].hit_pks = []
|
|
1429
|
-
@db[:vocalists_hits].filter([:first, :last]=>[@v1]).select_order_map([:year, :week]).
|
|
1435
|
+
@db[:vocalists_hits].filter([:first, :last]=>[@v1]).select_order_map([:year, :week]).must_equal []
|
|
1430
1436
|
|
|
1431
|
-
@db[:vocalists_hits].filter([:first, :last]=>[@v3]).select_order_map([:year, :week]).
|
|
1437
|
+
@db[:vocalists_hits].filter([:first, :last]=>[@v3]).select_order_map([:year, :week]).must_equal []
|
|
1432
1438
|
Vocalist[@v3].hit_pks = [@h1, @h3]
|
|
1433
|
-
@db[:vocalists_hits].filter([:first, :last]=>[@v3]).select_order_map([:year, :week]).
|
|
1439
|
+
@db[:vocalists_hits].filter([:first, :last]=>[@v3]).select_order_map([:year, :week]).must_equal [@h1, @h3]
|
|
1434
1440
|
Vocalist[@v3].hit_pks = []
|
|
1435
|
-
@db[:vocalists_hits].filter([:first, :last]=>[@v1]).select_order_map([:year, :week]).
|
|
1441
|
+
@db[:vocalists_hits].filter([:first, :last]=>[@v1]).select_order_map([:year, :week]).must_equal []
|
|
1436
1442
|
end
|
|
1437
1443
|
end
|
|
1438
1444
|
|
|
@@ -1459,59 +1465,63 @@ describe "List plugin without a scope" do
|
|
|
1459
1465
|
end
|
|
1460
1466
|
|
|
1461
1467
|
it "should return rows in order of position" do
|
|
1462
|
-
@c.map(:position).
|
|
1463
|
-
@c.map(:name).
|
|
1468
|
+
@c.map(:position).must_equal [1,2,3]
|
|
1469
|
+
@c.map(:name).must_equal %w[ abc def hig ]
|
|
1464
1470
|
end
|
|
1465
1471
|
|
|
1466
1472
|
it "should define prev and next" do
|
|
1467
1473
|
i = @c[:name => "abc"]
|
|
1468
|
-
i.prev.
|
|
1474
|
+
i.prev.must_equal nil
|
|
1469
1475
|
i = @c[:name => "def"]
|
|
1470
|
-
i.prev.
|
|
1471
|
-
i.next.
|
|
1476
|
+
i.prev.must_equal @c[:name => "abc"]
|
|
1477
|
+
i.next.must_equal @c[:name => "hig"]
|
|
1472
1478
|
i = @c[:name => "hig"]
|
|
1473
|
-
i.next.
|
|
1479
|
+
i.next.must_equal nil
|
|
1474
1480
|
end
|
|
1475
1481
|
|
|
1476
1482
|
it "should define move_to" do
|
|
1477
1483
|
@c[:name => "def"].move_to(1)
|
|
1478
|
-
@c.map(:name).
|
|
1484
|
+
@c.map(:name).must_equal %w[ def abc hig ]
|
|
1479
1485
|
|
|
1480
1486
|
@c[:name => "abc"].move_to(3)
|
|
1481
|
-
@c.map(:name).
|
|
1487
|
+
@c.map(:name).must_equal %w[ def hig abc ]
|
|
1482
1488
|
|
|
1483
|
-
|
|
1484
|
-
|
|
1489
|
+
@c[:name => "abc"].move_to(-1)
|
|
1490
|
+
@c.map(:name).must_equal %w[ abc def hig ]
|
|
1491
|
+
@c[:name => "abc"].move_to(10)
|
|
1492
|
+
@c.map(:name).must_equal %w[ def hig abc ]
|
|
1485
1493
|
end
|
|
1486
1494
|
|
|
1487
1495
|
it "should define move_to_top and move_to_bottom" do
|
|
1488
1496
|
@c[:name => "def"].move_to_top
|
|
1489
|
-
@c.map(:name).
|
|
1497
|
+
@c.map(:name).must_equal %w[ def abc hig ]
|
|
1490
1498
|
|
|
1491
1499
|
@c[:name => "def"].move_to_bottom
|
|
1492
|
-
@c.map(:name).
|
|
1500
|
+
@c.map(:name).must_equal %w[ abc hig def ]
|
|
1493
1501
|
end
|
|
1494
1502
|
|
|
1495
1503
|
it "should define move_up and move_down" do
|
|
1496
1504
|
@c[:name => "def"].move_up
|
|
1497
|
-
@c.map(:name).
|
|
1505
|
+
@c.map(:name).must_equal %w[ def abc hig ]
|
|
1498
1506
|
|
|
1499
1507
|
@c[:name => "abc"].move_down
|
|
1500
|
-
@c.map(:name).
|
|
1508
|
+
@c.map(:name).must_equal %w[ def hig abc ]
|
|
1501
1509
|
|
|
1502
1510
|
@c[:name => "abc"].move_up(2)
|
|
1503
|
-
@c.map(:name).
|
|
1511
|
+
@c.map(:name).must_equal %w[ abc def hig ]
|
|
1504
1512
|
|
|
1505
1513
|
@c[:name => "abc"].move_down(2)
|
|
1506
|
-
@c.map(:name).
|
|
1514
|
+
@c.map(:name).must_equal %w[ def hig abc ]
|
|
1507
1515
|
|
|
1508
|
-
|
|
1509
|
-
|
|
1516
|
+
@c[:name => "abc"].move_up(10)
|
|
1517
|
+
@c.map(:name).must_equal %w[ abc def hig ]
|
|
1518
|
+
@c[:name => "abc"].move_down(10)
|
|
1519
|
+
@c.map(:name).must_equal %w[ def hig abc ]
|
|
1510
1520
|
end
|
|
1511
1521
|
|
|
1512
1522
|
it "should update positions on destroy" do
|
|
1513
1523
|
@c[:name => "def"].destroy
|
|
1514
|
-
@c.select_map([:position, :name]).
|
|
1524
|
+
@c.select_map([:position, :name]).must_equal [[1, 'abc'], [2, 'hig']]
|
|
1515
1525
|
end
|
|
1516
1526
|
end
|
|
1517
1527
|
|
|
@@ -1541,102 +1551,106 @@ describe "List plugin with a scope" do
|
|
|
1541
1551
|
@db.drop_table?(:pages)
|
|
1542
1552
|
end
|
|
1543
1553
|
|
|
1544
|
-
|
|
1545
|
-
@c.map(:name).
|
|
1554
|
+
it "should return rows in order of position" do
|
|
1555
|
+
@c.map(:name).must_equal %w[ Hm Ps Au P1 P2 P3 ]
|
|
1546
1556
|
end
|
|
1547
1557
|
|
|
1548
1558
|
it "should define prev and next" do
|
|
1549
|
-
@c[:name => "Ps"].next.name.
|
|
1550
|
-
@c[:name => "Au"].prev.name.
|
|
1551
|
-
@c[:name => "P1"].next.name.
|
|
1552
|
-
@c[:name => "P2"].prev.name.
|
|
1559
|
+
@c[:name => "Ps"].next.name.must_equal 'Au'
|
|
1560
|
+
@c[:name => "Au"].prev.name.must_equal 'Ps'
|
|
1561
|
+
@c[:name => "P1"].next.name.must_equal 'P2'
|
|
1562
|
+
@c[:name => "P2"].prev.name.must_equal 'P1'
|
|
1553
1563
|
|
|
1554
|
-
@c[:name => "P1"].next(2).name.
|
|
1555
|
-
@c[:name => "P2"].next(-1).name.
|
|
1556
|
-
@c[:name => "P3"].prev(2).name.
|
|
1557
|
-
@c[:name => "P2"].prev(-1).name.
|
|
1564
|
+
@c[:name => "P1"].next(2).name.must_equal 'P3'
|
|
1565
|
+
@c[:name => "P2"].next(-1).name.must_equal 'P1'
|
|
1566
|
+
@c[:name => "P3"].prev(2).name.must_equal 'P1'
|
|
1567
|
+
@c[:name => "P2"].prev(-1).name.must_equal 'P3'
|
|
1558
1568
|
|
|
1559
|
-
@c[:name => "Ps"].prev.
|
|
1560
|
-
@c[:name => "Au"].next.
|
|
1561
|
-
@c[:name => "P1"].prev.
|
|
1562
|
-
@c[:name => "P3"].next.
|
|
1569
|
+
@c[:name => "Ps"].prev.must_equal nil
|
|
1570
|
+
@c[:name => "Au"].next.must_equal nil
|
|
1571
|
+
@c[:name => "P1"].prev.must_equal nil
|
|
1572
|
+
@c[:name => "P3"].next.must_equal nil
|
|
1563
1573
|
end
|
|
1564
1574
|
|
|
1565
|
-
|
|
1575
|
+
it "should define move_to" do
|
|
1566
1576
|
@c[:name => "P2"].move_to(1)
|
|
1567
|
-
@c.map(:name).
|
|
1577
|
+
@c.map(:name).must_equal %w[ Hm Ps Au P2 P1 P3 ]
|
|
1568
1578
|
|
|
1569
1579
|
@c[:name => "P2"].move_to(3)
|
|
1570
|
-
@c.map(:name).
|
|
1580
|
+
@c.map(:name).must_equal %w[ Hm Ps Au P1 P3 P2 ]
|
|
1571
1581
|
|
|
1572
|
-
|
|
1573
|
-
|
|
1582
|
+
@c[:name => "P2"].move_to(-1)
|
|
1583
|
+
@c.map(:name).must_equal %w[ Hm Ps Au P2 P1 P3 ]
|
|
1584
|
+
@c[:name => "P2"].move_to(10)
|
|
1585
|
+
@c.map(:name).must_equal %w[ Hm Ps Au P1 P3 P2 ]
|
|
1574
1586
|
end
|
|
1575
1587
|
|
|
1576
|
-
|
|
1588
|
+
it "should define move_to_top and move_to_bottom" do
|
|
1577
1589
|
@c[:name => "Au"].move_to_top
|
|
1578
|
-
@c.map(:name).
|
|
1590
|
+
@c.map(:name).must_equal %w[ Hm Au Ps P1 P2 P3 ]
|
|
1579
1591
|
|
|
1580
1592
|
@c[:name => "Au"].move_to_bottom
|
|
1581
|
-
@c.map(:name).
|
|
1593
|
+
@c.map(:name).must_equal %w[ Hm Ps Au P1 P2 P3 ]
|
|
1582
1594
|
end
|
|
1583
1595
|
|
|
1584
|
-
|
|
1596
|
+
it "should define move_up and move_down" do
|
|
1585
1597
|
@c[:name => "P2"].move_up
|
|
1586
|
-
@c.map(:name).
|
|
1598
|
+
@c.map(:name).must_equal %w[ Hm Ps Au P2 P1 P3 ]
|
|
1587
1599
|
|
|
1588
1600
|
@c[:name => "P1"].move_down
|
|
1589
|
-
@c.map(:name).
|
|
1601
|
+
@c.map(:name).must_equal %w[ Hm Ps Au P2 P3 P1 ]
|
|
1590
1602
|
|
|
1591
|
-
|
|
1592
|
-
|
|
1603
|
+
@c[:name => "P1"].move_up(10)
|
|
1604
|
+
@c.map(:name).must_equal %w[ Hm Ps Au P1 P2 P3 ]
|
|
1605
|
+
@c[:name => "P1"].move_down(10)
|
|
1606
|
+
@c.map(:name).must_equal %w[ Hm Ps Au P2 P3 P1 ]
|
|
1593
1607
|
end
|
|
1594
1608
|
|
|
1595
1609
|
it "should update positions on destroy" do
|
|
1596
1610
|
@c[:name => "P2"].destroy
|
|
1597
|
-
@c.select_order_map([:pos, :name]).
|
|
1611
|
+
@c.select_order_map([:pos, :name]).must_equal [[1, "Hm"], [1, "P1"], [1, "Ps"], [2, "Au"], [2, "P3"]]
|
|
1598
1612
|
end
|
|
1599
1613
|
end
|
|
1600
1614
|
|
|
1601
1615
|
describe "Sequel::Plugins::Tree" do
|
|
1602
|
-
|
|
1616
|
+
TreePluginSpecs = shared_description do
|
|
1603
1617
|
it "should instantiate" do
|
|
1604
|
-
@Node.all.size.
|
|
1618
|
+
@Node.all.size.must_equal 12
|
|
1605
1619
|
end
|
|
1606
1620
|
|
|
1607
1621
|
it "should find all descendants of a node" do
|
|
1608
|
-
@Node.find(:name => 'two').descendants.map{|m| m.name}.
|
|
1622
|
+
@Node.find(:name => 'two').descendants.map{|m| m.name}.must_equal %w'two.one two.two two.three two.two.one'
|
|
1609
1623
|
end
|
|
1610
1624
|
|
|
1611
1625
|
it "should find all ancestors of a node" do
|
|
1612
|
-
@Node.find(:name => "two.two.one").ancestors.map{|m| m.name}.
|
|
1626
|
+
@Node.find(:name => "two.two.one").ancestors.map{|m| m.name}.must_equal %w'two.two two'
|
|
1613
1627
|
end
|
|
1614
1628
|
|
|
1615
1629
|
it "should find all siblings of a node, excepting self" do
|
|
1616
|
-
@Node.find(:name=>"two.one").siblings.map{|m| m.name}.
|
|
1630
|
+
@Node.find(:name=>"two.one").siblings.map{|m| m.name}.must_equal %w'two.two two.three'
|
|
1617
1631
|
end
|
|
1618
1632
|
|
|
1619
1633
|
it "should find all siblings of a node, including self" do
|
|
1620
|
-
@Node.find(:name=>"two.one").self_and_siblings.map{|m| m.name}.
|
|
1634
|
+
@Node.find(:name=>"two.one").self_and_siblings.map{|m| m.name}.must_equal %w'two.one two.two two.three'
|
|
1621
1635
|
end
|
|
1622
1636
|
|
|
1623
1637
|
it "should find siblings for root nodes" do
|
|
1624
|
-
@Node.find(:name=>'three').self_and_siblings.map{|m| m.name}.
|
|
1638
|
+
@Node.find(:name=>'three').self_and_siblings.map{|m| m.name}.must_equal %w'one two three four five'
|
|
1625
1639
|
end
|
|
1626
1640
|
|
|
1627
1641
|
it "should find correct root for a node" do
|
|
1628
|
-
@Node.find(:name=>"two.two.one").root.name.
|
|
1629
|
-
@Node.find(:name=>"three").root.name.
|
|
1630
|
-
@Node.find(:name=>"five.one").root.name.
|
|
1642
|
+
@Node.find(:name=>"two.two.one").root.name.must_equal 'two'
|
|
1643
|
+
@Node.find(:name=>"three").root.name.must_equal 'three'
|
|
1644
|
+
@Node.find(:name=>"five.one").root.name.must_equal 'five'
|
|
1631
1645
|
end
|
|
1632
1646
|
|
|
1633
1647
|
it "iterate top-level nodes in order" do
|
|
1634
|
-
@Node.roots_dataset.count.
|
|
1635
|
-
@Node.roots.map{|p| p.name}.
|
|
1648
|
+
@Node.roots_dataset.count.must_equal 5
|
|
1649
|
+
@Node.roots.map{|p| p.name}.must_equal %w'one two three four five'
|
|
1636
1650
|
end
|
|
1637
1651
|
|
|
1638
1652
|
it "should have children" do
|
|
1639
|
-
@Node.find(:name=>'one').children.map{|m| m.name}.
|
|
1653
|
+
@Node.find(:name=>'one').children.map{|m| m.name}.must_equal %w'one.one one.two'
|
|
1640
1654
|
end
|
|
1641
1655
|
end
|
|
1642
1656
|
|
|
@@ -1671,7 +1685,7 @@ describe "Sequel::Plugins::Tree" do
|
|
|
1671
1685
|
@db.drop_table?(:nodes)
|
|
1672
1686
|
end
|
|
1673
1687
|
|
|
1674
|
-
|
|
1688
|
+
include TreePluginSpecs
|
|
1675
1689
|
end
|
|
1676
1690
|
|
|
1677
1691
|
describe "with composite key" do
|
|
@@ -1708,7 +1722,34 @@ describe "Sequel::Plugins::Tree" do
|
|
|
1708
1722
|
@db.drop_table?(:nodes)
|
|
1709
1723
|
end
|
|
1710
1724
|
|
|
1711
|
-
|
|
1725
|
+
include TreePluginSpecs
|
|
1726
|
+
end
|
|
1727
|
+
end
|
|
1728
|
+
|
|
1729
|
+
describe "Sequel::Plugins::UpdateRefresh" do
|
|
1730
|
+
before(:all) do
|
|
1731
|
+
@db = DB
|
|
1732
|
+
@db.create_table!(:tests) do
|
|
1733
|
+
primary_key :id
|
|
1734
|
+
String :name
|
|
1735
|
+
Integer :i
|
|
1736
|
+
end
|
|
1737
|
+
@c = Class.new(Sequel::Model(@db[:tests]))
|
|
1738
|
+
@c.plugin :update_refresh
|
|
1739
|
+
end
|
|
1740
|
+
before do
|
|
1741
|
+
@c.dataset.delete
|
|
1742
|
+
@foo = @c.create(:name=>'foo', :i=>10)
|
|
1743
|
+
end
|
|
1744
|
+
after(:all) do
|
|
1745
|
+
@db.drop_table?(:tests)
|
|
1746
|
+
end
|
|
1747
|
+
|
|
1748
|
+
it "should refresh when updating" do
|
|
1749
|
+
@foo.this.update(:i=>20)
|
|
1750
|
+
@foo.update(:name=>'bar')
|
|
1751
|
+
@foo.name.must_equal 'bar'
|
|
1752
|
+
@foo.i.must_equal 20
|
|
1712
1753
|
end
|
|
1713
1754
|
end
|
|
1714
1755
|
|
|
@@ -1733,55 +1774,55 @@ describe "Sequel::Plugins::PreparedStatements" do
|
|
|
1733
1774
|
end
|
|
1734
1775
|
|
|
1735
1776
|
it "should work with looking up using Model.[]" do
|
|
1736
|
-
@c[@foo.id].
|
|
1737
|
-
@c[@bar.id].
|
|
1738
|
-
@c[0].
|
|
1739
|
-
@c[nil].
|
|
1777
|
+
@c[@foo.id].must_equal @foo
|
|
1778
|
+
@c[@bar.id].must_equal @bar
|
|
1779
|
+
@c[0].must_equal nil
|
|
1780
|
+
@c[nil].must_equal nil
|
|
1740
1781
|
end
|
|
1741
1782
|
|
|
1742
1783
|
it "should work with looking up using Dataset#with_pk" do
|
|
1743
|
-
@c.dataset.with_pk(@foo.id).
|
|
1744
|
-
@c.dataset.with_pk(@bar.id).
|
|
1745
|
-
@c.dataset.with_pk(0).
|
|
1746
|
-
@c.dataset.with_pk(nil).
|
|
1784
|
+
@c.dataset.with_pk(@foo.id).must_equal @foo
|
|
1785
|
+
@c.dataset.with_pk(@bar.id).must_equal @bar
|
|
1786
|
+
@c.dataset.with_pk(0).must_equal nil
|
|
1787
|
+
@c.dataset.with_pk(nil).must_equal nil
|
|
1747
1788
|
|
|
1748
|
-
@c.dataset.filter(:i=>0).with_pk(@foo.id).
|
|
1749
|
-
@c.dataset.filter(:i=>10).with_pk(@foo.id).
|
|
1750
|
-
@c.dataset.filter(:i=>20).with_pk(@bar.id).
|
|
1751
|
-
@c.dataset.filter(:i=>10).with_pk(nil).
|
|
1752
|
-
@c.dataset.filter(:name=>'foo').with_pk(@foo.id).
|
|
1753
|
-
@c.dataset.filter(:name=>'bar').with_pk(@bar.id).
|
|
1754
|
-
@c.dataset.filter(:name=>'baz').with_pk(@bar.id).
|
|
1755
|
-
@c.dataset.filter(:name=>'bar').with_pk(nil).
|
|
1789
|
+
@c.dataset.filter(:i=>0).with_pk(@foo.id).must_equal nil
|
|
1790
|
+
@c.dataset.filter(:i=>10).with_pk(@foo.id).must_equal @foo
|
|
1791
|
+
@c.dataset.filter(:i=>20).with_pk(@bar.id).must_equal @bar
|
|
1792
|
+
@c.dataset.filter(:i=>10).with_pk(nil).must_equal nil
|
|
1793
|
+
@c.dataset.filter(:name=>'foo').with_pk(@foo.id).must_equal @foo
|
|
1794
|
+
@c.dataset.filter(:name=>'bar').with_pk(@bar.id).must_equal @bar
|
|
1795
|
+
@c.dataset.filter(:name=>'baz').with_pk(@bar.id).must_equal nil
|
|
1796
|
+
@c.dataset.filter(:name=>'bar').with_pk(nil).must_equal nil
|
|
1756
1797
|
end
|
|
1757
1798
|
|
|
1758
1799
|
it "should work with Model#destroy" do
|
|
1759
1800
|
@foo.destroy
|
|
1760
1801
|
@bar.destroy
|
|
1761
|
-
@c[@foo.id].
|
|
1762
|
-
@c[@bar.id].
|
|
1802
|
+
@c[@foo.id].must_equal nil
|
|
1803
|
+
@c[@bar.id].must_equal nil
|
|
1763
1804
|
end
|
|
1764
1805
|
|
|
1765
1806
|
it "should work with Model#update" do
|
|
1766
1807
|
@foo.update(:name=>'foo2', :i=>30)
|
|
1767
|
-
@c[@foo.id].
|
|
1808
|
+
@c[@foo.id].must_equal @c.load(:id=>@foo.id, :name=>'foo2', :i=>30)
|
|
1768
1809
|
@foo.update(:name=>'foo3')
|
|
1769
|
-
@c[@foo.id].
|
|
1810
|
+
@c[@foo.id].must_equal @c.load(:id=>@foo.id, :name=>'foo3', :i=>30)
|
|
1770
1811
|
@foo.update(:i=>40)
|
|
1771
|
-
@c[@foo.id].
|
|
1812
|
+
@c[@foo.id].must_equal @c.load(:id=>@foo.id, :name=>'foo3', :i=>40)
|
|
1772
1813
|
@foo.update(:i=>nil)
|
|
1773
|
-
@c[@foo.id].
|
|
1814
|
+
@c[@foo.id].must_equal @c.load(:id=>@foo.id, :name=>'foo3', :i=>nil)
|
|
1774
1815
|
end
|
|
1775
1816
|
|
|
1776
1817
|
it "should work with Model#create" do
|
|
1777
1818
|
o = @c.create(:name=>'foo2', :i=>30)
|
|
1778
|
-
@c[o.id].
|
|
1819
|
+
@c[o.id].must_equal @c.load(:id=>o.id, :name=>'foo2', :i=>30)
|
|
1779
1820
|
o = @c.create(:name=>'foo2')
|
|
1780
|
-
@c[o.id].
|
|
1821
|
+
@c[o.id].must_equal @c.load(:id=>o.id, :name=>'foo2', :i=>nil)
|
|
1781
1822
|
o = @c.create(:i=>30)
|
|
1782
|
-
@c[o.id].
|
|
1823
|
+
@c[o.id].must_equal @c.load(:id=>o.id, :name=>nil, :i=>30)
|
|
1783
1824
|
o = @c.create(:name=>nil, :i=>40)
|
|
1784
|
-
@c[o.id].
|
|
1825
|
+
@c[o.id].must_equal @c.load(:id=>o.id, :name=>nil, :i=>40)
|
|
1785
1826
|
end
|
|
1786
1827
|
end
|
|
1787
1828
|
|
|
@@ -1805,26 +1846,26 @@ describe "Sequel::Plugins::PreparedStatements with schema changes" do
|
|
|
1805
1846
|
|
|
1806
1847
|
it "should handle added columns" do
|
|
1807
1848
|
foo = @c.create(:name=>'foo')
|
|
1808
|
-
@c[foo.id].name.
|
|
1809
|
-
foo.ps_test.name.
|
|
1810
|
-
foo.ps_tests.map{|x| x.name}.
|
|
1811
|
-
foo.mps_tests.map{|x| x.name}.
|
|
1849
|
+
@c[foo.id].name.must_equal 'foo'
|
|
1850
|
+
foo.ps_test.name.must_equal 'foo'
|
|
1851
|
+
foo.ps_tests.map{|x| x.name}.must_equal %w'foo'
|
|
1852
|
+
foo.mps_tests.map{|x| x.name}.must_equal %w'foo'
|
|
1812
1853
|
foo.update(:name=>'foo2')
|
|
1813
|
-
@c[foo.id].name.
|
|
1854
|
+
@c[foo.id].name.must_equal 'foo2'
|
|
1814
1855
|
foo.delete
|
|
1815
|
-
foo.exists?.
|
|
1856
|
+
foo.exists?.must_equal false
|
|
1816
1857
|
|
|
1817
1858
|
@db.alter_table(:ps_test){add_column :i, Integer}
|
|
1818
1859
|
|
|
1819
1860
|
foo = @c.create(:name=>'foo')
|
|
1820
|
-
@c[foo.id].name.
|
|
1821
|
-
foo.ps_test.name.
|
|
1822
|
-
foo.ps_tests.map{|x| x.name}.
|
|
1823
|
-
foo.mps_tests.map{|x| x.name}.
|
|
1861
|
+
@c[foo.id].name.must_equal 'foo'
|
|
1862
|
+
foo.ps_test.name.must_equal 'foo'
|
|
1863
|
+
foo.ps_tests.map{|x| x.name}.must_equal %w'foo'
|
|
1864
|
+
foo.mps_tests.map{|x| x.name}.must_equal %w'foo'
|
|
1824
1865
|
foo.update(:name=>'foo2')
|
|
1825
|
-
@c[foo.id].name.
|
|
1866
|
+
@c[foo.id].name.must_equal 'foo2'
|
|
1826
1867
|
foo.delete
|
|
1827
|
-
foo.exists?.
|
|
1868
|
+
foo.exists?.must_equal false
|
|
1828
1869
|
end
|
|
1829
1870
|
end
|
|
1830
1871
|
|
|
@@ -1850,17 +1891,17 @@ describe "Caching plugins" do
|
|
|
1850
1891
|
@db.drop_table?(:albums, :artists)
|
|
1851
1892
|
end
|
|
1852
1893
|
|
|
1853
|
-
|
|
1894
|
+
CachingPluginSpecs = shared_description do
|
|
1854
1895
|
it "should work with looking up using Model.[]" do
|
|
1855
|
-
@Artist[1].
|
|
1856
|
-
@Artist[:id=>1].
|
|
1857
|
-
@Artist[0].
|
|
1858
|
-
@Artist[nil].
|
|
1896
|
+
@Artist[1].must_be_same_as(@Artist[1])
|
|
1897
|
+
@Artist[:id=>1].must_equal @Artist[1]
|
|
1898
|
+
@Artist[0].must_equal nil
|
|
1899
|
+
@Artist[nil].must_equal nil
|
|
1859
1900
|
end
|
|
1860
1901
|
|
|
1861
1902
|
it "should work with lookup up many_to_one associated objects" do
|
|
1862
1903
|
a = @Artist[1]
|
|
1863
|
-
@Album.first.artist.
|
|
1904
|
+
@Album.first.artist.must_be_same_as(a)
|
|
1864
1905
|
end
|
|
1865
1906
|
end
|
|
1866
1907
|
|
|
@@ -1877,7 +1918,7 @@ describe "Caching plugins" do
|
|
|
1877
1918
|
@Album.many_to_one :artist, :class=>@Artist
|
|
1878
1919
|
end
|
|
1879
1920
|
|
|
1880
|
-
|
|
1921
|
+
include CachingPluginSpecs
|
|
1881
1922
|
end
|
|
1882
1923
|
|
|
1883
1924
|
describe "static_cache plugin" do
|
|
@@ -1887,7 +1928,7 @@ describe "Caching plugins" do
|
|
|
1887
1928
|
@Album.many_to_one :artist, :class=>@Artist
|
|
1888
1929
|
end
|
|
1889
1930
|
|
|
1890
|
-
|
|
1931
|
+
include CachingPluginSpecs
|
|
1891
1932
|
end
|
|
1892
1933
|
end
|
|
1893
1934
|
|
|
@@ -1937,12 +1978,12 @@ describe "Sequel::Plugins::ConstraintValidations" do
|
|
|
1937
1978
|
@db.drop_constraint_validations_table
|
|
1938
1979
|
end
|
|
1939
1980
|
|
|
1940
|
-
|
|
1981
|
+
ConstraintValidationsSpecs = shared_description do
|
|
1941
1982
|
cspecify "should set up constraints that work even outside the model", :mysql do
|
|
1942
|
-
|
|
1983
|
+
@ds.insert(@valid_row)
|
|
1943
1984
|
|
|
1944
1985
|
# Test for unique constraint
|
|
1945
|
-
proc{@ds.insert(@valid_row)}.
|
|
1986
|
+
proc{@ds.insert(@valid_row)}.must_raise(Sequel::DatabaseError, Sequel::UniqueConstraintViolation, Sequel::ConstraintViolation)
|
|
1946
1987
|
|
|
1947
1988
|
@ds.delete
|
|
1948
1989
|
@violations.each do |col, vals|
|
|
@@ -1950,24 +1991,25 @@ describe "Sequel::Plugins::ConstraintValidations" do
|
|
|
1950
1991
|
vals += ['1234567'] if col == :minlen
|
|
1951
1992
|
vals.each do |val|
|
|
1952
1993
|
next if val.nil? && @validation_opts[:allow_nil]
|
|
1994
|
+
next if val == '' && @validation_opts[:allow_nil] && @db.database_type == :oracle
|
|
1953
1995
|
try[col] = val
|
|
1954
|
-
proc{@ds.insert(try)}.
|
|
1996
|
+
proc{@ds.insert(try)}.must_raise(Sequel::DatabaseError, Sequel::CheckConstraintViolation, Sequel::ConstraintViolation)
|
|
1955
1997
|
end
|
|
1956
1998
|
end
|
|
1957
1999
|
|
|
1958
2000
|
# Test for dropping of constraint
|
|
1959
2001
|
@db.alter_table(:cv_test){validate{drop :maxl2}}
|
|
1960
|
-
|
|
2002
|
+
@ds.insert(@valid_row.merge(:minlen=>'1234567'))
|
|
1961
2003
|
end
|
|
1962
2004
|
|
|
1963
2005
|
it "should set up automatic validations inside the model" do
|
|
1964
2006
|
c = Class.new(Sequel::Model(@ds))
|
|
1965
2007
|
c.plugin :constraint_validations
|
|
1966
2008
|
c.dataset.delete
|
|
1967
|
-
|
|
2009
|
+
c.create(@valid_row)
|
|
1968
2010
|
|
|
1969
2011
|
# Test for unique validation
|
|
1970
|
-
c.new(@valid_row).
|
|
2012
|
+
c.new(@valid_row).wont_be :valid?
|
|
1971
2013
|
|
|
1972
2014
|
c.dataset.delete
|
|
1973
2015
|
@violations.each do |col, vals|
|
|
@@ -1975,7 +2017,7 @@ describe "Sequel::Plugins::ConstraintValidations" do
|
|
|
1975
2017
|
vals.each do |val|
|
|
1976
2018
|
next if val.nil? && @validation_opts[:allow_nil]
|
|
1977
2019
|
try[col] = val
|
|
1978
|
-
c.new(try).
|
|
2020
|
+
c.new(try).wont_be :valid?
|
|
1979
2021
|
end
|
|
1980
2022
|
end
|
|
1981
2023
|
c.db.constraint_validations = nil
|
|
@@ -2015,13 +2057,13 @@ describe "Sequel::Plugins::ConstraintValidations" do
|
|
|
2015
2057
|
@validation_opts = {:allow_nil=>true}
|
|
2016
2058
|
@table_block.call
|
|
2017
2059
|
end
|
|
2018
|
-
|
|
2060
|
+
include ConstraintValidationsSpecs
|
|
2019
2061
|
end
|
|
2020
2062
|
describe "with :allow_nil=>false" do
|
|
2021
2063
|
before(:all) do
|
|
2022
2064
|
@table_block.call
|
|
2023
2065
|
end
|
|
2024
|
-
|
|
2066
|
+
include ConstraintValidationsSpecs
|
|
2025
2067
|
end
|
|
2026
2068
|
end
|
|
2027
2069
|
|
|
@@ -2060,16 +2102,16 @@ describe "Sequel::Plugins::ConstraintValidations" do
|
|
|
2060
2102
|
@validation_opts = {:allow_nil=>true}
|
|
2061
2103
|
@table_block.call
|
|
2062
2104
|
end
|
|
2063
|
-
|
|
2105
|
+
include ConstraintValidationsSpecs
|
|
2064
2106
|
end
|
|
2065
2107
|
describe "with :allow_nil=>false" do
|
|
2066
2108
|
before(:all) do
|
|
2067
2109
|
@table_block.call
|
|
2068
2110
|
end
|
|
2069
|
-
|
|
2111
|
+
include ConstraintValidationsSpecs
|
|
2070
2112
|
end
|
|
2071
2113
|
end
|
|
2072
|
-
end
|
|
2114
|
+
end
|
|
2073
2115
|
|
|
2074
2116
|
describe "date_arithmetic extension" do
|
|
2075
2117
|
asd = begin
|
|
@@ -2104,12 +2146,12 @@ describe "date_arithmetic extension" do
|
|
|
2104
2146
|
@check = lambda do |meth, in_date, in_interval, should|
|
|
2105
2147
|
output = @db.get(Sequel.send(meth, in_date, in_interval))
|
|
2106
2148
|
output = Time.parse(output.to_s) unless output.is_a?(Time) || output.is_a?(DateTime)
|
|
2107
|
-
output.year.
|
|
2108
|
-
output.month.
|
|
2109
|
-
output.day.
|
|
2110
|
-
output.hour.
|
|
2111
|
-
output.min.
|
|
2112
|
-
output.sec.
|
|
2149
|
+
output.year.must_equal should.year
|
|
2150
|
+
output.month.must_equal should.month
|
|
2151
|
+
output.day.must_equal should.day
|
|
2152
|
+
output.hour.must_equal should.hour
|
|
2153
|
+
output.min.must_equal should.min
|
|
2154
|
+
output.sec.must_equal should.sec
|
|
2113
2155
|
end
|
|
2114
2156
|
end
|
|
2115
2157
|
after(:all) do
|
|
@@ -2119,7 +2161,7 @@ describe "date_arithmetic extension" do
|
|
|
2119
2161
|
end
|
|
2120
2162
|
|
|
2121
2163
|
if asd
|
|
2122
|
-
|
|
2164
|
+
it "be able to use Sequel.date_add to add ActiveSupport::Duration objects to dates and datetimes" do
|
|
2123
2165
|
@check.call(:date_add, @date, @d0, @dt)
|
|
2124
2166
|
@check.call(:date_add, @date, @d1, @a1)
|
|
2125
2167
|
@check.call(:date_add, @date, @d2, @a2)
|
|
@@ -2129,7 +2171,7 @@ describe "date_arithmetic extension" do
|
|
|
2129
2171
|
@check.call(:date_add, @dt, @d2, @a2)
|
|
2130
2172
|
end
|
|
2131
2173
|
|
|
2132
|
-
|
|
2174
|
+
it "be able to use Sequel.date_sub to subtract ActiveSupport::Duration objects from dates and datetimes" do
|
|
2133
2175
|
@check.call(:date_sub, @date, @d0, @dt)
|
|
2134
2176
|
@check.call(:date_sub, @date, @d1, @s1)
|
|
2135
2177
|
@check.call(:date_sub, @date, @d2, @s2)
|
|
@@ -2140,7 +2182,7 @@ describe "date_arithmetic extension" do
|
|
|
2140
2182
|
end
|
|
2141
2183
|
end
|
|
2142
2184
|
|
|
2143
|
-
|
|
2185
|
+
it "be able to use Sequel.date_add to add interval hashes to dates and datetimes" do
|
|
2144
2186
|
@check.call(:date_add, @date, @h0, @dt)
|
|
2145
2187
|
@check.call(:date_add, @date, @h1, @a1)
|
|
2146
2188
|
@check.call(:date_add, @date, @h2, @a2)
|
|
@@ -2150,7 +2192,7 @@ describe "date_arithmetic extension" do
|
|
|
2150
2192
|
@check.call(:date_add, @dt, @h2, @a2)
|
|
2151
2193
|
end
|
|
2152
2194
|
|
|
2153
|
-
|
|
2195
|
+
it "be able to use Sequel.date_sub to subtract interval hashes from dates and datetimes" do
|
|
2154
2196
|
@check.call(:date_sub, @date, @h0, @dt)
|
|
2155
2197
|
@check.call(:date_sub, @date, @h1, @s1)
|
|
2156
2198
|
@check.call(:date_sub, @date, @h2, @s2)
|