sequel 3.28.0 → 3.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/CHANGELOG +119 -3
  2. data/Rakefile +5 -3
  3. data/bin/sequel +1 -5
  4. data/doc/model_hooks.rdoc +9 -1
  5. data/doc/opening_databases.rdoc +49 -40
  6. data/doc/prepared_statements.rdoc +27 -6
  7. data/doc/release_notes/3.28.0.txt +2 -2
  8. data/doc/release_notes/3.29.0.txt +459 -0
  9. data/doc/sharding.rdoc +7 -1
  10. data/doc/testing.rdoc +18 -9
  11. data/doc/transactions.rdoc +41 -1
  12. data/lib/sequel/adapters/ado.rb +28 -17
  13. data/lib/sequel/adapters/ado/mssql.rb +18 -6
  14. data/lib/sequel/adapters/amalgalite.rb +11 -7
  15. data/lib/sequel/adapters/db2.rb +122 -70
  16. data/lib/sequel/adapters/dbi.rb +15 -15
  17. data/lib/sequel/adapters/do.rb +5 -36
  18. data/lib/sequel/adapters/do/mysql.rb +0 -5
  19. data/lib/sequel/adapters/do/postgres.rb +0 -5
  20. data/lib/sequel/adapters/do/sqlite.rb +0 -5
  21. data/lib/sequel/adapters/firebird.rb +3 -6
  22. data/lib/sequel/adapters/ibmdb.rb +24 -16
  23. data/lib/sequel/adapters/informix.rb +2 -4
  24. data/lib/sequel/adapters/jdbc.rb +47 -11
  25. data/lib/sequel/adapters/jdbc/as400.rb +5 -24
  26. data/lib/sequel/adapters/jdbc/db2.rb +0 -5
  27. data/lib/sequel/adapters/jdbc/derby.rb +217 -0
  28. data/lib/sequel/adapters/jdbc/firebird.rb +0 -5
  29. data/lib/sequel/adapters/jdbc/h2.rb +10 -12
  30. data/lib/sequel/adapters/jdbc/hsqldb.rb +166 -0
  31. data/lib/sequel/adapters/jdbc/informix.rb +0 -5
  32. data/lib/sequel/adapters/jdbc/jtds.rb +0 -5
  33. data/lib/sequel/adapters/jdbc/mysql.rb +0 -10
  34. data/lib/sequel/adapters/jdbc/oracle.rb +70 -3
  35. data/lib/sequel/adapters/jdbc/postgresql.rb +0 -11
  36. data/lib/sequel/adapters/jdbc/sqlite.rb +0 -5
  37. data/lib/sequel/adapters/jdbc/sqlserver.rb +0 -5
  38. data/lib/sequel/adapters/jdbc/transactions.rb +56 -7
  39. data/lib/sequel/adapters/mock.rb +315 -0
  40. data/lib/sequel/adapters/mysql.rb +64 -51
  41. data/lib/sequel/adapters/mysql2.rb +15 -9
  42. data/lib/sequel/adapters/odbc.rb +13 -6
  43. data/lib/sequel/adapters/odbc/db2.rb +0 -4
  44. data/lib/sequel/adapters/odbc/mssql.rb +0 -5
  45. data/lib/sequel/adapters/openbase.rb +2 -4
  46. data/lib/sequel/adapters/oracle.rb +333 -51
  47. data/lib/sequel/adapters/postgres.rb +80 -27
  48. data/lib/sequel/adapters/shared/access.rb +0 -6
  49. data/lib/sequel/adapters/shared/db2.rb +13 -15
  50. data/lib/sequel/adapters/shared/firebird.rb +6 -6
  51. data/lib/sequel/adapters/shared/mssql.rb +23 -18
  52. data/lib/sequel/adapters/shared/mysql.rb +6 -6
  53. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +6 -0
  54. data/lib/sequel/adapters/shared/oracle.rb +185 -30
  55. data/lib/sequel/adapters/shared/postgres.rb +35 -18
  56. data/lib/sequel/adapters/shared/progress.rb +0 -6
  57. data/lib/sequel/adapters/shared/sqlite.rb +116 -37
  58. data/lib/sequel/adapters/sqlite.rb +16 -8
  59. data/lib/sequel/adapters/swift.rb +5 -5
  60. data/lib/sequel/adapters/swift/mysql.rb +0 -5
  61. data/lib/sequel/adapters/swift/postgres.rb +0 -5
  62. data/lib/sequel/adapters/swift/sqlite.rb +6 -4
  63. data/lib/sequel/adapters/tinytds.rb +13 -10
  64. data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +8 -0
  65. data/lib/sequel/core.rb +40 -0
  66. data/lib/sequel/database/connecting.rb +1 -2
  67. data/lib/sequel/database/dataset.rb +3 -3
  68. data/lib/sequel/database/dataset_defaults.rb +58 -0
  69. data/lib/sequel/database/misc.rb +62 -2
  70. data/lib/sequel/database/query.rb +113 -49
  71. data/lib/sequel/database/schema_methods.rb +7 -2
  72. data/lib/sequel/dataset/actions.rb +37 -19
  73. data/lib/sequel/dataset/features.rb +24 -0
  74. data/lib/sequel/dataset/graph.rb +7 -6
  75. data/lib/sequel/dataset/misc.rb +11 -3
  76. data/lib/sequel/dataset/mutation.rb +2 -3
  77. data/lib/sequel/dataset/prepared_statements.rb +6 -4
  78. data/lib/sequel/dataset/query.rb +46 -15
  79. data/lib/sequel/dataset/sql.rb +28 -4
  80. data/lib/sequel/extensions/named_timezones.rb +5 -0
  81. data/lib/sequel/extensions/thread_local_timezones.rb +1 -1
  82. data/lib/sequel/model.rb +2 -1
  83. data/lib/sequel/model/associations.rb +115 -33
  84. data/lib/sequel/model/base.rb +91 -31
  85. data/lib/sequel/plugins/class_table_inheritance.rb +4 -4
  86. data/lib/sequel/plugins/dataset_associations.rb +100 -0
  87. data/lib/sequel/plugins/force_encoding.rb +6 -6
  88. data/lib/sequel/plugins/identity_map.rb +1 -1
  89. data/lib/sequel/plugins/many_through_many.rb +6 -10
  90. data/lib/sequel/plugins/prepared_statements.rb +12 -1
  91. data/lib/sequel/plugins/prepared_statements_associations.rb +1 -1
  92. data/lib/sequel/plugins/rcte_tree.rb +29 -15
  93. data/lib/sequel/plugins/serialization.rb +6 -1
  94. data/lib/sequel/plugins/sharding.rb +0 -5
  95. data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
  96. data/lib/sequel/plugins/typecast_on_load.rb +9 -12
  97. data/lib/sequel/plugins/update_primary_key.rb +1 -1
  98. data/lib/sequel/timezones.rb +42 -42
  99. data/lib/sequel/version.rb +1 -1
  100. data/spec/adapters/mssql_spec.rb +29 -29
  101. data/spec/adapters/mysql_spec.rb +86 -104
  102. data/spec/adapters/oracle_spec.rb +48 -76
  103. data/spec/adapters/postgres_spec.rb +98 -33
  104. data/spec/adapters/spec_helper.rb +0 -5
  105. data/spec/adapters/sqlite_spec.rb +24 -21
  106. data/spec/core/connection_pool_spec.rb +9 -15
  107. data/spec/core/core_sql_spec.rb +20 -31
  108. data/spec/core/database_spec.rb +491 -227
  109. data/spec/core/dataset_spec.rb +638 -1051
  110. data/spec/core/expression_filters_spec.rb +0 -1
  111. data/spec/core/mock_adapter_spec.rb +378 -0
  112. data/spec/core/object_graph_spec.rb +48 -114
  113. data/spec/core/schema_generator_spec.rb +3 -3
  114. data/spec/core/schema_spec.rb +51 -114
  115. data/spec/core/spec_helper.rb +3 -90
  116. data/spec/extensions/class_table_inheritance_spec.rb +1 -1
  117. data/spec/extensions/dataset_associations_spec.rb +199 -0
  118. data/spec/extensions/instance_hooks_spec.rb +71 -0
  119. data/spec/extensions/named_timezones_spec.rb +22 -2
  120. data/spec/extensions/nested_attributes_spec.rb +3 -0
  121. data/spec/extensions/schema_spec.rb +1 -1
  122. data/spec/extensions/serialization_modification_detection_spec.rb +1 -0
  123. data/spec/extensions/serialization_spec.rb +5 -8
  124. data/spec/extensions/spec_helper.rb +4 -0
  125. data/spec/extensions/thread_local_timezones_spec.rb +22 -2
  126. data/spec/extensions/typecast_on_load_spec.rb +1 -6
  127. data/spec/integration/associations_test.rb +123 -12
  128. data/spec/integration/dataset_test.rb +140 -47
  129. data/spec/integration/eager_loader_test.rb +19 -21
  130. data/spec/integration/model_test.rb +80 -1
  131. data/spec/integration/plugin_test.rb +179 -128
  132. data/spec/integration/prepared_statement_test.rb +92 -91
  133. data/spec/integration/schema_test.rb +42 -23
  134. data/spec/integration/spec_helper.rb +25 -31
  135. data/spec/integration/timezone_test.rb +38 -12
  136. data/spec/integration/transaction_test.rb +161 -34
  137. data/spec/integration/type_test.rb +3 -3
  138. data/spec/model/association_reflection_spec.rb +83 -7
  139. data/spec/model/associations_spec.rb +393 -676
  140. data/spec/model/base_spec.rb +186 -116
  141. data/spec/model/dataset_methods_spec.rb +7 -27
  142. data/spec/model/eager_loading_spec.rb +343 -867
  143. data/spec/model/hooks_spec.rb +160 -79
  144. data/spec/model/model_spec.rb +118 -165
  145. data/spec/model/plugins_spec.rb +7 -13
  146. data/spec/model/record_spec.rb +138 -207
  147. data/spec/model/spec_helper.rb +10 -73
  148. metadata +14 -8
