This commit is contained in:
Stella Rouzi 2016-03-04 16:11:58 +00:00
commit 6b45645436

View file

@ -1,12 +1,56 @@
require 'spec_helper' require 'spec_helper'
feature User do feature User do
let(:user) { create(:user, name: 'My Name', biography: 'This is my biography!') }
shared_examples 'admin ability' do describe 'users#show' do
let!(:conference) { create(:conference, title: 'My conference') }
let!(:unconfirmed_event) { create(:event, state: 'unconfirmed', title: 'This is my test event title!', program: conference.program) }
end before :each do
unconfirmed_event.event_users = [create(:event_user, user: user, event_role: 'submitter')]
end
describe 'admin' do it 'shows user information' do
it_behaves_like 'admin ability', :admin visit user_path(user)
expect(page).to have_content 'My Name'
expect(page).to have_content 'This is my biography!'
expect(page).to have_selector('img')
expect(page).to_not have_content 'My Name presents'
end
it 'does not show event information for unconfirmed events' do
expect(page).to_not have_selector('h3', text: 'My Name presents 1 Event:')
expect(page).to_not have_selector('ul li h4', text: 'This is my test event title!')
expect(page).to_not have_selector('ul li h4 strong', text: 'at')
expect(page).to_not have_selector('ul li h4', text: 'at My conference')
end
it 'shows user event information, when user has confirmed events' do
# User has 3 confirmed events, and 1 unconfirmed
# 2 confirmed events in one conference, 1 confirmed event in another conference
event1 = create(:event, state: 'confirmed', title: 'This is my test event title!', program: conference.program)
event2 = create(:event, state: 'confirmed', title: 'This is my second test event title!', program: conference.program)
event1.event_users = [create(:event_user, user: user, event_role: 'submitter')]
event2.event_users = [create(:event_user, user: user, event_role: 'submitter')]
another_conference = create(:conference, title: 'My another conference')
another_event = create(:event, state: 'confirmed', title: 'This is my another test event title!', program: another_conference.program)
another_event.event_users = [create(:event_user, user: user, event_role: 'submitter')]
visit user_path(user)
expect(page).to have_selector('h3', text: 'My Name presents 3 Events:', count: 1)
expect(page).to have_selector('ul li h4', text: 'This is my test event title!', count: 1)
expect(page).to have_selector('ul li h4 strong', text: 'at', count: 3)
expect(page).to have_selector('ul li h4', text: 'at My conference', count: 2)
expect(page).to have_selector('ul li h4', text: 'This is my second test event title!', count: 1)
expect(page).to have_selector('ul li h4', text: 'This is my another test event title!', count: 1)
expect(page).to have_selector('ul li h4', text: 'at My another conference', count: 1)
end
end end
end end