mlins-active_migration 1.0.2 → 1.0.3

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.
@@ -0,0 +1,122 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ require File.dirname(__FILE__) + '/fixtures/product_three_migration'
4
+ require File.dirname(__FILE__) + '/fixtures/product_four_migration'
5
+
6
+ describe "A migration" do
7
+
8
+ before do
9
+ ActiveMigration::Base.logger = mock('logger', :null_object => true)
10
+ @legacy_record = mock('legacy_model', :id => 1, :name => 'Beer')
11
+ @active_record = mock('active_model', :id => 10, :name= => 'Beer', :save => true)
12
+ @active_record.stub!(:changed?).and_return(true,false)
13
+ Product.stub!(:new).and_return(@active_record)
14
+ Product.stub!(:table_name).and_return('some_new_table')
15
+ Legacy::Product.stub!(:count).and_return(1)
16
+ Legacy::Product.stub!(:find).and_return([@legacy_record])
17
+ Legacy::Product.stub!(:table_name).and_return('some_old_table')
18
+ @file = mock("file", :null_object => true)
19
+ File.stub!(:open).and_yield(@file)
20
+ end
21
+
22
+ it "should store key maps in /tmp by default" do
23
+ ActiveMigration::KeyMapper.storage_path.should == "/tmp"
24
+ end
25
+
26
+ it "should allow the key maps storage path to be changed" do
27
+ ActiveMigration::KeyMapper.storage_path = "/foo"
28
+ File.should_receive(:open).with(File.join('/foo', 'product_three_migration_map.yml'), 'w').and_yield(@file)
29
+ ProductThreeMigration.new.run
30
+ ActiveMigration::KeyMapper.storage_path = "/tmp"
31
+ end
32
+
33
+ it "should serialize the keys" do
34
+ @file.should_receive(:write).with({1 => 10}.to_yaml)
35
+ ProductThreeMigration.new.run
36
+ end
37
+
38
+ end
39
+
40
+ describe "A migration with model that has a composite primary key" do
41
+
42
+ before do
43
+ ActiveMigration::Base.logger = mock('logger', :null_object => true)
44
+ @legacy_record = mock('legacy_model', :id => [1,2], :name => 'Beer')
45
+ @active_record = mock('active_model', :id => 10, :name= => 'Beer', :save => true)
46
+ @active_record.stub!(:changed?).and_return(true,false)
47
+ Product.stub!(:new).and_return(@active_record)
48
+ Product.stub!(:table_name).and_return('some_new_table')
49
+ Legacy::Product.stub!(:count).and_return(1)
50
+ Legacy::Product.stub!(:find).and_return([@legacy_record])
51
+ Legacy::Product.stub!(:table_name).and_return('some_old_table')
52
+ @file = mock("file", :null_object => true)
53
+ File.stub!(:open).and_yield(@file)
54
+ end
55
+
56
+ it "should store key maps in /tmp by default" do
57
+ ActiveMigration::KeyMapper.storage_path.should == "/tmp"
58
+ end
59
+
60
+ it "should allow the key maps storage path to be changed" do
61
+ ActiveMigration::KeyMapper.storage_path = "/foo"
62
+ File.should_receive(:open).with(File.join('/foo', 'product_three_migration_map.yml'), 'w').and_yield(@file)
63
+ ProductThreeMigration.new.run
64
+ ActiveMigration::KeyMapper.storage_path = "/tmp"
65
+ end
66
+
67
+ it "should serialize the keys" do
68
+ @file.should_receive(:write).with({'1_2' => 10}.to_yaml)
69
+ ProductThreeMigration.new.run
70
+ end
71
+
72
+ end
73
+
74
+ describe "A migration" do
75
+
76
+ before do
77
+ @legacy_record = mock('legacy_model', :id => 1, :supplier_id => 1, :supplier_id= => 10)
78
+ @active_record = mock('active_model', :id => 10, :supplier_id= => 10, :save => true)
79
+ @active_record.stub!(:changed?).and_return(true,false)
80
+ Product.stub!(:new).and_return(@active_record)
81
+ Product.stub!(:table_name).and_return('some_new_table')
82
+ Legacy::Product.stub!(:count).and_return(1)
83
+ Legacy::Product.stub!(:find).and_return([@legacy_record])
84
+ Legacy::Product.stub!(:table_name).and_return('some_old_table')
85
+ @file = mock("file", :null_object => true)
86
+ File.stub!(:open).and_return(@file)
87
+ File.stub!(:file?).and_return(true)
88
+ @yaml = {1 => 10}
89
+ YAML.stub!(:load).and_return(@yaml)
90
+ end
91
+
92
+ it "should open the specified maps" do
93
+ File.should_receive(:open).with(File.join('/tmp', 'products_map.yml')).and_return(@file)
94
+ ProductFourMigration.new.run
95
+ end
96
+
97
+ it "should deserialize the specified maps" do
98
+ YAML.should_receive(:load).with(@file).and_return(@yaml)
99
+ ProductFourMigration.new.run
100
+ end
101
+
102
+ it "should set the legacy_model to the new value before the field is migrated" do
103
+ @legacy_record.should_receive(:supplier_id=).with(10).and_return(10)
104
+ ProductFourMigration.new.run
105
+ end
106
+
107
+ it "should set the legacy_model to the old value after the field is migrated" do
108
+ @legacy_record.should_receive(:supplier_id=).with(1).and_return(1)
109
+ ProductFourMigration.new.run
110
+ end
111
+
112
+ describe "#mapped_key" do
113
+
114
+ it 'should return the mapped key' do
115
+ p = ProductFourMigration.new
116
+ p.run
117
+ p.send(:mapped_key, :products, 1).should == 10
118
+ end
119
+
120
+ end
121
+
122
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,16 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'active_migration'
11
+
12
+ Legacy = Module.new
13
+ ActiveRecord = Module.new
14
+ Product = Class.new
15
+ Legacy::Product = Class.new
16
+ ActiveRecord::Base = Class.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mlins-active_migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Lins
@@ -38,8 +38,37 @@ extensions: []
38
38
 
