Sha256: 523a4eea455bcf7f64c459dbfe657ec478a567bf0728ff9a636ce61861d02390

Contents?: true

Size: 1.67 KB

Versions: 13

Compression:

Stored size: 1.67 KB

Contents

require 'test_helper'

module Shipit
  module Api
    class TasksControllerTest < ActionController::TestCase
      setup do
        @stack = shipit_stacks(:shipit)
        authenticate!
      end

      test "#index returns a list of tasks" do
        task = @stack.tasks.last

        get :index, stack_id: @stack.to_param
        assert_response :ok
        assert_json '0.id', task.id
      end

      test "#show returns a task" do
        task = @stack.tasks.last

        get :show, stack_id: @stack.to_param, id: task.id
        assert_response :ok
        assert_json 'id', task.id
      end

      test "#trigger triggers a custom task" do
        post :trigger, stack_id: @stack.to_param, task_name: 'restart'
        assert_response :accepted
        assert_json 'type', 'task'
        assert_json 'status', 'pending'
      end

      test "#trigger refuses to trigger a task with tasks not whitelisted" do
        env = {'DANGEROUS_VARIABLE' => 'bar'}
        post :trigger, stack_id: @stack.to_param, task_name: 'restart', env: env
        assert_response :unprocessable_entity
        assert_json 'message', 'Variables DANGEROUS_VARIABLE have not been whitelisted'
      end

      test "#trigger triggers a task with only whitelisted env variables" do
        env = {'FOO' => 'bar'}
        post :trigger, stack_id: @stack.to_param, task_name: 'restart', env: env
        assert_response :accepted
        assert_json 'type', 'task'
        assert_json 'status', 'pending'
      end

      test "#trigger returns a 404 when the task doesn't exist" do
        post :trigger, stack_id: @stack.to_param, task_name: 'doesnt_exist'
        assert_response :not_found
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
shipit-engine-0.11.0 test/controllers/api/tasks_controller_test.rb
shipit-engine-0.10.0 test/controllers/api/tasks_controller_test.rb
shipit-engine-0.9.0 test/controllers/api/tasks_controller_test.rb
shipit-engine-0.8.9 test/controllers/api/tasks_controller_test.rb
shipit-engine-0.8.8 test/controllers/api/tasks_controller_test.rb
shipit-engine-0.8.7 test/controllers/api/tasks_controller_test.rb
shipit-engine-0.8.6 test/controllers/api/tasks_controller_test.rb
shipit-engine-0.8.5 test/controllers/api/tasks_controller_test.rb
shipit-engine-0.8.4 test/controllers/api/tasks_controller_test.rb
shipit-engine-0.8.3 test/controllers/api/tasks_controller_test.rb
shipit-engine-0.8.2 test/controllers/api/tasks_controller_test.rb
shipit-engine-0.8.1 test/controllers/api/tasks_controller_test.rb
shipit-engine-0.8.0 test/controllers/api/tasks_controller_test.rb