This commit is contained in:
r888888888
2013-07-25 14:12:35 -07:00
parent c0921d0590
commit 303d6ce821
4 changed files with 66 additions and 10 deletions

View File

@@ -566,8 +566,32 @@ class PostTest < ActiveSupport::TestCase
end
context "that has been updated" do
should "create a new version if it's the first version" do
assert_difference("PostVersion.count", 1) do
post = FactoryGirl.create(:post)
end
end
should "create a new version if it's been over an hour since the last update" do
post = FactoryGirl.create(:post)
Timecop.travel(6.hours.from_now) do
assert_difference("PostVersion.count", 1) do
post.update_attributes(:tag_string => "zzz")
end
end
end
should "merge with the previous version if the updater is the same user and it's been less than an hour" do
post = FactoryGirl.create(:post)
assert_difference("PostVersion.count", 0) do
post.update_attributes(:tag_string => "zzz")
end
assert_equal("zzz", post.versions.last.tags)
end
should "increment the updater's post_update_count" do
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
post.stubs(:merge_version?).returns(false)
assert_difference("CurrentUser.post_update_count", 1) do
post.update_attributes(:tag_string => "zzz")
@@ -1200,6 +1224,7 @@ class PostTest < ActiveSupport::TestCase
context "a post that has been updated" do
setup do
@post = FactoryGirl.create(:post, :rating => "q", :tag_string => "aaa")
@post.stubs(:merge_version?).returns(false)
@post.update_attributes(:tag_string => "aaa bbb ccc ddd")
@post.update_attributes(:tag_string => "bbb xxx yyy", :source => "xyz")
@post.update_attributes(:tag_string => "bbb mmm yyy", :source => "abc")