spec/integration/integration_spec.rb in mongoid-history-0.0.9 vs spec/integration/integration_spec.rb in mongoid-history-0.1.0
- old
+ new
@@ -14,11 +14,11 @@
field :title
field :body
field :rating
embeds_many :comments
- track_history :on => [:title, :body]
+ track_history :on => [:title, :body], :track_destroy => true
end
class Comment
include Mongoid::Document
include Mongoid::Timestamps
@@ -35,11 +35,11 @@
include Mongoid::Timestamps
include Mongoid::History::Trackable
field :email
field :name
- track_history :except => [:email]
+ track_history :except => [:email]
end
end
before :each do
@user = User.create(:name => "Aaron", :email => "aaron@randomemail.com")
@@ -60,11 +60,10 @@
it "should not assign title and body on original" do
@comment.history_tracks.first.original.should == {}
end
-
it "should assign modifier" do
@comment.history_tracks.first.modifier.should == @user
end
it "should assign version" do
@@ -72,16 +71,39 @@
end
it "should assign scope" do
@comment.history_tracks.first.scope == "Post"
end
+
+ it "should assign method" do
+ @comment.history_tracks.first.action == "create"
+ end
it "should assign association_chain" do
@comment.history_tracks.first.association_chain = [{:id => @post.id, :name => "Post"}, {:id => @comment.id, :name => "Comment"}]
end
end
+ describe "on destruction" do
+ it "should have two history track records in post" do
+ lambda {
+ @post.destroy
+ }.should change(HistoryTracker, :count).by(1)
+ end
+
+ it "should assign destroy on track record" do
+ @post.destroy
+ @post.history_tracks.last.action == "destroy"
+ end
+
+ it "should return affected attributes from track record" do
+ @post.destroy
+ @post.history_tracks.last.affected["title"] == "Test"
+ end
+
+ end
+
describe "on update non-embedded" do
it "should create a history track if changed attributes match tracked attributes" do
lambda {
@post.update_attributes(:title => "Another Test")
}.should change(HistoryTracker, :count).by(1)
@@ -97,10 +119,15 @@
@post.update_attributes(:title => "Another Test")
@post.history_tracks.first.modified.should == {
"title" => "Another Test"
}
end
+
+ it "should assign method field" do
+ @post.update_attributes(:title => "Another Test")
+ @post.history_tracks.first.action.should == "update"
+ end
it "should assign original fields" do
@post.update_attributes(:title => "Another Test")
@post.history_tracks.first.original.should == {
"title" => "Test"
@@ -219,10 +246,16 @@
@post.update_attributes(:title => "Test2")
@post.history_tracks.where(:version => 1).first.undo!(@user)
@post.reload
@post.title.should == "Test"
end
+
+ it "should undo destruction" do
+ @post.destroy
+ @post.history_tracks.where(:version => 1).first.undo!(@user)
+ Post.find(@post.id).title.should == "Test"
+ end
it "should create a new history track after undo" do
@post.update_attributes(:title => "Test2")
@post.history_tracks.where(:version => 1).first.undo!(@user)
@post.reload
@@ -243,9 +276,18 @@
@track.redo!(@user)
@post2 = Post.where(:_id => @post.id).first
@post.title.should == @post2.title
end
+
+ it "should be destroyed after undo and redo" do
+ @post.destroy
+ @track = @post.history_tracks.where(:version => 1).first
+ @track.undo!(@user)
+ @track.redo!(@user)
+ Post.where(:_id => @post.id).first == nil
+ end
+
end
describe "embedded" do
it "should undo changes" do
@comment.update_attributes(:title => "Test2")