Skip to content

Commit

Permalink
Devise 4.1
Browse files Browse the repository at this point in the history
* Fix devise omniauth path deprecation by replacing
  user_omniauth_authorize_path(:github) with
  omniauth_authorize_path(:user, :github)
* Use devise_parameter_sanitizer.permit instead of .for
* Explictly set Devise's `config.reconfirmable` to
  `false`, because the new default is `true` but we
  don't have the DB columns for it.

UPDATED:
devise  3.5.9  4.1.0
  • Loading branch information
tjgrathwell committed May 9, 2016
1 parent 84a53ba commit 2c13ce7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ruby '2.3.1'
gem 'dotenv-rails', groups: [:development, :test]

gem 'rails', '4.2.6'
gem 'devise', '~> 3.5.0'
gem 'devise', '4.1.0'
gem 'pundit'
gem 'puma'
gem 'jquery-rails'
Expand Down
7 changes: 3 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ GEM
safe_yaml (~> 1.0.0)
crass (1.0.2)
debug_inspector (0.0.2)
devise (3.5.9)
devise (4.1.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
railties (>= 4.1.0, < 5.1)
responders
thread_safe (~> 0.1)
warden (~> 1.2.3)
diff-lcs (1.2.5)
dotenv (2.1.1)
Expand Down Expand Up @@ -353,7 +352,7 @@ DEPENDENCIES
capybara (>= 2.0.1)
capybara-screenshot
coffee-rails
devise (~> 3.5.0)
devise (= 4.1.0)
dotenv-rails
factory_girl_rails
faker
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def after_sign_in_path_for(resource)
protected

def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) do |u|
devise_parameter_sanitizer.permit(:sign_up) do |u|
u.permit(User::PERMITTED_ATTRIBUTES + [region_ids: []])
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/registrations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<i class='fa <%= provider[:icon] %>'></i>
<%= provider[:name] %> (UID <%= existing_authentication.uid %>)
<% else %>
<%= link_to user_omniauth_authorize_path(provider[:key]) do %>
<%= link_to omniauth_authorize_path(:user, provider[:key]) do %>
<i class='fa <%= provider[:icon] %>'></i>
Associate with <%= provider[:name] %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_sign_in.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ul class='external-auth'>
<% OmniauthProviders.provider_data.each do |provider| %>
<li>
<%= link_to user_omniauth_authorize_path(provider[:key], origin: session["user_return_to"]) do %>
<%= link_to omniauth_authorize_path(:user, provider[:key], origin: session["user_return_to"]) do %>
<i class='fa <%= provider[:icon] %>'></i>
<%= provider[:name] %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed new email is stored in
# unconfirmed email column, and copied to email column on successful confirmation.
# config.reconfirmable = true
config.reconfirmable = false

# Defines which key will be used when confirming an account
# config.confirmation_keys = [ :email ]
Expand Down
26 changes: 15 additions & 11 deletions spec/features/omniauth_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
require Rails.root.join('spec', 'services', 'omniauth_responses')

describe "signing in with omniauth" do
# TODO: why is this needed, they load in the app just fine
include Devise::Controllers::UrlHelpers
include Devise::OmniAuth::UrlHelpers

before do
OmniAuth.config.test_mode = true
end
Expand All @@ -14,7 +18,7 @@
end

it 'creates a user and authentication if the user does not exist' do
visit user_omniauth_authorize_path(:facebook)
visit omniauth_authorize_path(:user, :facebook)

within '#sign-up' do
click_on 'Sign up'
Expand All @@ -35,7 +39,7 @@
user = create(:user)
sign_in_as user

visit user_omniauth_authorize_path(:facebook)
visit omniauth_authorize_path(:user, :facebook)

authentication = user.authentications.first
expect(authentication.provider).to eq('facebook')
Expand All @@ -51,7 +55,7 @@
end

it 'creates a user and authentication if the user does not exist' do
visit user_omniauth_authorize_path(:google_oauth2)
visit omniauth_authorize_path(:user, :google_oauth2)

within '#sign-up' do
click_on 'Sign up'
Expand All @@ -72,7 +76,7 @@
user = create(:user)
sign_in_as user

visit user_omniauth_authorize_path(:google_oauth2)
visit omniauth_authorize_path(:user, :google_oauth2)

authentication = user.authentications.first
expect(authentication.provider).to eq('google_oauth2')
Expand All @@ -88,7 +92,7 @@
end

it 'creates a user and authentication after the user provides an email' do
visit user_omniauth_authorize_path(:twitter)
visit omniauth_authorize_path(:user, :twitter)

within '#sign-up' do
fill_in 'Email', with: 'cool_tweeter@example.com'
Expand All @@ -115,7 +119,7 @@
end

it 'creates a user and authentication after the user provides an email' do
visit user_omniauth_authorize_path(:meetup)
visit omniauth_authorize_path(:user, :meetup)

within '#sign-up' do
fill_in 'Email', with: 'meetup_user@example.com'
Expand All @@ -142,7 +146,7 @@
end

it 'creates a user and authentication after the user provides an email' do
visit user_omniauth_authorize_path(:github)
visit omniauth_authorize_path(:user, :github)

within '#sign-up' do
click_on 'Sign up'
Expand Down Expand Up @@ -173,7 +177,7 @@
sign_in_as user

expect {
visit user_omniauth_authorize_path(:facebook)
visit omniauth_authorize_path(:user, :facebook)
}.not_to change(Authentication, :count)

expect(page).to have_content 'already in use'
Expand All @@ -186,7 +190,7 @@
auth_response[:info].delete(:name)
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(auth_response)

visit user_omniauth_authorize_path(:github)
visit omniauth_authorize_path(:user, :github)

expect(find_field('user[first_name]').value).to be_blank
expect(find_field('user[last_name]').value).to be_blank
Expand All @@ -197,7 +201,7 @@
auth_response[:info][:name] = ''
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(auth_response)

visit user_omniauth_authorize_path(:github)
visit omniauth_authorize_path(:user, :github)

expect(find_field('user[first_name]').value).to be_blank
expect(find_field('user[last_name]').value).to be_blank
Expand All @@ -208,7 +212,7 @@
auth_response[:info][:name] = 'Enigma'
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(auth_response)

visit user_omniauth_authorize_path(:github)
visit omniauth_authorize_path(:user, :github)

expect(find_field('user[first_name]').value).to eq('Enigma')
expect(find_field('user[last_name]').value).to be_blank
Expand Down

0 comments on commit 2c13ce7

Please sign in to comment.