mover 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,31 @@ require 'spec_helper'
2
2
 
3
3
  describe Mover do
4
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
+ Article.copy_to(ArticleArchive, [ 'id = ?', 2 ])
13
+ end
14
+
15
+ describe 'should copy both articles and their associations' do
16
+ it "should copy articles" do
17
+ Article.count.should == 5
18
+ Comment.count.should == 5
19
+ ArticleArchive.count.should == 2
20
+ CommentArchive.count.should == 2
21
+ Article.find_by_id(1).nil?.should == false
22
+ Comment.find_by_id(2).nil?.should == false
23
+ ArticleArchive.find_by_id(1).nil?.should == false
24
+ CommentArchive.find_by_id(2).nil?.should == false
25
+ end
26
+ end
27
+
28
+ end
29
+
5
30
  describe :move_to do
6
31
 
7
32
  before(:each) do
@@ -28,13 +28,16 @@ def create_records(klass, values={})
28
28
  klass.delete_all
29
29
  (1..5).collect do |x|
30
30
  klass.column_names.each do |column|
31
+ next if column == 'id'
31
32
  if column == 'article_id'
32
33
  values[:article_id] = x
33
34
  else
34
35
  values[column.intern] = "#{klass} #{x} #{column}"
35
36
  end
36
37
  end
37
- values[:id] = x
38
- klass.create(values)
38
+ record = klass.new
39
+ record.id = x
40
+ record.update_attributes(values)
41
+ record
39
42
  end
40
43
  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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-04-02 00:00:00 -07:00
12
+ date: 2010-05-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency