migratrix 0.0.9 → 0.8.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.
Files changed (31) hide show
  1. data/lib/migratrix.rb +62 -6
  2. data/lib/migratrix/exceptions.rb +4 -1
  3. data/lib/migratrix/{extractors → extractions}/active_record.rb +14 -10
  4. data/lib/migratrix/{extractors/extractor.rb → extractions/extraction.rb} +21 -20
  5. data/lib/migratrix/loads/load.rb +43 -0
  6. data/lib/migratrix/loads/yaml.rb +15 -0
  7. data/lib/migratrix/migration.rb +115 -27
  8. data/lib/migratrix/migratrix.rb +43 -84
  9. data/lib/migratrix/registry.rb +20 -0
  10. data/lib/migratrix/transforms/map.rb +57 -0
  11. data/lib/migratrix/transforms/transform.rb +268 -0
  12. data/lib/migratrix/valid_options.rb +22 -0
  13. data/lib/patches/object_ext.rb +0 -4
  14. data/spec/fixtures/migrations/marbles_migration.rb +6 -4
  15. data/spec/lib/migratrix/{loggable_spec.rb → _loggable_spec.rb} +0 -0
  16. data/spec/lib/migratrix/extractions/active_record_spec.rb +146 -0
  17. data/spec/lib/migratrix/extractions/extraction_spec.rb +71 -0
  18. data/spec/lib/migratrix/loads/load_spec.rb +59 -0
  19. data/spec/lib/migratrix/loads/yaml_spec.rb +39 -0
  20. data/spec/lib/migratrix/migration_spec.rb +195 -27
  21. data/spec/lib/migratrix/migratrix_spec.rb +57 -85
  22. data/spec/lib/migratrix/registry_spec.rb +28 -0
  23. data/spec/lib/migratrix/transforms/map_spec.rb +55 -0
  24. data/spec/lib/migratrix/transforms/transform_spec.rb +134 -0
  25. data/spec/lib/migratrix_spec.rb +98 -0
  26. data/spec/lib/patches/object_ext_spec.rb +0 -7
  27. data/spec/spec_helper.rb +18 -13
  28. metadata +21 -10
  29. data/spec/lib/migratrix/extractors/active_record_spec.rb +0 -43
  30. data/spec/lib/migratrix/extractors/extractor_spec.rb +0 -63
  31. data/spec/lib/migratrix_module_spec.rb +0 -63
@@ -1,13 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Object do
4
- describe "#in?" do
5
- it "returns true if object is included in collection" do
6
- 3.should be_in([1,2,3,4])
7
- "sexy".should be_in("dylsexyc")
8
- end
9
- end
10
-
11
4
  describe "#deep_copy" do
12
5
  let(:ray) { [1,2,3]}
13
6
  let(:hash) { {a: 42, b: 69, c: 13, d: 64} }
data/spec/spec_helper.rb CHANGED
@@ -28,19 +28,7 @@ Dir[SPEC + "support/**/*.rb"].each {|f| require f}
28
28
 
29
29
  require LIB + 'migratrix'
30
30
 
31
- # Migatrix loads Migration classes into its namespace. In order to
32
- # test collision prevention, I needed to reach into Migratrix and
33
- # mindwipe it of any migrations. Here's the shiv to do that. I
34
- # originally put an API to do this on Migratrix but these specs are
35
- # the only clients of it so I removed it again. If you find a
36
- # legitimate use for it, feel free to re-add a remove_migration
37
- # method and send me a patch.
38
- def reset_migratrix!(migratrix)
39
- Migratrix.constants.map(&:to_s).select {|m| m =~ /.+Migration$/}.each do |migration|
40
- Migratrix.send(:remove_const, migration.to_sym)
41
- end
42
- migratrix.registered_migrations.clear
43
- end
31
+ require SPEC + "fixtures/migrations/marbles_migration"
44
32
 
45
33
  # Redirect singleton logger to logger of our choice, then release it
46
34
  # after the spec finishes or crashes.
@@ -54,7 +42,24 @@ def with_logger(logger, &block)
54
42
  end
55
43
  end
56
44
 
45
+ def with_logging_to(stream, &block)
46
+ begin
47
+ old_logger = Migratrix::Migratrix.logger
48
+ Migratrix::Migratrix.log_to stream
49
+ yield
50
+ ensure
51
+ Migratrix::Migratrix.logger = old_logger
52
+ end
53
+ end
54
+
57
55
  RSpec.configure do |config|
56
+ config.before(:each) do
57
+ @test_logger_buffer = StringIO.new
58
+ @test_logger = Migratrix::Migratrix.create_logger(@test_logger_buffer)
59
+ Migratrix::Migratrix.init_logger
60
+ Migratrix::Migratrix.logger = @test_logger
61
+
62
+ end
58
63
  # == Mock Framework