@@ -2,7 +2,7 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
2
2
 
3
3
  describe Sequel::Schema::Generator do
4
4
  before do
5
- @generator = Sequel::Schema::Generator.new(SchemaDummyDatabase.new) do
5
+ @generator = Sequel::Schema::Generator.new(Sequel.mock) do
6
6
  string :title
7
7
  column :body, :text
8
8
  foreign_key :parent_id
@@ -97,7 +97,7 @@ end
97
97
 
98
98
  describe Sequel::Schema::AlterTableGenerator do
99
99
  before do
100
- @generator = Sequel::Schema::AlterTableGenerator.new(SchemaDummyDatabase.new) do
100
+ @generator = Sequel::Schema::AlterTableGenerator.new(Sequel.mock) do
101
101
  add_column :aaa, :text
102
102
  drop_column :bbb
103
103
  rename_column :ccc, :ho
@@ -147,7 +147,7 @@ end
147
147
 
148
148
  describe "Sequel::Schema::Generator generic type methods" do
149
149
  it "should store the type class in :type for each column" do
150
- Sequel::Schema::Generator.new(SchemaDummyDatabase.new) do
150
+ Sequel::Schema::Generator.new(Sequel.mock) do
151
151
  String :a
152
152
  Integer :b
153
153
  Fixnum :c
@@ -2,7 +2,7 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
2
2
 
3
3
  describe "DB#create_table" do
4
4
  before do
5
- @db = SchemaDummyDatabase.new
5
+ @db = Sequel.mock
6
6
  end
7
7
 
8
8
  specify "should accept the table name" do
@@ -88,13 +88,11 @@ describe "DB#create_table" do
88
88
  end
89
89
  @db.sqls.should == ['CREATE TABLE cats (id integer PRIMARY KEY AUTOINCREMENT)']
90
90
 
91
- @db.sqls.clear
92
91
  @db.create_table(:cats) do
93
92
  primary_key :id, :serial, :auto_increment => false
94
93
  end
95
94
  @db.sqls.should == ['CREATE TABLE cats (id serial PRIMARY KEY)']
96
95
 
97
- @db.sqls.clear
98
96
  @db.create_table(:cats) do
99
97
  primary_key :id, :type => :serial, :auto_increment => false
100
98
  end
@@ -154,7 +152,6 @@ describe "DB#create_table" do
154
152
  varchar :name
155
153
  end
156
154
  @db.sqls.should == ["CREATE TABLE cats (name varchar(255))"]
157
- @db.sqls.clear
158
155
  @db.create_table(:cats) do
159
156
  varchar :name, :size => 51
160
157
  end
@@ -199,7 +196,6 @@ describe "DB#create_table" do
199
196
  end
200
197
  @db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects(id))"]
201
198
 
202
- @db.sqls.clear
203
199
  @db.create_table(:cats) do
204
200
  foreign_key :project_id, :table => :projects, :key => :zzz
205
201
  end
@@ -212,32 +208,25 @@ describe "DB#create_table" do
212
208
  end
213
209
  @db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON DELETE RESTRICT)"]
214
210
 
215
- @db.sqls.clear
216
211
  @db.create_table(:cats) do
217
212
  foreign_key :project_id, :table => :projects, :on_delete => :cascade
