Sha256: 3047a9da68d5580c2253d123150af6b3f1b0263940ef45692832b2335e082933

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

require 'test_helper'
require 'pry'
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

1 entries across 1 versions & 1 rubygems

Version Path
simon_says-0.1.0 test/controllers/documents_controller_test.rb