Skip to content

Test helpers for authorization #2986

Open
@arkirchner

Description

@arkirchner

Story

There are various ways to sign in a user in the system and request tests.

This flow is often used to sign in a teacher. The issue here is that the teacher will be signed as a user through this authorization flow (teacher is not part of the default group by default). The sign-in flow for external teachers should have been used.

teacher = create(:teacher)
fill_in('email', with: teacher.email)
fill_in('password', with: attributes_for(:teacher)[:password])
click_button(I18n.t('sessions.new.link'))

Request tests sign in users by overriding the current_user. For an integration level test, this might be a bit aggressive stubbing (it keeps the teacher a teacher no matter the login flow).

teacher = create(:teacher)
allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(teacher)

Goal

The goal it to create a test helper that automatically signs in users with the correct authorization flow. It should work similarly with Request and System tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementrubyPull requests that update Ruby code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions