migration-spec 0.1.1
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/.document +5 -0
- data/.gitignore +21 -0
- data/.rspec +1 -0
- data/LICENSE +20 -0
- data/README.markdown +71 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/migration-spec.rb +1 -0
- data/lib/migration-spec/main.rb +13 -0
- data/lib/migration-spec/matchers/content/have_column.rb +33 -0
- data/lib/migration-spec/matchers/content/have_index.rb +13 -0
- data/lib/migration-spec/matchers/content/have_table.rb +18 -0
- data/lib/migration-spec/matchers/content/have_tbl_column.rb +17 -0
- data/lib/migration-spec/matchers/content/have_up_down.rb +15 -0
- data/lib/migration-spec/matchers/generate_migration.rb +7 -0
- data/migration-spec.gemspec +91 -0
- data/spec/migration-spec/fixtures/db/migrations/001_do_columns.rb +13 -0
- data/spec/migration-spec/fixtures/db/migrations/002_do_index.rb +14 -0
- data/spec/migration-spec/fixtures/db/migrations/003_do_tables.rb +40 -0
- data/spec/migration-spec/fixtures/db/migrations/004_do_tbl_columns.rb +13 -0
- data/spec/migration-spec/fixtures/db/migrations/005_do_up_down.rb +21 -0
- data/spec/migration-spec/matchers/content/have_column_spec.rb +24 -0
- data/spec/migration-spec/matchers/content/have_index_spec.rb +20 -0
- data/spec/migration-spec/matchers/content/have_table_spec.rb +21 -0
- data/spec/migration-spec/matchers/content/have_tbl_column_spec.rb +25 -0
- data/spec/migration-spec/matchers/content/have_up_down_spec.rb +16 -0
- data/spec/migration-spec/matchers/generate_migration_spec.rb +18 -0
- data/spec/spec_helper.rb +50 -0
- metadata +164 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format nested --color
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Kristian Mandrup
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Migration spec
|
2
|
+
|
3
|
+
RSpec 2 matchers to let you specify expectations for your migration files and/or generators that generate migrations.
|
4
|
+
There is currently only support for Active Record migrations.
|
5
|
+
|
6
|
+
## Install
|
7
|
+
|
8
|
+
<code>gem install migration-spec</code>
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
See specs for how to use it!
|
13
|
+
|
14
|
+
Example:
|
15
|
+
<pre> require 'rspec'
|
16
|
+
require 'rspec/autorun'
|
17
|
+
require 'migration-spec'
|
18
|
+
|
19
|
+
def other_rails_app
|
20
|
+
File.expand_path(File.dirname(__FILE__) + '/rails_app')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should match expected column layout" do
|
24
|
+
|
25
|
+
Rails.root.should have_migration :add_columns
|
26
|
+
|
27
|
+
other_rails_app.should have_migration :do_columns do |klass|
|
28
|
+
klass.should have_up do |up|
|
29
|
+
up.should have_create_table :users do |user_tbl|
|
30
|
+
user_tbl.should have_columns :name => :string, :age => :integer, :admin => :boolean
|
31
|
+
user_tbl.should_not have_timestamps
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
klass.should have_down do |down|
|
36
|
+
down.should have_call 'drop_table', :users
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
</pre>
|
41
|
+
|
42
|
+
## Notes
|
43
|
+
|
44
|
+
The gem depends on 'code-spec', which I plan to improve with better argument handling than the current 'crude' approach.
|
45
|
+
This will make the 'have_call' statements used in the various matchers much better:
|
46
|
+
|
47
|
+
I am targeting to replace the current format:
|
48
|
+
<pre>
|
49
|
+
have_call 'rename_column', ":#{tbl_name}\s*,\s*:#{old_name},\s*:#{new_name}"
|
50
|
+
</pre>
|
51
|
+
|
52
|
+
With a much more readable DSL format:
|
53
|
+
<pre>
|
54
|
+
have_call 'rename_column', [:users, :name, :first_name]
|
55
|
+
</pre>
|
56
|
+
|
57
|
+
I will add this ASAP, so let me know if it's already there and I have forgotten to remove this notice!
|
58
|
+
|
59
|
+
## Note on Patches/Pull Requests
|
60
|
+
|
61
|
+
* Fork the project.
|
62
|
+
* Make your feature addition or bug fix.
|
63
|
+
* Add tests for it. This is important so I don't break it in a
|
64
|
+
future version unintentionally.
|
65
|
+
* Commit, do not mess with rakefile, version, or history.
|
66
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
67
|
+
* Send me a pull request. Bonus points for topic branches.
|
68
|
+
|
69
|
+
## Copyright
|
70
|
+
|
71
|
+
Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "migration-spec"
|
5
|
+
gem.summary = %Q{Migration RSpec 2 matchers}
|
6
|
+
gem.description = %Q{Migration RSpec 2 matchers to spec migration files, fx as generated by a Thor generator}
|
7
|
+
gem.email = "kmandrup@gmail.com"
|
8
|
+
gem.homepage = "http://github.com/kristianmandrup/migration-spec"
|
9
|
+
gem.authors = ["Kristian Mandrup"]
|
10
|
+
gem.add_dependency "rspec", ">= 2.0.0.beta.19"
|
11
|
+
gem.add_dependency "require_all", ">= 1.1.0"
|
12
|
+
gem.add_dependency 'rails3_assist', ">= 0.2.2"
|
13
|
+
gem.add_dependency 'rails-app-spec', ">= 0.2.2"
|
14
|
+
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
# require 'spec/rake/spectask'
|
23
|
+
# Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
# spec.libs << 'lib' << 'spec'
|
25
|
+
# spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
# spec.libs << 'lib' << 'spec'
|
30
|
+
# spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
# spec.rcov = true
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# task :spec => :check_dependencies
|
35
|
+
#
|
36
|
+
# task :default => :spec
|
37
|
+
#
|
38
|
+
# require 'rake/rdoctask'
|
39
|
+
# Rake::RDocTask.new do |rdoc|
|
40
|
+
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
#
|
42
|
+
# rdoc.rdoc_dir = 'rdoc'
|
43
|
+
# rdoc.title = "migration-spec #{version}"
|
44
|
+
# rdoc.rdoc_files.include('README*')
|
45
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
# end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'migration-spec/main'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'require_all'
|
3
|
+
require 'rails-app-spec'
|
4
|
+
require 'active_support/inflector'
|
5
|
+
|
6
|
+
require_all File.dirname(__FILE__) + '/matchers'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.include RSpec::RubyContentMatchers::ActiveRecord::Migration
|
10
|
+
config.include RSpec::RailsApp::Artifact::Matchers
|
11
|
+
end
|
12
|
+
|
13
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module RSpec::RubyContentMatchers
|
2
|
+
module ActiveRecord
|
3
|
+
module Migration
|
4
|
+
def have_remove_column(name)
|
5
|
+
have_call 't.remove', ":#{name}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def have_add_column(name, type='string')
|
9
|
+
have_call "t.#{type}", ":#{name}"
|
10
|
+
end
|
11
|
+
alias_method :have_column, :have_add_column
|
12
|
+
|
13
|
+
def have_columns(columns = {})
|
14
|
+
raise ArgumentError, "Columns must be passed as a :name => :type Hash" if !columns.kind_of? Hash
|
15
|
+
col_hash = {}
|
16
|
+
columns.each_pair do |name, type|
|
17
|
+
method_call = "t.#{type}"
|
18
|
+
arg = ":#{name}"
|
19
|
+
col_hash[method_call] = arg
|
20
|
+
end
|
21
|
+
HaveCalls.new col_hash
|
22
|
+
end
|
23
|
+
|
24
|
+
def have_change_column(name, type='string')
|
25
|
+
have_call "t.change", ":#{name}\s*,\s*:#{type}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def have_timestamps
|
29
|
+
have_call "t.timestamps"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RSpec::RubyContentMatchers
|
2
|
+
def have_add_tbl_index(tbl_name, index_name)
|
3
|
+
have_call 'add_index', :"#{tbl_name}" + '\s*,\s*' + ":#{index_name}"
|
4
|
+
end
|
5
|
+
|
6
|
+
def have_remove_tbl_index(tbl_name, index_name)
|
7
|
+
have_call 'remove_index', ":#{tbl_name}" + '\s*,\s*' + ":#{index_name}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def have_add_index(name)
|
11
|
+
have_call 't.add_index', ":#{name}"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RSpec::RubyContentMatchers
|
2
|
+
def have_create_table(name)
|
3
|
+
have_block 'create_table', :args => ":#{name}"
|
4
|
+
end
|
5
|
+
|
6
|
+
def have_change_table(name)
|
7
|
+
have_block 'change_table', :args => ":#{name}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def have_drop_table(name)
|
11
|
+
have_call 'drop_table', ":#{name}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def have_rename_table(name)
|
15
|
+
have_call 'rename_table', ":#{name}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RSpec::RubyContentMatchers
|
2
|
+
def have_remove_tbl_column(tbl_name, col_name)
|
3
|
+
have_call 'remove_column', ":#{tbl_name}\s*,\s*:#{col_name}"
|
4
|
+
end
|
5
|
+
|
6
|
+
def have_rename_tbl_column(tbl_name, old_name, new_name)
|
7
|
+
have_call 'rename_column', ":#{tbl_name}\s*,\s*:#{old_name},\s*:#{new_name}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def have_add_tbl_column(tbl_name, col_name, type = 'string')
|
11
|
+
have_call 'add_column', ":#{tbl_name}\s*,\s*:#{col_name}\s*,\s*:#{type}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def have_change_tbl_column tbl_name, col_name, type='string'
|
15
|
+
have_call 'change_column', ":#{tbl_name}\s*,\s*:#{col_name}\s*,\s*:#{type}"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RSpec::RubyContentMatchers
|
2
|
+
def have_up &block
|
3
|
+
have_method 'up', :class, &block
|
4
|
+
end
|
5
|
+
alias_method :have_up_method, :have_up
|
6
|
+
|
7
|
+
def have_down &block
|
8
|
+
have_method 'down', :class, &block
|
9
|
+
end
|
10
|
+
alias_method :have_down_method, :have_down
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{migration-spec}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = %q{2010-08-20}
|
13
|
+
s.description = %q{Migration RSpec 2 matchers to spec migration files, fx as generated by a Thor generator}
|
14
|
+
s.email = %q{kmandrup@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
".rspec",
|
23
|
+
"LICENSE",
|
24
|
+
"README.markdown",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/migration-spec.rb",
|
28
|
+
"lib/migration-spec/main.rb",
|
29
|
+
"lib/migration-spec/matchers/content/have_column.rb",
|
30
|
+
"lib/migration-spec/matchers/content/have_index.rb",
|
31
|
+
"lib/migration-spec/matchers/content/have_table.rb",
|
32
|
+
"lib/migration-spec/matchers/content/have_tbl_column.rb",
|
33
|
+
"lib/migration-spec/matchers/content/have_up_down.rb",
|
34
|
+
"lib/migration-spec/matchers/generate_migration.rb",
|
35
|
+
"migration-spec.gemspec",
|
36
|
+
"spec/migration-spec/fixtures/db/migrations/001_do_columns.rb",
|
37
|
+
"spec/migration-spec/fixtures/db/migrations/002_do_index.rb",
|
38
|
+
"spec/migration-spec/fixtures/db/migrations/003_do_tables.rb",
|
39
|
+
"spec/migration-spec/fixtures/db/migrations/004_do_tbl_columns.rb",
|
40
|
+
"spec/migration-spec/fixtures/db/migrations/005_do_up_down.rb",
|
41
|
+
"spec/migration-spec/matchers/content/have_column_spec.rb",
|
42
|
+
"spec/migration-spec/matchers/content/have_index_spec.rb",
|
43
|
+
"spec/migration-spec/matchers/content/have_table_spec.rb",
|
44
|
+
"spec/migration-spec/matchers/content/have_tbl_column_spec.rb",
|
45
|
+
"spec/migration-spec/matchers/content/have_up_down_spec.rb",
|
46
|
+
"spec/migration-spec/matchers/generate_migration_spec.rb",
|
47
|
+
"spec/spec_helper.rb"
|
48
|
+
]
|
49
|
+
s.homepage = %q{http://github.com/kristianmandrup/migration-spec}
|
50
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = %q{1.3.7}
|
53
|
+
s.summary = %q{Migration RSpec 2 matchers}
|
54
|
+
s.test_files = [
|
55
|
+
"spec/migration-spec/fixtures/db/migrations/001_do_columns.rb",
|
56
|
+
"spec/migration-spec/fixtures/db/migrations/002_do_index.rb",
|
57
|
+
"spec/migration-spec/fixtures/db/migrations/003_do_tables.rb",
|
58
|
+
"spec/migration-spec/fixtures/db/migrations/004_do_tbl_columns.rb",
|
59
|
+
"spec/migration-spec/fixtures/db/migrations/005_do_up_down.rb",
|
60
|
+
"spec/migration-spec/matchers/content/have_column_spec.rb",
|
61
|
+
"spec/migration-spec/matchers/content/have_index_spec.rb",
|
62
|
+
"spec/migration-spec/matchers/content/have_table_spec.rb",
|
63
|
+
"spec/migration-spec/matchers/content/have_tbl_column_spec.rb",
|
64
|
+
"spec/migration-spec/matchers/content/have_up_down_spec.rb",
|
65
|
+
"spec/migration-spec/matchers/generate_migration_spec.rb",
|
66
|
+
"spec/spec_helper.rb"
|
67
|
+
]
|
68
|
+
|
69
|
+
if s.respond_to? :specification_version then
|
70
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
71
|
+
s.specification_version = 3
|
72
|
+
|
73
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
74
|
+
s.add_runtime_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
75
|
+
s.add_runtime_dependency(%q<require_all>, [">= 1.1.0"])
|
76
|
+
s.add_runtime_dependency(%q<rails3_assist>, [">= 0.2.2"])
|
77
|
+
s.add_runtime_dependency(%q<rails-app-spec>, [">= 0.2.2"])
|
78
|
+
else
|
79
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
80
|
+
s.add_dependency(%q<require_all>, [">= 1.1.0"])
|
81
|
+
s.add_dependency(%q<rails3_assist>, [">= 0.2.2"])
|
82
|
+
s.add_dependency(%q<rails-app-spec>, [">= 0.2.2"])
|
83
|
+
end
|
84
|
+
else
|
85
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
86
|
+
s.add_dependency(%q<require_all>, [">= 1.1.0"])
|
87
|
+
s.add_dependency(%q<rails3_assist>, [">= 0.2.2"])
|
88
|
+
s.add_dependency(%q<rails-app-spec>, [">= 0.2.2"])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class DoTables < ActiveRecord::Migration
|
2
|
+
class << self
|
3
|
+
def up
|
4
|
+
create_table :users do |t|
|
5
|
+
t.string :name
|
6
|
+
t.integer :age
|
7
|
+
t.boolean :admin
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def down
|
12
|
+
drop_table :users
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.up
|
17
|
+
create_table :users do |t|
|
18
|
+
t.string :name
|
19
|
+
t.integer :age
|
20
|
+
t.boolean :admin
|
21
|
+
end
|
22
|
+
|
23
|
+
change_table :roles do |t|
|
24
|
+
...
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.down
|
29
|
+
drop_table :users do |t|
|
30
|
+
t.string :name
|
31
|
+
t.integer :age
|
32
|
+
t.boolean :admin
|
33
|
+
end
|
34
|
+
|
35
|
+
rename_table :roles do |t|
|
36
|
+
...
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class DoTblColumns < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
remove_column :users, :name
|
4
|
+
rename_column :users, :name, :first_name
|
5
|
+
add_column :users, :last_name, :string # assume string
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.down
|
9
|
+
add_column :users, :age, :integer
|
10
|
+
change_column :users, :last_name, :string # assume string
|
11
|
+
change_column :users, :age, :integer
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class DoUpDown < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :users, :male, :boolean
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.down
|
7
|
+
remove_column :users, :male
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def up
|
12
|
+
create_table :users do |t|
|
13
|
+
t.string :name
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def down
|
18
|
+
drop_table :users
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Have column matcher' do
|
4
|
+
# use_orm :active_record
|
5
|
+
use_helpers :app, :migration
|
6
|
+
|
7
|
+
it "should match expected column layout" do
|
8
|
+
fixtures_dir.should have_migration :do_columns do |klass|
|
9
|
+
klass.should have_up do |up|
|
10
|
+
up.should have_create_table :users do |user_tbl|
|
11
|
+
user_tbl.should have_columns :name => :string, :age => :integer, :admin => :boolean
|
12
|
+
user_tbl.should_not have_timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
klass.should have_down do |down|
|
17
|
+
down.should have_call 'drop_table', :users
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Have index matcher' do
|
4
|
+
# use_orm :active_record
|
5
|
+
use_helpers :app, :migration
|
6
|
+
|
7
|
+
it "should match expected index layout" do
|
8
|
+
fixtures_dir.should have_migration :do_index do |klass|
|
9
|
+
klass.should have_up do |up|
|
10
|
+
up.should have_add_index :name
|
11
|
+
up.should have_add_tbl_index :users, :name
|
12
|
+
end
|
13
|
+
|
14
|
+
klass.should have_remove_tbl_index :users, :name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Have table matcher' do
|
4
|
+
# use_orm :active_record
|
5
|
+
use_helpers :app, :migration
|
6
|
+
|
7
|
+
it "should match expected tables layout" do
|
8
|
+
fixtures_dir.should have_migration :do_tables do |klass|
|
9
|
+
klass.should have_up do |up|
|
10
|
+
up.should have_create_table :users
|
11
|
+
up.should have_change_table :roles
|
12
|
+
end
|
13
|
+
|
14
|
+
klass.should have_up do |up|
|
15
|
+
up.should have_drop_table :users
|
16
|
+
up.should have_rename_table :roles
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Have table matcher' do
|
4
|
+
# use_orm :active_record
|
5
|
+
use_helpers :app, :migration
|
6
|
+
|
7
|
+
it "should match expected tables layout" do
|
8
|
+
fixtures_dir.should have_migration :do_tables do |klass|
|
9
|
+
klass.should have_up do |up|
|
10
|
+
have_remove_tbl_column :users, :name
|
11
|
+
have_rename_tbl_column :users, :name, :first_name
|
12
|
+
have_add_tbl_column :users, :last_name # assume string
|
13
|
+
end
|
14
|
+
|
15
|
+
klass.should have_up do |up|
|
16
|
+
have_add_tbl_column :users, :age, :integer
|
17
|
+
have_change_tbl_column :users, :last_name # assume string
|
18
|
+
have_change_tbl_column :users, :age, :integer
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Have up and down method matcher' do
|
4
|
+
# use_orm :active_record
|
5
|
+
use_helpers :app, :migration
|
6
|
+
|
7
|
+
it "should match expected method layout" do
|
8
|
+
fixtures_dir.should have_migration :do_up_down do |klass|
|
9
|
+
klass.should have_up
|
10
|
+
klass.should have_down
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
Rails::Migration::Assist.orm = :active_record
|
4
|
+
|
5
|
+
describe 'migration' do
|
6
|
+
# use_orm :active_record
|
7
|
+
use_helpers :app, :migration
|
8
|
+
|
9
|
+
it "should have an create_account_migration file that contains an index method and two inserted comments" do
|
10
|
+
puts read_migration(:do_columns)
|
11
|
+
|
12
|
+
root_dir.should have_migration :do_columns
|
13
|
+
|
14
|
+
# root_dir.should generate_migration :do_columns do |migration_file|
|
15
|
+
# migration_file.should have_class_method :up
|
16
|
+
# end
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'rspec/autorun'
|
3
|
+
require 'migration-spec'
|
4
|
+
|
5
|
+
# RSpec::Generator.configure do |config|
|
6
|
+
# config.debug = false
|
7
|
+
# config.remove_temp_dir = true
|
8
|
+
# config.default_rails_root(__FILE__)
|
9
|
+
# config.lib = File.dirname(__FILE__) + '/../lib'
|
10
|
+
# # config.logger = :file # :stdout
|
11
|
+
# end
|
12
|
+
|
13
|
+
def fixtures_dir
|
14
|
+
File.expand_path(File.dirname(__FILE__) + '/migration-spec/fixtures')
|
15
|
+
end
|
16
|
+
|
17
|
+
def project_dir
|
18
|
+
File.dirname(__FILE__) + '/..'
|
19
|
+
end
|
20
|
+
|
21
|
+
def temp_dir name
|
22
|
+
File.join(project_dir, name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def make_temp_dir name
|
26
|
+
FileUtils.mkdir_p temp_dir(name)
|
27
|
+
temp_dir(name)
|
28
|
+
end
|
29
|
+
|
30
|
+
def remove_temp_dir name
|
31
|
+
FileUtils.rm_rf temp_dir(name)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
RSpec.configure do |config|
|
36
|
+
config.before do
|
37
|
+
rails_root_dir =Rails::Assist::App.rails_root_dir = fixtures_dir #temp_dir('tmp_rails')
|
38
|
+
end
|
39
|
+
|
40
|
+
config.after do
|
41
|
+
remove_temp_dir fixtures_dir # 'tmp_rails'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
Rails::Migration::Assist.orm = :active_record
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: migration-spec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kristian Mandrup
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-20 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- beta
|
33
|
+
- 19
|
34
|
+
version: 2.0.0.beta.19
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: require_all
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 1
|
48
|
+
- 0
|
49
|
+
version: 1.1.0
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: rails3_assist
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 2
|
63
|
+
- 2
|
64
|
+
version: 0.2.2
|
65
|
+
type: :runtime
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rails-app-spec
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
- 2
|
78
|
+
- 2
|
79
|
+
version: 0.2.2
|
80
|
+
type: :runtime
|
81
|
+
version_requirements: *id004
|
82
|
+
description: Migration RSpec 2 matchers to spec migration files, fx as generated by a Thor generator
|
83
|
+
email: kmandrup@gmail.com
|
84
|
+
executables: []
|
85
|
+
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files:
|
89
|
+
- LICENSE
|
90
|
+
- README.markdown
|
91
|
+
files:
|
92
|
+
- .document
|
93
|
+
- .gitignore
|
94
|
+
- .rspec
|
95
|
+
- LICENSE
|
96
|
+
- README.markdown
|
97
|
+
- Rakefile
|
98
|
+
- VERSION
|
99
|
+
- lib/migration-spec.rb
|
100
|
+
- lib/migration-spec/main.rb
|
101
|
+
- lib/migration-spec/matchers/content/have_column.rb
|
102
|
+
- lib/migration-spec/matchers/content/have_index.rb
|
103
|
+
- lib/migration-spec/matchers/content/have_table.rb
|
104
|
+
- lib/migration-spec/matchers/content/have_tbl_column.rb
|
105
|
+
- lib/migration-spec/matchers/content/have_up_down.rb
|
106
|
+
- lib/migration-spec/matchers/generate_migration.rb
|
107
|
+
- migration-spec.gemspec
|
108
|
+
- spec/migration-spec/fixtures/db/migrations/001_do_columns.rb
|
109
|
+
- spec/migration-spec/fixtures/db/migrations/002_do_index.rb
|
110
|
+
- spec/migration-spec/fixtures/db/migrations/003_do_tables.rb
|
111
|
+
- spec/migration-spec/fixtures/db/migrations/004_do_tbl_columns.rb
|
112
|
+
- spec/migration-spec/fixtures/db/migrations/005_do_up_down.rb
|
113
|
+
- spec/migration-spec/matchers/content/have_column_spec.rb
|
114
|
+
- spec/migration-spec/matchers/content/have_index_spec.rb
|
115
|
+
- spec/migration-spec/matchers/content/have_table_spec.rb
|
116
|
+
- spec/migration-spec/matchers/content/have_tbl_column_spec.rb
|
117
|
+
- spec/migration-spec/matchers/content/have_up_down_spec.rb
|
118
|
+
- spec/migration-spec/matchers/generate_migration_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
has_rdoc: true
|
121
|
+
homepage: http://github.com/kristianmandrup/migration-spec
|
122
|
+
licenses: []
|
123
|
+
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options:
|
126
|
+
- --charset=UTF-8
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
version: "0"
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
version: "0"
|
145
|
+
requirements: []
|
146
|
+
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 1.3.7
|
149
|
+
signing_key:
|
150
|
+
specification_version: 3
|
151
|
+
summary: Migration RSpec 2 matchers
|
152
|
+
test_files:
|
153
|
+
- spec/migration-spec/fixtures/db/migrations/001_do_columns.rb
|
154
|
+
- spec/migration-spec/fixtures/db/migrations/002_do_index.rb
|
155
|
+
- spec/migration-spec/fixtures/db/migrations/003_do_tables.rb
|
156
|
+
- spec/migration-spec/fixtures/db/migrations/004_do_tbl_columns.rb
|
157
|
+
- spec/migration-spec/fixtures/db/migrations/005_do_up_down.rb
|
158
|
+
- spec/migration-spec/matchers/content/have_column_spec.rb
|
159
|
+
- spec/migration-spec/matchers/content/have_index_spec.rb
|
160
|
+
- spec/migration-spec/matchers/content/have_table_spec.rb
|
161
|
+
- spec/migration-spec/matchers/content/have_tbl_column_spec.rb
|
162
|
+
- spec/migration-spec/matchers/content/have_up_down_spec.rb
|
163
|
+
- spec/migration-spec/matchers/generate_migration_spec.rb
|
164
|
+
- spec/spec_helper.rb
|