mover 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/LICENSE +1 -1
- data/Rakefile +90 -0
- data/config/gemsets.yml +5 -0
- data/config/gemspec.yml +13 -0
- data/init.rb +1 -0
- data/lib/mover.rb +0 -4
- data/lib/mover/gems.rb +137 -27
- data/mover.gemspec +32 -0
- data/rails/init.rb +1 -0
- data/spec/Rakefile +9 -0
- data/spec/config/database.yml.example +6 -0
- data/spec/db/migrate/001_create_fixtures.rb +28 -0
- data/spec/fixtures/article.rb +6 -0
- data/spec/fixtures/article_archive.rb +6 -0
- data/spec/fixtures/comment.rb +3 -0
- data/spec/fixtures/comment_archive.rb +3 -0
- data/spec/fixtures/gemsets.yml +9 -0
- data/spec/fixtures/gemspec.yml +15 -0
- data/spec/mover/gems_spec.rb +249 -0
- data/spec/mover_spec.rb +134 -0
- data/spec/spec_helper.rb +58 -0
- metadata +60 -18
- data/lib/mover/version.rb +0 -3
data/.gitignore
ADDED
data/LICENSE
CHANGED
data/Rakefile
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/lib/mover/gems'
|
2
|
+
|
3
|
+
Mover::Gems.activate %w(rake rspec)
|
4
|
+
|
5
|
+
require 'rake'
|
6
|
+
require 'spec/rake/spectask'
|
7
|
+
|
8
|
+
def gemspec
|
9
|
+
@gemspec ||= begin
|
10
|
+
file = File.expand_path('../mover.gemspec', __FILE__)
|
11
|
+
eval(File.read(file), binding, file)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if defined?(Spec::Rake::SpecTask)
|
16
|
+
desc "Run specs"
|
17
|
+
Spec::Rake::SpecTask.new do |t|
|
18
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
19
|
+
t.spec_opts = %w(-fs --color)
|
20
|
+
t.warning = true
|
21
|
+
end
|
22
|
+
task :spec
|
23
|
+
task :default => :spec
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Build gem(s)"
|
27
|
+
task :gem do
|
28
|
+
old_gemset = ENV['GEMSET']
|
29
|
+
root = File.expand_path('../', __FILE__)
|
30
|
+
pkg = "#{root}/pkg"
|
31
|
+
system "rm -Rf #{pkg}"
|
32
|
+
Mover::Gems.gemset_names.each do |gemset|
|
33
|
+
ENV['GEMSET'] = gemset.to_s
|
34
|
+
system "cd #{root} && gem build mover.gemspec"
|
35
|
+
system "mkdir -p #{pkg} && mv *.gem pkg"
|
36
|
+
end
|
37
|
+
ENV['GEMSET'] = old_gemset
|
38
|
+
end
|
39
|
+
|
40
|
+
namespace :gem do
|
41
|
+
desc "Install gem(s)"
|
42
|
+
task :install do
|
43
|
+
Rake::Task['gem'].invoke
|
44
|
+
Dir["#{File.dirname(__FILE__)}/pkg/*.gem"].each do |pkg|
|
45
|
+
system "gem install #{pkg} --no-ri --no-rdoc"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Push gem(s)"
|
50
|
+
task :push do
|
51
|
+
Rake::Task['gem'].invoke
|
52
|
+
Dir["#{File.dirname(__FILE__)}/pkg/*.gem"].each do |pkg|
|
53
|
+
system "gem push #{pkg}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
namespace :gems do
|
59
|
+
desc "Install gem dependencies (DEV=0 DOCS=0 GEMSPEC=default SUDO=0)"
|
60
|
+
task :install do
|
61
|
+
dev = ENV['DEV'] == '1'
|
62
|
+
docs = ENV['DOCS'] == '1' ? '' : '--no-ri --no-rdoc'
|
63
|
+
gemset = ENV['GEMSET']
|
64
|
+
sudo = ENV['SUDO'] == '1' ? 'sudo' : ''
|
65
|
+
|
66
|
+
Mover::Gems.gemset = gemset if gemset
|
67
|
+
|
68
|
+
if dev
|
69
|
+
gems = Mover::Gems.gemspec.development_dependencies
|
70
|
+
else
|
71
|
+
gems = Mover::Gems.gemspec.dependencies
|
72
|
+
end
|
73
|
+
|
74
|
+
gems.each do |name|
|
75
|
+
name = name.to_s
|
76
|
+
version = Mover::Gems.versions[name]
|
77
|
+
if Gem.source_index.find_name(name, version).empty?
|
78
|
+
version = version ? "-v #{version}" : ''
|
79
|
+
system "#{sudo} gem install #{name} #{version} #{docs}"
|
80
|
+
else
|
81
|
+
puts "already installed: #{name} #{version}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
desc "Validate the gemspec"
|
88
|
+
task :gemspec do
|
89
|
+
gemspec.validate
|
90
|
+
end
|
data/config/gemsets.yml
ADDED
data/config/gemspec.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
name: mover
|
2
|
+
version: 0.3.6
|
3
|
+
authors:
|
4
|
+
- Winton Welsh
|
5
|
+
email: mail@wintoni.us
|
6
|
+
homepage: http://github.com/winton/mover
|
7
|
+
summary: Move ActiveRecord records across tables like it ain't no thang
|
8
|
+
description: Move ActiveRecord records across tables like it ain't no thang
|
9
|
+
dependencies: null
|
10
|
+
development_dependencies:
|
11
|
+
- active_wrapper
|
12
|
+
- rake
|
13
|
+
- rspec
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init"
|
data/lib/mover.rb
CHANGED
data/lib/mover/gems.rb
CHANGED
@@ -1,41 +1,151 @@
|
|
1
1
|
unless defined?(Mover::Gems)
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'yaml'
|
4
4
|
|
5
5
|
module Mover
|
6
|
-
|
7
|
-
|
8
|
-
VERSIONS = {
|
9
|
-
:active_wrapper => '=0.3.4',
|
10
|
-
:rake => '=0.8.7',
|
11
|
-
:rspec => '=1.3.1'
|
12
|
-
}
|
13
|
-
|
14
|
-
TYPES = {
|
15
|
-
:gemspec => [],
|
16
|
-
:gemspec_dev => [ :active_wrapper, :rspec ],
|
17
|
-
:lib => [],
|
18
|
-
:rake => [ :rake, :rspec ],
|
19
|
-
:spec => [ :active_wrapper, :rspec ],
|
20
|
-
:spec_rake => [ :active_wrapper ]
|
21
|
-
}
|
22
|
-
|
6
|
+
module Gems
|
23
7
|
class <<self
|
24
8
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
9
|
+
attr_accessor :config
|
10
|
+
attr_reader :gemset, :gemsets, :versions
|
11
|
+
|
12
|
+
class SimpleStruct
|
13
|
+
attr_reader :hash
|
14
|
+
|
15
|
+
def initialize(hash)
|
16
|
+
@hash = hash
|
17
|
+
@hash.each do |key, value|
|
18
|
+
self.class.send(:define_method, key) { @hash[key] }
|
19
|
+
self.class.send(:define_method, "#{key}=") { |v| @hash[key] = v }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Gems.config = SimpleStruct.new(
|
25
|
+
:gemsets => [ "#{File.expand_path('../../../', __FILE__)}/config/gemsets.yml" ],
|
26
|
+
:gemspec => "#{File.expand_path('../../../', __FILE__)}/config/gemspec.yml",
|
27
|
+
:warn => true
|
28
|
+
)
|
29
|
+
|
30
|
+
def activate(*gems)
|
31
|
+
begin
|
32
|
+
require 'rubygems' unless defined?(::Gem)
|
33
|
+
rescue LoadError
|
34
|
+
puts "rubygems library could not be required" if @config.warn
|
35
|
+
end
|
36
|
+
|
37
|
+
self.gemset ||= gemset_from_loaded_specs
|
38
|
+
|
39
|
+
gems.flatten.collect(&:to_sym).each do |name|
|
40
|
+
version = @versions[name]
|
41
|
+
vendor = File.expand_path("../../../vendor/#{name}/lib", __FILE__)
|
42
|
+
if File.exists?(vendor)
|
43
|
+
$:.unshift vendor
|
44
|
+
elsif defined?(gem)
|
45
|
+
gem name.to_s, version
|
46
|
+
else
|
47
|
+
puts "#{name} #{"(#{version})" if version} failed to activate" if @config.warn
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def dependencies
|
53
|
+
dependency_filter(@gemspec.dependencies, @gemset)
|
54
|
+
end
|
55
|
+
|
56
|
+
def development_dependencies
|
57
|
+
dependency_filter(@gemspec.development_dependencies, @gemset)
|
58
|
+
end
|
59
|
+
|
60
|
+
def gemset=(gemset)
|
61
|
+
if gemset
|
62
|
+
@gemset = gemset.to_sym
|
63
|
+
|
64
|
+
@gemsets = @config.gemsets.reverse.collect { |config|
|
65
|
+
if config.is_a?(::String)
|
66
|
+
YAML::load(File.read(config)) rescue {}
|
67
|
+
elsif config.is_a?(::Hash)
|
68
|
+
config
|
69
|
+
end
|
70
|
+
}.inject({}) do |hash, config|
|
71
|
+
deep_merge(hash, symbolize_keys(config))
|
72
|
+
end
|
73
|
+
|
74
|
+
@versions = (@gemsets[gemspec.name.to_sym] || {}).inject({}) do |hash, (key, value)|
|
75
|
+
if !value.is_a?(::Hash) && value
|
76
|
+
hash[key] = value
|
77
|
+
elsif key == @gemset
|
78
|
+
(value || {}).each { |k, v| hash[k] = v }
|
31
79
|
end
|
80
|
+
hash
|
32
81
|
end
|
82
|
+
else
|
83
|
+
@gemset = nil
|
84
|
+
@gemsets = nil
|
85
|
+
@versions = nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def gemset_names
|
90
|
+
(
|
91
|
+
[ :default ] +
|
92
|
+
@gemsets[gemspec.name.to_sym].inject([]) { |array, (key, value)|
|
93
|
+
array.push(key) if value.is_a?(::Hash) || value.nil?
|
94
|
+
array
|
95
|
+
}
|
96
|
+
).uniq
|
97
|
+
end
|
98
|
+
|
99
|
+
def gemspec(reload=false)
|
100
|
+
if @gemspec && !reload
|
101
|
+
@gemspec
|
102
|
+
else
|
103
|
+
data = YAML::load(File.read(@config.gemspec)) rescue {}
|
104
|
+
@gemspec = SimpleStruct.new(data)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def deep_merge(first, second)
|
111
|
+
merger = lambda do |key, v1, v2|
|
112
|
+
Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2
|
33
113
|
end
|
114
|
+
first.merge(second, &merger)
|
34
115
|
end
|
35
116
|
|
36
|
-
def
|
37
|
-
(
|
38
|
-
|
117
|
+
def dependency_filter(dependencies, match)
|
118
|
+
(dependencies || []).inject([]) { |array, value|
|
119
|
+
if value.is_a?(::Hash)
|
120
|
+
array += value[match.to_s] if value[match.to_s]
|
121
|
+
else
|
122
|
+
array << value
|
123
|
+
end
|
124
|
+
array
|
125
|
+
}.uniq.collect(&:to_sym)
|
126
|
+
end
|
127
|
+
|
128
|
+
def gemset_from_loaded_specs
|
129
|
+
if defined?(Gem)
|
130
|
+
Gem.loaded_specs.each do |name, spec|
|
131
|
+
if name == gemspec.name
|
132
|
+
return :default
|
133
|
+
elsif name[0..gemspec.name.length] == "#{gemspec.name}-"
|
134
|
+
return name[gemspec.name.length+1..-1].to_sym
|
135
|
+
end
|
136
|
+
end
|
137
|
+
:default
|
138
|
+
else
|
139
|
+
:none
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def symbolize_keys(hash)
|
144
|
+
return {} unless hash.is_a?(::Hash)
|
145
|
+
hash.inject({}) do |options, (key, value)|
|
146
|
+
value = symbolize_keys(value) if value.is_a?(::Hash)
|
147
|
+
options[(key.to_sym rescue key) || key] = value
|
148
|
+
options
|
39
149
|
end
|
40
150
|
end
|
41
151
|
end
|
data/mover.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
root = File.expand_path('../', __FILE__)
|
3
|
+
lib = "#{root}/lib"
|
4
|
+
$:.unshift lib unless $:.include?(lib)
|
5
|
+
|
6
|
+
require 'mover/gems'
|
7
|
+
Mover::Gems.gemset ||= ENV['GEMSET'] || :default
|
8
|
+
|
9
|
+
Gem::Specification.new do |s|
|
10
|
+
Mover::Gems.gemspec.hash.each do |key, value|
|
11
|
+
if key == 'name' && Mover::Gems.gemset != :default
|
12
|
+
s.name = "#{value}-#{Mover::Gems.gemset}"
|
13
|
+
elsif key == 'summary' && Mover::Gems.gemset == :solo
|
14
|
+
s.summary = value + " (no dependencies)"
|
15
|
+
elsif !%w(dependencies development_dependencies).include?(key)
|
16
|
+
s.send "#{key}=", value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Mover::Gems.dependencies.each do |g|
|
21
|
+
s.add_dependency g.to_s, Mover::Gems.versions[g]
|
22
|
+
end
|
23
|
+
|
24
|
+
Mover::Gems.development_dependencies.each do |g|
|
25
|
+
s.add_development_dependency g.to_s, Mover::Gems.versions[g]
|
26
|
+
end
|
27
|
+
|
28
|
+
s.executables = `cd #{root} && git ls-files -- {bin}/*`.split("\n").collect { |f| File.basename(f) }
|
29
|
+
s.files = `cd #{root} && git ls-files`.split("\n")
|
30
|
+
s.require_paths = %w(lib)
|
31
|
+
s.test_files = `cd #{root} && git ls-files -- {features,test,spec}/*`.split("\n")
|
32
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/mover')
|
data/spec/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class CreateFixtures < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
[ :articles, :article_archives ].each do |table|
|
4
|
+
create_table table do |t|
|
5
|
+
t.string :title
|
6
|
+
t.string :body
|
7
|
+
t.boolean :read
|
8
|
+
t.datetime :moved_at
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
[ :comments, :comment_archives ].each do |table|
|
13
|
+
create_table table do |t|
|
14
|
+
t.string :title
|
15
|
+
t.string :body
|
16
|
+
t.boolean :read
|
17
|
+
t.integer :article_id
|
18
|
+
t.datetime :moved_at
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.down
|
24
|
+
[ :articles, :article_archives, :comments, :comment_archives ].each do |table|
|
25
|
+
drop_table table
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
name: name
|
2
|
+
version: 0.1.0
|
3
|
+
authors:
|
4
|
+
- Author
|
5
|
+
email: email@email.com
|
6
|
+
homepage: http://github.com/author/name
|
7
|
+
summary: Summary
|
8
|
+
description: Description
|
9
|
+
dependencies:
|
10
|
+
- rake
|
11
|
+
- default:
|
12
|
+
- mysql
|
13
|
+
- rspec2:
|
14
|
+
- mysql2
|
15
|
+
development_dependencies: null
|
@@ -0,0 +1,249 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mover::Gems do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@old_config = Mover::Gems.config
|
7
|
+
|
8
|
+
Mover::Gems.config.gemspec = "#{$root}/spec/fixtures/gemspec.yml"
|
9
|
+
Mover::Gems.config.gemsets = [
|
10
|
+
"#{$root}/spec/fixtures/gemsets.yml"
|
11
|
+
]
|
12
|
+
Mover::Gems.config.warn = true
|
13
|
+
|
14
|
+
Mover::Gems.gemspec true
|
15
|
+
Mover::Gems.gemset = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:each) do
|
19
|
+
Mover::Gems.config = @old_config
|
20
|
+
end
|
21
|
+
|
22
|
+
describe :activate do
|
23
|
+
it "should activate gems" do
|
24
|
+
Mover::Gems.stub!(:gem)
|
25
|
+
Mover::Gems.should_receive(:gem).with('rspec', '=1.3.1')
|
26
|
+
Mover::Gems.should_receive(:gem).with('rake', '=0.8.7')
|
27
|
+
Mover::Gems.activate :rspec, 'rake'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe :gemset= do
|
32
|
+
before(:each) do
|
33
|
+
Mover::Gems.config.gemsets = [
|
34
|
+
{
|
35
|
+
:name => {
|
36
|
+
:rake => '>0.8.6',
|
37
|
+
:default => {
|
38
|
+
:externals => '=1.0.2'
|
39
|
+
}
|
40
|
+
}
|
41
|
+
},
|
42
|
+
"#{$root}/spec/fixtures/gemsets.yml"
|
43
|
+
]
|
44
|
+
end
|
45
|
+
|
46
|
+
describe :default do
|
47
|
+
before(:each) do
|
48
|
+
Mover::Gems.gemset = :default
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should set @gemset" do
|
52
|
+
Mover::Gems.gemset.should == :default
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should set @gemsets" do
|
56
|
+
Mover::Gems.gemsets.should == {
|
57
|
+
:name => {
|
58
|
+
:rake => ">0.8.6",
|
59
|
+
:default => {
|
60
|
+
:externals => '=1.0.2',
|
61
|
+
:mysql => "=2.8.1",
|
62
|
+
:rspec => "=1.3.1"
|
63
|
+
},
|
64
|
+
:rspec2 => {
|
65
|
+
:mysql2 => "=0.2.6",
|
66
|
+
:rspec => "=2.3.0"
|
67
|
+
},
|
68
|
+
:solo => nil
|
69
|
+
}
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should set Gems.versions" do
|
74
|
+
Mover::Gems.versions.should == {
|
75
|
+
:externals => "=1.0.2",
|
76
|
+
:mysql => "=2.8.1",
|
77
|
+
:rake => ">0.8.6",
|
78
|
+
:rspec => "=1.3.1"
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return proper values for Gems.dependencies" do
|
83
|
+
Mover::Gems.dependencies.should == [ :rake, :mysql ]
|
84
|
+
Mover::Gems.development_dependencies.should == []
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return proper values for Gems.gemset_names" do
|
88
|
+
Mover::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe :rspec2 do
|
93
|
+
before(:each) do
|
94
|
+
Mover::Gems.gemset = "rspec2"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should set @gemset" do
|
98
|
+
Mover::Gems.gemset.should == :rspec2
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should set @gemsets" do
|
102
|
+
Mover::Gems.gemsets.should == {
|
103
|
+
:name => {
|
104
|
+
:rake => ">0.8.6",
|
105
|
+
:default => {
|
106
|
+
:externals => '=1.0.2',
|
107
|
+
:mysql => "=2.8.1",
|
108
|
+
:rspec => "=1.3.1"
|
109
|
+
},
|
110
|
+
:rspec2 => {
|
111
|
+
:mysql2=>"=0.2.6",
|
112
|
+
:rspec => "=2.3.0"
|
113
|
+
},
|
114
|
+
:solo => nil
|
115
|
+
}
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should set Gems.versions" do
|
120
|
+
Mover::Gems.versions.should == {
|
121
|
+
:mysql2 => "=0.2.6",
|
122
|
+
:rake => ">0.8.6",
|
123
|
+
:rspec => "=2.3.0"
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should return proper values for Gems.dependencies" do
|
128
|
+
Mover::Gems.dependencies.should == [ :rake, :mysql2 ]
|
129
|
+
Mover::Gems.development_dependencies.should == []
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should return proper values for Gems.gemset_names" do
|
133
|
+
Mover::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe :solo do
|
138
|
+
before(:each) do
|
139
|
+
Mover::Gems.gemset = :solo
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should set @gemset" do
|
143
|
+
Mover::Gems.gemset.should == :solo
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should set @gemsets" do
|
147
|
+
Mover::Gems.gemsets.should == {
|
148
|
+
:name => {
|
149
|
+
:rake => ">0.8.6",
|
150
|
+
:default => {
|
151
|
+
:externals => '=1.0.2',
|
152
|
+
:mysql => "=2.8.1",
|
153
|
+
:rspec => "=1.3.1"
|
154
|
+
},
|
155
|
+
:rspec2 => {
|
156
|
+
:mysql2=>"=0.2.6",
|
157
|
+
:rspec => "=2.3.0"
|
158
|
+
},
|
159
|
+
:solo => nil
|
160
|
+
}
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should set Gems.versions" do
|
165
|
+
Mover::Gems.versions.should == {:rake=>">0.8.6"}
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should return proper values for Gems.dependencies" do
|
169
|
+
Mover::Gems.dependencies.should == [:rake]
|
170
|
+
Mover::Gems.development_dependencies.should == []
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should return proper values for Gems.gemset_names" do
|
174
|
+
Mover::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe :nil do
|
179
|
+
before(:each) do
|
180
|
+
Mover::Gems.gemset = nil
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should set everything to nil" do
|
184
|
+
Mover::Gems.gemset.should == nil
|
185
|
+
Mover::Gems.gemsets.should == nil
|
186
|
+
Mover::Gems.versions.should == nil
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe :gemset_from_loaded_specs do
|
192
|
+
before(:each) do
|
193
|
+
Gem.stub!(:loaded_specs)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should return the correct gemset for name gem" do
|
197
|
+
Gem.should_receive(:loaded_specs).and_return({ "name" => nil })
|
198
|
+
Mover::Gems.send(:gemset_from_loaded_specs).should == :default
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should return the correct gemset for name-rspec gem" do
|
202
|
+
Gem.should_receive(:loaded_specs).and_return({ "name-rspec2" => nil })
|
203
|
+
Mover::Gems.send(:gemset_from_loaded_specs).should == :rspec2
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe :reload_gemspec do
|
208
|
+
it "should populate @gemspec" do
|
209
|
+
Mover::Gems.gemspec.hash.should == {
|
210
|
+
"name" => "name",
|
211
|
+
"version" => "0.1.0",
|
212
|
+
"authors" => ["Author"],
|
213
|
+
"email" => "email@email.com",
|
214
|
+
"homepage" => "http://github.com/author/name",
|
215
|
+
"summary" => "Summary",
|
216
|
+
"description" => "Description",
|
217
|
+
"dependencies" => [
|
218
|
+
"rake",
|
219
|
+
{ "default" => [ "mysql" ] },
|
220
|
+
{ "rspec2" => [ "mysql2" ] }
|
221
|
+
],
|
222
|
+
"development_dependencies" => nil
|
223
|
+
}
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should create methods from keys of @gemspec" do
|
227
|
+
Mover::Gems.gemspec.name.should == "name"
|
228
|
+
Mover::Gems.gemspec.version.should == "0.1.0"
|
229
|
+
Mover::Gems.gemspec.authors.should == ["Author"]
|
230
|
+
Mover::Gems.gemspec.email.should == "email@email.com"
|
231
|
+
Mover::Gems.gemspec.homepage.should == "http://github.com/author/name"
|
232
|
+
Mover::Gems.gemspec.summary.should == "Summary"
|
233
|
+
Mover::Gems.gemspec.description.should == "Description"
|
234
|
+
Mover::Gems.gemspec.dependencies.should == [
|
235
|
+
"rake",
|
236
|
+
{ "default" => ["mysql"] },
|
237
|
+
{ "rspec2" => [ "mysql2" ] }
|
238
|
+
]
|
239
|
+
Mover::Gems.gemspec.development_dependencies.should == nil
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should produce a valid gemspec" do
|
243
|
+
Mover::Gems.gemset = :default
|
244
|
+
gemspec = File.expand_path("../../../mover.gemspec", __FILE__)
|
245
|
+
gemspec = eval(File.read(gemspec), binding, gemspec)
|
246
|
+
gemspec.validate.should == true
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
data/spec/mover_spec.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mover do
|
4
|
+
|
5
|
+
[ :none, :generic, :quick ].each do |option|
|
6
|
+
|
7
|
+
describe "(option: #{option})" do
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@options = {}
|
11
|
+
@options[option] = true
|
12
|
+
end
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
[ 1, 0, 1 ].each { |v| $db.migrate(v) }
|
16
|
+
@articles = create_records(Article)
|
17
|
+
@comments = create_records(Comment)
|
18
|
+
@articles[0].move_to(ArticleArchive, @options)
|
19
|
+
Article.move_to(
|
20
|
+
ArticleArchive,
|
21
|
+
@options.merge(:conditions => [ 'articles.id = ?', 2 ])
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'move records' do
|
26
|
+
|
27
|
+
it "should move both articles and their associations" do
|
28
|
+
Article.count.should == 3
|
29
|
+
Comment.count.should == 3
|
30
|
+
ArticleArchive.count.should == 2
|
31
|
+
CommentArchive.count.should == 2
|
32
|
+
Article.find_by_id(1).nil?.should == true
|
33
|
+
Comment.find_by_id(2).nil?.should == true
|
34
|
+
ArticleArchive.find_by_id(1).nil?.should == false
|
35
|
+
CommentArchive.find_by_id(2).nil?.should == false
|
36
|
+
comments = ArticleArchive.find_by_id(1).comments
|
37
|
+
comments.length.should == 1
|
38
|
+
comments.first.id.should == 1
|
39
|
+
comments = ArticleArchive.find_by_id(2).comments
|
40
|
+
comments.length.should == 1
|
41
|
+
comments.first.id.should == 2
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should assign moved_at" do
|
45
|
+
ArticleArchive.find_by_id(1).moved_at.utc.to_s.should == Time.now.utc.to_s
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'move records back' do
|
50
|
+
|
51
|
+
before(:each) do
|
52
|
+
ArticleArchive.find(1).move_to(Article, @options)
|
53
|
+
ArticleArchive.move_to(
|
54
|
+
Article,
|
55
|
+
@options.merge(:conditions => [ 'article_archives.id = ?', 2 ])
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should move both articles and their associations" do
|
60
|
+
Article.count.should == 5
|
61
|
+
Comment.count.should == 5
|
62
|
+
ArticleArchive.count.should == 0
|
63
|
+
CommentArchive.count.should == 0
|
64
|
+
Article.find_by_id(1).nil?.should == false
|
65
|
+
Comment.find_by_id(2).nil?.should == false
|
66
|
+
ArticleArchive.find_by_id(1).nil?.should == true
|
67
|
+
CommentArchive.find_by_id(2).nil?.should == true
|
68
|
+
comments = Article.find_by_id(1).comments
|
69
|
+
comments.length.should == 1
|
70
|
+
comments.first.id.should == 1
|
71
|
+
comments = Article.find_by_id(2).comments
|
72
|
+
comments.length.should == 1
|
73
|
+
comments.first.id.should == 2
|
74
|
+
end
|
75
|
+
|
76
|
+
unless option == :quick
|
77
|
+
it "should copy articles" do
|
78
|
+
article_1 = Article.find(1)
|
79
|
+
article_1.update_attributes(:title => 'edited')
|
80
|
+
article_2 = Article.find(2)
|
81
|
+
article_2.update_attributes(:title => 'edited')
|
82
|
+
article_1.move_to(ArticleArchive, @options.merge(:copy => true))
|
83
|
+
Article.move_to(
|
84
|
+
ArticleArchive,
|
85
|
+
@options.merge(
|
86
|
+
:conditions => [ 'articles.id = ?', 2 ],
|
87
|
+
:copy => true
|
88
|
+
)
|
89
|
+
)
|
90
|
+
ArticleArchive.find(1).title.should == 'edited'
|
91
|
+
ArticleArchive.find(2).title.should == 'edited'
|
92
|
+
Article.count.should == 5
|
93
|
+
Comment.count.should == 5
|
94
|
+
ArticleArchive.count.should == 2
|
95
|
+
CommentArchive.count.should == 2
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'migrate magic column' do
|
103
|
+
|
104
|
+
before(:each) do
|
105
|
+
[ 1, 0, 1 ].each { |v| $db.migrate(v) }
|
106
|
+
@moved_at = Time.now.utc - 60
|
107
|
+
@articles = create_records(Article, :moved_at => @moved_at)
|
108
|
+
@comments = create_records(Comment)
|
109
|
+
@articles[0].move_to(ArticleArchive, :migrate => true)
|
110
|
+
Article.move_to(
|
111
|
+
ArticleArchive,
|
112
|
+
:conditions => [ 'articles.id = ?', 2 ],
|
113
|
+
:migrate => true
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should migrate magic column" do
|
118
|
+
ArticleArchive.find(1).moved_at.to_s.should == @moved_at.to_s
|
119
|
+
ArticleArchive.find(2).moved_at.to_s.should == @moved_at.to_s
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe :reserve_id do
|
124
|
+
|
125
|
+
it "should return an id" do
|
126
|
+
Article.reserve_id.class.should == Fixnum
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should delete the record" do
|
130
|
+
id = Article.reserve_id
|
131
|
+
Article.find_by_id(id).should == nil
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
3
|
+
$root = File.expand_path('../../', __FILE__)
|
4
|
+
require "#{$root}/lib/mover/gems"
|
5
|
+
|
6
|
+
Mover::Gems.activate %w(active_wrapper rspec)
|
7
|
+
|
8
|
+
require 'active_wrapper'
|
9
|
+
require 'fileutils'
|
10
|
+
|
11
|
+
require "#{$root}/lib/mover"
|
12
|
+
|
13
|
+
require "#{$root}/spec/fixtures/article"
|
14
|
+
require "#{$root}/spec/fixtures/article_archive"
|
15
|
+
require "#{$root}/spec/fixtures/comment"
|
16
|
+
require "#{$root}/spec/fixtures/comment_archive"
|
17
|
+
|
18
|
+
Spec::Runner.configure do |config|
|
19
|
+
end
|
20
|
+
|
21
|
+
$db, $log = ActiveWrapper.setup(
|
22
|
+
:base => File.dirname(__FILE__),
|
23
|
+
:env => 'test'
|
24
|
+
)
|
25
|
+
$db.establish_connection
|
26
|
+
|
27
|
+
def record_match?(original, copy)
|
28
|
+
(original.class.column_names & copy.class.column_names).each do |col|
|
29
|
+
copy.send(col).should == original.send(col)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def columns(table)
|
34
|
+
connection.columns(table).collect(&:name)
|
35
|
+
end
|
36
|
+
|
37
|
+
def connection
|
38
|
+
ActiveRecord::Base.connection
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_records(klass, values={})
|
42
|
+
klass.delete_all
|
43
|
+
keys = values.keys
|
44
|
+
(1..5).collect do |x|
|
45
|
+
klass.column_names.each do |column|
|
46
|
+
next if column == 'id'
|
47
|
+
if column == 'article_id' && !keys.include?(:article_id)
|
48
|
+
values[:article_id] = x
|
49
|
+
elsif !keys.include?(column.intern)
|
50
|
+
values[column.intern] = "#{klass} #{x} #{column}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
record = klass.new
|
54
|
+
record.id = x
|
55
|
+
record.update_attributes(values)
|
56
|
+
record
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 6
|
9
|
+
version: 0.3.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Winton Welsh
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-09 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -27,29 +27,42 @@ dependencies:
|
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 0
|
30
|
-
- 3
|
31
30
|
- 4
|
32
|
-
|
31
|
+
- 3
|
32
|
+
version: 0.4.3
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: rake
|
37
37
|
prerelease: false
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- - "
|
41
|
+
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
segments:
|
44
|
-
-
|
45
|
-
-
|
46
|
-
-
|
47
|
-
version:
|
44
|
+
- 0
|
45
|
+
- 8
|
46
|
+
- 7
|
47
|
+
version: 0.8.7
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rspec
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 1
|
60
|
+
- 0
|
61
|
+
version: "1.0"
|
62
|
+
type: :development
|
63
|
+
version_requirements: *id003
|
50
64
|
description: Move ActiveRecord records across tables like it ain't no thang
|
51
|
-
email:
|
52
|
-
- mail@wintoni.us
|
65
|
+
email: mail@wintoni.us
|
53
66
|
executables: []
|
54
67
|
|
55
68
|
extensions: []
|
@@ -57,11 +70,29 @@ extensions: []
|
|
57
70
|
extra_rdoc_files: []
|
58
71
|
|
59
72
|
files:
|
60
|
-
-
|
61
|
-
- lib/mover/version.rb
|
62
|
-
- lib/mover.rb
|
73
|
+
- .gitignore
|
63
74
|
- LICENSE
|
64
75
|
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- config/gemsets.yml
|
78
|
+
- config/gemspec.yml
|
79
|
+
- init.rb
|
80
|
+
- lib/mover.rb
|
81
|
+
- lib/mover/gems.rb
|
82
|
+
- mover.gemspec
|
83
|
+
- rails/init.rb
|
84
|
+
- spec/Rakefile
|
85
|
+
- spec/config/database.yml.example
|
86
|
+
- spec/db/migrate/001_create_fixtures.rb
|
87
|
+
- spec/fixtures/article.rb
|
88
|
+
- spec/fixtures/article_archive.rb
|
89
|
+
- spec/fixtures/comment.rb
|
90
|
+
- spec/fixtures/comment_archive.rb
|
91
|
+
- spec/fixtures/gemsets.yml
|
92
|
+
- spec/fixtures/gemspec.yml
|
93
|
+
- spec/mover/gems_spec.rb
|
94
|
+
- spec/mover_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
65
96
|
has_rdoc: true
|
66
97
|
homepage: http://github.com/winton/mover
|
67
98
|
licenses: []
|
@@ -94,5 +125,16 @@ rubygems_version: 1.3.7
|
|
94
125
|
signing_key:
|
95
126
|
specification_version: 3
|
96
127
|
summary: Move ActiveRecord records across tables like it ain't no thang
|
97
|
-
test_files:
|
98
|
-
|
128
|
+
test_files:
|
129
|
+
- spec/Rakefile
|
130
|
+
- spec/config/database.yml.example
|
131
|
+
- spec/db/migrate/001_create_fixtures.rb
|
132
|
+
- spec/fixtures/article.rb
|
133
|
+
- spec/fixtures/article_archive.rb
|
134
|
+
- spec/fixtures/comment.rb
|
135
|
+
- spec/fixtures/comment_archive.rb
|
136
|
+
- spec/fixtures/gemsets.yml
|
137
|
+
- spec/fixtures/gemspec.yml
|
138
|
+
- spec/mover/gems_spec.rb
|
139
|
+
- spec/mover_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
data/lib/mover/version.rb
DELETED