sequel 4.42.1 → 4.43.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +35 -1
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -4
- data/doc/release_notes/4.43.0.txt +87 -0
- data/doc/sql.rdoc +26 -27
- data/doc/testing.rdoc +2 -0
- data/doc/validations.rdoc +1 -1
- data/lib/sequel/adapters/ado.rb +5 -0
- data/lib/sequel/adapters/cubrid.rb +5 -0
- data/lib/sequel/adapters/ibmdb.rb +5 -0
- data/lib/sequel/adapters/jdbc.rb +6 -0
- data/lib/sequel/adapters/jdbc/derby.rb +5 -0
- data/lib/sequel/adapters/jdbc/hsqldb.rb +9 -5
- data/lib/sequel/adapters/jdbc/postgresql.rb +1 -1
- data/lib/sequel/adapters/jdbc/sqlite.rb +5 -0
- data/lib/sequel/adapters/jdbc/transactions.rb +5 -0
- data/lib/sequel/adapters/mock.rb +12 -9
- data/lib/sequel/adapters/mysql.rb +6 -0
- data/lib/sequel/adapters/mysql2.rb +7 -2
- data/lib/sequel/adapters/oracle.rb +5 -0
- data/lib/sequel/adapters/shared/db2.rb +7 -1
- data/lib/sequel/adapters/shared/mssql.rb +5 -0
- data/lib/sequel/adapters/shared/mysql.rb +8 -1
- data/lib/sequel/adapters/shared/oracle.rb +20 -12
- data/lib/sequel/adapters/shared/postgres.rb +11 -2
- data/lib/sequel/adapters/shared/sqlanywhere.rb +6 -0
- data/lib/sequel/adapters/shared/sqlite.rb +29 -0
- data/lib/sequel/adapters/sqlanywhere.rb +5 -0
- data/lib/sequel/adapters/sqlite.rb +13 -0
- data/lib/sequel/connection_pool/sharded_single.rb +5 -0
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
- data/lib/sequel/connection_pool/single.rb +15 -6
- data/lib/sequel/database/dataset.rb +3 -0
- data/lib/sequel/database/misc.rb +22 -1
- data/lib/sequel/database/query.rb +2 -4
- data/lib/sequel/dataset/actions.rb +0 -1
- data/lib/sequel/dataset/misc.rb +2 -4
- data/lib/sequel/dataset/query.rb +23 -6
- data/lib/sequel/extensions/_model_constraint_validations.rb +16 -0
- data/lib/sequel/extensions/_model_pg_row.rb +47 -0
- data/lib/sequel/extensions/looser_typecasting.rb +2 -0
- data/lib/sequel/extensions/migration.rb +12 -1
- data/lib/sequel/extensions/pg_array.rb +6 -0
- data/lib/sequel/extensions/pg_enum.rb +2 -1
- data/lib/sequel/extensions/pg_range.rb +6 -0
- data/lib/sequel/extensions/pg_row.rb +8 -0
- data/lib/sequel/model/associations.rb +3 -1
- data/lib/sequel/model/base.rb +14 -3
- data/lib/sequel/plugins/constraint_validations.rb +1 -8
- data/lib/sequel/plugins/instance_filters.rb +1 -1
- data/lib/sequel/plugins/pg_row.rb +1 -40
- data/lib/sequel/plugins/prepared_statements.rb +51 -20
- data/lib/sequel/plugins/prepared_statements_associations.rb +22 -4
- data/lib/sequel/plugins/prepared_statements_with_pk.rb +9 -1
- data/lib/sequel/plugins/sharding.rb +5 -0
- data/lib/sequel/plugins/update_primary_key.rb +1 -1
- data/lib/sequel/version.rb +2 -2
- data/spec/adapters/spec_helper.rb +4 -0
- data/spec/core/connection_pool_spec.rb +10 -0
- data/spec/core/database_spec.rb +29 -0
- data/spec/extensions/blacklist_security_spec.rb +4 -4
- data/spec/extensions/defaults_setter_spec.rb +1 -1
- data/spec/extensions/force_encoding_spec.rb +3 -2
- data/spec/extensions/identifier_mangling_spec.rb +7 -0
- data/spec/extensions/instance_filters_spec.rb +1 -0
- data/spec/extensions/migration_spec.rb +19 -0
- data/spec/extensions/pg_array_spec.rb +5 -0
- data/spec/extensions/pg_range_spec.rb +5 -0
- data/spec/extensions/pg_row_spec.rb +9 -0
- data/spec/extensions/prepared_statements_associations_spec.rb +45 -1
- data/spec/extensions/prepared_statements_spec.rb +138 -41
- data/spec/extensions/prepared_statements_with_pk_spec.rb +7 -0
- data/spec/extensions/serialization_spec.rb +6 -6
- data/spec/extensions/single_table_inheritance_spec.rb +3 -3
- data/spec/extensions/skip_create_refresh_spec.rb +1 -1
- data/spec/integration/associations_test.rb +2 -2
- data/spec/integration/dataset_test.rb +0 -4
- data/spec/integration/eager_loader_test.rb +5 -5
- data/spec/integration/plugin_test.rb +8 -6
- data/spec/integration/schema_test.rb +2 -2
- data/spec/integration/spec_helper.rb +10 -0
- data/spec/integration/timezone_test.rb +1 -1
- data/spec/integration/transaction_test.rb +5 -5
- data/spec/model/associations_spec.rb +13 -6
- data/spec/model/base_spec.rb +1 -1
- data/spec/model/hooks_spec.rb +4 -4
- data/spec/model/model_spec.rb +2 -2
- data/spec/model/record_spec.rb +17 -18
- metadata +6 -2
@@ -94,7 +94,7 @@ describe Sequel::Model, "single table inheritance plugin" do
|
|
94
94
|
StiTest.new.save
|
95
95
|
StiTestSub1.new.save
|
96
96
|
StiTestSub2.new.save
|
97
|
-
DB.sqls.must_equal ["INSERT INTO sti_tests (kind) VALUES ('StiTest')", "SELECT * FROM sti_tests WHERE
|
97
|
+
DB.sqls.must_equal ["INSERT INTO sti_tests (kind) VALUES ('StiTest')", "SELECT * FROM sti_tests WHERE id = 10", "INSERT INTO sti_tests (kind) VALUES ('StiTestSub1')", "SELECT * FROM sti_tests WHERE ((sti_tests.kind IN ('StiTestSub1')) AND (id = 10)) LIMIT 1", "INSERT INTO sti_tests (kind) VALUES ('StiTestSub2')", "SELECT * FROM sti_tests WHERE ((sti_tests.kind IN ('StiTestSub2')) AND (id = 10)) LIMIT 1"]
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should destroy the model correctly" do
|
@@ -119,14 +119,14 @@ describe Sequel::Model, "single table inheritance plugin" do
|
|
119
119
|
|
120
120
|
it "should override an existing value in the class name field" do
|
121
121
|
StiTest.create(:kind=>'StiTestSub1')
|
122
|
-
DB.sqls.must_equal ["INSERT INTO sti_tests (kind) VALUES ('StiTestSub1')", "SELECT * FROM sti_tests WHERE
|
122
|
+
DB.sqls.must_equal ["INSERT INTO sti_tests (kind) VALUES ('StiTestSub1')", "SELECT * FROM sti_tests WHERE id = 10"]
|
123
123
|
end
|
124
124
|
|
125
125
|
it "should handle type column with the same name as existing method names" do
|
126
126
|
StiTest.plugin :single_table_inheritance, :type
|
127
127
|
StiTest.columns :id, :type
|
128
128
|
StiTest.create
|
129
|
-
DB.sqls.must_equal ["INSERT INTO sti_tests (type) VALUES ('StiTest')", "SELECT * FROM sti_tests WHERE
|
129
|
+
DB.sqls.must_equal ["INSERT INTO sti_tests (type) VALUES ('StiTest')", "SELECT * FROM sti_tests WHERE id = 10"]
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should add a filter to model datasets inside subclasses hook to only retreive objects with the matching key" do
|
@@ -7,7 +7,7 @@ describe "Sequel::Plugins::SkipCreateRefresh" do
|
|
7
7
|
c.dataset = c.dataset.with_autoid(2)
|
8
8
|
c.db.reset
|
9
9
|
c.create(:x=>1)
|
10
|
-
c.db.sqls.must_equal ['INSERT INTO a (x) VALUES (1)', 'SELECT * FROM a WHERE
|
10
|
+
c.db.sqls.must_equal ['INSERT INTO a (x) VALUES (1)', 'SELECT * FROM a WHERE id = 2']
|
11
11
|
|
12
12
|
c.dataset = c.dataset.with_autoid(2)
|
13
13
|
c.plugin :skip_create_refresh
|
@@ -2264,7 +2264,7 @@ end
|
|
2264
2264
|
describe "Sequel::Model pg_array_to_many" do
|
2265
2265
|
before(:all) do
|
2266
2266
|
@db = DB
|
2267
|
-
@db.extension :pg_array
|
2267
|
+
@db.extension :pg_array unless @db.frozen?
|
2268
2268
|
Sequel.extension :pg_array_ops
|
2269
2269
|
@db.drop_table?(:tags, :albums, :artists)
|
2270
2270
|
@db.create_table(:artists) do
|
@@ -2345,7 +2345,7 @@ end if DB.database_type == :postgres && [:postgres, :jdbc].include?(DB.adapter_s
|
|
2345
2345
|
describe "Sequel::Model many_to_pg_array" do
|
2346
2346
|
before(:all) do
|
2347
2347
|
@db = DB
|
2348
|
-
@db.extension :pg_array
|
2348
|
+
@db.extension :pg_array unless @db.frozen?
|
2349
2349
|
Sequel.extension :pg_array_ops
|
2350
2350
|
@db.drop_table?(:tags, :albums, :artists)
|
2351
2351
|
@db.create_table(:artists) do
|
@@ -1825,11 +1825,7 @@ end
|
|
1825
1825
|
describe "Dataset replace" do
|
1826
1826
|
before do
|
1827
1827
|
DB.create_table!(:items){Integer :id, :unique=>true; Integer :value}
|
1828
|
-
sqls = []
|
1829
|
-
DB.loggers << Class.new{%w'info error'.each{|m| define_method(m){|sql| sqls << sql}}}.new
|
1830
|
-
|
1831
1828
|
@d = DB[:items]
|
1832
|
-
sqls.clear
|
1833
1829
|
end
|
1834
1830
|
|
1835
1831
|
after do
|
@@ -2,7 +2,7 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
|
|
2
2
|
|
3
3
|
describe "Eagerly loading a tree structure" do
|
4
4
|
before(:all) do
|
5
|
-
DB.
|
5
|
+
DB.instance_variable_get(:@schemas).clear
|
6
6
|
DB.create_table!(:nodes) do
|
7
7
|
primary_key :id
|
8
8
|
foreign_key :parent_id, :nodes
|
@@ -128,7 +128,7 @@ describe "Association Extensions" do
|
|
128
128
|
first(:name=>name) || model.create(:name=>name, :author_id=>model_object.pk)
|
129
129
|
end
|
130
130
|
end
|
131
|
-
DB.
|
131
|
+
DB.instance_variable_get(:@schemas).clear
|
132
132
|
DB.create_table!(:authors) do
|
133
133
|
primary_key :id
|
134
134
|
end
|
@@ -171,7 +171,7 @@ end
|
|
171
171
|
|
172
172
|
describe "has_many :through has_many and has_one :through belongs_to" do
|
173
173
|
before(:all) do
|
174
|
-
DB.
|
174
|
+
DB.instance_variable_get(:@schemas).clear
|
175
175
|
DB.create_table!(:firms) do
|
176
176
|
primary_key :id
|
177
177
|
end
|
@@ -322,7 +322,7 @@ end
|
|
322
322
|
|
323
323
|
describe "Polymorphic Associations" do
|
324
324
|
before(:all) do
|
325
|
-
DB.
|
325
|
+
DB.instance_variable_get(:@schemas).clear
|
326
326
|
DB.create_table!(:assets) do
|
327
327
|
primary_key :id
|
328
328
|
Integer :attachable_id
|
@@ -448,7 +448,7 @@ end
|
|
448
448
|
|
449
449
|
describe "many_to_one/one_to_many not referencing primary key" do
|
450
450
|
before(:all) do
|
451
|
-
DB.
|
451
|
+
DB.instance_variable_get(:@schemas).clear
|
452
452
|
DB.create_table!(:clients) do
|
453
453
|
primary_key :id
|
454
454
|
String :name
|
@@ -3,7 +3,7 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
|
|
3
3
|
describe "Class Table Inheritance Plugin" do
|
4
4
|
before(:all) do
|
5
5
|
@db = DB
|
6
|
-
@db.
|
6
|
+
@db.instance_variable_get(:@schemas).clear
|
7
7
|
@db.drop_table?(:staff, :executives, :managers, :employees)
|
8
8
|
@db.create_table(:employees) do
|
9
9
|
primary_key :id
|
@@ -175,7 +175,7 @@ end
|
|
175
175
|
describe "Many Through Many Plugin" do
|
176
176
|
before(:all) do
|
177
177
|
@db = DB
|
178
|
-
@db.
|
178
|
+
@db.instance_variable_get(:@schemas).clear
|
179
179
|
@db.drop_table?(:albums_artists, :albums, :artists)
|
180
180
|
@db.create_table(:albums) do
|
181
181
|
primary_key :id
|
@@ -470,7 +470,7 @@ end
|
|
470
470
|
describe "Tactical Eager Loading Plugin" do
|
471
471
|
before(:all) do
|
472
472
|
@db = DB
|
473
|
-
@db.
|
473
|
+
@db.instance_variable_get(:@schemas).clear
|
474
474
|
@db.drop_table?(:albums_artists)
|
475
475
|
@db.create_table!(:artists) do
|
476
476
|
primary_key :id
|
@@ -1992,7 +1992,7 @@ end
|
|
1992
1992
|
describe "Sequel::Plugins::ConstraintValidations" do
|
1993
1993
|
before(:all) do
|
1994
1994
|
@db = DB
|
1995
|
-
@db.extension(:constraint_validations)
|
1995
|
+
@db.extension(:constraint_validations) unless @db.frozen?
|
1996
1996
|
@db.drop_table?(:sequel_constraint_validations)
|
1997
1997
|
@db.create_constraint_validations_table
|
1998
1998
|
@ds = @db[:cv_test]
|
@@ -2064,6 +2064,7 @@ describe "Sequel::Plugins::ConstraintValidations" do
|
|
2064
2064
|
end
|
2065
2065
|
|
2066
2066
|
it "should set up automatic validations inside the model" do
|
2067
|
+
skip if @db.frozen?
|
2067
2068
|
c = Class.new(Sequel::Model(@ds))
|
2068
2069
|
c.plugin :constraint_validations
|
2069
2070
|
c.dataset.delete
|
@@ -2188,7 +2189,8 @@ describe "date_arithmetic extension" do
|
|
2188
2189
|
|
2189
2190
|
before(:all) do
|
2190
2191
|
@db = DB
|
2191
|
-
@db.extension(:date_arithmetic)
|
2192
|
+
@db.extension(:date_arithmetic) unless @db.frozen?
|
2193
|
+
skip if @db.database_type == :sqlite && @db.frozen?
|
2192
2194
|
if @db.database_type == :sqlite
|
2193
2195
|
@db.use_timestamp_timezones = false
|
2194
2196
|
end
|
@@ -2269,7 +2271,7 @@ end
|
|
2269
2271
|
describe "string_agg extension" do
|
2270
2272
|
before(:all) do
|
2271
2273
|
@db = DB
|
2272
|
-
@db.extension(:string_agg)
|
2274
|
+
@db.extension(:string_agg) unless @db.frozen?
|
2273
2275
|
@db.create_table!(:string_agg_test) do
|
2274
2276
|
Integer :id
|
2275
2277
|
String :s
|
@@ -48,7 +48,7 @@ describe "Database schema parser" do
|
|
48
48
|
DB.drop_table(:items)
|
49
49
|
end
|
50
50
|
end
|
51
|
-
end if IDENTIFIER_MANGLING
|
51
|
+
end if IDENTIFIER_MANGLING && !DB.frozen?
|
52
52
|
|
53
53
|
it "should not issue an sql query if the schema has been loaded unless :reload is true" do
|
54
54
|
DB.create_table!(:items){Integer :number}
|
@@ -843,5 +843,5 @@ describe "Database#tables and #views" do
|
|
843
843
|
@db.identifier_input_method = :xxxxx
|
844
844
|
@db.views.each{|t| t.to_s.must_match(/\Ax{5}\d+\z/)}
|
845
845
|
end if DB.supports_view_listing?
|
846
|
-
end if IDENTIFIER_MANGLING
|
846
|
+
end if IDENTIFIER_MANGLING && !DB.frozen?
|
847
847
|
end
|
@@ -20,6 +20,10 @@ Sequel::Deprecation.backtrace_filter = lambda{|line, lineno| lineno < 4 || line
|
|
20
20
|
Sequel.split_symbols = false if ENV['SEQUEL_NO_SPLIT_SYMBOLS']
|
21
21
|
Sequel::Database.extension :columns_introspection if ENV['SEQUEL_COLUMNS_INTROSPECTION']
|
22
22
|
Sequel::Model.cache_associations = false if ENV['SEQUEL_NO_CACHE_ASSOCIATIONS']
|
23
|
+
if ENV['SEQUEL_MODEL_PREPARED_STATEMENTS']
|
24
|
+
Sequel::Model.plugin :prepared_statements
|
25
|
+
Sequel::Model.plugin :prepared_statements_associations
|
26
|
+
end
|
23
27
|
Sequel::Model.use_transactions = false
|
24
28
|
Sequel.cache_anonymous_models = false
|
25
29
|
|
@@ -61,3 +65,9 @@ if dch = ENV['SEQUEL_DUPLICATE_COLUMNS_HANDLER']
|
|
61
65
|
DB.extension :duplicate_columns_handler
|
62
66
|
DB.opts[:on_duplicate_columns] = dch.to_sym unless dch.empty?
|
63
67
|
end
|
68
|
+
|
69
|
+
if ENV['SEQUEL_FREEZE_DATABASE']
|
70
|
+
DB.extension(:constraint_validations, :string_agg, :date_arithmetic)
|
71
|
+
DB.extension(:pg_array) if DB.database_type == :postgres
|
72
|
+
DB.freeze
|
73
|
+
end
|
@@ -166,17 +166,17 @@ describe "Database transactions" do
|
|
166
166
|
end
|
167
167
|
|
168
168
|
it "should handle returning inside of the block by committing" do
|
169
|
-
def
|
170
|
-
transaction do
|
171
|
-
|
169
|
+
def ret_commit
|
170
|
+
@db.transaction do
|
171
|
+
@db[:items] << {:name => 'abc'}
|
172
172
|
return
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
176
|
@d.count.must_equal 0
|
177
|
-
|
177
|
+
ret_commit
|
178
178
|
@d.count.must_equal 1
|
179
|
-
|
179
|
+
ret_commit
|
180
180
|
@d.count.must_equal 2
|
181
181
|
proc do
|
182
182
|
@db.transaction do
|
@@ -762,7 +762,7 @@ describe Sequel::Model, "one_to_one" do
|
|
762
762
|
sqls = DB.sqls
|
763
763
|
['INSERT INTO attributes (node_id, id) VALUES (1234, 3)',
|
764
764
|
'INSERT INTO attributes (id, node_id) VALUES (3, 1234)'].must_include(sqls.slice! 1)
|
765
|
-
sqls.must_equal ['UPDATE attributes SET node_id = NULL WHERE (node_id = 1234)', "SELECT * FROM attributes WHERE
|
765
|
+
sqls.must_equal ['UPDATE attributes SET node_id = NULL WHERE (node_id = 1234)', "SELECT * FROM attributes WHERE id = 3"]
|
766
766
|
|
767
767
|
@c2.new(:id => 1234).attribute.must_equal attrib
|
768
768
|
attrib = @c1.load(:id=>3)
|
@@ -801,7 +801,7 @@ describe Sequel::Model, "one_to_one" do
|
|
801
801
|
sqls = DB.sqls
|
802
802
|
['INSERT INTO attributes (node_id, id) VALUES (5, 3)',
|
803
803
|
'INSERT INTO attributes (id, node_id) VALUES (3, 5)'].must_include(sqls.slice! 1)
|
804
|
-
sqls.must_equal ['UPDATE attributes SET node_id = NULL WHERE (node_id = 5)', "SELECT * FROM attributes WHERE
|
804
|
+
sqls.must_equal ['UPDATE attributes SET node_id = NULL WHERE (node_id = 5)', "SELECT * FROM attributes WHERE id = 3"]
|
805
805
|
|
806
806
|
@c2.new(:id => 321, :xxx=>5).attribute.must_equal attrib
|
807
807
|
attrib = @c1.load(:id=>3)
|
@@ -947,7 +947,7 @@ describe Sequel::Model, "one_to_one" do
|
|
947
947
|
sqls = DB.sqls
|
948
948
|
["INSERT INTO nodes (blah, id) VALUES (3, 4321)",
|
949
949
|
"INSERT INTO nodes (id, blah) VALUES (4321, 3)"].must_include(sqls.slice! 1)
|
950
|
-
sqls.must_equal ["UPDATE nodes SET blah = NULL WHERE (blah = 3)", "SELECT * FROM nodes WHERE
|
950
|
+
sqls.must_equal ["UPDATE nodes SET blah = NULL WHERE (blah = 3)", "SELECT * FROM nodes WHERE id = 4321"]
|
951
951
|
end
|
952
952
|
|
953
953
|
it "should persist changes to associated object when the setter is called" do
|
@@ -1275,7 +1275,7 @@ describe Sequel::Model, "one_to_many" do
|
|
1275
1275
|
a.must_equal n.add_attribute(a)
|
1276
1276
|
sqls = DB.sqls
|
1277
1277
|
sqls.shift.must_match(/INSERT INTO attributes \((node_)?id, (node_)?id\) VALUES \(1?234, 1?234\)/)
|
1278
|
-
sqls.must_equal ["SELECT * FROM attributes WHERE
|
1278
|
+
sqls.must_equal ["SELECT * FROM attributes WHERE id = 234"]
|
1279
1279
|
a.values.must_equal(:node_id => 1234, :id => 234)
|
1280
1280
|
end
|
1281
1281
|
|
@@ -1307,7 +1307,7 @@ describe Sequel::Model, "one_to_many" do
|
|
1307
1307
|
n.add_attribute(:id => 234).must_equal @c1.load(:node_id => 1234, :id => 234)
|
1308
1308
|
sqls = DB.sqls
|
1309
1309
|
sqls.shift.must_match(/INSERT INTO attributes \((node_)?id, (node_)?id\) VALUES \(1?234, 1?234\)/)
|
1310
|
-
sqls.must_equal ["SELECT * FROM attributes WHERE
|
1310
|
+
sqls.must_equal ["SELECT * FROM attributes WHERE id = 234"]
|
1311
1311
|
end
|
1312
1312
|
|
1313
1313
|
it "should accept a primary key for the add_ method" do
|
@@ -2213,7 +2213,7 @@ describe Sequel::Model, "many_to_many" do
|
|
2213
2213
|
['INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (1234, 1)',
|
2214
2214
|
'INSERT INTO attributes_nodes (attribute_id, node_id) VALUES (1, 1234)'
|
2215
2215
|
].must_include(sqls.pop)
|
2216
|
-
sqls.must_equal ['INSERT INTO attributes (id) VALUES (1)', "SELECT * FROM attributes WHERE
|
2216
|
+
sqls.must_equal ['INSERT INTO attributes (id) VALUES (1)', "SELECT * FROM attributes WHERE id = 1"]
|
2217
2217
|
end
|
2218
2218
|
|
2219
2219
|
it "should define a remove_ method that works on existing records" do
|
@@ -4497,6 +4497,13 @@ describe "Model#freeze" do
|
|
4497
4497
|
@o.associations.frozen?.must_equal true
|
4498
4498
|
end
|
4499
4499
|
|
4500
|
+
it "should freeze associations after validating" do
|
4501
|
+
Album.send(:define_method, :validate){super(); b}
|
4502
|
+
@o = Album.load(:id=>1)
|
4503
|
+
@o.freeze
|
4504
|
+
@o.associations.fetch(:b).id.must_equal 1
|
4505
|
+
end
|
4506
|
+
|
4500
4507
|
it "should not break associations getters" do
|
4501
4508
|
Album::B.dataset = Album::B.dataset.with_fetch(:album_id=>1, :id=>2)
|
4502
4509
|
@o.b.must_equal Album::B.load(:id=>2, :album_id=>1)
|
data/spec/model/base_spec.rb
CHANGED
@@ -603,7 +603,7 @@ describe Sequel::Model, ".(allowed|restricted)_columns " do
|
|
603
603
|
i = @c.new
|
604
604
|
i.update(:x => 7, :z => 9)
|
605
605
|
i.values.must_equal(:x => 7)
|
606
|
-
DB.sqls.must_equal ["INSERT INTO blahblah (x) VALUES (7)", "SELECT * FROM blahblah WHERE
|
606
|
+
DB.sqls.must_equal ["INSERT INTO blahblah (x) VALUES (7)", "SELECT * FROM blahblah WHERE id = 10"]
|
607
607
|
end
|
608
608
|
end
|
609
609
|
|
data/spec/model/hooks_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe "Model#before_create && Model#after_create" do
|
|
17
17
|
it "should be called around new record creation" do
|
18
18
|
@c.send(:define_method, :before_create){DB << "BLAH before"}
|
19
19
|
@c.create(:x => 2)
|
20
|
-
DB.sqls.must_equal ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after', 'SELECT * FROM items WHERE
|
20
|
+
DB.sqls.must_equal ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after', 'SELECT * FROM items WHERE x = 2']
|
21
21
|
end
|
22
22
|
|
23
23
|
it ".create should cancel the save and raise an error if before_create returns false and raise_on_save_failure is true" do
|
@@ -124,7 +124,7 @@ describe "Model#before_save && Model#after_save" do
|
|
124
124
|
@c.set_primary_key :x
|
125
125
|
@c.unrestrict_primary_key
|
126
126
|
@c.create(:x => 2)
|
127
|
-
DB.sqls.must_equal ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after', 'SELECT * FROM items WHERE
|
127
|
+
DB.sqls.must_equal ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after', 'SELECT * FROM items WHERE x = 2']
|
128
128
|
end
|
129
129
|
|
130
130
|
it "#save should cancel the save and raise an error if before_save returns false and raise_on_save_failure is true" do
|
@@ -313,7 +313,7 @@ describe "Model around filters" do
|
|
313
313
|
end
|
314
314
|
end
|
315
315
|
@c.create(:x => 2)
|
316
|
-
DB.sqls.must_equal ['ac_before', 'INSERT INTO items (x) VALUES (2)', 'ac_after', "SELECT * FROM items WHERE
|
316
|
+
DB.sqls.must_equal ['ac_before', 'INSERT INTO items (x) VALUES (2)', 'ac_after', "SELECT * FROM items WHERE id = 10"]
|
317
317
|
end
|
318
318
|
|
319
319
|
it "around_delete should be called around record destruction" do
|
@@ -359,7 +359,7 @@ describe "Model around filters" do
|
|
359
359
|
end
|
360
360
|
end
|
361
361
|
@c.create(:x => 2)
|
362
|
-
DB.sqls.must_equal ['as_before', 'ac_before', 'INSERT INTO items (x) VALUES (2)', 'ac_after', 'as_after', "SELECT * FROM items WHERE
|
362
|
+
DB.sqls.must_equal ['as_before', 'ac_before', 'INSERT INTO items (x) VALUES (2)', 'ac_after', 'as_after', "SELECT * FROM items WHERE id = 10"]
|
363
363
|
@c.load(:id=>1, :x => 2).save
|
364
364
|
DB.sqls.must_equal ['as_before', 'au_before', 'UPDATE items SET x = 2 WHERE (id = 1)', 'au_after', 'as_after']
|
365
365
|
end
|
data/spec/model/model_spec.rb
CHANGED
@@ -798,7 +798,7 @@ describe Sequel::Model, ".find_or_create" do
|
|
798
798
|
@c.find_or_create(:x => 1).must_equal @c.load(:x=>1, :id=>1)
|
799
799
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (x = 1) LIMIT 1",
|
800
800
|
"INSERT INTO items (x) VALUES (1)",
|
801
|
-
"SELECT * FROM items WHERE
|
801
|
+
"SELECT * FROM items WHERE id = 1"]
|
802
802
|
end
|
803
803
|
|
804
804
|
it "should pass the new record to be created to the block if no record is found" do
|
@@ -808,7 +808,7 @@ describe Sequel::Model, ".find_or_create" do
|
|
808
808
|
sqls = @db.sqls
|
809
809
|
sqls.first.must_equal "SELECT * FROM items WHERE (x = 1) LIMIT 1"
|
810
810
|
["INSERT INTO items (x, y) VALUES (1, 2)", "INSERT INTO items (y, x) VALUES (2, 1)"].must_include(sqls[1])
|
811
|
-
sqls.last.must_equal "SELECT * FROM items WHERE
|
811
|
+
sqls.last.must_equal "SELECT * FROM items WHERE id = 1"
|
812
812
|
end
|
813
813
|
end
|
814
814
|
|
data/spec/model/record_spec.rb
CHANGED
@@ -64,7 +64,7 @@ describe "Model#save" do
|
|
64
64
|
it "should insert a record for a new model instance" do
|
65
65
|
o = @c.new(:x => 1)
|
66
66
|
o.save
|
67
|
-
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE
|
67
|
+
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE id = 13"]
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should raise if the object can't be refreshed after save" do
|
@@ -111,8 +111,7 @@ describe "Model#save" do
|
|
111
111
|
it "should use value returned by insert as the primary key and refresh the object" do
|
112
112
|
o = @c.new(:x => 11)
|
113
113
|
o.save
|
114
|
-
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (11)",
|
115
|
-
"SELECT * FROM items WHERE (id = 13) LIMIT 1"]
|
114
|
+
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (11)", "SELECT * FROM items WHERE id = 13"]
|
116
115
|
end
|
117
116
|
|
118
117
|
it "should allow you to skip refreshing by overridding _save_refresh" do
|
@@ -1111,7 +1110,7 @@ describe Sequel::Model, "#update" do
|
|
1111
1110
|
|
1112
1111
|
it "should filter the given params using the model columns" do
|
1113
1112
|
@o1.update(:x => 1, :z => 2)
|
1114
|
-
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE
|
1113
|
+
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE id = 10"]
|
1115
1114
|
|
1116
1115
|
DB.reset
|
1117
1116
|
@o2.update(:y => 1, :abc => 2)
|
@@ -1121,12 +1120,12 @@ describe Sequel::Model, "#update" do
|
|
1121
1120
|
it "should support virtual attributes" do
|
1122
1121
|
@c.send(:define_method, :blah=){|v| self.x = v}
|
1123
1122
|
@o1.update(:blah => 333)
|
1124
|
-
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (333)", "SELECT * FROM items WHERE
|
1123
|
+
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (333)", "SELECT * FROM items WHERE id = 10"]
|
1125
1124
|
end
|
1126
1125
|
|
1127
1126
|
it "should not modify the primary key" do
|
1128
1127
|
@o1.update(:x => 1, :id => 2)
|
1129
|
-
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE
|
1128
|
+
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE id = 10"]
|
1130
1129
|
DB.reset
|
1131
1130
|
@o2.update('y'=> 1, 'id'=> 2)
|
1132
1131
|
@o2.values.must_equal(:y => 1, :id=> 5)
|
@@ -1321,18 +1320,18 @@ describe Sequel::Model, "#(set|update)_(all|only)" do
|
|
1321
1320
|
|
1322
1321
|
it "#update_all should update all attributes" do
|
1323
1322
|
@c.new.update_all(:x => 1)
|
1324
|
-
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE
|
1323
|
+
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE id = 10"]
|
1325
1324
|
@c.new.update_all(:y => 1)
|
1326
|
-
DB.sqls.must_equal ["INSERT INTO items (y) VALUES (1)", "SELECT * FROM items WHERE
|
1325
|
+
DB.sqls.must_equal ["INSERT INTO items (y) VALUES (1)", "SELECT * FROM items WHERE id = 10"]
|
1327
1326
|
@c.new.update_all(:z => 1)
|
1328
|
-
DB.sqls.must_equal ["INSERT INTO items (z) VALUES (1)", "SELECT * FROM items WHERE
|
1327
|
+
DB.sqls.must_equal ["INSERT INTO items (z) VALUES (1)", "SELECT * FROM items WHERE id = 10"]
|
1329
1328
|
end
|
1330
1329
|
|
1331
1330
|
it "#update_only should only update given attributes" do
|
1332
1331
|
@o1.update_only({:x => 1, :y => 2, :z=>3, :id=>4}, [:x])
|
1333
|
-
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE
|
1332
|
+
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE id = 10"]
|
1334
1333
|
@c.new.update_only({:x => 1, :y => 2, :z=>3, :id=>4}, :x)
|
1335
|
-
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE
|
1334
|
+
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE id = 10"]
|
1336
1335
|
end
|
1337
1336
|
end
|
1338
1337
|
|
@@ -1699,13 +1698,13 @@ describe Sequel::Model, ".create" do
|
|
1699
1698
|
it "should be able to create rows in the associated table" do
|
1700
1699
|
o = @c.create(:x => 1)
|
1701
1700
|
o.class.must_equal @c
|
1702
|
-
DB.sqls.must_equal ['INSERT INTO items (x) VALUES (1)', "SELECT * FROM items WHERE
|
1701
|
+
DB.sqls.must_equal ['INSERT INTO items (x) VALUES (1)', "SELECT * FROM items WHERE id = 10"]
|
1703
1702
|
end
|
1704
1703
|
|
1705
1704
|
it "should be able to create rows without any values specified" do
|
1706
1705
|
o = @c.create
|
1707
1706
|
o.class.must_equal @c
|
1708
|
-
DB.sqls.must_equal ["INSERT INTO items DEFAULT VALUES", "SELECT * FROM items WHERE
|
1707
|
+
DB.sqls.must_equal ["INSERT INTO items DEFAULT VALUES", "SELECT * FROM items WHERE id = 10"]
|
1709
1708
|
end
|
1710
1709
|
|
1711
1710
|
it "should accept a block and call it" do
|
@@ -1715,14 +1714,14 @@ describe Sequel::Model, ".create" do
|
|
1715
1714
|
o1.must_be :===, o
|
1716
1715
|
o3.must_be :===, o
|
1717
1716
|
o2.must_equal :blah
|
1718
|
-
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (333)", "SELECT * FROM items WHERE
|
1717
|
+
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (333)", "SELECT * FROM items WHERE id = 10"]
|
1719
1718
|
end
|
1720
1719
|
|
1721
1720
|
it "should create a row for a model with custom primary key" do
|
1722
1721
|
@c.set_primary_key :x
|
1723
1722
|
o = @c.create(:x => 30)
|
1724
1723
|
o.class.must_equal @c
|
1725
|
-
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (30)", "SELECT * FROM items WHERE
|
1724
|
+
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (30)", "SELECT * FROM items WHERE x = 30"]
|
1726
1725
|
end
|
1727
1726
|
end
|
1728
1727
|
|
@@ -1741,14 +1740,14 @@ describe Sequel::Model, "#refresh" do
|
|
1741
1740
|
@c.dataset = @c.dataset.with_fetch(:x => 'kaboom', :id => 555)
|
1742
1741
|
@m.refresh
|
1743
1742
|
@m[:x].must_equal 'kaboom'
|
1744
|
-
DB.sqls.must_equal ["SELECT * FROM items WHERE
|
1743
|
+
DB.sqls.must_equal ["SELECT * FROM items WHERE id = 555"]
|
1745
1744
|
end
|
1746
1745
|
|
1747
1746
|
it "should raise if the instance is not found" do
|
1748
1747
|
@m = @c.new(:id => 555)
|
1749
1748
|
@c.dataset = @c.dataset.with_fetch([])
|
1750
1749
|
proc {@m.refresh}.must_raise(Sequel::NoExistingObject)
|
1751
|
-
DB.sqls.must_equal ["SELECT * FROM items WHERE
|
1750
|
+
DB.sqls.must_equal ["SELECT * FROM items WHERE id = 555"]
|
1752
1751
|
end
|
1753
1752
|
|
1754
1753
|
it "should be aliased by #reload" do
|
@@ -1756,7 +1755,7 @@ describe Sequel::Model, "#refresh" do
|
|
1756
1755
|
@c.dataset = @c.dataset.with_fetch(:x => 'kaboom', :id => 555)
|
1757
1756
|
@m.reload
|
1758
1757
|
@m[:x].must_equal 'kaboom'
|
1759
|
-
DB.sqls.must_equal ["SELECT * FROM items WHERE
|
1758
|
+
DB.sqls.must_equal ["SELECT * FROM items WHERE id = 555"]
|
1760
1759
|
end
|
1761
1760
|
end
|
1762
1761
|
|