migration_tools 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 186b818e893c384f8783b66f2f981e8bda5b9c67
4
+ data.tar.gz: 3f011c99b2d4956199b22220bb7b95245126b663
5
+ SHA512:
6
+ metadata.gz: 2879fa1ff51d4c2bd8202040b29b67ec0787d1d0add8c4d69b9ef720bc0fc94cba4ccf131deb34ca95dff44baf9a41d7881a0c35688fc4c729e1a547d95ff4b2
7
+ data.tar.gz: a262efb9138e997f9502650d88542ad80ca9c6549d7eec13747098404c78c32fe52e80c27c6e97d8fb1688a29ed1765054cc67da5517cc404150b6b01f0da5fc
@@ -13,7 +13,7 @@ module MigrationTools
13
13
 
14
14
  def migrate_with_forced_groups(direction)
15
15
  if MigrationTools.forced? && migration_group.blank?
16
- raise "Cowardly refusing to run migration without a group. Read https://github.com/morten/migration_tools/blob/master/README.rdoc"
16
+ raise "Cowardly refusing to run migration without a group. Read https://github.com/zendesk/migration_tools/blob/master/README.md"
17
17
  end
18
18
  migrate_without_forced_groups(direction)
19
19
  end
@@ -25,5 +25,9 @@ ActiveRecord::Migration.class_eval do
25
25
  class << self
26
26
  alias_method_chain :migrate, :forced_groups
27
27
  end
28
+
29
+ def migration_group
30
+ self.class.migration_group
31
+ end
28
32
  end
29
33
  ActiveRecord::MigrationProxy.delegate :migration_group, :to => :migration
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migration_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.0.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Morten Primdahl
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-15 00:00:00.000000000 Z
11
+ date: 2013-12-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: Rake tasks for Rails that add groups to migrations
@@ -33,54 +30,31 @@ executables: []
33
30
  extensions: []
34
31
  extra_rdoc_files: []
35
32
  files:
36
- - .gitignore
37
- - .travis.yml
38
- - Appraisals
39
- - Gemfile
40
- - Gemfile.lock
41
- - README.md
42
- - Rakefile
43
- - gemfiles/rails-2.3.gemfile
44
- - gemfiles/rails-2.3.gemfile.lock
45
- - gemfiles/rails-3.0.gemfile
46
- - gemfiles/rails-3.0.gemfile.lock
47
- - gemfiles/rails-3.2.gemfile
48
- - gemfiles/rails-3.2.gemfile.lock
49
- - gemfiles/rails_2.3.gemfile
50
- - gemfiles/rails_2.3.gemfile.lock
51
- - gemfiles/rails_3.0.gemfile
52
- - gemfiles/rails_3.0.gemfile.lock
53
- - gemfiles/rails_3.2.gemfile
54
- - gemfiles/rails_3.2.gemfile.lock
55
33
  - lib/migration_tools.rb
56
34
  - lib/migration_tools/migration_extension.rb
57
35
  - lib/migration_tools/tasks.rb
58
- - migration_tools.gemspec
59
- - test/helper.rb
60
- - test/test_migration_tools.rb
61
- homepage: http://github.com/morten/migration_tools
36
+ homepage: https://github.com/zendesk/migration_tools
62
37
  licenses:
63
38
  - Apache License Version 2.0
39
+ metadata: {}
64
40
  post_install_message:
65
41
  rdoc_options: []
66
42
  require_paths:
67
43
  - lib
68
44
  required_ruby_version: !ruby/object:Gem::Requirement
69
- none: false
70
45
  requirements:
71
- - - ! '>='
46
+ - - '>='
72
47
  - !ruby/object:Gem::Version
73
48
  version: '0'
74
49
  required_rubygems_version: !ruby/object:Gem::Requirement
75
- none: false
76
50
  requirements:
77
- - - ! '>='
51
+ - - '>='
78
52
  - !ruby/object:Gem::Version
79
53
  version: '0'
80
54
  requirements: []
