dm-migrations 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname + '../../spec_helper'
3
+
4
+ require Pathname(__FILE__).dirname + '../../../lib/sql/column'
5
+
6
+ describe SQL::Column do
7
+ before do
8
+ @column = SQL::Column.new
9
+ end
10
+
11
+ %w{name type not_null default_value primary_key unique}.each do |meth|
12
+ it "should have a ##{meth} attribute" do
13
+ @column.should respond_to(meth.intern)
14
+ end
15
+ end
16
+
17
+ end
18
+
@@ -0,0 +1,99 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname + '../../spec_helper'
3
+
4
+ require Pathname(__FILE__).dirname + '../../../lib/sql/sqlite3'
5
+
6
+ # a dummy class to include the module into
7
+ class PostgresqlExtension
8
+ include SQL::Postgresql
9
+ end
10
+
11
+ describe "SQLite3 Extensions" do
12
+ before do
13
+ @pe = PostgresqlExtension.new
14
+ end
15
+
16
+ it 'should support schema-level transactions' do
17
+ @pe.supports_schema_transactions?.should be_true
18
+ end
19
+
20
+ it 'should support the serial column attribute' do
21
+ @pe.supports_serial?.should be_true
22
+ end
23
+
24
+ it 'should create a table object from the name' do
25
+ table = mock('SQLite3 Table')
26
+ SQL::Postgresql::Table.should_receive(:new).with(@pe, 'users').and_return(table)
27
+
28
+ @pe.table('users').should == table
29
+ end
30
+
31
+ describe 'recreating the database' do
32
+ end
33
+
34
+ describe 'Table' do
35
+ before do
36
+ @cs1 = mock('Column Struct')
37
+ @cs2 = mock('Column Struct')
38
+ @adapter = mock('adapter', :query => [])
39
+ @adapter.stub!(:query_table).with('users').and_return([@cs1, @cs2])
40
+
41
+ @col1 = mock('SQLite3 Column')
42
+ @col2 = mock('SQLite3 Column')
43
+ SQL::Postgresql::Column.stub!(:new).and_return(@col1, @col2)
44
+ end
45
+
46
+ it 'should initialize columns by querying the table' do
47
+ @adapter.should_receive(:query_table).with('users').and_return([@cs1,@cs2])
48
+ SQL::Postgresql::Table.new(@adapter, 'users')
49
+ end
50
+
51
+ it 'should create SQLite3 Column objects from the returned column structs' do
52
+ SQL::Postgresql::Column.should_receive(:new).with(@cs1).and_return(@col1)
53
+ SQL::Postgresql::Column.should_receive(:new).with(@cs2).and_return(@col2)
54
+ SQL::Postgresql::Table.new(@adapter, 'users')
55
+ end
56
+
57
+ it 'should set the @columns to the looked-up columns' do
58
+ t = SQL::Postgresql::Table.new(@adapter, 'users')
59
+ t.columns.should == [@col1, @col2]
60
+ end
61
+
62
+ describe '#query_column_constraints' do
63
+
64
+ end
65
+
66
+ end
67
+
68
+ describe 'Column' do
69
+ before do
70
+ @cs = mock('Struct',
71
+ :column_name => 'id',
72
+ :data_type => 'integer',
73
+ :column_default => 123,
74
+ :is_nullable => 'NO')
75
+ @c = SQL::Postgresql::Column.new(@cs)
76
+ end
77
+
78
+ it 'should set the name from the column_name value' do
79
+ @c.name.should == 'id'
80
+ end
81
+
82
+ it 'should set the type from the data_type value' do
83
+ @c.type.should == 'integer'
84
+ end
85
+
86
+ it 'should set the default_value from the column_default value' do
87
+ @c.default_value.should == 123
88
+ end
89
+
90
+ it 'should set not_null based on the is_nullable value' do
91
+ @c.not_null.should == true
92
+ end
93
+
94
+ end
95
+
96
+
97
+ end
98
+
99
+
@@ -0,0 +1,109 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname + '../../spec_helper'
3
+
4
+ require Pathname(__FILE__).dirname + '../../../lib/sql/sqlite3'
5
+
6
+ # a dummy class to include the module into
7
+ class Sqlite3Extension
8
+ include SQL::Sqlite3
9
+ end
10
+
11
+ describe "SQLite3 Extensions" do
12
+ before do
13
+ @se = Sqlite3Extension.new
14
+ end
15
+
16
+ it 'should support schema-level transactions' do
17
+ @se.supports_schema_transactions?.should be_true
18
+ end
19
+
20
+ it 'should support the serial column attribute' do
21
+ @se.supports_serial?.should be_true
22
+ end
23
+
24
+ it 'should create a table object from the name' do
25
+ table = mock('SQLite3 Table')
26
+ SQL::Sqlite3::Table.should_receive(:new).with(@se, 'users').and_return(table)
27
+
28
+ @se.table('users').should == table
29
+ end
30
+
31
+ describe 'recreating the database' do
32
+ before do
33
+ uri = mock('URI', :path => '/foo/bar.db')
34
+ @se.instance_variable_set('@uri', uri)
35
+ end
36
+
37
+ it 'should rm the db file' do
38
+ @se.should_receive(:system).with('rm /foo/bar.db')
39
+ @se.recreate_database
40
+ end
41
+
42
+ end
43
+
44
+ describe 'Table' do
45
+ before do
46
+ @cs1 = mock('Column Struct')
47
+ @cs2 = mock('Column Struct')
48
+ @adapter = mock('adapter')
49
+ @adapter.stub!(:query_table).with('users').and_return([@cs1, @cs2])
50
+
51
+ @col1 = mock('SQLite3 Column')
52
+ @col2 = mock('SQLite3 Column')
53
+ SQL::Sqlite3::Column.stub!(:new).and_return(@col1, @col2)
54
+ end
55
+
56
+ it 'should initialize columns by querying the table' do
57
+ @adapter.should_receive(:query_table).with('users').and_return([@cs1,@cs2])
58
+ SQL::Sqlite3::Table.new(@adapter, 'users')
59
+ end
60
+
61
+ it 'should create SQLite3 Column objects from the returned column structs' do
62
+ SQL::Sqlite3::Column.should_receive(:new).with(@cs1).and_return(@col1)
63
+ SQL::Sqlite3::Column.should_receive(:new).with(@cs2).and_return(@col2)
64
+ SQL::Sqlite3::Table.new(@adapter, 'users')
65
+ end
66
+
67
+ it 'should set the @columns to the looked-up columns' do
68
+ t = SQL::Sqlite3::Table.new(@adapter, 'users')
69
+ t.columns.should == [@col1, @col2]
70
+ end
71
+
72
+ end
73
+
74
+ describe 'Column' do
75
+ before do
76
+ @cs = mock('Struct',
77
+ :name => 'id',
78
+ :type => 'integer',
79
+ :dflt_value => 123,
80
+ :pk => true,
81
+ :notnull => 0)
82
+ @c = SQL::Sqlite3::Column.new(@cs)
83
+ end
84
+
85
+ it 'should set the name from the name value' do
86
+ @c.name.should == 'id'
87
+ end
88
+
89
+ it 'should set the type from the type value' do
90
+ @c.type.should == 'integer'
91
+ end
92
+
93
+ it 'should set the default_value from the dflt_value value' do
94
+ @c.default_value.should == 123
95
+ end
96
+
97
+ it 'should set the primary_key from the pk value' do
98
+ @c.primary_key.should == true
99
+ end
100
+
101
+ it 'should set not_null based on the notnull value' do
102
+ @c.not_null.should == true
103
+ end
104
+
105
+ end
106
+
107
+
108
+ end
109
+
@@ -0,0 +1,93 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname + '../../spec_helper'
3
+
4
+ require Pathname(__FILE__).dirname + '../../../lib/sql/table_creator'
5
+
6
+ describe 'SQL module' do
7
+ describe 'TableCreator' do
8
+ before do
9
+ @adapter = mock('adapter')
10
+ @adapter.stub!(:quote_table_name).and_return(%{'users'})
11
+ @tc = SQL::TableCreator.new(@adapter, 'users') { }
12
+ end
13
+
14
+ describe 'initialization' do
15
+ it 'should set @adapter to the adapter' do
16
+ @tc.instance_variable_get("@adapter").should == @adapter
17
+ end
18
+
19
+ it 'should set @table_name to the stringified table name' do
20
+ @tc.instance_variable_get("@table_name").should == 'users'
21
+ end
22
+
23
+ it 'should set @opts to the options hash' do
24
+ @tc.instance_variable_get("@opts").should == {}
25
+ end
26
+
27
+ it 'should set @columns to an empty array' do
28
+ @tc.instance_variable_get("@columns").should == []
29
+ end
30
+
31
+ it 'should evaluate the given block' do
32
+ block = lambda { column :foo, :bar }
33
+ col = mock('column')
34
+ SQL::TableCreator::Column.should_receive(:new).with(@adapter, :foo, :bar, {}).and_return(col)
35
+ tc = SQL::TableCreator.new(@adapter, 'users', {}, &block)
36
+ tc.instance_variable_get("@columns").should == [col]
37
+ end
38
+ end
39
+
40
+ it 'should have a table_name' do
41
+ @tc.should respond_to(:table_name)
42
+ @tc.table_name.should == 'users'
43
+ end
44
+
45
+ it 'should use the adapter to quote the table name' do
46
+ @adapter.should_receive(:quote_table_name).with('users').and_return(%{'users'})
47
+ @tc.quoted_table_name.should == %{'users'}
48
+ end
49
+
50
+ it 'should initialze a new column and add it to the list of columns' do
51
+ col = mock('column')
52
+ SQL::TableCreator::Column.should_receive(:new).with(@adapter, :foo, :bar, {}).and_return(col)
53
+ @tc.column(:foo, :bar)
54
+ @tc.instance_variable_get("@columns").should == [col]
55
+ end
56
+
57
+ it 'should output an SQL CREATE statement to build itself' do
58
+ @tc.to_sql.should ==
59
+ %{CREATE TABLE 'users' ()}
60
+ end
61
+
62
+ describe 'Column' do
63
+ before do
64
+ @adapter.stub!(:quote_column_name).and_return(%{'id'})
65
+ @adapter.class.stub!(:type_map).and_return(Integer => {:type => 'int'})
66
+ @adapter.stub!(:property_schema_statement).and_return("SOME SQL")
67
+ @c = SQL::TableCreator::Column.new(@adapter, 'id', Integer, :serial => true)
68
+ end
69
+
70
+ describe 'initialization' do
71
+ it 'should set @adapter to the adapter' do
72
+ @c.instance_variable_get("@adapter").should == @adapter
73
+ end
74
+
75
+ it 'should set @name to the stringified name' do
76
+ @c.instance_variable_get("@name").should == 'id'
77
+ end
78
+
79
+ # TODO make this really the type, not this sql bullshit
80
+ it 'should set @type to the type' do
81
+ @c.instance_variable_get("@type").should == "SOME SQL"
82
+ end
83
+
84
+ it 'should set @opts to the options hash' do
85
+ @c.instance_variable_get("@opts").should == {:serial => true}
86
+ end
87
+
88
+ end
89
+
90
+ end
91
+ end
92
+
93
+ end
@@ -0,0 +1,52 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname + '../../spec_helper'
3
+
4
+ require Pathname(__FILE__).dirname + '../../../lib/sql/table_modifier'
5
+
6
+ describe 'SQL module' do
7
+ describe 'TableModifier' do
8
+ before do
9
+ @adapter = mock('adapter')
10
+ @adapter.stub!(:quote_table_name).and_return(%{'users'})
11
+ @tc = SQL::TableModifier.new(@adapter, :users) { }
12
+ end
13
+
14
+ describe 'initialization' do
15
+ it 'should set @adapter to the adapter' do
16
+ @tc.instance_variable_get("@adapter").should == @adapter
17
+ end
18
+
19
+ it 'should set @table_name to the stringified table name' do
20
+ @tc.instance_variable_get("@table_name").should == 'users'
21
+ end
22
+
23
+ it 'should set @opts to the options hash' do
24
+ @tc.instance_variable_get("@opts").should == {}
25
+ end
26
+
27
+ it 'should set @statements to an empty array' do
28
+ @tc.instance_variable_get("@statements").should == []
29
+ end
30
+
31
+ it 'should evaluate the given block' do
32
+ block = lambda { column :foo, :bar }
33
+ col = mock('column')
34
+ SQL::TableCreator::Column.should_receive(:new).with(@adapter, :foo, :bar, {}).and_return(col)
35
+ tc = SQL::TableCreator.new(@adapter, 'users', {}, &block)
36
+ tc.instance_variable_get("@columns").should == [col]
37
+ end
38
+ end
39
+
40
+ it 'should have a table_name' do
41
+ @tc.should respond_to(:table_name)
42
+ @tc.table_name.should == 'users'
43
+ end
44
+
45
+ it 'should use the adapter to quote the table name' do
46
+ @adapter.should_receive(:quote_table_name).with('users').and_return(%{'users'})
47
+ @tc.quoted_table_name.should == %{'users'}
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,31 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname + '../../spec_helper'
3
+
4
+ require Pathname(__FILE__).dirname + '../../../lib/sql/table'
5
+
6
+ describe SQL::Table do
7
+ before do
8
+ @table = SQL::Table.new
9
+ end
10
+
11
+ %w{name columns}.each do |meth|
12
+ it "should have a ##{meth} attribute" do
13
+ @table.should respond_to(meth.intern)
14
+ end
15
+ end
16
+
17
+ it 'should #to_s as the name' do
18
+ @table.name = "table_name"
19
+ @table.to_s.should == "table_name"
20
+ end
21
+
22
+ it 'should find a column by name' do
23
+ column_a = mock('column', :name => 'id')
24
+ column_b = mock('column', :name => 'login')
25
+ @table.columns = [column_a, column_b]
26
+
27
+ @table.column('id').should == column_a
28
+ end
29
+
30
+
31
+ end
@@ -0,0 +1,10 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname + '../spec_helper'
3
+
4
+ require Pathname(__FILE__).dirname + '../../lib/sql'
5
+
6
+ describe 'SQL module' do
7
+
8
+ it 'doesnt really do anything'
9
+
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Sadauskas
@@ -9,54 +9,85 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-25 00:00:00 -05:00
12
+ date: 2008-07-24 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: dm-core
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - "="
21
22
  - !ruby/object:Gem::Version
