mover 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{MIT-LICENSE → LICENSE} +2 -2
- data/README.md +100 -0
- data/lib/mover/gems.rb +43 -0
- data/lib/mover/version.rb +3 -0
- data/lib/mover.rb +87 -77
- metadata +37 -30
- data/README.markdown +0 -72
- data/Rakefile +0 -2
- data/init.rb +0 -1
- data/rails/init.rb +0 -2
- data/require.rb +0 -51
- data/spec/Rakefile +0 -10
- data/spec/config/database.yml.example +0 -6
- data/spec/db/migrate/001_create_fixtures.rb +0 -28
- data/spec/fixtures/article.rb +0 -9
- data/spec/fixtures/article_archive.rb +0 -9
- data/spec/fixtures/comment.rb +0 -3
- data/spec/fixtures/comment_archive.rb +0 -3
- data/spec/log/test.log +0 -14153
- data/spec/mover_spec.rb +0 -107
- data/spec/spec_helper.rb +0 -43
data/spec/mover_spec.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mover do
|
4
|
-
|
5
|
-
describe :copy_to do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
[ 1, 0, 1 ].each { |v| $db.migrate(v) }
|
9
|
-
@articles = create_records(Article)
|
10
|
-
@comments = create_records(Comment)
|
11
|
-
@articles[0].copy_to(ArticleArchive)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'should copy both articles and their associations' do
|
15
|
-
it "should copy articles" do
|
16
|
-
Article.copy_to(ArticleArchive, [ 'id = ? OR id = ? OR id = ?', 1, 2, 3 ])
|
17
|
-
Article.count.should == 5
|
18
|
-
Comment.count.should == 5
|
19
|
-
ArticleArchive.count.should == 3
|
20
|
-
CommentArchive.count.should == 3
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'should overwrite first copy if copied twice' do
|
25
|
-
it "should copy articles" do
|
26
|
-
Article.find(1).update_attributes(:title => 'foobar edited')
|
27
|
-
Article.copy_to(ArticleArchive, [ 'id = ? OR id = ? OR id = ?', 1, 2, 3 ])
|
28
|
-
ArticleArchive.find(1).title.should == 'foobar edited'
|
29
|
-
Article.count.should == 5
|
30
|
-
Comment.count.should == 5
|
31
|
-
ArticleArchive.count.should == 3
|
32
|
-
CommentArchive.count.should == 3
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe :move_to do
|
38
|
-
|
39
|
-
before(:each) do
|
40
|
-
[ 1, 0, 1 ].each { |v| $db.migrate(v) }
|
41
|
-
@articles = create_records(Article)
|
42
|
-
@comments = create_records(Comment)
|
43
|
-
@articles[0].move_to(ArticleArchive)
|
44
|
-
Article.move_to(ArticleArchive, [ 'id = ?', 2 ])
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'move records' do
|
48
|
-
|
49
|
-
it "should move both articles and their associations" do
|
50
|
-
Article.count.should == 3
|
51
|
-
Comment.count.should == 3
|
52
|
-
ArticleArchive.count.should == 2
|
53
|
-
CommentArchive.count.should == 2
|
54
|
-
Article.find_by_id(1).nil?.should == true
|
55
|
-
Comment.find_by_id(2).nil?.should == true
|
56
|
-
ArticleArchive.find_by_id(1).nil?.should == false
|
57
|
-
CommentArchive.find_by_id(2).nil?.should == false
|
58
|
-
comments = ArticleArchive.find_by_id(1).comments
|
59
|
-
comments.length.should == 1
|
60
|
-
comments.first.id.should == 1
|
61
|
-
comments = ArticleArchive.find_by_id(2).comments
|
62
|
-
comments.length.should == 1
|
63
|
-
comments.first.id.should == 2
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should assign moved_at" do
|
67
|
-
ArticleArchive.find_by_id(1).moved_at.utc.to_s.should == Time.now.utc.to_s
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe 'move records back' do
|
72
|
-
|
73
|
-
before(:each) do
|
74
|
-
ArticleArchive.find(1).move_to(Article)
|
75
|
-
ArticleArchive.move_to(Article, [ 'id = ?', 2 ])
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should move both articles and their associations" do
|
79
|
-
Article.count.should == 5
|
80
|
-
Comment.count.should == 5
|
81
|
-
ArticleArchive.count.should == 0
|
82
|
-
CommentArchive.count.should == 0
|
83
|
-
Article.find_by_id(1).nil?.should == false
|
84
|
-
Comment.find_by_id(2).nil?.should == false
|
85
|
-
ArticleArchive.find_by_id(1).nil?.should == true
|
86
|
-
CommentArchive.find_by_id(2).nil?.should == true
|
87
|
-
comments = Article.find_by_id(1).comments
|
88
|
-
comments.length.should == 1
|
89
|
-
comments.first.id.should == 1
|
90
|
-
comments = Article.find_by_id(2).comments
|
91
|
-
comments.length.should == 1
|
92
|
-
comments.first.id.should == 2
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe :reserve_id do
|
98
|
-
it "should return an id" do
|
99
|
-
Article.reserve_id.class.should == Fixnum
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should delete the record" do
|
103
|
-
id = Article.reserve_id
|
104
|
-
Article.find_by_id(id).should == nil
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../require")
|
2
|
-
Require.spec_helper!
|
3
|
-
|
4
|
-
Spec::Runner.configure do |config|
|
5
|
-
end
|
6
|
-
|
7
|
-
$db, $log = ActiveWrapper.setup(
|
8
|
-
:base => File.dirname(__FILE__),
|
9
|
-
:env => 'test'
|
10
|
-
)
|
11
|
-
$db.establish_connection
|
12
|
-
|
13
|
-
def record_match?(original, copy)
|
14
|
-
(original.class.column_names & copy.class.column_names).each do |col|
|
15
|
-
copy.send(col).should == original.send(col)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def columns(table)
|
20
|
-
connection.columns(table).collect(&:name)
|
21
|
-
end
|
22
|
-
|
23
|
-
def connection
|
24
|
-
ActiveRecord::Base.connection
|
25
|
-
end
|
26
|
-
|
27
|
-
def create_records(klass, values={})
|
28
|
-
klass.delete_all
|
29
|
-
(1..5).collect do |x|
|
30
|
-
klass.column_names.each do |column|
|
31
|
-
next if column == 'id'
|
32
|
-
if column == 'article_id'
|
33
|
-
values[:article_id] = x
|
34
|
-
else
|
35
|
-
values[column.intern] = "#{klass} #{x} #{column}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
record = klass.new
|
39
|
-
record.id = x
|
40
|
-
record.update_attributes(values)
|
41
|
-
record
|
42
|
-
end
|
43
|
-
end
|