Permalink
Browse files

Move some more specs from database_spec to schema_spec

Add a spec for Database#drop_column with :cascade.

Also, move some classes to spec_helper.  Inline classes in
multithousand line spec files are not a good thing.
  • Loading branch information...
1 parent 27c0b71 commit 93e1b597e11cd0c39b3add471ef9336e0da763e5 @jeremyevans jeremyevans committed Jun 7, 2011
Showing with 231 additions and 227 deletions.
  1. +0 −227 spec/core/database_spec.rb
  2. +202 −0 spec/core/schema_spec.rb
  3. +29 −0 spec/core/spec_helper.rb
View
@@ -478,233 +478,6 @@ def @o.to_ary; [self]; end
end
end
-class DummyDataset < Sequel::Dataset
- def first
- raise if @opts[:from] == [:a]
- true
- end
-end
-
-class DummyDatabase < Sequel::Database
- attr_reader :sqls
-
- def execute(sql, opts={})
- @sqls ||= []
- @sqls << sql
- end
-
- def transaction; yield; end
-
- def dataset
- DummyDataset.new(self)
- end
-end
-
-describe "Database#create_table" do
- before do
- @db = DummyDatabase.new
- end
-
- specify "should construct proper SQL" do
- @db.create_table :test do
- primary_key :id, :integer, :null => false
- column :name, :text
- index :name, :unique => true
- end
- @db.sqls.should == [
- 'CREATE TABLE test (id integer NOT NULL PRIMARY KEY AUTOINCREMENT, name text)',
- 'CREATE UNIQUE INDEX test_name_index ON test (name)'
- ]
- end
-
- specify "should create a temporary table" do
- @db.create_table :test_tmp, :temp => true do
- primary_key :id, :integer, :null => false
- column :name, :text
- index :name, :unique => true
- end
-
- @db.sqls.should == [
- 'CREATE TEMPORARY TABLE test_tmp (id integer NOT NULL PRIMARY KEY AUTOINCREMENT, name text)',
- 'CREATE UNIQUE INDEX test_tmp_name_index ON test_tmp (name)'
- ]
- end
-
- specify "should not use default schema when creating a temporary table" do
- @db.default_schema = :foo
- @db.create_table :test_tmp, :temp => true do
- column :name, :text
- end
- @db.sqls.should == ['CREATE TEMPORARY TABLE test_tmp (name text)']
- end
-end
-
-describe "Database#alter_table" do
- before do
- @db = DummyDatabase.new
- end
-
- specify "should construct proper SQL" do
- @db.alter_table :xyz do
- add_column :aaa, :text, :null => false, :unique => true
- drop_column :bbb
- rename_column :ccc, :ddd
- set_column_type :eee, :integer
- set_column_default :hhh, 'abcd'
-
- add_index :fff, :unique => true
- drop_index :ggg
- end
-
- @db.sqls.should == [
- 'ALTER TABLE xyz ADD COLUMN aaa text NOT NULL UNIQUE',
- 'ALTER TABLE xyz DROP COLUMN bbb',
- 'ALTER TABLE xyz RENAME COLUMN ccc TO ddd',
- 'ALTER TABLE xyz ALTER COLUMN eee TYPE integer',
- "ALTER TABLE xyz ALTER COLUMN hhh SET DEFAULT 'abcd'",
-
- 'CREATE UNIQUE INDEX xyz_fff_index ON xyz (fff)',
- 'DROP INDEX xyz_ggg_index'
- ]
- end
-end
-
-describe "Database#add_column" do
- before do
- @db = DummyDatabase.new
- end
-
- specify "should construct proper SQL" do
- @db.add_column :test, :name, :text, :unique => true
- @db.sqls.should == [
- 'ALTER TABLE test ADD COLUMN name text UNIQUE'
- ]
- end
-end
-
-describe "Database#drop_column" do
- before do
- @db = DummyDatabase.new
- end
-
- specify "should construct proper SQL" do
- @db.drop_column :test, :name
- @db.sqls.should == [
- 'ALTER TABLE test DROP COLUMN name'
- ]
- end
-end
-
-describe "Database#rename_column" do
- before do
- @db = DummyDatabase.new
- end
-
- specify "should construct proper SQL" do
- @db.rename_column :test, :abc, :def
- @db.sqls.should == [
- 'ALTER TABLE test RENAME COLUMN abc TO def'
- ]
- end
-end
-
-describe "Database#set_column_type" do
- before do
- @db = DummyDatabase.new
- end
-
- specify "should construct proper SQL" do
- @db.set_column_type :test, :name, :integer
- @db.sqls.should == [
- 'ALTER TABLE test ALTER COLUMN name TYPE integer'
- ]
- end
-end
-
-describe "Database#set_column_default" do
- before do
- @db = DummyDatabase.new
- end
-
- specify "should construct proper SQL" do
- @db.set_column_default :test, :name, 'zyx'
- @db.sqls.should == [
- "ALTER TABLE test ALTER COLUMN name SET DEFAULT 'zyx'"
- ]
- end
-end
-
-describe "Database#add_index" do
- before do
- @db = DummyDatabase.new
- end
-
- specify "should construct proper SQL" do
- @db.add_index :test, :name, :unique => true
- @db.sqls.should == [
- 'CREATE UNIQUE INDEX test_name_index ON test (name)'
- ]
- end
-
- specify "should accept multiple columns" do
- @db.add_index :test, [:one, :two]
- @db.sqls.should == [
- 'CREATE INDEX test_one_two_index ON test (one, two)'
- ]
- end
-end
-
-describe "Database#drop_index" do
- before do
- @db = DummyDatabase.new
- end
-
- specify "should construct proper SQL" do
- @db.drop_index :test, :name
- @db.sqls.should == [
- 'DROP INDEX test_name_index'
- ]
- end
-
-end
-
-class Dummy2Database < Sequel::Database
- attr_reader :sql
- def execute(sql); @sql = sql; end
- def transaction; yield; end
-end
-
-describe "Database#drop_table" do
- before do
- @db = DummyDatabase.new
- end
-
- specify "should construct proper SQL" do
- @db.drop_table :test
- @db.sqls.should == ['DROP TABLE test']
- end
-
- specify "should accept multiple table names" do
- @db.drop_table :a, :bb, :ccc
- @db.sqls.should == [
- 'DROP TABLE a',
- 'DROP TABLE bb',
- 'DROP TABLE ccc'
- ]
- end
-end
-
-describe "Database#rename_table" do
- before do
- @db = DummyDatabase.new
- end
-
- specify "should construct proper SQL" do
- @db.rename_table :abc, :xyz
- @db.sqls.should == ['ALTER TABLE abc RENAME TO xyz']
- end
-end
-
describe "Database#table_exists?" do
specify "should try to select the first record from the table's dataset" do
db2 = DummyDatabase.new
Oops, something went wrong.

0 comments on commit 93e1b59

Please sign in to comment.