From 1c961deceda532c8edcb7581d3163fce371f4248 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 23:36:37 +0400 Subject: [PATCH] #321: added specs --- app/models/ability.rb | 2 +- spec/models/cancan_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 01baddc0c..30cde50a3 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -60,7 +60,7 @@ class Ability can :remove_user, Group can :create, Project - can([:mass_import, :run_mass_import], Project) if user.platforms.select(&:main?).find{ |p| local_admin?(p) }.present? + can([:mass_import, :run_mass_import], Project) if user.platforms.main.find{ |p| local_admin?(p) }.present? can :read, Project, :visibility => 'open' can [:read, :archive, :membered, :get_id], Project, :owner_type => 'User', :owner_id => user.id can [:read, :archive, :membered, :get_id], Project, :owner_type => 'Group', :owner_id => user.group_ids diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index 3e6a8377a..ec1d16d33 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -65,6 +65,12 @@ describe CanCan do end end + [:mass_import, :run_mass_import].each do |action| + it "should not be able to #{ action } project" do + @ability.should_not be_able_to(action, Project) + end + end + it 'should not be able to update register request' do @ability.should_not be_able_to(:update, register_request) end @@ -93,6 +99,12 @@ describe CanCan do end end + [:mass_import, :run_mass_import].each do |action| + it "should not be able to #{ action } project" do + @ability.should_not be_able_to(action, Project) + end + end + it "shoud be able to show user profile" do @ability.should be_able_to(:show, User) end @@ -260,6 +272,13 @@ describe CanCan do before(:each) do @platform.owner = @user @platform.save + @ability = Ability.new(@user) + end + + [:mass_import, :run_mass_import].each do |action| + it "should be able to #{ action } project" do + @ability.should be_able_to(action, Project) + end end [:read, :update, :destroy, :change_visibility].each do |action| @@ -272,6 +291,13 @@ describe CanCan do context 'with read rights' do before(:each) do @platform.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'reader') + @ability = Ability.new(@user) + end + + [:mass_import, :run_mass_import].each do |action| + it "should not be able to #{ action } project" do + @ability.should_not be_able_to(action, Project) + end end it "should be able to read platform" do