migration_test_helper 1.0.0 → 1.1.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/README +13 -2
- data/Rakefile +4 -1
- data/lib/migration_test_helper.rb +20 -2
- data/test/db/migrate_bad/001_create_top_dogs.rb +8 -0
- data/test/db/schema.rb +1 -1
- data/test/migration_test_helper_test.rb +67 -5
- metadata +3 -1
data/README
CHANGED
@@ -32,7 +32,7 @@ If you're using it outside of a Rails environment (for whatever reason) include
|
|
32
32
|
assert_schema do |s|
|
33
33
|
s.table :books do |t|
|
34
34
|
t.column :id, :integer
|
35
|
-
t.column :title, :string
|
35
|
+
t.column :title, :string, :limit => 5
|
36
36
|
t.column :author, :string
|
37
37
|
end
|
38
38
|
|
@@ -40,7 +40,7 @@ If you're using it outside of a Rails environment (for whatever reason) include
|
|
40
40
|
t.column :id, :integer
|
41
41
|
t.column :book_id, :integer
|
42
42
|
t.column :body, :text
|
43
|
-
t.column :rating, :integer
|
43
|
+
t.column :rating, :integer, :default => 0
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -48,8 +48,18 @@ If you're using it outside of a Rails environment (for whatever reason) include
|
|
48
48
|
This would verify there are only two tables defined in the test database: _books_ and _reviews_ (schema_info is ignored). It will also verify that the _book_ table has the three columns, _id_, _title_ and _author_, each with their respective types.
|
49
49
|
|
50
50
|
|
51
|
+
*assert_table*: verify a table is found exactly as specified:
|
52
|
+
|
53
|
+
assert_table :books do |t|
|
54
|
+
t.column :id, :integer
|
55
|
+
t.column :title, :string, :limit => 5
|
56
|
+
t.column :author, :string
|
57
|
+
end
|
58
|
+
|
59
|
+
|
51
60
|
*drop_all_tables*: does just what it says to your _test_ database.
|
52
61
|
|
62
|
+
|
53
63
|
*migrate*: executes the migrations against the test database using the same mechanism as rake db:migrate.
|
54
64
|
|
55
65
|
def test_the_migrations
|
@@ -101,6 +111,7 @@ The *migrate* helper can also be useful for testing data tranformation migration
|
|
101
111
|
def test_should_get_rid_of_bad_data
|
102
112
|
drop_all_tables
|
103
113
|
migrate :version => 7
|
114
|
+
Book.reset_column_information
|
104
115
|
book = Book.create! :title => "bad title\nwith\todd spacing"
|
105
116
|
migrate :version => 8 # should cleanse spacing in book titles
|
106
117
|
book.reload
|
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
16
16
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
17
|
end
|
18
18
|
|
19
|
-
GEM_VERSION = '1.
|
19
|
+
GEM_VERSION = '1.1.0'
|
20
20
|
|
21
21
|
Hoe.new('migration_test_helper',GEM_VERSION) do |p|
|
22
22
|
p.author = "Micah Alles"
|
@@ -33,6 +33,9 @@ test database.
|
|
33
33
|
p.gem_files = FileList["{test,lib,tasks}/**/*"] + %w|LICENSE README Rakefile init.rb install.rb uninstall.rb|
|
34
34
|
|
35
35
|
p.changes = <<-EOS
|
36
|
+
* added assert_table() for checking a single table instead of entire schema
|
37
|
+
|
38
|
+
* options can now be verfied on a column: t.column :name, :string, :default => 'hot cookie', :limit => 10
|
36
39
|
EOS
|
37
40
|
p.rubyforge_name = 'migrationtest'
|
38
41
|
end
|
@@ -40,7 +40,7 @@ module MigrationTestHelper
|
|
40
40
|
#
|
41
41
|
# assert_schema do |s|
|
42
42
|
# s.table :dogs do |t|
|
43
|
-
# t.column :id, :integer
|
43
|
+
# t.column :id, :integer, :default => 2
|
44
44
|
# t.column :name, :string
|
45
45
|
# end
|
46
46
|
# end
|
@@ -51,6 +51,20 @@ module MigrationTestHelper
|
|
51
51
|
schema.verify
|
52
52
|
end
|
53
53
|
|
54
|
+
#
|
55
|
+
# verifies a single table exactly matches the one specified
|
56
|
+
#
|
57
|
+
# assert_table :dogs do |t|
|
58
|
+
# t.column :id, :integer, :default => 2
|
59
|
+
# t.column :name, :string
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
def assert_table(name)
|
63
|
+
table = Table.new(name)
|
64
|
+
yield table
|
65
|
+
table.verify
|
66
|
+
end
|
67
|
+
|
54
68
|
#
|
55
69
|
# drops all tables in the database
|
56
70
|
#
|
@@ -111,12 +125,16 @@ module MigrationTestHelper
|
|
111
125
|
assert conn.tables.include?(@name), "table <#{@name}> not found in schema"
|
112
126
|
end
|
113
127
|
|
114
|
-
def column(colname,type)
|
128
|
+
def column(colname,type,options={})
|
115
129
|
colname = colname.to_s
|
116
130
|
@columns << colname
|
117
131
|
col = conn.columns(name).find {|c| c.name == colname }
|
118
132
|
assert_not_nil col, "column <#{colname}> not found in table <#{self.name}>"
|
119
133
|
assert_equal type, col.type, "wrong type for column <#{colname}> in table <#{name}>"
|
134
|
+
options.each do |k,v|
|
135
|
+
k = k.to_sym
|
136
|
+
assert_equal v, col.send(k), "column <#{colname}> in table <#{name}> has wrong :#{k}"
|
137
|
+
end
|
120
138
|
end
|
121
139
|
|
122
140
|
def verify #:nodoc:
|
data/test/db/schema.rb
CHANGED
@@ -31,20 +31,20 @@ class MigrationTestHelperTest < Test::Unit::TestCase
|
|
31
31
|
assert_schema do |s|
|
32
32
|
s.table :dogs do |t|
|
33
33
|
t.column :id, :integer
|
34
|
-
t.column :tail, :string
|
34
|
+
t.column :tail, :string, :default => 'top dog', :limit => 187
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def test_assert_schema_should_fail_if_a_table_is_not_specified
|
41
41
|
see_failure 'wrong tables in schema.*dogs' do
|
42
42
|
assert_schema do |s|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
47
|
+
def test_assert_schema_should_fail_if_a_table_is_not_found
|
48
48
|
see_failure 'table <things> not found in schema' do
|
49
49
|
assert_schema do |s|
|
50
50
|
s.table :things do |t|
|
@@ -54,7 +54,7 @@ class MigrationTestHelperTest < Test::Unit::TestCase
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
57
|
+
def test_assert_schema_should_fail_if_a_column_is_not_specified
|
58
58
|
see_failure 'wrong columns for table.*dogs.*tail' do
|
59
59
|
assert_schema do |s|
|
60
60
|
s.table :dogs do |t|
|
@@ -64,7 +64,7 @@ class MigrationTestHelperTest < Test::Unit::TestCase
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
67
|
+
def test_assert_schema_should_fail_if_a_column_is_not_found
|
68
68
|
see_failure 'column <legs> not found in table <dogs>' do
|
69
69
|
assert_schema do |s|
|
70
70
|
s.table :dogs do |t|
|
@@ -76,6 +76,59 @@ class MigrationTestHelperTest < Test::Unit::TestCase
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
+
def test_assert_schema_should_fail_if_wrong_options_not_specified
|
80
|
+
see_failure 'column <tail> in table <dogs> has wrong :default' do
|
81
|
+
assert_table :dogs do |t|
|
82
|
+
t.column :id, :integer
|
83
|
+
t.column :tail, :string, :default => "blah"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_assert_table_should_not_fail_if_table_is_matched
|
89
|
+
see_no_failure do
|
90
|
+
assert_table :dogs do |t|
|
91
|
+
t.column :id, :integer
|
92
|
+
t.column :tail, :string, :default => 'top dog', :limit => 187
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_assert_table_should_fail_if_a_table_is_not_found
|
98
|
+
see_failure 'table <things> not found in schema' do
|
99
|
+
assert_table :things do |t|
|
100
|
+
t.column :id, :integer
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_assert_table_should_fail_if_a_column_is_not_specified
|
106
|
+
see_failure 'wrong columns for table.*dogs.*tail' do
|
107
|
+
assert_table :dogs do |t|
|
108
|
+
t.column :id, :integer
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_assert_table_should_fail_if_a_column_is_not_found
|
114
|
+
see_failure 'column <legs> not found in table <dogs>' do
|
115
|
+
assert_table :dogs do |t|
|
116
|
+
t.column :id, :integer
|
117
|
+
t.column :tail, :string
|
118
|
+
t.column :legs, :integer
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_assert_table_should_fail_if_wrong_options_not_specified
|
124
|
+
see_failure 'column <tail> in table <dogs> has wrong :default' do
|
125
|
+
assert_table :dogs do |t|
|
126
|
+
t.column :id, :integer
|
127
|
+
t.column :tail, :string, :default => "blah"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
79
132
|
def test_should_drop_all_tables
|
80
133
|
assert_equal ['dogs','schema_info'].sort, ActiveRecord::Base.connection.tables.sort
|
81
134
|
drop_all_tables
|
@@ -160,5 +213,14 @@ class MigrationTestHelperTest < Test::Unit::TestCase
|
|
160
213
|
"wrong default migration dir"
|
161
214
|
|
162
215
|
end
|
216
|
+
|
217
|
+
def test_should_raise_error_if_migration_fails
|
218
|
+
MigrationTestHelper.migration_dir = plugin_path('test/db/migrate_bad')
|
219
|
+
drop_all_tables
|
220
|
+
err = assert_raise RuntimeError do
|
221
|
+
migrate
|
222
|
+
end
|
223
|
+
assert_match(//i, err.message)
|
224
|
+
end
|
163
225
|
end
|
164
226
|
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: migration_test_helper
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
6
|
+
version: 1.1.0
|
7
7
|
date: 2007-01-30 00:00:00 -05:00
|
8
8
|
summary: A Rails plugin for testing migrations
|
9
9
|
require_paths:
|
@@ -34,8 +34,10 @@ files:
|
|
34
34
|
- test/log
|
35
35
|
- test/migration_test_helper_test.rb
|
36
36
|
- test/config/database.yml
|
37
|
+
- test/db/migrate_bad
|
37
38
|
- test/db/migrate_good
|
38
39
|
- test/db/schema.rb
|
40
|
+
- test/db/migrate_bad/001_create_top_dogs.rb
|
39
41
|
- test/db/migrate_good/001_create_top_dogs.rb
|
40
42
|
- test/db/migrate_good/002_create_bottom_dogs.rb
|
41
43
|
- test/db/migrate_good/003_create_cats.rb
|