39
39
  extra_rdoc_files: []
40
40
 
41
- files: []
42
-
41
+ files:
42
+ - CHANGELOG
43
+ - MIT-LICENSE
44
+ - Rakefile
45
+ - README
46
+ - VERSION.yml
47
+ - lib/active_migration
48
+ - lib/active_migration/base.rb
49
+ - lib/active_migration/callbacks.rb
50
+ - lib/active_migration/dependencies.rb
51
+ - lib/active_migration/key_mapper.rb
52
+ - lib/active_migration/version.rb
53
+ - lib/active_migration.rb
54
+ - lib/activemigration.rb
55
+ - spec/base_spec.rb
56
+ - spec/callbacks_spec.rb
57
+ - spec/dependencies_spec.rb
58
+ - spec/fixtures
59
+ - spec/fixtures/product_eight_migration.rb
60
+ - spec/fixtures/product_five_migration.rb
61
+ - spec/fixtures/product_four_migration.rb
62
+ - spec/fixtures/product_nine_migration.rb
63
+ - spec/fixtures/product_one_migration.rb
64
+ - spec/fixtures/product_seven_migration.rb
65
+ - spec/fixtures/product_six_migration.rb
66
+ - spec/fixtures/product_ten_migration.rb
67
+ - spec/fixtures/product_three_migration.rb
68
+ - spec/fixtures/product_two_migration.rb
69
+ - spec/key_mapper_spec.rb
70
+ - spec/spec.opts
71
+ - spec/spec_helper.rb
43
72
  has_rdoc: false
44
73
  homepage: http://github.com/mlins/active_migration
45
74
  post_install_message: