Update registration tests to use a fixed forbidden screen name list

This commit is contained in:
Karina Kwiatek 2022-07-23 00:15:28 +02:00 committed by Karina Kwiatek
parent fb73ce05db
commit 0789ed773e
1 changed files with 39 additions and 24 deletions

View File

@ -6,6 +6,17 @@ describe User::RegistrationsController, type: :controller do
before do
# Required for devise to register routes
@request.env["devise.mapping"] = Devise.mappings[:user]
stub_const("APP_CONFIG", {
"hostname" => "example.com",
"https" => true,
"items_per_page" => 5,
"forbidden_screen_names" => %w[
justask_admin retrospring_admin admin justask retrospring
moderation moderator mod administrator siteadmin site_admin
help retro_spring retroospring retrosprlng
]
})
end
describe "#create" do
@ -18,10 +29,10 @@ describe User::RegistrationsController, type: :controller do
let :registration_params do
{
user: {
screen_name: 'dio',
email: 'the-world-21@somewhere.everywhere',
password: 'AReallySecurePassword456!',
password_confirmation: 'AReallySecurePassword456!'
screen_name: "dio",
email: "the-world-21@somewhere.everywhere",
password: "AReallySecurePassword456!",
password_confirmation: "AReallySecurePassword456!"
}
}
end
@ -56,10 +67,10 @@ describe User::RegistrationsController, type: :controller do
let(:registration_params) do
{
user: {
screen_name: '',
email: '',
password: '',
password_confirmation: ''
screen_name: "",
email: "",
password: "",
password_confirmation: ""
}
}
end
@ -70,14 +81,16 @@ describe User::RegistrationsController, type: :controller do
end
context "when username contains invalid characters" do
let(:registration_params) { {
let(:registration_params) do
{
user: {
screen_name: 'Dio Brando',
email: 'the-world-21@somewhere.everywhere',
password: 'AReallySecurePassword456!',
password_confirmation: 'AReallySecurePassword456!'
screen_name: "Dio Brando",
email: "the-world-21@somewhere.everywhere",
password: "AReallySecurePassword456!",
password_confirmation: "AReallySecurePassword456!"
}
} }
}
end
it "does not create a user" do
expect { subject }.not_to(change { User.count })
@ -85,14 +98,16 @@ describe User::RegistrationsController, type: :controller do
end
context "when username is forbidden" do
let(:registration_params) { {
let(:registration_params) do
{
user: {
screen_name: 'inbox',
email: 'the-world-21@somewhere.everywhere',
password: 'AReallySecurePassword456!',
password_confirmation: 'AReallySecurePassword456!'
screen_name: "moderator",
email: "the-world-21@somewhere.everywhere",
password: "AReallySecurePassword456!",
password_confirmation: "AReallySecurePassword456!"
}
} }
}
end
it "does not create a user" do
expect { subject }.not_to(change { User.count })