218
213
  end
219
214
  @db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON DELETE CASCADE)"]
220
215
 
221
- @db.sqls.clear
222
216
  @db.create_table(:cats) do
223
217
  foreign_key :project_id, :table => :projects, :on_delete => :no_action
224
218
  end
225
219
  @db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON DELETE NO ACTION)"]
226
- @db.sqls.clear
227
220
 
228
- @db.sqls.clear
229
221
  @db.create_table(:cats) do
230
222
  foreign_key :project_id, :table => :projects, :on_delete => :set_null
231
223
  end
232
224
  @db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON DELETE SET NULL)"]
233
- @db.sqls.clear
234
225
 
235
- @db.sqls.clear
236
226
  @db.create_table(:cats) do
237
227
  foreign_key :project_id, :table => :projects, :on_delete => :set_default
238
228
  end
239
229
  @db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON DELETE SET DEFAULT)"]
240
- @db.sqls.clear
241
230
  end
242
231
 
243
232
  specify "should accept foreign keys with ON UPDATE clause" do
@@ -246,32 +235,25 @@ describe "DB#create_table" do
246
235
  end
247
236
  @db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON UPDATE RESTRICT)"]
248
237
 
249
- @db.sqls.clear
250
238
  @db.create_table(:cats) do
251
239
  foreign_key :project_id, :table => :projects, :on_update => :cascade
252
240
  end
253
241
  @db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON UPDATE CASCADE)"]
254
242
 
255
- @db.sqls.clear
256
243
  @db.create_table(:cats) do
257
244
  foreign_key :project_id, :table => :projects, :on_update => :no_action
258
245
  end
259
246
  @db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON UPDATE NO ACTION)"]
260
- @db.sqls.clear
261
247
 
262
- @db.sqls.clear
263
248
  @db.create_table(:cats) do
264
249
  foreign_key :project_id, :table => :projects, :on_update => :set_null
265
250
  end
266
251
  @db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON UPDATE SET NULL)"]
267
- @db.sqls.clear
268
252
 
269
- @db.sqls.clear
270
253
  @db.create_table(:cats) do
271
254
  foreign_key :project_id, :table => :projects, :on_update => :set_default
272
255
  end
273
256
  @db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON UPDATE SET DEFAULT)"]
274
- @db.sqls.clear
275
257
  end
276
258
 
277
259
  specify "should accept foreign keys with deferrable option" do
@@ -368,7 +350,6 @@ describe "DB#create_table" do
368
350
  @db.meta_def(:execute_ddl){|*a| raise Sequel::DatabaseError if /blah/.match(a.first); super(*a)}
369
351
  lambda{@db.create_table(:cats){Integer :id; index :blah; index :id}}.should raise_error(Sequel::DatabaseError)
370
352
  @db.sqls.should == ['CREATE TABLE cats (id integer)']
371
- @db.sqls.clear
372
353
  lambda{@db.create_table(:cats, :ignore_index_errors=>true){Integer :id; index :blah; index :id}}.should_not raise_error(Sequel::DatabaseError)
373
354
  @db.sqls.should == ['CREATE TABLE cats (id integer)', 'CREATE INDEX cats_id_index ON cats (id)']
374
355
  end
@@ -506,7 +487,6 @@ describe "DB#create_table" do
506
487
  foreign_key [:a, :b], :abc, :key => [:real_a, :real_b]
507
488
  end
508
489
  @db.sqls.should == ["CREATE TABLE cats (a integer, b integer, FOREIGN KEY (a, b) REFERENCES abc(real_a, real_b))"]
509
- @db.sqls.clear
510
490
 
511
491
  @db.create_table(:cats) do
512
492
  integer :a
@@ -524,7 +504,6 @@ describe "DB#create_table" do
524
504
  end
525
505
  @db.sqls.should == ["CREATE TABLE cats (a integer, b integer, FOREIGN KEY (a, b) REFERENCES abc ON DELETE CASCADE)"]
526
506
 
527
- @db.sqls.clear
528
507
  @db.create_table(:cats) do
529
508
  integer :a
530
509
  integer :b
@@ -532,7 +511,6 @@ describe "DB#create_table" do
532
511
  end
533
512
  @db.sqls.should == ["CREATE TABLE cats (a integer, b integer, FOREIGN KEY (a, b) REFERENCES abc ON UPDATE NO ACTION)"]
534
513
 
535
- @db.sqls.clear
536
514
  @db.create_table(:cats) do
