genki-dm-has-versions 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'merb-core'
5
5
  require 'merb-core/tasks/merb'
6
6
 
7
7
  GEM_NAME = "dm-has-versions"
8
- GEM_VERSION = "0.1.0"
8
+ GEM_VERSION = "0.1.1"
9
9
  AUTHOR = "Genki Takiuchi"
10
10
  EMAIL = "genki@s21g.com"
11
11
  HOMEPAGE = "http://blog.s21g.com/genki"
@@ -57,6 +57,11 @@ module DataMapper
57
57
  result
58
58
  end
59
59
 
60
+ self.after :destroy do |result|
61
+ self.versions.destroy! if result
62
+ result
63
+ end
64
+
60
65
  include DataMapper::Has::Versions::InstanceMethods
61
66
  end
62
67
 
@@ -41,6 +41,12 @@ describe "dm-has-versions" do
41
41
  @story.versions.should be_empty
42
42
  end
43
43
 
44
+ it "should not generate versions if the story was not modified" do
45
+ @story.versions.should be_empty
46
+ @story.save
47
+ @story.versions.should be_empty
48
+ end
49
+
44
50
  describe "destory and revert of versions" do
45
51
  before do
46
52
  @story.update_attributes :title => 'test-2'
@@ -86,6 +92,23 @@ describe "dm-has-versions" do
86
92
  @story.title.should == "test-2"
87
93
  @story.dirty_attributes[Story.title].should be_nil
88
94
  end
95
+
96
+ it "should destroy all versions if the story was dstroyed" do
97
+ @story.versions.should_not be_empty
98
+ @story.destroy
99
+ Story::Version.all(:story_id => @story.id).should be_empty
100
+ end
101
+
102
+ it "should keep child_models while version control" do
103
+ @story.comments.create :body => "Hey, maiha!"
104
+ @story.comments.count.should == 1
105
+ story = Story.get(@story.id)
106
+ story.version.should == 3
107
+ story.version = 1
108
+ story.title.should == 'test-2'
109
+ story.comments.should_not be_empty
110
+ story.comments.last.body.should == "Hey, maiha!"
111
+ end
89
112
  end
90
113
  end
91
114
  end
@@ -0,0 +1,8 @@
1
+ class Comment
2
+ include DataMapper::Resource
3
+
4
+ property :id, Serial
5
+ property :body, Text
6
+
7
+ belongs_to :story
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genki-dm-has-versions
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
  - Genki Takiuchi