From 80895ef46e822e55b3e331ed820fb78e3fffc7ed Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 11 Oct 2016 04:07:28 +0000 Subject: [PATCH] Add tests for reverting to foreign versions. --- test/factories/artist_commentary.rb | 9 +++++ .../artist_commentaries_controller_test.rb | 36 +++++++++++++++++++ test/functional/artists_controller_test.rb | 22 +++++++++--- test/functional/notes_controller_test.rb | 10 ++++++ test/functional/pools_controller_test.rb | 10 ++++++ test/functional/posts_controller_test.rb | 10 ++++++ test/functional/wiki_pages_controller_test.rb | 10 ++++++ 7 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 test/factories/artist_commentary.rb create mode 100644 test/functional/artist_commentaries_controller_test.rb diff --git a/test/factories/artist_commentary.rb b/test/factories/artist_commentary.rb new file mode 100644 index 000000000..af4b30126 --- /dev/null +++ b/test/factories/artist_commentary.rb @@ -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 diff --git a/test/functional/artist_commentaries_controller_test.rb b/test/functional/artist_commentaries_controller_test.rb new file mode 100644 index 000000000..b37371997 --- /dev/null +++ b/test/functional/artist_commentaries_controller_test.rb @@ -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 diff --git a/test/functional/artists_controller_test.rb b/test/functional/artists_controller_test.rb index d7ea92213..3b67df884 100644 --- a/test/functional/artists_controller_test.rb +++ b/test/functional/artists_controller_test.rb @@ -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 diff --git a/test/functional/notes_controller_test.rb b/test/functional/notes_controller_test.rb index f5be8d2af..b93e2ac31 100644 --- a/test/functional/notes_controller_test.rb +++ b/test/functional/notes_controller_test.rb @@ -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 diff --git a/test/functional/pools_controller_test.rb b/test/functional/pools_controller_test.rb index 0311099ef..6a87cc3b2 100644 --- a/test/functional/pools_controller_test.rb +++ b/test/functional/pools_controller_test.rb @@ -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 diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb index 5800b2689..044268177 100644 --- a/test/functional/posts_controller_test.rb +++ b/test/functional/posts_controller_test.rb @@ -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 diff --git a/test/functional/wiki_pages_controller_test.rb b/test/functional/wiki_pages_controller_test.rb index b0701d141..9d5bb8b12 100644 --- a/test/functional/wiki_pages_controller_test.rb +++ b/test/functional/wiki_pages_controller_test.rb @@ -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