Sha256: fa0585ecbd51fdee410d24943ca5a21db904491073c882fda3f5c54982429ea3

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require 'test_helper'

class PicturesControllerTest < ActionController::TestCase
  tests Ckeditor::PicturesController

  def setup
    @image = Rack::Test::UploadedFile.new('test/dummy/test/fixtures/files/rails.png', 'image/png')
    @routes = Ckeditor::Engine.routes
  end

  def teardown
    Ckeditor::Picture.destroy_all
  end

  test 'index action' do
    get :index

    assert_equal 200, @response.status
  end

  test 'create action via filebrowser' do
    assert_difference 'Ckeditor::Picture.count' do
      post :create, params: { qqfile: @image }
    end

    assert_equal 200, @response.status
  end

  test 'create action via CKEditor upload form' do
    assert_difference 'Ckeditor::Picture.count' do
      post :create, params: { upload: @image, CKEditor: 'ckeditor_field' }
    end

    assert_equal 200, @response.status
  end

  test 'create action via html5 upload' do
    params = { qqfile: @image.original_filename }

    assert_difference 'Ckeditor::Picture.count' do
      post :create, params: params, body: @image.read
    end

    assert_equal 200, @response.status
  end

  test 'invalid params for create action' do
    assert_no_difference 'Ckeditor::Picture.count' do
      post :create, params: { qqfile: nil, format: :html }
    end
  end

  test 'destroy action via filebrowser' do
    @picture = Ckeditor::Picture.create! data: @image

    assert_difference 'Ckeditor::Picture.count', -1 do
      delete :destroy, params: { id: @picture.id }
    end

    assert_equal 302, @response.status
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ckeditor-5.1.3 test/controllers/pictures_controller_test.rb
ckeditor-5.1.2 test/controllers/pictures_controller_test.rb