This commit is contained in:
Stella Rouzi 2014-07-24 22:11:54 +03:00
parent 439d632251
commit 2d3a1ef37e

View file

@ -6,7 +6,7 @@ describe 'User' do
subject(:ability){ Ability.new(user) } subject(:ability){ Ability.new(user) }
let(:user){ nil } let(:user){ nil }
let(:conference_not_public) { create(:conference, make_conference_public: false) } let(:conference_not_public) { create(:conference, make_conference_public: false) }
let(:conference_public) { create(:conference)} let(:conference_public) { create(:conference, make_conference_public: true) }
let(:event_confirmed) { create(:event, state: 'confirmed') } let(:event_confirmed) { create(:event, state: 'confirmed') }
let(:someevent) { create(:event) } let(:someevent) { create(:event) }
@ -28,30 +28,40 @@ describe 'User' do
context 'when is a Signed In User' do # Test abilities for signed in users (without any role) context 'when is a Signed In User' do # Test abilities for signed in users (without any role)
let(:user) { create(:participant) } let(:user) { create(:participant) }
let(:someuser) { create(:participant) }
let(:registration1) { create(:registration, conference: conference_public, user: user) } let(:registration1) { create(:registration, conference: conference_public, user: user) }
let(:registration2) { create(:registration, conference: conference_not_public, user: user) } let(:registration2) { create(:registration, conference: conference_not_public, user: someuser) }
it{ should be_able_to(:create, Event) } # Can create a new proposal
it{ should be_able_to(:index, Event) } # Can access proposal index page
it{ should_not be_able_to(:manage, Event.new) } # Cannot manage events that are not theirs
it{ should be_able_to(:show, event_confirmed) } # Can only view confirmed events
it{ should_not be_able_to(:show, someevent) }
it{ should be_able_to(:create, Event) } # Can register for a conference
it{ should be_able_to(:index, Event) } it{ should be_able_to(:register, registration1) }
it{ should_not be_able_to(:manage, Event.new) } it{ should be_able_to(:update, registration1) }
it{ should be_able_to(:show, event_confirmed) } it{ should be_able_to(:unregister, registration1) }
# Cannot change the registration of other people
it{ should be_able_to(:manage, registration1) } it{ should_not be_able_to(:register, registration2) }
it{ should be_able_to(:manage, registration2) } it{ should_not be_able_to(:update, registration2) }
it{ should_not be_able_to(:unregister, registration2) }
# Can see the conference splash page only if conference is public
it{ should be_able_to(:show, conference_public)} it{ should be_able_to(:show, conference_public)}
it{ should_not be_able_to(:show, conference_not_public)} it{ should_not be_able_to(:show, conference_not_public)}
it{ should_not be_able_to(:manage, Conference) }
# Cannot manage a conference
it{ should_not be_able_to(:manage, conference_public) }
end end
context '#is_admin?' do context '#is_admin?' do
let(:user) { create(:admin) } let(:user) { create(:admin) }
it{ should be_able_to(:manage, User) } it{ should be_able_to(:manage, User) }
end end
context 'signed in users can manage their events' do context 'signed in users can manage their events' do
>>>>>>> adding tests and some fixes in ability
let(:user) { create(:participant) } let(:user) { create(:participant) }
let(:user2) { create(:participant) } let(:user2) { create(:participant) }
let(:myevent) { create(:event, users: [user]) } let(:myevent) { create(:event, users: [user]) }
@ -60,19 +70,11 @@ describe 'User' do
# Users are able to update and destroy their own events # Users are able to update and destroy their own events
it{ should be_able_to(:update, myevent) } it{ should be_able_to(:update, myevent) }
it{ should be_able_to(:destroy, myevent) } it{ should be_able_to(:destroy, myevent) }
<<<<<<< HEAD
=======
it{ should be_able_to(:manage, myevent) } it{ should be_able_to(:manage, myevent) }
>>>>>>> adding tests and some fixes in ability
# Users are not able to update and destroy other users events # Users are not able to update and destroy other users events
it{ should_not be_able_to(:update, someevent) } it{ should_not be_able_to(:update, someevent) }
it{ should_not be_able_to(:destroy, someevent) } it{ should_not be_able_to(:destroy, someevent) }
<<<<<<< HEAD
end
=======
it{ should_not be_able_to(:manage, someevent) }
end end
context 'when is an organizer' do context 'when is an organizer' do
@ -110,6 +112,5 @@ describe 'User' do
it{ should be_able_to(:manage, create(:event_type, conference: conference1)) } it{ should be_able_to(:manage, create(:event_type, conference: conference1)) }
# it{ should_not be_able_to(:create, Registration) } # it{ should_not be_able_to(:create, Registration) }
end end
>>>>>>> adding tests and some fixes in ability
end end
end end