created tests for user ability

This commit is contained in:
raluka 2015-08-26 13:07:13 +02:00
parent eab2894fad
commit 84cd952b57
3 changed files with 13 additions and 7 deletions

View file

@ -137,9 +137,8 @@ class Ability
can :manage, Sponsor, conference_id: conf_ids_for_organizer can :manage, Sponsor, conference_id: conf_ids_for_organizer
can :manage, SponsorshipLevel, conference_id: conf_ids_for_organizer can :manage, SponsorshipLevel, conference_id: conf_ids_for_organizer
can :manage, Ticket, conference_id: conf_ids_for_organizer can :manage, Ticket, conference_id: conf_ids_for_organizer
can [:read, :create], Comment, commentable_type: 'Event', can [:index, :create], Comment, commentable_type: 'Event',
commentable_id: Event.where(conference_id: conf_ids_for_organizer).pluck(:id) commentable_id: Event.where(conference_id: conf_ids_for_organizer).pluck(:id)
end end
def signed_in_with_cfp_role(user) def signed_in_with_cfp_role(user)
@ -158,7 +157,7 @@ class Ability
can :manage, CallForPaper, conference_id: conf_ids_for_cfp can :manage, CallForPaper, conference_id: conf_ids_for_cfp
can :manage, Commercial, commercialable_type: 'Event', can :manage, Commercial, commercialable_type: 'Event',
commercialable_id: Event.where(conference_id: conf_ids_for_cfp).pluck(:id) commercialable_id: Event.where(conference_id: conf_ids_for_cfp).pluck(:id)
can [:read, :create], Comment, commentable_type: 'Event', can [:index, :create], Comment, commentable_type: 'Event',
commentable_id: Event.where(conference_id: conf_ids_for_cfp).pluck(:id) commentable_id: Event.where(conference_id: conf_ids_for_cfp).pluck(:id)
end end

View file

@ -25,7 +25,7 @@
%b.caret %b.caret
%ul.dropdown-menu %ul.dropdown-menu
= render 'layouts/user_menu' = render 'layouts/user_menu'
- if can? :read, Comment - if can? :index, Comment #TODO modify condition
%ul.nav.navbar-nav.navbar-right %ul.nav.navbar-nav.navbar-right
%li.dropdown %li.dropdown
%a.dropdown-toggle{"data-toggle" => "dropdown", :href => "#", id: "unread-comments-preview"} %a.dropdown-toggle{"data-toggle" => "dropdown", :href => "#", id: "unread-comments-preview"}

View file

@ -141,7 +141,8 @@ describe 'User' do
it{ should_not be_able_to(:manage, other_event.difficulty_level) } it{ should_not be_able_to(:manage, other_event.difficulty_level) }
it{ should be_able_to(:manage, event.commercials.first) } it{ should be_able_to(:manage, event.commercials.first) }
it{ should_not be_able_to(:manage, other_event.commercials.first) } it{ should_not be_able_to(:manage, other_event.commercials.first) }
it{ should be_able_to([:read, :create], event.comment_threads.first) } it{ should be_able_to(:create, event.comment_threads.first) }
it{ should be_able_to(:index, event.comment_threads.first) }
end end
context 'when user has the role cfp' do context 'when user has the role cfp' do
@ -199,6 +200,8 @@ describe 'User' do
it{ should_not be_able_to(:manage, other_event.difficulty_level) } it{ should_not be_able_to(:manage, other_event.difficulty_level) }
it{ should be_able_to(:manage, event.commercials.first) } it{ should be_able_to(:manage, event.commercials.first) }
it{ should_not be_able_to(:manage, other_event.commercials.first) } it{ should_not be_able_to(:manage, other_event.commercials.first) }
it{ should be_able_to(:create, event.comment_threads.first) }
it{ should be_able_to(:index, event.comment_threads.first) }
end end
context 'when user has the role info_desk' do context 'when user has the role info_desk' do
@ -256,6 +259,8 @@ describe 'User' do
it{ should_not be_able_to(:manage, other_event.difficulty_level) } it{ should_not be_able_to(:manage, other_event.difficulty_level) }
it{ should_not be_able_to(:manage, event.commercials.first) } it{ should_not be_able_to(:manage, event.commercials.first) }
it{ should_not be_able_to(:manage, other_event.commercials.first) } it{ should_not be_able_to(:manage, other_event.commercials.first) }
it{ should_not be_able_to(:create, event.comment_threads.first) }
it{ should_not be_able_to(:index, event.comment_threads.first) }
end end
context 'when user has the role volunteers_coordinator' do context 'when user has the role volunteers_coordinator' do
@ -313,6 +318,8 @@ describe 'User' do
it{ should_not be_able_to(:manage, other_event.difficulty_level) } it{ should_not be_able_to(:manage, other_event.difficulty_level) }
it{ should_not be_able_to(:manage, event.commercials.first) } it{ should_not be_able_to(:manage, event.commercials.first) }
it{ should_not be_able_to(:manage, other_event.commercials.first) } it{ should_not be_able_to(:manage, other_event.commercials.first) }
it{ should_not be_able_to(:create, event.comment_threads.first) }
it{ should_not be_able_to(:index, event.comment_threads.first) }
it 'should be_able to :manage Vposition' it 'should be_able to :manage Vposition'
it 'should be_able to :manage Vday' it 'should be_able to :manage Vday'
end end