Sha256: 81a480db79e5e16c625da51ddde5411a6f448c16e2071b53b828eb016add4360

Contents?: true

Size: 1.4 KB

Versions: 10

Compression:

Stored size: 1.4 KB

Contents

require 'test_helper'

class Api::StacksControllerTest < ActionController::TestCase
  setup do
    authenticate!
    @stack = stacks(:shipit)
  end

  test "#index returns a list of stacks" do
    stack = Stack.last

    get :index
    assert_response :ok
    assert_json '0.id', stack.id
    assert_json do |stacks|
      assert_equal 3, stacks.size
    end
  end

  test "#index is paginable" do
    get :index, page_size: 1
    assert_json do |list|
      assert_instance_of Array, list
      assert_equal 1, list.size

      stack_id = list.last['id']
      assert_link 'next', api_stacks_url(since: stack_id, page_size: 1)
      assert_link 'first', api_stacks_url(page_size: 1)
    end
  end

  test "the `next` link is not provided when the last page is reached" do
    get :index, page_size: Stack.count
    assert_no_link 'next'
  end

  test "an api client scoped to a stack will only see that one stack" do
    authenticate!(:here_come_the_walrus)
    get :index
    assert_json do |stacks|
      assert_equal 1, stacks.size
    end
  end

  test "a request with insufficient permissions will render a 403" do
    @client.update!(permissions: [])
    get :index
    assert_response :forbidden
    assert_json 'message', 'This operation requires the `read:stack` permission'
  end

  test "#show renders the stack" do
    get :show, id: @stack.to_param
    assert_response :ok
    assert_json 'id', @stack.id
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
shipit-engine-0.5.2 test/controllers/api/stacks_controller_test.rb
shipit-engine-0.5.1 test/controllers/api/stacks_controller_test.rb
shipit-engine-0.5.0 test/controllers/api/stacks_controller_test.rb
shipit-engine-0.4.10 test/controllers/api/stacks_controller_test.rb
shipit-engine-0.4.9 test/controllers/api/stacks_controller_test.rb
shipit-engine-0.4.8 test/controllers/api/stacks_controller_test.rb
shipit-engine-0.4.7 test/controllers/api/stacks_controller_test.rb
shipit-engine-0.4.6 test/controllers/api/stacks_controller_test.rb
shipit-engine-0.4.5 test/controllers/api/stacks_controller_test.rb
shipit-engine-0.4.4 test/controllers/api/stacks_controller_test.rb