81
55
  rubyforge_project:
82
- rubygems_version: 1.8.23
56
+ rubygems_version: 2.0.3
83
57
  signing_key:
84
- specification_version: 3
58
+ specification_version: 4
85
59
  summary: Encourage migrations that do not require downtime
86
60
  test_files: []
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- .eprj
2
- .DS_Store
3
- .rvmrc
4
- .project
5
- .loadpath
6
- .sass-cache
7
- !.rvmrc.example
8
- Thumbs.db
9
- log/**/*
10
- log/*
11
- tmp/**/*
12
- tmp/*
13
- pkg/*
14
- pkg
15
- .idea
16
- .rake_tasks\~
17
- .cap_tasks\~
18
- *.tmproj
19
- mkmf.log
20
- .bundle/config
21
- .bundle/environment.rb
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- script: "bundle exec rake test"
2
- rvm:
3
- - 1.8.7
4
- - 1.9.3
5
- gemfile:
6
- - gemfiles/rails-2.3.gemfile
7
- - gemfiles/rails-3.0.gemfile
8
- - gemfiles/rails-3.2.gemfile
data/Appraisals DELETED
@@ -1,12 +0,0 @@
1
- appraise "rails-2.3" do
2
- gem "activerecord", "~> 2.3.6", :require => "active_record"
3
- end
4
-
5
- appraise "rails-3.0" do
6
- gem "activerecord", "~> 3.0.15", :require => "active_record"
7
- end
8
-
9
- appraise "rails-3.2" do
10
- gem "activerecord", "~> 3.2.6", :require => "active_record"
11
- end
12
-
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source :rubygems
2
- gemspec
3
-
4
- gem "rake"
5
- gem "mocha", "~>0.11.0" # 0.12.0 has no more dots in test output
6
- gem "test-unit", ">=2.5.1"
7
- gem "appraisal"
8
- gem "sqlite3"
data/Gemfile.lock DELETED
@@ -1,45 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- migration_tools (1.0.0)
5
- activerecord
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.2.12)
11
- activesupport (= 3.2.12)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.12)
14
- activemodel (= 3.2.12)
15
- activesupport (= 3.2.12)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.12)
19
- i18n (~> 0.6)
20
- multi_json (~> 1.0)
21
- appraisal (0.4.1)
22
- bundler
23
- rake
24
- arel (3.0.2)
25
- builder (3.0.4)
26
- i18n (0.6.1)
27
- metaclass (0.0.1)
28
- mocha (0.11.4)
29
- metaclass (~> 0.0.1)
30
- multi_json (1.6.1)
31
- rake (0.9.2.2)
32
- sqlite3 (1.3.6)
33
- test-unit (2.5.1)
34
- tzinfo (0.3.35)
35
-
36
- PLATFORMS
37
- ruby
38
-
39
- DEPENDENCIES
40
- appraisal
41
- migration_tools!
42
- mocha (~> 0.11.0)
43
- rake
44
- sqlite3
45
- test-unit (>= 2.5.1)
data/README.md DELETED
@@ -1,59 +0,0 @@
1
- # Migration Tools [![Build Status](https://secure.travis-ci.org/morten/migration_tools.png)](http://travis-ci.org/morten/migration_tools)
2
-
3
- Rake tasks for grouping migrations.
4
-
5
- ## Groups
6
-
7
- The migration tools allow you to specify a group in your migrations. This is used to allow you to run your migrations in groups, as opposed to all at once. This is useful if you want to run a certain group of migrations before a deploy, another group during deploy and a third group after deploy.
8
-
9
- We use this technique to be able to QA new production code in an isolated environment that runs against the production database. It also reduces the number of moving parts come deploy time, which is helpful when you're doing zero downtime deploys.
10
-
11
- You specify which group a migration belongs to inside the migration, like so:
12
-
13
- ```ruby
14
- class CreateHello < ActiveRecord::Migration
15
- group :before
16
-
17
- def self.up
18
- ...
19
- end
20
- end
21
- ```
22
-
23
- The names of the possible groups are predefined to avoid turning this solution in to a generic hammer from hell. You can use the following groups: before, during, after, change. We define these as:
24
-
25
- *before* this is for migrations that are safe to run before a deploy of new code, e.g. adding columns/tables
26
-
27
- *during* this is for migrations that require the data structure and code to deploy "synchronously"
28
-
29
- *after* this is for migrations that should run after the new code has been pushed and is running
30
-
31
- *change* this is a special group that you run whenever you want to change DB data which you'd otherwise do in script/console
32
-
33
-
34
- ## Commands
35
-
36
- The list commands
37
-
38
- ```
39
- $ rake db:migrate:list - shows pending migrations by group
40
- $ rake db:migrate:list:before - shows pending migrations for the before group
41
- $ rake db:migrate:list:during - shows pending migrations for the during group
42
- $ rake db:migrate:list:after - shows pending migrations for the after group
43
- $ rake db:migrate:list:change - shows pending migrations for the change group
44
- ```
45
-
46
- The group commands
47
-
48
- ```
49
- $ GROUP=before rake db:migrate:group - runs the migrations in the specified group
50
- $ rake db:migrate:group:before - runs pending migrations for the before group
51
- $ rake db:migrate:group:during - runs pending migrations for the during group
52
- $ rake db:migrate:group:after - runs pending migrations for the after group
53
- $ rake db:migrate:group:change - runs pending migrations for the change group
54
- ```
55
- Note that rake db:migrate is entirely unaffected by this.
56
-
57
- ## License
58
-
59
- Released under the Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.html
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'appraisal'
3
-
4
- require 'rake/testtask'
5
- Rake::TestTask.new(:test) do |test|
6
- test.libs << 'lib'
7
- test.pattern = 'test/**/test_*.rb'
8
- test.verbose = true
9
- end
10
-
11
- task :default do
12
- sh "bundle exec rake appraisal:install && bundle exec rake appraisal test"
13
- end
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "rake"
6
- gem "mocha", "~>0.11.0"
7
- gem "test-unit", ">=2.5.1"
8
- gem "appraisal"
9
- gem "sqlite3"
10
- gem "activerecord", "~> 2.3.6", :require=>"active_record"
11
-
12
- gemspec :path=>"../"
@@ -1,33 +0,0 @@
1
- PATH
2
- remote: /Users/primdahl/Git/migration_tools
3
- specs:
4
- migration_tools (1.0.0)
5
- activerecord
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activerecord (2.3.14)
11
- activesupport (= 2.3.14)
12
- activesupport (2.3.14)
13
- appraisal (0.4.1)
14
- bundler
15
- rake
16
- metaclass (0.0.1)
17
- mocha (0.11.4)
18
- metaclass (~> 0.0.1)
19
- rake (0.9.2.2)
20
- sqlite3 (1.3.6)
21
- test-unit (2.5.1)
22
-
23
- PLATFORMS
24
- ruby
25
-
26
- DEPENDENCIES
27
- activerecord (~> 2.3.6)
28
- appraisal
29
- migration_tools!
30
- mocha (~> 0.11.0)
31
- rake
32
- sqlite3
33
- test-unit (>= 2.5.1)
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "rake"
6
- gem "mocha", "~>0.11.0"
7
- gem "test-unit", ">=2.5.1"
8
- gem "appraisal"
9
- gem "sqlite3"
10
- gem "activerecord", "~> 3.0.15", :require=>"active_record"
11
-
12
- gemspec :path=>"../"
@@ -1,44 +0,0 @@
1
- PATH
2
- remote: /Users/primdahl/Git/migration_tools
3
- specs:
4
- migration_tools (1.0.0)
5
- activerecord
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.0.15)
11
- activesupport (= 3.0.15)
12
- builder (~> 2.1.2)
13
- i18n (~> 0.5.0)
14
- activerecord (3.0.15)
15
- activemodel (= 3.0.15)
16
- activesupport (= 3.0.15)
17
- arel (~> 2.0.10)
18
- tzinfo (~> 0.3.23)
19
- activesupport (3.0.15)
20
- appraisal (0.4.1)
21
- bundler
22
- rake
23
- arel (2.0.10)
24
- builder (2.1.2)
25
- i18n (0.5.0)
26
- metaclass (0.0.1)
27
- mocha (0.11.4)
28
- metaclass (~> 0.0.1)
29
- rake (0.9.2.2)
30
- sqlite3 (1.3.6)
31
- test-unit (2.5.1)
32
- tzinfo (0.3.33)
33
-
34
- PLATFORMS
35
- ruby
36
-
37
- DEPENDENCIES
38
- activerecord (~> 3.0.15)
39
- appraisal
40
- migration_tools!
41
- mocha (~> 0.11.0)
42
- rake
43
- sqlite3
44
- test-unit (>= 2.5.1)
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "rake"
6
- gem "mocha", "~>0.11.0"
7
- gem "test-unit", ">=2.5.1"
8
- gem "appraisal"
9
- gem "sqlite3"
10
- gem "activerecord", "~> 3.2.6", :require=>"active_record"
11
-
12
- gemspec :path=>"../"
@@ -1,46 +0,0 @@
1
- PATH
2
- remote: /Users/primdahl/Git/migration_tools
3
- specs:
4
- migration_tools (1.0.0)
5
- activerecord
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.2.6)
11
- activesupport (= 3.2.6)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.6)
14
- activemodel (= 3.2.6)
15
- activesupport (= 3.2.6)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.6)
19
- i18n (~> 0.6)
20
- multi_json (~> 1.0)
21
- appraisal (0.4.1)
22
- bundler
23
- rake
24
- arel (3.0.2)
25
- builder (3.0.0)
26
- i18n (0.6.0)
27
- metaclass (0.0.1)
28
- mocha (0.11.4)
29
- metaclass (~> 0.0.1)
30
- multi_json (1.3.6)
31
- rake (0.9.2.2)
32
- sqlite3 (1.3.6)
33
- test-unit (2.5.1)
34
- tzinfo (0.3.33)
35
-
36
- PLATFORMS
37
- ruby
38
-
39
- DEPENDENCIES
40
- activerecord (~> 3.2.6)
41
- appraisal
42
- migration_tools!
43
- mocha (~> 0.11.0)
44
- rake
45
- sqlite3
46
- test-unit (>= 2.5.1)
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "rake"
6
- gem "mocha", "~>0.11.0"
7
- gem "test-unit", ">=2.5.1"
8
- gem "appraisal"
9
- gem "sqlite3"
10
- gem "activerecord", "~> 2.3.6", :require=>"active_record"
11
-
12
- gemspec :path=>"../"
@@ -1,33 +0,0 @@
1
- PATH
2
- remote: /Users/primdahl/Git/migration_tools
3
- specs:
4
- migration_tools (1.0.0)
5
- activerecord
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activerecord (2.3.17)
11
- activesupport (= 2.3.17)
12
- activesupport (2.3.17)
13
- appraisal (0.5.1)
14
- bundler
15
- rake
16
- metaclass (0.0.1)
17
- mocha (0.11.4)
18
- metaclass (~> 0.0.1)
19
- rake (10.0.3)
20
- sqlite3 (1.3.6)
21
- test-unit (2.5.4)
22
-
23
- PLATFORMS
24
- ruby
25
-
26
- DEPENDENCIES
27
- activerecord (~> 2.3.6)
28
- appraisal
29
- migration_tools!
30
- mocha (~> 0.11.0)
31
- rake
32
- sqlite3
33
- test-unit (>= 2.5.1)
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "rake"
6
- gem "mocha", "~>0.11.0"
7
- gem "test-unit", ">=2.5.1"
8
- gem "appraisal"
9
- gem "sqlite3"
10
- gem "activerecord", "~> 3.0.15", :require=>"active_record"
11
-
12
- gemspec :path=>"../"
@@ -1,44 +0,0 @@
1
- PATH
2
- remote: /Users/primdahl/Git/migration_tools
3
- specs:
4
- migration_tools (1.0.0)
5
- activerecord
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.0.17)
11
- activesupport (= 3.0.17)
12
- builder (~> 2.1.2)
13
- i18n (~> 0.5.0)
14
- activerecord (3.0.17)
15
- activemodel (= 3.0.17)
16
- activesupport (= 3.0.17)
17
- arel (~> 2.0.10)
18
- tzinfo (~> 0.3.23)
19
- activesupport (3.0.17)
20
- appraisal (0.5.1)
21
- bundler
22
- rake
23
- arel (2.0.10)
24
- builder (2.1.2)
25
- i18n (0.5.0)
26
- metaclass (0.0.1)
27
- mocha (0.11.4)
28
- metaclass (~> 0.0.1)
29
- rake (10.0.3)
30
- sqlite3 (1.3.6)
31
- test-unit (2.5.4)
32
- tzinfo (0.3.35)
33
-
34
- PLATFORMS
35
- ruby
36
-
37
- DEPENDENCIES
38
- activerecord (~> 3.0.15)
39
- appraisal
40
- migration_tools!
41
- mocha (~> 0.11.0)
42
- rake
43
- sqlite3
44
- test-unit (>= 2.5.1)
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "rake"
6
- gem "mocha", "~>0.11.0"
7
- gem "test-unit", ">=2.5.1"
8
- gem "appraisal"
9
- gem "sqlite3"
10
- gem "activerecord", "~> 3.2.6", :require=>"active_record"
11
-
12
- gemspec :path=>"../"
@@ -1,46 +0,0 @@
1
- PATH
2
- remote: /Users/primdahl/Git/migration_tools
3
- specs:
4
- migration_tools (1.0.0)
5
- activerecord
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.2.12)
11
- activesupport (= 3.2.12)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.12)
14
- activemodel (= 3.2.12)
15
- activesupport (= 3.2.12)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.12)
19
- i18n (~> 0.6)
20
- multi_json (~> 1.0)
21
- appraisal (0.5.1)
22
- bundler
23
- rake
24
- arel (3.0.2)
25
- builder (3.0.4)
26
- i18n (0.6.1)
27
- metaclass (0.0.1)
28
- mocha (0.11.4)
29
- metaclass (~> 0.0.1)
30
- multi_json (1.6.1)
31
- rake (10.0.3)
32
- sqlite3 (1.3.6)
33
- test-unit (2.5.4)
34
- tzinfo (0.3.35)
35
-
36
- PLATFORMS
37
- ruby
38
-
39
- DEPENDENCIES
40
- activerecord (~> 3.2.6)
41
- appraisal
42
- migration_tools!
43
- mocha (~> 0.11.0)
44
- rake
45
- sqlite3
46
- test-unit (>= 2.5.1)
@@ -1,10 +0,0 @@
1
- Gem::Specification.new "migration_tools", "1.0.0" do |s|
2
- s.description = "Rake tasks for Rails that add groups to migrations"
3
- s.summary = "Encourage migrations that do not require downtime"
4
- s.homepage = "http://github.com/morten/migration_tools"
5
- s.email = "morten@zendesk.com"
6
- s.authors = ["Morten Primdahl"]
7
- s.files = `git ls-files`.split("\n")
8
- s.license = "Apache License Version 2.0"
9
- s.add_runtime_dependency "activerecord"
10
- end
data/test/helper.rb DELETED
@@ -1,11 +0,0 @@
1
- require 'test/unit'
2
- require 'mocha'
3
-
4
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
5
- require 'migration_tools'
6
-
7
- ActiveRecord::Base.establish_connection(
8
- :adapter => "sqlite3",
9
- :database => ":memory:"
10
- )
11
-
@@ -1,193 +0,0 @@
1
- require File.expand_path '../helper', __FILE__
2
-
3
- class Alpha < ActiveRecord::Migration
4
- group :before
5
- def self.up
6
- end
7
- end
8
-
9
- class Beta < ActiveRecord::Migration
10
- group :before
11
- def self.up
12
- puts "Beaver"
13
- end
14
- end
15
-
16
- class Delta < ActiveRecord::Migration
17
- group :change
18
- def self.up
19
- end
20
- end
21
-
22
- class Kappa < ActiveRecord::Migration
23
- def self.up
24
- end
25
- end
26
-
27
- class TestMigrationTools < Test::Unit::TestCase
28
-
29
- def setup
30
- ENV['GROUP'] = nil
31
- Rake::Task.clear
32
- Rake::Task.define_task("environment")
33
- Rake::Task.define_task("db:schema:dump")
34
- @task = MigrationTools::Tasks.new
35
-
36
- def @task.abort(msg = nil)
37
- @aborted = true
38
- end
39
-
40
- def @task.aborted?
41
- @aborted || false
42
- end
43
- end
44
-
45
- def migrations
46
- [ Alpha, Beta, Delta, Kappa ]
47
- end
48
-
49
- def proxies
50
- @proxies ||= migrations.map { |m| stub(:migration => m, :version => migrations.index(m), :name => m.name, :migration_group => m.migration_group) }
51
- end
52
-
53
- def test_grouping
54
- assert_equal [ Alpha, Beta ], migrations.select { |m| m.migration_group == 'before' }
55
- assert_equal [ Delta ], migrations.select { |m| m.migration_group == 'change' }
56
- assert_equal [ Kappa ], migrations.select { |m| m.migration_group.nil? }
57
- end
58
-
59
- def test_runtime_checking
60
- begin
61
- eval("class Kappa < ActiveRecord::Migration; group 'drunk'; end")
62
- fail "You should not be able to specify custom groups"
63
- rescue RuntimeError => e
64
- assert e.message.index('Invalid group "drunk" - valid groups are ["before", "during", "after", "change"]')
65
- end
66
- end
67
-
68
- def test_migration_proxy_delegation
69
- args = if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR > 0
70
- [:name, :version, :filename, :scope]
71
- else
72
- []
73
- end
74
-
75
- proxy = ActiveRecord::MigrationProxy.new(*args)
76
- proxy.expects(:migration).returns(Delta)
77
- assert_equal "change", proxy.migration_group
78
- end
79
-
80
- def test_forcing
81
- assert !MigrationTools.forced?
82
- Kappa.migrate("up")
83
-
84
- MigrationTools.forced!
85
- assert MigrationTools.forced?
86
-
87
- Alpha.migrate("up")
88
- begin
89
- Kappa.migrate("up")
90
- fail "You should not be able to run migrations without groups in forced mode"
91
- rescue RuntimeError => e
92
- assert e.message =~ /Cowardly refusing/
93
- end
94
- end
95
-
96
- def test_task_presence
97
- assert Rake::Task["db:migrate:list"]
98
- assert Rake::Task["db:migrate:group"]
99
- assert Rake::Task["db:migrate:group:before"]
100
- assert Rake::Task["db:migrate:group:during"]
101
- assert Rake::Task["db:migrate:group:after"]
102
- assert Rake::Task["db:migrate:group:change"]
103
- end
104
-
105
- def test_migrate_list_without_pending_without_group
106
- ActiveRecord::Migrator.expects(:new).returns(stub(:pending_migrations => []))
107
- MigrationTools::Tasks.any_instance.expects(:notify).with("Your database schema is up to date", "").once
108
-
109
- Rake::Task["db:migrate:list"].invoke
110
- end
111
-
112
- def test_migrate_list_without_pending_with_group
113
- ENV['GROUP'] = 'before'
114
- ActiveRecord::Migrator.expects(:new).returns(stub(:pending_migrations => []))
115
- MigrationTools::Tasks.any_instance.expects(:notify).with("Your database schema is up to date", "before").once
116
-
117
- Rake::Task["db:migrate:list"].invoke
118
- end
119
-
120
- def test_migrate_list_with_pending_without_group
121
- ActiveRecord::Migrator.expects(:new).returns(stub(:pending_migrations => proxies))
122
- MigrationTools::Tasks.any_instance.expects(:notify).with("You have #{proxies.size} pending migrations", "").once
123
- MigrationTools::Tasks.any_instance.expects(:notify).with(" 0 before Alpha").once
124
- MigrationTools::Tasks.any_instance.expects(:notify).with(" 1 before Beta").once
125
- MigrationTools::Tasks.any_instance.expects(:notify).with(" 2 change Delta").once
126
- MigrationTools::Tasks.any_instance.expects(:notify).with(" 3 Kappa").once
127
-
128
- Rake::Task["db:migrate:list"].invoke
129
- end
130
-
131
- def test_migrate_list_with_pending_with_group
132
- ENV['GROUP'] = 'before'
133
- ActiveRecord::Migrator.expects(:new).returns(stub(:pending_migrations => proxies))
134
- MigrationTools::Tasks.any_instance.expects(:notify).with("You have 2 pending migrations", "before").once
135
- MigrationTools::Tasks.any_instance.expects(:notify).with(" 0 before Alpha").once
136
- MigrationTools::Tasks.any_instance.expects(:notify).with(" 1 before Beta").once
137
-
138
- Rake::Task["db:migrate:list"].invoke
139
- end
140
-
141
- def test_abort_if_pending_migrations_with_group_without_migrations
142
- @task.stubs(:notify)
143
- ActiveRecord::Migrator.expects(:new).returns(stub(:pending_migrations => proxies))
144
- Rake::Task["db:abort_if_pending_migrations:after"].invoke
145
- assert !@task.aborted?, "aborted where it shouldn't"
146
- end
147
-
148
- def test_abort_if_pending_migrations_with_group_with_migrations
149
- @task.stubs(:notify)
150
- ActiveRecord::Migrator.expects(:new).returns(stub(:pending_migrations => proxies))
151
- Rake::Task["db:abort_if_pending_migrations:before"].invoke
152
- assert @task.aborted?, "did not abort"
153
- end
154
-
155
- def test_migrate_group_with_group_without_pending
156
- ENV['GROUP'] = 'before'
157
- ActiveRecord::Migrator.expects(:new).returns(stub(:pending_migrations => []))
158
- MigrationTools::Tasks.any_instance.expects(:notify).with("Your database schema is up to date").once
159
-
160
- Rake::Task["db:migrate:group"].invoke
161
- end
162
-
163
- def test_migrate_group_with_pending
164
- ENV['GROUP'] = 'before'
165
- migrator = stub(:pending_migrations => proxies)
166
- ActiveRecord::Migrator.expects(:new).returns(migrator)
167
-
168
- proxies.select { |p| p.migration_group == 'before' }.each do |p|
169
- ActiveRecord::Migrator.expects(:run).with(:up, 'db/migrate', p.version).once
170
- end
171
-
172
- Rake::Task["db:migrate:group"].invoke
173
- end
174
-
175
- def test_migrate_with_invalid_group
176
- ENV['GROUP'] = 'drunk'
177
- begin
178
- Rake::Task["db:migrate:group"].invoke
179
- fail "Should throw an error"
180
- rescue RuntimeError => e
181
- assert e.message =~ /Invalid group/
182
- end
183
- end
184
-
185
- def test_convenience_list_method
186
- ActiveRecord::Migrator.expects(:new).returns(stub(:pending_migrations => proxies))
187
- MigrationTools::Tasks.any_instance.expects(:notify).with("You have 2 pending migrations", "before").once
188
- MigrationTools::Tasks.any_instance.expects(:notify).with(" 0 before Alpha").once
189
- MigrationTools::Tasks.any_instance.expects(:notify).with(" 1 before Beta").once
190
-
191
- Rake::Task["db:migrate:list:before"].invoke
192
- end
193
- end