sequel 4.22.0 → 4.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +22 -0
- data/README.rdoc +6 -0
- data/Rakefile +59 -81
- data/doc/migration.rdoc +2 -0
- data/doc/release_notes/4.23.0.txt +65 -0
- data/doc/sharding.rdoc +16 -14
- data/doc/testing.rdoc +61 -77
- data/lib/sequel/adapters/jdbc.rb +1 -0
- data/lib/sequel/adapters/mock.rb +0 -1
- data/lib/sequel/adapters/postgres.rb +1 -0
- data/lib/sequel/adapters/postgresql.rb +1 -0
- data/lib/sequel/adapters/shared/postgres.rb +3 -3
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
- data/lib/sequel/connection_pool/threaded.rb +9 -1
- data/lib/sequel/database/connecting.rb +1 -1
- data/lib/sequel/database/transactions.rb +2 -1
- data/lib/sequel/dataset/prepared_statements.rb +1 -1
- data/lib/sequel/extensions/constraint_validations.rb +12 -12
- data/lib/sequel/extensions/date_arithmetic.rb +0 -4
- data/lib/sequel/extensions/pagination.rb +14 -2
- data/lib/sequel/extensions/pg_enum.rb +2 -2
- data/lib/sequel/extensions/pg_hstore.rb +1 -1
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +2 -0
- data/lib/sequel/plugins/delay_add_association.rb +50 -0
- data/lib/sequel/plugins/list.rb +2 -2
- data/lib/sequel/plugins/nested_attributes.rb +8 -28
- data/lib/sequel/plugins/update_refresh.rb +50 -0
- data/lib/sequel/plugins/validate_associated.rb +55 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +29 -29
- data/spec/adapters/firebird_spec.rb +97 -103
- data/spec/adapters/informix_spec.rb +25 -25
- data/spec/adapters/mssql_spec.rb +156 -172
- data/spec/adapters/mysql_spec.rb +334 -359
- data/spec/adapters/oracle_spec.rb +67 -69
- data/spec/adapters/postgres_spec.rb +1298 -1249
- data/spec/adapters/spec_helper.rb +2 -35
- data/spec/adapters/sqlanywhere_spec.rb +39 -39
- data/spec/adapters/sqlite_spec.rb +203 -200
- data/spec/bin_spec.rb +57 -59
- data/spec/core/connection_pool_spec.rb +402 -401
- data/spec/core/database_spec.rb +953 -944
- data/spec/core/dataset_spec.rb +2178 -2168
- data/spec/core/deprecated_spec.rb +19 -19
- data/spec/core/expression_filters_spec.rb +415 -415
- data/spec/core/mock_adapter_spec.rb +212 -212
- data/spec/core/object_graph_spec.rb +73 -73
- data/spec/core/placeholder_literalizer_spec.rb +71 -71
- data/spec/core/schema_generator_spec.rb +44 -44
- data/spec/core/schema_spec.rb +470 -472
- data/spec/core/spec_helper.rb +5 -20
- data/spec/core/version_spec.rb +2 -2
- data/spec/core_extensions_spec.rb +320 -320
- data/spec/extensions/accessed_columns_spec.rb +12 -12
- data/spec/extensions/active_model_spec.rb +3 -3
- data/spec/extensions/after_initialize_spec.rb +2 -2
- data/spec/extensions/arbitrary_servers_spec.rb +23 -23
- data/spec/extensions/association_dependencies_spec.rb +34 -34
- data/spec/extensions/association_pks_spec.rb +98 -98
- data/spec/extensions/association_proxies_spec.rb +33 -33
- data/spec/extensions/auto_validations_spec.rb +46 -46
- data/spec/extensions/blacklist_security_spec.rb +19 -18
- data/spec/extensions/blank_spec.rb +36 -36
- data/spec/extensions/boolean_readers_spec.rb +36 -36
- data/spec/extensions/caching_spec.rb +82 -82
- data/spec/extensions/class_table_inheritance_spec.rb +72 -72
- data/spec/extensions/column_conflicts_spec.rb +19 -14
- data/spec/extensions/column_select_spec.rb +19 -19
- data/spec/extensions/columns_introspection_spec.rb +43 -43
- data/spec/extensions/composition_spec.rb +64 -64
- data/spec/extensions/connection_validator_spec.rb +92 -90
- data/spec/extensions/constraint_validations_plugin_spec.rb +92 -92
- data/spec/extensions/constraint_validations_spec.rb +80 -80
- data/spec/extensions/core_refinements_spec.rb +220 -220
- data/spec/extensions/csv_serializer_spec.rb +44 -44
- data/spec/extensions/current_datetime_timestamp_spec.rb +8 -8
- data/spec/extensions/dataset_associations_spec.rb +65 -65
- data/spec/extensions/dataset_source_alias_spec.rb +16 -16
- data/spec/extensions/date_arithmetic_spec.rb +51 -58
- data/spec/extensions/defaults_setter_spec.rb +19 -19
- data/spec/extensions/delay_add_association_spec.rb +52 -0
- data/spec/extensions/dirty_spec.rb +51 -51
- data/spec/extensions/eager_each_spec.rb +8 -8
- data/spec/extensions/empty_array_ignore_nulls_spec.rb +10 -10
- data/spec/extensions/error_splitter_spec.rb +2 -2
- data/spec/extensions/error_sql_spec.rb +4 -4
- data/spec/extensions/eval_inspect_spec.rb +3 -3
- data/spec/extensions/filter_having_spec.rb +8 -8
- data/spec/extensions/force_encoding_spec.rb +30 -30
- data/spec/extensions/from_block_spec.rb +7 -7
- data/spec/extensions/graph_each_spec.rb +19 -19
- data/spec/extensions/hash_aliases_spec.rb +5 -5
- data/spec/extensions/hook_class_methods_spec.rb +100 -100
- data/spec/extensions/inflector_spec.rb +54 -54
- data/spec/extensions/input_transformer_spec.rb +10 -10
- data/spec/extensions/insert_returning_select_spec.rb +8 -8
- data/spec/extensions/instance_filters_spec.rb +26 -26
- data/spec/extensions/instance_hooks_spec.rb +85 -85
- data/spec/extensions/json_serializer_spec.rb +68 -68
- data/spec/extensions/lazy_attributes_spec.rb +49 -49
- data/spec/extensions/list_spec.rb +77 -75
- data/spec/extensions/looser_typecasting_spec.rb +16 -16
- data/spec/extensions/many_through_many_spec.rb +627 -627
- data/spec/extensions/meta_def_spec.rb +7 -7
- data/spec/extensions/migration_spec.rb +217 -217
- data/spec/extensions/modification_detection_spec.rb +20 -20
- data/spec/extensions/mssql_optimistic_locking_spec.rb +21 -21
- data/spec/extensions/named_timezones_spec.rb +18 -18
- data/spec/extensions/nested_attributes_spec.rb +107 -107
- data/spec/extensions/null_dataset_spec.rb +24 -24
- data/spec/extensions/optimistic_locking_spec.rb +21 -21
- data/spec/extensions/pagination_spec.rb +52 -52
- data/spec/extensions/pg_array_associations_spec.rb +273 -273
- data/spec/extensions/pg_array_ops_spec.rb +52 -52
- data/spec/extensions/pg_array_spec.rb +152 -152
- data/spec/extensions/pg_enum_spec.rb +13 -13
- data/spec/extensions/pg_hstore_ops_spec.rb +63 -63
- data/spec/extensions/pg_hstore_spec.rb +84 -84
- data/spec/extensions/pg_inet_spec.rb +15 -15
- data/spec/extensions/pg_interval_spec.rb +29 -29
- data/spec/extensions/pg_json_ops_spec.rb +86 -84
- data/spec/extensions/pg_json_spec.rb +104 -104
- data/spec/extensions/pg_loose_count_spec.rb +6 -6
- data/spec/extensions/pg_range_ops_spec.rb +24 -24
- data/spec/extensions/pg_range_spec.rb +143 -143
- data/spec/extensions/pg_row_ops_spec.rb +14 -14
- data/spec/extensions/pg_row_plugin_spec.rb +12 -12
- data/spec/extensions/pg_row_spec.rb +118 -118
- data/spec/extensions/pg_static_cache_updater_spec.rb +28 -28
- data/spec/extensions/pg_typecast_on_load_spec.rb +21 -21
- data/spec/extensions/prepared_statements_associations_spec.rb +42 -42
- data/spec/extensions/prepared_statements_safe_spec.rb +18 -18
- data/spec/extensions/prepared_statements_spec.rb +28 -28
- data/spec/extensions/prepared_statements_with_pk_spec.rb +11 -11
- data/spec/extensions/pretty_table_spec.rb +16 -16
- data/spec/extensions/query_literals_spec.rb +37 -37
- data/spec/extensions/query_spec.rb +32 -32
- data/spec/extensions/rcte_tree_spec.rb +141 -141
- data/spec/extensions/round_timestamps_spec.rb +21 -21
- data/spec/extensions/schema_caching_spec.rb +8 -8
- data/spec/extensions/schema_dumper_spec.rb +78 -78
- data/spec/extensions/schema_spec.rb +31 -27
- data/spec/extensions/scissors_spec.rb +3 -3
- data/spec/extensions/select_remove_spec.rb +14 -14
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +28 -28
- data/spec/extensions/serialization_modification_detection_spec.rb +33 -33
- data/spec/extensions/serialization_spec.rb +79 -78
- data/spec/extensions/server_block_spec.rb +17 -17
- data/spec/extensions/set_overrides_spec.rb +30 -30
- data/spec/extensions/sharding_spec.rb +65 -65
- data/spec/extensions/shared_caching_spec.rb +29 -29
- data/spec/extensions/single_table_inheritance_spec.rb +79 -79
- data/spec/extensions/skip_create_refresh_spec.rb +3 -3
- data/spec/extensions/spec_helper.rb +4 -29
- data/spec/extensions/split_array_nil_spec.rb +9 -9
- data/spec/extensions/split_values_spec.rb +7 -7
- data/spec/extensions/sql_expr_spec.rb +32 -32
- data/spec/extensions/static_cache_spec.rb +123 -123
- data/spec/extensions/string_date_time_spec.rb +34 -34
- data/spec/extensions/string_stripper_spec.rb +15 -15
- data/spec/extensions/subclasses_spec.rb +31 -31
- data/spec/extensions/table_select_spec.rb +15 -15
- data/spec/extensions/tactical_eager_loading_spec.rb +23 -23
- data/spec/extensions/thread_local_timezones_spec.rb +13 -13
- data/spec/extensions/timestamps_spec.rb +40 -40
- data/spec/extensions/to_dot_spec.rb +34 -34
- data/spec/extensions/touch_spec.rb +52 -52
- data/spec/extensions/tree_spec.rb +72 -72
- data/spec/extensions/typecast_on_load_spec.rb +25 -25
- data/spec/extensions/unlimited_update_spec.rb +2 -2
- data/spec/extensions/update_or_create_spec.rb +36 -36
- data/spec/extensions/update_primary_key_spec.rb +35 -35
- data/spec/extensions/update_refresh_spec.rb +41 -0
- data/spec/extensions/validate_associated_spec.rb +52 -0
- data/spec/extensions/validation_class_methods_spec.rb +314 -317
- data/spec/extensions/validation_helpers_spec.rb +195 -195
- data/spec/extensions/xml_serializer_spec.rb +48 -48
- data/spec/guards_helper.rb +55 -0
- data/spec/integration/associations_test.rb +1089 -1088
- data/spec/integration/database_test.rb +29 -29
- data/spec/integration/dataset_test.rb +661 -661
- data/spec/integration/eager_loader_test.rb +147 -147
- data/spec/integration/migrator_test.rb +122 -122
- data/spec/integration/model_test.rb +70 -70
- data/spec/integration/plugin_test.rb +682 -640
- data/spec/integration/prepared_statement_test.rb +172 -172
- data/spec/integration/schema_test.rb +245 -245
- data/spec/integration/spec_helper.rb +1 -64
- data/spec/integration/timezone_test.rb +17 -17
- data/spec/integration/transaction_test.rb +87 -87
- data/spec/integration/type_test.rb +33 -33
- data/spec/model/association_reflection_spec.rb +130 -121
- data/spec/model/associations_spec.rb +1112 -1113
- data/spec/model/base_spec.rb +197 -196
- data/spec/model/class_dataset_methods_spec.rb +118 -118
- data/spec/model/dataset_methods_spec.rb +49 -49
- data/spec/model/eager_loading_spec.rb +705 -702
- data/spec/model/hooks_spec.rb +169 -168
- data/spec/model/inflector_spec.rb +5 -5
- data/spec/model/model_spec.rb +287 -297
- data/spec/model/plugins_spec.rb +47 -47
- data/spec/model/record_spec.rb +534 -535
- data/spec/model/spec_helper.rb +3 -21
- data/spec/model/validations_spec.rb +72 -70
- data/spec/spec_config.rb +8 -0
- metadata +41 -9
- data/lib/sequel/adapters/fdbsql.rb +0 -286
- data/lib/sequel/adapters/jdbc/fdbsql.rb +0 -66
- data/lib/sequel/adapters/openbase.rb +0 -54
- data/lib/sequel/adapters/shared/fdbsql.rb +0 -550
- data/spec/adapters/fdbsql_spec.rb +0 -429
- data/spec/rspec_helper.rb +0 -22
@@ -12,15 +12,15 @@ describe Sequel::Inflections do
|
|
12
12
|
|
13
13
|
it "should be possible to clear the list of singulars, plurals, and uncountables" do
|
14
14
|
Sequel.inflections.clear(:plurals)
|
15
|
-
Sequel.inflections.plurals.
|
15
|
+
Sequel.inflections.plurals.must_equal []
|
16
16
|
Sequel.inflections.plural('blah', 'blahs')
|
17
17
|
Sequel.inflections.clear
|
18
|
-
Sequel.inflections.plurals.
|
19
|
-
Sequel.inflections.singulars.
|
20
|
-
Sequel.inflections.uncountables.
|
18
|
+
Sequel.inflections.plurals.must_equal []
|
19
|
+
Sequel.inflections.singulars.must_equal []
|
20
|
+
Sequel.inflections.uncountables.must_equal []
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should be yielded and returned by Sequel.inflections" do
|
24
|
-
Sequel.inflections{|i| i.
|
24
|
+
Sequel.inflections{|i| i.must_equal Sequel::Inflections}.must_equal Sequel::Inflections
|
25
25
|
end
|
26
26
|
end
|
data/spec/model/model_spec.rb
CHANGED
@@ -8,62 +8,62 @@ describe "Sequel::Model()" do
|
|
8
8
|
it "should return a model subclass with the given dataset if given a dataset" do
|
9
9
|
ds = @db[:blah]
|
10
10
|
c = Sequel::Model(ds)
|
11
|
-
c.superclass.
|
12
|
-
c.dataset.
|
11
|
+
c.superclass.must_equal Sequel::Model
|
12
|
+
c.dataset.must_equal ds
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should return a model subclass with a dataset with the default database and given table name if given a Symbol" do
|
16
16
|
c = Sequel::Model(:blah)
|
17
|
-
c.superclass.
|
18
|
-
c.db.
|
19
|
-
c.table_name.
|
17
|
+
c.superclass.must_equal Sequel::Model
|
18
|
+
c.db.must_equal @db
|
19
|
+
c.table_name.must_equal :blah
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should return a model subclass with a dataset with the default database and given table name if given a LiteralString" do
|
23
23
|
c = Sequel::Model(Sequel.lit('blah'))
|
24
|
-
c.superclass.
|
25
|
-
c.db.
|
26
|
-
c.table_name.
|
24
|
+
c.superclass.must_equal Sequel::Model
|
25
|
+
c.db.must_equal @db
|
26
|
+
c.table_name.must_equal Sequel.lit('blah')
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should return a model subclass with a dataset with the default database and given table name if given an SQL::Identifier" do
|
30
30
|
c = Sequel::Model(Sequel.identifier(:blah))
|
31
|
-
c.superclass.
|
32
|
-
c.db.
|
33
|
-
c.table_name.
|
31
|
+
c.superclass.must_equal Sequel::Model
|
32
|
+
c.db.must_equal @db
|
33
|
+
c.table_name.must_equal Sequel.identifier(:blah)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should return a model subclass with a dataset with the default database and given table name if given an SQL::QualifiedIdentifier" do
|
37
37
|
c = Sequel::Model(Sequel.qualify(:boo, :blah))
|
38
|
-
c.superclass.
|
39
|
-
c.db.
|
40
|
-
c.table_name.
|
38
|
+
c.superclass.must_equal Sequel::Model
|
39
|
+
c.db.must_equal @db
|
40
|
+
c.table_name.must_equal Sequel.qualify(:boo, :blah)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should return a model subclass with a dataset with the default database and given table name if given an SQL::AliasedExpression" do
|
44
44
|
c = Sequel::Model(Sequel.as(:blah, :boo))
|
45
|
-
c.superclass.
|
46
|
-
c.db.
|
47
|
-
c.table_name.
|
45
|
+
c.superclass.must_equal Sequel::Model
|
46
|
+
c.db.must_equal @db
|
47
|
+
c.table_name.must_equal :boo
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should return a model subclass with the given dataset if given a dataset using an SQL::Identifier" do
|
51
51
|
ds = @db[Sequel.identifier(:blah)]
|
52
52
|
c = Sequel::Model(ds)
|
53
|
-
c.superclass.
|
54
|
-
c.dataset.
|
53
|
+
c.superclass.must_equal Sequel::Model
|
54
|
+
c.dataset.must_equal ds
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should return a model subclass associated to the given database if given a database" do
|
58
58
|
db = Sequel.mock
|
59
59
|
c = Sequel::Model(db)
|
60
|
-
c.superclass.
|
61
|
-
c.db.
|
62
|
-
proc{c.dataset}.
|
60
|
+
c.superclass.must_equal Sequel::Model
|
61
|
+
c.db.must_equal db
|
62
|
+
proc{c.dataset}.must_raise(Sequel::Error)
|
63
63
|
class SmBlahTest < c
|
64
64
|
end
|
65
|
-
SmBlahTest.db.
|
66
|
-
SmBlahTest.table_name.
|
65
|
+
SmBlahTest.db.must_equal db
|
66
|
+
SmBlahTest.table_name.must_equal :sm_blah_tests
|
67
67
|
end
|
68
68
|
|
69
69
|
describe "reloading" do
|
@@ -76,59 +76,43 @@ describe "Sequel::Model()" do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should work without raising an exception with a symbol" do
|
79
|
-
|
80
|
-
|
81
|
-
class ::Album < Sequel::Model(:table); end
|
82
|
-
end.should_not raise_error
|
79
|
+
class ::Album < Sequel::Model(:table); end
|
80
|
+
class ::Album < Sequel::Model(:table); end
|
83
81
|
end
|
84
82
|
|
85
83
|
it "should work without raising an exception with an SQL::Identifier " do
|
86
|
-
|
87
|
-
|
88
|
-
class ::Album < Sequel::Model(Sequel.identifier(:table)); end
|
89
|
-
end.should_not raise_error
|
84
|
+
class ::Album < Sequel::Model(Sequel.identifier(:table)); end
|
85
|
+
class ::Album < Sequel::Model(Sequel.identifier(:table)); end
|
90
86
|
end
|
91
87
|
|
92
88
|
it "should work without raising an exception with an SQL::QualifiedIdentifier " do
|
93
|
-
|
94
|
-
|
95
|
-
class ::Album < Sequel::Model(Sequel.qualify(:schema, :table)); end
|
96
|
-
end.should_not raise_error
|
89
|
+
class ::Album < Sequel::Model(Sequel.qualify(:schema, :table)); end
|
90
|
+
class ::Album < Sequel::Model(Sequel.qualify(:schema, :table)); end
|
97
91
|
end
|
98
92
|
|
99
93
|
it "should work without raising an exception with an SQL::AliasedExpression" do
|
100
|
-
|
101
|
-
|
102
|
-
class ::Album < Sequel::Model(Sequel.as(:table, :alias)); end
|
103
|
-
end.should_not raise_error
|
94
|
+
class ::Album < Sequel::Model(Sequel.as(:table, :alias)); end
|
95
|
+
class ::Album < Sequel::Model(Sequel.as(:table, :alias)); end
|
104
96
|
end
|
105
97
|
|
106
98
|
it "should work without raising an exception with an LiteralString" do
|
107
|
-
|
108
|
-
|
109
|
-
class ::Album < Sequel::Model(Sequel.lit('table')); end
|
110
|
-
end.should_not raise_error
|
99
|
+
class ::Album < Sequel::Model(Sequel.lit('table')); end
|
100
|
+
class ::Album < Sequel::Model(Sequel.lit('table')); end
|
111
101
|
end
|
112
102
|
|
113
103
|
it "should work without raising an exception with a database" do
|
114
|
-
|
115
|
-
|
116
|
-
class ::Album < Sequel::Model(@db); end
|
117
|
-
end.should_not raise_error
|
104
|
+
class ::Album < Sequel::Model(@db); end
|
105
|
+
class ::Album < Sequel::Model(@db); end
|
118
106
|
end
|
119
107
|
|
120
108
|
it "should work without raising an exception with a dataset" do
|
121
|
-
|
122
|
-
|
123
|
-
class ::Album < Sequel::Model(@db[:table]); end
|
124
|
-
end.should_not raise_error
|
109
|
+
class ::Album < Sequel::Model(@db[:table]); end
|
110
|
+
class ::Album < Sequel::Model(@db[:table]); end
|
125
111
|
end
|
126
112
|
|
127
113
|
it "should work without raising an exception with a dataset with an SQL::Identifier" do
|
128
|
-
|
129
|
-
|
130
|
-
class ::Album < Sequel::Model(@db[Sequel.identifier(:table)]); end
|
131
|
-
end.should_not raise_error
|
114
|
+
class ::Album < Sequel::Model(@db[Sequel.identifier(:table)]); end
|
115
|
+
class ::Album < Sequel::Model(@db[Sequel.identifier(:table)]); end
|
132
116
|
end
|
133
117
|
|
134
118
|
it "should raise an exception if anonymous model caching is disabled" do
|
@@ -136,31 +120,31 @@ describe "Sequel::Model()" do
|
|
136
120
|
proc do
|
137
121
|
class ::Album < Sequel::Model(@db[Sequel.identifier(:table)]); end
|
138
122
|
class ::Album < Sequel::Model(@db[Sequel.identifier(:table)]); end
|
139
|
-
end.
|
123
|
+
end.must_raise TypeError
|
140
124
|
end
|
141
125
|
end
|
142
126
|
end
|
143
127
|
|
144
128
|
describe Sequel::Model do
|
145
129
|
it "should have class method aliased as model" do
|
146
|
-
Sequel::Model.instance_methods.collect{|x| x.to_s}.
|
130
|
+
Sequel::Model.instance_methods.collect{|x| x.to_s}.must_include("model")
|
147
131
|
|
148
132
|
model_a = Class.new(Sequel::Model(:items))
|
149
|
-
model_a.new.model.
|
133
|
+
model_a.new.model.wont_be_nil
|
150
134
|
end
|
151
135
|
|
152
136
|
it "should be associated with a dataset" do
|
153
137
|
model_a = Class.new(Sequel::Model) { set_dataset DB[:as] }
|
154
138
|
|
155
|
-
model_a.dataset.
|
156
|
-
model_a.dataset.opts[:from].
|
139
|
+
model_a.dataset.must_be_kind_of(Sequel::Mock::Dataset)
|
140
|
+
model_a.dataset.opts[:from].must_equal [:as]
|
157
141
|
|
158
142
|
model_b = Class.new(Sequel::Model) { set_dataset DB[:bs] }
|
159
143
|
|
160
|
-
model_b.dataset.
|
161
|
-
model_b.dataset.opts[:from].
|
144
|
+
model_b.dataset.must_be_kind_of(Sequel::Mock::Dataset)
|
145
|
+
model_b.dataset.opts[:from].must_equal [:bs]
|
162
146
|
|
163
|
-
model_a.dataset.opts[:from].
|
147
|
+
model_a.dataset.opts[:from].must_equal [:as]
|
164
148
|
end
|
165
149
|
end
|
166
150
|
|
@@ -170,71 +154,71 @@ describe Sequel::Model do
|
|
170
154
|
end
|
171
155
|
|
172
156
|
it "has table_name return name of table" do
|
173
|
-
@model.table_name.
|
157
|
+
@model.table_name.must_equal :items
|
174
158
|
end
|
175
159
|
|
176
160
|
it "defaults to primary key of id" do
|
177
|
-
@model.primary_key.
|
161
|
+
@model.primary_key.must_equal :id
|
178
162
|
end
|
179
163
|
|
180
164
|
it "allow primary key change" do
|
181
165
|
@model.set_primary_key :ssn
|
182
|
-
@model.primary_key.
|
166
|
+
@model.primary_key.must_equal :ssn
|
183
167
|
end
|
184
168
|
|
185
169
|
it "allows dataset change" do
|
186
170
|
@model.set_dataset(DB[:foo])
|
187
|
-
@model.table_name.
|
171
|
+
@model.table_name.must_equal :foo
|
188
172
|
end
|
189
173
|
|
190
174
|
it "allows set_dataset to accept a Symbol" do
|
191
175
|
@model.db = DB
|
192
176
|
@model.set_dataset(:foo)
|
193
|
-
@model.table_name.
|
177
|
+
@model.table_name.must_equal :foo
|
194
178
|
end
|
195
179
|
|
196
180
|
it "allows set_dataset to accept a LiteralString" do
|
197
181
|
@model.db = DB
|
198
182
|
@model.set_dataset(Sequel.lit('foo'))
|
199
|
-
@model.table_name.
|
183
|
+
@model.table_name.must_equal Sequel.lit('foo')
|
200
184
|
end
|
201
185
|
|
202
186
|
it "allows set_dataset to acceptan SQL::Identifier" do
|
203
187
|
@model.db = DB
|
204
188
|
@model.set_dataset(Sequel.identifier(:foo))
|
205
|
-
@model.table_name.
|
189
|
+
@model.table_name.must_equal Sequel.identifier(:foo)
|
206
190
|
end
|
207
191
|
|
208
192
|
it "allows set_dataset to acceptan SQL::QualifiedIdentifier" do
|
209
193
|
@model.db = DB
|
210
194
|
@model.set_dataset(Sequel.qualify(:bar, :foo))
|
211
|
-
@model.table_name.
|
195
|
+
@model.table_name.must_equal Sequel.qualify(:bar, :foo)
|
212
196
|
end
|
213
197
|
|
214
198
|
it "allows set_dataset to acceptan SQL::AliasedExpression" do
|
215
199
|
@model.db = DB
|
216
200
|
@model.set_dataset(Sequel.as(:foo, :bar))
|
217
|
-
@model.table_name.
|
201
|
+
@model.table_name.must_equal :bar
|
218
202
|
end
|
219
203
|
|
220
204
|
it "table_name should respect table aliases" do
|
221
205
|
@model.set_dataset(:foo___x)
|
222
|
-
@model.table_name.
|
206
|
+
@model.table_name.must_equal :x
|
223
207
|
end
|
224
208
|
|
225
209
|
it "set_dataset should raise an error unless given a Symbol or Dataset" do
|
226
|
-
proc{@model.set_dataset(Object.new)}.
|
210
|
+
proc{@model.set_dataset(Object.new)}.must_raise(Sequel::Error)
|
227
211
|
end
|
228
212
|
|
229
213
|
it "set_dataset should add the destroy method to the dataset that destroys each object" do
|
230
214
|
ds = DB[:foo]
|
231
|
-
ds.
|
215
|
+
ds.wont_respond_to(:destroy)
|
232
216
|
@model.set_dataset(ds)
|
233
|
-
ds.
|
217
|
+
ds.must_respond_to(:destroy)
|
234
218
|
DB.sqls
|
235
219
|
ds._fetch = [{:id=>1}, {:id=>2}]
|
236
|
-
ds.destroy.
|
237
|
-
DB.sqls.
|
220
|
+
ds.destroy.must_equal 2
|
221
|
+
DB.sqls.must_equal ["SELECT * FROM foo", "DELETE FROM foo WHERE id = 1", "DELETE FROM foo WHERE id = 2"]
|
238
222
|
end
|
239
223
|
|
240
224
|
it "set_dataset should add the destroy method that respects sharding with transactions" do
|
@@ -243,34 +227,40 @@ describe Sequel::Model do
|
|
243
227
|
@model.use_transactions = true
|
244
228
|
@model.set_dataset(ds)
|
245
229
|
db.sqls
|
246
|
-
ds.destroy.
|
247
|
-
db.sqls.
|
230
|
+
ds.destroy.must_equal 0
|
231
|
+
db.sqls.must_equal ["BEGIN -- s1", "SELECT * FROM foo -- s1", "COMMIT -- s1"]
|
248
232
|
end
|
249
233
|
|
250
234
|
it "should raise an error on set_dataset if there is an error connecting to the database" do
|
251
235
|
def @model.columns() raise Sequel::DatabaseConnectionError end
|
252
|
-
proc{@model.set_dataset(Sequel::Database.new[:foo].join(:blah))}.
|
236
|
+
proc{@model.set_dataset(Sequel::Database.new[:foo].join(:blah))}.must_raise Sequel::DatabaseConnectionError
|
253
237
|
end
|
254
238
|
|
255
239
|
it "should not raise an error if there is a problem getting the columns for a dataset" do
|
256
240
|
def @model.columns() raise Sequel::Error end
|
257
|
-
|
241
|
+
@model.set_dataset(DB[:foo].join(:blah))
|
258
242
|
end
|
259
243
|
|
260
244
|
it "doesn't raise an error on set_dataset if there is an error raised getting the schema" do
|
261
245
|
def @model.get_db_schema(*) raise Sequel::Error end
|
262
|
-
|
246
|
+
@model.set_dataset(DB[:foo])
|
247
|
+
end
|
248
|
+
|
249
|
+
it "reload_db_schema? should be false by default" do
|
250
|
+
c = Class.new
|
251
|
+
c.extend Sequel::Model::ClassMethods
|
252
|
+
c.send(:reload_db_schema?).must_equal false
|
263
253
|
end
|
264
254
|
|
265
255
|
it "doesn't raise an error on inherited if there is an error setting the dataset" do
|
266
256
|
def @model.set_dataset(*) raise Sequel::Error end
|
267
|
-
|
257
|
+
Class.new(@model)
|
268
258
|
end
|
269
259
|
|
270
260
|
it "should raise if bad inherited instance variable value is used" do
|
271
261
|
def @model.inherited_instance_variables() super.merge(:@a=>:foo) end
|
272
262
|
@model.instance_eval{@a=1}
|
273
|
-
proc{Class.new(@model)}.
|
263
|
+
proc{Class.new(@model)}.must_raise(Sequel::Error)
|
274
264
|
end
|
275
265
|
|
276
266
|
it "copy inherited instance variables into subclass if set" do
|
@@ -279,10 +269,10 @@ describe Sequel::Model do
|
|
279
269
|
m = Class.new(@model)
|
280
270
|
@model.instance_eval{@a=5; @b << 6; @c[3] << 7; @c[8] = [9]; @d=40}
|
281
271
|
m.instance_eval do
|
282
|
-
@a.
|
283
|
-
@b.
|
284
|
-
@c.
|
285
|
-
@d.
|
272
|
+
@a.must_equal 1
|
273
|
+
@b.must_equal [2]
|
274
|
+
@c.must_equal(3=>[4])
|
275
|
+
@d.must_equal 20
|
286
276
|
end
|
287
277
|
end
|
288
278
|
end
|
@@ -295,38 +285,38 @@ describe Sequel::Model, "constructors" do
|
|
295
285
|
|
296
286
|
it "should accept a hash" do
|
297
287
|
m = @m.new(:a => 1, :b => 2)
|
298
|
-
m.values.
|
299
|
-
m.
|
288
|
+
m.values.must_equal(:a => 1, :b => 2)
|
289
|
+
m.must_be :new?
|
300
290
|
end
|
301
291
|
|
302
292
|
it "should accept a block and yield itself to the block" do
|
303
293
|
block_called = false
|
304
|
-
m = @m.new {|i| block_called = true; i.
|
294
|
+
m = @m.new {|i| block_called = true; i.must_be_kind_of(@m); i.values[:a] = 1}
|
305
295
|
|
306
|
-
block_called.
|
307
|
-
m.values[:a].
|
296
|
+
block_called.must_equal true
|
297
|
+
m.values[:a].must_equal 1
|
308
298
|
end
|
309
299
|
|
310
300
|
it "should have dataset row_proc create an existing object" do
|
311
301
|
@m.dataset = Sequel.mock.dataset
|
312
302
|
o = @m.dataset.row_proc.call(:a=>1)
|
313
|
-
o.
|
314
|
-
o.values.
|
315
|
-
o.new?.
|
303
|
+
o.must_be_kind_of(@m)
|
304
|
+
o.values.must_equal(:a=>1)
|
305
|
+
o.new?.must_equal false
|
316
306
|
end
|
317
307
|
|
318
308
|
it "should have .call create an existing object" do
|
319
309
|
o = @m.call(:a=>1)
|
320
|
-
o.
|
321
|
-
o.values.
|
322
|
-
o.new?.
|
310
|
+
o.must_be_kind_of(@m)
|
311
|
+
o.values.must_equal(:a=>1)
|
312
|
+
o.new?.must_equal false
|
323
313
|
end
|
324
314
|
|
325
315
|
it "should have .load create an existing object" do
|
326
316
|
o = @m.load(:a=>1)
|
327
|
-
o.
|
328
|
-
o.values.
|
329
|
-
o.new?.
|
317
|
+
o.must_be_kind_of(@m)
|
318
|
+
o.values.must_equal(:a=>1)
|
319
|
+
o.new?.must_equal false
|
330
320
|
end
|
331
321
|
end
|
332
322
|
|
@@ -340,14 +330,14 @@ describe Sequel::Model, "new" do
|
|
340
330
|
|
341
331
|
it "should be marked as new?" do
|
342
332
|
o = @m.new
|
343
|
-
o.
|
333
|
+
o.must_be :new?
|
344
334
|
end
|
345
335
|
|
346
336
|
it "should not be marked as new? once it is saved" do
|
347
337
|
o = @m.new(:x => 1)
|
348
|
-
o.
|
338
|
+
o.must_be :new?
|
349
339
|
o.save
|
350
|
-
o.
|
340
|
+
o.wont_be :new?
|
351
341
|
end
|
352
342
|
|
353
343
|
it "should use the last inserted id as primary key if not in values" do
|
@@ -356,11 +346,11 @@ describe Sequel::Model, "new" do
|
|
356
346
|
|
357
347
|
o = @m.new(:x => 1)
|
358
348
|
o.save
|
359
|
-
o.id.
|
349
|
+
o.id.must_equal 1234
|
360
350
|
|
361
351
|
o = @m.load(:x => 1, :id => 333)
|
362
352
|
o.save
|
363
|
-
o.id.
|
353
|
+
o.id.must_equal 333
|
364
354
|
end
|
365
355
|
end
|
366
356
|
|
@@ -370,27 +360,27 @@ describe Sequel::Model, ".subset" do
|
|
370
360
|
DB.reset
|
371
361
|
end
|
372
362
|
|
373
|
-
|
374
|
-
proc {@c.new_only}.
|
363
|
+
it "should create a filter on the underlying dataset" do
|
364
|
+
proc {@c.new_only}.must_raise(NoMethodError)
|
375
365
|
|
376
366
|
@c.subset(:new_only){age < 'new'}
|
377
367
|
|
378
|
-
@c.new_only.sql.
|
379
|
-
@c.dataset.new_only.sql.
|
368
|
+
@c.new_only.sql.must_equal "SELECT * FROM items WHERE (age < 'new')"
|
369
|
+
@c.dataset.new_only.sql.must_equal "SELECT * FROM items WHERE (age < 'new')"
|
380
370
|
|
381
371
|
@c.subset(:pricey){price > 100}
|
382
372
|
|
383
|
-
@c.pricey.sql.
|
384
|
-
@c.dataset.pricey.sql.
|
373
|
+
@c.pricey.sql.must_equal "SELECT * FROM items WHERE (price > 100)"
|
374
|
+
@c.dataset.pricey.sql.must_equal "SELECT * FROM items WHERE (price > 100)"
|
385
375
|
|
386
|
-
@c.pricey.new_only.sql.
|
387
|
-
@c.new_only.pricey.sql.
|
376
|
+
@c.pricey.new_only.sql.must_equal "SELECT * FROM items WHERE ((price > 100) AND (age < 'new'))"
|
377
|
+
@c.new_only.pricey.sql.must_equal "SELECT * FROM items WHERE ((age < 'new') AND (price > 100))"
|
388
378
|
end
|
389
379
|
|
390
|
-
|
380
|
+
it "should not override existing model methods" do
|
391
381
|
def @c.active() true end
|
392
382
|
@c.subset(:active, :active)
|
393
|
-
@c.active.
|
383
|
+
@c.active.must_equal true
|
394
384
|
end
|
395
385
|
end
|
396
386
|
|
@@ -402,19 +392,19 @@ describe Sequel::Model, ".find" do
|
|
402
392
|
end
|
403
393
|
|
404
394
|
it "should return the first record matching the given filter" do
|
405
|
-
@c.find(:name => 'sharon').
|
406
|
-
DB.sqls.
|
395
|
+
@c.find(:name => 'sharon').must_be_kind_of(@c)
|
396
|
+
DB.sqls.must_equal ["SELECT * FROM items WHERE (name = 'sharon') LIMIT 1"]
|
407
397
|
|
408
|
-
@c.find(Sequel.expr(:name).like('abc%')).
|
409
|
-
DB.sqls.
|
398
|
+
@c.find(Sequel.expr(:name).like('abc%')).must_be_kind_of(@c)
|
399
|
+
DB.sqls.must_equal ["SELECT * FROM items WHERE (name LIKE 'abc%' ESCAPE '\\') LIMIT 1"]
|
410
400
|
end
|
411
401
|
|
412
|
-
|
413
|
-
@c.find{id > 1}.
|
414
|
-
DB.sqls.
|
402
|
+
it "should accept filter blocks" do
|
403
|
+
@c.find{id > 1}.must_be_kind_of(@c)
|
404
|
+
DB.sqls.must_equal ["SELECT * FROM items WHERE (id > 1) LIMIT 1"]
|
415
405
|
|
416
|
-
@c.find{(x > 1) & (y < 2)}.
|
417
|
-
DB.sqls.
|
406
|
+
@c.find{(x > 1) & (y < 2)}.must_be_kind_of(@c)
|
407
|
+
DB.sqls.must_equal ["SELECT * FROM items WHERE ((x > 1) AND (y < 2)) LIMIT 1"]
|
418
408
|
end
|
419
409
|
end
|
420
410
|
|
@@ -432,71 +422,71 @@ describe Sequel::Model, ".finder" do
|
|
432
422
|
@db.sqls
|
433
423
|
end
|
434
424
|
|
435
|
-
|
425
|
+
it "should create a method that calls the method given and returns the first instance" do
|
436
426
|
@c.finder :foo
|
437
|
-
@c.first_foo(1, 2).
|
438
|
-
@c.first_foo(3, 4).
|
439
|
-
@db.sqls.
|
427
|
+
@c.first_foo(1, 2).must_equal @o
|
428
|
+
@c.first_foo(3, 4).must_equal @o
|
429
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
|
440
430
|
end
|
441
431
|
|
442
|
-
|
432
|
+
it "should work correctly when subclassing" do
|
443
433
|
@c.finder(:foo)
|
444
434
|
@sc = Class.new(@c)
|
445
435
|
@sc.set_dataset :foos
|
446
436
|
@db.sqls
|
447
|
-
@sc.first_foo(1, 2).
|
448
|
-
@sc.first_foo(3, 4).
|
449
|
-
@db.sqls.
|
437
|
+
@sc.first_foo(1, 2).must_equal @sc.load(@h)
|
438
|
+
@sc.first_foo(3, 4).must_equal @sc.load(@h)
|
439
|
+
@db.sqls.must_equal ["SELECT * FROM foos WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
|
450
440
|
end
|
451
441
|
|
452
|
-
|
442
|
+
it "should work correctly when dataset is modified" do
|
453
443
|
@c.finder(:foo)
|
454
|
-
@c.first_foo(1, 2).
|
444
|
+
@c.first_foo(1, 2).must_equal @o
|
455
445
|
@c.set_dataset :foos
|
456
|
-
@c.first_foo(3, 4).
|
457
|
-
@db.sqls.
|
446
|
+
@c.first_foo(3, 4).must_equal @o
|
447
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM foos LIMIT 1", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
|
458
448
|
end
|
459
449
|
|
460
|
-
|
450
|
+
it "should create a method based on the given block if no method symbol provided" do
|
461
451
|
@c.finder(:name=>:first_foo){|pl, ds| ds.where(pl.arg).limit(1)}
|
462
|
-
@c.first_foo(:id=>1).
|
463
|
-
@db.sqls.
|
452
|
+
@c.first_foo(:id=>1).must_equal @o
|
453
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1) LIMIT 1"]
|
464
454
|
end
|
465
455
|
|
466
|
-
|
467
|
-
proc{@c.finder(:foo, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.
|
456
|
+
it "should raise an error if both a block and method symbol given" do
|
457
|
+
proc{@c.finder(:foo, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.must_raise(Sequel::Error)
|
468
458
|
end
|
469
459
|
|
470
|
-
|
471
|
-
proc{@c.finder({:name2=>:foo}, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.
|
460
|
+
it "should raise an error if two option hashes are provided" do
|
461
|
+
proc{@c.finder({:name2=>:foo}, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.must_raise(Sequel::Error)
|
472
462
|
end
|
473
463
|
|
474
|
-
|
464
|
+
it "should support :type option" do
|
475
465
|
@c.finder :foo, :type=>:all
|
476
466
|
@c.finder :foo, :type=>:each
|
477
467
|
@c.finder :foo, :type=>:get
|
478
468
|
|
479
469
|
a = []
|
480
|
-
@c.all_foo(1, 2){|r| a << r}.
|
481
|
-
a.
|
470
|
+
@c.all_foo(1, 2){|r| a << r}.must_equal [@o]
|
471
|
+
a.must_equal [@o]
|
482
472
|
|
483
473
|
a = []
|
484
474
|
@c.each_foo(3, 4){|r| a << r}
|
485
|
-
a.
|
475
|
+
a.must_equal [@o]
|
486
476
|
|
487
|
-
@c.get_foo(5, 6).
|
477
|
+
@c.get_foo(5, 6).must_equal [:id, 1]
|
488
478
|
|
489
|
-
@db.sqls.
|
479
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4", "SELECT * FROM items WHERE (bar = 5) ORDER BY 6 LIMIT 1"]
|
490
480
|
end
|
491
481
|
|
492
|
-
|
482
|
+
it "should support :name option" do
|
493
483
|
@c.finder :foo, :name=>:find_foo
|
494
|
-
@c.find_foo(1, 2).
|
495
|
-
@c.find_foo(3, 4).
|
496
|
-
@db.sqls.
|
484
|
+
@c.find_foo(1, 2).must_equal @o
|
485
|
+
@c.find_foo(3, 4).must_equal @o
|
486
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
|
497
487
|
end
|
498
488
|
|
499
|
-
|
489
|
+
it "should support :arity option" do
|
500
490
|
def @c.foobar(*b)
|
501
491
|
ds = dataset
|
502
492
|
b.each_with_index do |a, i|
|
@@ -508,23 +498,23 @@ describe Sequel::Model, ".finder" do
|
|
508
498
|
@c.finder :foobar, :arity=>2, :name=>:find_foobar_2
|
509
499
|
@c.find_foobar_1(:a)
|
510
500
|
@c.find_foobar_2(:a, :b)
|
511
|
-
@db.sqls.
|
501
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (0 = a) LIMIT 1", "SELECT * FROM items WHERE ((0 = a) AND (1 = b)) LIMIT 1"]
|
512
502
|
end
|
513
503
|
|
514
|
-
|
504
|
+
it "should support :mod option" do
|
515
505
|
m = Module.new
|
516
506
|
@c.finder :foo, :mod=>m
|
517
|
-
proc{@c.first_foo}.
|
507
|
+
proc{@c.first_foo}.must_raise NoMethodError
|
518
508
|
@c.extend m
|
519
|
-
@c.first_foo(1, 2).
|
520
|
-
@c.first_foo(3, 4).
|
521
|
-
@db.sqls.
|
509
|
+
@c.first_foo(1, 2).must_equal @o
|
510
|
+
@c.first_foo(3, 4).must_equal @o
|
511
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
|
522
512
|
end
|
523
513
|
|
524
|
-
|
514
|
+
it "should raise error when calling with the wrong arity" do
|
525
515
|
@c.finder :foo
|
526
|
-
proc{@c.first_foo(1)}.
|
527
|
-
proc{@c.first_foo(1,2,3)}.
|
516
|
+
proc{@c.first_foo(1)}.must_raise Sequel::Error
|
517
|
+
proc{@c.first_foo(1,2,3)}.must_raise Sequel::Error
|
528
518
|
end
|
529
519
|
end
|
530
520
|
|
@@ -549,68 +539,68 @@ describe Sequel::Model, ".prepared_finder" do
|
|
549
539
|
@db.sqls
|
550
540
|
end
|
551
541
|
|
552
|
-
|
542
|
+
it "should create a method that calls the method given and returns the first instance" do
|
553
543
|
@c.prepared_finder :foo
|
554
|
-
@c.first_foo(1, 2).
|
555
|
-
@c.first_foo(3, 4).
|
556
|
-
@db.sqls.
|
544
|
+
@c.first_foo(1, 2).must_equal @o
|
545
|
+
@c.first_foo(3, 4).must_equal @o
|
546
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
|
557
547
|
end
|
558
548
|
|
559
|
-
|
549
|
+
it "should work correctly when subclassing" do
|
560
550
|
@c.prepared_finder(:foo)
|
561
551
|
@sc = Class.new(@c)
|
562
552
|
@sc.set_dataset :foos
|
563
553
|
@db.sqls
|
564
|
-
@sc.first_foo(1, 2).
|
565
|
-
@sc.first_foo(3, 4).
|
566
|
-
@db.sqls.
|
554
|
+
@sc.first_foo(1, 2).must_equal @sc.load(@h)
|
555
|
+
@sc.first_foo(3, 4).must_equal @sc.load(@h)
|
556
|
+
@db.sqls.must_equal ["SELECT * FROM foos WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
|
567
557
|
end
|
568
558
|
|
569
|
-
|
559
|
+
it "should work correctly when dataset is modified" do
|
570
560
|
@c.prepared_finder(:foo)
|
571
|
-
@c.first_foo(1, 2).
|
561
|
+
@c.first_foo(1, 2).must_equal @o
|
572
562
|
@c.set_dataset :foos
|
573
|
-
@c.first_foo(3, 4).
|
574
|
-
@db.sqls.
|
563
|
+
@c.first_foo(3, 4).must_equal @o
|
564
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM foos LIMIT 1", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
|
575
565
|
end
|
576
566
|
|
577
|
-
|
567
|
+
it "should create a method based on the given block if no method symbol provided" do
|
578
568
|
@c.prepared_finder(:name=>:first_foo){|a1| where(:id=>a1).limit(1)}
|
579
|
-
@c.first_foo(1).
|
580
|
-
@db.sqls.
|
569
|
+
@c.first_foo(1).must_equal @o
|
570
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1) LIMIT 1 -- prepared"]
|
581
571
|
end
|
582
572
|
|
583
|
-
|
584
|
-
proc{@c.prepared_finder(:foo, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.
|
573
|
+
it "should raise an error if both a block and method symbol given" do
|
574
|
+
proc{@c.prepared_finder(:foo, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.must_raise(Sequel::Error)
|
585
575
|
end
|
586
576
|
|
587
|
-
|
588
|
-
proc{@c.prepared_finder({:name2=>:foo}, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.
|
577
|
+
it "should raise an error if two option hashes are provided" do
|
578
|
+
proc{@c.prepared_finder({:name2=>:foo}, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.must_raise(Sequel::Error)
|
589
579
|
end
|
590
580
|
|
591
|
-
|
581
|
+
it "should support :type option" do
|
592
582
|
@c.prepared_finder :foo, :type=>:all
|
593
583
|
@c.prepared_finder :foo, :type=>:each
|
594
584
|
|
595
585
|
a = []
|
596
|
-
@c.all_foo(1, 2){|r| a << r}.
|
597
|
-
a.
|
586
|
+
@c.all_foo(1, 2){|r| a << r}.must_equal [@o]
|
587
|
+
a.must_equal [@o]
|
598
588
|
|
599
589
|
a = []
|
600
590
|
@c.each_foo(3, 4){|r| a << r}
|
601
|
-
a.
|
591
|
+
a.must_equal [@o]
|
602
592
|
|
603
|
-
@db.sqls.
|
593
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 -- prepared"]
|
604
594
|
end
|
605
595
|
|
606
|
-
|
596
|
+
it "should support :name option" do
|
607
597
|
@c.prepared_finder :foo, :name=>:find_foo
|
608
|
-
@c.find_foo(1, 2).
|
609
|
-
@c.find_foo(3, 4).
|
610
|
-
@db.sqls.
|
598
|
+
@c.find_foo(1, 2).must_equal @o
|
599
|
+
@c.find_foo(3, 4).must_equal @o
|
600
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
|
611
601
|
end
|
612
602
|
|
613
|
-
|
603
|
+
it "should support :arity option" do
|
614
604
|
def @c.foobar(*b)
|
615
605
|
ds = dataset
|
616
606
|
b.each_with_index do |a, i|
|
@@ -622,24 +612,24 @@ describe Sequel::Model, ".prepared_finder" do
|
|
622
612
|
@c.prepared_finder :foobar, :arity=>2, :name=>:find_foobar_2
|
623
613
|
@c.find_foobar_1(:a)
|
624
614
|
@c.find_foobar_2(:a, :b)
|
625
|
-
@db.sqls.
|
615
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (0 = a) LIMIT 1 -- prepared", "SELECT * FROM items WHERE ((0 = a) AND (1 = b)) LIMIT 1 -- prepared"]
|
626
616
|
end
|
627
617
|
|
628
|
-
|
618
|
+
it "should support :mod option" do
|
629
619
|
m = Module.new
|
630
620
|
@c.prepared_finder :foo, :mod=>m
|
631
|
-
proc{@c.first_foo}.
|
621
|
+
proc{@c.first_foo}.must_raise NoMethodError
|
632
622
|
@c.extend m
|
633
|
-
@c.first_foo(1, 2).
|
634
|
-
@c.first_foo(3, 4).
|
635
|
-
@db.sqls.
|
623
|
+
@c.first_foo(1, 2).must_equal @o
|
624
|
+
@c.first_foo(3, 4).must_equal @o
|
625
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
|
636
626
|
end
|
637
627
|
|
638
|
-
|
628
|
+
it "should handle models with names" do
|
639
629
|
def @c.name; 'foobar' end
|
640
630
|
@c.prepared_finder :foo
|
641
|
-
@c.first_foo(1, 2).
|
642
|
-
@db.sqls.
|
631
|
+
@c.first_foo(1, 2).must_equal @o
|
632
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared"]
|
643
633
|
end
|
644
634
|
end
|
645
635
|
|
@@ -650,13 +640,13 @@ describe Sequel::Model, ".fetch" do
|
|
650
640
|
end
|
651
641
|
|
652
642
|
it "should return instances of Model" do
|
653
|
-
@c.fetch("SELECT * FROM items").first.
|
643
|
+
@c.fetch("SELECT * FROM items").first.must_be_kind_of(@c)
|
654
644
|
end
|
655
645
|
|
656
646
|
it "should return true for .empty? and not raise an error on empty selection" do
|
657
647
|
rows = @c.fetch("SELECT * FROM items WHERE FALSE")
|
658
648
|
@c.send(:define_method, :fetch_rows){|sql| yield({:count => 0})}
|
659
|
-
|
649
|
+
rows.empty?
|
660
650
|
end
|
661
651
|
end
|
662
652
|
|
@@ -673,15 +663,15 @@ describe Sequel::Model, ".find_or_create" do
|
|
673
663
|
it "should find the record" do
|
674
664
|
@db.fetch = [{:x=>1, :id=>1}]
|
675
665
|
@db.autoid = 1
|
676
|
-
@c.find_or_create(:x => 1).
|
677
|
-
@db.sqls.
|
666
|
+
@c.find_or_create(:x => 1).must_equal @c.load(:x=>1, :id=>1)
|
667
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (x = 1) LIMIT 1"]
|
678
668
|
end
|
679
669
|
|
680
670
|
it "should create the record if not found" do
|
681
671
|
@db.fetch = [[], {:x=>1, :id=>1}]
|
682
672
|
@db.autoid = 1
|
683
|
-
@c.find_or_create(:x => 1).
|
684
|
-
@db.sqls.
|
673
|
+
@c.find_or_create(:x => 1).must_equal @c.load(:x=>1, :id=>1)
|
674
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (x = 1) LIMIT 1",
|
685
675
|
"INSERT INTO items (x) VALUES (1)",
|
686
676
|
"SELECT * FROM items WHERE (id = 1) LIMIT 1"]
|
687
677
|
end
|
@@ -689,18 +679,18 @@ describe Sequel::Model, ".find_or_create" do
|
|
689
679
|
it "should pass the new record to be created to the block if no record is found" do
|
690
680
|
@db.fetch = [[], {:x=>1, :id=>1}]
|
691
681
|
@db.autoid = 1
|
692
|
-
@c.find_or_create(:x => 1){|x| x[:y] = 2}.
|
682
|
+
@c.find_or_create(:x => 1){|x| x[:y] = 2}.must_equal @c.load(:x=>1, :id=>1)
|
693
683
|
sqls = @db.sqls
|
694
|
-
sqls.first.
|
695
|
-
["INSERT INTO items (x, y) VALUES (1, 2)", "INSERT INTO items (y, x) VALUES (2, 1)"].
|
696
|
-
sqls.last.
|
684
|
+
sqls.first.must_equal "SELECT * FROM items WHERE (x = 1) LIMIT 1"
|
685
|
+
["INSERT INTO items (x, y) VALUES (1, 2)", "INSERT INTO items (y, x) VALUES (2, 1)"].must_include(sqls[1])
|
686
|
+
sqls.last.must_equal "SELECT * FROM items WHERE (id = 1) LIMIT 1"
|
697
687
|
end
|
698
688
|
end
|
699
689
|
|
700
690
|
describe Sequel::Model, ".all" do
|
701
691
|
it "should return all records in the dataset" do
|
702
692
|
c = Class.new(Sequel::Model(:items))
|
703
|
-
c.all.
|
693
|
+
c.all.must_equal [c.load(:x=>1, :id=>1)]
|
704
694
|
end
|
705
695
|
end
|
706
696
|
|
@@ -715,26 +705,26 @@ describe Sequel::Model, "A model class without a primary key" do
|
|
715
705
|
|
716
706
|
it "should be able to insert records without selecting them back" do
|
717
707
|
i = nil
|
718
|
-
|
719
|
-
i.class.
|
720
|
-
i.values.to_hash.
|
708
|
+
i = @c.create(:x => 1)
|
709
|
+
i.class.wont_be_nil
|
710
|
+
i.values.to_hash.must_equal(:x => 1)
|
721
711
|
|
722
|
-
DB.sqls.
|
712
|
+
DB.sqls.must_equal ['INSERT INTO items (x) VALUES (1)']
|
723
713
|
end
|
724
714
|
|
725
715
|
it "should raise when deleting" do
|
726
|
-
proc{@c.load(:x=>1).delete}.
|
716
|
+
proc{@c.load(:x=>1).delete}.must_raise Sequel::Error
|
727
717
|
end
|
728
718
|
|
729
719
|
it "should raise when updating" do
|
730
|
-
proc{@c.load(:x=>1).update(:x=>2)}.
|
720
|
+
proc{@c.load(:x=>1).update(:x=>2)}.must_raise Sequel::Error
|
731
721
|
end
|
732
722
|
|
733
723
|
it "should insert a record when saving" do
|
734
724
|
o = @c.new(:x => 2)
|
735
|
-
o.
|
725
|
+
o.must_be :new?
|
736
726
|
o.save
|
737
|
-
DB.sqls.
|
727
|
+
DB.sqls.must_equal ['INSERT INTO items (x) VALUES (2)']
|
738
728
|
end
|
739
729
|
end
|
740
730
|
|
@@ -752,20 +742,20 @@ describe Sequel::Model, "attribute accessors" do
|
|
752
742
|
|
753
743
|
it "should be created on set_dataset" do
|
754
744
|
%w'x z x= z='.each do |x|
|
755
|
-
@c.instance_methods.collect{|z| z.to_s}.
|
745
|
+
@c.instance_methods.collect{|z| z.to_s}.wont_include(x)
|
756
746
|
end
|
757
747
|
@c.set_dataset(@dataset)
|
758
748
|
%w'x z x= z='.each do |x|
|
759
|
-
@c.instance_methods.collect{|z| z.to_s}.
|
749
|
+
@c.instance_methods.collect{|z| z.to_s}.must_include(x)
|
760
750
|
end
|
761
751
|
o = @c.new
|
762
752
|
%w'x z x= z='.each do |x|
|
763
|
-
o.methods.collect{|z| z.to_s}.
|
753
|
+
o.methods.collect{|z| z.to_s}.must_include(x)
|
764
754
|
end
|
765
755
|
|
766
|
-
o.x.
|
756
|
+
o.x.must_equal nil
|
767
757
|
o.x = 34
|
768
|
-
o.x.
|
758
|
+
o.x.must_equal 34
|
769
759
|
end
|
770
760
|
|
771
761
|
it "should be only accept one argument for the write accessor" do
|
@@ -773,9 +763,9 @@ describe Sequel::Model, "attribute accessors" do
|
|
773
763
|
o = @c.new
|
774
764
|
|
775
765
|
o.x = 34
|
776
|
-
o.x.
|
777
|
-
proc{o.send(:x=)}.
|
778
|
-
proc{o.send(:x=, 3, 4)}.
|
766
|
+
o.x.must_equal 34
|
767
|
+
proc{o.send(:x=)}.must_raise ArgumentError
|
768
|
+
proc{o.send(:x=, 3, 4)}.must_raise ArgumentError
|
779
769
|
end
|
780
770
|
|
781
771
|
it "should have a working typecasting setter even if the column is not selected" do
|
@@ -783,7 +773,7 @@ describe Sequel::Model, "attribute accessors" do
|
|
783
773
|
o = @c.new
|
784
774
|
|
785
775
|
o.x = '34'
|
786
|
-
o.x.
|
776
|
+
o.x.must_equal 34
|
787
777
|
end
|
788
778
|
|
789
779
|
it "should typecast if the new value is the same as the existing but has a different class" do
|
@@ -792,9 +782,9 @@ describe Sequel::Model, "attribute accessors" do
|
|
792
782
|
|
793
783
|
o.x = 34
|
794
784
|
o.x = 34.0
|
795
|
-
o.x.
|
785
|
+
o.x.must_equal 34.0
|
796
786
|
o.x = 34
|
797
|
-
o.x.
|
787
|
+
o.x.must_equal 34
|
798
788
|
end
|
799
789
|
end
|
800
790
|
|
@@ -806,42 +796,42 @@ describe Sequel::Model, ".[]" do
|
|
806
796
|
end
|
807
797
|
|
808
798
|
it "should return the first record for the given pk" do
|
809
|
-
@c[1].
|
810
|
-
DB.sqls.
|
811
|
-
@c[9999].
|
812
|
-
DB.sqls.
|
799
|
+
@c[1].must_equal @c.load(:name => 'sharon', :id => 1)
|
800
|
+
DB.sqls.must_equal ["SELECT * FROM items WHERE id = 1"]
|
801
|
+
@c[9999].must_equal @c.load(:name => 'sharon', :id => 1)
|
802
|
+
DB.sqls.must_equal ["SELECT * FROM items WHERE id = 9999"]
|
813
803
|
end
|
814
804
|
|
815
805
|
it "should have #[] return nil if no rows match" do
|
816
806
|
@c.dataset._fetch = []
|
817
|
-
@c[1].
|
818
|
-
DB.sqls.
|
807
|
+
@c[1].must_equal nil
|
808
|
+
DB.sqls.must_equal ["SELECT * FROM items WHERE id = 1"]
|
819
809
|
end
|
820
810
|
|
821
811
|
it "should work correctly for custom primary key" do
|
822
812
|
@c.set_primary_key :name
|
823
|
-
@c['sharon'].
|
824
|
-
DB.sqls.
|
813
|
+
@c['sharon'].must_equal @c.load(:name => 'sharon', :id => 1)
|
814
|
+
DB.sqls.must_equal ["SELECT * FROM items WHERE name = 'sharon'"]
|
825
815
|
end
|
826
816
|
|
827
817
|
it "should use a qualified primary key if the dataset is joined" do
|
828
818
|
@c.dataset = @c.dataset.cross_join(:a)
|
829
|
-
@c[1].
|
830
|
-
DB.sqls.
|
819
|
+
@c[1].must_equal @c.load(:name => 'sharon', :id => 1)
|
820
|
+
DB.sqls.must_equal ["SELECT * FROM items CROSS JOIN a WHERE (items.id = 1) LIMIT 1"]
|
831
821
|
end
|
832
822
|
|
833
823
|
it "should work correctly for composite primary key specified as array" do
|
834
824
|
@c.set_primary_key [:node_id, :kind]
|
835
|
-
@c[3921, 201].
|
825
|
+
@c[3921, 201].must_be_kind_of(@c)
|
836
826
|
sqls = DB.sqls
|
837
|
-
sqls.length.
|
838
|
-
sqls.first.
|
827
|
+
sqls.length.must_equal 1
|
828
|
+
sqls.first.must_match(/^SELECT \* FROM items WHERE \((\(node_id = 3921\) AND \(kind = 201\))|(\(kind = 201\) AND \(node_id = 3921\))\) LIMIT 1$/)
|
839
829
|
end
|
840
830
|
end
|
841
831
|
|
842
832
|
describe "Model#inspect" do
|
843
|
-
|
844
|
-
Sequel::Model.load(:x => 333).inspect.
|
833
|
+
it "should include the class name and the values" do
|
834
|
+
Sequel::Model.load(:x => 333).inspect.must_equal '#<Sequel::Model @values={:x=>333}>'
|
845
835
|
end
|
846
836
|
end
|
847
837
|
|
@@ -855,7 +845,7 @@ describe "Model.db_schema" do
|
|
855
845
|
@dataset = @db[:items]
|
856
846
|
end
|
857
847
|
|
858
|
-
|
848
|
+
it "should not call database's schema if it isn't supported" do
|
859
849
|
def @db.supports_schema_parsing?() false end
|
860
850
|
def @db.schema(table, opts = {})
|
861
851
|
raise Sequel::Error
|
@@ -863,105 +853,105 @@ describe "Model.db_schema" do
|
|
863
853
|
@dataset.instance_variable_set(:@columns, [:x, :y])
|
864
854
|
|
865
855
|
@c.dataset = @dataset
|
866
|
-
@c.db_schema.
|
867
|
-
@c.columns.
|
868
|
-
@c.dataset.instance_variable_get(:@columns).
|
856
|
+
@c.db_schema.must_equal(:x=>{}, :y=>{})
|
857
|
+
@c.columns.must_equal [:x, :y]
|
858
|
+
@c.dataset.instance_variable_get(:@columns).must_equal [:x, :y]
|
869
859
|
end
|
870
860
|
|
871
|
-
|
861
|
+
it "should use the database's schema and set the columns and dataset columns" do
|
872
862
|
def @db.schema(table, opts = {})
|
873
863
|
[[:x, {:type=>:integer}], [:y, {:type=>:string}]]
|
874
864
|
end
|
875
865
|
@c.dataset = @dataset
|
876
|
-
@c.db_schema.
|
877
|
-
@c.columns.
|
878
|
-
@c.dataset.instance_variable_get(:@columns).
|
866
|
+
@c.db_schema.must_equal(:x=>{:type=>:integer}, :y=>{:type=>:string})
|
867
|
+
@c.columns.must_equal [:x, :y]
|
868
|
+
@c.dataset.instance_variable_get(:@columns).must_equal [:x, :y]
|
879
869
|
end
|
880
870
|
|
881
|
-
|
871
|
+
it "should not restrict the schema for datasets with a :select option" do
|
882
872
|
def @c.columns; [:x, :z]; end
|
883
873
|
def @db.schema(table, opts = {})
|
884
874
|
[[:x, {:type=>:integer}], [:y, {:type=>:string}]]
|
885
875
|
end
|
886
876
|
@c.dataset = @dataset.select(:x, :y___z)
|
887
|
-
@c.db_schema.
|
877
|
+
@c.db_schema.must_equal(:x=>{:type=>:integer}, :z=>{}, :y=>{:type=>:string})
|
888
878
|
end
|
889
879
|
|
890
|
-
|
880
|
+
it "should fallback to fetching records if schema raises an error" do
|
891
881
|
def @db.schema(table, opts={})
|
892
882
|
raise Sequel::Error
|
893
883
|
end
|
894
884
|
@c.dataset = @dataset.join(:x, :id).columns(:id, :x)
|
895
|
-
@c.db_schema.
|
885
|
+
@c.db_schema.must_equal(:x=>{}, :id=>{})
|
896
886
|
end
|
897
887
|
|
898
|
-
|
888
|
+
it "should automatically set a singular primary key based on the schema" do
|
899
889
|
ds = @dataset
|
900
890
|
d = ds.db
|
901
891
|
def d.schema(table, *opts) [[:x, {:primary_key=>true}]] end
|
902
|
-
@c.primary_key.
|
892
|
+
@c.primary_key.must_equal :id
|
903
893
|
@c.dataset = ds
|
904
|
-
@c.db_schema.
|
905
|
-
@c.primary_key.
|
894
|
+
@c.db_schema.must_equal(:x=>{:primary_key=>true})
|
895
|
+
@c.primary_key.must_equal :x
|
906
896
|
end
|
907
897
|
|
908
|
-
|
898
|
+
it "should automatically set a singular primary key even if there are specific columns selected" do
|
909
899
|
ds = @dataset.select(:a, :b, :x)
|
910
900
|
d = ds.db
|
911
901
|
def d.schema(table, *opts) [[:a, {:primary_key=>false}], [:b, {:primary_key=>false}], [:x, {:primary_key=>true}]] end
|
912
|
-
@c.primary_key.
|
902
|
+
@c.primary_key.must_equal :id
|
913
903
|
@c.dataset = ds
|
914
|
-
@c.db_schema.
|
915
|
-
@c.primary_key.
|
904
|
+
@c.db_schema.must_equal(:a=>{:primary_key=>false}, :b=>{:primary_key=>false}, :x=>{:primary_key=>true})
|
905
|
+
@c.primary_key.must_equal :x
|
916
906
|
end
|
917
907
|
|
918
|
-
|
908
|
+
it "should automatically set the composite primary key based on the schema" do
|
919
909
|
ds = @dataset
|
920
910
|
d = ds.db
|
921
911
|
def d.schema(table, *opts) [[:x, {:primary_key=>true}], [:y, {:primary_key=>true}]] end
|
922
|
-
@c.primary_key.
|
912
|
+
@c.primary_key.must_equal :id
|
923
913
|
@c.dataset = ds
|
924
|
-
@c.db_schema.
|
925
|
-
@c.primary_key.
|
914
|
+
@c.db_schema.must_equal(:x=>{:primary_key=>true}, :y=>{:primary_key=>true})
|
915
|
+
@c.primary_key.must_equal [:x, :y]
|
926
916
|
end
|
927
917
|
|
928
|
-
|
918
|
+
it "should set an immutable composite primary key based on the schema" do
|
929
919
|
ds = @dataset
|
930
920
|
d = ds.db
|
931
921
|
def d.schema(table, *opts) [[:x, {:primary_key=>true}], [:y, {:primary_key=>true}]] end
|
932
922
|
@c.dataset = ds
|
933
|
-
@c.primary_key.
|
934
|
-
proc{@c.primary_key.pop}.
|
923
|
+
@c.primary_key.must_equal [:x, :y]
|
924
|
+
proc{@c.primary_key.pop}.must_raise
|
935
925
|
end
|
936
926
|
|
937
|
-
|
927
|
+
it "should automatically set no primary key based on the schema" do
|
938
928
|
ds = @dataset
|
939
929
|
d = ds.db
|
940
930
|
def d.schema(table, *opts) [[:x, {:primary_key=>false}], [:y, {:primary_key=>false}]] end
|
941
|
-
@c.primary_key.
|
931
|
+
@c.primary_key.must_equal :id
|
942
932
|
@c.dataset = ds
|
943
|
-
@c.db_schema.
|
944
|
-
@c.primary_key.
|
933
|
+
@c.db_schema.must_equal(:x=>{:primary_key=>false}, :y=>{:primary_key=>false})
|
934
|
+
@c.primary_key.must_equal nil
|
945
935
|
end
|
946
936
|
|
947
|
-
|
937
|
+
it "should automatically set primary key for dataset selecting table.*" do
|
948
938
|
ds = @dataset.select_all(:items)
|
949
939
|
d = ds.db
|
950
940
|
def d.schema(table, *opts) [[:x, {:primary_key=>true}]] end
|
951
|
-
@c.primary_key.
|
941
|
+
@c.primary_key.must_equal :id
|
952
942
|
@c.dataset = ds
|
953
|
-
@c.db_schema.
|
954
|
-
@c.primary_key.
|
943
|
+
@c.db_schema.must_equal(:x=>{:primary_key=>true})
|
944
|
+
@c.primary_key.must_equal :x
|
955
945
|
end
|
956
946
|
|
957
|
-
|
947
|
+
it "should not modify the primary key unless all column schema hashes have a :primary_key entry" do
|
958
948
|
ds = @dataset
|
959
949
|
d = ds.db
|
960
950
|
def d.schema(table, *opts) [[:x, {:primary_key=>false}], [:y, {}]] end
|
961
|
-
@c.primary_key.
|
951
|
+
@c.primary_key.must_equal :id
|
962
952
|
@c.dataset = ds
|
963
|
-
@c.db_schema.
|
964
|
-
@c.primary_key.
|
953
|
+
@c.db_schema.must_equal(:x=>{:primary_key=>false}, :y=>{})
|
954
|
+
@c.primary_key.must_equal :id
|
965
955
|
end
|
966
956
|
end
|
967
957
|
|
@@ -970,23 +960,23 @@ describe "Model#use_transactions" do
|
|
970
960
|
@c = Class.new(Sequel::Model(:items))
|
971
961
|
end
|
972
962
|
|
973
|
-
|
963
|
+
it "should return class value by default" do
|
974
964
|
@c.use_transactions = true
|
975
|
-
@c.new.use_transactions.
|
965
|
+
@c.new.use_transactions.must_equal true
|
976
966
|
@c.use_transactions = false
|
977
|
-
@c.new.use_transactions.
|
967
|
+
@c.new.use_transactions.must_equal false
|
978
968
|
end
|
979
969
|
|
980
|
-
|
970
|
+
it "should return set value if manually set" do
|
981
971
|
instance = @c.new
|
982
972
|
instance.use_transactions = false
|
983
|
-
instance.use_transactions.
|
973
|
+
instance.use_transactions.must_equal false
|
984
974
|
@c.use_transactions = true
|
985
|
-
instance.use_transactions.
|
975
|
+
instance.use_transactions.must_equal false
|
986
976
|
|
987
977
|
instance.use_transactions = true
|
988
|
-
instance.use_transactions.
|
978
|
+
instance.use_transactions.must_equal true
|
989
979
|
@c.use_transactions = false
|
990
|
-
instance.use_transactions.
|
980
|
+
instance.use_transactions.must_equal true
|
991
981
|
end
|
992
982
|
end
|