59
64
  #
60
65
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migratrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-16 00:00:00.000000000Z
12
+ date: 2011-10-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop
16
- requirement: &2153508480 !ruby/object:Gem::Requirement
16
+ requirement: &2164512960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153508480
24
+ version_requirements: *2164512960
25
25
  description: Migratrix, a Rails legacy database migration tool supporting multiple
26
26
  strategies, including arbitrary n-ary migrations (1->n, n->1, n->m), arbitrary inputs
27
27
  and outputs (ActiveRecord, bare SQL, CSV) and migration logging
@@ -38,22 +38,33 @@ files:
38
38
  - lib/migratrix.rb
39
39
  - lib/migratrix/active_record_migration_helpers.rb
40
40
  - lib/migratrix/exceptions.rb
41
- - lib/migratrix/extractors/active_record.rb
42
- - lib/migratrix/extractors/extractor.rb
41
+ - lib/migratrix/extractions/active_record.rb
42
+ - lib/migratrix/extractions/extraction.rb
43
+ - lib/migratrix/loads/load.rb
44
+ - lib/migratrix/loads/yaml.rb
43
45
  - lib/migratrix/loggable.rb
44
46
  - lib/migratrix/migration.rb
45
47
  - lib/migratrix/migratrix.rb
48
+ - lib/migratrix/registry.rb
49
+ - lib/migratrix/transforms/map.rb
50
+ - lib/migratrix/transforms/transform.rb
51
+ - lib/migratrix/valid_options.rb
46
52
  - lib/patches/andand.rb
47
53
  - lib/patches/object_ext.rb
48
54
  - lib/patches/string_ext.rb
49
55
  - spec/fixtures/migrations/marbles_migration.rb
50
- - spec/lib/migratrix/extractors/active_record_spec.rb
51
- - spec/lib/migratrix/extractors/extractor_spec.rb
52
- - spec/lib/migratrix/loggable_spec.rb
56
+ - spec/lib/migratrix/_loggable_spec.rb
57
+ - spec/lib/migratrix/extractions/active_record_spec.rb
58
+ - spec/lib/migratrix/extractions/extraction_spec.rb
59
+ - spec/lib/migratrix/loads/load_spec.rb
60
+ - spec/lib/migratrix/loads/yaml_spec.rb
53
61
  - spec/lib/migratrix/migration_spec.rb
54
62
  - spec/lib/migratrix/migrator_spec.rb
55
63
  - spec/lib/migratrix/migratrix_spec.rb
56
- - spec/lib/migratrix_module_spec.rb
64
+ - spec/lib/migratrix/registry_spec.rb
65
+ - spec/lib/migratrix/transforms/map_spec.rb
66
+ - spec/lib/migratrix/transforms/transform_spec.rb
67
+ - spec/lib/migratrix_spec.rb
57
68
  - spec/lib/patches/object_ext_spec.rb
58
69
  - spec/lib/patches/string_ext_spec.rb
