Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Fixes for issue #23 #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ def meetup
@user = User.find_for_meetup_oauth(request.env['omniauth.auth'], current_user)

if @user.persisted?
@user.set_organizer_flag(request.env['omniauth.auth'])
sign_in_and_redirect(@user, event: :authentication)
else
session['devise.meetup_data'] = request.env['omniauth.auth']
redirect_to(root_path)
redirect_to(root_path, notice: 'You are not a member of this meetup group. Please join first.')
end
end
end
4 changes: 1 addition & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ def self.by_name
end

def self.find_for_meetup_oauth(auth, signed_in_resource = nil)
user = User.where(provider: auth.provider, uid: auth.uid.to_s).first_or_create.tap do |u|
User.where(provider: auth.provider, uid: auth.uid.to_s).first_or_create do |u|
u.name = auth.info.name
end
user.set_organizer_flag(auth)
user
end

def voted_on?(topic)
Expand Down
45 changes: 22 additions & 23 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
require 'spec_helper'

describe User do

describe '.find_for_meetup_oauth' do
let(:auth) { OpenStruct.new(provider: 'test', uid: '123456', info: OpenStruct.new(name: 'Joe Blow')) }

describe '.find_for_meetup_oauth' do
context 'when the user does not exist' do
let(:auth) { OpenStruct.new(provider: 'test', uid: '123456', info: OpenStruct.new(name: 'Joe Blow')) }

before { Meetup::Profile.stub(:get).and_return({'role' => ''}) }

it 'creates the user' do
Expand All @@ -30,24 +28,6 @@
User.find_by_name('Joe Blow').organizer.should be_false
end
end

context 'when the user is an organizer' do
before { Meetup::Profile.stub(:get).and_return({'role' => 'Organizer'}) }

it 'sets the user as an organizer' do
User.find_for_meetup_oauth(auth)
User.find_by_name('Joe Blow').organizer.should be_true
end
end

context 'when the user is a co-organizer' do
before { Meetup::Profile.stub(:get).and_return({'role' => 'Co-Organizer'}) }

it 'sets the user as an organizer' do
User.find_for_meetup_oauth(auth)
User.find_by_name('Joe Blow').organizer.should be_true
end
end
end

context 'when the user does exist' do
Expand All @@ -61,9 +41,28 @@
it 'does not create the user' do
expect {User.find_for_meetup_oauth(auth)}.to_not change(User,:count)
end
end
end

describe '.set_organizer_flag' do
let(:user) { User.create(name: 'Joe Blow') }

context 'when the user is an organizer' do
before { Meetup::Profile.stub(:get).and_return({'role' => 'Organizer'}) }

it 'sets the user as an organizer' do
user.set_organizer_flag(auth)
expect(user.organizer).to be_true
end
end

end
context 'when the user is a co-organizer' do
before { Meetup::Profile.stub(:get).and_return({'role' => 'Co-Organizer'}) }

it 'sets the user as an organizer' do
user.set_organizer_flag(auth)
expect(user.organizer).to be_true
end
end
end
end