Skip to content

Commit

Permalink
Omniauth: crash less when the provider sends us empty string as a ful…
Browse files Browse the repository at this point in the history
…l name
  • Loading branch information
tjgrathwell committed Mar 14, 2014
1 parent 9f42312 commit 99eed3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/services/omniauth_providers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def self.user_attributes_from_omniauth(omniauth)
private

def self.split_name(full_name)
return {} unless full_name
return {} if full_name.blank?

components = full_name.split(' ')
{
Expand Down
30 changes: 20 additions & 10 deletions spec/features/omniauth_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,38 @@
end
end

context "when the omniauth provider sends a nil 'full name' field" do
before do
describe "parsing the name attribute" do
it "assigns blank first name and last name if name is not present" do
auth_response = OmniauthResponses.github_response
auth_response[:info].delete(:name)
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(auth_response)

visit user_omniauth_authorize_path(:github)

find_field('user[first_name]').value.should be_blank
find_field('user[last_name]').value.should be_blank
end

it 'requires the user to enter first_name and last_name and authentication after the user provides an email' do
it "assigns blank first name and last name if name is an empty string" do
auth_response = OmniauthResponses.github_response
auth_response[:info][:name] = ''
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(auth_response)

visit user_omniauth_authorize_path(:github)

find_field('user[first_name]').value.should be_blank
find_field('user[last_name]').value.should be_blank
end

fill_in 'user[first_name]', with: 'Dan'
fill_in 'user[last_name]', with: 'Danson'
it "assigns just the first name if the 'name' attribute has no spaces" do
auth_response = OmniauthResponses.github_response
auth_response[:info][:name] = 'Enigma'
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(auth_response)

click_on 'Sign up'
visit user_omniauth_authorize_path(:github)

user = User.last
user.first_name.should == "Dan"
user.last_name.should == "Danson"
user.email.should == "ffjords@example.com"
find_field('user[first_name]').value.should == 'Enigma'
find_field('user[last_name]').value.should be_blank
end
end
end

0 comments on commit 99eed3d

Please sign in to comment.