couch-migrate 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,9 +2,10 @@ source "http://rubygems.org"
2
2
  gem 'couchrest'
3
3
 
4
4
  group :development do
5
- gem "rspec", "~> 2.3.0"
5
+ gem "rspec", "~> 2.6.0"
6
6
  gem "yard", "~> 0.6.0"
7
7
  gem "bundler", "~> 1.0.0"
8
8
  gem "jeweler", "~> 1.6.4"
9
9
  gem "rcov", ">= 0"
10
+ gem 'fakefs'
10
11
  end
@@ -6,6 +6,7 @@ GEM
6
6
  multi_json (~> 1.0.0)
7
7
  rest-client (~> 1.6.1)
8
8
  diff-lcs (1.1.3)
9
+ fakefs (0.4.0)
9
10
  git (1.2.5)
10
11
  jeweler (1.6.4)
11
12
  bundler (~> 1.0)
@@ -17,14 +18,14 @@ GEM
17
18
  rcov (0.9.10)
18
19
  rest-client (1.6.7)
19
20
  mime-types (>= 1.16)
20
- rspec (2.3.0)
21
- rspec-core (~> 2.3.0)
22
- rspec-expectations (~> 2.3.0)
23
- rspec-mocks (~> 2.3.0)
24
- rspec-core (2.3.1)
25
- rspec-expectations (2.3.0)
21
+ rspec (2.6.0)
22
+ rspec-core (~> 2.6.0)
23
+ rspec-expectations (~> 2.6.0)
24
+ rspec-mocks (~> 2.6.0)
25
+ rspec-core (2.6.4)
26
+ rspec-expectations (2.6.0)
26
27
  diff-lcs (~> 1.1.2)
27
- rspec-mocks (2.3.0)
28
+ rspec-mocks (2.6.0)
28
29
  yard (0.6.8)
29
30
 
30
31
  PLATFORMS
@@ -33,7 +34,8 @@ PLATFORMS
33
34
  DEPENDENCIES
34
35
  bundler (~> 1.0.0)
35
36
  couchrest
37
+ fakefs
36
38
  jeweler (~> 1.6.4)
37
39
  rcov
38
- rspec (~> 2.3.0)
40
+ rspec (~> 2.6.0)
39
41
  yard (~> 0.6.0)
@@ -115,6 +115,14 @@ db:seed" could provide.
115
115
  end
116
116
  end
117
117
 
118
+ == Note
119
+
120
+ This gem requires Ruby 1.9 only because of the use of
121
+ "require_relative". In the true spirit of open source, if you would like
122
+ to use this gem with Ruby 1.8, please fork it, fix those requires, enjoy
123
+ using it, and then submit a pull request. One gold star will be awarded
124
+ to the person who does this.
125
+
118
126
  == Thanks
119
127
 
120
128
  Thanks to OpenLogic (http://openlogic.com), a great company that
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.1.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{couch-migrate}
8
- s.version = "1.1.2"
8
+ s.version = "1.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Greg Edwards"]
12
- s.date = %q{2011-09-28}
12
+ s.date = %q{2011-10-04}
13
13
  s.description = %q{A simple migration system for CouchDB.}
14
14
  s.email = %q{greg@greglearns.com}
15
15
  s.extra_rdoc_files = [
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "couch-migrate.gemspec",
29
- "db/migrate/1_test.rb",
29
+ "db/migrate/1_example.rb",
30
30
  "lib/couch-migrate.rb",
31
31
  "lib/couch_migrate/base_executer.rb",
32
32
  "lib/couch_migrate/base_migrater.rb",
@@ -46,6 +46,8 @@ Gem::Specification.new do |s|
46
46
  "spec/couch_migrate/couch_persisted_list_spec.rb",
47
47
  "spec/couch_migrate/file_migrater_spec.rb",
48
48
  "spec/couch_migrate/file_persisted_list_spec.rb",
49
+ "spec/couch_migrate/shared_persisted_list.rb",
50
+ "spec/couch_migrate/shared_sequential_migrations.rb",
49
51
  "spec/spec_helper.rb"
50
52
  ]
