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
@@ -18,27 +18,27 @@ describe "Sequel::Plugins::AssociationProxies" do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should send method calls to the associated object array if sent an array method" do
|
21
|
-
@i.associations.has_key?(:tags).
|
22
|
-
@t.select{|x| false}.
|
23
|
-
@i.associations.has_key?(:tags).
|
21
|
+
@i.associations.has_key?(:tags).must_equal false
|
22
|
+
@t.select{|x| false}.must_equal []
|
23
|
+
@i.associations.has_key?(:tags).must_equal true
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should send method calls to the association dataset if sent a non-array method" do
|
27
|
-
@i.associations.has_key?(:tags).
|
28
|
-
@t.filter(:a=>1).sql.
|
29
|
-
@i.associations.has_key?(:tags).
|
27
|
+
@i.associations.has_key?(:tags).must_equal false
|
28
|
+
@t.filter(:a=>1).sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
|
29
|
+
@i.associations.has_key?(:tags).must_equal false
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should accept block to plugin to specify which methods to proxy to dataset" do
|
33
33
|
Item.plugin :association_proxies do |opts|
|
34
34
|
opts[:method] == :where || opts[:arguments].length == 2 || opts[:block]
|
35
35
|
end
|
36
|
-
@i.associations.has_key?(:tags).
|
37
|
-
@t.where(:a=>1).sql.
|
38
|
-
@t.filter('a = ?', 1).sql.
|
39
|
-
@t.filter{{:a=>1}}.sql.
|
36
|
+
@i.associations.has_key?(:tags).must_equal false
|
37
|
+
@t.where(:a=>1).sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
|
38
|
+
@t.filter('a = ?', 1).sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
|
39
|
+
@t.filter{{:a=>1}}.sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
|
40
40
|
|
41
|
-
@i.associations.has_key?(:tags).
|
41
|
+
@i.associations.has_key?(:tags).must_equal false
|
42
42
|
Item.plugin :association_proxies do |opts|
|
43
43
|
proxy_arg = opts[:proxy_argument]
|
44
44
|
proxy_block = opts[:proxy_block]
|
@@ -46,41 +46,41 @@ describe "Sequel::Plugins::AssociationProxies" do
|
|
46
46
|
is_size = opts[:method] == :size
|
47
47
|
is_size && !cached && !proxy_arg && !proxy_block
|
48
48
|
end
|
49
|
-
@t.size.
|
50
|
-
Item.db.sqls.
|
51
|
-
@i.tags{|ds| ds}.size.
|
52
|
-
Item.db.sqls.
|
53
|
-
@i.tags(true).size.
|
54
|
-
Item.db.sqls.
|
55
|
-
@t.size.
|
56
|
-
Item.db.sqls.
|
49
|
+
@t.size.must_equal 1
|
50
|
+
Item.db.sqls.must_equal ["SELECT count(*) AS count FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE (items_tags.item_id = 1) LIMIT 1"]
|
51
|
+
@i.tags{|ds| ds}.size.must_equal 1
|
52
|
+
Item.db.sqls.must_equal ["SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE (items_tags.item_id = 1)"]
|
53
|
+
@i.tags(true).size.must_equal 1
|
54
|
+
Item.db.sqls.must_equal ["SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE (items_tags.item_id = 1)"]
|
55
|
+
@t.size.must_equal 1
|
56
|
+
Item.db.sqls.must_equal []
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should reload the cached association if sent an array method and the reload flag was given" do
|
60
|
-
@t.select{|x| false}.
|
61
|
-
Item.db.sqls.length.
|
62
|
-
@t.select{|x| false}.
|
63
|
-
Item.db.sqls.length.
|
64
|
-
@i.tags(true).select{|x| false}.
|
65
|
-
Item.db.sqls.length.
|
66
|
-
@t.filter(:a=>1).sql.
|
67
|
-
Item.db.sqls.length.
|
60
|
+
@t.select{|x| false}.must_equal []
|
61
|
+
Item.db.sqls.length.must_equal 1
|
62
|
+
@t.select{|x| false}.must_equal []
|
63
|
+
Item.db.sqls.length.must_equal 0
|
64
|
+
@i.tags(true).select{|x| false}.must_equal []
|
65
|
+
Item.db.sqls.length.must_equal 1
|
66
|
+
@t.filter(:a=>1).sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
|
67
|
+
Item.db.sqls.length.must_equal 0
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should not return a proxy object for associations that do not return an array" do
|
71
71
|
Item.many_to_one :tag
|
72
|
-
proc{@i.tag.filter(:a=>1)}.
|
72
|
+
proc{@i.tag.filter(:a=>1)}.must_raise(NoMethodError)
|
73
73
|
|
74
74
|
Tag.one_to_one :item
|
75
|
-
proc{Tag.load(:id=>1, :item_id=>2).item.filter(:a=>1)}.
|
75
|
+
proc{Tag.load(:id=>1, :item_id=>2).item.filter(:a=>1)}.must_raise(NoMethodError)
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should work correctly in subclasses" do
|
79
79
|
i = Class.new(Item).load(:id=>1)
|
80
|
-
i.associations.has_key?(:tags).
|
81
|
-
i.tags.select{|x| false}.
|
82
|
-
i.associations.has_key?(:tags).
|
83
|
-
i.tags.filter(:a=>1).sql.
|
80
|
+
i.associations.has_key?(:tags).must_equal false
|
81
|
+
i.tags.select{|x| false}.must_equal []
|
82
|
+
i.associations.has_key?(:tags).must_equal true
|
83
|
+
i.tags.filter(:a=>1).sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
|
84
84
|
end
|
85
85
|
|
86
86
|
end
|
@@ -28,131 +28,131 @@ describe "Sequel::Plugins::AutoValidations" do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should have automatically created validations" do
|
31
|
-
@m.valid?.
|
32
|
-
@m.errors.
|
31
|
+
@m.valid?.must_equal false
|
32
|
+
@m.errors.must_equal(:d=>["is not present"], :name=>["is not present"])
|
33
33
|
|
34
34
|
@m.name = ''
|
35
|
-
@m.valid?.
|
36
|
-
@m.errors.
|
35
|
+
@m.valid?.must_equal false
|
36
|
+
@m.errors.must_equal(:d=>["is not present"])
|
37
37
|
|
38
38
|
@m.set(:d=>'/', :num=>'a', :name=>'1')
|
39
|
-
@m.valid?.
|
40
|
-
@m.errors.
|
39
|
+
@m.valid?.must_equal false
|
40
|
+
@m.errors.must_equal(:d=>["is not a valid date"], :num=>["is not a valid integer"])
|
41
41
|
|
42
42
|
@m.set(:d=>Date.today, :num=>1)
|
43
|
-
@m.valid?.
|
44
|
-
@m.errors.
|
43
|
+
@m.valid?.must_equal false
|
44
|
+
@m.errors.must_equal([:name, :num]=>["is already taken"])
|
45
45
|
|
46
46
|
@m.set(:name=>'a'*51)
|
47
|
-
@m.valid?.
|
48
|
-
@m.errors.
|
47
|
+
@m.valid?.must_equal false
|
48
|
+
@m.errors.must_equal(:name=>["is longer than 50 characters"])
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should handle databases that don't support index parsing" do
|
52
52
|
def (@m.db).supports_index_parsing?() false end
|
53
53
|
@m.model.send(:setup_auto_validations)
|
54
54
|
@m.set(:d=>Date.today, :num=>1, :name=>'1')
|
55
|
-
@m.valid?.
|
55
|
+
@m.valid?.must_equal true
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should handle models that select from subqueries" do
|
59
59
|
@c.set_dataset @c.dataset.from_self
|
60
|
-
|
60
|
+
@c.send(:setup_auto_validations)
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should support :not_null=>:presence option" do
|
64
64
|
@c.plugin :auto_validations, :not_null=>:presence
|
65
65
|
@m.set(:d=>Date.today, :num=>'')
|
66
|
-
@m.valid?.
|
67
|
-
@m.errors.
|
66
|
+
@m.valid?.must_equal false
|
67
|
+
@m.errors.must_equal(:name=>["is not present"])
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should automatically validate explicit nil values for columns with not nil defaults" do
|
71
71
|
@m.set(:d=>Date.today, :name=>1, :nnd=>nil)
|
72
72
|
@m.id = nil
|
73
|
-
@m.valid?.
|
74
|
-
@m.errors.
|
73
|
+
@m.valid?.must_equal false
|
74
|
+
@m.errors.must_equal(:id=>["is not present"], :nnd=>["is not present"])
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should allow skipping validations by type" do
|
78
78
|
@c = Class.new(@c)
|
79
79
|
@m = @c.new
|
80
80
|
@c.skip_auto_validations(:not_null)
|
81
|
-
@m.valid?.
|
81
|
+
@m.valid?.must_equal true
|
82
82
|
|
83
83
|
@m.set(:d=>'/', :num=>'a', :name=>'1')
|
84
|
-
@m.valid?.
|
85
|
-
@m.errors.
|
84
|
+
@m.valid?.must_equal false
|
85
|
+
@m.errors.must_equal(:d=>["is not a valid date"], :num=>["is not a valid integer"])
|
86
86
|
|
87
87
|
@c.skip_auto_validations(:types)
|
88
|
-
@m.valid?.
|
89
|
-
@m.errors.
|
88
|
+
@m.valid?.must_equal false
|
89
|
+
@m.errors.must_equal([:name, :num]=>["is already taken"])
|
90
90
|
|
91
91
|
@c.skip_auto_validations(:unique)
|
92
|
-
@m.valid?.
|
92
|
+
@m.valid?.must_equal true
|
93
93
|
|
94
94
|
@m.set(:name=>'a'*51)
|
95
|
-
@m.valid?.
|
96
|
-
@m.errors.
|
95
|
+
@m.valid?.must_equal false
|
96
|
+
@m.errors.must_equal(:name=>["is longer than 50 characters"])
|
97
97
|
|
98
98
|
@c.skip_auto_validations(:max_length)
|
99
|
-
@m.valid?.
|
99
|
+
@m.valid?.must_equal true
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should allow skipping all auto validations" do
|
103
103
|
@c = Class.new(@c)
|
104
104
|
@m = @c.new
|
105
105
|
@c.skip_auto_validations(:all)
|
106
|
-
@m.valid?.
|
106
|
+
@m.valid?.must_equal true
|
107
107
|
@m.set(:d=>'/', :num=>'a', :name=>'1')
|
108
|
-
@m.valid?.
|
108
|
+
@m.valid?.must_equal true
|
109
109
|
@m.set(:name=>'a'*51)
|
110
|
-
@m.valid?.
|
110
|
+
@m.valid?.must_equal true
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should work correctly in subclasses" do
|
114
114
|
@c = Class.new(@c)
|
115
115
|
@m = @c.new
|
116
|
-
@m.valid?.
|
117
|
-
@m.errors.
|
116
|
+
@m.valid?.must_equal false
|
117
|
+
@m.errors.must_equal(:d=>["is not present"], :name=>["is not present"])
|
118
118
|
|
119
119
|
@m.set(:d=>'/', :num=>'a', :name=>'1')
|
120
|
-
@m.valid?.
|
121
|
-
@m.errors.
|
120
|
+
@m.valid?.must_equal false
|
121
|
+
@m.errors.must_equal(:d=>["is not a valid date"], :num=>["is not a valid integer"])
|
122
122
|
|
123
123
|
@m.set(:d=>Date.today, :num=>1)
|
124
|
-
@m.valid?.
|
125
|
-
@m.errors.
|
124
|
+
@m.valid?.must_equal false
|
125
|
+
@m.errors.must_equal([:name, :num]=>["is already taken"])
|
126
126
|
|
127
127
|
@m.set(:name=>'a'*51)
|
128
|
-
@m.valid?.
|
129
|
-
@m.errors.
|
128
|
+
@m.valid?.must_equal false
|
129
|
+
@m.errors.must_equal(:name=>["is longer than 50 characters"])
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should work correctly in STI subclasses" do
|
133
133
|
@c.plugin(:single_table_inheritance, :num, :model_map=>{1=>@c}, :key_map=>proc{[1, 2]})
|
134
134
|
sc = Class.new(@c)
|
135
135
|
@m = sc.new
|
136
|
-
@m.valid?.
|
137
|
-
@m.errors.
|
136
|
+
@m.valid?.must_equal false
|
137
|
+
@m.errors.must_equal(:d=>["is not present"], :name=>["is not present"])
|
138
138
|
|
139
139
|
@m.set(:d=>'/', :num=>'a', :name=>'1')
|
140
|
-
@m.valid?.
|
141
|
-
@m.errors.
|
140
|
+
@m.valid?.must_equal false
|
141
|
+
@m.errors.must_equal(:d=>["is not a valid date"], :num=>["is not a valid integer"])
|
142
142
|
|
143
143
|
@m.db.sqls
|
144
144
|
@m.set(:d=>Date.today, :num=>1)
|
145
|
-
@m.valid?.
|
146
|
-
@m.errors.
|
147
|
-
@m.db.sqls.
|
145
|
+
@m.valid?.must_equal false
|
146
|
+
@m.errors.must_equal([:name, :num]=>["is already taken"])
|
147
|
+
@m.db.sqls.must_equal ["SELECT count(*) AS count FROM test WHERE ((name = '1') AND (num = 1)) LIMIT 1"]
|
148
148
|
|
149
149
|
@m.set(:name=>'a'*51)
|
150
|
-
@m.valid?.
|
151
|
-
@m.errors.
|
150
|
+
@m.valid?.must_equal false
|
151
|
+
@m.errors.must_equal(:name=>["is longer than 50 characters"])
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should work correctly when changing the dataset" do
|
155
155
|
@c.set_dataset(@c.db[:foo])
|
156
|
-
@c.new.valid?.
|
156
|
+
@c.new.valid?.must_equal true
|
157
157
|
end
|
158
158
|
end
|
@@ -16,24 +16,24 @@ describe Sequel::Model, "#(set|update)_except" do
|
|
16
16
|
|
17
17
|
it "should raise errors if not all hash fields can be set and strict_param_setting is true" do
|
18
18
|
@c.strict_param_setting = true
|
19
|
-
proc{@c.new.set_except({:x => 1, :y => 2, :z=>3, :id=>4}, :x, :y)}.
|
20
|
-
proc{@c.new.set_except({:x => 1, :y => 2, :z=>3}, :x, :y)}.
|
19
|
+
proc{@c.new.set_except({:x => 1, :y => 2, :z=>3, :id=>4}, :x, :y)}.must_raise(Sequel::MassAssignmentRestriction)
|
20
|
+
proc{@c.new.set_except({:x => 1, :y => 2, :z=>3}, :x, :y)}.must_raise(Sequel::MassAssignmentRestriction)
|
21
21
|
(o = @c.new).set_except({:z => 3}, :x, :y)
|
22
|
-
o.values.
|
22
|
+
o.values.must_equal(:z=>3)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "#set_except should not set given attributes or the primary key" do
|
26
26
|
@o1.set_except({:x => 1, :y => 2, :z=>3, :id=>4}, [:y, :z])
|
27
|
-
@o1.values.
|
27
|
+
@o1.values.must_equal(:x => 1)
|
28
28
|
@o1.set_except({:x => 4, :y => 2, :z=>3, :id=>4}, :y, :z)
|
29
|
-
@o1.values.
|
29
|
+
@o1.values.must_equal(:x => 4)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "#update_except should not update given attributes" do
|
33
33
|
@o1.update_except({:x => 1, :y => 2, :z=>3, :id=>4}, [:y, :z])
|
34
|
-
DB.sqls.
|
34
|
+
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
35
35
|
@c.new.update_except({:x => 1, :y => 2, :z=>3, :id=>4}, :y, :z)
|
36
|
-
DB.sqls.
|
36
|
+
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -46,42 +46,43 @@ describe Sequel::Model, ".restricted_columns " do
|
|
46
46
|
end
|
47
47
|
@c.strict_param_setting = false
|
48
48
|
@c.instance_variable_set(:@columns, [:x, :y, :z])
|
49
|
+
DB.sqls
|
49
50
|
end
|
50
51
|
|
51
52
|
it "should set the restricted columns correctly" do
|
52
|
-
@c.restricted_columns.
|
53
|
+
@c.restricted_columns.must_equal nil
|
53
54
|
@c.set_restricted_columns :x
|
54
|
-
@c.restricted_columns.
|
55
|
+
@c.restricted_columns.must_equal [:x]
|
55
56
|
@c.set_restricted_columns :x, :y
|
56
|
-
@c.restricted_columns.
|
57
|
+
@c.restricted_columns.must_equal [:x, :y]
|
57
58
|
end
|
58
59
|
|
59
60
|
it "should not set restricted columns by default" do
|
60
61
|
@c.set_restricted_columns :z
|
61
62
|
i = @c.new(:x => 1, :y => 2, :z => 3)
|
62
|
-
i.values.
|
63
|
+
i.values.must_equal(:x => 1, :y => 2)
|
63
64
|
i.set(:x => 4, :y => 5, :z => 6)
|
64
|
-
i.values.
|
65
|
+
i.values.must_equal(:x => 4, :y => 5)
|
65
66
|
|
66
67
|
@c.instance_dataset._fetch = @c.dataset._fetch = {:x => 7}
|
67
68
|
i = @c.new
|
68
69
|
i.update(:x => 7, :z => 9)
|
69
|
-
i.values.
|
70
|
-
DB.sqls.
|
70
|
+
i.values.must_equal(:x => 7)
|
71
|
+
DB.sqls.must_equal ["INSERT INTO blahblah (x) VALUES (7)", "SELECT * FROM blahblah WHERE (id = 10) LIMIT 1"]
|
71
72
|
end
|
72
73
|
|
73
74
|
it "should have allowed take precedence over restricted" do
|
74
75
|
@c.set_allowed_columns :x, :y
|
75
76
|
@c.set_restricted_columns :y, :z
|
76
77
|
i = @c.new(:x => 1, :y => 2, :z => 3)
|
77
|
-
i.values.
|
78
|
+
i.values.must_equal(:x => 1, :y => 2)
|
78
79
|
i.set(:x => 4, :y => 5, :z => 6)
|
79
|
-
i.values.
|
80
|
+
i.values.must_equal(:x => 4, :y => 5)
|
80
81
|
|
81
82
|
@c.instance_dataset._fetch = @c.dataset._fetch = {:y => 7}
|
82
83
|
i = @c.new
|
83
84
|
i.update(:y => 7, :z => 9)
|
84
|
-
i.values.
|
85
|
-
DB.sqls.
|
85
|
+
i.values.must_equal(:y => 7)
|
86
|
+
DB.sqls.must_equal ["INSERT INTO blahblah (y) VALUES (7)", "SELECT * FROM blahblah WHERE (id = 10) LIMIT 1"]
|
86
87
|
end
|
87
88
|
end
|
@@ -3,67 +3,67 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
|
|
3
3
|
Sequel.extension :blank
|
4
4
|
|
5
5
|
describe "Object#blank?" do
|
6
|
-
|
7
|
-
[].blank?.
|
8
|
-
{}.blank?.
|
6
|
+
it "it should be true if the object responds true to empty?" do
|
7
|
+
[].blank?.must_equal true
|
8
|
+
{}.blank?.must_equal true
|
9
9
|
o = Object.new
|
10
10
|
def o.empty?; true; end
|
11
|
-
o.blank?.
|
11
|
+
o.blank?.must_equal true
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
[2].blank?.
|
16
|
-
{1=>2}.blank?.
|
17
|
-
Object.new.blank?.
|
14
|
+
it "it should be false if the object doesn't respond true to empty?" do
|
15
|
+
[2].blank?.must_equal false
|
16
|
+
{1=>2}.blank?.must_equal false
|
17
|
+
Object.new.blank?.must_equal false
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "Numeric#blank?" do
|
22
|
-
|
23
|
-
1.blank?.
|
24
|
-
0.blank?.
|
25
|
-
-1.blank?.
|
26
|
-
1.0.blank?.
|
27
|
-
0.0.blank?.
|
28
|
-
-1.0.blank?.
|
29
|
-
10000000000000000.blank?.
|
30
|
-
-10000000000000000.blank?.
|
31
|
-
10000000000000000.0.blank?.
|
32
|
-
-10000000000000000.0.blank?.
|
22
|
+
it "it should always be false" do
|
23
|
+
1.blank?.must_equal false
|
24
|
+
0.blank?.must_equal false
|
25
|
+
-1.blank?.must_equal false
|
26
|
+
1.0.blank?.must_equal false
|
27
|
+
0.0.blank?.must_equal false
|
28
|
+
-1.0.blank?.must_equal false
|
29
|
+
10000000000000000.blank?.must_equal false
|
30
|
+
-10000000000000000.blank?.must_equal false
|
31
|
+
10000000000000000.0.blank?.must_equal false
|
32
|
+
-10000000000000000.0.blank?.must_equal false
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
describe "NilClass#blank?" do
|
37
|
-
|
38
|
-
nil.blank?.
|
37
|
+
it "it should always be true" do
|
38
|
+
nil.blank?.must_equal true
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
describe "TrueClass#blank?" do
|
43
|
-
|
44
|
-
true.blank?.
|
43
|
+
it "it should always be false" do
|
44
|
+
true.blank?.must_equal false
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "FalseClass#blank?" do
|
49
|
-
|
50
|
-
false.blank?.
|
49
|
+
it "it should always be true" do
|
50
|
+
false.blank?.must_equal true
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
describe "String#blank?" do
|
55
|
-
|
56
|
-
''.blank?.
|
55
|
+
it "it should be true if the string is empty" do
|
56
|
+
''.blank?.must_equal true
|
57
57
|
end
|
58
|
-
|
59
|
-
' '.blank?.
|
60
|
-
"\r\n\t".blank?.
|
61
|
-
(' '*4000).blank?.
|
62
|
-
("\r\n\t"*4000).blank?.
|
58
|
+
it "it should be true if the string is composed of just whitespace" do
|
59
|
+
' '.blank?.must_equal true
|
60
|
+
"\r\n\t".blank?.must_equal true
|
61
|
+
(' '*4000).blank?.must_equal true
|
62
|
+
("\r\n\t"*4000).blank?.must_equal true
|
63
63
|
end
|
64
|
-
|
65
|
-
'1'.blank?.
|
66
|
-
("\r\n\t"*4000 + 'a').blank?.
|
67
|
-
("\r\na\t"*4000).blank?.
|
64
|
+
it "it should be false if the string has any non whitespace characters" do
|
65
|
+
'1'.blank?.must_equal false
|
66
|
+
("\r\n\t"*4000 + 'a').blank?.must_equal false
|
67
|
+
("\r\na\t"*4000).blank?.must_equal false
|
68
68
|
end
|
69
69
|
end
|