viking-sequel 3.10.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 +3134 -0
- data/COPYING +19 -0
- data/README.rdoc +723 -0
- data/Rakefile +193 -0
- data/bin/sequel +196 -0
- data/doc/advanced_associations.rdoc +644 -0
- data/doc/cheat_sheet.rdoc +218 -0
- data/doc/dataset_basics.rdoc +106 -0
- data/doc/dataset_filtering.rdoc +158 -0
- data/doc/opening_databases.rdoc +296 -0
- data/doc/prepared_statements.rdoc +104 -0
- data/doc/reflection.rdoc +84 -0
- data/doc/release_notes/1.0.txt +38 -0
- data/doc/release_notes/1.1.txt +143 -0
- data/doc/release_notes/1.3.txt +101 -0
- data/doc/release_notes/1.4.0.txt +53 -0
- data/doc/release_notes/1.5.0.txt +155 -0
- data/doc/release_notes/2.0.0.txt +298 -0
- data/doc/release_notes/2.1.0.txt +271 -0
- data/doc/release_notes/2.10.0.txt +328 -0
- data/doc/release_notes/2.11.0.txt +215 -0
- data/doc/release_notes/2.12.0.txt +534 -0
- data/doc/release_notes/2.2.0.txt +253 -0
- data/doc/release_notes/2.3.0.txt +88 -0
- data/doc/release_notes/2.4.0.txt +106 -0
- data/doc/release_notes/2.5.0.txt +137 -0
- data/doc/release_notes/2.6.0.txt +157 -0
- data/doc/release_notes/2.7.0.txt +166 -0
- data/doc/release_notes/2.8.0.txt +171 -0
- data/doc/release_notes/2.9.0.txt +97 -0
- data/doc/release_notes/3.0.0.txt +221 -0
- data/doc/release_notes/3.1.0.txt +406 -0
- data/doc/release_notes/3.10.0.txt +286 -0
- data/doc/release_notes/3.2.0.txt +268 -0
- data/doc/release_notes/3.3.0.txt +192 -0
- data/doc/release_notes/3.4.0.txt +325 -0
- data/doc/release_notes/3.5.0.txt +510 -0
- data/doc/release_notes/3.6.0.txt +366 -0
- data/doc/release_notes/3.7.0.txt +179 -0
- data/doc/release_notes/3.8.0.txt +151 -0
- data/doc/release_notes/3.9.0.txt +233 -0
- data/doc/schema.rdoc +36 -0
- data/doc/sharding.rdoc +113 -0
- data/doc/virtual_rows.rdoc +205 -0
- data/lib/sequel.rb +1 -0
- data/lib/sequel/adapters/ado.rb +90 -0
- data/lib/sequel/adapters/ado/mssql.rb +30 -0
- data/lib/sequel/adapters/amalgalite.rb +176 -0
- data/lib/sequel/adapters/db2.rb +139 -0
- data/lib/sequel/adapters/dbi.rb +113 -0
- data/lib/sequel/adapters/do.rb +188 -0
- data/lib/sequel/adapters/do/mysql.rb +49 -0
- data/lib/sequel/adapters/do/postgres.rb +91 -0
- data/lib/sequel/adapters/do/sqlite.rb +40 -0
- data/lib/sequel/adapters/firebird.rb +283 -0
- data/lib/sequel/adapters/informix.rb +77 -0
- data/lib/sequel/adapters/jdbc.rb +587 -0
- data/lib/sequel/adapters/jdbc/as400.rb +58 -0
- data/lib/sequel/adapters/jdbc/h2.rb +133 -0
- data/lib/sequel/adapters/jdbc/mssql.rb +57 -0
- data/lib/sequel/adapters/jdbc/mysql.rb +78 -0
- data/lib/sequel/adapters/jdbc/oracle.rb +50 -0
- data/lib/sequel/adapters/jdbc/postgresql.rb +108 -0
- data/lib/sequel/adapters/jdbc/sqlite.rb +55 -0
- data/lib/sequel/adapters/mysql.rb +421 -0
- data/lib/sequel/adapters/odbc.rb +143 -0
- data/lib/sequel/adapters/odbc/mssql.rb +42 -0
- data/lib/sequel/adapters/openbase.rb +64 -0
- data/lib/sequel/adapters/oracle.rb +131 -0
- data/lib/sequel/adapters/postgres.rb +504 -0
- data/lib/sequel/adapters/shared/mssql.rb +490 -0
- data/lib/sequel/adapters/shared/mysql.rb +498 -0
- data/lib/sequel/adapters/shared/oracle.rb +195 -0
- data/lib/sequel/adapters/shared/postgres.rb +830 -0
- data/lib/sequel/adapters/shared/progress.rb +44 -0
- data/lib/sequel/adapters/shared/sqlite.rb +389 -0
- data/lib/sequel/adapters/sqlite.rb +224 -0
- data/lib/sequel/adapters/utils/stored_procedures.rb +84 -0
- data/lib/sequel/connection_pool.rb +99 -0
- data/lib/sequel/connection_pool/sharded_single.rb +84 -0
- data/lib/sequel/connection_pool/sharded_threaded.rb +211 -0
- data/lib/sequel/connection_pool/single.rb +29 -0
- data/lib/sequel/connection_pool/threaded.rb +150 -0
- data/lib/sequel/core.rb +293 -0
- data/lib/sequel/core_sql.rb +241 -0
- data/lib/sequel/database.rb +1079 -0
- data/lib/sequel/database/schema_generator.rb +327 -0
- data/lib/sequel/database/schema_methods.rb +203 -0
- data/lib/sequel/database/schema_sql.rb +320 -0
- data/lib/sequel/dataset.rb +32 -0
- data/lib/sequel/dataset/actions.rb +441 -0
- data/lib/sequel/dataset/features.rb +86 -0
- data/lib/sequel/dataset/graph.rb +254 -0
- data/lib/sequel/dataset/misc.rb +119 -0
- data/lib/sequel/dataset/mutation.rb +64 -0
- data/lib/sequel/dataset/prepared_statements.rb +227 -0
- data/lib/sequel/dataset/query.rb +709 -0
- data/lib/sequel/dataset/sql.rb +996 -0
- data/lib/sequel/exceptions.rb +51 -0
- data/lib/sequel/extensions/blank.rb +43 -0
- data/lib/sequel/extensions/inflector.rb +242 -0
- data/lib/sequel/extensions/looser_typecasting.rb +21 -0
- data/lib/sequel/extensions/migration.rb +239 -0
- data/lib/sequel/extensions/named_timezones.rb +61 -0
- data/lib/sequel/extensions/pagination.rb +100 -0
- data/lib/sequel/extensions/pretty_table.rb +82 -0
- data/lib/sequel/extensions/query.rb +52 -0
- data/lib/sequel/extensions/schema_dumper.rb +271 -0
- data/lib/sequel/extensions/sql_expr.rb +122 -0
- data/lib/sequel/extensions/string_date_time.rb +46 -0
- data/lib/sequel/extensions/thread_local_timezones.rb +48 -0
- data/lib/sequel/metaprogramming.rb +9 -0
- data/lib/sequel/model.rb +120 -0
- data/lib/sequel/model/associations.rb +1514 -0
- data/lib/sequel/model/base.rb +1069 -0
- data/lib/sequel/model/default_inflections.rb +45 -0
- data/lib/sequel/model/errors.rb +39 -0
- data/lib/sequel/model/exceptions.rb +21 -0
- data/lib/sequel/model/inflections.rb +162 -0
- data/lib/sequel/model/plugins.rb +70 -0
- data/lib/sequel/plugins/active_model.rb +59 -0
- data/lib/sequel/plugins/association_dependencies.rb +103 -0
- data/lib/sequel/plugins/association_proxies.rb +41 -0
- data/lib/sequel/plugins/boolean_readers.rb +53 -0
- data/lib/sequel/plugins/caching.rb +141 -0
- data/lib/sequel/plugins/class_table_inheritance.rb +214 -0
- data/lib/sequel/plugins/composition.rb +138 -0
- data/lib/sequel/plugins/force_encoding.rb +72 -0
- data/lib/sequel/plugins/hook_class_methods.rb +126 -0
- data/lib/sequel/plugins/identity_map.rb +116 -0
- data/lib/sequel/plugins/instance_filters.rb +98 -0
- data/lib/sequel/plugins/instance_hooks.rb +57 -0
- data/lib/sequel/plugins/lazy_attributes.rb +77 -0
- data/lib/sequel/plugins/many_through_many.rb +208 -0
- data/lib/sequel/plugins/nested_attributes.rb +206 -0
- data/lib/sequel/plugins/optimistic_locking.rb +81 -0
- data/lib/sequel/plugins/rcte_tree.rb +281 -0
- data/lib/sequel/plugins/schema.rb +66 -0
- data/lib/sequel/plugins/serialization.rb +166 -0
- data/lib/sequel/plugins/single_table_inheritance.rb +74 -0
- data/lib/sequel/plugins/subclasses.rb +45 -0
- data/lib/sequel/plugins/tactical_eager_loading.rb +61 -0
- data/lib/sequel/plugins/timestamps.rb +87 -0
- data/lib/sequel/plugins/touch.rb +118 -0
- data/lib/sequel/plugins/typecast_on_load.rb +72 -0
- data/lib/sequel/plugins/validation_class_methods.rb +405 -0
- data/lib/sequel/plugins/validation_helpers.rb +223 -0
- data/lib/sequel/sql.rb +1020 -0
- data/lib/sequel/timezones.rb +161 -0
- data/lib/sequel/version.rb +12 -0
- data/lib/sequel_core.rb +1 -0
- data/lib/sequel_model.rb +1 -0
- data/spec/adapters/firebird_spec.rb +407 -0
- data/spec/adapters/informix_spec.rb +97 -0
- data/spec/adapters/mssql_spec.rb +403 -0
- data/spec/adapters/mysql_spec.rb +1019 -0
- data/spec/adapters/oracle_spec.rb +286 -0
- data/spec/adapters/postgres_spec.rb +969 -0
- data/spec/adapters/spec_helper.rb +51 -0
- data/spec/adapters/sqlite_spec.rb +432 -0
- data/spec/core/connection_pool_spec.rb +808 -0
- data/spec/core/core_sql_spec.rb +417 -0
- data/spec/core/database_spec.rb +1662 -0
- data/spec/core/dataset_spec.rb +3827 -0
- data/spec/core/expression_filters_spec.rb +595 -0
- data/spec/core/object_graph_spec.rb +296 -0
- data/spec/core/schema_generator_spec.rb +159 -0
- data/spec/core/schema_spec.rb +830 -0
- data/spec/core/spec_helper.rb +56 -0
- data/spec/core/version_spec.rb +7 -0
- data/spec/extensions/active_model_spec.rb +76 -0
- data/spec/extensions/association_dependencies_spec.rb +127 -0
- data/spec/extensions/association_proxies_spec.rb +50 -0
- data/spec/extensions/blank_spec.rb +67 -0
- data/spec/extensions/boolean_readers_spec.rb +92 -0
- data/spec/extensions/caching_spec.rb +250 -0
- data/spec/extensions/class_table_inheritance_spec.rb +252 -0
- data/spec/extensions/composition_spec.rb +194 -0
- data/spec/extensions/force_encoding_spec.rb +117 -0
- data/spec/extensions/hook_class_methods_spec.rb +470 -0
- data/spec/extensions/identity_map_spec.rb +202 -0
- data/spec/extensions/inflector_spec.rb +181 -0
- data/spec/extensions/instance_filters_spec.rb +55 -0
- data/spec/extensions/instance_hooks_spec.rb +133 -0
- data/spec/extensions/lazy_attributes_spec.rb +153 -0
- data/spec/extensions/looser_typecasting_spec.rb +39 -0
- data/spec/extensions/many_through_many_spec.rb +884 -0
- data/spec/extensions/migration_spec.rb +332 -0
- data/spec/extensions/named_timezones_spec.rb +72 -0
- data/spec/extensions/nested_attributes_spec.rb +396 -0
- data/spec/extensions/optimistic_locking_spec.rb +100 -0
- data/spec/extensions/pagination_spec.rb +99 -0
- data/spec/extensions/pretty_table_spec.rb +91 -0
- data/spec/extensions/query_spec.rb +85 -0
- data/spec/extensions/rcte_tree_spec.rb +205 -0
- data/spec/extensions/schema_dumper_spec.rb +357 -0
- data/spec/extensions/schema_spec.rb +127 -0
- data/spec/extensions/serialization_spec.rb +209 -0
- data/spec/extensions/single_table_inheritance_spec.rb +96 -0
- data/spec/extensions/spec_helper.rb +91 -0
- data/spec/extensions/sql_expr_spec.rb +89 -0
- data/spec/extensions/string_date_time_spec.rb +93 -0
- data/spec/extensions/subclasses_spec.rb +52 -0
- data/spec/extensions/tactical_eager_loading_spec.rb +65 -0
- data/spec/extensions/thread_local_timezones_spec.rb +45 -0
- data/spec/extensions/timestamps_spec.rb +150 -0
- data/spec/extensions/touch_spec.rb +155 -0
- data/spec/extensions/typecast_on_load_spec.rb +69 -0
- data/spec/extensions/validation_class_methods_spec.rb +984 -0
- data/spec/extensions/validation_helpers_spec.rb +438 -0
- data/spec/integration/associations_test.rb +281 -0
- data/spec/integration/database_test.rb +26 -0
- data/spec/integration/dataset_test.rb +963 -0
- data/spec/integration/eager_loader_test.rb +734 -0
- data/spec/integration/model_test.rb +130 -0
- data/spec/integration/plugin_test.rb +814 -0
- data/spec/integration/prepared_statement_test.rb +213 -0
- data/spec/integration/schema_test.rb +361 -0
- data/spec/integration/spec_helper.rb +73 -0
- data/spec/integration/timezone_test.rb +55 -0
- data/spec/integration/transaction_test.rb +122 -0
- data/spec/integration/type_test.rb +96 -0
- data/spec/model/association_reflection_spec.rb +175 -0
- data/spec/model/associations_spec.rb +2633 -0
- data/spec/model/base_spec.rb +418 -0
- data/spec/model/dataset_methods_spec.rb +78 -0
- data/spec/model/eager_loading_spec.rb +1391 -0
- data/spec/model/hooks_spec.rb +240 -0
- data/spec/model/inflector_spec.rb +26 -0
- data/spec/model/model_spec.rb +593 -0
- data/spec/model/plugins_spec.rb +236 -0
- data/spec/model/record_spec.rb +1500 -0
- data/spec/model/spec_helper.rb +97 -0
- data/spec/model/validations_spec.rb +153 -0
- data/spec/rcov.opts +6 -0
- data/spec/spec_config.rb.example +10 -0
- metadata +346 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'logger'
|
3
|
+
unless Object.const_defined?('Sequel')
|
4
|
+
$:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
|
5
|
+
require 'sequel'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require File.join(File.dirname(File.dirname(__FILE__)), 'spec_config.rb') unless defined?(INTEGRATION_DB)
|
9
|
+
rescue LoadError
|
10
|
+
end
|
11
|
+
|
12
|
+
Sequel::Model.use_transactions = false
|
13
|
+
|
14
|
+
$sqls = []
|
15
|
+
def clear_sqls
|
16
|
+
$sqls.clear
|
17
|
+
end
|
18
|
+
|
19
|
+
class Spec::Example::ExampleGroup
|
20
|
+
def log
|
21
|
+
begin
|
22
|
+
INTEGRATION_DB.loggers << Logger.new(STDOUT)
|
23
|
+
yield
|
24
|
+
ensure
|
25
|
+
INTEGRATION_DB.loggers.pop
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.log_specify(message, &block)
|
30
|
+
specify(message){log{instance_eval(&block)}}
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.cspecify(message, *checked, &block)
|
34
|
+
pending = false
|
35
|
+
checked.each do |c|
|
36
|
+
case c
|
37
|
+
when INTEGRATION_DB.database_type
|
38
|
+
pending = c
|
39
|
+
when Array
|
40
|
+
case c.length
|
41
|
+
when 1
|
42
|
+
pending = c if c.first == INTEGRATION_DB.class.adapter_scheme
|
43
|
+
when 2
|
44
|
+
if c.first.is_a?(Proc)
|
45
|
+
pending = c if c.first.call(INTEGRATION_DB) && c.last == INTEGRATION_DB.database_type
|
46
|
+
elsif c.last.is_a?(Proc)
|
47
|
+
pending = c if c.first == INTEGRATION_DB.class.adapter_scheme && c.last.call(INTEGRATION_DB)
|
48
|
+
else
|
49
|
+
pending = c if c.first == INTEGRATION_DB.class.adapter_scheme && c.last == INTEGRATION_DB.database_type
|
50
|
+
end
|
51
|
+
when 3
|
52
|
+
pending = c if c[0] == INTEGRATION_DB.class.adapter_scheme && c[1] == INTEGRATION_DB.database_type && c[2].call(INTEGRATION_DB)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
break if pending
|
56
|
+
end
|
57
|
+
if pending
|
58
|
+
specify(message){pending("Not yet working on #{Array(pending).join(', ')}", &block)}
|
59
|
+
else
|
60
|
+
specify(message, &block)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
if defined?(INTEGRATION_DB) || defined?(INTEGRATION_URL) || ENV['SEQUEL_INTEGRATION_URL']
|
66
|
+
unless defined?(INTEGRATION_DB)
|
67
|
+
url = defined?(INTEGRATION_URL) ? INTEGRATION_URL : ENV['SEQUEL_INTEGRATION_URL']
|
68
|
+
INTEGRATION_DB = Sequel.connect(url)
|
69
|
+
#INTEGRATION_DB.instance_variable_set(:@server_version, 80100)
|
70
|
+
end
|
71
|
+
else
|
72
|
+
INTEGRATION_DB = Sequel.sqlite('', :quote_identifiers=>false)
|
73
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper.rb')
|
2
|
+
|
3
|
+
describe "Sequel timezone support" do
|
4
|
+
def test_timezone
|
5
|
+
t = Time.now
|
6
|
+
@db[:t].insert(t)
|
7
|
+
t2 = @db[:t].single_value
|
8
|
+
t2 = Sequel.database_to_application_timestamp(t2.to_s) unless t2.is_a?(Time)
|
9
|
+
(t2 - t).should be_close(0, 2)
|
10
|
+
t2.utc_offset.should == 0 if Sequel.application_timezone == :utc
|
11
|
+
t2.utc_offset.should == t.getlocal.utc_offset if Sequel.application_timezone == :local
|
12
|
+
@db[:t].delete
|
13
|
+
|
14
|
+
dt = DateTime.now
|
15
|
+
Sequel.datetime_class = DateTime
|
16
|
+
@db[:t].insert(dt)
|
17
|
+
dt2 = @db[:t].single_value
|
18
|
+
dt2 = Sequel.database_to_application_timestamp(dt2.to_s) unless dt2.is_a?(DateTime)
|
19
|
+
(dt2 - dt).should be_close(0, 0.00002)
|
20
|
+
dt2.offset.should == 0 if Sequel.application_timezone == :utc
|
21
|
+
dt2.offset.should == dt.offset if Sequel.application_timezone == :local
|
22
|
+
end
|
23
|
+
|
24
|
+
before do
|
25
|
+
@db = INTEGRATION_DB
|
26
|
+
@db.create_table!(:t){DateTime :t}
|
27
|
+
end
|
28
|
+
after do
|
29
|
+
@db.drop_table(:t)
|
30
|
+
Sequel.default_timezone = nil
|
31
|
+
Sequel.datetime_class = Time
|
32
|
+
end
|
33
|
+
|
34
|
+
cspecify "should support using UTC for database storage and local time for the application", [:do, proc{|db| db.database_type != :sqlite}] do
|
35
|
+
Sequel.database_timezone = :utc
|
36
|
+
Sequel.application_timezone = :local
|
37
|
+
test_timezone
|
38
|
+
end
|
39
|
+
|
40
|
+
cspecify "should support using local time for database storage and UTC for the application", [:do, proc{|db| db.database_type != :sqlite}] do
|
41
|
+
Sequel.database_timezone = :local
|
42
|
+
Sequel.application_timezone = :utc
|
43
|
+
test_timezone
|
44
|
+
end
|
45
|
+
|
46
|
+
cspecify "should support using UTC for both database storage and for application", [:do, proc{|db| db.database_type != :sqlite}] do
|
47
|
+
Sequel.default_timezone = :utc
|
48
|
+
test_timezone
|
49
|
+
end
|
50
|
+
|
51
|
+
specify "should support using local time for both database storage and for application" do
|
52
|
+
Sequel.default_timezone = :local
|
53
|
+
test_timezone
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper.rb')
|
2
|
+
|
3
|
+
describe "Database transactions" do
|
4
|
+
before do
|
5
|
+
INTEGRATION_DB.drop_table(:items) if INTEGRATION_DB.table_exists?(:items)
|
6
|
+
INTEGRATION_DB.create_table(:items, :engine=>'InnoDB'){String :name; Integer :value}
|
7
|
+
@d = INTEGRATION_DB[:items]
|
8
|
+
clear_sqls
|
9
|
+
end
|
10
|
+
after do
|
11
|
+
INTEGRATION_DB.drop_table(:items) if INTEGRATION_DB.table_exists?(:items)
|
12
|
+
end
|
13
|
+
|
14
|
+
specify "should support transactions" do
|
15
|
+
INTEGRATION_DB.transaction do
|
16
|
+
@d << {:name => 'abc', :value => 1}
|
17
|
+
end
|
18
|
+
|
19
|
+
@d.count.should == 1
|
20
|
+
end
|
21
|
+
|
22
|
+
specify "should have #transaction yield the connection" do
|
23
|
+
INTEGRATION_DB.transaction do |conn|
|
24
|
+
conn.should_not == nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
specify "should correctly rollback transactions" do
|
29
|
+
proc do
|
30
|
+
INTEGRATION_DB.transaction do
|
31
|
+
@d << {:name => 'abc', :value => 1}
|
32
|
+
raise Interrupt, 'asdf'
|
33
|
+
end
|
34
|
+
end.should raise_error(Interrupt)
|
35
|
+
|
36
|
+
proc do
|
37
|
+
INTEGRATION_DB.transaction do
|
38
|
+
@d << {:name => 'abc', :value => 1}
|
39
|
+
raise Sequel::Rollback
|
40
|
+
end
|
41
|
+
end.should_not raise_error
|
42
|
+
|
43
|
+
@d.count.should == 0
|
44
|
+
end
|
45
|
+
|
46
|
+
specify "should support nested transactions" do
|
47
|
+
@db = INTEGRATION_DB
|
48
|
+
@db.transaction do
|
49
|
+
@db.transaction do
|
50
|
+
@d << {:name => 'abc', :value => 1}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
@d.count.should == 1
|
54
|
+
|
55
|
+
@d.delete
|
56
|
+
proc {@db.transaction do
|
57
|
+
@d << {:name => 'abc', :value => 1}
|
58
|
+
@db.transaction do
|
59
|
+
raise Sequel::Rollback
|
60
|
+
end
|
61
|
+
end}.should_not raise_error
|
62
|
+
@d.count.should == 0
|
63
|
+
|
64
|
+
proc {@db.transaction do
|
65
|
+
@d << {:name => 'abc', :value => 1}
|
66
|
+
@db.transaction do
|
67
|
+
raise Interrupt, 'asdf'
|
68
|
+
end
|
69
|
+
end}.should raise_error(Interrupt)
|
70
|
+
@d.count.should == 0
|
71
|
+
end
|
72
|
+
|
73
|
+
if INTEGRATION_DB.supports_savepoints?
|
74
|
+
cspecify "should support nested transactions through savepoints using the savepoint option", [:jdbc, :sqlite] do
|
75
|
+
@db = INTEGRATION_DB
|
76
|
+
@db.transaction do
|
77
|
+
@d << {:name => '1'}
|
78
|
+
@db.transaction(:savepoint=>true) do
|
79
|
+
@d << {:name => '2'}
|
80
|
+
@db.transaction do
|
81
|
+
@d << {:name => '3'}
|
82
|
+
raise Sequel::Rollback
|
83
|
+
end
|
84
|
+
end
|
85
|
+
@d << {:name => '4'}
|
86
|
+
@db.transaction do
|
87
|
+
@d << {:name => '6'}
|
88
|
+
@db.transaction(:savepoint=>true) do
|
89
|
+
@d << {:name => '7'}
|
90
|
+
raise Sequel::Rollback
|
91
|
+
end
|
92
|
+
end
|
93
|
+
@d << {:name => '5'}
|
94
|
+
end
|
95
|
+
|
96
|
+
@d.order(:name).map(:name).should == %w{1 4 5 6}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
specify "should handle returning inside of the block by committing" do
|
101
|
+
def INTEGRATION_DB.ret_commit
|
102
|
+
transaction do
|
103
|
+
self[:items] << {:name => 'abc'}
|
104
|
+
return
|
105
|
+
self[:items] << {:name => 'd'}
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
@d.count.should == 0
|
110
|
+
INTEGRATION_DB.ret_commit
|
111
|
+
@d.count.should == 1
|
112
|
+
INTEGRATION_DB.ret_commit
|
113
|
+
@d.count.should == 2
|
114
|
+
proc do
|
115
|
+
INTEGRATION_DB.transaction do
|
116
|
+
raise Interrupt, 'asdf'
|
117
|
+
end
|
118
|
+
end.should raise_error(Interrupt)
|
119
|
+
|
120
|
+
@d.count.should == 2
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper.rb')
|
2
|
+
|
3
|
+
describe "Supported types" do
|
4
|
+
def create_items_table_with_column(name, type, opts={})
|
5
|
+
INTEGRATION_DB.create_table!(:items){column name, type, opts}
|
6
|
+
INTEGRATION_DB[:items]
|
7
|
+
end
|
8
|
+
|
9
|
+
cspecify "should support casting correctly", [:sqlite, :sqlite] do
|
10
|
+
ds = create_items_table_with_column(:number, Integer)
|
11
|
+
ds.insert(:number => 1)
|
12
|
+
ds.select(:number.cast_string.as(:n)).map(:n).should == %w'1'
|
13
|
+
ds = create_items_table_with_column(:name, String)
|
14
|
+
ds.insert(:name=> '1')
|
15
|
+
ds.select(:name.cast_numeric.as(:n)).map(:n).should == [1]
|
16
|
+
end
|
17
|
+
|
18
|
+
specify "should support NULL correctly" do
|
19
|
+
ds = create_items_table_with_column(:number, Integer)
|
20
|
+
ds.insert(:number => nil)
|
21
|
+
ds.all.should == [{:number=>nil}]
|
22
|
+
end
|
23
|
+
|
24
|
+
specify "should support generic integer type" do
|
25
|
+
ds = create_items_table_with_column(:number, Integer)
|
26
|
+
ds.insert(:number => 2)
|
27
|
+
ds.all.should == [{:number=>2}]
|
28
|
+
end
|
29
|
+
|
30
|
+
specify "should support generic fixnum type" do
|
31
|
+
ds = create_items_table_with_column(:number, Fixnum)
|
32
|
+
ds.insert(:number => 2)
|
33
|
+
ds.all.should == [{:number=>2}]
|
34
|
+
end
|
35
|
+
|
36
|
+
specify "should support generic bignum type" do
|
37
|
+
ds = create_items_table_with_column(:number, Bignum)
|
38
|
+
ds.insert(:number => 2**34)
|
39
|
+
ds.all.should == [{:number=>2**34}]
|
40
|
+
end
|
41
|
+
|
42
|
+
specify "should support generic float type" do
|
43
|
+
ds = create_items_table_with_column(:number, Float)
|
44
|
+
ds.insert(:number => 2.1)
|
45
|
+
ds.all.should == [{:number=>2.1}]
|
46
|
+
end
|
47
|
+
|
48
|
+
cspecify "should support generic numeric type", [:odbc, :mssql] do
|
49
|
+
ds = create_items_table_with_column(:number, Numeric, :size=>[15, 10])
|
50
|
+
ds.insert(:number => BigDecimal.new('2.123456789'))
|
51
|
+
ds.all.should == [{:number=>BigDecimal.new('2.123456789')}]
|
52
|
+
ds = create_items_table_with_column(:number, BigDecimal, :size=>[15, 10])
|
53
|
+
ds.insert(:number => BigDecimal.new('2.123456789'))
|
54
|
+
ds.all.should == [{:number=>BigDecimal.new('2.123456789')}]
|
55
|
+
end
|
56
|
+
|
57
|
+
specify "should support generic string type" do
|
58
|
+
ds = create_items_table_with_column(:name, String)
|
59
|
+
ds.insert(:name => 'Test User')
|
60
|
+
ds.all.should == [{:name=>'Test User'}]
|
61
|
+
end
|
62
|
+
|
63
|
+
cspecify "should support generic date type", [:do, :sqlite], [:jdbc, :sqlite], :mssql do
|
64
|
+
ds = create_items_table_with_column(:dat, Date)
|
65
|
+
d = Date.today
|
66
|
+
ds.insert(:dat => d)
|
67
|
+
ds.first[:dat].should == d
|
68
|
+
end
|
69
|
+
|
70
|
+
cspecify "should support generic datetime type", [:do, :sqlite], [:jdbc, :sqlite] do
|
71
|
+
ds = create_items_table_with_column(:tim, DateTime)
|
72
|
+
t = DateTime.now
|
73
|
+
ds.insert(:tim => t)
|
74
|
+
ds.first[:tim].strftime('%Y%m%d%H%M%S').should == t.strftime('%Y%m%d%H%M%S')
|
75
|
+
ds = create_items_table_with_column(:tim, Time)
|
76
|
+
t = Time.now
|
77
|
+
ds.insert(:tim => t)
|
78
|
+
ds.first[:tim].strftime('%Y%m%d%H%M%S').should == t.strftime('%Y%m%d%H%M%S')
|
79
|
+
end
|
80
|
+
|
81
|
+
cspecify "should support generic file type", [:do], [:odbc, :mssql] do
|
82
|
+
ds = create_items_table_with_column(:name, File)
|
83
|
+
ds.insert(:name => ("a\0"*300).to_sequel_blob)
|
84
|
+
ds.all.should == [{:name=>("a\0"*300).to_sequel_blob}]
|
85
|
+
ds.first[:name].should be_a_kind_of(::Sequel::SQL::Blob)
|
86
|
+
end
|
87
|
+
|
88
|
+
cspecify "should support generic boolean type", [:do, :sqlite], [:jdbc, :sqlite], [:odbc, :mssql] do
|
89
|
+
ds = create_items_table_with_column(:number, TrueClass)
|
90
|
+
ds.insert(:number => true)
|
91
|
+
ds.all.should == [{:number=>true}]
|
92
|
+
ds = create_items_table_with_column(:number, FalseClass)
|
93
|
+
ds.insert(:number => true)
|
94
|
+
ds.all.should == [{:number=>true}]
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe Sequel::Model::Associations::AssociationReflection, "#associated_class" do
|
4
|
+
before do
|
5
|
+
@c = Class.new(Sequel::Model)
|
6
|
+
class ::ParParent < Sequel::Model; end
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should use the :class value if present" do
|
10
|
+
@c.many_to_one :c, :class=>ParParent
|
11
|
+
@c.association_reflection(:c).keys.should include(:class)
|
12
|
+
@c.association_reflection(:c).associated_class.should == ParParent
|
13
|
+
end
|
14
|
+
it "should figure out the class if the :class value is not present" do
|
15
|
+
@c.many_to_one :c, :class=>'ParParent'
|
16
|
+
@c.association_reflection(:c).keys.should_not include(:class)
|
17
|
+
@c.association_reflection(:c).associated_class.should == ParParent
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Sequel::Model::Associations::AssociationReflection, "#primary_key" do
|
22
|
+
before do
|
23
|
+
@c = Class.new(Sequel::Model)
|
24
|
+
class ::ParParent < Sequel::Model; end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should use the :primary_key value if present" do
|
28
|
+
@c.many_to_one :c, :class=>ParParent, :primary_key=>:blah__blah
|
29
|
+
@c.association_reflection(:c).keys.should include(:primary_key)
|
30
|
+
@c.association_reflection(:c).primary_key.should == :blah__blah
|
31
|
+
end
|
32
|
+
it "should use the associated table's primary key if :primary_key is not present" do
|
33
|
+
@c.many_to_one :c, :class=>'ParParent'
|
34
|
+
@c.association_reflection(:c).keys.should_not include(:primary_key)
|
35
|
+
@c.association_reflection(:c).primary_key.should == :id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe Sequel::Model::Associations::AssociationReflection, "#reciprocal" do
|
40
|
+
before do
|
41
|
+
class ::ParParent < Sequel::Model; end
|
42
|
+
class ::ParParentTwo < Sequel::Model; end
|
43
|
+
class ::ParParentThree < Sequel::Model; end
|
44
|
+
end
|
45
|
+
after do
|
46
|
+
Object.send(:remove_const, :ParParent)
|
47
|
+
Object.send(:remove_const, :ParParentTwo)
|
48
|
+
Object.send(:remove_const, :ParParentThree)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should use the :reciprocal value if present" do
|
52
|
+
@c = Class.new(Sequel::Model)
|
53
|
+
@d = Class.new(Sequel::Model)
|
54
|
+
@c.many_to_one :c, :class=>@d, :reciprocal=>:xx
|
55
|
+
@c.association_reflection(:c).keys.should include(:reciprocal)
|
56
|
+
@c.association_reflection(:c).reciprocal.should == :xx
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should require the associated class is the current class to be a reciprocal" do
|
60
|
+
ParParent.many_to_one :par_parent_two, :key=>:blah
|
61
|
+
ParParent.many_to_one :par_parent_three, :key=>:blah
|
62
|
+
ParParentTwo.one_to_many :par_parents, :key=>:blah
|
63
|
+
ParParentThree.one_to_many :par_parents, :key=>:blah
|
64
|
+
|
65
|
+
ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_two
|
66
|
+
ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_three
|
67
|
+
|
68
|
+
ParParent.many_to_many :par_parent_twos, :left_key=>:l, :right_key=>:r, :join_table=>:jt
|
69
|
+
ParParent.many_to_many :par_parent_threes, :left_key=>:l, :right_key=>:r, :join_table=>:jt
|
70
|
+
ParParentTwo.many_to_many :par_parents, :right_key=>:l, :left_key=>:r, :join_table=>:jt
|
71
|
+
ParParentThree.many_to_many :par_parents, :right_key=>:l, :left_key=>:r, :join_table=>:jt
|
72
|
+
|
73
|
+
ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_twos
|
74
|
+
ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_threes
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should handle composite keys" do
|
78
|
+
ParParent.many_to_one :par_parent_two, :key=>[:a, :b], :primary_key=>[:c, :b]
|
79
|
+
ParParent.many_to_one :par_parent_three, :key=>[:d, :e], :primary_key=>[:c, :b]
|
80
|
+
ParParentTwo.one_to_many :par_parents, :primary_key=>[:c, :b], :key=>[:a, :b]
|
81
|
+
ParParentThree.one_to_many :par_parents, :primary_key=>[:c, :b], :key=>[:d, :e]
|
82
|
+
|
83
|
+
ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_two
|
84
|
+
ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_three
|
85
|
+
|
86
|
+
ParParent.many_to_many :par_parent_twos, :left_key=>[:l1, :l2], :right_key=>[:r1, :r2], :left_primary_key=>[:pl1, :pl2], :right_primary_key=>[:pr1, :pr2], :join_table=>:jt
|
87
|
+
ParParent.many_to_many :par_parent_threes, :right_key=>[:l1, :l2], :left_key=>[:r1, :r2], :left_primary_key=>[:pl1, :pl2], :right_primary_key=>[:pr1, :pr2], :join_table=>:jt
|
88
|
+
ParParentTwo.many_to_many :par_parents, :right_key=>[:l1, :l2], :left_key=>[:r1, :r2], :right_primary_key=>[:pl1, :pl2], :left_primary_key=>[:pr1, :pr2], :join_table=>:jt
|
89
|
+
ParParentThree.many_to_many :par_parents, :left_key=>[:l1, :l2], :right_key=>[:r1, :r2], :right_primary_key=>[:pl1, :pl2], :left_primary_key=>[:pr1, :pr2], :join_table=>:jt
|
90
|
+
|
91
|
+
ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_twos
|
92
|
+
ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_threes
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should figure out the reciprocal if the :reciprocal value is not present" do
|
96
|
+
ParParent.many_to_one :par_parent_two
|
97
|
+
ParParentTwo.one_to_many :par_parents
|
98
|
+
ParParent.many_to_many :par_parent_threes
|
99
|
+
ParParentThree.many_to_many :par_parents
|
100
|
+
|
101
|
+
ParParent.association_reflection(:par_parent_two).keys.should_not include(:reciprocal)
|
102
|
+
ParParent.association_reflection(:par_parent_two).reciprocal.should == :par_parents
|
103
|
+
ParParentTwo.association_reflection(:par_parents).keys.should_not include(:reciprocal)
|
104
|
+
ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_two
|
105
|
+
ParParent.association_reflection(:par_parent_threes).keys.should_not include(:reciprocal)
|
106
|
+
ParParent.association_reflection(:par_parent_threes).reciprocal.should == :par_parents
|
107
|
+
ParParentThree.association_reflection(:par_parents).keys.should_not include(:reciprocal)
|
108
|
+
ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_threes
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe Sequel::Model::Associations::AssociationReflection, "#select" do
|
113
|
+
before do
|
114
|
+
@c = Class.new(Sequel::Model)
|
115
|
+
class ::ParParent < Sequel::Model; end
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should use the :select value if present" do
|
119
|
+
@c.many_to_one :c, :class=>ParParent, :select=>[:par_parents__id]
|
120
|
+
@c.association_reflection(:c).keys.should include(:select)
|
121
|
+
@c.association_reflection(:c).select.should == [:par_parents__id]
|
122
|
+
end
|
123
|
+
it "should be the associated_table.* if :select is not present for a many_to_many associaiton" do
|
124
|
+
@c.many_to_many :cs, :class=>'ParParent'
|
125
|
+
@c.association_reflection(:cs).keys.should_not include(:select)
|
126
|
+
@c.association_reflection(:cs).select.should == :par_parents.*
|
127
|
+
end
|
128
|
+
it "should be if :select is not present for a many_to_one and one_to_many associaiton" do
|
129
|
+
@c.one_to_many :cs, :class=>'ParParent'
|
130
|
+
@c.association_reflection(:cs).keys.should_not include(:select)
|
131
|
+
@c.association_reflection(:cs).select.should == nil
|
132
|
+
@c.many_to_one :c, :class=>'ParParent'
|
133
|
+
@c.association_reflection(:c).keys.should_not include(:select)
|
134
|
+
@c.association_reflection(:c).select.should == nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe Sequel::Model::Associations::AssociationReflection, "#can_have_associated_objects?" do
|
139
|
+
it "should be true for any given object (for backward compatibility)" do
|
140
|
+
Sequel::Model::Associations::AssociationReflection.new.can_have_associated_objects?(Object.new).should == true
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe Sequel::Model::Associations::AssociationReflection, "#associated_object_keys" do
|
145
|
+
before do
|
146
|
+
@c = Class.new(Sequel::Model)
|
147
|
+
class ::ParParent < Sequel::Model; end
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should use the primary keys for a many_to_one association" do
|
151
|
+
@c.many_to_one :c, :class=>ParParent
|
152
|
+
@c.association_reflection(:c).associated_object_keys.should == [:id]
|
153
|
+
@c.many_to_one :c, :class=>ParParent, :primary_key=>:d_id
|
154
|
+
@c.association_reflection(:c).associated_object_keys.should == [:d_id]
|
155
|
+
@c.many_to_one :c, :class=>ParParent, :key=>[:c_id1, :c_id2], :primary_key=>[:id1, :id2]
|
156
|
+
@c.association_reflection(:c).associated_object_keys.should == [:id1, :id2]
|
157
|
+
end
|
158
|
+
it "should use the keys for a one_to_many association" do
|
159
|
+
ParParent.one_to_many :cs, :class=>ParParent
|
160
|
+
ParParent.association_reflection(:cs).associated_object_keys.should == [:par_parent_id]
|
161
|
+
@c.one_to_many :cs, :class=>ParParent, :key=>:d_id
|
162
|
+
@c.association_reflection(:cs).associated_object_keys.should == [:d_id]
|
163
|
+
@c.one_to_many :cs, :class=>ParParent, :key=>[:c_id1, :c_id2], :primary_key=>[:id1, :id2]
|
164
|
+
@c.association_reflection(:cs).associated_object_keys.should == [:c_id1, :c_id2]
|
165
|
+
end
|
166
|
+
it "should use the right primary keys for a many_to_many association" do
|
167
|
+
@c.many_to_many :cs, :class=>ParParent
|
168
|
+
@c.association_reflection(:cs).associated_object_keys.should == [:id]
|
169
|
+
@c.many_to_many :cs, :class=>ParParent, :right_primary_key=>:d_id
|
170
|
+
@c.association_reflection(:cs).associated_object_keys.should == [:d_id]
|
171
|
+
@c.many_to_many :cs, :class=>ParParent, :right_key=>[:c_id1, :c_id2], :right_primary_key=>[:id1, :id2]
|
172
|
+
@c.association_reflection(:cs).associated_object_keys.should == [:id1, :id2]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|