Sha256: 77bbd7e644274c941507b3b18562044d9b402977823198f982a36813e9d3454f

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require 'test_helper'

class ArticlesControllerTest < ActionController::TestCase
  test "any access with no clearance level gets redirected" do
    # Undefined role
    get :new
    assert_redirected_to root_url

    post :create
    assert_redirected_to root_url
  end

  test "any access with undefined clearance level gets redirected" do
    # The role doesn't exist (undefined)
    get :new, nil, {role: :super}
    assert_redirected_to root_url

    post :create, nil, {role: :super}
    assert_redirected_to root_url
  end

  test "any unauthorized access gets redirected" do
    # The roles exist but aren't authorized.
    get :new, nil, {role: :user}
    assert_redirected_to root_url

    post :create, nil, {role: :editor}
    assert_redirected_to root_url
  end

  test "authorized accesses aren't redirected" do
    get :new, nil, {role: :admin}        # Admins can create articles
    assert_response :success

    get :edit, {id: 1}, {role: :editor}  # Editors can edit articles
    assert_response :success

    get :show, {id: 1}, {role: :user}    # Users can view articles
    assert_response :success
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
action_access-0.0.3 test/controllers/articles_controller_test.rb
action_access-0.0.2 test/controllers/articles_controller_test.rb
action_access-0.0.1 test/controllers/articles_controller_test.rb