mongoid_rails_migrations 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c66ba09b162f9b2a9db6aadc8ed14fc0126795c5
4
- data.tar.gz: b11d88f13706aaa7cbfa3040548eff78277d0c37
3
+ metadata.gz: 258e610c43efd94878675b841b0c046473d033d1
4
+ data.tar.gz: 3e2ce38153ee9bfc6ff7b3a2b0c0c87e8e823d69
5
5
  SHA512:
6
- metadata.gz: 7bb0036dce3aa488e344cb4d1e12e5db545568fc1e0191609fe7c980a287a3e0653586baeb8e678572d625fcd868e3883e7ce1aeb7abe792ced976e3be3a8cea
7
- data.tar.gz: 1ee702dd69a9031212409283a5d70b3e1c0caf6d2d685f47cd22074bfbe3b4b77fcd13fa7059db4b2edaf4cd5ce03dfeda3fd10cef3276574ab6cefe5ab1dd22
6
+ metadata.gz: 311fa5ed6d1f24305753750b4967caf4660b8dd106af34e7a86960e2d23cd674ddf8fa2b5af271ebdda892dd62e585494c60c3631ed6d64b66fc30e8af1df153
7
+ data.tar.gz: 98da99b5a0688b958a731c02e6a7291c4a3292908da441bf3bcc8e6eb5ec0de30de505471b82112a16a052d9cf7183e9bda85cf866815a0dfdc5ea9a8594f151
@@ -198,10 +198,25 @@ module Mongoid #:nodoc
198
198
  end
199
199
  end
200
200
 
201
+ def status(migrations_path, target_version = nil)
202
+ case
203
+ when target_version.nil? then new(:up, migrations_path, target_version).status
204
+ when current_version > target_version then new(:down, migrations_path, target_version).status
205
+ else new(:up, migrations_path, target_version).status
206
+ end
207
+ end
208
+
201
209
  def rollback(migrations_path, steps=1)
202
210
  move(:down, migrations_path, steps)
203
211
  end
204
212
 
213
+ def rollback_to(migrations_path, target_version)
214
+ all_versions = get_all_versions
215
+ rollback_to = all_versions.index(target_version.to_i) + 1
216
+ rollback_steps = all_versions.size - rollback_to
217
+ rollback migrations_path, rollback_steps
218
+ end
219
+
205
220
  def forward(migrations_path, steps=1)
206
221
  move(:up, migrations_path, steps)
207
222
  end
@@ -287,19 +302,7 @@ module Mongoid #:nodoc
287
302
  end
288
303
 
289
304
  def migrate
290
- current = migrations.detect { |m| m.version == current_version }
291
- target = migrations.detect { |m| m.version == @target_version }
292
-
293
- if target.nil? && !@target_version.nil? && @target_version > 0
294
- raise UnknownMigrationVersionError.new(@target_version)
295
- end
296
-
297
- start = up? ? 0 : (migrations.index(current) || 0)
298
- finish = migrations.index(target) || migrations.size - 1
299
- runnable = migrations[start..finish]
300
-
301
- # skip the last migration if we're headed down, but not ALL the way down
302
- runnable.pop if down? && !target.nil?
305
+ runnable = runnable_migrations
303
306
 
304
307
  runnable.each do |migration|
305
308
  Rails.logger.info "Migrating to #{migration.name} (#{migration.version})" if Rails.logger
@@ -331,6 +334,17 @@ module Mongoid #:nodoc
331
334
  end
332
335
  end
333
336
 
337
+ def status
338
+ database_name = Migration.connection.options[:database]
339
+ puts "\ndatabase: #{database_name}\n\n"
340
+ puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name"
341
+ puts "-" * 50
342
+ to_run_migrations.each do |migration|
343
+ status = migrated.include?(migration.version.to_i) ? 'down' : 'up'
344
+ puts "#{status.center(8)} #{migration.version.to_s.ljust(14)} #{migration.name}"
345
+ end
346
+ end
347
+
334
348
  def migrations