22
- version: 0.9.2
23
+ version: 0.9.3
23
24
  version:
24
- description: DataMapper plugin for writing and specing migrations
25
- email: psadauskas@gmail.com
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.0
34
+ version:
35
+ description: DataMapper plugin for writing and speccing migrations
36
+ email:
37
+ - psadauskas@gmail.com
26
38
  executables: []
27
39
 
28
40
  extensions: []
29
41
 
30
42
  extra_rdoc_files:
31
- - README
43
+ - README.txt
32
44
  - LICENSE
33
45
  - TODO
34
46
  files:
47
+ - History.txt
48
+ - LICENSE
49
+ - Manifest.txt
50
+ - README.txt
51
+ - Rakefile
52
+ - TODO
53
+ - db/migrations/1_create_people_table.rb
54
+ - db/migrations/2_add_dob_to_people.rb
55
+ - db/migrations/config.rb
56
+ - examples/sample_migration.rb
57
+ - examples/sample_migration_spec.rb
35
58
  - lib/dm-migrations.rb
59
+ - lib/dm-migrations/version.rb
36
60
  - lib/migration.rb
37
61
  - lib/migration_runner.rb
38
62
  - lib/spec/example/migration_example_group.rb
39
63
  - lib/spec/matchers/migration_matchers.rb