537
515
  integer :a
538
516
  integer :b
@@ -540,7 +518,6 @@ describe "DB#create_table" do
540
518
  end
541
519
  @db.sqls.should == ["CREATE TABLE cats (a integer, b integer, FOREIGN KEY (a, b) REFERENCES abc ON DELETE RESTRICT ON UPDATE SET DEFAULT)"]
542
520
 
543
- @db.sqls.clear
544
521
  @db.create_table(:cats) do
545
522
  integer :a
546
523
  integer :b
@@ -552,7 +529,7 @@ end
552
529
 
553
530
  describe "DB#create_table!" do
554
531
  before do
555
- @db = SchemaDummyDatabase.new
532
+ @db = Sequel.mock
556
533
  end
557
534
 
558
535
  specify "should create the table if it does not exist" do
@@ -570,13 +547,13 @@ end
570
547
 
571
548
  describe "DB#create_table?" do
572
549
  before do
573
- @db = SchemaDummyDatabase.new
550
+ @db = Sequel.mock
574
551
  end
575
552
 
576
553
  specify "should not create the table if the table already exists" do
577
554
  @db.meta_def(:table_exists?){|a| true}
578
555
  @db.create_table?(:cats){|*a|}
579
- @db.sqls.should == nil
556
+ @db.sqls.should == []
580
557
  end
581
558
 
582
559
  specify "should create the table if the table doesn't already exist" do
@@ -594,7 +571,7 @@ end
594
571
 
595
572
  describe "DB#drop_table" do
596
573
  before do
597
- @db = SchemaDummyDatabase.new
574
+ @db = Sequel.mock
598
575
  end
599
576
 
600
577
  specify "should generate a DROP TABLE statement" do
@@ -615,7 +592,7 @@ end
615
592
 
616
593
  describe "DB#alter_table" do
617
594
  before do
618
- @db = SchemaDummyDatabase.new
595
+ @db = Sequel.mock
619
596
  end
620
597
 
621
598
  specify "should allow adding not null constraint" do
@@ -659,7 +636,6 @@ describe "DB#alter_table" do
659
636
  end
660
637
  @db.sqls.should == ["ALTER TABLE cats ADD UNIQUE (a, b)"]
661
638
 
662
- @db.sqls.clear
663
639
  @db.alter_table(:cats) do
664
640
  add_unique_constraint [:a, :b], :name => :ab_uniq
665
641
  end
@@ -679,19 +655,16 @@ describe "DB#alter_table" do
679
655
  end
680
656
  @db.sqls.should == ["ALTER TABLE cats ADD FOREIGN KEY (node_id, prop_id) REFERENCES nodes_props"]
681
657
 
682
- @db.sqls.clear
683
658
  @db.alter_table(:cats) do
684
659
  add_foreign_key [:node_id, :prop_id], :nodes_props, :name => :cfk
685
660
  end
686
661
  @db.sqls.should == ["ALTER TABLE cats ADD CONSTRAINT cfk FOREIGN KEY (node_id, prop_id) REFERENCES nodes_props"]
687
662
 
688
- @db.sqls.clear
689
663
  @db.alter_table(:cats) do
690
664
  add_foreign_key [:node_id, :prop_id], :nodes_props, :key => [:nid, :pid]
691
665
  end
692
666
  @db.sqls.should == ["ALTER TABLE cats ADD FOREIGN KEY (node_id, prop_id) REFERENCES nodes_props(nid, pid)"]
693
667
 
694
- @db.sqls.clear
695
668
  @db.alter_table(:cats) do
696
669
  add_foreign_key [:node_id, :prop_id], :nodes_props, :on_delete => :restrict, :on_update => :cascade
697
670
  end
@@ -709,7 +682,7 @@ describe "DB#alter_table" do
709
682
  @db.meta_def(:execute_ddl){|*a| raise Sequel::DatabaseError}
710
683
  lambda{@db.add_index(:cats, :id)}.should raise_error(Sequel::DatabaseError)
711
684
  lambda{@db.add_index(:cats, :id, :ignore_errors=>true)}.should_not raise_error(Sequel::DatabaseError)
712
- @db.sqls.should == nil
685
+ @db.sqls.should == []
713
686
  end
714
687
 
715
688
  specify "should support add_primary_key" do
@@ -725,7 +698,6 @@ describe "DB#alter_table" do
725
698
  end
726
699
  @db.sqls.should == ["ALTER TABLE cats ADD PRIMARY KEY (id, type)"]
