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
|
@@ -11,163 +11,163 @@ describe "Sequel::Plugins::StaticCache" do
|
|
|
11
11
|
|
|
12
12
|
it "should not attempt to validate objects" do
|
|
13
13
|
@c.send(:define_method, :validate){errors.add(:name, 'bad')}
|
|
14
|
-
|
|
15
|
-
@c.map{|o| o.valid?}.
|
|
14
|
+
@c.plugin(:static_cache)
|
|
15
|
+
@c.map{|o| o.valid?}.must_equal [true, true]
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
static_cache_specs = shared_description do
|
|
19
19
|
it "should use a ruby hash as a cache of all model instances" do
|
|
20
|
-
@c.cache.
|
|
21
|
-
@c.cache[1].
|
|
22
|
-
@c.cache[2].
|
|
20
|
+
@c.cache.must_equal(1=>@c.load(:id=>1), 2=>@c.load(:id=>2))
|
|
21
|
+
@c.cache[1].must_be_same_as(@c1)
|
|
22
|
+
@c.cache[2].must_be_same_as(@c2)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it "should make .[] method with primary key use the cache" do
|
|
26
|
-
@c[1].
|
|
27
|
-
@c[2].
|
|
28
|
-
@c[3].
|
|
29
|
-
@c[[1, 2]].
|
|
30
|
-
@c[nil].
|
|
31
|
-
@c[].
|
|
32
|
-
@db.sqls.
|
|
26
|
+
@c[1].must_equal @c1
|
|
27
|
+
@c[2].must_equal @c2
|
|
28
|
+
@c[3].must_equal nil
|
|
29
|
+
@c[[1, 2]].must_equal nil
|
|
30
|
+
@c[nil].must_equal nil
|
|
31
|
+
@c[].must_equal nil
|
|
32
|
+
@db.sqls.must_equal []
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "should have .[] with a hash not use the cache" do
|
|
36
36
|
@db.fetch = {:id=>2}
|
|
37
|
-
@c[:id=>2].
|
|
38
|
-
@db.sqls.
|
|
37
|
+
@c[:id=>2].must_equal @c2
|
|
38
|
+
@db.sqls.must_equal ['SELECT * FROM t WHERE (id = 2) LIMIT 1']
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "should support cache_get_pk" do
|
|
42
|
-
@c.cache_get_pk(1).
|
|
43
|
-
@c.cache_get_pk(2).
|
|
44
|
-
@c.cache_get_pk(3).
|
|
45
|
-
@db.sqls.
|
|
42
|
+
@c.cache_get_pk(1).must_equal @c1
|
|
43
|
+
@c.cache_get_pk(2).must_equal @c2
|
|
44
|
+
@c.cache_get_pk(3).must_equal nil
|
|
45
|
+
@db.sqls.must_equal []
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it "should have each just iterate over the hash's values without sending a query" do
|
|
49
49
|
a = []
|
|
50
50
|
@c.each{|o| a << o}
|
|
51
51
|
a = a.sort_by{|o| o.id}
|
|
52
|
-
a.first.
|
|
53
|
-
a.last.
|
|
54
|
-
@db.sqls.
|
|
52
|
+
a.first.must_equal @c1
|
|
53
|
+
a.last.must_equal @c2
|
|
54
|
+
@db.sqls.must_equal []
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it "should have map just iterate over the hash's values without sending a query if no argument is given" do
|
|
58
|
-
@c.map{|v| v.id}.sort.
|
|
59
|
-
@db.sqls.
|
|
58
|
+
@c.map{|v| v.id}.sort.must_equal [1, 2]
|
|
59
|
+
@db.sqls.must_equal []
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
it "should have count with no argument or block not issue a query" do
|
|
63
|
-
@c.count.
|
|
64
|
-
@db.sqls.
|
|
63
|
+
@c.count.must_equal 2
|
|
64
|
+
@db.sqls.must_equal []
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "should have count with argument or block not issue a query" do
|
|
68
68
|
@db.fetch = [[{:count=>1}], [{:count=>2}]]
|
|
69
|
-
@c.count(:a).
|
|
70
|
-
@c.count{b}.
|
|
71
|
-
@db.sqls.
|
|
69
|
+
@c.count(:a).must_equal 1
|
|
70
|
+
@c.count{b}.must_equal 2
|
|
71
|
+
@db.sqls.must_equal ["SELECT count(a) AS count FROM t LIMIT 1", "SELECT count(b) AS count FROM t LIMIT 1"]
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
it "should have map not send a query if given an argument" do
|
|
75
|
-
@c.map(:id).sort.
|
|
76
|
-
@db.sqls.
|
|
77
|
-
@c.map([:id,:id]).sort.
|
|
78
|
-
@db.sqls.
|
|
75
|
+
@c.map(:id).sort.must_equal [1, 2]
|
|
76
|
+
@db.sqls.must_equal []
|
|
77
|
+
@c.map([:id,:id]).sort.must_equal [[1,1], [2,2]]
|
|
78
|
+
@db.sqls.must_equal []
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it "should have map without a block or argument not raise an exception or issue a query" do
|
|
82
|
-
@c.map.to_a.
|
|
83
|
-
@db.sqls.
|
|
82
|
+
@c.map.to_a.must_equal @c.all
|
|
83
|
+
@db.sqls.must_equal []
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
it "should have map without a block not return a frozen object" do
|
|
87
|
-
@c.map.frozen?.
|
|
87
|
+
@c.map.frozen?.must_equal false
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
it "should have map with a block and argument raise" do
|
|
91
|
-
proc{@c.map(:id){}}.
|
|
91
|
+
proc{@c.map(:id){}}.must_raise(Sequel::Error)
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
it "should have other enumerable methods work without sending a query" do
|
|
95
95
|
a = @c.sort_by{|o| o.id}
|
|
96
|
-
a.first.
|
|
97
|
-
a.last.
|
|
98
|
-
@db.sqls.
|
|
96
|
+
a.first.must_equal @c1
|
|
97
|
+
a.last.must_equal @c2
|
|
98
|
+
@db.sqls.must_equal []
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
it "should have all return all objects" do
|
|
102
102
|
a = @c.all.sort_by{|o| o.id}
|
|
103
|
-
a.first.
|
|
104
|
-
a.last.
|
|
105
|
-
@db.sqls.
|
|
103
|
+
a.first.must_equal @c1
|
|
104
|
+
a.last.must_equal @c2
|
|
105
|
+
@db.sqls.must_equal []
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
it "should have all not return a frozen object" do
|
|
109
|
-
@c.all.frozen?.
|
|
109
|
+
@c.all.frozen?.must_equal false
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
it "should have all return things in dataset order" do
|
|
113
|
-
@c.all.
|
|
113
|
+
@c.all.must_equal [@c1, @c2]
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
it "should have to_hash without arguments run without a query" do
|
|
117
117
|
a = @c.to_hash
|
|
118
|
-
a.
|
|
119
|
-
a[1].
|
|
120
|
-
a[2].
|
|
121
|
-
@db.sqls.
|
|
118
|
+
a.must_equal(1=>@c1, 2=>@c2)
|
|
119
|
+
a[1].must_equal @c1
|
|
120
|
+
a[2].must_equal @c2
|
|
121
|
+
@db.sqls.must_equal []
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
it "should have to_hash with arguments return results without a query" do
|
|
125
125
|
a = @c.to_hash(:id)
|
|
126
|
-
a.
|
|
127
|
-
a[1].
|
|
128
|
-
a[2].
|
|
126
|
+
a.must_equal(1=>@c1, 2=>@c2)
|
|
127
|
+
a[1].must_equal @c1
|
|
128
|
+
a[2].must_equal @c2
|
|
129
129
|
|
|
130
130
|
a = @c.to_hash([:id])
|
|
131
|
-
a.
|
|
132
|
-
a[[1]].
|
|
133
|
-
a[[2]].
|
|
131
|
+
a.must_equal([1]=>@c1, [2]=>@c2)
|
|
132
|
+
a[[1]].must_equal @c1
|
|
133
|
+
a[[2]].must_equal @c2
|
|
134
134
|
|
|
135
|
-
@c.to_hash(:id, :id).
|
|
136
|
-
@c.to_hash([:id], :id).
|
|
137
|
-
@c.to_hash(:id, [:id]).
|
|
138
|
-
@c.to_hash([:id], [:id]).
|
|
135
|
+
@c.to_hash(:id, :id).must_equal(1=>1, 2=>2)
|
|
136
|
+
@c.to_hash([:id], :id).must_equal([1]=>1, [2]=>2)
|
|
137
|
+
@c.to_hash(:id, [:id]).must_equal(1=>[1], 2=>[2])
|
|
138
|
+
@c.to_hash([:id], [:id]).must_equal([1]=>[1], [2]=>[2])
|
|
139
139
|
|
|
140
|
-
@db.sqls.
|
|
140
|
+
@db.sqls.must_equal []
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
it "should have to_hash not return a frozen object" do
|
|
144
|
-
@c.to_hash.frozen?.
|
|
144
|
+
@c.to_hash.frozen?.must_equal false
|
|
145
145
|
end
|
|
146
146
|
|
|
147
147
|
it "should have to_hash_groups without arguments return the cached objects without a query" do
|
|
148
148
|
a = @c.to_hash_groups(:id)
|
|
149
|
-
a.
|
|
150
|
-
a[1].first.
|
|
151
|
-
a[2].first.
|
|
149
|
+
a.must_equal(1=>[@c1], 2=>[@c2])
|
|
150
|
+
a[1].first.must_equal @c1
|
|
151
|
+
a[2].first.must_equal @c2
|
|
152
152
|
|
|
153
153
|
a = @c.to_hash_groups([:id])
|
|
154
|
-
a.
|
|
155
|
-
a[[1]].first.
|
|
156
|
-
a[[2]].first.
|
|
154
|
+
a.must_equal([1]=>[@c1], [2]=>[@c2])
|
|
155
|
+
a[[1]].first.must_equal @c1
|
|
156
|
+
a[[2]].first.must_equal @c2
|
|
157
157
|
|
|
158
|
-
@c.to_hash_groups(:id, :id).
|
|
159
|
-
@c.to_hash_groups([:id], :id).
|
|
160
|
-
@c.to_hash_groups(:id, [:id]).
|
|
161
|
-
@c.to_hash_groups([:id], [:id]).
|
|
158
|
+
@c.to_hash_groups(:id, :id).must_equal(1=>[1], 2=>[2])
|
|
159
|
+
@c.to_hash_groups([:id], :id).must_equal([1]=>[1], [2]=>[2])
|
|
160
|
+
@c.to_hash_groups(:id, [:id]).must_equal(1=>[[1]], 2=>[[2]])
|
|
161
|
+
@c.to_hash_groups([:id], [:id]).must_equal([1]=>[[1]], [2]=>[[2]])
|
|
162
162
|
|
|
163
|
-
@db.sqls.
|
|
163
|
+
@db.sqls.must_equal []
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
it "subclasses should work correctly" do
|
|
167
167
|
c = Class.new(@c)
|
|
168
|
-
c.all.
|
|
169
|
-
c.to_hash.
|
|
170
|
-
@db.sqls.
|
|
168
|
+
c.all.must_equal [c.load(:id=>1), c.load(:id=>2)]
|
|
169
|
+
c.to_hash.must_equal(1=>c.load(:id=>1), 2=>c.load(:id=>2))
|
|
170
|
+
@db.sqls.must_equal ['SELECT * FROM t']
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
it "set_dataset should work correctly" do
|
|
@@ -175,10 +175,10 @@ describe "Sequel::Plugins::StaticCache" do
|
|
|
175
175
|
ds.instance_variable_set(:@columns, [:id])
|
|
176
176
|
ds._fetch = {:id=>3}
|
|
177
177
|
@c.dataset = ds
|
|
178
|
-
@c.all.
|
|
179
|
-
@c.to_hash.
|
|
180
|
-
@c.to_hash[3].
|
|
181
|
-
@db.sqls.
|
|
178
|
+
@c.all.must_equal [@c.load(:id=>3)]
|
|
179
|
+
@c.to_hash.must_equal(3=>@c.load(:id=>3))
|
|
180
|
+
@c.to_hash[3].must_equal @c.all.first
|
|
181
|
+
@db.sqls.must_equal ['SELECT * FROM t2']
|
|
182
182
|
end
|
|
183
183
|
end
|
|
184
184
|
|
|
@@ -190,7 +190,7 @@ describe "Sequel::Plugins::StaticCache" do
|
|
|
190
190
|
@db.sqls
|
|
191
191
|
end
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
include static_cache_specs
|
|
194
194
|
|
|
195
195
|
it "should work correctly with composite keys" do
|
|
196
196
|
@db.fetch = [{:id=>1, :id2=>1}, {:id=>2, :id2=>1}]
|
|
@@ -201,83 +201,83 @@ describe "Sequel::Plugins::StaticCache" do
|
|
|
201
201
|
@db.sqls
|
|
202
202
|
@c1 = @c.cache[[1, 2]]
|
|
203
203
|
@c2 = @c.cache[[2, 1]]
|
|
204
|
-
@c[[1, 2]].
|
|
205
|
-
@c[[2, 1]].
|
|
206
|
-
@db.sqls.
|
|
204
|
+
@c[[1, 2]].must_be_same_as(@c1)
|
|
205
|
+
@c[[2, 1]].must_be_same_as(@c2)
|
|
206
|
+
@db.sqls.must_equal []
|
|
207
207
|
end
|
|
208
208
|
|
|
209
209
|
it "all of the static cache values (model instances) should be frozen" do
|
|
210
|
-
@c.all.all?{|o| o.frozen?}.
|
|
210
|
+
@c.all.all?{|o| o.frozen?}.must_equal true
|
|
211
211
|
end
|
|
212
212
|
|
|
213
213
|
it "should make .[] method with primary key return cached instances" do
|
|
214
|
-
@c[1].
|
|
215
|
-
@c[2].
|
|
214
|
+
@c[1].must_be_same_as(@c1)
|
|
215
|
+
@c[2].must_be_same_as(@c2)
|
|
216
216
|
end
|
|
217
217
|
|
|
218
218
|
it "should have cache_get_pk return cached instances" do
|
|
219
|
-
@c.cache_get_pk(1).
|
|
220
|
-
@c.cache_get_pk(2).
|
|
219
|
+
@c.cache_get_pk(1).must_be_same_as(@c1)
|
|
220
|
+
@c.cache_get_pk(2).must_be_same_as(@c2)
|
|
221
221
|
end
|
|
222
222
|
|
|
223
223
|
it "should have each yield cached objects" do
|
|
224
224
|
a = []
|
|
225
225
|
@c.each{|o| a << o}
|
|
226
226
|
a = a.sort_by{|o| o.id}
|
|
227
|
-
a.first.
|
|
228
|
-
a.last.
|
|
227
|
+
a.first.must_be_same_as(@c1)
|
|
228
|
+
a.last.must_be_same_as(@c2)
|
|
229
229
|
end
|
|
230
230
|
|
|
231
231
|
it "should have other enumerable methods work yield cached objects" do
|
|
232
232
|
a = @c.sort_by{|o| o.id}
|
|
233
|
-
a.first.
|
|
234
|
-
a.last.
|
|
233
|
+
a.first.must_be_same_as(@c1)
|
|
234
|
+
a.last.must_be_same_as(@c2)
|
|
235
235
|
end
|
|
236
236
|
|
|
237
237
|
it "should have all return cached instances" do
|
|
238
238
|
a = @c.all.sort_by{|o| o.id}
|
|
239
|
-
a.first.
|
|
240
|
-
a.last.
|
|
239
|
+
a.first.must_be_same_as(@c1)
|
|
240
|
+
a.last.must_be_same_as(@c2)
|
|
241
241
|
end
|
|
242
242
|
|
|
243
243
|
it "should have to_hash without arguments use cached instances" do
|
|
244
244
|
a = @c.to_hash
|
|
245
|
-
a[1].
|
|
246
|
-
a[2].
|
|
245
|
+
a[1].must_be_same_as(@c1)
|
|
246
|
+
a[2].must_be_same_as(@c2)
|
|
247
247
|
end
|
|
248
248
|
|
|
249
249
|
it "should have to_hash with arguments return cached instances" do
|
|
250
250
|
a = @c.to_hash(:id)
|
|
251
|
-
a[1].
|
|
252
|
-
a[2].
|
|
251
|
+
a[1].must_be_same_as(@c1)
|
|
252
|
+
a[2].must_be_same_as(@c2)
|
|
253
253
|
|
|
254
254
|
a = @c.to_hash([:id])
|
|
255
|
-
a[[1]].
|
|
256
|
-
a[[2]].
|
|
255
|
+
a[[1]].must_be_same_as(@c1)
|
|
256
|
+
a[[2]].must_be_same_as(@c2)
|
|
257
257
|
end
|
|
258
258
|
|
|
259
259
|
it "should have to_hash_groups without single argument return the cached instances" do
|
|
260
260
|
a = @c.to_hash_groups(:id)
|
|
261
|
-
a[1].first.
|
|
262
|
-
a[2].first.
|
|
261
|
+
a[1].first.must_be_same_as(@c1)
|
|
262
|
+
a[2].first.must_be_same_as(@c2)
|
|
263
263
|
|
|
264
264
|
a = @c.to_hash_groups([:id])
|
|
265
|
-
a[[1]].first.
|
|
266
|
-
a[[2]].first.
|
|
265
|
+
a[[1]].first.must_be_same_as(@c1)
|
|
266
|
+
a[[2]].first.must_be_same_as(@c2)
|
|
267
267
|
end
|
|
268
268
|
|
|
269
269
|
it "should not allow the saving of new objects" do
|
|
270
|
-
proc{@c.create}.
|
|
270
|
+
proc{@c.create}.must_raise(Sequel::HookFailed)
|
|
271
271
|
end
|
|
272
272
|
|
|
273
273
|
it "should not allow the saving of existing objects" do
|
|
274
274
|
@db.fetch = {:id=>1}
|
|
275
|
-
proc{@c.first(:id=>1).save}.
|
|
275
|
+
proc{@c.first(:id=>1).save}.must_raise(Sequel::HookFailed)
|
|
276
276
|
end
|
|
277
277
|
|
|
278
278
|
it "should not allow the destroying of existing objects" do
|
|
279
279
|
@db.fetch = {:id=>1}
|
|
280
|
-
proc{@c.first(:id=>1).destroy}.
|
|
280
|
+
proc{@c.first(:id=>1).destroy}.must_raise(Sequel::HookFailed)
|
|
281
281
|
end
|
|
282
282
|
end
|
|
283
283
|
|
|
@@ -289,50 +289,50 @@ describe "Sequel::Plugins::StaticCache" do
|
|
|
289
289
|
@db.sqls
|
|
290
290
|
end
|
|
291
291
|
|
|
292
|
-
|
|
292
|
+
include static_cache_specs
|
|
293
293
|
|
|
294
294
|
it "record retrieved by primary key should not be frozen" do
|
|
295
|
-
@c[1].frozen?.
|
|
296
|
-
@c.cache_get_pk(1).frozen?.
|
|
295
|
+
@c[1].frozen?.must_equal false
|
|
296
|
+
@c.cache_get_pk(1).frozen?.must_equal false
|
|
297
297
|
end
|
|
298
298
|
|
|
299
299
|
it "none of values returned in #all should be frozen" do
|
|
300
|
-
@c.all.all?{|o| !o.frozen?}.
|
|
300
|
+
@c.all.all?{|o| !o.frozen?}.must_equal true
|
|
301
301
|
end
|
|
302
302
|
|
|
303
303
|
it "none of values yielded by each should be frozen" do
|
|
304
304
|
a = []
|
|
305
305
|
@c.each{|o| a << o}
|
|
306
|
-
a.all?{|o| !o.frozen?}.
|
|
306
|
+
a.all?{|o| !o.frozen?}.must_equal true
|
|
307
307
|
end
|
|
308
308
|
|
|
309
309
|
it "none of values yielded by Enumerable method should be frozen" do
|
|
310
|
-
@c.sort_by{|o| o.id}.all?{|o| !o.frozen?}.
|
|
310
|
+
@c.sort_by{|o| o.id}.all?{|o| !o.frozen?}.must_equal true
|
|
311
311
|
end
|
|
312
312
|
|
|
313
313
|
it "none of values returned by map without an argument or block should be frozen" do
|
|
314
|
-
@c.map{|o| o}.all?{|o| !o.frozen?}.
|
|
315
|
-
@c.map.all?{|o| !o.frozen?}.
|
|
314
|
+
@c.map{|o| o}.all?{|o| !o.frozen?}.must_equal true
|
|
315
|
+
@c.map.all?{|o| !o.frozen?}.must_equal true
|
|
316
316
|
end
|
|
317
317
|
|
|
318
318
|
it "none of values in the hash returned by to_hash without an argument should be frozen" do
|
|
319
|
-
@c.to_hash.values.all?{|o| !o.frozen?}.
|
|
319
|
+
@c.to_hash.values.all?{|o| !o.frozen?}.must_equal true
|
|
320
320
|
end
|
|
321
321
|
|
|
322
322
|
it "none of values in the hash returned by to_hash with a single argument should be frozen" do
|
|
323
|
-
@c.to_hash(:id).values.all?{|o| !o.frozen?}.
|
|
323
|
+
@c.to_hash(:id).values.all?{|o| !o.frozen?}.must_equal true
|
|
324
324
|
end
|
|
325
325
|
|
|
326
326
|
it "none of values in the hash returned by to_hash with a single array argument should be frozen" do
|
|
327
|
-
@c.to_hash([:id, :id]).values.all?{|o| !o.frozen?}.
|
|
327
|
+
@c.to_hash([:id, :id]).values.all?{|o| !o.frozen?}.must_equal true
|
|
328
328
|
end
|
|
329
329
|
|
|
330
330
|
it "none of values in the hash returned by to_hash_groups with a single argument should be frozen" do
|
|
331
|
-
@c.to_hash_groups(:id).values.flatten.all?{|o| !o.frozen?}.
|
|
331
|
+
@c.to_hash_groups(:id).values.flatten.all?{|o| !o.frozen?}.must_equal true
|
|
332
332
|
end
|
|
333
333
|
|
|
334
334
|
it "none of values in the hash returned by to_hash_groups with a single array argument should be frozen" do
|
|
335
|
-
@c.to_hash_groups([:id, :id]).values.flatten.all?{|o| !o.frozen?}.
|
|
335
|
+
@c.to_hash_groups([:id, :id]).values.flatten.all?{|o| !o.frozen?}.must_equal true
|
|
336
336
|
end
|
|
337
337
|
|
|
338
338
|
it "should not automatically update the cache when creating new model objects" do
|
|
@@ -341,21 +341,21 @@ describe "Sequel::Plugins::StaticCache" do
|
|
|
341
341
|
@db.autoid = 3
|
|
342
342
|
@db.fetch = [[{:id=>1}, {:id=>2}, {:id=>3}], [{:id=>3}]]
|
|
343
343
|
o.save
|
|
344
|
-
@c[3].
|
|
344
|
+
@c[3].must_equal nil
|
|
345
345
|
end
|
|
346
346
|
|
|
347
347
|
it "should not automatically update the cache when updating model objects" do
|
|
348
348
|
o = @c[2]
|
|
349
349
|
@db.fetch = [[{:id=>1}, {:id=>2, :name=>'a'}]]
|
|
350
350
|
o.update(:name=>'a')
|
|
351
|
-
@c[2].values.
|
|
351
|
+
@c[2].values.must_equal(:id=>2)
|
|
352
352
|
end
|
|
353
353
|
|
|
354
354
|
it "should not automatically update the cache when updating model objects" do
|
|
355
355
|
o = @c[2]
|
|
356
356
|
@db.fetch = [[{:id=>1}]]
|
|
357
357
|
o.destroy
|
|
358
|
-
@c[2].
|
|
358
|
+
@c[2].must_equal @c2
|
|
359
359
|
end
|
|
360
360
|
end
|
|
361
361
|
end
|