Sha256: 5821a89f389bcd585701999806409c5fb39d2aaa039e40169ca9e122179d6c0d

Contents?: true

Size: 942 Bytes

Versions: 3

Compression:

Stored size: 942 Bytes

Contents

require "test_helper"

class SudosControllerTest < ActionDispatch::IntegrationTest
  setup do
    @<%= singular_table_name %>, @token = sign_in_as(<%= table_name %>(:lazaro_nixon))
    @<%= singular_table_name %>.sessions.last.update! sudo_at: 1.day.ago
  end

  test "should sudo" do
    post sudo_url, params: { password: "Secret123456" }, headers: { "Authorization" => "Bearer #{@token}" }
    assert_response :no_content
  end

  test "should not sudo with wrong password" do
    post sudo_url, params: { password: "SecretWrong123" }, headers: { "Authorization" => "Bearer #{@token}" }

    assert_response :bad_request
    assert_equal "The password you entered is incorrect", response.parsed_body["error"]
  end

  def sign_in_as(<%= singular_table_name %>)
    post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret123456" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
authentication-zero-2.3.2 lib/generators/authentication/templates/test_unit/controllers/api/sudos_controller_test.rb.tt
authentication-zero-2.3.1 lib/generators/authentication/templates/test_unit/controllers/api/sudos_controller_test.rb.tt
authentication-zero-2.3.0 lib/generators/authentication/templates/test_unit/controllers/api/sudos_controller_test.rb.tt