727
700
 
728
- @db.sqls.clear
729
701
  @db.alter_table(:cats) do
730
702
  add_primary_key [:id, :type], :name => :cpk
731
703
  end
@@ -809,7 +781,7 @@ end
809
781
 
810
782
  describe "Database#create_table" do
811
783
  before do
812
- @db = DummyDatabase.new
784
+ @db = Sequel.mock
813
785
  end
814
786
 
815
787
  specify "should construct proper SQL" do
@@ -818,10 +790,8 @@ describe "Database#create_table" do
818
790
  column :name, :text
819
791
  index :name, :unique => true
820
792
  end
821
- @db.sqls.should == [
822
- 'CREATE TABLE test (id integer NOT NULL PRIMARY KEY AUTOINCREMENT, name text)',
823
- 'CREATE UNIQUE INDEX test_name_index ON test (name)'
824
- ]
793
+ @db.sqls.should == ['CREATE TABLE test (id integer NOT NULL PRIMARY KEY AUTOINCREMENT, name text)',
794
+ 'CREATE UNIQUE INDEX test_name_index ON test (name)']
825
795
  end
826
796
 
827
797
  specify "should create a temporary table" do
@@ -831,10 +801,8 @@ describe "Database#create_table" do
831
801
  index :name, :unique => true
832
802
  end
833
803
 
834
- @db.sqls.should == [
835
- 'CREATE TEMPORARY TABLE test_tmp (id integer NOT NULL PRIMARY KEY AUTOINCREMENT, name text)',
836
- 'CREATE UNIQUE INDEX test_tmp_name_index ON test_tmp (name)'
837
- ]
804
+ @db.sqls.should == ['CREATE TEMPORARY TABLE test_tmp (id integer NOT NULL PRIMARY KEY AUTOINCREMENT, name text)',
805
+ 'CREATE UNIQUE INDEX test_tmp_name_index ON test_tmp (name)']
838
806
  end
839
807
 
840
808
  specify "should not use default schema when creating a temporary table" do
@@ -848,7 +816,7 @@ end
848
816
 
849
817
  describe "Database#alter_table" do
850
818
  before do
851
- @db = DummyDatabase.new
819
+ @db = Sequel.mock
852
820
  end
853
821
 
854
822
  specify "should construct proper SQL" do
@@ -858,40 +826,31 @@ describe "Database#alter_table" do
858
826
  rename_column :ccc, :ddd
859
827
  set_column_type :eee, :integer
860
828
  set_column_default :hhh, 'abcd'
861
-
862
829
  add_index :fff, :unique => true
863
830
  drop_index :ggg
864
831
  end
865
832
 
866
- @db.sqls.should == [
867
- 'ALTER TABLE xyz ADD COLUMN aaa text NOT NULL UNIQUE',
833
+ @db.sqls.should == ['ALTER TABLE xyz ADD COLUMN aaa text NOT NULL UNIQUE',
868
834
  'ALTER TABLE xyz DROP COLUMN bbb',
869
835
  'ALTER TABLE xyz RENAME COLUMN ccc TO ddd',
870
836
  'ALTER TABLE xyz ALTER COLUMN eee TYPE integer',
871
837
  "ALTER TABLE xyz ALTER COLUMN hhh SET DEFAULT 'abcd'",
872
-
873
838
  'CREATE UNIQUE INDEX xyz_fff_index ON xyz (fff)',
874
- 'DROP INDEX xyz_ggg_index'
875
- ]
839
+ 'DROP INDEX xyz_ggg_index']
876
840
  end
877
841
  end
878
842
 
879
843
  describe "Database#add_column" do
880
- before do
881
- @db = DummyDatabase.new
882
- end
883
-
884
844
  specify "should construct proper SQL" do
885
- @db.add_column :test, :name, :text, :unique => true
886
- @db.sqls.should == [
887
- 'ALTER TABLE test ADD COLUMN name text UNIQUE'
888
- ]
845
+ db = Sequel.mock
846
+ db.add_column :test, :name, :text, :unique => true
847
+ db.sqls.should == ['ALTER TABLE test ADD COLUMN name text UNIQUE']
889
848
  end
890
849
  end
891
850
 
892
851
  describe "Database#drop_column" do
893
852
  before do
894
- @db = DummyDatabase.new
853
+ @db = Sequel.mock
895
854
  end
896
855
 
897
856
  specify "should construct proper SQL" do
@@ -907,80 +866,68 @@ end
907
866
 