64
+ - lib/sql.rb
40
65
  - lib/sql/column.rb
41
66
  - lib/sql/mysql.rb
42
67
  - lib/sql/postgresql.rb
43
68
  - lib/sql/sqlite3.rb
44
69
  - lib/sql/table.rb
45
- - lib/sql.rb
70
+ - lib/sql/table_creator.rb
71
+ - lib/sql/table_modifier.rb
46
72
  - spec/integration/migration_runner_spec.rb
47
73
  - spec/integration/migration_spec.rb
48
74
  - spec/integration/sql_spec.rb
49
- - spec/spec_helper.rb
50
75
  - spec/spec.opts
51
- - Rakefile
52
- - README
53
- - LICENSE
54
- - TODO
76
+ - spec/spec_helper.rb
77
+ - spec/unit/migration_spec.rb
78
+ - spec/unit/sql/column_spec.rb
79
+ - spec/unit/sql/postgresql_spec.rb
80
+ - spec/unit/sql/sqlite3_extensions_spec.rb
81
+ - spec/unit/sql/table_creator_spec.rb
82
+ - spec/unit/sql/table_modifier_spec.rb
83
+ - spec/unit/sql/table_spec.rb
84
+ - spec/unit/sql_spec.rb
55
85
  has_rdoc: true
56
86
  homepage: http://github.com/sam/dm-more/tree/master/dm-migrations
57
87
  post_install_message:
58
- rdoc_options: []
59
-
88
+ rdoc_options:
89
+ - --main
90
+ - README.txt
60
91
  require_paths:
61
92
  - lib
62
93
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -73,10 +104,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
104
  version:
74
105
  requirements: []
75
106
 
76
- rubyforge_project:
77
- rubygems_version: 1.0.1
107
+ rubyforge_project: datamapper
108
+ rubygems_version: 1.2.0
78
109
  signing_key:
79
110
  specification_version: 2
80
- summary: DataMapper plugin for writing and specing migrations
111
+ summary: DataMapper plugin for writing and speccing migrations
81
112
  test_files: []
82
113