59
70
  - spec/spec_helper.rb
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
- require 'active_record'
3
-
4
- class TestModel < ::ActiveRecord::Base
5
- # self.abstract_class = true
6
- end
7
-
8
- class TestActiveRecordExtractor < Migratrix::Extractors::ActiveRecord
9
- end
10
-
11
- describe Migratrix::Extractors::ActiveRecord do
12
- let(:extractor) { TestActiveRecordExtractor.new }
13
- describe "sanity check cat" do
14
- it "is sanity checked" do
15
- Migratrix::Extractors::Extractor.should_not be_nil
16
- TestActiveRecordExtractor.should_not be_nil
17
- end
18
- end
19
-
20
- describe ".new" do
21
- it "raises TypeError unless source is Active" do
22
- lambda { TestActiveRecordExtractor.new :source => Object }.should raise_error(TypeError)
23
- end
24
- end
25
-
26
- describe "#source=" do
27
- it "raises TypeError unless source is Active" do
28
- lambda { extractor.source = Object }.should raise_error(TypeError)
29
- end
30
- end
31
-
32
- describe "#obtain_source" do
33
- it "raises ExtractorSourceUndefined unless source is defined" do
34
- lambda { extractor.extract }.should raise_error(Migratrix::ExtractorSourceUndefined)
35
- end
36
-
37
- it "returns the legacy ActiveRecord class" do
38
- extractor.source = TestModel
39
- extractor.obtain_source(TestModel).should == TestModel
40
- end
41
- end
42
- end
43
-
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class TestExtractor < Migratrix::Extractors::Extractor
4
- end
5
-
6
- describe Migratrix::Extractors::Extractor do
7
- describe "sanity check cat" do
8
- it "is sanity checked" do
9
- Migratrix::Extractors::Extractor.should_not be_nil
10
- TestExtractor.should_not be_nil
11
- end
12
- end
13
-
14
- describe "unimplemented method" do
15
- let(:base_extractor) { Migratrix::Extractors::Extractor.new }
16
- [:obtain_source, :handle_where, :handle_limit, :handle_offset, :handle_order, :to_query, :execute_extract].each do |method|
17
- describe "#{method}" do
18
- it "raises NotImplementedError" do
19
- lambda { base_extractor.send(method, nil) }.should raise_error(NotImplementedError)
20
- end
21
- end
22
- end
23
- end
24
-
25
- describe "#extract (default strategy)" do
26
- describe "with no options" do
27
- let(:extractor) { TestExtractor.new }
28
- it "should call handle_source and execute_extract only" do
29
- extractor.should_receive(:obtain_source).with(nil).and_return(13)
30
- extractor.should_receive(:execute_extract).with(13).and_return(64)
31
- extractor.extract.should == 64
32
- end
33
- end
34
-
35
- describe "with all options" do
36
- let(:extractor) { TestExtractor.new "where" => 1, "order" => 2, "limit" => 3, "offset" => 4 }
37
- it "should call entire handler chain" do
38
- extractor.should_receive(:obtain_source).with(nil).and_return("A")
39
- extractor.should_receive(:handle_where).with("A", 1).and_return("B")
40
- extractor.should_receive(:handle_order).with("B", 2).and_return("C")
41
- extractor.should_receive(:handle_limit).with("C", 3).and_return("D")
42
- extractor.should_receive(:handle_offset).with("D", 4).and_return("E")
43
- extractor.should_receive(:execute_extract).with("E").and_return("BONG")
44
- extractor.extract.should == "BONG"
45
- end
46
- end
47
-
48
- describe "with overridden options" do
49
- let(:extractor) { TestExtractor.new }
50
- let(:overrides) { {"where" => 5, "order" => 6, "limit" => 7, "offset" => 8 } }
51
- it "should call entire handler chain" do
52
- extractor.should_receive(:obtain_source).with(nil).and_return("A")
53
- extractor.should_receive(:handle_where).with("A", 5).and_return("B")
54
- extractor.should_receive(:handle_order).with("B", 6).and_return("C")
55
- extractor.should_receive(:handle_limit).with("C", 7).and_return("D")
56
- extractor.should_receive(:handle_offset).with("D", 8).and_return("E")
57
- extractor.should_receive(:execute_extract).with("E").and_return("BONG")
58
- extractor.extract(overrides).should == "BONG"
59
- end
60
- end
61
- end
62
- end
63
-
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Migratrix do
4
- describe "sanity check kitty" do
5
- it "is sanity checked" do
6
- Migratrix.should_not be_nil
7
- Migratrix.class.should == Module
8
- end
9
- end
10
-
11
- describe "convenience delegator methods" do
12
- def spec_delegates_to_migratrix(method, *args)
13
- if args.size > 0
14
- Migratrix::Migratrix.should_receive(method).with(*args).once
15
- else
16
- Migratrix::Migratrix.should_receive(method).once
17
- end
18
- Migratrix.send(method, *args)
19
- end
20
-
21
- describe ".migrate!" do
22
- let (:migratrix) { Migratrix::Migratrix.new }
23
-
24
- before do
25
- reset_migratrix! migratrix
26
- Migratrix::Migratrix.stub!(:new).and_return(migratrix)
27
- migratrix.migrations_path = SPEC + "fixtures/migrations"
28
- end
29
-
30
- it "delegates to Migratrix::Migratrix" do
31
- Migratrix.migrate! :marbles
32
- Migratrix::MarblesMigration.should be_migrated
33
- end
34
- end
35
-
36
- describe ".logger" do
37
- it "delegates to Migratrix::Migratrix" do
38
- spec_delegates_to_migratrix :logger
39
- end
40
- end
41
-
42
- describe ".logger=" do
43
- let (:logger) { Logger.new(StringIO.new) }
44
- it "delegates to Migratrix::Migratrix" do
45
- spec_delegates_to_migratrix :logger=, logger
46
- end
47
- end
48
-
49
- describe ".log_to" do
50
- let (:buffer) { StringIO.new }
51
- it "delegates to Migratrix::Migratrix" do
52
- spec_delegates_to_migratrix :log_to, buffer
53
- end
54
- end
55
-
56
- describe ".reload_migration" do
57
- it "delegates to Migratrix::Migratrix" do
58
- spec_delegates_to_migratrix :reload_migration, :marbles
59
- end
60
- end
61
- end
62
- end
63
-