diff options
| author | AppleDash <[email protected]> | 2021-02-25 05:05:48 -0500 |
|---|---|---|
| committer | AppleDash <[email protected]> | 2021-02-25 05:05:48 -0500 |
| commit | d2524f8afb24973a877b509d70befbc907d6ae81 (patch) | |
| tree | 8434644164b9025b21b62032187faf1adbdb8cca /test/controllers/posts_controller_test.rb | |
| parent | 9d4442a381a3a04116c63bb431479a8826727a1f (diff) | |
Minimal paste support works
Diffstat (limited to 'test/controllers/posts_controller_test.rb')
| -rw-r--r-- | test/controllers/posts_controller_test.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/test/controllers/posts_controller_test.rb b/test/controllers/posts_controller_test.rb new file mode 100644 index 0000000..378e16f --- /dev/null +++ b/test/controllers/posts_controller_test.rb @@ -0,0 +1,70 @@ +# 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 @image.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 |
