Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PD: international opt-in additional work #23603

Merged
merged 7 commits into from Jul 18, 2018
Expand Up @@ -5,7 +5,7 @@ class Pd::InternationalOptInController < ApplicationController
def new
return render '/pd/application/teacher_application/logged_out' unless current_user
return render '/pd/application/teacher_application/not_teacher' unless current_user.teacher?
return render '/pd/application/teacher_application/no_teacher_email' unless current_user.email
return render '/pd/application/teacher_application/no_teacher_email' unless current_user.email.present?

@script_data = {
props: {
Expand Down
Expand Up @@ -56,4 +56,31 @@ class Api::V1::Pd::InternationalOptInsControllerTest < ::ActionController::TestC

assert_response :bad_request
end

test 'students can not create a new international opt-in' do
student = create :student
sign_in student

assert_does_not_create Pd::InternationalOptIn do
put :create, params: {
form_data: SAMPLE_FORM_DATA,
user: student
}
assert_response :forbidden
end

assert_response :forbidden
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is redundant w line 69

end

test 'user required to create a new international opt-in' do
assert_does_not_create Pd::InternationalOptIn do
put :create, params: {
form_data: SAMPLE_FORM_DATA,
user: nil
}
assert_response :redirect
end

assert_response :redirect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this too, with line 81

end
end
@@ -0,0 +1,32 @@
require 'test_helper'

class Pd::InternationalOptInControllerTest < ::ActionController::TestCase
self.use_transactional_test_case = true

test 'signed in teacher' do
teacher = create :teacher
sign_in teacher
get :new
assert_response :success
end

test 'signed out' do
get :new
assert_template 'pd/application/teacher_application/logged_out'
end

test 'signed in student' do
sign_in create :student
get :new
assert_template 'pd/application/teacher_application/not_teacher'
end

test 'signed in teacher with no email' do
teacher = create :teacher
teacher.email = ""
teacher.save(validate: false)
sign_in teacher
get :new
assert_template 'pd/application/teacher_application/no_teacher_email'
end
end