[refs #2249] Add personal repositories specs. Correct perosnal repository factory

This commit is contained in:
konstantin.grabar 2011-11-30 13:53:53 +04:00
parent 7535fc124a
commit eed248676d
3 changed files with 186 additions and 0 deletions

View File

@ -1,5 +1,108 @@
require 'spec_helper' require 'spec_helper'
require 'shared_examples/personal_repositories_controller'
describe PersonalRepositoriesController do describe PersonalRepositoriesController do
before(:each) do
@repository = Factory(:personal_repository)
@platform = Factory(:platform)
@project = Factory(:project)
@another_user = Factory(:user)
@create_params = {:repository => {:name => 'pro', :description => 'pro2'}, :platform_id => @platform.id}
end
context 'for guest' do
[:show, :add_project, :remove_project, :settings, :change_visibility].each do |action|
it "should not be able to perform #{ action } action" do
get action, :id => @repository.id
response.should redirect_to(new_user_session_path)
end
end
end
context 'for admin' do
before(:each) do
@admin = Factory(:admin)
set_session_for(@admin)
end
it_should_behave_like 'be_able_to_perform_show_action'
it_should_behave_like 'be_able_to_perform_add_project_action'
it_should_behave_like 'be_able_to_perform_add_project_action_with_project_id_param'
it_should_behave_like 'add_project_to_repository'
it_should_behave_like 'be_able_to_perform_remove_project'
it_should_behave_like 'remove_project_from_repository'
it_should_behave_like 'be_able_to_perform_settings_action'
it_should_behave_like 'be_able_to_perform_change_visibility'
it_should_behave_like 'be_able_to_change_visibility'
end
context 'for anyone except admin' do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
end
end
context 'for owner user' do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
@repository.update_attribute(:owner, @user)
r = @repository.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'admin')
r.save!
@repository.platform.update_attribute(:owner, @user)
p = @repository.platform.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'admin')
p.save!
end
it_should_behave_like 'be_able_to_perform_settings_action'
it_should_behave_like 'be_able_to_perform_change_visibility'
it_should_behave_like 'be_able_to_change_visibility'
it_should_behave_like 'be_able_to_perform_show_action'
it_should_behave_like 'be_able_to_perform_add_project_action'
it_should_behave_like 'be_able_to_perform_add_project_action_with_project_id_param'
it_should_behave_like 'add_project_to_repository'
it_should_behave_like 'be_able_to_perform_remove_project'
it_should_behave_like 'remove_project_from_repository'
end
context 'for reader user' do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
r = @repository.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'reader')
r.save!
end
it_should_behave_like 'be_able_to_perform_show_action'
it 'should not be able to perform add_project action' do
get :add_project, :id => @repository.id
response.should redirect_to(forbidden_path)
end
it 'should not be able to perform add_project action with project_id param' do
get :add_project, :id => @repository.id, :project_id => @project.id
response.should redirect_to(forbidden_path)
end
it 'should not be able to perform settings action' do
get :settings, :id => @repository.id
response.should redirect_to(forbidden_path)
end
it 'should not be able to perform change_visibility action' do
get :change_visibility, :id => @repository.id
response.should redirect_to(forbidden_path)
end
it 'should not change visibility of repository' do
get :change_visibility, :id => @repository.id
@repository.platform.reload.visibility.should == 'hidden'
end
end
end end

View File

@ -13,6 +13,7 @@ Factory.define(:personal_repository, :class => Repository) do |p|
p.after_create { |rep| p.after_create { |rep|
rep.platform.platform_type = 'personal' rep.platform.platform_type = 'personal'
rep.platform.visibility = 'hidden'
rep.platform.save! rep.platform.save!
} }
end end

View File

@ -0,0 +1,82 @@
shared_examples_for 'be_able_to_perform_show_action' do
it 'should be able to perform show action' do
get :show, :id => @repository.id
response.should render_template(:show)
end
end
shared_examples_for 'be_able_to_perform_add_project_action' do
it 'should be able to perform add_project action' do
get :add_project, :id => @repository.id
response.should render_template(:projects_list)
end
end
shared_examples_for 'be_able_to_perform_add_project_action_with_project_id_param' do
it 'should be able to perform add_project action with project_id param' do
get :add_project, :id => @repository.id, :project_id => @project.id
response.should redirect_to(personal_repository_path(@repository))
end
end
shared_examples_for 'add_project_to_repository' do
it 'should be able to add project to repository' do
get :add_project, :id => @repository.id, :project_id => @project.id
@repository.projects.exists? :id => @project.id
end
end
shared_examples_for 'be_able_to_perform_remove_project' do
it 'should be able to perform remove_project action' do
get :remove_project, :id => @repository.id, :project_id => @project.id
response.should redirect_to(personal_repository_path(@repository))
end
end
shared_examples_for 'remove_project_from_repository' do
it 'should be able to remove project from repository' do
get :remove_project, :id => @repository.id, :project_id => @project.id
!@repository.projects.exists? :id => @project.id
end
end
shared_examples_for 'be_able_to_perform_destroy_action' do
it 'should be able to perform destroy action' do
delete :destroy, :id => @repository.id
response.should redirect_to(platform_path(@repository.platform.id))
end
end
shared_examples_for 'change_repositories_count_after_destroy' do
it 'should change objects count after destroy action' do
lambda { delete :destroy, :id => @repository.id }.should change{ Repository.count }.by(-1)
end
end
shared_examples_for 'not_be_able_to_destroy_personal_repository' do
it 'should not be able to destroy personal repository' do
delete :destroy, :id => @personal_repository.id
response.should redirect_to(forbidden_path)
end
end
shared_examples_for 'be_able_to_perform_settings_action' do
it 'should be able to perform settings action' do
get :settings, :id => @repository.id
response.should render_template(:settings)
end
end
shared_examples_for 'be_able_to_perform_change_visibility' do
it 'should be able to perform change_visibility action' do
get :change_visibility, :id => @repository.id
response.should redirect_to(settings_personal_repository_path(@repository))
end
end
shared_examples_for 'be_able_to_change_visibility' do
it 'should change visibility of repository' do
get :change_visibility, :id => @repository.id
@repository.platform.reload.visibility.should == 'open'
end
end