From cdafbc849d5a786b2030319c86e74591b8393a9f Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 6 Feb 2017 15:04:14 -0600 Subject: [PATCH] tests: add more artist commentary controller tests. --- .../artist_commentaries_controller_test.rb | 72 ++++++++++++++++++- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/test/functional/artist_commentaries_controller_test.rb b/test/functional/artist_commentaries_controller_test.rb index b37371997..ae76150bc 100644 --- a/test/functional/artist_commentaries_controller_test.rb +++ b/test/functional/artist_commentaries_controller_test.rb @@ -6,16 +6,82 @@ class ArtistCommentariesControllerTest < ActionController::TestCase @user = FactoryGirl.create(:user) CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" + + @commentary1 = FactoryGirl.create(:artist_commentary) + @commentary2 = FactoryGirl.create(:artist_commentary) end teardown do CurrentUser.user = nil end + context "index action" do + should "render" do + get :index + assert_response :success + end + + should "render with search params" do + params = { + search: { + text_matches: @commentary1.original_title, + post_id: @commentary1.post_id, + original_present: "yes", + translated_present: "yes", + post_tags_match: @commentary1.post.tag_array.first, + } + } + + get :index, params + assert_response :success + end + end + + context "show action" do + should "render" do + get :show, { id: @commentary1.id } + assert_redirected_to(@commentary1.post) + + get :show, { post_id: @commentary1.post_id } + assert_redirected_to(@commentary1.post) + end + end + + context "create_or_update action" do + should "render for create" do + params = { + artist_commentary: { + original_title: "foo", + post_id: FactoryGirl.create(:post).id, + } + } + + post :create_or_update, params, { user_id: @user.id } + assert_redirected_to(ArtistCommentary.find_by_post_id(params[:artist_commentary][:post_id])) + end + + should "render for update" do + params = { + artist_commentary: { + post_id: @commentary1.post_id, + original_title: "foo", + } + } + + post :create_or_update, params, { user_id: @user.id } + assert_redirected_to(@commentary1) + assert_equal("foo", @commentary1.reload.original_title) + end + end + context "revert action" do - setup do - @commentary1 = FactoryGirl.create(:artist_commentary) - @commentary2 = FactoryGirl.create(:artist_commentary) + should "work" do + original_title = @commentary1.original_title + @commentary1.update(original_title: "foo") + + post :revert, { :id => @commentary1.post_id, :version_id => @commentary1.versions(true).first.id }, {:user_id => @user.id} + assert_redirected_to(@commentary1) + assert_equal(original_title, @commentary1.reload.original_title) end should "return 404 when trying to revert a nonexistent commentary" do