# frozen_string_literal: true require 'test_helper' require 'rack/test' class PostsControllerTest < ActionController::TestCase setup do @post = create(:post) @request.cookies['_ses'] = 'c1836832948' end test 'should get index' do get :index assert_response :success assert assigns(:posts) end test 'should get show' do get :show, params: { id: @post.id } assert_response :success end test 'should get new' do get :new assert_response :success end test 'should create a new image' do image_file = Rack::Test::UploadedFile.new Rails.root.join('test/fixtures/image_files/dedupe_evade_1.jpeg'), 'image/jpeg' assert_difference('Image.count') do post :create, params: { image: { description: '', source_url: 'h', tag_input: 'safe, nightmare moon, nightmare dupe', image: image_file } } end assert_redirected_to short_post_path(assigns(:post)) end test 'duplicates should redirect to the target image' do @dedupe_1 = create(:dedupe_image_2) ImageDuplicateMergeJob.perform_now @post.id, @dedupe_1.id, nil get :show, params: { id: @post.id } assert_response :redirect assert_redirected_to short_post_path(@dedupe_1) end test 'content destruction of a post should do nothing given a non-hidden post' do sign_in create(:moderator) delete :destroy, params: { id: @post.id } @post.reload assert_response :redirect assert_redirected_to root_path assert_not @post.destroyed_content end test 'content destruction of a post should remove the file contents' do sign_in create(:moderator) PostHider.new(@post, reason: 'The era of deletion is upon us.').save delete :destroy, params: { id: @post.id } @post.reload assert @post.destroyed_content end end