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 before do
# Required for devise to register routes # Required for devise to register routes
@request.env["devise.mapping"] = Devise.mappings[:user] @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 end
describe "#create" do describe "#create" do
@ -17,12 +28,12 @@ describe User::RegistrationsController, type: :controller do
let :registration_params do let :registration_params do
{ {
user: { user: {
screen_name: 'dio', screen_name: "dio",
email: 'the-world-21@somewhere.everywhere', email: "the-world-21@somewhere.everywhere",
password: 'AReallySecurePassword456!', password: "AReallySecurePassword456!",
password_confirmation: 'AReallySecurePassword456!' password_confirmation: "AReallySecurePassword456!"
} }
} }
end end
@ -55,12 +66,12 @@ describe User::RegistrationsController, type: :controller do
context "when registration params are empty" do context "when registration params are empty" do
let(:registration_params) do let(:registration_params) do
{ {
user: { user: {
screen_name: '', screen_name: "",
email: '', email: "",
password: '', password: "",
password_confirmation: '' password_confirmation: ""
} }
} }
end end
@ -70,14 +81,16 @@ describe User::RegistrationsController, type: :controller do
end end
context "when username contains invalid characters" do context "when username contains invalid characters" do
let(:registration_params) { { let(:registration_params) do
{
user: { user: {
screen_name: 'Dio Brando', screen_name: "Dio Brando",
email: 'the-world-21@somewhere.everywhere', email: "the-world-21@somewhere.everywhere",
password: 'AReallySecurePassword456!', password: "AReallySecurePassword456!",
password_confirmation: 'AReallySecurePassword456!' password_confirmation: "AReallySecurePassword456!"
} }
} } }
end
it "does not create a user" do it "does not create a user" do
expect { subject }.not_to(change { User.count }) expect { subject }.not_to(change { User.count })
@ -85,14 +98,16 @@ describe User::RegistrationsController, type: :controller do
end end
context "when username is forbidden" do context "when username is forbidden" do
let(:registration_params) { { let(:registration_params) do
{
user: { user: {
screen_name: 'inbox', screen_name: "moderator",
email: 'the-world-21@somewhere.everywhere', email: "the-world-21@somewhere.everywhere",
password: 'AReallySecurePassword456!', password: "AReallySecurePassword456!",
password_confirmation: 'AReallySecurePassword456!' password_confirmation: "AReallySecurePassword456!"
} }
} } }
end
it "does not create a user" do it "does not create a user" do
expect { subject }.not_to(change { User.count }) expect { subject }.not_to(change { User.count })