* Reworked how post versioning works, now more closely resembles the 1.18 strategy
This commit is contained in:
@@ -1,8 +1,36 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostVersionsControllerTest < ActionController::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "The post versions controller" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
@post = Factory.create(:post)
|
||||
@post.update_attributes(:tag_string => "1 2", :source => "xxx")
|
||||
@post.update_attributes(:tag_string => "2 3", :rating => "e")
|
||||
end
|
||||
|
||||
should "list all versions" do
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_not_nil(assigns(:post_versions))
|
||||
end
|
||||
|
||||
should "list all versions that match the search criteria" do
|
||||
get :index, {:search => {:post_id_equals => @post.id}}
|
||||
assert_response :success
|
||||
assert_not_nil(assigns(:post_versions))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,37 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostVotesControllerTest < ActionController::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "The post vote controller" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@post = Factory.create(:post)
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "increment a post's score if the score is positive" do
|
||||
post :create, {:post_id => @post.id, :score => "up", :format => "js"}, {:user_id => @user.id}
|
||||
@post.reload
|
||||
assert_equal(1, @post.score)
|
||||
end
|
||||
|
||||
context "for a post that has already been voted on" do
|
||||
setup do
|
||||
@post.vote!("up")
|
||||
end
|
||||
|
||||
should "fail silently on an error" do
|
||||
assert_nothing_raised do
|
||||
post :create, {:post_id => @post.id, :score => "up", :format => "js"}, {:user_id => @user.id}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
require_relative '../test_helper'
|
||||
|
||||
class PostHistoryTest < ActiveSupport::TestCase
|
||||
context "A post" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
PostHistory.stubs(:revision_time).returns("TIME")
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
should "create a revision after creation" do
|
||||
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
assert_equal(1, post.revisions.size)
|
||||
assert_equal({"source"=>nil, "rating"=>"q", "tag_string"=>"aaa bbb ccc", "parent_id"=>nil, "user_id"=>@user.id, "ip_addr"=>"127.0.0.1", "updated_at"=>"TIME"}, post.revisions.last)
|
||||
end
|
||||
|
||||
should "create additional revisions after updating" do
|
||||
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
post.update_attributes(:tag_string => "bbb ccc ddd")
|
||||
post.reload
|
||||
assert_equal(2, post.revisions.size)
|
||||
assert_equal({"source"=>nil, "rating"=>"q", "tag_string"=>"bbb ccc ddd", "parent_id"=>nil, "user_id"=>@user.id, "ip_addr"=>"127.0.0.1", "updated_at"=>"TIME"}, post.revisions.last)
|
||||
end
|
||||
|
||||
context "history" do
|
||||
setup do
|
||||
@post = Factory.create(:post, :tag_string => "aaa bbb ccc", :source => "xyz", :rating => "q")
|
||||
@post.update_attributes(:tag_string => "bbb ccc ddd", :source => "abc", :rating => "s")
|
||||
@post.update_attributes(:tag_string => "ccc ddd eee")
|
||||
@revisions = []
|
||||
@post.history.each_revision do |revision|
|
||||
@revisions << revision
|
||||
end
|
||||
end
|
||||
|
||||
should "link revisions together" do
|
||||
assert_nil(@revisions[0].prev)
|
||||
assert_equal(@revisions[0], @revisions[1].prev)
|
||||
assert_equal(@revisions[1], @revisions[2].prev)
|
||||
end
|
||||
|
||||
should "iterate over its revisions" do
|
||||
assert_equal(3, @revisions.size)
|
||||
assert_equal(%w(aaa bbb ccc), @revisions[0].tag_array)
|
||||
assert_equal(%w(bbb ccc ddd), @revisions[1].tag_array)
|
||||
assert_equal(%w(ccc ddd eee), @revisions[2].tag_array)
|
||||
end
|
||||
|
||||
should "create a diff for each revision detailing what changed" do
|
||||
assert_equal({:add=>["aaa", "bbb", "ccc"], :del=>[], :rating=>"q", :source=>"xyz", :parent_id=>nil}, @revisions[0].diff)
|
||||
assert_equal({:del=>["aaa"], :add=>["ddd"], :rating=>"s", :source=>"abc"}, @revisions[1].diff)
|
||||
assert_equal({:del=>["bbb"], :add=>["eee"]}, @revisions[2].diff)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
52
test/unit/post_version_test.rb
Normal file
52
test/unit/post_version_test.rb
Normal file
@@ -0,0 +1,52 @@
|
||||
require_relative '../test_helper'
|
||||
|
||||
class PostVersionTest < ActiveSupport::TestCase
|
||||
context "A post" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "that has been created" do
|
||||
setup do
|
||||
@parent = Factory.create(:post)
|
||||
@post = Factory.create(:post, :tag_string => "aaa bbb ccc", :rating => "e", :parent => @parent, :source => "xyz")
|
||||
end
|
||||
|
||||
should "also create a version" do
|
||||
assert_equal(1, @post.versions.size)
|
||||
@version = @post.versions.last
|
||||
assert_equal("aaa bbb ccc", @version.add_tags)
|
||||
assert_equal("", @version.del_tags)
|
||||
assert_equal(@post.rating, @version.rating)
|
||||
assert_equal(@post.parent_id, @version.parent_id)
|
||||
assert_equal(@post.source, @version.source)
|
||||
end
|
||||
end
|
||||
|
||||
context "that has been updated" do
|
||||
setup do
|
||||
@parent = Factory.create(:post)
|
||||
@post = Factory.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "")
|
||||
end
|
||||
|
||||
should "also create a version" do
|
||||
assert_equal(2, @post.versions.size)
|
||||
@version = @post.versions.last
|
||||
assert_equal("xxx", @version.add_tags)
|
||||
assert_equal("aaa", @version.del_tags)
|
||||
assert_nil(@version.rating)
|
||||
assert_equal("", @version.source)
|
||||
assert_nil(@version.parent_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -68,7 +68,7 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
ta1 = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "xxx")
|
||||
p1.reload
|
||||
assert_not_equal("uploader:#{ta1.creator_id}", p1.uploader_string)
|
||||
assert_equal(ta1.creator_id, p1.history.revisions.last["user_id"])
|
||||
assert_equal(ta1.creator_id, p1.versions.last.updater_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -114,7 +114,7 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
ti1 = Factory.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
|
||||
p1.reload
|
||||
assert_not_equal("uploader:#{ti1.creator_id}", p1.uploader_string)
|
||||
assert_equal(ti1.creator_id, p1.history.revisions.last["user_id"])
|
||||
assert_equal(ti1.creator_id, p1.versions.last.updater_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user