[refs #232] Add groups tests

This commit is contained in:
konstantin.grabar 2012-03-20 19:40:49 +04:00
parent fcc17c7c0a
commit aa4bd2c1bc
3 changed files with 195 additions and 11 deletions

View File

@ -285,17 +285,17 @@ ActiveRecord::Schema.define(:version => 20120314223151) do
t.text "description"
t.string "ancestry"
t.boolean "has_issues", :default => true
t.boolean "has_wiki", :default => false
t.string "srpm_file_name"
t.string "srpm_content_type"
t.integer "srpm_file_size"
t.datetime "srpm_updated_at"
t.boolean "has_wiki", :default => false
t.string "default_branch", :default => "master"
t.boolean "is_rpm", :default => true
end
add_index "projects", ["category_id"], :name => "index_projects_on_category_id"
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true
create_table "register_requests", :force => true do |t|
t.string "name"
@ -303,13 +303,14 @@ ActiveRecord::Schema.define(:version => 20120314223151) do
t.string "token"
t.boolean "approved", :default => false
t.boolean "rejected", :default => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "interest"
t.text "more"
end
add_index "register_requests", ["email"], :name => "index_register_requests_on_email", :unique => true, :case_sensitive => false
add_index "register_requests", ["token"], :name => "index_register_requests_on_token", :unique => true, :case_sensitive => false
create_table "relations", :force => true do |t|
t.integer "object_id"

View File

@ -1,6 +1,82 @@
# -*- encoding : utf-8 -*-
require 'spec_helper'
shared_examples_for 'group user without update rights' do
it 'should be not able to perform update action' do
put :update, {:id => @group.id}.merge(@update_params)
response.should redirect_to(forbidden_path)
end
it 'should not be able to update group data' do
put :update, :id => @group.id, :group => {:description => 'new description'}
@group.reload.description.should_not == 'new description'
end
pending 'should be able to manage_members group' do
get :manage_members, :id => @group.id
response.should render_template("")
end
end
shared_examples_for 'group user without destroy rights' do
it 'should not be able to destroy group' do
delete :destroy, :id => @group.id
response.should redirect_to(forbidden_path)
end
it 'should not change groups count after destroy action' do
lambda { delete :destroy, :id => @group.id }.should change{ Group.count }.by(0)
end
end
shared_examples_for 'group admin' do
it_should_behave_like 'no group user'
it 'should be able to update group data' do
put :update, :id => @group.id, :group => {:description => 'new description'}
@group.reload.description.should == 'new description'
end
it 'should be able to perform update action' do
put :update, {:id => @group.id}.merge(@update_params)
response.should redirect_to(group_path(@group))
end
pending 'should be able to manage_members group' do
get :manage_members, :id => @group.id
response.should render_template("")
end
end
shared_examples_for 'no group user' do
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(group_path( Group.last.id ))
end
it 'should change objects count on create' do
lambda { post :create, @create_params }.should change{ Group.count }.by(1)
end
it 'should be able to perform autocomplete_group_uname action' do
get :autocomplete_group_uname
response.should be_success
end
end
shared_examples_for 'group owner' do
it_should_behave_like 'group admin'
it 'should be able to destroy group' do
delete :destroy, :id => @group.id
response.should redirect_to(groups_path)
end
it 'should change groups count after destroy action' do
lambda { delete :destroy, :id => @group.id }.should change{ Group.count }.by(-1)
end
end
describe GroupsController do
before(:each) do
stub_rsync_methods
@ -22,13 +98,14 @@ describe GroupsController do
end
end
context 'for admin' do
context 'for global admin' do
before(:each) do
@admin = Factory(:admin)
set_session_for(@admin)
end
it_should_behave_like 'update_member_relation'
it_should_behave_like 'group owner'
it 'should be able to perform index action' do
get :index
@ -39,14 +116,41 @@ describe GroupsController do
put :update, {:id => @group.id}.merge(@update_params)
response.should redirect_to(group_path(@group))
end
end
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(group_path( Group.last.id ))
context 'for group admin' do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end
it 'should change objects count on create' do
lambda { post :create, @create_params }.should change{ Group.count }.by(1)
it_should_behave_like 'update_member_relation'
it_should_behave_like 'group admin'
it_should_behave_like 'group user without destroy rights'
end
context 'for group owner' do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
@group.update_attribute(:owner, @user)
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end
it_should_behave_like 'update_member_relation'
it_should_behave_like 'group owner'
end
context 'for group reader and writer user' do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end
it_should_behave_like 'no group user'
it_should_behave_like 'group user without destroy rights'
it_should_behave_like 'group user without update rights'
end
end

View File

@ -1,6 +1,85 @@
# -*- encoding : utf-8 -*-
require 'spec_helper'
require "cancan/matchers"
describe Group do
pending "add some examples to (or delete) #{__FILE__}"
before(:each) do
stub_rsync_methods
@group = Factory(:group)
@ability = Ability.new(User.new)
end
context 'for guest' do
[:read, :update, :destroy, :manage_members, :autocomplete_group_uname].each do |action|
it "should not be able to #{action} group" do
@ability.should_not be_able_to(action, @group)
end
end
end
context 'for global admin' do
before(:each) do
@admin = Factory(:admin)
@ability = Ability.new(@admin)
end
[:read, :update, :destroy, :manage_members, :autocomplete_group_uname].each do |action|
it "should be able to #{action} group" do
@ability.should be_able_to(action, @group)
end
end
end
context 'for group admin' do
before(:each) do
@user = Factory(:user)
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@ability = Ability.new(@user)
end
[:read, :update, :manage_members, :autocomplete_group_uname].each do |action|
it "should be able to #{action} group" do
@ability.should be_able_to(action, @group)
end
end
it "should not be able to destroy group" do
@ability.should_not be_able_to(:destroy, @group)
end
end
context 'for group owner' do
before(:each) do
@user = Factory(:user)
@group.update_attribute(:owner, @user)
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@ability = Ability.new(@user)
end
[:read, :update, :destroy, :manage_members, :autocomplete_group_uname].each do |action|
it "should be able to #{action} group" do
@ability.should be_able_to(action, @group)
end
end
end
context 'for group reader and writer user' do
before(:each) do
@user = Factory(:user)
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'reader')
@ability = Ability.new(@user)
end
[:read, :autocomplete_group_uname].each do |action|
it "should be able to #{action} group" do
@ability.should be_able_to(action, @group)
end
end
[:update, :destroy, :manage_members].each do |action|
it "should not be able to #{action} group" do
@ability.should_not be_able_to(action, @group)
end
end
end
end