sequel 4.22.0 → 4.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +22 -0
- data/README.rdoc +6 -0
- data/Rakefile +59 -81
- data/doc/migration.rdoc +2 -0
- data/doc/release_notes/4.23.0.txt +65 -0
- data/doc/sharding.rdoc +16 -14
- data/doc/testing.rdoc +61 -77
- data/lib/sequel/adapters/jdbc.rb +1 -0
- data/lib/sequel/adapters/mock.rb +0 -1
- data/lib/sequel/adapters/postgres.rb +1 -0
- data/lib/sequel/adapters/postgresql.rb +1 -0
- data/lib/sequel/adapters/shared/postgres.rb +3 -3
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
- data/lib/sequel/connection_pool/threaded.rb +9 -1
- data/lib/sequel/database/connecting.rb +1 -1
- data/lib/sequel/database/transactions.rb +2 -1
- data/lib/sequel/dataset/prepared_statements.rb +1 -1
- data/lib/sequel/extensions/constraint_validations.rb +12 -12
- data/lib/sequel/extensions/date_arithmetic.rb +0 -4
- data/lib/sequel/extensions/pagination.rb +14 -2
- data/lib/sequel/extensions/pg_enum.rb +2 -2
- data/lib/sequel/extensions/pg_hstore.rb +1 -1
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +2 -0
- data/lib/sequel/plugins/delay_add_association.rb +50 -0
- data/lib/sequel/plugins/list.rb +2 -2
- data/lib/sequel/plugins/nested_attributes.rb +8 -28
- data/lib/sequel/plugins/update_refresh.rb +50 -0
- data/lib/sequel/plugins/validate_associated.rb +55 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +29 -29
- data/spec/adapters/firebird_spec.rb +97 -103
- data/spec/adapters/informix_spec.rb +25 -25
- data/spec/adapters/mssql_spec.rb +156 -172
- data/spec/adapters/mysql_spec.rb +334 -359
- data/spec/adapters/oracle_spec.rb +67 -69
- data/spec/adapters/postgres_spec.rb +1298 -1249
- data/spec/adapters/spec_helper.rb +2 -35
- data/spec/adapters/sqlanywhere_spec.rb +39 -39
- data/spec/adapters/sqlite_spec.rb +203 -200
- data/spec/bin_spec.rb +57 -59
- data/spec/core/connection_pool_spec.rb +402 -401
- data/spec/core/database_spec.rb +953 -944
- data/spec/core/dataset_spec.rb +2178 -2168
- data/spec/core/deprecated_spec.rb +19 -19
- data/spec/core/expression_filters_spec.rb +415 -415
- data/spec/core/mock_adapter_spec.rb +212 -212
- data/spec/core/object_graph_spec.rb +73 -73
- data/spec/core/placeholder_literalizer_spec.rb +71 -71
- data/spec/core/schema_generator_spec.rb +44 -44
- data/spec/core/schema_spec.rb +470 -472
- data/spec/core/spec_helper.rb +5 -20
- data/spec/core/version_spec.rb +2 -2
- data/spec/core_extensions_spec.rb +320 -320
- data/spec/extensions/accessed_columns_spec.rb +12 -12
- data/spec/extensions/active_model_spec.rb +3 -3
- data/spec/extensions/after_initialize_spec.rb +2 -2
- data/spec/extensions/arbitrary_servers_spec.rb +23 -23
- data/spec/extensions/association_dependencies_spec.rb +34 -34
- data/spec/extensions/association_pks_spec.rb +98 -98
- data/spec/extensions/association_proxies_spec.rb +33 -33
- data/spec/extensions/auto_validations_spec.rb +46 -46
- data/spec/extensions/blacklist_security_spec.rb +19 -18
- data/spec/extensions/blank_spec.rb +36 -36
- data/spec/extensions/boolean_readers_spec.rb +36 -36
- data/spec/extensions/caching_spec.rb +82 -82
- data/spec/extensions/class_table_inheritance_spec.rb +72 -72
- data/spec/extensions/column_conflicts_spec.rb +19 -14
- data/spec/extensions/column_select_spec.rb +19 -19
- data/spec/extensions/columns_introspection_spec.rb +43 -43
- data/spec/extensions/composition_spec.rb +64 -64
- data/spec/extensions/connection_validator_spec.rb +92 -90
- data/spec/extensions/constraint_validations_plugin_spec.rb +92 -92
- data/spec/extensions/constraint_validations_spec.rb +80 -80
- data/spec/extensions/core_refinements_spec.rb +220 -220
- data/spec/extensions/csv_serializer_spec.rb +44 -44
- data/spec/extensions/current_datetime_timestamp_spec.rb +8 -8
- data/spec/extensions/dataset_associations_spec.rb +65 -65
- data/spec/extensions/dataset_source_alias_spec.rb +16 -16
- data/spec/extensions/date_arithmetic_spec.rb +51 -58
- data/spec/extensions/defaults_setter_spec.rb +19 -19
- data/spec/extensions/delay_add_association_spec.rb +52 -0
- data/spec/extensions/dirty_spec.rb +51 -51
- data/spec/extensions/eager_each_spec.rb +8 -8
- data/spec/extensions/empty_array_ignore_nulls_spec.rb +10 -10
- data/spec/extensions/error_splitter_spec.rb +2 -2
- data/spec/extensions/error_sql_spec.rb +4 -4
- data/spec/extensions/eval_inspect_spec.rb +3 -3
- data/spec/extensions/filter_having_spec.rb +8 -8
- data/spec/extensions/force_encoding_spec.rb +30 -30
- data/spec/extensions/from_block_spec.rb +7 -7
- data/spec/extensions/graph_each_spec.rb +19 -19
- data/spec/extensions/hash_aliases_spec.rb +5 -5
- data/spec/extensions/hook_class_methods_spec.rb +100 -100
- data/spec/extensions/inflector_spec.rb +54 -54
- data/spec/extensions/input_transformer_spec.rb +10 -10
- data/spec/extensions/insert_returning_select_spec.rb +8 -8
- data/spec/extensions/instance_filters_spec.rb +26 -26
- data/spec/extensions/instance_hooks_spec.rb +85 -85
- data/spec/extensions/json_serializer_spec.rb +68 -68
- data/spec/extensions/lazy_attributes_spec.rb +49 -49
- data/spec/extensions/list_spec.rb +77 -75
- data/spec/extensions/looser_typecasting_spec.rb +16 -16
- data/spec/extensions/many_through_many_spec.rb +627 -627
- data/spec/extensions/meta_def_spec.rb +7 -7
- data/spec/extensions/migration_spec.rb +217 -217
- data/spec/extensions/modification_detection_spec.rb +20 -20
- data/spec/extensions/mssql_optimistic_locking_spec.rb +21 -21
- data/spec/extensions/named_timezones_spec.rb +18 -18
- data/spec/extensions/nested_attributes_spec.rb +107 -107
- data/spec/extensions/null_dataset_spec.rb +24 -24
- data/spec/extensions/optimistic_locking_spec.rb +21 -21
- data/spec/extensions/pagination_spec.rb +52 -52
- data/spec/extensions/pg_array_associations_spec.rb +273 -273
- data/spec/extensions/pg_array_ops_spec.rb +52 -52
- data/spec/extensions/pg_array_spec.rb +152 -152
- data/spec/extensions/pg_enum_spec.rb +13 -13
- data/spec/extensions/pg_hstore_ops_spec.rb +63 -63
- data/spec/extensions/pg_hstore_spec.rb +84 -84
- data/spec/extensions/pg_inet_spec.rb +15 -15
- data/spec/extensions/pg_interval_spec.rb +29 -29
- data/spec/extensions/pg_json_ops_spec.rb +86 -84
- data/spec/extensions/pg_json_spec.rb +104 -104
- data/spec/extensions/pg_loose_count_spec.rb +6 -6
- data/spec/extensions/pg_range_ops_spec.rb +24 -24
- data/spec/extensions/pg_range_spec.rb +143 -143
- data/spec/extensions/pg_row_ops_spec.rb +14 -14
- data/spec/extensions/pg_row_plugin_spec.rb +12 -12
- data/spec/extensions/pg_row_spec.rb +118 -118
- data/spec/extensions/pg_static_cache_updater_spec.rb +28 -28
- data/spec/extensions/pg_typecast_on_load_spec.rb +21 -21
- data/spec/extensions/prepared_statements_associations_spec.rb +42 -42
- data/spec/extensions/prepared_statements_safe_spec.rb +18 -18
- data/spec/extensions/prepared_statements_spec.rb +28 -28
- data/spec/extensions/prepared_statements_with_pk_spec.rb +11 -11
- data/spec/extensions/pretty_table_spec.rb +16 -16
- data/spec/extensions/query_literals_spec.rb +37 -37
- data/spec/extensions/query_spec.rb +32 -32
- data/spec/extensions/rcte_tree_spec.rb +141 -141
- data/spec/extensions/round_timestamps_spec.rb +21 -21
- data/spec/extensions/schema_caching_spec.rb +8 -8
- data/spec/extensions/schema_dumper_spec.rb +78 -78
- data/spec/extensions/schema_spec.rb +31 -27
- data/spec/extensions/scissors_spec.rb +3 -3
- data/spec/extensions/select_remove_spec.rb +14 -14
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +28 -28
- data/spec/extensions/serialization_modification_detection_spec.rb +33 -33
- data/spec/extensions/serialization_spec.rb +79 -78
- data/spec/extensions/server_block_spec.rb +17 -17
- data/spec/extensions/set_overrides_spec.rb +30 -30
- data/spec/extensions/sharding_spec.rb +65 -65
- data/spec/extensions/shared_caching_spec.rb +29 -29
- data/spec/extensions/single_table_inheritance_spec.rb +79 -79
- data/spec/extensions/skip_create_refresh_spec.rb +3 -3
- data/spec/extensions/spec_helper.rb +4 -29
- data/spec/extensions/split_array_nil_spec.rb +9 -9
- data/spec/extensions/split_values_spec.rb +7 -7
- data/spec/extensions/sql_expr_spec.rb +32 -32
- data/spec/extensions/static_cache_spec.rb +123 -123
- data/spec/extensions/string_date_time_spec.rb +34 -34
- data/spec/extensions/string_stripper_spec.rb +15 -15
- data/spec/extensions/subclasses_spec.rb +31 -31
- data/spec/extensions/table_select_spec.rb +15 -15
- data/spec/extensions/tactical_eager_loading_spec.rb +23 -23
- data/spec/extensions/thread_local_timezones_spec.rb +13 -13
- data/spec/extensions/timestamps_spec.rb +40 -40
- data/spec/extensions/to_dot_spec.rb +34 -34
- data/spec/extensions/touch_spec.rb +52 -52
- data/spec/extensions/tree_spec.rb +72 -72
- data/spec/extensions/typecast_on_load_spec.rb +25 -25
- data/spec/extensions/unlimited_update_spec.rb +2 -2
- data/spec/extensions/update_or_create_spec.rb +36 -36
- data/spec/extensions/update_primary_key_spec.rb +35 -35
- data/spec/extensions/update_refresh_spec.rb +41 -0
- data/spec/extensions/validate_associated_spec.rb +52 -0
- data/spec/extensions/validation_class_methods_spec.rb +314 -317
- data/spec/extensions/validation_helpers_spec.rb +195 -195
- data/spec/extensions/xml_serializer_spec.rb +48 -48
- data/spec/guards_helper.rb +55 -0
- data/spec/integration/associations_test.rb +1089 -1088
- data/spec/integration/database_test.rb +29 -29
- data/spec/integration/dataset_test.rb +661 -661
- data/spec/integration/eager_loader_test.rb +147 -147
- data/spec/integration/migrator_test.rb +122 -122
- data/spec/integration/model_test.rb +70 -70
- data/spec/integration/plugin_test.rb +682 -640
- data/spec/integration/prepared_statement_test.rb +172 -172
- data/spec/integration/schema_test.rb +245 -245
- data/spec/integration/spec_helper.rb +1 -64
- data/spec/integration/timezone_test.rb +17 -17
- data/spec/integration/transaction_test.rb +87 -87
- data/spec/integration/type_test.rb +33 -33
- data/spec/model/association_reflection_spec.rb +130 -121
- data/spec/model/associations_spec.rb +1112 -1113
- data/spec/model/base_spec.rb +197 -196
- data/spec/model/class_dataset_methods_spec.rb +118 -118
- data/spec/model/dataset_methods_spec.rb +49 -49
- data/spec/model/eager_loading_spec.rb +705 -702
- data/spec/model/hooks_spec.rb +169 -168
- data/spec/model/inflector_spec.rb +5 -5
- data/spec/model/model_spec.rb +287 -297
- data/spec/model/plugins_spec.rb +47 -47
- data/spec/model/record_spec.rb +534 -535
- data/spec/model/spec_helper.rb +3 -21
- data/spec/model/validations_spec.rb +72 -70
- data/spec/spec_config.rb +8 -0
- metadata +41 -9
- data/lib/sequel/adapters/fdbsql.rb +0 -286
- data/lib/sequel/adapters/jdbc/fdbsql.rb +0 -66
- data/lib/sequel/adapters/openbase.rb +0 -54
- data/lib/sequel/adapters/shared/fdbsql.rb +0 -550
- data/spec/adapters/fdbsql_spec.rb +0 -429
- data/spec/rspec_helper.rb +0 -22
@@ -12,17 +12,17 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
12
12
|
DB.reset
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
it "should be definable using a block" do
|
16
16
|
adds = []
|
17
17
|
c = model_class.call Sequel::Model do
|
18
18
|
before_save{adds << 'hi'}
|
19
19
|
end
|
20
20
|
|
21
21
|
c.new.before_save
|
22
|
-
adds.
|
22
|
+
adds.must_equal ['hi']
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
it "should be definable using a method name" do
|
26
26
|
adds = []
|
27
27
|
c = model_class.call Sequel::Model do
|
28
28
|
define_method(:bye){adds << 'bye'}
|
@@ -30,10 +30,10 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
c.new.before_save
|
33
|
-
adds.
|
33
|
+
adds.must_equal ['bye']
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
it "should be additive" do
|
37
37
|
adds = []
|
38
38
|
c = model_class.call Sequel::Model do
|
39
39
|
after_save{adds << 'hyiyie'}
|
@@ -41,10 +41,10 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
c.new.after_save
|
44
|
-
adds.
|
44
|
+
adds.must_equal ['hyiyie', 'byiyie']
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
it "before hooks should run in reverse order" do
|
48
48
|
adds = []
|
49
49
|
c = model_class.call Sequel::Model do
|
50
50
|
before_save{adds << 'hyiyie'}
|
@@ -52,10 +52,10 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
c.new.before_save
|
55
|
-
adds.
|
55
|
+
adds.must_equal ['byiyie', 'hyiyie']
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
it "should not be additive if the method or tag already exists" do
|
59
59
|
adds = []
|
60
60
|
c = model_class.call Sequel::Model do
|
61
61
|
define_method(:bye){adds << 'bye'}
|
@@ -64,7 +64,7 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
c.new.before_save
|
67
|
-
adds.
|
67
|
+
adds.must_equal ['bye']
|
68
68
|
|
69
69
|
adds = []
|
70
70
|
d = model_class.call Sequel::Model do
|
@@ -73,7 +73,7 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
d.new.before_save
|
76
|
-
adds.
|
76
|
+
adds.must_equal ['byiyie']
|
77
77
|
|
78
78
|
adds = []
|
79
79
|
e = model_class.call Sequel::Model do
|
@@ -83,7 +83,7 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
e.new.before_save
|
86
|
-
adds.
|
86
|
+
adds.must_equal ['byiyie']
|
87
87
|
|
88
88
|
adds = []
|
89
89
|
e = model_class.call Sequel::Model do
|
@@ -93,10 +93,10 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
e.new.before_save
|
96
|
-
adds.
|
96
|
+
adds.must_equal ['bye']
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
it "should be inheritable" do
|
100
100
|
adds = []
|
101
101
|
a = model_class.call Sequel::Model do
|
102
102
|
after_save{adds << '123'}
|
@@ -109,10 +109,10 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
109
109
|
end
|
110
110
|
|
111
111
|
b.new.after_save
|
112
|
-
adds.
|
112
|
+
adds.must_equal ['123', '456', '789']
|
113
113
|
end
|
114
114
|
|
115
|
-
|
115
|
+
it "should be overridable in descendant classes" do
|
116
116
|
adds = []
|
117
117
|
a = model_class.call Sequel::Model do
|
118
118
|
before_save{adds << '123'}
|
@@ -124,13 +124,13 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
a.new.before_save
|
127
|
-
adds.
|
127
|
+
adds.must_equal ['123']
|
128
128
|
adds = []
|
129
129
|
b.new.before_save
|
130
|
-
adds.
|
130
|
+
adds.must_equal ['456']
|
131
131
|
end
|
132
132
|
|
133
|
-
|
133
|
+
it "should stop processing if a before hook returns false" do
|
134
134
|
flag = true
|
135
135
|
adds = []
|
136
136
|
|
@@ -140,18 +140,18 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
a.new.before_save
|
143
|
-
adds.
|
143
|
+
adds.must_equal ['blah', 'cruel']
|
144
144
|
|
145
145
|
# chain should not break on nil
|
146
146
|
adds = []
|
147
147
|
flag = nil
|
148
148
|
a.new.before_save
|
149
|
-
adds.
|
149
|
+
adds.must_equal ['blah', 'cruel']
|
150
150
|
|
151
151
|
adds = []
|
152
152
|
flag = false
|
153
153
|
a.new.before_save
|
154
|
-
adds.
|
154
|
+
adds.must_equal ['blah']
|
155
155
|
|
156
156
|
b = Class.new(a)
|
157
157
|
b.class_eval do
|
@@ -160,7 +160,7 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
160
160
|
|
161
161
|
adds = []
|
162
162
|
b.new.before_save
|
163
|
-
adds.
|
163
|
+
adds.must_equal ['mau', 'blah']
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
@@ -176,36 +176,36 @@ describe "Model#before_create && Model#after_create" do
|
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
|
-
|
179
|
+
it "should be called around new record creation" do
|
180
180
|
@c.before_create {DB << "BLAH before"}
|
181
181
|
@c.create(:x => 2)
|
182
|
-
DB.sqls.
|
182
|
+
DB.sqls.must_equal ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after']
|
183
183
|
end
|
184
184
|
|
185
|
-
|
185
|
+
it ".create should cancel the save and raise an error if before_create returns false and raise_on_save_failure is true" do
|
186
186
|
@c.before_create{false}
|
187
|
-
proc{@c.create(:x => 2)}.
|
188
|
-
DB.sqls.
|
187
|
+
proc{@c.create(:x => 2)}.must_raise(Sequel::HookFailed)
|
188
|
+
DB.sqls.must_equal []
|
189
189
|
end
|
190
190
|
|
191
|
-
|
191
|
+
it ".create should cancel the save and raise an error if before_create calls cancel_action and raise_on_save_failure is true" do
|
192
192
|
@c.before_create{cancel_action}
|
193
|
-
proc{@c.create(:x => 2)}.
|
194
|
-
DB.sqls.
|
193
|
+
proc{@c.create(:x => 2)}.must_raise(Sequel::HookFailed)
|
194
|
+
DB.sqls.must_equal []
|
195
195
|
end
|
196
196
|
|
197
|
-
|
197
|
+
it ".create should cancel the save and return nil if before_create returns false and raise_on_save_failure is false" do
|
198
198
|
@c.before_create{false}
|
199
199
|
@c.raise_on_save_failure = false
|
200
|
-
@c.create(:x => 2).
|
201
|
-
DB.sqls.
|
200
|
+
@c.create(:x => 2).must_equal nil
|
201
|
+
DB.sqls.must_equal []
|
202
202
|
end
|
203
203
|
|
204
|
-
|
204
|
+
it ".create should cancel the save and return nil if before_create calls cancel_action and raise_on_save_failure is false" do
|
205
205
|
@c.before_create{cancel_action}
|
206
206
|
@c.raise_on_save_failure = false
|
207
|
-
@c.create(:x => 2).
|
208
|
-
DB.sqls.
|
207
|
+
@c.create(:x => 2).must_equal nil
|
208
|
+
DB.sqls.must_equal []
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
@@ -218,24 +218,24 @@ describe "Model#before_update && Model#after_update" do
|
|
218
218
|
end
|
219
219
|
end
|
220
220
|
|
221
|
-
|
221
|
+
it "should be called around record update" do
|
222
222
|
@c.before_update {DB << "BLAH before"}
|
223
223
|
m = @c.load(:id => 2233, :x=>123)
|
224
224
|
m.save
|
225
|
-
DB.sqls.
|
225
|
+
DB.sqls.must_equal ['BLAH before', 'UPDATE items SET x = 123 WHERE (id = 2233)', 'BLAH after']
|
226
226
|
end
|
227
227
|
|
228
|
-
|
228
|
+
it "#save should cancel the save and raise an error if before_update returns false and raise_on_save_failure is true" do
|
229
229
|
@c.before_update{false}
|
230
|
-
proc{@c.load(:id => 2233).save}.
|
231
|
-
DB.sqls.
|
230
|
+
proc{@c.load(:id => 2233).save}.must_raise(Sequel::HookFailed)
|
231
|
+
DB.sqls.must_equal []
|
232
232
|
end
|
233
233
|
|
234
|
-
|
234
|
+
it "#save should cancel the save and return nil if before_update returns false and raise_on_save_failure is false" do
|
235
235
|
@c.before_update{false}
|
236
236
|
@c.raise_on_save_failure = false
|
237
|
-
@c.load(:id => 2233).save.
|
238
|
-
DB.sqls.
|
237
|
+
@c.load(:id => 2233).save.must_equal nil
|
238
|
+
DB.sqls.must_equal []
|
239
239
|
end
|
240
240
|
end
|
241
241
|
|
@@ -249,31 +249,31 @@ describe "Model#before_save && Model#after_save" do
|
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
252
|
-
|
252
|
+
it "should be called around record update" do
|
253
253
|
@c.before_save {DB << "BLAH before"}
|
254
254
|
m = @c.load(:id => 2233, :x=>123)
|
255
255
|
m.save
|
256
|
-
DB.sqls.
|
256
|
+
DB.sqls.must_equal ['BLAH before', 'UPDATE items SET x = 123 WHERE (id = 2233)', 'BLAH after']
|
257
257
|
end
|
258
258
|
|
259
|
-
|
259
|
+
it "should be called around record creation" do
|
260
260
|
@c.before_save {DB << "BLAH before"}
|
261
261
|
@c.no_primary_key
|
262
262
|
@c.create(:x => 2)
|
263
|
-
DB.sqls.
|
263
|
+
DB.sqls.must_equal ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after']
|
264
264
|
end
|
265
265
|
|
266
|
-
|
266
|
+
it "#save should cancel the save and raise an error if before_save returns false and raise_on_save_failure is true" do
|
267
267
|
@c.before_save{false}
|
268
|
-
proc{@c.load(:id => 2233).save}.
|
269
|
-
DB.sqls.
|
268
|
+
proc{@c.load(:id => 2233).save}.must_raise(Sequel::HookFailed)
|
269
|
+
DB.sqls.must_equal []
|
270
270
|
end
|
271
271
|
|
272
|
-
|
272
|
+
it "#save should cancel the save and return nil if before_save returns false and raise_on_save_failure is false" do
|
273
273
|
@c.before_save{false}
|
274
274
|
@c.raise_on_save_failure = false
|
275
|
-
@c.load(:id => 2233).save.
|
276
|
-
DB.sqls.
|
275
|
+
@c.load(:id => 2233).save.must_equal nil
|
276
|
+
DB.sqls.must_equal []
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
@@ -286,24 +286,24 @@ describe "Model#before_destroy && Model#after_destroy" do
|
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
289
|
-
|
289
|
+
it "should be called around record destruction" do
|
290
290
|
@c.before_destroy {DB << "BLAH before"}
|
291
291
|
m = @c.load(:id => 2233)
|
292
292
|
m.destroy
|
293
|
-
DB.sqls.
|
293
|
+
DB.sqls.must_equal ['BLAH before', "DELETE FROM items WHERE id = 2233", 'BLAH after']
|
294
294
|
end
|
295
295
|
|
296
|
-
|
296
|
+
it "#destroy should cancel the destroy and raise an error if before_destroy returns false and raise_on_save_failure is true" do
|
297
297
|
@c.before_destroy{false}
|
298
|
-
proc{@c.load(:id => 2233).destroy}.
|
299
|
-
DB.sqls.
|
298
|
+
proc{@c.load(:id => 2233).destroy}.must_raise(Sequel::HookFailed)
|
299
|
+
DB.sqls.must_equal []
|
300
300
|
end
|
301
301
|
|
302
|
-
|
302
|
+
it "#destroy should cancel the destroy and return nil if before_destroy returns false and raise_on_save_failure is false" do
|
303
303
|
@c.before_destroy{false}
|
304
304
|
@c.raise_on_save_failure = false
|
305
|
-
@c.load(:id => 2233).destroy.
|
306
|
-
DB.sqls.
|
305
|
+
@c.load(:id => 2233).destroy.must_equal nil
|
306
|
+
DB.sqls.must_equal []
|
307
307
|
end
|
308
308
|
end
|
309
309
|
|
@@ -322,42 +322,42 @@ describe "Model#before_validation && Model#after_validation" do
|
|
322
322
|
end
|
323
323
|
end
|
324
324
|
|
325
|
-
|
325
|
+
it "should be called around validation" do
|
326
326
|
@c.before_validation{DB << "BLAH before"}
|
327
327
|
m = @c.load(:id => 2233)
|
328
|
-
m.
|
329
|
-
DB.sqls.
|
328
|
+
m.must_be :valid?
|
329
|
+
DB.sqls.must_equal ['BLAH before', 'BLAH after']
|
330
330
|
|
331
331
|
DB.sqls.clear
|
332
332
|
m = @c.load(:id => 22)
|
333
|
-
m.
|
334
|
-
DB.sqls.
|
333
|
+
m.wont_be :valid?
|
334
|
+
DB.sqls.must_equal ['BLAH before', 'BLAH after']
|
335
335
|
end
|
336
336
|
|
337
|
-
|
337
|
+
it "should be called when calling save" do
|
338
338
|
@c.before_validation{DB << "BLAH before"}
|
339
339
|
m = @c.load(:id => 2233, :x=>123)
|
340
|
-
m.save.
|
341
|
-
DB.sqls.
|
340
|
+
m.save.must_equal m
|
341
|
+
DB.sqls.must_equal ['BLAH before', 'BLAH after', 'UPDATE items SET x = 123 WHERE (id = 2233)']
|
342
342
|
|
343
343
|
DB.sqls.clear
|
344
344
|
m = @c.load(:id => 22)
|
345
345
|
m.raise_on_save_failure = false
|
346
|
-
m.save.
|
347
|
-
DB.sqls.
|
346
|
+
m.save.must_equal nil
|
347
|
+
DB.sqls.must_equal ['BLAH before', 'BLAH after']
|
348
348
|
end
|
349
349
|
|
350
|
-
|
350
|
+
it "#save should cancel the save and raise an error if before_validation returns false and raise_on_save_failure is true" do
|
351
351
|
@c.before_validation{false}
|
352
|
-
proc{@c.load(:id => 2233).save}.
|
353
|
-
DB.sqls.
|
352
|
+
proc{@c.load(:id => 2233).save}.must_raise(Sequel::HookFailed)
|
353
|
+
DB.sqls.must_equal []
|
354
354
|
end
|
355
355
|
|
356
|
-
|
356
|
+
it "#save should cancel the save and return nil if before_validation returns false and raise_on_save_failure is false" do
|
357
357
|
@c.before_validation{false}
|
358
358
|
@c.raise_on_save_failure = false
|
359
|
-
@c.load(:id => 2233).save.
|
360
|
-
DB.sqls.
|
359
|
+
@c.load(:id => 2233).save.must_equal nil
|
360
|
+
DB.sqls.must_equal []
|
361
361
|
end
|
362
362
|
end
|
363
363
|
|
@@ -366,18 +366,18 @@ describe "Model.has_hooks?" do
|
|
366
366
|
@c = model_class.call(Sequel::Model(:items))
|
367
367
|
end
|
368
368
|
|
369
|
-
|
370
|
-
@c.has_hooks?(:before_save).
|
369
|
+
it "should return false if no hooks are defined" do
|
370
|
+
@c.has_hooks?(:before_save).must_equal false
|
371
371
|
end
|
372
372
|
|
373
|
-
|
373
|
+
it "should return true if hooks are defined" do
|
374
374
|
@c.before_save {'blah'}
|
375
|
-
@c.has_hooks?(:before_save).
|
375
|
+
@c.has_hooks?(:before_save).must_equal true
|
376
376
|
end
|
377
377
|
|
378
|
-
|
378
|
+
it "should return true if hooks are inherited" do
|
379
379
|
@d = Class.new(@c)
|
380
|
-
@d.has_hooks?(:before_save).
|
380
|
+
@d.has_hooks?(:before_save).must_equal false
|
381
381
|
end
|
382
382
|
end
|
383
383
|
|
@@ -399,31 +399,31 @@ describe "Model#add_hook_type" do
|
|
399
399
|
Object.send(:remove_const, :Foo)
|
400
400
|
end
|
401
401
|
|
402
|
-
|
403
|
-
@f.
|
404
|
-
@f.
|
402
|
+
it "should have before_bar and after_bar class methods" do
|
403
|
+
@f.must_respond_to(:before_bar)
|
404
|
+
@f.must_respond_to(:before_bar)
|
405
405
|
end
|
406
406
|
|
407
|
-
|
408
|
-
@f.new.
|
409
|
-
@f.new.
|
407
|
+
it "should have before_bar and after_bar instance methods" do
|
408
|
+
@f.new.must_respond_to(:before_bar)
|
409
|
+
@f.new.must_respond_to(:before_bar)
|
410
410
|
end
|
411
411
|
|
412
|
-
|
412
|
+
it "it should return true for bar when before_bar and after_bar hooks are returing true" do
|
413
413
|
a = 1
|
414
414
|
@f.before_bar { a += 1}
|
415
|
-
@f.new.bar.
|
416
|
-
a.
|
415
|
+
@f.new.bar.must_equal true
|
416
|
+
a.must_equal 2
|
417
417
|
@f.after_bar { a *= 2}
|
418
|
-
@f.new.bar.
|
419
|
-
a.
|
418
|
+
@f.new.bar.must_equal true
|
419
|
+
a.must_equal 6
|
420
420
|
end
|
421
421
|
|
422
|
-
|
423
|
-
@f.new.bar.
|
422
|
+
it "it should return nil for bar when before_bar and after_bar hooks are returing false" do
|
423
|
+
@f.new.bar.must_equal true
|
424
424
|
@f.after_bar { false }
|
425
|
-
@f.new.bar.
|
425
|
+
@f.new.bar.must_equal :a
|
426
426
|
@f.before_bar { false }
|
427
|
-
@f.new.bar.
|
427
|
+
@f.new.bar.must_equal :b
|
428
428
|
end
|
429
429
|
end
|
@@ -4,79 +4,79 @@ Sequel.extension :inflector
|
|
4
4
|
|
5
5
|
describe String do
|
6
6
|
it "#camelize and #camelcase should transform the word to CamelCase" do
|
7
|
-
"egg_and_hams".camelize.
|
8
|
-
"egg_and_hams".camelize(false).
|
9
|
-
"post".camelize.
|
10
|
-
"post".camelcase.
|
7
|
+
"egg_and_hams".camelize.must_equal "EggAndHams"
|
8
|
+
"egg_and_hams".camelize(false).must_equal "eggAndHams"
|
9
|
+
"post".camelize.must_equal "Post"
|
10
|
+
"post".camelcase.must_equal "Post"
|
11
11
|
end
|
12
12
|
|
13
13
|
it "#constantize should eval the string to get a constant" do
|
14
|
-
"String".constantize.
|
15
|
-
"String::Inflections".constantize.
|
16
|
-
proc{"BKSDDF".constantize}.
|
17
|
-
proc{"++A++".constantize}.
|
14
|
+
"String".constantize.must_equal String
|
15
|
+
"String::Inflections".constantize.must_equal String::Inflections
|
16
|
+
proc{"BKSDDF".constantize}.must_raise NameError
|
17
|
+
proc{"++A++".constantize}.must_raise NameError
|
18
18
|
end
|
19
19
|
|
20
20
|
it "#dasherize should transform underscores to dashes" do
|
21
|
-
"egg_and_hams".dasherize.
|
22
|
-
"post".dasherize.
|
21
|
+
"egg_and_hams".dasherize.must_equal "egg-and-hams"
|
22
|
+
"post".dasherize.must_equal "post"
|
23
23
|
end
|
24
24
|
|
25
25
|
it "#demodulize should remove any preceding modules" do
|
26
|
-
"String::Inflections::Blah".demodulize.
|
27
|
-
"String::Inflections".demodulize.
|
28
|
-
"String".demodulize.
|
26
|
+
"String::Inflections::Blah".demodulize.must_equal "Blah"
|
27
|
+
"String::Inflections".demodulize.must_equal "Inflections"
|
28
|
+
"String".demodulize.must_equal "String"
|
29
29
|
end
|
30
30
|
|
31
31
|
it "#humanize should remove _i, transform underscore to spaces, and capitalize" do
|
32
|
-
"egg_and_hams".humanize.
|
33
|
-
"post".humanize.
|
34
|
-
"post_id".humanize.
|
32
|
+
"egg_and_hams".humanize.must_equal "Egg and hams"
|
33
|
+
"post".humanize.must_equal "Post"
|
34
|
+
"post_id".humanize.must_equal "Post"
|
35
35
|
end
|
36
36
|
|
37
37
|
it "#titleize and #titlecase should underscore, humanize, and capitalize all words" do
|
38
|
-
"egg-and: hams".titleize.
|
39
|
-
"post".titleize.
|
40
|
-
"post".titlecase.
|
38
|
+
"egg-and: hams".titleize.must_equal "Egg And: Hams"
|
39
|
+
"post".titleize.must_equal "Post"
|
40
|
+
"post".titlecase.must_equal "Post"
|
41
41
|
end
|
42
42
|
|
43
43
|
it "#underscore should add underscores between CamelCased words, change :: to / and - to _, and downcase" do
|
44
|
-
"EggAndHams".underscore.
|
45
|
-
"EGGAndHams".underscore.
|
46
|
-
"Egg::And::Hams".underscore.
|
47
|
-
"post".underscore.
|
48
|
-
"post-id".underscore.
|
44
|
+
"EggAndHams".underscore.must_equal "egg_and_hams"
|
45
|
+
"EGGAndHams".underscore.must_equal "egg_and_hams"
|
46
|
+
"Egg::And::Hams".underscore.must_equal "egg/and/hams"
|
47
|
+
"post".underscore.must_equal "post"
|
48
|
+
"post-id".underscore.must_equal "post_id"
|
49
49
|
end
|
50
50
|
|
51
51
|
it "#pluralize should transform words from singular to plural" do
|
52
|
-
"post".pluralize.
|
53
|
-
"octopus".pluralize.
|
54
|
-
"the blue mailman".pluralize.
|
55
|
-
"CamelOctopus".pluralize.
|
52
|
+
"post".pluralize.must_equal "posts"
|
53
|
+
"octopus".pluralize.must_equal"octopuses"
|
54
|
+
"the blue mailman".pluralize.must_equal "the blue mailmen"
|
55
|
+
"CamelOctopus".pluralize.must_equal "CamelOctopuses"
|
56
56
|
end
|
57
57
|
|
58
58
|
it "#singularize should transform words from plural to singular" do
|
59
|
-
"posts".singularize.
|
60
|
-
"octopuses".singularize.
|
61
|
-
"the blue mailmen".singularize.
|
62
|
-
"CamelOctopuses".singularize.
|
59
|
+
"posts".singularize.must_equal "post"
|
60
|
+
"octopuses".singularize.must_equal "octopus"
|
61
|
+
"the blue mailmen".singularize.must_equal "the blue mailman"
|
62
|
+
"CamelOctopuses".singularize.must_equal "CamelOctopus"
|
63
63
|
end
|
64
64
|
|
65
65
|
it "#tableize should transform class names to table names" do
|
66
|
-
"RawScaledScorer".tableize.
|
67
|
-
"egg_and_ham".tableize.
|
68
|
-
"fancyCategory".tableize.
|
66
|
+
"RawScaledScorer".tableize.must_equal "raw_scaled_scorers"
|
67
|
+
"egg_and_ham".tableize.must_equal "egg_and_hams"
|
68
|
+
"fancyCategory".tableize.must_equal "fancy_categories"
|
69
69
|
end
|
70
70
|
|
71
71
|
it "#classify should tranform table names to class names" do
|
72
|
-
"egg_and_hams".classify.
|
73
|
-
"post".classify.
|
72
|
+
"egg_and_hams".classify.must_equal "EggAndHam"
|
73
|
+
"post".classify.must_equal "Post"
|
74
74
|
end
|
75
75
|
|
76
76
|
it "#foreign_key should create a foreign key name from a class name" do
|
77
|
-
"Message".foreign_key.
|
78
|
-
"Message".foreign_key(false).
|
79
|
-
"Admin::Post".foreign_key.
|
77
|
+
"Message".foreign_key.must_equal "message_id"
|
78
|
+
"Message".foreign_key(false).must_equal "messageid"
|
79
|
+
"Admin::Post".foreign_key.must_equal "post_id"
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -92,12 +92,12 @@ describe String::Inflections do
|
|
92
92
|
|
93
93
|
it "should be possible to clear the list of singulars, plurals, and uncountables" do
|
94
94
|
String.inflections.clear(:plurals)
|
95
|
-
String.inflections.plurals.
|
95
|
+
String.inflections.plurals.must_equal []
|
96
96
|
String.inflections.plural('blah', 'blahs')
|
97
97
|
String.inflections.clear
|
98
|
-
String.inflections.plurals.
|
99
|
-
String.inflections.singulars.
|
100
|
-
String.inflections.uncountables.
|
98
|
+
String.inflections.plurals.must_equal []
|
99
|
+
String.inflections.singulars.must_equal []
|
100
|
+
String.inflections.uncountables.must_equal []
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should be able to specify new inflection rules" do
|
@@ -107,16 +107,16 @@ describe String::Inflections do
|
|
107
107
|
i.irregular('yy', 'yyy')
|
108
108
|
i.uncountable(%w'zz')
|
109
109
|
end
|
110
|
-
'roxx'.pluralize.
|
111
|
-
'rottt'.singularize.
|
112
|
-
'yy'.pluralize.
|
113
|
-
'yyy'.singularize.
|
114
|
-
'zz'.pluralize.
|
115
|
-
'zz'.singularize.
|
110
|
+
'roxx'.pluralize.must_equal 'roxxx'
|
111
|
+
'rottt'.singularize.must_equal 'rott'
|
112
|
+
'yy'.pluralize.must_equal 'yyy'
|
113
|
+
'yyy'.singularize.must_equal 'yy'
|
114
|
+
'zz'.pluralize.must_equal 'zz'
|
115
|
+
'zz'.singularize.must_equal 'zz'
|
116
116
|
end
|
117
117
|
|
118
118
|
it "should be yielded and returned by String.inflections" do
|
119
|
-
String.inflections{|i| i.
|
119
|
+
String.inflections{|i| i.must_equal String::Inflections}.must_equal String::Inflections
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -173,11 +173,11 @@ describe 'Default inflections' do
|
|
173
173
|
:sex=>:sexes,
|
174
174
|
:move=>:moves
|
175
175
|
}.each do |k, v|
|
176
|
-
k.to_s.pluralize.
|
177
|
-
v.to_s.singularize.
|
176
|
+
k.to_s.pluralize.must_equal v.to_s
|
177
|
+
v.to_s.singularize.must_equal k.to_s
|
178
178
|
end
|
179
179
|
[:equipment, :information, :rice, :money, :species, :series, :fish, :sheep, :news].each do |a|
|
180
|
-
a.to_s.pluralize.
|
180
|
+
a.to_s.pluralize.must_equal a.to_s.singularize
|
181
181
|
end
|
182
182
|
end
|
183
183
|
end
|