335
349
  @migrations ||= begin
336
350
  files = Array(@migrations_path).inject([]) do |files, path|
@@ -368,6 +382,34 @@ module Mongoid #:nodoc
368
382
  migrations.reject { |m| already_migrated.include?(m.version.to_i) }
369
383
  end
370
384
 
385
+ def runnable_migrations
386
+ current = migrations.detect { |m| m.version == current_version }
387
+ target = migrations.detect { |m| m.version == @target_version }
388
+
389
+ if target.nil? && !@target_version.nil? && @target_version > 0
390
+ raise UnknownMigrationVersionError.new(@target_version)
391
+ end
392
+
393
+ start = up? ? 0 : (migrations.index(current) || 0)
394
+ finish = migrations.index(target) || migrations.size - 1
395
+ runnable = migrations[start..finish]
396
+
397
+ # skip the last migration if we're headed down, but not ALL the way down
398
+ runnable.pop if down? && !target.nil?
399
+
400
+ runnable
401
+ end
402
+
403
+ def to_run_migrations
404
+ runnable_migrations.select do |migration|
405
+ if up?
406
+ !migrated.include?(migration.version.to_i)
407
+ elsif down?
408
+ migrated.include?(migration.version.to_i)
409
+ end
410
+ end
411
+ end
412
+
371
413
  def migrated
372
414
  @migrated_versions ||= self.class.get_all_versions
373
415
  end
@@ -71,6 +71,11 @@ namespace :db do
71
71
  raise "VERSION is required" unless version
72
72
  Mongoid::Migrator.run(:down, Mongoid::Migrator.migrations_path, version)
73
73
  end