908
867
  describe "Database#rename_column" do
909
868
  before do
910
- @db = DummyDatabase.new
869
+ @db = Sequel.mock
911
870
  end
912
871
 
913
872
  specify "should construct proper SQL" do
914
873
  @db.rename_column :test, :abc, :def
915
- @db.sqls.should == [
916
- 'ALTER TABLE test RENAME COLUMN abc TO def'
917
- ]
874
+ @db.sqls.should == ['ALTER TABLE test RENAME COLUMN abc TO def']
918
875
  end
919
876
  end
920
877
 
921
878
  describe "Database#set_column_type" do
922
879
  before do
923
- @db = DummyDatabase.new
880
+ @db = Sequel.mock
924
881
  end
925
882
 
926
883
  specify "should construct proper SQL" do
927
884
  @db.set_column_type :test, :name, :integer
928
- @db.sqls.should == [
929
- 'ALTER TABLE test ALTER COLUMN name TYPE integer'
930
- ]
885
+ @db.sqls.should == ['ALTER TABLE test ALTER COLUMN name TYPE integer']
931
886
  end
932
887
  end
933
888
 
934
889
  describe "Database#set_column_default" do
935
890
  before do
936
- @db = DummyDatabase.new
891
+ @db = Sequel.mock
937
892
  end
938
893
 
939
894
  specify "should construct proper SQL" do
940
895
  @db.set_column_default :test, :name, 'zyx'
941
- @db.sqls.should == [
942
- "ALTER TABLE test ALTER COLUMN name SET DEFAULT 'zyx'"
943
- ]
896
+ @db.sqls.should == ["ALTER TABLE test ALTER COLUMN name SET DEFAULT 'zyx'"]
944
897
  end
945
898
  end
946
899
 
947
900
  describe "Database#add_index" do
948
901
  before do
949
- @db = DummyDatabase.new
902
+ @db = Sequel.mock
950
903
  end
951
904
 
952
905
  specify "should construct proper SQL" do
953
906
  @db.add_index :test, :name, :unique => true
954
- @db.sqls.should == [
955
- 'CREATE UNIQUE INDEX test_name_index ON test (name)'
956
- ]
907
+ @db.sqls.should == ['CREATE UNIQUE INDEX test_name_index ON test (name)']
957
908
  end
958
909
 
959
910
  specify "should accept multiple columns" do
960
911
  @db.add_index :test, [:one, :two]
961
- @db.sqls.should == [
962
- 'CREATE INDEX test_one_two_index ON test (one, two)'
963
- ]
912
+ @db.sqls.should == ['CREATE INDEX test_one_two_index ON test (one, two)']
964
913
  end
965
914
  end
966
915
 
967
916
  describe "Database#drop_index" do
968
917
  before do
969
- @db = DummyDatabase.new
918
+ @db = Sequel.mock
970
919
  end
971
920
 
972
921
  specify "should construct proper SQL" do
973
922
  @db.drop_index :test, :name
974
- @db.sqls.should == [
975
- 'DROP INDEX test_name_index'
976
- ]
923
+ @db.sqls.should == ['DROP INDEX test_name_index']
977
924
  end
978
925
 
979
926
  end
980
927
 
981
928
  describe "Database#drop_table" do
982
929
  before do
983
- @db = DummyDatabase.new
930
+ @db = Sequel.mock
984
931
  end
985
932
 
986
933
  specify "should construct proper SQL" do
@@ -990,17 +937,13 @@ describe "Database#drop_table" do
990
937
 
991
938
  specify "should accept multiple table names" do
992
939
  @db.drop_table :a, :bb, :ccc
993
- @db.sqls.should == [
994
- 'DROP TABLE a',
995
- 'DROP TABLE bb',
996
- 'DROP TABLE ccc'
997
- ]
940
+ @db.sqls.should == ['DROP TABLE a', 'DROP TABLE bb', 'DROP TABLE ccc']
998
941
  end
999
942
  end
1000
943
 
1001
944
  describe "Database#rename_table" do
1002
945
  before do
1003
- @db = DummyDatabase.new
946
+ @db = Sequel.mock
1004
947
  end
1005
948
 
1006
949
  specify "should construct proper SQL" do
@@ -1011,13 +954,12 @@ end
1011
954
 
1012
955
  describe "Database#create_view" do
1013
956
  before do
1014
- @db = DummyDatabase.new
957
+ @db = Sequel.mock
1015
958
  end
1016
959
 
1017
960
  specify "should construct proper SQL with raw SQL" do
1018
961
  @db.create_view :test, "SELECT * FROM xyz"
1019
962
  @db.sqls.should == ['CREATE VIEW test AS SELECT * FROM xyz']
1020
- @db.sqls.clear
1021
963
  @db.create_view :test.identifier, "SELECT * FROM xyz"
1022
964
  @db.sqls.should == ['CREATE VIEW test AS SELECT * FROM xyz']
1023
965
  end
@@ -1025,21 +967,6 @@ describe "Database#create_view" do
1025
967
  specify "should construct proper SQL with dataset" do
1026
968
  @db.create_view :test, @db[:items].select(:a, :b).order(:c)
1027
969
  @db.sqls.should == ['CREATE VIEW test AS SELECT a, b FROM items ORDER BY c']
1028
- @db.sqls.clear
1029
- @db.create_view :test.qualify(:sch), @db[:items].select(:a, :b).order(:c)
1030
- @db.sqls.should == ['CREATE VIEW sch.test AS SELECT a, b FROM items ORDER BY c']
1031
- end
1032
- end
1033
-
1034
- describe "Database#create_or_replace_view" do
1035
- before do
1036
- @db = DummyDatabase.new
1037
- end
1038
-
1039
- specify "should construct proper SQL with raw SQL" do
1040
- @db.create_or_replace_view :test, "SELECT * FROM xyz"
1041
- @db.sqls.should == ['CREATE OR REPLACE VIEW test AS SELECT * FROM xyz']
1042
- @db.sqls.clear
1043
970
  @db.create_or_replace_view :sch__test, "SELECT * FROM xyz"
1044
971
  @db.sqls.should == ['CREATE OR REPLACE VIEW sch.test AS SELECT * FROM xyz']
1045
972
  end
@@ -1047,7 +974,6 @@ describe "Database#create_or_replace_view" do
1047
974
  specify "should construct proper SQL with dataset" do
1048
975
  @db.create_or_replace_view :test, @db[:items].select(:a, :b).order(:c)
1049
976
  @db.sqls.should == ['CREATE OR REPLACE VIEW test AS SELECT a, b FROM items ORDER BY c']
1050
- @db.sqls.clear
1051
977
  @db.create_or_replace_view :test.identifier, @db[:items].select(:a, :b).order(:c)
1052
978
  @db.sqls.should == ['CREATE OR REPLACE VIEW test AS SELECT a, b FROM items ORDER BY c']
1053
979
  end
@@ -1055,7 +981,7 @@ end
1055
981
 
1056
982
  describe "Database#drop_view" do
1057
983
  before do
1058
- @db = DummyDatabase.new
984
+ @db = Sequel.mock
1059
985
  end
1060
986
 
1061
987
  specify "should construct proper SQL" do
@@ -1078,12 +1004,8 @@ describe "Database#drop_view" do
1078
1004
  end
1079
1005
 
1080
1006
  describe "Database#alter_table_sql" do
1081
- before do
1082
- @db = DummyDatabase.new
1083
- end
1084
-
1085
1007
  specify "should raise error for an invalid op" do
1086
- proc {@db.send(:alter_table_sql, :mau, :op => :blah)}.should raise_error(Sequel::Error)
1008
+ proc {Sequel.mock.send(:alter_table_sql, :mau, :op => :blah)}.should raise_error(Sequel::Error)
1087
1009
  end
1088
1010
  end
1089
1011
 
@@ -1100,6 +1022,21 @@ describe "Schema Parser" do
1100
1022
  proc{@db.schema(:x)}.should raise_error(Sequel::Error)
1101
1023
  end
1102
1024
 
1025
+ specify "should provide options if given a table name" do
1026
+ c = nil
1027
+ @db.meta_def(:schema_parse_table) do |t, opts|
1028
+ c = [t, opts]
1029
+ [[:a, {:db_type=>t.to_s}]]
1030
+ end
1031
+ @db.schema(:x)
1032
+ c.should == ["x", {}]
1033
+ @db.schema(:s__x)
1034
+ c.should == ["x", {:schema=>"s"}]
1035
+ ds = @db[:s__y]
1036
+ @db.schema(ds)
1037
+ c.should == ["y", {:schema=>"s", :dataset=>ds}]
1038
+ end
1039
+
1103
1040
  specify "should parse the schema correctly for a single table" do
1104
1041
  sqls = @sqls
1105
1042
  proc{@db.schema(:x)}.should raise_error(Sequel::Error)