Add registration tests
This commit is contained in:
parent
9f01da8e03
commit
c4fb5d1db9
1
Gemfile
1
Gemfile
|
@ -88,6 +88,7 @@ gem 'puma'
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem 'rake'
|
gem 'rake'
|
||||||
|
gem 'rspec-mocks'
|
||||||
gem 'rspec-rails', '~> 3.9'
|
gem 'rspec-rails', '~> 3.9'
|
||||||
gem 'rspec-its', '~> 1.3'
|
gem 'rspec-its', '~> 1.3'
|
||||||
gem "rspec-sidekiq", "~> 3.0", require: false
|
gem "rspec-sidekiq", "~> 3.0", require: false
|
||||||
|
|
|
@ -609,6 +609,7 @@ DEPENDENCIES
|
||||||
redis
|
redis
|
||||||
rolify (~> 5.2)
|
rolify (~> 5.2)
|
||||||
rspec-its (~> 1.3)
|
rspec-its (~> 1.3)
|
||||||
|
rspec-mocks
|
||||||
rspec-rails (~> 3.9)
|
rspec-rails (~> 3.9)
|
||||||
rspec-sidekiq (~> 3.0)
|
rspec-sidekiq (~> 3.0)
|
||||||
ruby-progressbar
|
ruby-progressbar
|
||||||
|
|
|
@ -3,4 +3,6 @@ return unless APP_CONFIG.dig(:hcaptcha, :enabled)
|
||||||
Hcaptcha.configure do |config|
|
Hcaptcha.configure do |config|
|
||||||
config.site_key = APP_CONFIG.dig(:hcaptcha, :site_key)
|
config.site_key = APP_CONFIG.dig(:hcaptcha, :site_key)
|
||||||
config.secret_key = APP_CONFIG.dig(:hcaptcha, :secret_key)
|
config.secret_key = APP_CONFIG.dig(:hcaptcha, :secret_key)
|
||||||
|
|
||||||
|
config.skip_verify_env.delete 'test'
|
||||||
end
|
end
|
|
@ -0,0 +1,69 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe User::RegistrationsController, type: :controller do
|
||||||
|
before do
|
||||||
|
@request.env["devise.mapping"] = Devise.mappings[:user]
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#create" do
|
||||||
|
context "valid user sign up" do
|
||||||
|
let :registration_params do
|
||||||
|
{
|
||||||
|
user: {
|
||||||
|
screen_name: 'dio',
|
||||||
|
email: 'the-world-21@somewhere.everywhere',
|
||||||
|
password: 'AReallySecurePassword456!',
|
||||||
|
password_confirmation: 'AReallySecurePassword456!'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { post :create, params: registration_params }
|
||||||
|
|
||||||
|
it "doesn't allow a registration without solving the captcha" do
|
||||||
|
expect { subject }.not_to(change { User.count })
|
||||||
|
expect(response).to redirect_to :new_user_registration
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a user" do
|
||||||
|
allow(controller).to receive(:verify_hcaptcha).and_return(true)
|
||||||
|
expect { subject }.to change { User.count }.by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "invalid user sign up" do
|
||||||
|
subject { post :create, params: registration_params }
|
||||||
|
|
||||||
|
let!(:registration_params) { {} }
|
||||||
|
it "rejects unfilled registration forms" do
|
||||||
|
expect { subject }.not_to(change { User.count })
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:registration_params) { {
|
||||||
|
user: {
|
||||||
|
screen_name: 'Dio Brando',
|
||||||
|
email: 'the-world-21@somewhere.everywhere',
|
||||||
|
password: 'AReallySecurePassword456!',
|
||||||
|
password_confirmation: 'AReallySecurePassword456!'
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
it "rejects registrations with invalid usernames" do
|
||||||
|
expect { subject }.not_to(change { User.count })
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:registration_params) { {
|
||||||
|
user: {
|
||||||
|
screen_name: 'inbox',
|
||||||
|
email: 'the-world-21@somewhere.everywhere',
|
||||||
|
password: 'AReallySecurePassword456!',
|
||||||
|
password_confirmation: 'AReallySecurePassword456!'
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
it "rejects registrations with reserved usernames" do
|
||||||
|
expect { subject }.not_to(change { User.count })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue