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.
@@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
3
3
  describe Mover::Migrator do
4
4
 
5
5
  before(:each) do
6
+ $db.migrate(1)
6
7
  $db.migrate(0)
7
8
  $db.migrate(1)
8
9
  end
@@ -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(:archived)
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
- ArchivedArticle.count.should == 2
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 = ArchivedArticle.find(original.id)
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
- ArchivedComment.count.should == 2
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 = ArchivedComment.find(original.id)
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 = ArchivedArticle.find(x)
50
- comment = ArchivedComment.find(x)
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 = ArchivedArticle.find(x)
60
- comment = ArchivedComment.find(x)
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(:archived)
74
+ a.move_to(:archive)
74
75
  end
75
- @articles = ArchivedArticle.find(1, 2)
76
- @comments = ArchivedComment.find(1, 2)
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
- ArchivedArticle.count.should == 0
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
- ArchivedComment.count.should == 0
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(:archived, [ 'id = ? OR id = ?', 1, 2 ])
117
- Article.move_to(:drafted, [ 'id = ? OR id = ?', 3, 4 ])
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
- ArchivedArticle.count.should == 2
123
- DraftedArticle.count.should == 2
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
- ArchivedComment.count.should == 2
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(:archived, [ 'id = ? OR id = ?', 1, 2 ])
138
- Article.move_to(:drafted, [ 'id = ? OR id = ?', 3, 4 ])
139
- Article.move_from(:archived, [ 'id = ? OR id = ?', 1, 2 ])
140
- Article.move_from(:drafted, [ 'id = ? OR id = ?', 3, 4 ])
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
- ArchivedArticle.count.should == 0
146
- DraftedArticle.count.should == 0
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
- ArchivedComment.count.should == 0
152
+ CommentArchive.count.should == 0
152
153
  end
153
154
  end
154
155
  end
@@ -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("archived_articles").collect(&:name)
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?("archived_articles").should == true
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(:archived)
31
+ Article.drop_movable_table(:archive)
31
32
  Article.create_movable_table(
32
- :archived,
33
+ :archive,
33
34
  :columns => %w(id read),
34
35
  :indexes => %w(read)
35
36
  )
36
- @archive_columns = connection.columns("archived_articles").collect(&:name)
37
+ @archive_columns = connection.columns("articles_archive").collect(&:name)
37
38
  end
38
39
 
39
40
  after(:all) do
40
- Article.drop_movable_table(:archived)
41
- Article.create_movable_table(:archived)
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, 'archived_articles')
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, 'archived_articles')
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(:archived)
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 = 'archived_articles';
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("archived_articles")
44
+ @old_archive_columns = columns("articles_archive")
45
45
  $db.migrate(version)
46
46
  @new_article_columns = columns("articles")
47
- @new_archive_columns = columns("archived_articles")
47
+ @new_archive_columns = columns("articles_archive")
48
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh