spec/lib/history_spec.rb in active_metadata-0.8.1 vs spec/lib/history_spec.rb in active_metadata-0.8.2

- old
+ new

@@ -1,17 +1,18 @@ require "spec_helper" require "time" describe ActiveMetadata do - before(:each) do - @document = Document.create! { |d| d.name = "John" } - @document.reload - end describe "history" do + before(:each) do + @document = Document.create! { |d| d.name = "John" } + @document.reload + end + it "should create history when a document is created" do @document.history_for(:name).should have(1).record end it "should create history for a defined field when a document is created" do @@ -75,7 +76,56 @@ history = @document.history_for(:name).first history.created_by.should eq current_user.id end end + + describe "skip_history_notification" do + + context "given an user that watch Document#name" do + + before do + @user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith') + ActiveMetadata::Watcher.create! :model_class => "Document", :label => :name, :owner_id => @user.id + end + + it "and skip_history_notification false creating a Document with name not null should save the history and generate a notification" do + @document = Document.create! name: "John" + @document.history_for(:name)[0].value.should eq(@document.name) + @document.notifier.should_not be_nil + end + + it "when true creating a Document with name not null should save the history but do not generate any notification" do + @document = Document.create! name: "John", skip_history_notification: true + @document.history_for(:name)[0].value.should eq(@document.name) + @document.notifier.should be_nil + end + + end + + context "given an user that watch Author#name (does not persist ancestor)" do + + before do + @user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith') + ActiveMetadata::Watcher.create! :model_class => "Author", :label => :name, :owner_id => @user.id + end + + it "when a new record is craeted by the parent document instance should save history and generate a notification" do + @document = Document.create! name: "John" + @author = @document.create_author name: "my title" + @author.history_for(:name)[0].value.should eq(@author.name) + @author.notifier.should_not be_nil + end + + it "when a new record is craeted by the parent document skipping notifications should save history and not generate any notification" do + @document = Document.create! name: "John" + @author = @document.create_author name: "my title", skip_history_notification: true + @author.history_for(:name)[0].value.should eq(@author.name) + @author.notifier.should be_nil + end + + end + + end + end \ No newline at end of file