Skip to content

Commit

Permalink
Merge pull request #373 from call4paperz/bugfix/store=user-name-database
Browse files Browse the repository at this point in the history
fixed bug about registration form
  • Loading branch information
italomatos committed Nov 9, 2019
2 parents 3580e90 + 8b3d996 commit 9f66b7d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ group :test do
gem 'culerity'
gem 'database_cleaner'
gem 'factory_bot_rails'
gem 'faker'
gem 'rails-controller-testing'
gem 'rspec_junit_formatter'
gem 'shoulda-matchers'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ GEM
factory_bot_rails (4.8.2)
factory_bot (~> 4.8.2)
railties (>= 3.0.0)
faker (2.7.0)
i18n (>= 1.6, < 1.8)
faraday (0.17.0)
multipart-post (>= 1.2, < 3)
ffi (1.11.1)
Expand Down Expand Up @@ -366,6 +368,7 @@ DEPENDENCIES
devise (~> 4.7.1)
dotenv-rails
factory_bot_rails
faker
fog-aws (~> 3.3.0)
foreman
friendly_id (~> 5.2.5)
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ class ApplicationController < ActionController::Base

protect_from_forgery with: :exception

before_action :configure_permitted_parameters, if: :devise_controller?

protected
def store_location
if (request.get? && request.format.html? && !request.xhr? && !devise_controller?)
store_location_for(:user, request.url)
end
end

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up) do |u|
u.permit(:name, :email, :password, :password_confirmation)
end
end

private
def profile_completing?
params['controller'] == 'profiles' &&
Expand Down
20 changes: 20 additions & 0 deletions spec/features/registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
} do

context "Register through sign up form" do

it 'While registering, with correct data, all was persisted' do
visit '/users/sign_up'

user_name = Faker::Name.name
user_email = Faker::Internet.email

fill_in 'user_name', with: user_name
fill_in "user_email", with: user_email
fill_in "user_password", with: '123123'
fill_in "user_password_confirmation", with: '123123'
find("input[type=image]").click

user = User.where(email: user_email).first

expect(user.name).to eq(user_name)
end

scenario "While registering, I can't register without an email" do
visit '/users/sign_up'

Expand Down Expand Up @@ -39,6 +57,7 @@
scenario "While registering, I'm able to register with valid data" do
visit '/users/sign_up'

fill_in 'user_name', with: 'Test User'
fill_in "user_email", with: 'email@example.com'
fill_in "user_password", with: '123123'
fill_in "user_password_confirmation", with: '123123'
Expand All @@ -47,6 +66,7 @@
expect(page).to have_content 'A message with a confirmation link has been sent to your email address.'

user = User.where(email: 'email@example.com').first

user.confirm
sign_in_with user, '123123'
expect(page).to have_content 'Logout'
Expand Down

0 comments on commit 9f66b7d

Please sign in to comment.