Add tests for reverting to foreign versions.
This commit is contained in:
9
test/factories/artist_commentary.rb
Normal file
9
test/factories/artist_commentary.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
FactoryGirl.define do
|
||||
factory(:artist_commentary) do
|
||||
post :factory => :post
|
||||
original_title { FFaker::Lorem.sentences.join(" ") }
|
||||
original_description { FFaker::Lorem.sentences.join(" ") }
|
||||
translated_title { FFaker::Lorem.sentences.join(" ") }
|
||||
translated_description { FFaker::Lorem.sentences.join(" ") }
|
||||
end
|
||||
end
|
||||
36
test/functional/artist_commentaries_controller_test.rb
Normal file
36
test/functional/artist_commentaries_controller_test.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ArtistCommentariesControllerTest < ActionController::TestCase
|
||||
context "The artist commentaries controller" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
end
|
||||
|
||||
context "revert action" do
|
||||
setup do
|
||||
@commentary1 = FactoryGirl.create(:artist_commentary)
|
||||
@commentary2 = FactoryGirl.create(:artist_commentary)
|
||||
end
|
||||
|
||||
should "return 404 when trying to revert a nonexistent commentary" do
|
||||
post :revert, { :id => -1, :version_id => -1 }, {:user_id => @user.id}
|
||||
|
||||
assert_response 404
|
||||
end
|
||||
|
||||
should "not allow reverting to a previous version of another artist commentary" do
|
||||
post :revert, { :id => @commentary1.post_id, :version_id => @commentary2.versions(true).first.id }, {:user_id => @user.id}
|
||||
@commentary1.reload
|
||||
|
||||
assert_not_equal(@commentary1.original_title, @commentary2.original_title)
|
||||
assert_response :missing
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -136,11 +136,23 @@ class ArtistsControllerTest < ActionController::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "revert an artist" do
|
||||
@artist.update_attributes(:name => "xyz")
|
||||
@artist.update_attributes(:name => "abc")
|
||||
version = @artist.versions.first
|
||||
post :revert, {:id => @artist.id, :version_id => version.id}
|
||||
context "reverting an artist" do
|
||||
should "work" do
|
||||
@artist.update_attributes(:name => "xyz")
|
||||
@artist.update_attributes(:name => "abc")
|
||||
version = @artist.versions.first
|
||||
post :revert, {:id => @artist.id, :version_id => version.id}
|
||||
end
|
||||
|
||||
should "not allow reverting to a previous version of another artist" do
|
||||
@artist2 = FactoryGirl.create(:artist)
|
||||
|
||||
post :revert, { :id => @artist.id, :version_id => @artist2.versions(true).first.id }, {:user_id => @user.id}
|
||||
@artist.reload
|
||||
|
||||
assert_not_equal(@artist.name, @artist2.name)
|
||||
assert_response :missing
|
||||
end
|
||||
end
|
||||
|
||||
context "when finding an artist" do
|
||||
|
||||
@@ -77,6 +77,16 @@ class NotesControllerTest < ActionController::TestCase
|
||||
@note.reload
|
||||
assert_equal("000", @note.body)
|
||||
end
|
||||
|
||||
should "not allow reverting to a previous version of another note" do
|
||||
@note2 = FactoryGirl.create(:note, :body => "note 2")
|
||||
|
||||
post :revert, { :id => @note.id, :version_id => @note2.versions(true).first.id }, {:user_id => @user.id}
|
||||
@note.reload
|
||||
|
||||
assert_not_equal(@note.body, @note2.body)
|
||||
assert_response :missing
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -107,6 +107,16 @@ class PoolsControllerTest < ActionController::TestCase
|
||||
@pool.reload
|
||||
assert_equal([@post.id], @pool.post_id_array)
|
||||
end
|
||||
|
||||
should "not allow reverting to a previous version of another pool" do
|
||||
@pool2 = FactoryGirl.create(:pool)
|
||||
|
||||
post :revert, { :id => @pool.id, :version_id => @pool2.versions(true).first.id }, {:user_id => @user.id}
|
||||
@pool.reload
|
||||
|
||||
assert_not_equal(@pool.name, @pool2.name)
|
||||
assert_response :missing
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -127,6 +127,16 @@ class PostsControllerTest < ActionController::TestCase
|
||||
@post.reload
|
||||
assert_equal("aaaa", @post.tag_string)
|
||||
end
|
||||
|
||||
should "not allow reverting to a previous version of another post" do
|
||||
@post2 = FactoryGirl.create(:post, :uploader_id => @user.id, :tag_string => "herp")
|
||||
|
||||
post :revert, { :id => @post.id, :version_id => @post2.versions.first.id }, {:user_id => @user.id}
|
||||
@post.reload
|
||||
|
||||
assert_not_equal(@post.tag_string, @post2.tag_string)
|
||||
assert_response :missing
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -97,6 +97,16 @@ class WikiPagesControllerTest < ActionController::TestCase
|
||||
@wiki_page.reload
|
||||
assert_equal("1", @wiki_page.body)
|
||||
end
|
||||
|
||||
should "not allow reverting to a previous version of another wiki page" do
|
||||
@wiki_page_2 = FactoryGirl.create(:wiki_page)
|
||||
|
||||
post :revert, { :id => @wiki_page.id, :version_id => @wiki_page_2.versions(true).first.id }, {:user_id => @user.id}
|
||||
@wiki_page.reload
|
||||
|
||||
assert_not_equal(@wiki_page.body, @wiki_page_2.body)
|
||||
assert_response :missing
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user