51
53
  s.homepage = %q{https://github.com/gedwards/couch-migrate}
@@ -59,26 +61,29 @@ Gem::Specification.new do |s|
59
61
 
60
62
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
63
  s.add_runtime_dependency(%q<couchrest>, [">= 0"])
62
- s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
64
+ s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
63
65
  s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
64
66
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
65
67
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
66
68
  s.add_development_dependency(%q<rcov>, [">= 0"])
69
+ s.add_development_dependency(%q<fakefs>, [">= 0"])
67
70
  else
68
71
  s.add_dependency(%q<couchrest>, [">= 0"])
69
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
72
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
70
73
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
71
74
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
75
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
73
76
  s.add_dependency(%q<rcov>, [">= 0"])
77
+ s.add_dependency(%q<fakefs>, [">= 0"])
74
78
  end
75
79
  else
76
80
  s.add_dependency(%q<couchrest>, [">= 0"])
77
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
81
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
78
82
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
79
83
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
80
84
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
81
85
  s.add_dependency(%q<rcov>, [">= 0"])
86
+ s.add_dependency(%q<fakefs>, [">= 0"])
82
87
  end
83
88
  end
84
89
 
File without changes
@@ -1,5 +1,6 @@
1
1
  require_relative 'base_executer'
2
2
  require_relative 'base_persisted_list'
3
+ require 'pathname'
3
4
 
4
5
  module CouchMigrate
5
6
  class BaseMigrater
@@ -87,7 +88,7 @@ module CouchMigrate
87
88
 
88
89
  def filter_and_sort(arr= [])
89
90
  # discard invalid formats, then sort numerically by first number, then alphabetically for remainder
90
- format = /(\d+)_(.*)\.rb/
91
+ format = /^(\d+)_(.*)\.rb$/
91
92
  arr.map do |e|
92
93
  name = Pathname.new(e).basename.to_s
93
94
  match = format.match(name)
@@ -28,7 +28,6 @@ module CouchMigrate
28
28
  def cleanup
29
29
  @list = []
30
30
  write
31
- self
32
31
  end
33
32
 
34
33
  end
@@ -3,9 +3,9 @@ require 'yaml'
3
3
 
4
4
  module CouchMigrate
5
5
  class FilePersistedList < BasePersistedList
6
- def initialize(directory="db/migrate")
6
+ def initialize(meta_file_directory="db/migrate")
7
7
  super()
8
- path = Pathname.new(directory)
8
+ path = Pathname.new(meta_file_directory)
9
9
  path.mkpath
10
10
  @path = path+"meta.yml"
11
11
  read
@@ -26,7 +26,8 @@ module CouchMigrate
26
26
  end
27
27
 
28
28
  def cleanup
29
- @path.delete rescue nil
29
+ File.delete(@path.to_s) rescue nil
30
+ # @path.delete rescue nil # fakefs does not handle this correctly
30
31
  end
31
32
 
32
33
  end
@@ -1,8 +1,49 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  require 'couch-migrate'
3
+ require 'pathname'
4
+ require 'fakefs/spec_helpers'
5
+
6
+ describe CouchMigrate::BaseMigrater, "sorting and filtering" do
7
+
8
+ it "ignores files that do not follow the migrationOrder_migration_title format" do
9
+ names = [
10
+ '2_name.rb', #valid
11
+ 'a_bad_name.rb', #invalid
12
+ '.#1_migration_a.rb', #invalid
13
+ '3_name.rb', #valid
14
+ ]
15
+ subject.raw_migrations(names)
16
+ subject.raw_migrations.should == ['2_name.rb', '3_name.rb']
17
+ end
18
+
19
+ it "sorts on migration numbers" do
20
+ subject.raw_migrations(['2_name.rb','1_name.rb', '3_name.rb'])
21
+ subject.pending_migrations.should == ['1_name.rb','2_name.rb', '3_name.rb']
22
+ end
23
+
24
+ it "sorts on title if migration numbers are the same" do
25
+ subject.raw_migrations(['2_a_name.rb','2_b_name.rb'])
26
+ subject.raw_migrations.should == ['2_a_name.rb','2_b_name.rb']
27
+ end
28
+
29
+ it "sorts on title if migration numbers are the same (version 2)" do
30
+ subject.raw_migrations(['2_b_name.rb','2_a_name.rb'])
31
+ subject.raw_migrations.should == ['2_a_name.rb','2_b_name.rb']
32
+ end
33
+
34
+ it "sorts migration numbers numerically, not alphabetically" do
35
+ subject.raw_migrations(['10_name.rb','2_name.rb'])
36
+ subject.raw_migrations.should == ['2_name.rb', '10_name.rb']
37
+ end
38
+
39
+ it "sorts migration numbers numerically, not alphabetically (version 2)" do
40
+ subject.raw_migrations(['2_name.rb','10_name.rb'])
41
+ subject.raw_migrations.should == ['2_name.rb', '10_name.rb']
42
+ end
43
+
44
+ end
3
45
 
4
- describe "BaseMigrater", "#migrate" do
5
- subject { CouchMigrate::BaseMigrater.new }
46
+ describe CouchMigrate::BaseMigrater, "#migrate" do
6
47
 
7
48
  let(:file_name_1){ "1_migration_a.rb" }
8
49
  let(:file_name_2){ "2_migration_b.rb" }
@@ -14,24 +55,25 @@ describe "BaseMigrater", "#migrate" do
14
55
  subject.raw_migrations([file_name_1, file_name_2]).raw_migrations.should == [file_name_1,file_name_2]
15
56
  end
16
57
 
58
+ it "does not execute migrations that have already been run" do
59
+ subject.raw_migrations([file_name_1, file_name_2]).completed_migrations([file_name_1]).pending_migrations.should == [file_name_2]
60
+ end
61
+
17
62
  context "interacting with the file system" do
18
- let(:path){ Pathname.new("spec/tmp") }
19
- let(:file_1){ path + file_name_1 }
20
- let(:file_2){ path + file_name_2 }
21
- let(:file_3){ path + file_name_3 }
22
-
23
- before(:all) do
24
- path.mkpath
25
- File.open(file_3,"w"){|f| f << "up do end" }
26
- File.open(file_2,"w"){|f| f << "up do raise '2 simulated failure' end" }
27
- File.open(file_1,"w"){|f| f << "up do end" }
28
- end
63
+ include FakeFS::SpecHelpers
64
+
65
+ let(:path){ Pathname.new("spec/tmp").tap{|p| p.mkpath} }
66
+
67
+ before(:each) do
68
+ # create migration files
69
+ [
70
+ [file_name_1, "up do end" ],
71
+ [file_name_2, "up do raise '2 simulated failure' end" ],
72
+ [file_name_3, "up do end" ],
73
+ ].each do |file_name, content|
74
+ File.open(path+file_name, 'w') {|f| f << content}
75
+ end
29
76
 
30
- after(:all) do
31
- file_1.delete
32
- file_2.delete
33
- file_3.delete
34
- path.rmdir rescue nil
35
77
  end
36
78
 
37
79
  it "reads the db/migrations directory to generate a list of potential migrations to run" do
@@ -41,51 +83,14 @@ describe "BaseMigrater", "#migrate" do
41
83
 
42
84
  it "stops when a migration file exits with an error, not processing any subsequent files afterwards" do
43
85
  subject.directory(path).pending_migrations.should == [file_name_1, file_name_2, file_name_3]
86
+
44
87
  subject.migrate(:quiet, :up).should == {success: [file_name_1], failed: [file_name_2]}
88
+
45
89
  subject.failed_migration.should == file_name_2
46
90
  subject.pending_migrations.should == [file_name_2, file_name_3]
47
91
  end
48
92
 
49
93
  end
50
94
 
51
- it "does not execute migrations that have already been run" do
52
- subject.raw_migrations([file_name_1, file_name_2]).completed_migrations([file_name_1]).pending_migrations.should == [file_name_2]
53
- end
54
-
55
- end
56
-
57
- describe "BaseMigrater", "sorting and filtering" do
58
- subject { CouchMigrate::BaseMigrater.new }
59
-
60
- it "sorts on migration numbers" do
61
- subject.raw_migrations(['2_name.rb','1_name.rb', '3_name.rb'])
62
- subject.pending_migrations.should == ['1_name.rb','2_name.rb', '3_name.rb']
63
- end
64
-
65
- it "sorts on title if migration numbers are the same" do
66
- subject.raw_migrations(['2_a_name.rb','2_b_name.rb'])
67
- subject.raw_migrations.should == ['2_a_name.rb','2_b_name.rb']
68
- end
69
-
70
- it "sorts on title if migration numbers are the same (version 2)" do
71
- subject.raw_migrations(['2_b_name.rb','2_a_name.rb'])
72
- subject.raw_migrations.should == ['2_a_name.rb','2_b_name.rb']
73
- end
74
-
75
- it "sorts migration numbers numerically, not alphabetically" do
76
- subject.raw_migrations(['10_name.rb','2_name.rb'])
77
- subject.raw_migrations.should == ['2_name.rb', '10_name.rb']
78
- end
79
-
80
- it "sorts migration numbers numerically, not alphabetically (version 2)" do
81
- subject.raw_migrations(['2_name.rb','10_name.rb'])
82
- subject.raw_migrations.should == ['2_name.rb', '10_name.rb']
83
- end
84
-
85
- it "ignores files that do not have follow the migrationOrder_migration_title format" do
86
- subject.raw_migrations(['2_name.rb','a_bad_name.rb'])
87
- subject.raw_migrations.should == ['2_name.rb']
88
- end
89
-
90
95
  end
91
96
 
@@ -1,44 +1,11 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  require 'couch-migrate'
3
+ require_relative 'shared_persisted_list'
3
4
 
4
5
  describe CouchMigrate::BasePersistedList do
5
6
 
6
- it "starts off with an empty value/list" do
7
- subject.get.should == []
7
+ it_should_behave_like "a_persisted_list" do
8
+ subject { CouchMigrate::BasePersistedList.new }
8
9
  end
9
-
10
- it "can set values" do
11
- arr = [1,2,3]
12
- subject.set(arr).get.should == arr
13
- end
14
-
15
- it "can append values" do
16
- arr = [1,2,3]
17
- more = [4,5]
18
- expected = [1,2,3,4,5]
19
-
20
- subject.set(arr).add(more)
21
- subject.get.should == expected
22
- end
23
-
24
- it "can remove values" do
25
- arr = [1,2,3]
26
- remove = [2,3]
27
- expected = [1]
28
-
29
- subject.set(arr).remove(remove)
30
- subject.get.should == expected
31
- end
32
-
33
- it "can be reset" do
34
- subject.set([1,2,3]).reset
35
- subject.get.should == []
36
- end
37
-
38
- it "is chainable" do
39
- subject.set([1]).add([2]).get.should == [1,2]
40
- subject.set([1]).add([2]).reset.get.should == []
41
- end
42
-
43
10
  end
44
11
 
@@ -1,84 +1,20 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  require 'couch-migrate'
3
+ require_relative 'shared_sequential_migrations'
3
4
 
4
- describe "CouchMigrater", "#migrate" do
5
+ describe CouchMigrate::CouchMigrater, "#migrate" do
5
6
 
6
-
7
- context "interacting with the file system" do
7
+ it_should_behave_like "sequential_migrations" do
8
8
  subject { CouchMigrate::CouchMigrater }
9
- let(:db_path) { 'http://127.0.0.1:5984/couch-migrate_test' }
10
- let(:path){ Pathname.new("spec/tmp") }
11
-
12
- let(:file_name_1){ "1_migration_a.rb" }
13
- let(:file_name_2){ "2_migration_b.rb" }
14
- let(:file_name_3){ "3_migration_b.rb" }
15
- let(:file_path_1){ path + file_name_1 }
16
- let(:file_path_2){ path + file_name_2 }
17
- let(:file_path_3){ path + file_name_3 }
18
-
19
- before(:each) do
20
- migrater.reset # clear pre-existing migration meta data
21
- path.mkpath
22
- file_path_1.delete rescue nil
23
- file_path_2.delete rescue nil
24
- file_path_3.delete rescue nil
25
- end
26
9
 
27
- after(:each) do
28
- # migrater.reset # remove meta file
29
- file_path_1.delete rescue nil
30
- file_path_2.delete rescue nil
31
- file_path_3.delete rescue nil
32
- path.rmdir rescue nil
33
- end
10
+ let(:path){ Pathname.new("spec/tmp") }
11
+ let(:db_path) { 'http://127.0.0.1:5984/couch-migrate_test' }
34
12
 
35
13
  def migrater
36
14
  # allows new migrations to be picked up
37
- res = subject.new(db_path, path)
38
- res
39
- end
40
-
41
- it "handles a sequence of migration added over time" do
42
- params = [:up, :quiet]
43
- down_params = [:down, :quiet]
44
-
45
- # should succeed
46
- File.open(file_path_1,"w"){|f| f << "up do end" }
47
- migrater.migrate(*params).should == {success: [file_name_1]}
48
-
49
- # should do nothing
50
- migrater.migrate(*params).should == {}
51
-
52
- # should fail
53
- File.open(file_path_2,"w"){|f| f << "up do raise '2 simulated failure' end" }
54
- migrater.migrate(*params).should == {success: [], failed: [file_name_2]}
55
-
56
- # should pass now
57
- File.open(file_path_2,"w"){|f| f << "up do end" }
58
- migrater.migrate(*params).should == {success: [file_name_2]}
59
-
60
- # should succeed
61
- File.open(file_path_3,"w"){|f| f << "up do end" }
62
- migrater.migrate(*params).should == {success: [file_name_3]}
63
-
64
- # should do nothing
65
- migrater.migrate(*params).should == {}
66
-
67
- # resetting the migration causes all to be run next time
68
- migrater.reset
69
- migrater.migrate(*params).should == {success: [file_name_1, file_name_2, file_name_3]}
70
-
71
- # Down * 3
72
- migrater.migrate(*down_params).should == {success: [file_name_3]}
73
- migrater.migrate(*down_params).should == {success: [file_name_2]}
74
- migrater.migrate(*down_params).should == {success: [file_name_1]}
75
-
76
- # Down does nothing
77
- migrater.migrate(*down_params).should == {}
15
+ subject.new(db_path, path)
78
16
  end
79
-
80
17
  end
81
18
 
82
19
  end
83
20
 
84
-
@@ -1,40 +1,12 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  require 'couch-migrate'
3
+ require_relative 'shared_persisted_list'
3
4
 
4
5
  describe CouchMigrate::CouchPersistedList do
5
- let(:db_path) { 'http://127.0.0.1:5984/couch-migrate_test' }
6
- subject { CouchMigrate::CouchPersistedList.new(db_path) }
7
6
 
8
- before(:each) do
9
- subject.reset
7
+ it_should_behave_like "a_persisted_list" do
8
+ let(:db_path) { 'http://127.0.0.1:5984/couch-migrate_test' }
9
+ subject { CouchMigrate::CouchPersistedList.new(db_path).tap{|l| l.reset} }
10
10
  end
11
-
12
- it "starts off with an empty value/list" do
13
- subject.get.should == []
14
- end
15
-
16
- it "can set values" do
17
- arr = [1,2,3]
18
- subject.set(arr).get.should == arr
19
- end
20
-
21
- it "can append values" do
22
- arr = [1,2,3]
23
- more = [4,5]
24
- expected = [1,2,3,4,5]
25
-
26
- subject.set(arr).add(more)
27
- subject.get.should == expected
28
- end
29
-
30
- it "can be reset" do
31
- subject.set([1,2,3]).reset
32
- subject.get.should == []
33
- end
34
-
35
- it "is chainable" do
36
- subject.set([1]).add([2]).get.should == [1,2]
37
- subject.set([1]).add([2]).reset.get.should == []
38
- end
39
-
40
11
  end
12
+
@@ -1,86 +1,17 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  require 'couch-migrate'
3
+ require_relative 'shared_sequential_migrations'
3
4
 
4
- describe "FileMigrater", "#migrate" do
5
+ describe CouchMigrate::FileMigrater, "#migrate" do
5
6
 
6
-
7
- context "interacting with the file system" do
7
+ it_should_behave_like "sequential_migrations" do
8
8
  subject { CouchMigrate::FileMigrater }
9
9
  let(:path){ Pathname.new("spec/tmp") }
10
10
 
11
- let(:file_name_1){ "1_migration_a.rb" }
12
- let(:file_name_2){ "2_migration_b.rb" }
13
- let(:file_name_3){ "3_migration_b.rb" }
14
- let(:file_path_1){ path + file_name_1 }
15
- let(:file_path_2){ path + file_name_2 }
16
- let(:file_path_3){ path + file_name_3 }
17
-
18
- before(:each) do
19
- migrater.reset # clear pre-existing migration meta data
20
- path.mkpath
21
- file_path_1.delete rescue nil
22
- file_path_2.delete rescue nil
23
- file_path_3.delete rescue nil
24
- end
25
-
26
- after(:each) do
27
- migrater.reset # remove meta file
28
- file_path_1.delete rescue nil
29
- file_path_2.delete rescue nil
30
- file_path_3.delete rescue nil
31
- path.rmdir rescue nil
32
- end
33
-
34
11
  def migrater
35
12
  # allows new migrations to be picked up
36
13
  subject.new(path)
37
14
  end
38
-
39
- it "handles a sequence of migration added over time" do
40
- up_params = [:up, :quiet]
41
- down_params = [:down, :quiet]
42
-
43
- # should succeed
44
- File.open(file_path_1,"w"){|f| f << "up do end" }
45
- migrater.migrate(*up_params).should == {success: [file_name_1]}
46
-
47
- # should do nothing
48
- migrater.migrate(*up_params).should == {}
49
-
50
- # should fail
51
- File.open(file_path_2,"w"){|f| f << "up do raise '2 simulated failure' end" }
52
- migrater.migrate(*up_params).should == {success: [], failed: [file_name_2]}
53
-
54
- # should pass now
55
- File.open(file_path_2,"w"){|f| f << "up do end" }
56
- migrater.migrate(*up_params).should == {success: [file_name_2]}
57
-
58
- # Down
59
- migrater.migrate(*down_params).should == {success: [file_name_2]}
60
-
61
- # up
62
- migrater.migrate(*up_params).should == {success: [file_name_2]}
63
-
64
- # should succeed
65
- File.open(file_path_3,"w"){|f| f << "up do end" }
66
- migrater.migrate(*up_params).should == {success: [file_name_3]}
67
-
68
- # should do nothing
69
- migrater.migrate(*up_params).should == {}
70
-
71
- # resetting the migration causes all to be run next time
72
- migrater.reset
73
- migrater.migrate(*up_params).should == {success: [file_name_1, file_name_2, file_name_3]}
74
-
75
- # Down * 3
76
- migrater.migrate(*down_params).should == {success: [file_name_3]}
77
- migrater.migrate(*down_params).should == {success: [file_name_2]}
78
- migrater.migrate(*down_params).should == {success: [file_name_1]}
79
-
80
- # Down does nothing
81
- migrater.migrate(*down_params).should == {}
82
- end
83
-
84
15
  end
85
16
 
86
17
  end
@@ -1,42 +1,13 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  require 'couch-migrate'
3
3
  require 'pathname'
4
+ require_relative 'shared_persisted_list'
4
5
 
5
6
  describe CouchMigrate::FilePersistedList do
6
- let(:path){ Pathname.new("spec/tmp") }
7
- subject { CouchMigrate::FilePersistedList.new(path) }
8
7
 
9
- after(:all) do
10
- Pathname.new(path).delete
8
+ it_should_behave_like "a_persisted_list" do
9
+ let(:path){ Pathname.new("spec/tmp") }
10
+ subject { CouchMigrate::FilePersistedList.new(path) }
11
11
  end
12
-
13
- it "starts off with an empty value/list" do
14
- subject.get.should == []
15
- end
16
-
17
- it "can set values" do
18
- arr = [1,2,3]
19
- subject.set(arr).get.should == arr
20
- end
21
-
22
- it "can append values" do
23
- arr = [1,2,3]
24
- more = [4,5]
25
- expected = [1,2,3,4,5]
26
-
27
- subject.set(arr).add(more)
28
- subject.get.should == expected
29
- end
30
-
31
- it "can be reset" do
32
- subject.set([1,2,3]).reset
33
- subject.get.should == []
34
- end
35
-
36
- it "is chainable" do
37
- subject.set([1]).add([2]).get.should == [1,2]
38
- subject.set([1]).add([2]).reset.get.should == []
39
- end
40
-
41
12
  end
42
13
 
@@ -0,0 +1,46 @@
1
+ require 'fakefs/spec_helpers'
2
+
3
+ shared_examples_for "a_persisted_list" do
4
+ include FakeFS::SpecHelpers
5
+
6
+ subject { raise "subject must return a new instance" }
7
+
8
+ it "starts off with an empty value/list" do
9
+ subject.get.should == []
10
+ end
11
+
12
+ it "can set values" do
13
+ arr = [1,2,3]
14
+ subject.set(arr).get.should == arr
15
+ end
16
+
17
+ it "can append values" do
18
+ arr = [1,2,3]
19
+ more = [4,5]
20
+ expected = [1,2,3,4,5]
21
+
22
+ subject.set(arr).add(more)
23
+ subject.get.should == expected
24
+ end
25
+
26
+ it "can remove values" do
27
+ arr = [1,2,3]
28
+ remove = [2,3]
29
+ expected = [1]
30
+
31
+ subject.set(arr).remove(remove)
32
+ subject.get.should == expected
33
+ end
34
+
35
+ it "can be reset" do
36
+ subject.set([1,2,3]).reset
37
+ subject.get.should == []
38
+ end
39
+
40
+ it "is chainable" do
41
+ subject.set([1]).add([2]).get.should == [1,2]
42
+ subject.set([1]).add([2]).reset.get.should == []
43
+ end
44
+
45
+ end
46
+
@@ -0,0 +1,84 @@
1
+ require 'pathname'
2
+ require 'fakefs/spec_helpers'
3
+
4
+ shared_examples_for "sequential_migrations" do
5
+ let(:path){ raise "a path must be defined by the grouping using these shared examples" }
6
+
7
+ include FakeFS::SpecHelpers
8
+
9
+ def migrater
10
+ # allows new migrations to be picked up
11
+ raise "Groups that include shared examples for sequential migrations must implement a migrater function that returns a new migration object"
12
+ end
13
+
14
+ context "sequential usage over time" do
15
+
16
+ let(:file_name_1){ "1_migration_a.rb" }
17
+ let(:file_name_2){ "2_migration_b.rb" }
18
+ let(:file_name_3){ "3_migration_b.rb" }
19
+
20
+ before(:each) do
21
+ path.mkpath
22
+ migrater.reset # clear pre-existing migration meta data
23
+ end
24
+
25
+ def create_migration(file_name, content)
26
+ File.open(path+file_name,"w"){|f| f << content }
27
+ end
28
+
29
+ it "handles a sequence of migration added over time" do
30
+ up_params = [:up, :quiet]
31
+ down_params = [:down, :quiet]
32
+
33
+ # should succeed
34
+ create_migration(file_name_1, "up do end" )
35
+ migrater.raw_migrations.should == [file_name_1]
36
+ migrater.completed_migrations.should == []
37
+ migrater.pending_migrations.should == [file_name_1]
38
+ migrater.migrate(*up_params).should == {success: [file_name_1]}
39
+
40
+ # should do nothing
41
+ migrater.migrate(*up_params).should == {}
42
+
43
+ # should fail
44
+ create_migration(file_name_2, "up do raise '2 simulated failure' end" )
45
+ migrater.migrate(*up_params).should == {success: [], failed: [file_name_2]}
46
+
47
+ # should pass now
48
+ create_migration(file_name_2, "up do end" )
49
+ migrater.migrate(*up_params).should == {success: [file_name_2]}
50
+
51
+ # Down
52
+ migrater.migrate(*down_params).should == {success: [file_name_2]}
53
+
54
+ # up
55
+ migrater.migrate(*up_params).should == {success: [file_name_2]}
56
+
57
+ # should succeed
58
+ create_migration(file_name_3, "up do end" )
59
+ migrater.migrate(*up_params).should == {success: [file_name_3]}
60
+
61
+ # should do nothing
62
+ migrater.migrate(*up_params).should == {}
63
+
64
+ # resetting the migration causes all to be run next time
65
+ migrater.reset
66
+ migrater.pending_migrations.should == [file_name_1, file_name_2, file_name_3]
67
+ migrater.migrate(*up_params).should == {success: [file_name_1, file_name_2, file_name_3]}
68
+
69
+ # Down * 3
70
+ migrater.migrate(*down_params).should == {success: [file_name_3]}
71
+ migrater.migrate(*down_params).should == {success: [file_name_2]}
72
+ migrater.migrate(*down_params).should == {success: [file_name_1]}
73
+
74
+ # Down does nothing after going down as far as possible
75
+ migrater.migrate(*down_params).should == {}
76
+
77
+ # Now, back up
78
+ migrater.pending_migrations.should == [file_name_1, file_name_2, file_name_3]
79
+ migrater.migrate(*up_params).should == {success: [file_name_1, file_name_2, file_name_3]}
80
+
81
+ end
82
+ end
83
+ end
84
+
@@ -1,6 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
+ require 'fakefs/safe'
4
5
 
5
6
  # Requires supporting files with custom matchers and macros, etc,
6
7
  # in ./support/ and its subdirectories.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couch-migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-28 00:00:00.000000000 -06:00
12
+ date: 2011-10-04 00:00:00.000000000 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: couchrest
17
- requirement: &2158537840 !ruby/object:Gem::Requirement
17
+ requirement: &2154429960 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,21 +22,21 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2158537840
25
+ version_requirements: *2154429960
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &2158536380 !ruby/object:Gem::Requirement
28
+ requirement: &2154429080 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 2.3.0
33
+ version: 2.6.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2158536380
36
+ version_requirements: *2154429080
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: yard
39
- requirement: &2158534860 !ruby/object:Gem::Requirement
39
+ requirement: &2154428340 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.6.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2158534860
47
+ version_requirements: *2154428340
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bundler
50
- requirement: &2158513340 !ruby/object:Gem::Requirement
50
+ requirement: &2154427760 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 1.0.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2158513340
58
+ version_requirements: *2154427760
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: jeweler
61
- requirement: &2158512000 !ruby/object:Gem::Requirement
61
+ requirement: &2154427160 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.6.4
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2158512000
69
+ version_requirements: *2154427160
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rcov
72
- requirement: &2158510080 !ruby/object:Gem::Requirement
72
+ requirement: &2154426620 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,18 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2158510080
80
+ version_requirements: *2154426620
81
+ - !ruby/object:Gem::Dependency
82
+ name: fakefs
83
+ requirement: &2154425960 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *2154425960
81
92
  description: A simple migration system for CouchDB.
82
93
  email: greg@greglearns.com
83
94
  executables: []
@@ -95,7 +106,7 @@ files:
95
106
  - Rakefile
96
107
  - VERSION
97
108
  - couch-migrate.gemspec
98
- - db/migrate/1_test.rb
109
+ - db/migrate/1_example.rb
99
110
  - lib/couch-migrate.rb
100
111
  - lib/couch_migrate/base_executer.rb
101
112
  - lib/couch_migrate/base_migrater.rb
@@ -115,6 +126,8 @@ files:
115
126
  - spec/couch_migrate/couch_persisted_list_spec.rb
116
127
  - spec/couch_migrate/file_migrater_spec.rb
117
128
  - spec/couch_migrate/file_persisted_list_spec.rb
129
+ - spec/couch_migrate/shared_persisted_list.rb
130
+ - spec/couch_migrate/shared_sequential_migrations.rb
118
131
  - spec/spec_helper.rb
119
132
  has_rdoc: true
120
133
  homepage: https://github.com/gedwards/couch-migrate
@@ -132,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
145
  version: '0'
133
146
  segments:
134
147
  - 0
135
- hash: 126001030709164033
148
+ hash: 3382144699293927769
136
149
  required_rubygems_version: !ruby/object:Gem::Requirement
137
150
  none: false
138
151
  requirements: