mover 0.1.0 → 0.1.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.
- data/README.markdown +12 -12
- data/lib/mover/migrator.rb +3 -2
- data/lib/mover/record.rb +1 -1
- data/lib/mover/table.rb +2 -2
- data/lib/mover.rb +3 -3
- data/require.rb +1 -1
- data/spec/db/migrate/001_create_articles.rb +9 -9
- data/spec/fixtures/article.rb +1 -1
- data/spec/fixtures/comment.rb +1 -1
- data/spec/log/test.log +7266 -3635
- data/spec/mover/migrator_spec.rb +1 -0
- data/spec/mover/record_spec.rb +27 -26
- data/spec/mover/table_spec.rb +12 -11
- data/spec/spec_helper.rb +2 -2
- metadata +1 -1
data/spec/mover/migrator_spec.rb
CHANGED
data/spec/mover/record_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
3
3
|
describe Mover::Base::Record do
|
4
4
|
|
5
5
|
before(:all) do
|
6
|
+
$db.migrate(1)
|
6
7
|
$db.migrate(0)
|
7
8
|
$db.migrate(1)
|
8
9
|
end
|
@@ -14,40 +15,40 @@ describe Mover::Base::Record do
|
|
14
15
|
@articles = create_records
|
15
16
|
@comments = create_records(Comment)
|
16
17
|
@articles[0..1].each do |a|
|
17
|
-
a.move_to(:
|
18
|
+
a.move_to(:archive)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
it "should move some records to the archive table" do
|
22
23
|
Article.count.should == 3
|
23
|
-
|
24
|
+
ArticleArchive.count.should == 2
|
24
25
|
end
|
25
26
|
|
26
27
|
it "should preserve record attributes" do
|
27
28
|
2.times do |x|
|
28
29
|
original = @articles[x]
|
29
|
-
copy =
|
30
|
+
copy = ArticleArchive.find(original.id)
|
30
31
|
record_match?(original, copy)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
35
|
it "should move associated records" do
|
35
36
|
Comment.count.should == 3
|
36
|
-
|
37
|
+
CommentArchive.count.should == 2
|
37
38
|
end
|
38
39
|
|
39
40
|
it "should preserve associated record attributes" do
|
40
41
|
2.times do |x|
|
41
42
|
original = @comments[x]
|
42
|
-
copy =
|
43
|
+
copy = CommentArchive.find(original.id)
|
43
44
|
record_match?(original, copy)
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
47
48
|
it "should populate move_id" do
|
48
49
|
(1..2).each do |x|
|
49
|
-
article =
|
50
|
-
comment =
|
50
|
+
article = ArticleArchive.find(x)
|
51
|
+
comment = CommentArchive.find(x)
|
51
52
|
comment.move_id.nil?.should == false
|
52
53
|
comment.move_id.length.should == 32
|
53
54
|
comment.move_id.should == article.move_id
|
@@ -56,8 +57,8 @@ describe Mover::Base::Record do
|
|
56
57
|
|
57
58
|
it "should populate moved_at" do
|
58
59
|
(1..2).each do |x|
|
59
|
-
article =
|
60
|
-
comment =
|
60
|
+
article = ArticleArchive.find(x)
|
61
|
+
comment = CommentArchive.find(x)
|
61
62
|
comment.moved_at.nil?.should == false
|
62
63
|
comment.moved_at.should == article.moved_at
|
63
64
|
end
|
@@ -70,10 +71,10 @@ describe Mover::Base::Record do
|
|
70
71
|
articles = create_records
|
71
72
|
create_records(Comment)
|
72
73
|
articles[0..1].each do |a|
|
73
|
-
a.move_to(:
|
74
|
+
a.move_to(:archive)
|
74
75
|
end
|
75
|
-
@articles =
|
76
|
-
@comments =
|
76
|
+
@articles = ArticleArchive.find(1, 2)
|
77
|
+
@comments = CommentArchive.find(1, 2)
|
77
78
|
@articles.each do |article|
|
78
79
|
article.move_from
|
79
80
|
end
|
@@ -81,7 +82,7 @@ describe Mover::Base::Record do
|
|
81
82
|
|
82
83
|
it "should move records back to the original table" do
|
83
84
|
Article.count.should == 5
|
84
|
-
|
85
|
+
ArticleArchive.count.should == 0
|
85
86
|
end
|
86
87
|
|
87
88
|
it "should preserve record attributes" do
|
@@ -94,7 +95,7 @@ describe Mover::Base::Record do
|
|
94
95
|
|
95
96
|
it "should move associated records" do
|
96
97
|
Comment.count.should == 5
|
97
|
-
|
98
|
+
CommentArchive.count.should == 0
|
98
99
|
end
|
99
100
|
|
100
101
|
it "should preserve associated record attributes" do
|
@@ -113,19 +114,19 @@ describe Mover::Base::Record do
|
|
113
114
|
before(:all) do
|
114
115
|
create_records
|
115
116
|
create_records(Comment)
|
116
|
-
Article.move_to(:
|
117
|
-
Article.move_to(:
|
117
|
+
Article.move_to(:archive, [ 'id = ? OR id = ?', 1, 2 ])
|
118
|
+
Article.move_to(:draft, [ 'id = ? OR id = ?', 3, 4 ])
|
118
119
|
end
|
119
120
|
|
120
121
|
it "should move the records" do
|
121
122
|
Article.count.should == 1
|
122
|
-
|
123
|
-
|
123
|
+
ArticleArchive.count.should == 2
|
124
|
+
ArticleDraft.count.should == 2
|
124
125
|
end
|
125
126
|
|
126
127
|
it "should move associated records" do
|
127
128
|
Comment.count.should == 3
|
128
|
-
|
129
|
+
CommentArchive.count.should == 2
|
129
130
|
end
|
130
131
|
end
|
131
132
|
|
@@ -134,21 +135,21 @@ describe Mover::Base::Record do
|
|
134
135
|
before(:all) do
|
135
136
|
create_records
|
136
137
|
create_records(Comment)
|
137
|
-
Article.move_to(:
|
138
|
-
Article.move_to(:
|
139
|
-
Article.move_from(:
|
140
|
-
Article.move_from(:
|
138
|
+
Article.move_to(:archive, [ 'id = ? OR id = ?', 1, 2 ])
|
139
|
+
Article.move_to(:draft, [ 'id = ? OR id = ?', 3, 4 ])
|
140
|
+
Article.move_from(:archive, [ 'id = ? OR id = ?', 1, 2 ])
|
141
|
+
Article.move_from(:draft, [ 'id = ? OR id = ?', 3, 4 ])
|
141
142
|
end
|
142
143
|
|
143
144
|
it "should move the records" do
|
144
145
|
Article.count.should == 5
|
145
|
-
|
146
|
-
|
146
|
+
ArticleArchive.count.should == 0
|
147
|
+
ArticleDraft.count.should == 0
|
147
148
|
end
|
148
149
|
|
149
150
|
it "should move associated records" do
|
150
151
|
Comment.count.should == 5
|
151
|
-
|
152
|
+
CommentArchive.count.should == 0
|
152
153
|
end
|
153
154
|
end
|
154
155
|
end
|
data/spec/mover/table_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
3
3
|
describe Mover::Base::Table do
|
4
4
|
|
5
5
|
before(:all) do
|
6
|
+
$db.migrate(1)
|
6
7
|
$db.migrate(0)
|
7
8
|
$db.migrate(1)
|
8
9
|
end
|
@@ -11,11 +12,11 @@ describe Mover::Base::Table do
|
|
11
12
|
|
12
13
|
before(:all) do
|
13
14
|
@article_columns = connection.columns("articles").collect(&:name)
|
14
|
-
@archive_columns = connection.columns("
|
15
|
+
@archive_columns = connection.columns("articles_archive").collect(&:name)
|
15
16
|
end
|
16
17
|
|
17
18
|
it "should create an archive table" do
|
18
|
-
connection.table_exists?("
|
19
|
+
connection.table_exists?("articles_archive").should == true
|
19
20
|
end
|
20
21
|
|
21
22
|
it "should create an archive table with the same structure as the original table" do
|
@@ -27,18 +28,18 @@ describe Mover::Base::Table do
|
|
27
28
|
describe 'with options' do
|
28
29
|
|
29
30
|
before(:all) do
|
30
|
-
Article.drop_movable_table(:
|
31
|
+
Article.drop_movable_table(:archive)
|
31
32
|
Article.create_movable_table(
|
32
|
-
:
|
33
|
+
:archive,
|
33
34
|
:columns => %w(id read),
|
34
35
|
:indexes => %w(read)
|
35
36
|
)
|
36
|
-
@archive_columns = connection.columns("
|
37
|
+
@archive_columns = connection.columns("articles_archive").collect(&:name)
|
37
38
|
end
|
38
39
|
|
39
40
|
after(:all) do
|
40
|
-
Article.drop_movable_table(:
|
41
|
-
Article.create_movable_table(:
|
41
|
+
Article.drop_movable_table(:archive)
|
42
|
+
Article.create_movable_table(:archive)
|
42
43
|
end
|
43
44
|
|
44
45
|
it "should create the correct columns" do
|
@@ -49,7 +50,7 @@ describe Mover::Base::Table do
|
|
49
50
|
end
|
50
51
|
|
51
52
|
it "should create archive indexes" do
|
52
|
-
indexes = Article.send(:indexed_columns, '
|
53
|
+
indexes = Article.send(:indexed_columns, 'articles_archive')
|
53
54
|
indexes.to_set.should == [ "read" ].to_set
|
54
55
|
end
|
55
56
|
end
|
@@ -57,7 +58,7 @@ describe Mover::Base::Table do
|
|
57
58
|
describe 'without options' do
|
58
59
|
|
59
60
|
it "should create archive indexes" do
|
60
|
-
indexes = Article.send(:indexed_columns, '
|
61
|
+
indexes = Article.send(:indexed_columns, 'articles_archive')
|
61
62
|
indexes.to_set.should == [ "id", "title" ].to_set
|
62
63
|
end
|
63
64
|
end
|
@@ -66,12 +67,12 @@ describe Mover::Base::Table do
|
|
66
67
|
describe :drop_movable_table do
|
67
68
|
|
68
69
|
it "should drop the table" do
|
69
|
-
Article.drop_movable_table(:
|
70
|
+
Article.drop_movable_table(:archive)
|
70
71
|
output = connection.execute(<<-SQL)
|
71
72
|
SELECT COUNT(*)
|
72
73
|
FROM information_schema.tables
|
73
74
|
WHERE table_schema = '#{Article.configurations['test']['database']}'
|
74
|
-
AND table_name = '
|
75
|
+
AND table_name = 'articles_archive';
|
75
76
|
SQL
|
76
77
|
output.fetch_row.should == ['0']
|
77
78
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -41,8 +41,8 @@ end
|
|
41
41
|
|
42
42
|
def migrate_with_state(version)
|
43
43
|
@old_article_columns = columns("articles")
|
44
|
-
@old_archive_columns = columns("
|
44
|
+
@old_archive_columns = columns("articles_archive")
|
45
45
|
$db.migrate(version)
|
46
46
|
@new_article_columns = columns("articles")
|
47
|
-
@new_archive_columns = columns("
|
47
|
+
@new_archive_columns = columns("articles_archive")
|
48
48
|
end
|