74
+
75
+ desc 'Display status of migrations'
76
+ task :status => :environment do
77
+ Mongoid::Migrator.status("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
78
+ end
74
79
  end
75
80
 
76
81
  desc 'Rolls the database back to the previous migration. Specify the number of steps with STEP=n'
@@ -79,6 +84,13 @@ namespace :db do
79
84
  Mongoid::Migrator.rollback(Mongoid::Migrator.migrations_path, step)
80
85
  end
81
86
 
87
+ desc 'Rolls the database back to the specified VERSION'
88
+ task :rollback_to => :environment do
89
+ version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
90
+ raise "VERSION is required" unless version
91
+ Mongoid::Migrator.rollback_to('db/migrate/', version)
92
+ end
93
+
82
94
  namespace :schema do
83
95
  task :load do
84
96
  # noop
@@ -90,4 +102,4 @@ namespace :db do
90
102
  # Stub out for MongoDB
91
103
  end
92
104
  end
93
- end
105
+ end
@@ -1,3 +1,3 @@
1
1
  module MongoidRailsMigrations #:nodoc:
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -1,32 +1,28 @@
1
- require File.join(File.dirname(__FILE__), 'lib', 'mongoid_rails_migrations', 'version')
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'mongoid_rails_migrations/version'
2
4
 
3
- Gem::Specification.new do |s|
4
- s.platform = Gem::Platform::RUBY
5
- s.name = 'mongoid_rails_migrations'
6
- s.version = MongoidRailsMigrations::VERSION
7
- s.summary = 'Data migrations for Mongoid in Active Record style, minus column input.'
8
- s.license = 'MIT'
9
- s.description = 'Migrations for the migrator.'
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'mongoid_rails_migrations'
7
+ spec.version = MongoidRailsMigrations::VERSION
8
+ spec.authors = ['Alan Da Costa']
9
+ spec.email = ['alandacosta@gmail.com']
10
10
 
11
- s.required_ruby_version = '>= 1.8.6'
12
- s.required_rubygems_version = '>= 1.3.6'
11
+ spec.summary = 'Data migrations for Mongoid.'
12
+ spec.description = 'Data migrations for Mongoid in Active Record style, minus column input.'
13
+ spec.homepage = 'http://github.com/adacosta/mongoid_rails_migrations'
14
+ spec.license = 'MIT'
13
15
 
14
- s.author = 'Alan Da Costa'
15
- s.email = 'alandacosta@gmail.com'
16
- s.date = %q{2015-01-01}
17
- s.homepage = 'http://github.com/adacosta/mongoid_rails_migrations'
18
-
19
- s.require_paths = ['lib']
20
- s.files = Dir['.gitignore', 'Gemfile', 'Gemfile.lock', 'Rakefile', 'README.rdoc', 'mongoid_rails_migrations.gemspec', 'lib/**/*']
21
- s.test_files = Dir['test/**/*']
22
- s.has_rdoc = false
16
+ spec.files = Dir['README.rdoc', 'mongoid_rails_migrations.gemspec', 'lib/**/*']
17
+ spec.require_paths = ['lib']
23
18
 
24
19
  rails_version = '>= 4.2.0'
25
20
 
26
- s.add_runtime_dependency('bundler', '>= 1.0.0')
27
- s.add_runtime_dependency('mongoid', '>= 4.0.0')
28
- s.add_runtime_dependency('rails', rails_version)
29
- s.add_runtime_dependency('railties', rails_version)
30
- s.add_runtime_dependency('activesupport', rails_version)
31
- s.add_development_dependency 'rake'
21
+ spec.add_runtime_dependency('bundler', '>= 1.0.0')
22
+ spec.add_runtime_dependency('mongoid', '>= 4.0.0')
23
+ spec.add_runtime_dependency('rails', rails_version)
24
+ spec.add_runtime_dependency('railties', rails_version)
25
+ spec.add_runtime_dependency('activesupport', rails_version)
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'minitest'
32
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_rails_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Da Costa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-01 00:00:00.000000000 Z
11
+ date: 2018-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,17 +94,27 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: Migrations for the migrator.
98
- email: alandacosta@gmail.com
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Data migrations for Mongoid in Active Record style, minus column input.
112
+ email:
113
+ - alandacosta@gmail.com
99
114
  executables: []
100
115
  extensions: []
101
116
  extra_rdoc_files: []
102
117
  files:
103
- - ".gitignore"
104
- - Gemfile
105
- - Gemfile.lock
106
- - README.rdoc
107
- - Rakefile
108
118
  - lib/mongoid_rails_migrations.rb
109
119
  - lib/mongoid_rails_migrations/active_record_ext/migrations.rb
110
120
  - lib/mongoid_rails_migrations/models/data_migration.rb
@@ -116,17 +126,6 @@ files:
116
126
  - lib/rails/generators/mongoid/migration/templates/migration.rb
117
127
  - lib/rails/generators/mongoid/mongoid_generator.rb
118
128
  - mongoid_rails_migrations.gemspec
119
- - test/config.rb
120
- - test/helper.rb
121
- - test/migration_test.rb
122
- - test/migrations/duplicate/names/20100513073457_add_duplicate_survey_schema.rb
123
- - test/migrations/duplicate/names/20100513073724_add_duplicate_survey_schema.rb
124
- - test/migrations/duplicate/versions/20100513073457_add_another_duplicate_survey_schema.rb
125
- - test/migrations/duplicate/versions/20100513073457_add_duplicate_survey_schema.rb
126
- - test/migrations/other_valid/20160509073459_add_other_plan_survey_schema.rb
127
- - test/migrations/valid/20100513054656_add_baseline_survey_schema.rb
128
- - test/migrations/valid/20100513063902_add_improvement_plan_survey_schema.rb
129
- - test/models/survey_schema.rb
130
129
  homepage: http://github.com/adacosta/mongoid_rails_migrations
131
130
  licenses:
132
131
  - MIT
@@ -139,27 +138,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
138
  requirements:
140
139
  - - ">="
141
140
  - !ruby/object:Gem::Version
142
- version: 1.8.6
141
+ version: '0'
143
142
  required_rubygems_version: !ruby/object:Gem::Requirement
144
143
  requirements:
145
144
  - - ">="
146
145
  - !ruby/object:Gem::Version
147
- version: 1.3.6
146
+ version: '0'
148
147
  requirements: []
149
148
  rubyforge_project:
150
- rubygems_version: 2.6.13
149
+ rubygems_version: 2.5.1
151
150
  signing_key:
152
151
  specification_version: 4
153
- summary: Data migrations for Mongoid in Active Record style, minus column input.
154
- test_files:
155
- - test/migrations/duplicate/names/20100513073724_add_duplicate_survey_schema.rb
156
- - test/migrations/duplicate/names/20100513073457_add_duplicate_survey_schema.rb
157
- - test/migrations/duplicate/versions/20100513073457_add_duplicate_survey_schema.rb
158
- - test/migrations/duplicate/versions/20100513073457_add_another_duplicate_survey_schema.rb
159
- - test/migrations/other_valid/20160509073459_add_other_plan_survey_schema.rb
160
- - test/migrations/valid/20100513054656_add_baseline_survey_schema.rb
161
- - test/migrations/valid/20100513063902_add_improvement_plan_survey_schema.rb
162
- - test/migration_test.rb
163
- - test/helper.rb
164
- - test/config.rb
165
- - test/models/survey_schema.rb
152
+ summary: Data migrations for Mongoid.
153
+ test_files: []
154
+ has_rdoc:
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- .bundle
2
- .DS_Store
3
- .rvmrc
4
- .idea
5
- log/
6
- .ruby-version
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source "http://rubygems.org"
2
- gemspec :name => 'mongoid_rails_migrations'
3
-
4
- group :test do
5
- gem 'minitest'
6
- gem 'pry'
7
- end
@@ -1,142 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- mongoid_rails_migrations (1.1.0)
5
- activesupport (>= 4.2.0)
6
- bundler (>= 1.0.0)
7
- mongoid (>= 4.0.0)
8
- rails (>= 4.2.0)
9
- railties (>= 4.2.0)
10
-
11
- GEM
12
- remote: http://rubygems.org/
13
- specs:
14
- actioncable (5.2.0)
15
- actionpack (= 5.2.0)
16
- nio4r (~> 2.0)
17
- websocket-driver (>= 0.6.1)
18
- actionmailer (5.2.0)
19
- actionpack (= 5.2.0)
20
- actionview (= 5.2.0)
21
- activejob (= 5.2.0)
22
- mail (~> 2.5, >= 2.5.4)
23
- rails-dom-testing (~> 2.0)
24
- actionpack (5.2.0)
25
- actionview (= 5.2.0)
26
- activesupport (= 5.2.0)
27
- rack (~> 2.0)
28
- rack-test (>= 0.6.3)
29
- rails-dom-testing (~> 2.0)
30
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
31
- actionview (5.2.0)
32
- activesupport (= 5.2.0)
33
- builder (~> 3.1)
34
- erubi (~> 1.4)
35
- rails-dom-testing (~> 2.0)
36
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
37
- activejob (5.2.0)
38
- activesupport (= 5.2.0)
39
- globalid (>= 0.3.6)
40
- activemodel (5.2.0)
41
- activesupport (= 5.2.0)
42
- activerecord (5.2.0)
43
- activemodel (= 5.2.0)
44
- activesupport (= 5.2.0)
45
- arel (>= 9.0)
46
- activestorage (5.2.0)
47
- actionpack (= 5.2.0)
48
- activerecord (= 5.2.0)
49
- marcel (~> 0.3.1)
50
- activesupport (5.2.0)
51
- concurrent-ruby (~> 1.0, >= 1.0.2)
52
- i18n (>= 0.7, < 2)
53
- minitest (~> 5.1)
54
- tzinfo (~> 1.1)
55
- arel (9.0.0)
56
- bson (4.3.0)
57
- builder (3.2.3)
58
- coderay (1.1.2)
59
- concurrent-ruby (1.0.5)
60
- crass (1.0.4)
61
- erubi (1.7.1)
62
- globalid (0.4.1)
63
- activesupport (>= 4.2.0)
64
- i18n (1.0.1)
65
- concurrent-ruby (~> 1.0)
66
- loofah (2.2.2)
67
- crass (~> 1.0.2)
68
- nokogiri (>= 1.5.9)
69
- mail (2.7.0)
70
- mini_mime (>= 0.1.1)
71
- marcel (0.3.2)
72
- mimemagic (~> 0.3.2)
73
- method_source (0.9.0)
74
- mimemagic (0.3.2)
75
- mini_mime (1.0.0)
76
- mini_portile2 (2.3.0)
77
- minitest (5.11.3)
78
- mongo (2.6.1)
79
- bson (>= 4.3.0, < 5.0.0)
80
- mongoid (7.0.1)
81
- activemodel (>= 5.1, < 6.0.0)
82
- mongo (>= 2.5.1, < 3.0.0)
83
- nio4r (2.3.1)
84
- nokogiri (1.8.4)
85
- mini_portile2 (~> 2.3.0)
86
- pry (0.11.3)
87
- coderay (~> 1.1.0)
88
- method_source (~> 0.9.0)
89
- rack (2.0.5)
90
- rack-test (1.1.0)
91
- rack (>= 1.0, < 3)
92
- rails (5.2.0)
93
- actioncable (= 5.2.0)
94
- actionmailer (= 5.2.0)
95
- actionpack (= 5.2.0)
96
- actionview (= 5.2.0)
97
- activejob (= 5.2.0)
98
- activemodel (= 5.2.0)
99
- activerecord (= 5.2.0)
100
- activestorage (= 5.2.0)
101
- activesupport (= 5.2.0)
102
- bundler (>= 1.3.0)
103
- railties (= 5.2.0)
104
- sprockets-rails (>= 2.0.0)
105
- rails-dom-testing (2.0.3)
106
- activesupport (>= 4.2.0)
107
- nokogiri (>= 1.6)
108
- rails-html-sanitizer (1.0.4)
109
- loofah (~> 2.2, >= 2.2.2)
110
- railties (5.2.0)
111
- actionpack (= 5.2.0)
112
- activesupport (= 5.2.0)
113
- method_source
114
- rake (>= 0.8.7)
115
- thor (>= 0.18.1, < 2.0)
116
- rake (12.3.1)
117
- sprockets (3.7.2)
118
- concurrent-ruby (~> 1.0)
119
- rack (> 1, < 3)
120
- sprockets-rails (3.2.1)
121
- actionpack (>= 4.0)
122
- activesupport (>= 4.0)
123
- sprockets (>= 3.0.0)
124
- thor (0.20.0)
125
- thread_safe (0.3.6)
126
- tzinfo (1.2.5)
127
- thread_safe (~> 0.1)
128
- websocket-driver (0.7.0)
129
- websocket-extensions (>= 0.1.0)
130
- websocket-extensions (0.1.3)
131
-
132
- PLATFORMS
133
- ruby
134
-
135
- DEPENDENCIES
136
- minitest
137
- mongoid_rails_migrations!
138
- pry
139
- rake
140
-
141
- BUNDLED WITH
142
- 1.13.7
@@ -1,56 +0,0 @@
1
- == RELEASE NOTES
2
- * The most current release, 1.1.x, targets Mongoid >= 4.0.0 and Rails >= 4.2.0 .
3
- * For Rails >= 3.2.0 and Mongoid >= 3.0.0, use version 1.0.0 .
4
- * For Rails >= 3.0.0 (but < 3.2.0) and Mongoid >= 2.0.0, use version 0.0.14 .
5
-
6
- == SYNOPSIS
7
- * Data migrations for Mongoid.
8
-
9
- == MIGRATE WHEN ...
10
- * The migrating is good
11
-
12
- == INSTALL
13
- * gem install mongoid_rails_migrations
14
- * In your Gemfile, include (after including mongoid):
15
- gem "mongoid_rails_migrations", <version>
16
-
17
- == FEATURES AND HOW TO USE
18
- * generator:
19
- * rails generate mongoid:migration your_migration_name_here
20
-
21
- * migrations:
22
- * db:migrate
23
- * db:migrate:down
24
- * db:migrate:up
25
- * db:rollback
26
- * db:migrate:redo
27
- * db:migrate:reset
28
- * db:reseed (handled by mongoid)
29
- * db:version
30
-
31
- == TESTING
32
- ```rake test:mongoid:migrations```
33
-
34
- == CREDITS TO
35
- * rails
36
- * mongoid
37
- * contributions from the community (git log)
38
-
39
- Much of this gem simply modifies existing code from both projects.
40
- With that out of the way, on to the license.
41
-
42
- == LICENSE (MIT)
43
-
44
- Copyright © 2013: Alan Da Costa
45
-
46
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'),
47
- to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish,
48
- distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
49
- the following conditions:
50
-
51
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
52
-
53
- The software is provided 'as is', without warranty of any kind, express or implied, including but not limited to the warranties of
54
- merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any
55
- claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the
56
- software or the use or other dealings in the software.
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__))
2
- require "bundler/gem_tasks"
3
-
4
- task :default => ['test:mongoid:migrations']
5
-
6
- namespace :test do
7
- namespace :mongoid do
8
- desc "Test mongoid rails migrations"
9
- task :migrations do
10
- load 'test/migration_test.rb'
11
- end
12
- end
13
- end
@@ -1,9 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'lib', 'mongoid_rails_migrations')
2
- require File.join(File.dirname(__FILE__), '..', 'lib', 'rails', 'generators', 'mongoid', 'mongoid_generator')
3
-
4
- Mongoid.configure.connect_to('mongoid_test')
5
-
6
- # require all models
7
- Dir[File.join(File.dirname(__FILE__), 'models', '*.rb')].each { |file| require file }
8
-
9
- MIGRATIONS_ROOT = File.join(File.dirname(__FILE__), 'migrations')
@@ -1,34 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__))
2
-
3
- require 'bundler/setup'
4
- Bundler.require(:test)
5
-
6
- require 'mongoid'
7
- require 'config'
8
- require 'minitest/autorun'
9
- require 'rake'
10
- require 'rake/testtask'
11
- require 'rdoc/task'
12
-
13
- # leave out active_record, in favor of a monogo adapter
14
- %w(
15
- action_controller
16
- action_mailer
17
- active_resource
18
- rails/test_unit
19
- mongoid
20
- ).each do |framework|
21
- begin
22
- require "#{framework}/railtie"
23
- rescue LoadError
24
- end
25
- end
26
-
27
-
28
- ActiveSupport.test_order = :sorted if ActiveSupport.respond_to?(:test_order)
29
-
30
- module TestMongoidRailsMigrations
31
- class Application < Rails::Application; end
32
- end
33
-
34
- TestMongoidRailsMigrations::Application.load_tasks
@@ -1,165 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class Mongoid::Migration
4
- class <<self
5
- attr_accessor :message_count
6
-
7
- def puts(text="")
8
- self.message_count ||= 0
9
- self.message_count += 1
10
- end
11
- end
12
- end
13
-
14
- module Mongoid
15
- class TestCase < ActiveSupport::TestCase #:nodoc:
16
-
17
- def setup
18
- Mongoid::Migration.verbose = true
19
- Mongo::Logger.logger.level = 1
20
- # same as db:drop command in lib/mongoid_rails_migrations/mongoid_ext/railties/database.rake
21
- if Mongoid.respond_to?(:default_client)
22
- Mongoid.default_client.database.drop
23
- else
24
- Mongoid.default_session.drop
25
- end
26
- end
27
-
28
- def teardown; end
29
-
30
- def test_drop_works
31
- assert_equal 0, Mongoid::Migrator.current_version, "db:drop should take us down to version 0"
32
- end
33
-
34
- def test_migrations_path
35
- assert_equal ["db/migrate"], Mongoid::Migrator.migrations_path
36
-
37
- Mongoid::Migrator.migrations_path += ["engines/my_engine/db/migrate"]
38
-
39
- assert_equal ["db/migrate", "engines/my_engine/db/migrate"], Mongoid::Migrator.migrations_path
40
- end
41
-
42
- def test_finds_migrations
43
- assert Mongoid::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").migrations.size == 2
44
- assert_equal 2, Mongoid::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").pending_migrations.size
45
- end
46
-
47
- def test_finds_migrations_in_multiple_paths
48
- migration_paths = [MIGRATIONS_ROOT + "/valid", MIGRATIONS_ROOT + "/other_valid"]
49
-
50
- assert Mongoid::Migrator.new(:up, migration_paths).migrations.size == 3
51
- assert_equal 3, Mongoid::Migrator.new(:up, migration_paths).pending_migrations.size
52
- end
53
-
54
- def test_migrator_current_version
55
- Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 20100513054656)
56
- assert_equal(20100513054656, Mongoid::Migrator.current_version)
57
- end
58
-
59
- def test_migrator
60
- assert SurveySchema.first.nil?, "All SurveySchemas should be clear before migration run"
61
-
62
- Mongoid::Migrator.up(MIGRATIONS_ROOT + "/valid")
63
-
64
- assert_equal 20100513063902, Mongoid::Migrator.current_version
65
- assert !SurveySchema.first.nil?
66
-
67
- Mongoid::Migrator.down(MIGRATIONS_ROOT + "/valid")
68
- assert_equal 0, Mongoid::Migrator.current_version
69
-
70
- assert SurveySchema.create(:label => 'Questionable Survey')
71
- assert_equal 1, SurveySchema.all.size
72
- end
73
-
74
- def test_migrator_two_up_and_one_down
75
- assert SurveySchema.where(:label => 'Baseline Survey').first.nil?
76
- assert_equal 0, SurveySchema.all.size
77
-
78
- Mongoid::Migrator.up(MIGRATIONS_ROOT + "/valid", 20100513054656)
79
-
80
- assert !SurveySchema.where(:label => 'Baseline Survey').first.nil?
81
- assert_equal 1, SurveySchema.all.size
82
-
83
- assert SurveySchema.where(:label => 'Improvement Plan Survey').first.nil?
84
-
85
- Mongoid::Migrator.up(MIGRATIONS_ROOT + "/valid", 20100513063902)
86
- assert_equal 20100513063902, Mongoid::Migrator.current_version
87
-
88
- assert !SurveySchema.where(:label => 'Improvement Plan Survey').first.nil?
89
- assert_equal 2, SurveySchema.all.size
90
-
91
- Mongoid::Migrator.down(MIGRATIONS_ROOT + "/valid", 20100513054656)
92
- assert_equal 20100513054656, Mongoid::Migrator.current_version
93
-
94
- assert SurveySchema.where(:label => 'Improvement Plan Survey').first.nil?
95
- assert !SurveySchema.where(:label => 'Baseline Survey').first.nil?
96
- assert_equal 1, SurveySchema.all.size
97
- end
98
-
99
- def test_finds_pending_migrations
100
- Mongoid::Migrator.up(MIGRATIONS_ROOT + "/valid", 20100513054656)
101
- pending_migrations = Mongoid::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").pending_migrations
102
-
103
- assert_equal 1, pending_migrations.size
104
- assert_equal pending_migrations[0].version, 20100513063902
105
- assert_equal pending_migrations[0].name, 'AddImprovementPlanSurveySchema'
106
- end
107
-
108
- def test_migrator_rollback
109
- Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/valid")
110
- assert_equal(20100513063902, Mongoid::Migrator.current_version)
111
-
112
- Mongoid::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
113
- assert_equal(20100513054656, Mongoid::Migrator.current_version)
114
-
115
- Mongoid::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
116
- assert_equal(0, Mongoid::Migrator.current_version)
117
- end
118
-
119
- def test_migrator_forward
120
- Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 20100513054656)
121
- assert_equal(20100513054656, Mongoid::Migrator.current_version)
122
-
123
- Mongoid::Migrator.forward(MIGRATIONS_ROOT + "/valid", 20100513063902)
124
- assert_equal(20100513063902, Mongoid::Migrator.current_version)
125
- end
126
-
127
- def test_migrator_with_duplicate_names
128
- assert_raise(Mongoid::DuplicateMigrationNameError) do
129
- Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate/names", nil)
130
- end
131
- end
132
-
133
- def test_migrator_with_duplicate_versions
134
- assert_raise(Mongoid::DuplicateMigrationVersionError) do
135
- Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate/versions", nil)
136
- end
137
- end
138
-
139
- def test_migrator_with_missing_version_numbers
140
- assert_raise(Mongoid::UnknownMigrationVersionError) do
141
- Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 500)
142
- end
143
- end
144
-
145
- def test_default_state_of_timestamped_migrations
146
- assert Mongoid.configure.timestamped_migrations, "Mongoid.configure.timestamped_migrations should default to true"
147
- end
148
-
149
- def test_timestamped_migrations_generates_non_sequential_next_number
150
- next_number = Mongoid::Generators::Base.next_migration_number(MIGRATIONS_ROOT + "/valid")
151
- assert_not_equal "20100513063903", next_number
152
- end
153
-
154
- def test_turning_off_timestamped_migrations
155
- Mongoid.configure.timestamped_migrations = false
156
- next_number = Mongoid::Generators::Base.next_migration_number(MIGRATIONS_ROOT + "/valid")
157
- assert_equal "20100513063903", next_number
158
- end
159
-
160
- def test_migration_returns_connection_without_error
161
- Mongoid::Migration.connection
162
- end
163
-
164
- end
165
- end
@@ -1,9 +0,0 @@
1
- class AddDuplicateSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:label => 'Duplicate Survey')
4
- end
5
-
6
- def self.down
7
- SurveySchema.where(:label => 'Duplicate Survey').first.destroy
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class AddDuplicateSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:label => 'Duplicate Survey')
4
- end
5
-
6
- def self.down
7
- SurveySchema.where(:label => 'Duplicate Survey').first.destroy
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class AddDuplicateSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:label => 'Duplicate Survey')
4
- end
5
-
6
- def self.down
7
- SurveySchema.where(:label => 'Duplicate Survey').first.destroy
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class AddDuplicateSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:label => 'Duplicate Survey')
4
- end
5
-
6
- def self.down
7
- SurveySchema.where(:label => 'Duplicate Survey').first.destroy
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class AddOtherPlanSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:label => 'Other Plan Survey')
4
- end
5
-
6
- def self.down
7
- SurveySchema.where(:label => 'Other Plan Survey').first.destroy
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- class AddBaselineSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:id => '4c47bf87f3395c339c000001',
4
- :label => 'Baseline Survey')
5
- end
6
-
7
- def self.down
8
- SurveySchema.where(:label => 'Baseline Survey').first.destroy
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- class AddImprovementPlanSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:label => 'Improvement Plan Survey')
4
- end
5
-
6
- def self.down
7
- SurveySchema.where(:label => 'Improvement Plan Survey').first.destroy
8
- end
9
- end
@@ -1,6 +0,0 @@
1
- class SurveySchema
2
- include Mongoid::Document
3
- include Mongoid::Timestamps
4
-
5
- field :label
6
- end