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
|
@@ -12,84 +12,84 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
12
12
|
@m = @c.new
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
it "should take an :allow_blank option" do
|
|
16
16
|
@c.set_validations{validates_format(/.+_.+/, :value, :allow_blank=>true)}
|
|
17
17
|
@m.value = 'abc_'
|
|
18
|
-
@m.
|
|
18
|
+
@m.wont_be :valid?
|
|
19
19
|
@m.value = '1_1'
|
|
20
|
-
@m.
|
|
20
|
+
@m.must_be :valid?
|
|
21
21
|
o = Object.new
|
|
22
22
|
@m.value = o
|
|
23
|
-
@m.
|
|
23
|
+
@m.wont_be :valid?
|
|
24
24
|
def o.blank?
|
|
25
25
|
true
|
|
26
26
|
end
|
|
27
|
-
@m.
|
|
27
|
+
@m.must_be :valid?
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
it "should take an :allow_missing option" do
|
|
31
31
|
@c.set_validations{validates_format(/.+_.+/, :value, :allow_missing=>true)}
|
|
32
32
|
@m.values.clear
|
|
33
|
-
@m.
|
|
33
|
+
@m.must_be :valid?
|
|
34
34
|
@m.value = nil
|
|
35
|
-
@m.
|
|
35
|
+
@m.wont_be :valid?
|
|
36
36
|
@m.value = '1_1'
|
|
37
|
-
@m.
|
|
37
|
+
@m.must_be :valid?
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
it "should take an :allow_nil option" do
|
|
41
41
|
@c.set_validations{validates_format(/.+_.+/, :value, :allow_nil=>true)}
|
|
42
42
|
@m.value = 'abc_'
|
|
43
|
-
@m.
|
|
43
|
+
@m.wont_be :valid?
|
|
44
44
|
@m.value = '1_1'
|
|
45
|
-
@m.
|
|
45
|
+
@m.must_be :valid?
|
|
46
46
|
@m.value = nil
|
|
47
|
-
@m.
|
|
47
|
+
@m.must_be :valid?
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
it "should take a :message option" do
|
|
51
51
|
@c.set_validations{validates_format(/.+_.+/, :value, :message=>"is so blah")}
|
|
52
52
|
@m.value = 'abc_'
|
|
53
|
-
@m.
|
|
54
|
-
@m.errors.full_messages.
|
|
53
|
+
@m.wont_be :valid?
|
|
54
|
+
@m.errors.full_messages.must_equal ['value is so blah']
|
|
55
55
|
@m.value = '1_1'
|
|
56
|
-
@m.
|
|
56
|
+
@m.must_be :valid?
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
it "should allow a proc for the :message option" do
|
|
60
60
|
@c.set_validations{validates_format(/.+_.+/, :value, :message=>proc{|f| "doesn't match #{f.inspect}"})}
|
|
61
61
|
@m.value = 'abc_'
|
|
62
|
-
@m.
|
|
63
|
-
@m.errors.
|
|
62
|
+
@m.wont_be :valid?
|
|
63
|
+
@m.errors.must_equal(:value=>["doesn't match /.+_.+/"])
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
it "should take multiple attributes in the same call" do
|
|
67
67
|
@c.columns :value, :value2
|
|
68
68
|
@c.set_validations{validates_presence([:value, :value2])}
|
|
69
|
-
@m.
|
|
69
|
+
@m.wont_be :valid?
|
|
70
70
|
@m.value = 1
|
|
71
|
-
@m.
|
|
71
|
+
@m.wont_be :valid?
|
|
72
72
|
@m.value2 = 1
|
|
73
|
-
@m.
|
|
73
|
+
@m.must_be :valid?
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
it "should support modifying default options for all models" do
|
|
77
77
|
@c.set_validations{validates_presence(:value)}
|
|
78
|
-
@m.
|
|
79
|
-
@m.errors.
|
|
78
|
+
@m.wont_be :valid?
|
|
79
|
+
@m.errors.must_equal(:value=>['is not present'])
|
|
80
80
|
o = Sequel::Plugins::ValidationHelpers::DEFAULT_OPTIONS[:presence].dup
|
|
81
81
|
Sequel::Plugins::ValidationHelpers::DEFAULT_OPTIONS[:presence][:message] = lambda{"was not entered"}
|
|
82
|
-
@m.
|
|
83
|
-
@m.errors.
|
|
82
|
+
@m.wont_be :valid?
|
|
83
|
+
@m.errors.must_equal(:value=>["was not entered"])
|
|
84
84
|
@m.value = 1
|
|
85
|
-
@m.
|
|
85
|
+
@m.must_be :valid?
|
|
86
86
|
|
|
87
87
|
@m.values.clear
|
|
88
88
|
Sequel::Plugins::ValidationHelpers::DEFAULT_OPTIONS[:presence][:allow_missing] = true
|
|
89
|
-
@m.
|
|
89
|
+
@m.must_be :valid?
|
|
90
90
|
@m.value = nil
|
|
91
|
-
@m.
|
|
92
|
-
@m.errors.
|
|
91
|
+
@m.wont_be :valid?
|
|
92
|
+
@m.errors.must_equal(:value=>["was not entered"])
|
|
93
93
|
|
|
94
94
|
|
|
95
95
|
c = Class.new(Sequel::Model)
|
|
@@ -101,28 +101,28 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
m = c.new(:value=>nil)
|
|
104
|
-
m.
|
|
105
|
-
m.errors.
|
|
104
|
+
m.wont_be :valid?
|
|
105
|
+
m.errors.must_equal(:value=>["was not entered"])
|
|
106
106
|
Sequel::Plugins::ValidationHelpers::DEFAULT_OPTIONS[:presence] = o
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
it "should support modifying default validation options for a particular model" do
|
|
110
110
|
@c.set_validations{validates_presence(:value)}
|
|
111
|
-
@m.
|
|
112
|
-
@m.errors.
|
|
111
|
+
@m.wont_be :valid?
|
|
112
|
+
@m.errors.must_equal(:value=>['is not present'])
|
|
113
113
|
@c.class_eval do
|
|
114
114
|
def default_validation_helpers_options(type)
|
|
115
115
|
{:allow_missing=>true, :message=>proc{'was not entered'}}
|
|
116
116
|
end
|
|
117
117
|
end
|
|
118
118
|
@m.value = nil
|
|
119
|
-
@m.
|
|
120
|
-
@m.errors.
|
|
119
|
+
@m.wont_be :valid?
|
|
120
|
+
@m.errors.must_equal(:value=>["was not entered"])
|
|
121
121
|
@m.value = 1
|
|
122
|
-
@m.
|
|
122
|
+
@m.must_be :valid?
|
|
123
123
|
|
|
124
124
|
@m.values.clear
|
|
125
|
-
@m.
|
|
125
|
+
@m.must_be :valid?
|
|
126
126
|
|
|
127
127
|
c = Class.new(Sequel::Model)
|
|
128
128
|
c.class_eval do
|
|
@@ -133,225 +133,225 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
133
133
|
end
|
|
134
134
|
end
|
|
135
135
|
m = c.new
|
|
136
|
-
m.
|
|
137
|
-
m.errors.
|
|
136
|
+
m.wont_be :valid?
|
|
137
|
+
m.errors.must_equal(:value=>['is not present'])
|
|
138
138
|
end
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
it "should support validates_exact_length" do
|
|
141
141
|
@c.set_validations{validates_exact_length(3, :value)}
|
|
142
|
-
@m.
|
|
142
|
+
@m.wont_be :valid?
|
|
143
143
|
@m.value = '123'
|
|
144
|
-
@m.
|
|
144
|
+
@m.must_be :valid?
|
|
145
145
|
@m.value = '12'
|
|
146
|
-
@m.
|
|
146
|
+
@m.wont_be :valid?
|
|
147
147
|
@m.value = '1234'
|
|
148
|
-
@m.
|
|
148
|
+
@m.wont_be :valid?
|
|
149
149
|
end
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
it "should support validate_format" do
|
|
152
152
|
@c.set_validations{validates_format(/.+_.+/, :value)}
|
|
153
153
|
@m.value = 'abc_'
|
|
154
|
-
@m.
|
|
154
|
+
@m.wont_be :valid?
|
|
155
155
|
@m.value = 'abc_def'
|
|
156
|
-
@m.
|
|
156
|
+
@m.must_be :valid?
|
|
157
157
|
end
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
it "should support validates_includes with an array" do
|
|
160
160
|
@c.set_validations{validates_includes([1,2], :value)}
|
|
161
|
-
@m.
|
|
161
|
+
@m.wont_be :valid?
|
|
162
162
|
@m.value = 1
|
|
163
|
-
@m.
|
|
163
|
+
@m.must_be :valid?
|
|
164
164
|
@m.value = 1.5
|
|
165
|
-
@m.
|
|
165
|
+
@m.wont_be :valid?
|
|
166
166
|
@m.value = 2
|
|
167
|
-
@m.
|
|
167
|
+
@m.must_be :valid?
|
|
168
168
|
@m.value = 3
|
|
169
|
-
@m.
|
|
169
|
+
@m.wont_be :valid?
|
|
170
170
|
end
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
it "should support validates_includes with a range" do
|
|
173
173
|
@c.set_validations{validates_includes(1..4, :value)}
|
|
174
|
-
@m.
|
|
174
|
+
@m.wont_be :valid?
|
|
175
175
|
@m.value = 1
|
|
176
|
-
@m.
|
|
176
|
+
@m.must_be :valid?
|
|
177
177
|
@m.value = 1.5
|
|
178
|
-
@m.
|
|
178
|
+
@m.must_be :valid?
|
|
179
179
|
@m.value = 0
|
|
180
|
-
@m.
|
|
180
|
+
@m.wont_be :valid?
|
|
181
181
|
@m.value = 5
|
|
182
|
-
@m.
|
|
182
|
+
@m.wont_be :valid?
|
|
183
183
|
end
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
it "should supports validates_integer" do
|
|
186
186
|
@c.set_validations{validates_integer(:value)}
|
|
187
187
|
@m.value = 'blah'
|
|
188
|
-
@m.
|
|
188
|
+
@m.wont_be :valid?
|
|
189
189
|
@m.value = '123'
|
|
190
|
-
@m.
|
|
190
|
+
@m.must_be :valid?
|
|
191
191
|
@m.value = '123.1231'
|
|
192
|
-
@m.
|
|
192
|
+
@m.wont_be :valid?
|
|
193
193
|
end
|
|
194
194
|
|
|
195
|
-
|
|
195
|
+
it "should support validates_length_range" do
|
|
196
196
|
@c.set_validations{validates_length_range(2..5, :value)}
|
|
197
|
-
@m.
|
|
197
|
+
@m.wont_be :valid?
|
|
198
198
|
@m.value = '12345'
|
|
199
|
-
@m.
|
|
199
|
+
@m.must_be :valid?
|
|
200
200
|
@m.value = '1'
|
|
201
|
-
@m.
|
|
201
|
+
@m.wont_be :valid?
|
|
202
202
|
@m.value = '123456'
|
|
203
|
-
@m.
|
|
203
|
+
@m.wont_be :valid?
|
|
204
204
|
end
|
|
205
205
|
|
|
206
|
-
|
|
206
|
+
it "should support validates_max_length" do
|
|
207
207
|
@c.set_validations{validates_max_length(5, :value)}
|
|
208
|
-
@m.
|
|
208
|
+
@m.wont_be :valid?
|
|
209
209
|
@m.value = '12345'
|
|
210
|
-
@m.
|
|
210
|
+
@m.must_be :valid?
|
|
211
211
|
@m.value = '123456'
|
|
212
|
-
@m.
|
|
213
|
-
@m.errors[:value].
|
|
212
|
+
@m.wont_be :valid?
|
|
213
|
+
@m.errors[:value].must_equal ['is longer than 5 characters']
|
|
214
214
|
@m.value = nil
|
|
215
|
-
@m.
|
|
216
|
-
@m.errors[:value].
|
|
215
|
+
@m.wont_be :valid?
|
|
216
|
+
@m.errors[:value].must_equal ['is not present']
|
|
217
217
|
end
|
|
218
218
|
|
|
219
|
-
|
|
219
|
+
it "should support validates_max_length with nil value" do
|
|
220
220
|
@c.set_validations{validates_max_length(5, :value, :message=>'tl', :nil_message=>'np')}
|
|
221
221
|
@m.value = '123456'
|
|
222
|
-
@m.
|
|
223
|
-
@m.errors[:value].
|
|
222
|
+
@m.wont_be :valid?
|
|
223
|
+
@m.errors[:value].must_equal ['tl']
|
|
224
224
|
@m.value = nil
|
|
225
|
-
@m.
|
|
226
|
-
@m.errors[:value].
|
|
225
|
+
@m.wont_be :valid?
|
|
226
|
+
@m.errors[:value].must_equal ['np']
|
|
227
227
|
end
|
|
228
228
|
|
|
229
|
-
|
|
229
|
+
it "should support validates_min_length" do
|
|
230
230
|
@c.set_validations{validates_min_length(5, :value)}
|
|
231
|
-
@m.
|
|
231
|
+
@m.wont_be :valid?
|
|
232
232
|
@m.value = '12345'
|
|
233
|
-
@m.
|
|
233
|
+
@m.must_be :valid?
|
|
234
234
|
@m.value = '1234'
|
|
235
|
-
@m.
|
|
235
|
+
@m.wont_be :valid?
|
|
236
236
|
end
|
|
237
237
|
|
|
238
|
-
|
|
238
|
+
it "should support validates_schema_types" do
|
|
239
239
|
@c.set_validations{validates_schema_types}
|
|
240
240
|
@m.value = 123
|
|
241
|
-
@m.
|
|
241
|
+
@m.must_be :valid?
|
|
242
242
|
@m.value = '123'
|
|
243
|
-
@m.
|
|
243
|
+
@m.must_be :valid?
|
|
244
244
|
@m.meta_def(:db_schema){{:value=>{:type=>:integer}}}
|
|
245
|
-
@m.
|
|
246
|
-
@m.errors.full_messages.
|
|
245
|
+
@m.wont_be :valid?
|
|
246
|
+
@m.errors.full_messages.must_equal ['value is not a valid integer']
|
|
247
247
|
|
|
248
248
|
@c.set_validations{validates_schema_types(:value)}
|
|
249
249
|
@m.meta_def(:db_schema){{:value=>{:type=>:integer}}}
|
|
250
|
-
@m.
|
|
251
|
-
@m.errors.full_messages.
|
|
250
|
+
@m.wont_be :valid?
|
|
251
|
+
@m.errors.full_messages.must_equal ['value is not a valid integer']
|
|
252
252
|
|
|
253
253
|
@c.set_validations{validates_schema_types(:value, :message=>'is bad')}
|
|
254
254
|
@m.meta_def(:db_schema){{:value=>{:type=>:integer}}}
|
|
255
|
-
@m.
|
|
256
|
-
@m.errors.full_messages.
|
|
255
|
+
@m.wont_be :valid?
|
|
256
|
+
@m.errors.full_messages.must_equal ['value is bad']
|
|
257
257
|
end
|
|
258
258
|
|
|
259
|
-
|
|
259
|
+
it "should support validates_numeric" do
|
|
260
260
|
@c.set_validations{validates_numeric(:value)}
|
|
261
261
|
@m.value = 'blah'
|
|
262
|
-
@m.
|
|
262
|
+
@m.wont_be :valid?
|
|
263
263
|
@m.value = '123'
|
|
264
|
-
@m.
|
|
264
|
+
@m.must_be :valid?
|
|
265
265
|
@m.value = '123.1231'
|
|
266
|
-
@m.
|
|
266
|
+
@m.must_be :valid?
|
|
267
267
|
@m.value = '+1'
|
|
268
|
-
@m.
|
|
268
|
+
@m.must_be :valid?
|
|
269
269
|
@m.value = '-1'
|
|
270
|
-
@m.
|
|
270
|
+
@m.must_be :valid?
|
|
271
271
|
@m.value = '+1.123'
|
|
272
|
-
@m.
|
|
272
|
+
@m.must_be :valid?
|
|
273
273
|
@m.value = '-0.123'
|
|
274
|
-
@m.
|
|
274
|
+
@m.must_be :valid?
|
|
275
275
|
@m.value = '-0.123E10'
|
|
276
|
-
@m.
|
|
276
|
+
@m.must_be :valid?
|
|
277
277
|
@m.value = '32.123e10'
|
|
278
|
-
@m.
|
|
278
|
+
@m.must_be :valid?
|
|
279
279
|
@m.value = '+32.123E10'
|
|
280
|
-
@m.
|
|
281
|
-
@m.
|
|
280
|
+
@m.must_be :valid?
|
|
281
|
+
@m.must_be :valid?
|
|
282
282
|
@m.value = '.0123'
|
|
283
283
|
end
|
|
284
284
|
|
|
285
|
-
|
|
285
|
+
it "should support validates_type" do
|
|
286
286
|
@c.set_validations{validates_type(Integer, :value)}
|
|
287
287
|
@m.value = 123
|
|
288
|
-
@m.
|
|
288
|
+
@m.must_be :valid?
|
|
289
289
|
@m.value = '123'
|
|
290
|
-
@m.
|
|
291
|
-
@m.errors.full_messages.
|
|
290
|
+
@m.wont_be :valid?
|
|
291
|
+
@m.errors.full_messages.must_equal ['value is not a valid integer']
|
|
292
292
|
|
|
293
293
|
@c.set_validations{validates_type(:String, :value)}
|
|
294
294
|
@m.value = '123'
|
|
295
|
-
@m.
|
|
295
|
+
@m.must_be :valid?
|
|
296
296
|
@m.value = 123
|
|
297
|
-
@m.
|
|
298
|
-
@m.errors.full_messages.
|
|
297
|
+
@m.wont_be :valid?
|
|
298
|
+
@m.errors.full_messages.must_equal ['value is not a valid string']
|
|
299
299
|
|
|
300
300
|
@c.set_validations{validates_type('Integer', :value)}
|
|
301
301
|
@m.value = 123
|
|
302
|
-
@m.
|
|
302
|
+
@m.must_be :valid?
|
|
303
303
|
@m.value = 123.05
|
|
304
|
-
@m.
|
|
305
|
-
@m.errors.full_messages.
|
|
304
|
+
@m.wont_be :valid?
|
|
305
|
+
@m.errors.full_messages.must_equal ['value is not a valid integer']
|
|
306
306
|
|
|
307
307
|
@c.set_validations{validates_type(Integer, :value)}
|
|
308
308
|
@m.value = 1
|
|
309
|
-
@m.
|
|
309
|
+
@m.must_be :valid?
|
|
310
310
|
@m.value = false
|
|
311
|
-
@m.
|
|
311
|
+
@m.wont_be :valid?
|
|
312
312
|
|
|
313
313
|
@c.set_validations{validates_type([Integer, Float], :value)}
|
|
314
314
|
@m.value = 1
|
|
315
|
-
@m.
|
|
315
|
+
@m.must_be :valid?
|
|
316
316
|
@m.value = 1.0
|
|
317
|
-
@m.
|
|
317
|
+
@m.must_be :valid?
|
|
318
318
|
@m.value = BigDecimal.new('1.0')
|
|
319
|
-
@m.
|
|
320
|
-
@m.errors.full_messages.
|
|
319
|
+
@m.wont_be :valid?
|
|
320
|
+
@m.errors.full_messages.must_equal ['value is not a valid integer or float']
|
|
321
321
|
end
|
|
322
322
|
|
|
323
|
-
|
|
323
|
+
it "should support validates_not_null" do
|
|
324
324
|
@c.set_validations{validates_not_null(:value)}
|
|
325
|
-
@m.
|
|
325
|
+
@m.wont_be :valid?
|
|
326
326
|
@m.value = ''
|
|
327
|
-
@m.
|
|
327
|
+
@m.must_be :valid?
|
|
328
328
|
@m.value = 1234
|
|
329
|
-
@m.
|
|
329
|
+
@m.must_be :valid?
|
|
330
330
|
@m.value = nil
|
|
331
|
-
@m.
|
|
331
|
+
@m.wont_be :valid?
|
|
332
332
|
@m.value = true
|
|
333
|
-
@m.
|
|
333
|
+
@m.must_be :valid?
|
|
334
334
|
@m.value = false
|
|
335
|
-
@m.
|
|
335
|
+
@m.must_be :valid?
|
|
336
336
|
@m.value = Time.now
|
|
337
|
-
@m.
|
|
337
|
+
@m.must_be :valid?
|
|
338
338
|
end
|
|
339
339
|
|
|
340
|
-
|
|
340
|
+
it "should support validates_presence" do
|
|
341
341
|
@c.set_validations{validates_presence(:value)}
|
|
342
|
-
@m.
|
|
342
|
+
@m.wont_be :valid?
|
|
343
343
|
@m.value = ''
|
|
344
|
-
@m.
|
|
344
|
+
@m.wont_be :valid?
|
|
345
345
|
@m.value = 1234
|
|
346
|
-
@m.
|
|
346
|
+
@m.must_be :valid?
|
|
347
347
|
@m.value = nil
|
|
348
|
-
@m.
|
|
348
|
+
@m.wont_be :valid?
|
|
349
349
|
@m.value = true
|
|
350
|
-
@m.
|
|
350
|
+
@m.must_be :valid?
|
|
351
351
|
@m.value = false
|
|
352
|
-
@m.
|
|
352
|
+
@m.must_be :valid?
|
|
353
353
|
@m.value = Time.now
|
|
354
|
-
@m.
|
|
354
|
+
@m.must_be :valid?
|
|
355
355
|
end
|
|
356
356
|
|
|
357
357
|
it "should support validates_unique with a single attribute" do
|
|
@@ -368,28 +368,28 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
368
368
|
end
|
|
369
369
|
|
|
370
370
|
@user = @c.new(:username => "0records", :password => "anothertest")
|
|
371
|
-
@user.
|
|
371
|
+
@user.must_be :valid?
|
|
372
372
|
@user = @c.load(:id=>3, :username => "0records", :password => "anothertest")
|
|
373
|
-
@user.
|
|
373
|
+
@user.must_be :valid?
|
|
374
374
|
|
|
375
375
|
DB.sqls
|
|
376
376
|
@user = @c.new(:password => "anothertest")
|
|
377
|
-
@user.
|
|
378
|
-
DB.sqls.
|
|
377
|
+
@user.must_be :valid?
|
|
378
|
+
DB.sqls.must_equal []
|
|
379
379
|
|
|
380
380
|
@user = @c.new(:username => "1record", :password => "anothertest")
|
|
381
|
-
@user.
|
|
382
|
-
@user.errors.full_messages.
|
|
381
|
+
@user.wont_be :valid?
|
|
382
|
+
@user.errors.full_messages.must_equal ['username is already taken']
|
|
383
383
|
@user = @c.load(:id=>4, :username => "1record", :password => "anothertest")
|
|
384
|
-
@user.
|
|
385
|
-
@user.errors.full_messages.
|
|
384
|
+
@user.wont_be :valid?
|
|
385
|
+
@user.errors.full_messages.must_equal ['username is already taken']
|
|
386
386
|
|
|
387
387
|
@user = @c.load(:id=>1, :username => "0records", :password => "anothertest")
|
|
388
|
-
@user.
|
|
389
|
-
DB.sqls.last.
|
|
388
|
+
@user.must_be :valid?
|
|
389
|
+
DB.sqls.last.must_equal "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (id != 1)) LIMIT 1"
|
|
390
390
|
@user = @c.new(:username => "0records", :password => "anothertest")
|
|
391
|
-
@user.
|
|
392
|
-
DB.sqls.last.
|
|
391
|
+
@user.must_be :valid?
|
|
392
|
+
DB.sqls.last.must_equal "SELECT count(*) AS count FROM items WHERE (username = '0records') LIMIT 1"
|
|
393
393
|
end
|
|
394
394
|
|
|
395
395
|
it "should support validates_unique with multiple attributes" do
|
|
@@ -406,35 +406,35 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
406
406
|
end
|
|
407
407
|
|
|
408
408
|
@user = @c.new(:username => "0records", :password => "anothertest")
|
|
409
|
-
@user.
|
|
409
|
+
@user.must_be :valid?
|
|
410
410
|
@user = @c.load(:id=>3, :username => "0records", :password => "anothertest")
|
|
411
|
-
@user.
|
|
411
|
+
@user.must_be :valid?
|
|
412
412
|
|
|
413
413
|
DB.sqls
|
|
414
414
|
@user = @c.new(:password => "anothertest")
|
|
415
|
-
@user.
|
|
416
|
-
@user.errors.full_messages.
|
|
415
|
+
@user.must_be :valid?
|
|
416
|
+
@user.errors.full_messages.must_equal []
|
|
417
417
|
@user = @c.new(:username => "0records")
|
|
418
|
-
@user.
|
|
419
|
-
@user.errors.full_messages.
|
|
418
|
+
@user.must_be :valid?
|
|
419
|
+
@user.errors.full_messages.must_equal []
|
|
420
420
|
@user = @c.new
|
|
421
|
-
@user.
|
|
422
|
-
@user.errors.full_messages.
|
|
423
|
-
DB.sqls.
|
|
421
|
+
@user.must_be :valid?
|
|
422
|
+
@user.errors.full_messages.must_equal []
|
|
423
|
+
DB.sqls.must_equal []
|
|
424
424
|
|
|
425
425
|
@user = @c.new(:username => "1record", :password => "anothertest")
|
|
426
|
-
@user.
|
|
427
|
-
@user.errors.full_messages.
|
|
426
|
+
@user.wont_be :valid?
|
|
427
|
+
@user.errors.full_messages.must_equal ['username and password is already taken']
|
|
428
428
|
@user = @c.load(:id=>4, :username => "1record", :password => "anothertest")
|
|
429
|
-
@user.
|
|
430
|
-
@user.errors.full_messages.
|
|
429
|
+
@user.wont_be :valid?
|
|
430
|
+
@user.errors.full_messages.must_equal ['username and password is already taken']
|
|
431
431
|
|
|
432
432
|
@user = @c.load(:id=>1, :username => "0records", :password => "anothertest")
|
|
433
|
-
@user.
|
|
434
|
-
DB.sqls.last.
|
|
433
|
+
@user.must_be :valid?
|
|
434
|
+
DB.sqls.last.must_equal "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = 'anothertest') AND (id != 1)) LIMIT 1"
|
|
435
435
|
@user = @c.new(:username => "0records", :password => "anothertest")
|
|
436
|
-
@user.
|
|
437
|
-
DB.sqls.last.
|
|
436
|
+
@user.must_be :valid?
|
|
437
|
+
DB.sqls.last.must_equal "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = 'anothertest')) LIMIT 1"
|
|
438
438
|
end
|
|
439
439
|
|
|
440
440
|
it "should support validates_unique with a block" do
|
|
@@ -444,9 +444,9 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
444
444
|
@c.dataset._fetch = {:v=>0}
|
|
445
445
|
|
|
446
446
|
DB.reset
|
|
447
|
-
@c.new(:username => "0records", :password => "anothertest").
|
|
448
|
-
@c.load(:id=>3, :username => "0records", :password => "anothertest").
|
|
449
|
-
DB.sqls.
|
|
447
|
+
@c.new(:username => "0records", :password => "anothertest").must_be :valid?
|
|
448
|
+
@c.load(:id=>3, :username => "0records", :password => "anothertest").must_be :valid?
|
|
449
|
+
DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '0records') AND active) LIMIT 1",
|
|
450
450
|
"SELECT count(*) AS count FROM items WHERE ((username = '0records') AND active AND (id != 3)) LIMIT 1"]
|
|
451
451
|
end
|
|
452
452
|
|
|
@@ -457,9 +457,9 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
457
457
|
@c.dataset._fetch = {:v=>0}
|
|
458
458
|
|
|
459
459
|
DB.reset
|
|
460
|
-
@c.new(:username => "0RECORDS", :password => "anothertest").
|
|
461
|
-
@c.load(:id=>3, :username => "0RECORDS", :password => "anothertest").
|
|
462
|
-
DB.sqls.
|
|
460
|
+
@c.new(:username => "0RECORDS", :password => "anothertest").must_be :valid?
|
|
461
|
+
@c.load(:id=>3, :username => "0RECORDS", :password => "anothertest").must_be :valid?
|
|
462
|
+
DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE (lower(username) = '0records') LIMIT 1",
|
|
463
463
|
"SELECT count(*) AS count FROM items WHERE ((lower(username) = '0records') AND (id != 3)) LIMIT 1"]
|
|
464
464
|
end
|
|
465
465
|
|
|
@@ -471,9 +471,9 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
471
471
|
@c.dataset._fetch = {:v=>0}
|
|
472
472
|
|
|
473
473
|
DB.reset
|
|
474
|
-
@c.new(:username => "0records", :password => "anothertest").
|
|
475
|
-
@c.load(:id=>3, :username => "0records", :password => "anothertest").
|
|
476
|
-
DB.sqls.
|
|
474
|
+
@c.new(:username => "0records", :password => "anothertest").must_be :valid?
|
|
475
|
+
@c.load(:id=>3, :username => "0records", :password => "anothertest").must_be :valid?
|
|
476
|
+
DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((a IN (1, 2, 3)) AND (username = '0records')) LIMIT 1",
|
|
477
477
|
"SELECT count(*) AS count FROM items WHERE ((a IN (1, 2, 3)) AND (username = '0records') AND (id != 3)) LIMIT 1"]
|
|
478
478
|
end
|
|
479
479
|
|
|
@@ -485,9 +485,9 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
485
485
|
@c.dataset._fetch = {:v=>0}
|
|
486
486
|
|
|
487
487
|
DB.reset
|
|
488
|
-
@c.new(:username => "0records", :password => "anothertest").
|
|
489
|
-
@c.load(:id=>3, :username => "0records", :password => "anothertest").
|
|
490
|
-
DB.sqls.
|
|
488
|
+
@c.new(:username => "0records", :password => "anothertest").must_be :valid?
|
|
489
|
+
@c.load(:id=>3, :username => "0records", :password => "anothertest").must_be :valid?
|
|
490
|
+
DB.sqls.must_equal ["SELECT count(*) AS count FROM items CROSS JOIN a WHERE (username = '0records') LIMIT 1",
|
|
491
491
|
"SELECT count(*) AS count FROM items CROSS JOIN a WHERE ((username = '0records') AND (items.id != 3)) LIMIT 1"]
|
|
492
492
|
end
|
|
493
493
|
|
|
@@ -498,26 +498,26 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
498
498
|
@c.dataset._fetch = {:v=>0}
|
|
499
499
|
|
|
500
500
|
DB.reset
|
|
501
|
-
@c.new(:username => "0records", :password => "anothertest").
|
|
502
|
-
DB.sqls.
|
|
501
|
+
@c.new(:username => "0records", :password => "anothertest").must_be :valid?
|
|
502
|
+
DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = 'anothertest')) LIMIT 1"]
|
|
503
503
|
DB.reset
|
|
504
504
|
m = @c.load(:id=>3, :username => "0records", :password => "anothertest")
|
|
505
|
-
m.
|
|
506
|
-
DB.sqls.
|
|
505
|
+
m.must_be :valid?
|
|
506
|
+
DB.sqls.must_equal []
|
|
507
507
|
|
|
508
508
|
m.username = '1'
|
|
509
|
-
m.
|
|
510
|
-
DB.sqls.
|
|
509
|
+
m.must_be :valid?
|
|
510
|
+
DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '1') AND (password = 'anothertest') AND (id != 3)) LIMIT 1"]
|
|
511
511
|
|
|
512
512
|
m = @c.load(:id=>3, :username => "0records", :password => "anothertest")
|
|
513
513
|
DB.reset
|
|
514
514
|
m.password = '1'
|
|
515
|
-
m.
|
|
516
|
-
DB.sqls.
|
|
515
|
+
m.must_be :valid?
|
|
516
|
+
DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = '1') AND (id != 3)) LIMIT 1"]
|
|
517
517
|
DB.reset
|
|
518
518
|
m.username = '2'
|
|
519
|
-
m.
|
|
520
|
-
DB.sqls.
|
|
519
|
+
m.must_be :valid?
|
|
520
|
+
DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '2') AND (password = '1') AND (id != 3)) LIMIT 1"]
|
|
521
521
|
end
|
|
522
522
|
|
|
523
523
|
it "should not attempt a database query if the underlying columns have validation errors" do
|
|
@@ -528,7 +528,7 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
528
528
|
|
|
529
529
|
DB.reset
|
|
530
530
|
m = @c.new(:username => "1", :password => "anothertest")
|
|
531
|
-
m.
|
|
532
|
-
DB.sqls.
|
|
531
|
+
m.wont_be :valid?
|
|
532
|
+
DB.sqls.must_equal []
|
|
533
533
|
end
|
|
534
534
|
end
|