sequel 2.12.0 → 3.0.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.
- data/CHANGELOG +62 -0
- data/README.rdoc +3 -3
- data/Rakefile +7 -0
- data/doc/advanced_associations.rdoc +44 -0
- data/doc/release_notes/3.0.0.txt +221 -0
- data/lib/sequel/adapters/amalgalite.rb +208 -0
- data/lib/sequel/adapters/db2.rb +3 -0
- data/lib/sequel/adapters/dbi.rb +9 -0
- data/lib/sequel/adapters/do.rb +0 -4
- data/lib/sequel/adapters/firebird.rb +16 -18
- data/lib/sequel/adapters/informix.rb +5 -3
- data/lib/sequel/adapters/jdbc.rb +24 -20
- data/lib/sequel/adapters/jdbc/h2.rb +15 -4
- data/lib/sequel/adapters/mysql.rb +4 -8
- data/lib/sequel/adapters/odbc.rb +0 -4
- data/lib/sequel/adapters/oracle.rb +0 -4
- data/lib/sequel/adapters/shared/mssql.rb +16 -5
- data/lib/sequel/adapters/shared/mysql.rb +87 -86
- data/lib/sequel/adapters/shared/oracle.rb +92 -3
- data/lib/sequel/adapters/shared/postgres.rb +85 -29
- data/lib/sequel/adapters/shared/progress.rb +8 -3
- data/lib/sequel/adapters/shared/sqlite.rb +53 -23
- data/lib/sequel/adapters/sqlite.rb +4 -7
- data/lib/sequel/adapters/utils/unsupported.rb +3 -3
- data/lib/sequel/connection_pool.rb +18 -25
- data/lib/sequel/core.rb +2 -21
- data/lib/sequel/database.rb +60 -44
- data/lib/sequel/database/schema_generator.rb +26 -31
- data/lib/sequel/database/schema_methods.rb +8 -3
- data/lib/sequel/database/schema_sql.rb +114 -28
- data/lib/sequel/dataset.rb +14 -41
- data/lib/sequel/dataset/convenience.rb +31 -54
- data/lib/sequel/dataset/graph.rb +7 -13
- data/lib/sequel/dataset/sql.rb +43 -54
- data/lib/sequel/extensions/inflector.rb +0 -5
- data/lib/sequel/extensions/schema_dumper.rb +238 -0
- data/lib/sequel/metaprogramming.rb +0 -20
- data/lib/sequel/model.rb +1 -2
- data/lib/sequel/model/base.rb +18 -16
- data/lib/sequel/model/inflections.rb +6 -9
- data/lib/sequel/plugins/caching.rb +0 -6
- data/lib/sequel/plugins/hook_class_methods.rb +1 -1
- data/lib/sequel/sql.rb +2 -0
- data/lib/sequel/version.rb +2 -2
- data/spec/adapters/firebird_spec.rb +35 -8
- data/spec/adapters/mysql_spec.rb +173 -266
- data/spec/adapters/oracle_spec.rb +13 -0
- data/spec/adapters/postgres_spec.rb +127 -227
- data/spec/adapters/sqlite_spec.rb +13 -171
- data/spec/core/connection_pool_spec.rb +15 -4
- data/spec/core/core_sql_spec.rb +14 -170
- data/spec/core/database_spec.rb +50 -132
- data/spec/core/dataset_spec.rb +47 -930
- data/spec/core/expression_filters_spec.rb +12 -0
- data/spec/core/schema_generator_spec.rb +37 -45
- data/spec/core/schema_spec.rb +26 -16
- data/spec/core/spec_helper.rb +0 -25
- data/spec/extensions/inflector_spec.rb +0 -3
- data/spec/extensions/schema_dumper_spec.rb +292 -0
- data/spec/extensions/serialization_spec.rb +9 -0
- data/spec/extensions/single_table_inheritance_spec.rb +6 -1
- data/spec/extensions/spec_helper.rb +1 -3
- data/spec/extensions/validation_helpers_spec.rb +4 -4
- data/spec/integration/database_test.rb +18 -0
- data/spec/integration/dataset_test.rb +112 -1
- data/spec/integration/eager_loader_test.rb +70 -9
- data/spec/integration/prepared_statement_test.rb +2 -2
- data/spec/integration/schema_test.rb +76 -27
- data/spec/integration/spec_helper.rb +0 -14
- data/spec/integration/transaction_test.rb +27 -0
- data/spec/model/associations_spec.rb +0 -36
- data/spec/model/base_spec.rb +18 -123
- data/spec/model/hooks_spec.rb +2 -235
- data/spec/model/inflector_spec.rb +15 -115
- data/spec/model/model_spec.rb +0 -120
- data/spec/model/plugins_spec.rb +0 -70
- data/spec/model/record_spec.rb +35 -93
- data/spec/model/spec_helper.rb +0 -27
- data/spec/model/validations_spec.rb +0 -931
- metadata +9 -14
- data/lib/sequel/deprecated.rb +0 -593
- data/lib/sequel/deprecated_migration.rb +0 -91
- data/lib/sequel/model/deprecated.rb +0 -204
- data/lib/sequel/model/deprecated_hooks.rb +0 -103
- data/lib/sequel/model/deprecated_inflector.rb +0 -335
- data/lib/sequel/model/deprecated_validations.rb +0 -388
- data/spec/core/core_ext_spec.rb +0 -156
- data/spec/core/migration_spec.rb +0 -263
- data/spec/core/pretty_table_spec.rb +0 -58
- data/spec/model/caching_spec.rb +0 -217
- data/spec/model/schema_spec.rb +0 -92
@@ -1,126 +1,26 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
|
-
describe
|
4
|
-
deprec_specify "#camelize and #camelcase should transform the word to CamelCase" do
|
5
|
-
"egg_and_hams".camelize.should == "EggAndHams"
|
6
|
-
"egg_and_hams".camelize(false).should == "eggAndHams"
|
7
|
-
"post".camelize.should == "Post"
|
8
|
-
"post".camelcase.should == "Post"
|
9
|
-
end
|
10
|
-
|
11
|
-
deprec_specify "#constantize should eval the string to get a constant" do
|
12
|
-
"String".constantize.should == String
|
13
|
-
"String::Inflections".constantize.should == String::Inflections
|
14
|
-
proc{"BKSDDF".constantize}.should raise_error
|
15
|
-
proc{"++A++".constantize}.should raise_error
|
16
|
-
end
|
17
|
-
|
18
|
-
deprec_specify "#dasherize should transform underscores to dashes" do
|
19
|
-
"egg_and_hams".dasherize.should == "egg-and-hams"
|
20
|
-
"post".dasherize.should == "post"
|
21
|
-
end
|
22
|
-
|
23
|
-
deprec_specify "#demodulize should remove any preceding modules" do
|
24
|
-
"String::Inflections::Blah".demodulize.should == "Blah"
|
25
|
-
"String::Inflections".demodulize.should == "Inflections"
|
26
|
-
"String".demodulize.should == "String"
|
27
|
-
end
|
28
|
-
|
29
|
-
deprec_specify "#humanize should remove _i, transform underscore to spaces, and capitalize" do
|
30
|
-
"egg_and_hams".humanize.should == "Egg and hams"
|
31
|
-
"post".humanize.should == "Post"
|
32
|
-
"post_id".humanize.should == "Post"
|
33
|
-
end
|
34
|
-
|
35
|
-
deprec_specify "#titleize and #titlecase should underscore, humanize, and capitalize all words" do
|
36
|
-
"egg-and: hams".titleize.should == "Egg And: Hams"
|
37
|
-
"post".titleize.should == "Post"
|
38
|
-
"post".titlecase.should == "Post"
|
39
|
-
end
|
40
|
-
|
41
|
-
deprec_specify "#underscore should add underscores between CamelCased words, change :: to / and - to _, and downcase" do
|
42
|
-
"EggAndHams".underscore.should == "egg_and_hams"
|
43
|
-
"EGGAndHams".underscore.should == "egg_and_hams"
|
44
|
-
"Egg::And::Hams".underscore.should == "egg/and/hams"
|
45
|
-
"post".underscore.should == "post"
|
46
|
-
"post-id".underscore.should == "post_id"
|
47
|
-
end
|
48
|
-
|
49
|
-
deprec_specify "#pluralize should transform words from singular to plural" do
|
50
|
-
"post".pluralize.should == "posts"
|
51
|
-
"octopus".pluralize.should =="octopi"
|
52
|
-
"the blue mailman".pluralize.should == "the blue mailmen"
|
53
|
-
"CamelOctopus".pluralize.should == "CamelOctopi"
|
54
|
-
end
|
55
|
-
|
56
|
-
deprec_specify "#singularize should transform words from plural to singular" do
|
57
|
-
"posts".singularize.should == "post"
|
58
|
-
"octopi".singularize.should == "octopus"
|
59
|
-
"the blue mailmen".singularize.should == "the blue mailman"
|
60
|
-
"CamelOctopi".singularize.should == "CamelOctopus"
|
61
|
-
end
|
62
|
-
|
63
|
-
deprec_specify "#tableize should transform class names to table names" do
|
64
|
-
"RawScaledScorer".tableize.should == "raw_scaled_scorers"
|
65
|
-
"egg_and_ham".tableize.should == "egg_and_hams"
|
66
|
-
"fancyCategory".tableize.should == "fancy_categories"
|
67
|
-
end
|
68
|
-
|
69
|
-
deprec_specify "#classify should tranform table names to class names" do
|
70
|
-
"egg_and_hams".classify.should == "EggAndHam"
|
71
|
-
"post".classify.should == "Post"
|
72
|
-
end
|
73
|
-
|
74
|
-
deprec_specify "#foreign_key should create a foreign key name from a class name" do
|
75
|
-
"Message".foreign_key.should == "message_id"
|
76
|
-
"Message".foreign_key(false).should == "messageid"
|
77
|
-
"Admin::Post".foreign_key.should == "post_id"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe String::Inflections do
|
3
|
+
describe Sequel::Inflections do
|
82
4
|
before do
|
83
|
-
|
84
|
-
@plurals, @singulars, @uncountables = String.inflections.plurals.dup, String.inflections.singulars.dup, String.inflections.uncountables.dup
|
85
|
-
end
|
5
|
+
@plurals, @singulars, @uncountables = Sequel.inflections.plurals.dup, Sequel.inflections.singulars.dup, Sequel.inflections.uncountables.dup
|
86
6
|
end
|
87
7
|
after do
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
String.inflections.uncountables.replace(@uncountables)
|
92
|
-
Sequel.inflections.plurals.replace(@plurals)
|
93
|
-
Sequel.inflections.singulars.replace(@singulars)
|
94
|
-
Sequel.inflections.uncountables.replace(@uncountables)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
deprec_specify "should be possible to clear the list of singulars, plurals, and uncountables" do
|
99
|
-
String.inflections.clear(:plurals)
|
100
|
-
String.inflections.plurals.should == []
|
101
|
-
String.inflections.plural('blah', 'blahs')
|
102
|
-
String.inflections.clear
|
103
|
-
String.inflections.plurals.should == []
|
104
|
-
String.inflections.singulars.should == []
|
105
|
-
String.inflections.uncountables.should == []
|
8
|
+
Sequel.inflections.plurals.replace(@plurals)
|
9
|
+
Sequel.inflections.singulars.replace(@singulars)
|
10
|
+
Sequel.inflections.uncountables.replace(@uncountables)
|
106
11
|
end
|
107
12
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
'rottt'.singularize.should == 'rott'
|
117
|
-
'yy'.pluralize.should == 'yyy'
|
118
|
-
'yyy'.singularize.should == 'yy'
|
119
|
-
'zz'.pluralize.should == 'zz'
|
120
|
-
'zz'.singularize.should == 'zz'
|
13
|
+
it "should be possible to clear the list of singulars, plurals, and uncountables" do
|
14
|
+
Sequel.inflections.clear(:plurals)
|
15
|
+
Sequel.inflections.plurals.should == []
|
16
|
+
Sequel.inflections.plural('blah', 'blahs')
|
17
|
+
Sequel.inflections.clear
|
18
|
+
Sequel.inflections.plurals.should == []
|
19
|
+
Sequel.inflections.singulars.should == []
|
20
|
+
Sequel.inflections.uncountables.should == []
|
121
21
|
end
|
122
22
|
|
123
|
-
|
124
|
-
|
23
|
+
it "should be yielded and returned by Sequel.inflections" do
|
24
|
+
Sequel.inflections{|i| i.should == Sequel::Inflections}.should == Sequel::Inflections
|
125
25
|
end
|
126
26
|
end
|
data/spec/model/model_spec.rb
CHANGED
@@ -64,22 +64,6 @@ describe Sequel::Model, "dataset & schema" do
|
|
64
64
|
ds.should respond_to(:destroy)
|
65
65
|
end
|
66
66
|
|
67
|
-
deprec_specify "sets schema with implicit table name" do
|
68
|
-
@model.set_schema do
|
69
|
-
primary_key :ssn, :string
|
70
|
-
end
|
71
|
-
@model.primary_key.should == :ssn
|
72
|
-
@model.table_name.should == :items
|
73
|
-
end
|
74
|
-
|
75
|
-
deprec_specify "sets schema with explicit table name" do
|
76
|
-
@model.set_schema :foo do
|
77
|
-
primary_key :id
|
78
|
-
end
|
79
|
-
@model.primary_key.should == :id
|
80
|
-
@model.table_name.should == :foo
|
81
|
-
end
|
82
|
-
|
83
67
|
it "doesn't raise an error on set_dataset if there is an error raised getting the schema" do
|
84
68
|
@model.meta_def(:get_db_schema){raise Sequel::Error}
|
85
69
|
proc{@model.set_dataset(MODEL_DB[:foo])}.should_not raise_error
|
@@ -91,60 +75,6 @@ describe Sequel::Model, "dataset & schema" do
|
|
91
75
|
end
|
92
76
|
end
|
93
77
|
|
94
|
-
describe Sequel::Model, "#sti_key" do
|
95
|
-
before do
|
96
|
-
deprec do
|
97
|
-
class ::StiTest < Sequel::Model
|
98
|
-
def kind=(x); self[:kind] = x; end
|
99
|
-
def refresh; end
|
100
|
-
set_sti_key :kind
|
101
|
-
end
|
102
|
-
end
|
103
|
-
class ::StiTestSub1 < StiTest
|
104
|
-
end
|
105
|
-
class ::StiTestSub2 < StiTest
|
106
|
-
end
|
107
|
-
@ds = StiTest.dataset
|
108
|
-
MODEL_DB.reset
|
109
|
-
end
|
110
|
-
|
111
|
-
deprec_specify "should return rows with the correct class based on the polymorphic_key value" do
|
112
|
-
def @ds.fetch_rows(sql)
|
113
|
-
yield({:kind=>'StiTest'})
|
114
|
-
yield({:kind=>'StiTestSub1'})
|
115
|
-
yield({:kind=>'StiTestSub2'})
|
116
|
-
end
|
117
|
-
StiTest.all.collect{|x| x.class}.should == [StiTest, StiTestSub1, StiTestSub2]
|
118
|
-
end
|
119
|
-
|
120
|
-
deprec_specify "should fallback to the main class if polymophic_key value is NULL" do
|
121
|
-
def @ds.fetch_rows(sql)
|
122
|
-
yield({:kind=>nil})
|
123
|
-
end
|
124
|
-
StiTest.all.collect{|x| x.class}.should == [StiTest]
|
125
|
-
end
|
126
|
-
|
127
|
-
deprec_specify "should fallback to the main class if the given class does not exist" do
|
128
|
-
def @ds.fetch_rows(sql)
|
129
|
-
yield({:kind=>'StiTestSub3'})
|
130
|
-
end
|
131
|
-
StiTest.all.collect{|x| x.class}.should == [StiTest]
|
132
|
-
end
|
133
|
-
|
134
|
-
deprec_specify "should add a before_create hook that sets the model class name for the key" do
|
135
|
-
StiTest.new.save
|
136
|
-
StiTestSub1.new.save
|
137
|
-
StiTestSub2.new.save
|
138
|
-
MODEL_DB.sqls.should == ["INSERT INTO sti_tests (kind) VALUES ('StiTest')", "INSERT INTO sti_tests (kind) VALUES ('StiTestSub1')", "INSERT INTO sti_tests (kind) VALUES ('StiTestSub2')"]
|
139
|
-
end
|
140
|
-
|
141
|
-
deprec_specify "should add a filter to model datasets inside subclasses hook to only retreive objects with the matching key" do
|
142
|
-
StiTest.dataset.sql.should == "SELECT * FROM sti_tests"
|
143
|
-
StiTestSub1.dataset.sql.should == "SELECT * FROM sti_tests WHERE (kind = 'StiTestSub1')"
|
144
|
-
StiTestSub2.dataset.sql.should == "SELECT * FROM sti_tests WHERE (kind = 'StiTestSub2')"
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
78
|
describe Sequel::Model, "constructor" do
|
149
79
|
|
150
80
|
before(:each) do
|
@@ -327,47 +257,6 @@ describe Sequel::Model, ".find_or_create" do
|
|
327
257
|
end
|
328
258
|
end
|
329
259
|
|
330
|
-
describe Sequel::Model, ".delete_all" do
|
331
|
-
|
332
|
-
before(:each) do
|
333
|
-
MODEL_DB.reset
|
334
|
-
@c = Class.new(Sequel::Model(:items)) do
|
335
|
-
no_primary_key
|
336
|
-
end
|
337
|
-
|
338
|
-
@c.dataset.meta_def(:delete) {MODEL_DB << delete_sql}
|
339
|
-
end
|
340
|
-
|
341
|
-
deprec_specify "should delete all records in the dataset" do
|
342
|
-
@c.delete_all
|
343
|
-
MODEL_DB.sqls.should == ["DELETE FROM items"]
|
344
|
-
end
|
345
|
-
|
346
|
-
end
|
347
|
-
|
348
|
-
describe Sequel::Model, ".destroy_all" do
|
349
|
-
|
350
|
-
before(:each) do
|
351
|
-
MODEL_DB.reset
|
352
|
-
@c = Class.new(Sequel::Model(:items)) do
|
353
|
-
no_primary_key
|
354
|
-
end
|
355
|
-
|
356
|
-
@c.dataset.meta_def(:delete) {MODEL_DB << delete_sql}
|
357
|
-
end
|
358
|
-
|
359
|
-
deprec_specify "should delete all records in the dataset" do
|
360
|
-
@c.dataset.meta_def(:destroy) {MODEL_DB << "DESTROY this stuff"}
|
361
|
-
@c.destroy_all
|
362
|
-
MODEL_DB.sqls.should == ["DESTROY this stuff"]
|
363
|
-
end
|
364
|
-
|
365
|
-
deprec_specify "should call dataset.destroy" do
|
366
|
-
@c.dataset.should_receive(:destroy).and_return(true)
|
367
|
-
@c.destroy_all
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
260
|
describe Sequel::Model, ".all" do
|
372
261
|
|
373
262
|
before(:each) do
|
@@ -582,12 +471,3 @@ context "Model.db_schema" do
|
|
582
471
|
@c.db_schema.should == {:x=>{}}
|
583
472
|
end
|
584
473
|
end
|
585
|
-
|
586
|
-
context "Model.str_columns" do
|
587
|
-
deprec_specify "should return the columns as frozen strings" do
|
588
|
-
c = Class.new(Sequel::Model)
|
589
|
-
c.meta_def(:columns){[:a, :b]}
|
590
|
-
c.orig_str_columns.should == %w'a b'
|
591
|
-
proc{c.orig_str_columns.first << 'a'}.should raise_error
|
592
|
-
end
|
593
|
-
end
|
data/spec/model/plugins_spec.rb
CHANGED
@@ -69,74 +69,4 @@ describe Sequel::Model, "using a plugin" do
|
|
69
69
|
c.should respond_to(:ghi)
|
70
70
|
c.ghi.should == {:a => 1, :b => 2}
|
71
71
|
end
|
72
|
-
|
73
|
-
deprec_specify "should have an .is alias" do
|
74
|
-
c = nil
|
75
|
-
proc do
|
76
|
-
c = Class.new(Sequel::Model)
|
77
|
-
c.class_eval do
|
78
|
-
set_dataset MODEL_DB[:items]
|
79
|
-
is :timestamped, :a => 1, :b => 2
|
80
|
-
end
|
81
|
-
end.should_not raise_error(LoadError)
|
82
|
-
|
83
|
-
c.should respond_to(:stamp_opts)
|
84
|
-
c.stamp_opts.should == {:a => 1, :b => 2}
|
85
|
-
|
86
|
-
# instance methods
|
87
|
-
m = c.new
|
88
|
-
m.should respond_to(:get_stamp)
|
89
|
-
m.should respond_to(:abc)
|
90
|
-
m.abc.should == {:a => 1, :b => 2}
|
91
|
-
t = Time.now
|
92
|
-
m[:stamp] = t
|
93
|
-
m.get_stamp.should == t
|
94
|
-
|
95
|
-
# class methods
|
96
|
-
c.should respond_to(:deff)
|
97
|
-
c.deff.should == {:a => 1, :b => 2}
|
98
|
-
|
99
|
-
# dataset methods
|
100
|
-
c.dataset.should respond_to(:ghi)
|
101
|
-
c.dataset.ghi.should == {:a => 1, :b => 2}
|
102
|
-
|
103
|
-
# dataset methods called on the class
|
104
|
-
c.should respond_to(:ghi)
|
105
|
-
c.ghi.should == {:a => 1, :b => 2}
|
106
|
-
end
|
107
|
-
|
108
|
-
deprec_specify "should have an .is_a alias" do
|
109
|
-
c = nil
|
110
|
-
proc do
|
111
|
-
c = Class.new(Sequel::Model)
|
112
|
-
c.class_eval do
|
113
|
-
set_dataset MODEL_DB[:items]
|
114
|
-
is_a :timestamped, :a => 1, :b => 2
|
115
|
-
end
|
116
|
-
end.should_not raise_error(LoadError)
|
117
|
-
|
118
|
-
c.should respond_to(:stamp_opts)
|
119
|
-
c.stamp_opts.should == {:a => 1, :b => 2}
|
120
|
-
|
121
|
-
# instance methods
|
122
|
-
m = c.new
|
123
|
-
m.should respond_to(:get_stamp)
|
124
|
-
m.should respond_to(:abc)
|
125
|
-
m.abc.should == {:a => 1, :b => 2}
|
126
|
-
t = Time.now
|
127
|
-
m[:stamp] = t
|
128
|
-
m.get_stamp.should == t
|
129
|
-
|
130
|
-
# class methods
|
131
|
-
c.should respond_to(:deff)
|
132
|
-
c.deff.should == {:a => 1, :b => 2}
|
133
|
-
|
134
|
-
# dataset methods
|
135
|
-
c.dataset.should respond_to(:ghi)
|
136
|
-
c.dataset.ghi.should == {:a => 1, :b => 2}
|
137
|
-
|
138
|
-
# dataset methods called on the class
|
139
|
-
c.should respond_to(:ghi)
|
140
|
-
c.ghi.should == {:a => 1, :b => 2}
|
141
|
-
end
|
142
72
|
end
|
data/spec/model/record_spec.rb
CHANGED
@@ -1,5 +1,39 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
2
|
|
3
|
+
describe "Model#save server use" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@c = Class.new(Sequel::Model(:items)) do
|
7
|
+
columns :id, :x, :y
|
8
|
+
end
|
9
|
+
@c.db = MockDatabase.new
|
10
|
+
db2 = @db2 = MockDatabase.new
|
11
|
+
@c.class_eval do
|
12
|
+
define_method(:after_save) do
|
13
|
+
model.db = db2
|
14
|
+
ds = model.dataset
|
15
|
+
def ds.fetch_rows(sql)
|
16
|
+
yield @db.execute(sql, @opts[:server])
|
17
|
+
end
|
18
|
+
@this = nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should use the :default server if the model doesn't have one already specified" do
|
24
|
+
@c.db.should_receive(:execute).with("INSERT INTO items (x) VALUES (1)").and_return(10)
|
25
|
+
@db2.should_receive(:execute).with('SELECT * FROM items WHERE (id = 10) LIMIT 1', :default).and_return(:x=>1, :id=>10)
|
26
|
+
@c.new(:x=>1).save
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should use the model's server if the model has one already specified" do
|
30
|
+
@c.dataset = @c.dataset.server(:blah)
|
31
|
+
@c.db.should_receive(:execute).with("INSERT INTO items (x) VALUES (1)").and_return(10)
|
32
|
+
@db2.should_receive(:execute).with('SELECT * FROM items WHERE (id = 10) LIMIT 1', :blah).and_return(:x=>1, :id=>10)
|
33
|
+
@c.new(:x=>1).save
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
3
37
|
describe "Model#save" do
|
4
38
|
|
5
39
|
before(:each) do
|
@@ -228,73 +262,6 @@ describe "Model#save_changes" do
|
|
228
262
|
end
|
229
263
|
end
|
230
264
|
|
231
|
-
describe "Model#update_values" do
|
232
|
-
before(:each) do
|
233
|
-
MODEL_DB.reset
|
234
|
-
|
235
|
-
@c = Class.new(Sequel::Model(:items)) do
|
236
|
-
unrestrict_primary_key
|
237
|
-
columns :id, :x, :y
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
deprec_specify "should generate an update statement" do
|
242
|
-
o = @c.new(:id => 1)
|
243
|
-
o.update_values(:x => 1)
|
244
|
-
MODEL_DB.sqls.first.should == "UPDATE items SET x = 1 WHERE (id = 1)"
|
245
|
-
end
|
246
|
-
|
247
|
-
deprec_specify "should update attribute values" do
|
248
|
-
o = @c.new(:id => 1)
|
249
|
-
o.x.should be_nil
|
250
|
-
o.update_values(:x => 1)
|
251
|
-
o.x.should == 1
|
252
|
-
end
|
253
|
-
|
254
|
-
deprec_specify "should support string keys" do
|
255
|
-
o = @c.new(:id => 1)
|
256
|
-
o.x.should be_nil
|
257
|
-
o.update_values('x' => 1)
|
258
|
-
o.x.should == 1
|
259
|
-
MODEL_DB.sqls.first.should == "UPDATE items SET x = 1 WHERE (id = 1)"
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
describe "Model#set_values" do
|
264
|
-
before(:each) do
|
265
|
-
MODEL_DB.reset
|
266
|
-
|
267
|
-
@c = Class.new(Sequel::Model(:items)) do
|
268
|
-
unrestrict_primary_key
|
269
|
-
columns :id, :x, :y
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
deprec_specify "should not touch the database" do
|
274
|
-
o = @c.new(:id => 1)
|
275
|
-
o.set_values(:x => 1)
|
276
|
-
MODEL_DB.sqls.should == []
|
277
|
-
end
|
278
|
-
|
279
|
-
deprec_specify "should update attribute values" do
|
280
|
-
o = @c.new(:id => 1)
|
281
|
-
o.x.should be_nil
|
282
|
-
o.set_values(:x => 1)
|
283
|
-
o.x.should == 1
|
284
|
-
end
|
285
|
-
|
286
|
-
deprec_specify "should support string keys" do
|
287
|
-
o = @c.new(:id => 1)
|
288
|
-
o.x.should be_nil
|
289
|
-
o.set_values('x' => 1)
|
290
|
-
o.x.should == 1
|
291
|
-
end
|
292
|
-
|
293
|
-
deprec_specify "should raise an error if used with a non-String, non-Symbol key" do
|
294
|
-
proc{@c.new.set_values(1=>2)}.should raise_error(Sequel::Error)
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
265
|
describe "Model#new?" do
|
299
266
|
|
300
267
|
before(:each) do
|
@@ -506,23 +473,11 @@ describe Sequel::Model, "#set" do
|
|
506
473
|
MODEL_DB.sqls.should == []
|
507
474
|
end
|
508
475
|
|
509
|
-
deprec_specify "should be aliased as set_with_params" do
|
510
|
-
@o1.set_with_params(:x => 1, :z => 2)
|
511
|
-
@o1.values.should == {:x => 1}
|
512
|
-
MODEL_DB.sqls.should == []
|
513
|
-
end
|
514
|
-
|
515
476
|
it "should return self" do
|
516
477
|
returned_value = @o1.set(:x => 1, :z => 2)
|
517
478
|
returned_value.should == @o1
|
518
479
|
MODEL_DB.sqls.should == []
|
519
480
|
end
|
520
|
-
|
521
|
-
deprec_specify "should assume it is a column if no column information is present and the key is a symbol" do
|
522
|
-
@c.instance_variable_set(:@columns, nil)
|
523
|
-
o = @c.new.set(:x123=>1)
|
524
|
-
o[:x123].should == 1
|
525
|
-
end
|
526
481
|
end
|
527
482
|
|
528
483
|
describe Sequel::Model, "#update" do
|
@@ -562,11 +517,6 @@ describe Sequel::Model, "#update" do
|
|
562
517
|
@o2.values.should == {:y => 1, :id=> 5}
|
563
518
|
MODEL_DB.sqls.first.should == "UPDATE items SET y = 1 WHERE (id = 5)"
|
564
519
|
end
|
565
|
-
|
566
|
-
deprec_specify "should be aliased as update_with_params" do
|
567
|
-
@o1.update_with_params(:x => 1, :z => 2)
|
568
|
-
MODEL_DB.sqls.first.should == "INSERT INTO items (x) VALUES (1)"
|
569
|
-
end
|
570
520
|
end
|
571
521
|
|
572
522
|
describe Sequel::Model, "#(set|update)_(all|except|only)" do
|
@@ -950,14 +900,6 @@ describe Sequel::Model, "typecasting" do
|
|
950
900
|
m.x.should == '1'
|
951
901
|
end
|
952
902
|
|
953
|
-
deprec_specify "should not convert if serializing the field" do
|
954
|
-
@c.serialize :x
|
955
|
-
@c.instance_variable_set(:@db_schema, {:x=>{:type=>:string}})
|
956
|
-
m = @c.new
|
957
|
-
m.x =[1, 2]
|
958
|
-
m.x.should == [1, 2]
|
959
|
-
end
|
960
|
-
|
961
903
|
specify "should convert to integer for an integer field" do
|
962
904
|
@c.instance_variable_set(:@db_schema, {:x=>{:type=>:integer}})
|
963
905
|
m = @c.new
|
@@ -1065,7 +1007,7 @@ describe Sequel::Model, "typecasting" do
|
|
1065
1007
|
specify "should convert to BigDecimal for a decimal field" do
|
1066
1008
|
@c.instance_variable_set(:@db_schema, {:x=>{:type=>:decimal}})
|
1067
1009
|
m = @c.new
|
1068
|
-
bd = '1.0'
|
1010
|
+
bd = BigDecimal.new('1.0')
|
1069
1011
|
m.x = '1.0'
|
1070
1012
|
m.x.should == bd
|
1071
1013
|
m.x = 1.0
|