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
|
@@ -10,45 +10,45 @@ describe "Sequel::Plugins::InputTransformer" do
|
|
|
10
10
|
|
|
11
11
|
it "should apply transformation to input" do
|
|
12
12
|
@o.name = ' name '
|
|
13
|
-
@o.name.
|
|
13
|
+
@o.name.must_equal ' eman '
|
|
14
14
|
@o.name = [1, 2, 3]
|
|
15
|
-
@o.name.
|
|
15
|
+
@o.name.must_equal [1, 2, 3]
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "should not apply any transformers by default" do
|
|
19
19
|
c = Class.new(Sequel::Model)
|
|
20
20
|
c.columns :name, :b
|
|
21
21
|
c.plugin :input_transformer
|
|
22
|
-
c.new(:name => ' name ').name.
|
|
22
|
+
c.new(:name => ' name ').name.must_equal ' name '
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it "should allow skipping of columns using .skip_input_transformer" do
|
|
26
26
|
@c.skip_input_transformer :reverser, :name
|
|
27
27
|
v = ' name '
|
|
28
28
|
@o.name = v
|
|
29
|
-
@o.name.
|
|
29
|
+
@o.name.must_be_same_as(v)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
it "should work correctly in subclasses" do
|
|
33
33
|
o = Class.new(@c).new
|
|
34
34
|
o.name = ' name '
|
|
35
|
-
o.name.
|
|
35
|
+
o.name.must_equal ' eman '
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it "should raise an error if adding input filter without name" do
|
|
39
|
-
proc{@c.add_input_transformer(nil){}}.
|
|
40
|
-
proc{@c.plugin(:input_transformer){}}.
|
|
39
|
+
proc{@c.add_input_transformer(nil){}}.must_raise(Sequel::Error)
|
|
40
|
+
proc{@c.plugin(:input_transformer){}}.must_raise(Sequel::Error)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
it "should raise an error if adding input filter without block" do
|
|
44
|
-
proc{@c.add_input_transformer(:foo)}.
|
|
45
|
-
proc{@c.plugin(:input_transformer, :foo)}.
|
|
44
|
+
proc{@c.add_input_transformer(:foo)}.must_raise(Sequel::Error)
|
|
45
|
+
proc{@c.plugin(:input_transformer, :foo)}.must_raise(Sequel::Error)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it "should apply multiple input transformers in reverse order of their call" do
|
|
49
49
|
@c.add_input_transformer(:add_bar){|v| v << 'bar'}
|
|
50
50
|
@c.add_input_transformer(:add_foo){|v| v << 'foo'}
|
|
51
51
|
@o.name = ' name '
|
|
52
|
-
@o.name.
|
|
52
|
+
@o.name.must_equal 'raboof eman '
|
|
53
53
|
end
|
|
54
54
|
end
|
|
@@ -14,23 +14,23 @@ describe "Sequel::Plugins::InsertReturningSelect" do
|
|
|
14
14
|
|
|
15
15
|
it "should add a returning clause when inserting using selected columns" do
|
|
16
16
|
@Album.plugin :insert_returning_select
|
|
17
|
-
@Album.create(:x=>2).
|
|
18
|
-
@db.sqls.
|
|
17
|
+
@Album.create(:x=>2).must_equal @Album.load(:id=>1, :x=>2)
|
|
18
|
+
@db.sqls.must_equal ['INSERT INTO albums (x) VALUES (2) RETURNING id, x']
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "should not add a returning clause if selection does not consist of just columns" do
|
|
22
22
|
@Album.dataset = @Album.dataset.select_append(Sequel.as(1, :b))
|
|
23
23
|
@Album.plugin :insert_returning_select
|
|
24
24
|
@db.sqls.clear
|
|
25
|
-
@Album.create(:x=>2).
|
|
26
|
-
@db.sqls.
|
|
25
|
+
@Album.create(:x=>2).must_equal @Album.load(:id=>1, :x=>2)
|
|
26
|
+
@db.sqls.must_equal ['INSERT INTO albums (x) VALUES (2)', 'SELECT id, x, 1 AS b FROM albums WHERE (id = 1) LIMIT 1']
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it "should not add a returning clause if database doesn't support it" do
|
|
30
30
|
@db.extend_datasets{def supports_returning?(_) false end}
|
|
31
31
|
@Album.plugin :insert_returning_select
|
|
32
|
-
@Album.create(:x=>2).
|
|
33
|
-
@db.sqls.
|
|
32
|
+
@Album.create(:x=>2).must_equal @Album.load(:id=>1, :x=>2)
|
|
33
|
+
@db.sqls.must_equal ['INSERT INTO albums (x) VALUES (2)', 'SELECT id, x FROM albums WHERE (id = 1) LIMIT 1']
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "should work correctly with subclasses" do
|
|
@@ -40,7 +40,7 @@ describe "Sequel::Plugins::InsertReturningSelect" do
|
|
|
40
40
|
b.columns :id, :x
|
|
41
41
|
b.dataset = @db[:albums].select(:id, :x)
|
|
42
42
|
@db.sqls.clear
|
|
43
|
-
b.create(:x=>2).
|
|
44
|
-
@db.sqls.
|
|
43
|
+
b.create(:x=>2).must_equal b.load(:id=>1, :x=>2)
|
|
44
|
+
@db.sqls.must_equal ['INSERT INTO albums (x) VALUES (2) RETURNING id, x']
|
|
45
45
|
end
|
|
46
46
|
end
|
|
@@ -10,70 +10,70 @@ describe "instance_filters plugin" do
|
|
|
10
10
|
DB.sqls
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
it "should raise an error when updating a stale record" do
|
|
14
14
|
@p.update(:name=>'Bob')
|
|
15
|
-
DB.sqls.
|
|
15
|
+
DB.sqls.must_equal ["UPDATE people SET name = 'Bob' WHERE (id = 1)"]
|
|
16
16
|
@p.instance_filter(:name=>'Jim')
|
|
17
17
|
@p.this.numrows = 0
|
|
18
|
-
proc{@p.update(:name=>'Joe')}.
|
|
19
|
-
DB.sqls.
|
|
18
|
+
proc{@p.update(:name=>'Joe')}.must_raise(Sequel::Plugins::InstanceFilters::Error)
|
|
19
|
+
DB.sqls.must_equal ["UPDATE people SET name = 'Joe' WHERE ((id = 1) AND (name = 'Jim'))"]
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
it "should raise an error when destroying a stale record" do
|
|
23
23
|
@p.destroy
|
|
24
|
-
DB.sqls.
|
|
24
|
+
DB.sqls.must_equal ["DELETE FROM people WHERE id = 1"]
|
|
25
25
|
@p.instance_filter(:name=>'Jim')
|
|
26
26
|
@p.this.numrows = 0
|
|
27
|
-
proc{@p.destroy}.
|
|
28
|
-
DB.sqls.
|
|
27
|
+
proc{@p.destroy}.must_raise(Sequel::Plugins::InstanceFilters::Error)
|
|
28
|
+
DB.sqls.must_equal ["DELETE FROM people WHERE ((id = 1) AND (name = 'Jim'))"]
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
it "should work when using the prepared_statements plugin" do
|
|
32
32
|
@c.plugin :prepared_statements
|
|
33
33
|
|
|
34
34
|
@p.update(:name=>'Bob')
|
|
35
|
-
DB.sqls.
|
|
35
|
+
DB.sqls.must_equal ["UPDATE people SET name = 'Bob' WHERE (id = 1)"]
|
|
36
36
|
@p.instance_filter(:name=>'Jim')
|
|
37
37
|
@p.this.numrows = 0
|
|
38
|
-
proc{@p.update(:name=>'Joe')}.
|
|
39
|
-
DB.sqls.
|
|
38
|
+
proc{@p.update(:name=>'Joe')}.must_raise(Sequel::Plugins::InstanceFilters::Error)
|
|
39
|
+
DB.sqls.must_equal ["UPDATE people SET name = 'Joe' WHERE ((id = 1) AND (name = 'Jim'))"]
|
|
40
40
|
|
|
41
41
|
@p = @c.load(:id=>1, :name=>'John', :num=>1)
|
|
42
42
|
@p.this.numrows = 1
|
|
43
43
|
@p.destroy
|
|
44
|
-
DB.sqls.
|
|
44
|
+
DB.sqls.must_equal ["DELETE FROM people WHERE (id = 1)"]
|
|
45
45
|
@p.instance_filter(:name=>'Jim')
|
|
46
46
|
@p.this.numrows = 0
|
|
47
|
-
proc{@p.destroy}.
|
|
48
|
-
DB.sqls.
|
|
47
|
+
proc{@p.destroy}.must_raise(Sequel::Plugins::InstanceFilters::Error)
|
|
48
|
+
DB.sqls.must_equal ["DELETE FROM people WHERE ((id = 1) AND (name = 'Jim'))"]
|
|
49
49
|
|
|
50
|
-
@c.create.
|
|
50
|
+
@c.create.must_be_kind_of(@c)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
it "should apply all instance filters" do
|
|
54
54
|
@p.instance_filter(:name=>'Jim')
|
|
55
55
|
@p.instance_filter{num > 2}
|
|
56
56
|
@p.update(:name=>'Bob')
|
|
57
|
-
DB.sqls.
|
|
57
|
+
DB.sqls.must_equal ["UPDATE people SET name = 'Bob' WHERE ((id = 1) AND (name = 'Jim') AND (num > 2))"]
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
it "should drop instance filters after updating" do
|
|
61
61
|
@p.instance_filter(:name=>'Joe')
|
|
62
62
|
@p.update(:name=>'Joe')
|
|
63
|
-
DB.sqls.
|
|
63
|
+
DB.sqls.must_equal ["UPDATE people SET name = 'Joe' WHERE ((id = 1) AND (name = 'Joe'))"]
|
|
64
64
|
@p.update(:name=>'Bob')
|
|
65
|
-
DB.sqls.
|
|
65
|
+
DB.sqls.must_equal ["UPDATE people SET name = 'Bob' WHERE (id = 1)"]
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
it "shouldn't allow instance filters on frozen objects" do
|
|
69
69
|
@p.instance_filter(:name=>'Joe')
|
|
70
70
|
@p.freeze
|
|
71
|
-
proc{@p.instance_filter(:name=>'Jim')}.
|
|
71
|
+
proc{@p.instance_filter(:name=>'Jim')}.must_raise
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
it "should have dup duplicate internal structures" do
|
|
75
75
|
@p.instance_filter(:name=>'Joe')
|
|
76
|
-
@p.dup.send(:instance_filters).
|
|
77
|
-
@p.dup.send(:instance_filters).
|
|
76
|
+
@p.dup.send(:instance_filters).must_equal @p.send(:instance_filters)
|
|
77
|
+
@p.dup.send(:instance_filters).wont_be_same_as(@p.send(:instance_filters))
|
|
78
78
|
end
|
|
79
79
|
end
|
|
@@ -20,19 +20,19 @@ describe "InstanceHooks plugin" do
|
|
|
20
20
|
@o.before_create_hook{r 2}
|
|
21
21
|
@o.after_create_hook{r 3}
|
|
22
22
|
@o.before_create_hook{r 4}
|
|
23
|
-
@o.save.
|
|
24
|
-
@r.
|
|
23
|
+
@o.save.wont_equal nil
|
|
24
|
+
@r.must_equal [4, 2, 1, 3]
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "should cancel the save if before_create_hook block returns false" do
|
|
28
28
|
@o.after_create_hook{r 1}
|
|
29
29
|
@o.before_create_hook{r false}
|
|
30
30
|
@o.before_create_hook{r 4}
|
|
31
|
-
@o.save.
|
|
32
|
-
@r.
|
|
31
|
+
@o.save.must_equal nil
|
|
32
|
+
@r.must_equal [4, false]
|
|
33
33
|
@r.clear
|
|
34
|
-
@o.save.
|
|
35
|
-
@r.
|
|
34
|
+
@o.save.must_equal nil
|
|
35
|
+
@r.must_equal [4, false]
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it "should support before_update_hook and after_update_hook" do
|
|
@@ -40,21 +40,21 @@ describe "InstanceHooks plugin" do
|
|
|
40
40
|
@x.before_update_hook{r 2}
|
|
41
41
|
@x.after_update_hook{r 3}
|
|
42
42
|
@x.before_update_hook{r 4}
|
|
43
|
-
@x.save.
|
|
44
|
-
@r.
|
|
45
|
-
@x.save.
|
|
46
|
-
@r.
|
|
43
|
+
@x.save.wont_equal nil
|
|
44
|
+
@r.must_equal [4, 2, 1, 3]
|
|
45
|
+
@x.save.wont_equal nil
|
|
46
|
+
@r.must_equal [4, 2, 1, 3]
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
it "should cancel the save if before_update_hook block returns false" do
|
|
50
50
|
@x.after_update_hook{r 1}
|
|
51
51
|
@x.before_update_hook{r false}
|
|
52
52
|
@x.before_update_hook{r 4}
|
|
53
|
-
@x.save.
|
|
54
|
-
@r.
|
|
53
|
+
@x.save.must_equal nil
|
|
54
|
+
@r.must_equal [4, false]
|
|
55
55
|
@r.clear
|
|
56
|
-
@x.save.
|
|
57
|
-
@r.
|
|
56
|
+
@x.save.must_equal nil
|
|
57
|
+
@r.must_equal [4, false]
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
it "should support before_save_hook and after_save_hook" do
|
|
@@ -62,36 +62,36 @@ describe "InstanceHooks plugin" do
|
|
|
62
62
|
@o.before_save_hook{r 2}
|
|
63
63
|
@o.after_save_hook{r 3}
|
|
64
64
|
@o.before_save_hook{r 4}
|
|
65
|
-
@o.save.
|
|
66
|
-
@r.
|
|
65
|
+
@o.save.wont_equal nil
|
|
66
|
+
@r.must_equal [4, 2, 1, 3]
|
|
67
67
|
@r.clear
|
|
68
68
|
|
|
69
69
|
@x.after_save_hook{r 1}
|
|
70
70
|
@x.before_save_hook{r 2}
|
|
71
71
|
@x.after_save_hook{r 3}
|
|
72
72
|
@x.before_save_hook{r 4}
|
|
73
|
-
@x.save.
|
|
74
|
-
@r.
|
|
75
|
-
@x.save.
|
|
76
|
-
@r.
|
|
73
|
+
@x.save.wont_equal nil
|
|
74
|
+
@r.must_equal [4, 2, 1, 3]
|
|
75
|
+
@x.save.wont_equal nil
|
|
76
|
+
@r.must_equal [4, 2, 1, 3]
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
it "should cancel the save if before_save_hook block returns false" do
|
|
80
80
|
@x.after_save_hook{r 1}
|
|
81
81
|
@x.before_save_hook{r false}
|
|
82
82
|
@x.before_save_hook{r 4}
|
|
83
|
-
@x.save.
|
|
84
|
-
@r.
|
|
83
|
+
@x.save.must_equal nil
|
|
84
|
+
@r.must_equal [4, false]
|
|
85
85
|
@r.clear
|
|
86
86
|
|
|
87
87
|
@x.after_save_hook{r 1}
|
|
88
88
|
@x.before_save_hook{r false}
|
|
89
89
|
@x.before_save_hook{r 4}
|
|
90
|
-
@x.save.
|
|
91
|
-
@r.
|
|
90
|
+
@x.save.must_equal nil
|
|
91
|
+
@r.must_equal [4, false]
|
|
92
92
|
@r.clear
|
|
93
|
-
@x.save.
|
|
94
|
-
@r.
|
|
93
|
+
@x.save.must_equal nil
|
|
94
|
+
@r.must_equal [4, false]
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
it "should support before_destroy_hook and after_destroy_hook" do
|
|
@@ -99,16 +99,16 @@ describe "InstanceHooks plugin" do
|
|
|
99
99
|
@x.before_destroy_hook{r 2}
|
|
100
100
|
@x.after_destroy_hook{r 3}
|
|
101
101
|
@x.before_destroy_hook{r 4}
|
|
102
|
-
@x.destroy.
|
|
103
|
-
@r.
|
|
102
|
+
@x.destroy.wont_equal nil
|
|
103
|
+
@r.must_equal [4, 2, 1, 3]
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
it "should cancel the destroy if before_destroy_hook block returns false" do
|
|
107
107
|
@x.after_destroy_hook{r 1}
|
|
108
108
|
@x.before_destroy_hook{r false}
|
|
109
109
|
@x.before_destroy_hook{r 4}
|
|
110
|
-
@x.destroy.
|
|
111
|
-
@r.
|
|
110
|
+
@x.destroy.must_equal nil
|
|
111
|
+
@r.must_equal [4, false]
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
it "should support before_validation_hook and after_validation_hook" do
|
|
@@ -116,19 +116,19 @@ describe "InstanceHooks plugin" do
|
|
|
116
116
|
@o.before_validation_hook{r 2}
|
|
117
117
|
@o.after_validation_hook{r 3}
|
|
118
118
|
@o.before_validation_hook{r 4}
|
|
119
|
-
@o.valid?.
|
|
120
|
-
@r.
|
|
119
|
+
@o.valid?.must_equal true
|
|
120
|
+
@r.must_equal [4, 2, 1, 3]
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
it "should cancel the save if before_validation_hook block returns false" do
|
|
124
124
|
@o.after_validation_hook{r 1}
|
|
125
125
|
@o.before_validation_hook{r false}
|
|
126
126
|
@o.before_validation_hook{r 4}
|
|
127
|
-
@o.valid?.
|
|
128
|
-
@r.
|
|
127
|
+
@o.valid?.must_equal false
|
|
128
|
+
@r.must_equal [4, false]
|
|
129
129
|
@r.clear
|
|
130
|
-
@o.valid?.
|
|
131
|
-
@r.
|
|
130
|
+
@o.valid?.must_equal false
|
|
131
|
+
@r.must_equal [4, false]
|
|
132
132
|
end
|
|
133
133
|
|
|
134
134
|
it "should clear only related hooks on successful create" do
|
|
@@ -140,15 +140,15 @@ describe "InstanceHooks plugin" do
|
|
|
140
140
|
@o.after_save_hook{r 6}
|
|
141
141
|
@o.before_create_hook{r 7}
|
|
142
142
|
@o.after_create_hook{r 8}
|
|
143
|
-
@o.save.
|
|
144
|
-
@r.
|
|
143
|
+
@o.save.wont_equal nil
|
|
144
|
+
@r.must_equal [5, 7, 8, 6]
|
|
145
145
|
@o.instance_variable_set(:@new, false)
|
|
146
|
-
@o.save.
|
|
147
|
-
@r.
|
|
148
|
-
@o.save.
|
|
149
|
-
@r.
|
|
146
|
+
@o.save.wont_equal nil
|
|
147
|
+
@r.must_equal [5, 7, 8, 6, 4, 3]
|
|
148
|
+
@o.save.wont_equal nil
|
|
149
|
+
@r.must_equal [5, 7, 8, 6, 4, 3]
|
|
150
150
|
@o.destroy
|
|
151
|
-
@r.
|
|
151
|
+
@r.must_equal [5, 7, 8, 6, 4, 3, 2, 1]
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
it "should clear only related hooks on successful update" do
|
|
@@ -158,12 +158,12 @@ describe "InstanceHooks plugin" do
|
|
|
158
158
|
@x.after_update_hook{r 4}
|
|
159
159
|
@x.before_save_hook{r 5}
|
|
160
160
|
@x.after_save_hook{r 6}
|
|
161
|
-
@x.save.
|
|
162
|
-
@r.
|
|
163
|
-
@x.save.
|
|
164
|
-
@r.
|
|
161
|
+
@x.save.wont_equal nil
|
|
162
|
+
@r.must_equal [5, 3, 4, 6]
|
|
163
|
+
@x.save.wont_equal nil
|
|
164
|
+
@r.must_equal [5, 3, 4, 6]
|
|
165
165
|
@x.destroy
|
|
166
|
-
@r.
|
|
166
|
+
@r.must_equal [5, 3, 4, 6, 2, 1]
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
it "should clear only related hooks on successful destroy" do
|
|
@@ -172,23 +172,23 @@ describe "InstanceHooks plugin" do
|
|
|
172
172
|
@x.before_update_hook{r 3}
|
|
173
173
|
@x.before_save_hook{r 4}
|
|
174
174
|
@x.destroy
|
|
175
|
-
@r.
|
|
176
|
-
@x.save.
|
|
177
|
-
@r.
|
|
175
|
+
@r.must_equal [2, 1]
|
|
176
|
+
@x.save.wont_equal nil
|
|
177
|
+
@r.must_equal [2, 1, 4, 3]
|
|
178
178
|
end
|
|
179
179
|
|
|
180
180
|
it "should not clear validations hooks on successful save" do
|
|
181
181
|
@x.after_validation_hook{@x.errors.add(:id, 'a') if @x.id == 1; r 1}
|
|
182
182
|
@x.before_validation_hook{r 2}
|
|
183
|
-
@x.save.
|
|
184
|
-
@r.
|
|
185
|
-
@x.save.
|
|
186
|
-
@r.
|
|
183
|
+
@x.save.must_equal nil
|
|
184
|
+
@r.must_equal [2, 1]
|
|
185
|
+
@x.save.must_equal nil
|
|
186
|
+
@r.must_equal [2, 1, 2, 1]
|
|
187
187
|
@x.id = 2
|
|
188
|
-
@x.save.
|
|
189
|
-
@r.
|
|
190
|
-
@x.save.
|
|
191
|
-
@r.
|
|
188
|
+
@x.save.must_equal @x
|
|
189
|
+
@r.must_equal [2, 1, 2, 1, 2, 1]
|
|
190
|
+
@x.save.must_equal @x
|
|
191
|
+
@r.must_equal [2, 1, 2, 1, 2, 1]
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
it "should not allow addition of instance hooks to frozen instances" do
|
|
@@ -197,10 +197,10 @@ describe "InstanceHooks plugin" do
|
|
|
197
197
|
@x.before_update_hook{r 3}
|
|
198
198
|
@x.before_save_hook{r 4}
|
|
199
199
|
@x.freeze
|
|
200
|
-
proc{@x.after_destroy_hook{r 1}}.
|
|
201
|
-
proc{@x.before_destroy_hook{r 2}}.
|
|
202
|
-
proc{@x.before_update_hook{r 3}}.
|
|
203
|
-
proc{@x.before_save_hook{r 4}}.
|
|
200
|
+
proc{@x.after_destroy_hook{r 1}}.must_raise(Sequel::Error)
|
|
201
|
+
proc{@x.before_destroy_hook{r 2}}.must_raise(Sequel::Error)
|
|
202
|
+
proc{@x.before_update_hook{r 3}}.must_raise(Sequel::Error)
|
|
203
|
+
proc{@x.before_save_hook{r 4}}.must_raise(Sequel::Error)
|
|
204
204
|
end
|
|
205
205
|
end
|
|
206
206
|
|
|
@@ -230,47 +230,47 @@ describe "InstanceHooks plugin with transactions" do
|
|
|
230
230
|
it "should support after_commit_hook" do
|
|
231
231
|
@o.after_commit_hook{@db.execute('ac1')}
|
|
232
232
|
@o.after_commit_hook{@db.execute('ac2')}
|
|
233
|
-
@o.save.
|
|
234
|
-
@db.sqls.
|
|
233
|
+
@o.save.wont_equal nil
|
|
234
|
+
@db.sqls.must_equal ['BEGIN', 'as', 'COMMIT', 'ac1', 'ac2']
|
|
235
235
|
end
|
|
236
236
|
|
|
237
237
|
it "should support after_rollback_hook" do
|
|
238
238
|
@or.after_rollback_hook{@db.execute('ar1')}
|
|
239
239
|
@or.after_rollback_hook{@db.execute('ar2')}
|
|
240
|
-
@or.save.
|
|
241
|
-
@db.sqls.
|
|
240
|
+
@or.save.must_equal nil
|
|
241
|
+
@db.sqls.must_equal ['BEGIN', 'as', 'ROLLBACK', 'ar1', 'ar2']
|
|
242
242
|
end
|
|
243
243
|
|
|
244
244
|
it "should support after_commit_hook" do
|
|
245
245
|
@o.after_destroy_commit_hook{@db.execute('adc1')}
|
|
246
246
|
@o.after_destroy_commit_hook{@db.execute('adc2')}
|
|
247
|
-
@o.destroy.
|
|
248
|
-
@db.sqls.
|
|
247
|
+
@o.destroy.wont_equal nil
|
|
248
|
+
@db.sqls.must_equal ['BEGIN', "DELETE FROM items WHERE (id = 1)", 'ad', 'COMMIT', 'adc1', 'adc2']
|
|
249
249
|
end
|
|
250
250
|
|
|
251
251
|
it "should support after_rollback_hook" do
|
|
252
252
|
@or.after_destroy_rollback_hook{@db.execute('adr1')}
|
|
253
253
|
@or.after_destroy_rollback_hook{@db.execute('adr2')}
|
|
254
|
-
@or.destroy.
|
|
255
|
-
@db.sqls.
|
|
254
|
+
@or.destroy.must_equal nil
|
|
255
|
+
@db.sqls.must_equal ['BEGIN', "DELETE FROM items WHERE (id = 1)", 'ad', 'ROLLBACK', 'adr1', 'adr2']
|
|
256
256
|
end
|
|
257
257
|
|
|
258
258
|
it "should have *_hook methods return self "do
|
|
259
|
-
@o.before_destroy_hook{r 1}.
|
|
260
|
-
@o.before_validation_hook{r 1}.
|
|
261
|
-
@o.before_save_hook{r 1}.
|
|
262
|
-
@o.before_update_hook{r 1}.
|
|
263
|
-
@o.before_create_hook{r 1}.
|
|
259
|
+
@o.before_destroy_hook{r 1}.must_be_same_as(@o)
|
|
260
|
+
@o.before_validation_hook{r 1}.must_be_same_as(@o)
|
|
261
|
+
@o.before_save_hook{r 1}.must_be_same_as(@o)
|
|
262
|
+
@o.before_update_hook{r 1}.must_be_same_as(@o)
|
|
263
|
+
@o.before_create_hook{r 1}.must_be_same_as(@o)
|
|
264
264
|
|
|
265
|
-
@o.after_destroy_hook{r 1}.
|
|
266
|
-
@o.after_validation_hook{r 1}.
|
|
267
|
-
@o.after_save_hook{r 1}.
|
|
268
|
-
@o.after_update_hook{r 1}.
|
|
269
|
-
@o.after_create_hook{r 1}.
|
|
270
|
-
@o.after_commit_hook{r 1}.
|
|
271
|
-
@o.after_rollback_hook{r 1}.
|
|
272
|
-
@o.after_destroy_commit_hook{r 1}.
|
|
273
|
-
@o.after_destroy_rollback_hook{r 1}.
|
|
265
|
+
@o.after_destroy_hook{r 1}.must_be_same_as(@o)
|
|
266
|
+
@o.after_validation_hook{r 1}.must_be_same_as(@o)
|
|
267
|
+
@o.after_save_hook{r 1}.must_be_same_as(@o)
|
|
268
|
+
@o.after_update_hook{r 1}.must_be_same_as(@o)
|
|
269
|
+
@o.after_create_hook{r 1}.must_be_same_as(@o)
|
|
270
|
+
@o.after_commit_hook{r 1}.must_be_same_as(@o)
|
|
271
|
+
@o.after_rollback_hook{r 1}.must_be_same_as(@o)
|
|
272
|
+
@o.after_destroy_commit_hook{r 1}.must_be_same_as(@o)
|
|
273
|
+
@o.after_destroy_rollback_hook{r 1}.must_be_same_as(@o)
|
|
274
274
|
end
|
|
275
275
|
|
|
276
276
|
end
|