Sha256: 784aee9e0609e4e515eda0d000f7d4a45249b0f41751e4e628e601d625a45b0b

Contents?: true

Size: 1.72 KB

Versions: 9

Compression:

Stored size: 1.72 KB

Contents

require 'test_helper'

class DocumentsControllerTest < ActionController::TestCase
  setup do
    @alpha = documents(:alpha)
    @beta  = documents(:beta)

    @bob = users(:bob)
    @jim = users(:jim)
  end

  def as_bob!
    @controller.current_user = @bob
  end

  def as_jim!
    @controller.current_user = @jim
  end

  test "show" do
    as_bob!

    get :show, params: { id: @alpha.id }, format: :json

    assert_response :success
  end

  test "show without through relationship" do
    as_jim!

    assert_raises ActiveRecord::RecordNotFound do
      get :show, params: { id: @alpha.id }, format: :json
    end
  end

  test "update with access" do
    as_bob!

    patch :update, params: { id: @alpha.id, document: { title: 'Test' } }, format: :json

    assert_response :success
  end

  test "update without access" do
    as_bob!

    assert_raises SimonSays::Authorizer::Denied do
      patch :update, params: { id: @beta.id, document: { title: 'Test' } }, format: :json
    end
  end

  test "update without through relationship" do
    as_jim!

    assert_raises ActiveRecord::RecordNotFound do
      patch :update, params: { id: @alpha.id, document: { title: 'Test' } }, format: :json
    end
  end

  test "destroy with access" do
    as_bob!

    assert_difference 'Document.count', -1 do
      delete :destroy, params: { id: @alpha.id }, format: :json
    end
  end

  test "destroy without access" do
    as_bob!

    assert_raises SimonSays::Authorizer::Denied do
      delete :destroy, params: { id: @beta.id }, format: :json
    end
  end

  test "destroy without through relationship" do
    as_jim!

    assert_raises ActiveRecord::RecordNotFound do
      delete :destroy, params: { id: @beta.id }, format: :json
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
simon_says-0.3.0.alpha.7 test/controllers/documents_controller_test.rb
simon_says-0.3.0.alpha.6 test/controllers/documents_controller_test.rb
simon_says-0.3.0.alpha.5 test/controllers/documents_controller_test.rb
simon_says-0.3.0.alpha.4 test/controllers/documents_controller_test.rb
simon_says-0.3.0.alpha.3 test/controllers/documents_controller_test.rb
simon_says-0.3.0.alpha.1 test/controllers/documents_controller_test.rb
simon_says-0.2.0 test/controllers/documents_controller_test.rb
simon_says-0.1.6 test/controllers/documents_controller_test.rb
simon_says-0.1.5 test/controllers/documents_controller_test.rb