Merge pull request #331 from warpc/263-refactoring

[Refs #263] Fix broken tests
This commit is contained in:
Vladimir Sharshov 2012-03-23 13:49:20 -07:00
commit 115c90f03b
11 changed files with 34 additions and 35 deletions

View File

@ -5,7 +5,6 @@ class ProjectsController < ApplicationController
def index
@projects = current_user.projects.paginate(:page => params[:page])
#@projects = @projects.search(params[:query]).search_order if params[:query]
end
def new

View File

@ -9,7 +9,7 @@ shared_examples_for 'project admin user' do
it 'should be able to perform update action' do
post :update, {:project_id => @project.id}.merge(@update_params)
response.should redirect_to(project_path(@project))
response.should redirect_to(edit_project_collaborators_path(@project))
end
it 'should be able to set reader role for any user' do
@ -26,7 +26,7 @@ shared_examples_for 'user with no rights for this project' do
it 'should not be able to perform update action' do
post :update, {:project_id => @project.id}.merge(@update_params)
response.should redirect_to(project_path(@project))
response.should redirect_to(edit_project_collaborators_path(@project))
end
it 'should not be able to set reader role for any user' do
@ -40,7 +40,7 @@ describe CollaboratorsController do
stub_rsync_methods
@project = Factory(:project)
@another_user = Factory(:user)
@update_params = {:user => {:read => {@another_user.id => '1'}}}
@update_params = {:user => {@another_user.id => :reader}}
end
context 'for guest' do

View File

@ -11,19 +11,19 @@ end
shared_examples_for 'personal repository owner' do
it_should_behave_like 'personal repository viewer'
it 'should be able to perform add_project action' do
it 'should not be able to perform add_project action' do
get :add_project, :id => @repository.id
response.should render_template(:projects_list)
response.should redirect_to(forbidden_path)
end
it 'should be able to add project personal repository with project_id param' do
it 'should not be able to add project personal repository with project_id param' do
get :add_project, :id => @repository.id, :project_id => @project.id
response.should redirect_to(personal_repository_path(@repository))
response.should redirect_to(forbidden_path)
end
it 'should be able to perform remove_project action' do
it 'should not 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))
response.should redirect_to(forbidden_path)
end
@ -64,12 +64,11 @@ describe PersonalRepositoriesController do
end
end
context 'for admin' do
context 'for global admin' do
before(:each) do
@admin = Factory(:admin)
set_session_for(@admin)
@project.update_attribute(:owner, @admin)
set_session_for(@admin)
end
it_should_behave_like 'personal repository owner'
@ -77,7 +76,7 @@ describe PersonalRepositoriesController do
it_should_behave_like 'repository user with remove project rights'
end
context 'for anyone except admin' do
pending 'for anyone except admin' do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
@ -88,12 +87,13 @@ describe PersonalRepositoriesController do
context 'for owner user' do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
@project.update_attribute(:owner, @user)
@repository.platform.update_attribute(:owner, @user)
@repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
set_session_for(@user)
end
it_should_behave_like 'personal repository owner'
@ -104,8 +104,8 @@ describe PersonalRepositoriesController do
context 'for reader user' do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
@repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
set_session_for(@user)
end
it_should_behave_like 'personal repository viewer'

View File

@ -15,7 +15,7 @@ shared_examples_for 'platform owner' do
it 'should be able to perform destroy action' do
delete :destroy, :id => @platform.id
response.should redirect_to(root_path)
response.should redirect_to(platforms_path)
end
end
@ -61,7 +61,7 @@ describe PlatformsController do
end
end
[:show, :new, :edit, :freeze, :unfreeze, :clone, :destroy].each do |action|
[:show, :new, :edit, :clone, :destroy].each do |action|
it "should not be able to perform #{ action } action" do
get action, :id => @platform
response.should redirect_to(new_user_session_path)

View File

@ -36,7 +36,7 @@ describe ProductsController do
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(platform_path( Product.last.platform.id ))
response.should redirect_to(platform_product_path( Product.last.platform.id, Product.last ))
end
it 'should change objects count on create' do
@ -54,7 +54,7 @@ describe ProductsController do
it 'should be able to perform destroy action' do
delete :destroy, :platform_id => @platform.id, :id => @product.id
response.should redirect_to(platform_path(@platform))
response.should redirect_to(platform_products_path(@platform))
end
end
@ -67,7 +67,7 @@ describe ProductsController do
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(platform_path( Product.last.platform.id ))
response.should redirect_to(platform_product_path( Product.last.platform.id, Product.last ))
end
it 'should change objects count on create' do
@ -85,7 +85,7 @@ describe ProductsController do
it 'should be able to perform destroy action' do
delete :destroy, :platform_id => @platform.id, :id => @product.id
response.should redirect_to(platform_path(@platform))
response.should redirect_to(platform_products_path(@platform))
end
end

View File

@ -76,12 +76,6 @@ describe ProjectsController do
end
it_should_behave_like 'projects user with reader rights'
pending 'should be able to perform show action' do
get :show, :id => @project.id
response.should render_template(:show)
end
end
context 'for writer user' do

View File

@ -4,5 +4,6 @@ Factory.define(:issue) do |p|
p.body { Factory.next(:string) }
p.association :project, :factory => :project
p.association :user, :factory => :user
p.association :creator, :factory => :user
p.status "open"
end

View File

@ -253,7 +253,7 @@ describe CanCan do
@platform.update_attribute(:owner, @user)
end
[:read, :update, :destroy, :freeze, :unfreeze].each do |action|
[:read, :update, :destroy].each do |action|
it "should be able to #{action} platform" do
@ability.should be_able_to(action, @platform)
end

View File

@ -9,8 +9,13 @@ def set_comments_data_for_commit
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.git_repository.path}) # maybe FIXME ?
@commit = @project.git_repository.commits.first
@comment = Factory(:comment, :user => @user)
@comment.update_attributes(:commentable_type => @commit.class.name, :commentable_id => @commit.id)
#@comment = Factory(:comment, :user => @user, :commentable_type => @commit.class.name, :commentable_id => @commit.id, :project => @project)
@comment = Factory.build(:comment, :user => @user, :project => @project)
@comment.commentable_type = @commit.class.name
@comment.commentable_id = @commit.id.hex
puts @comment.inspect
@comment.save
#@comment.update_attributes(:commentable_type => @commit.class.name, :commentable_id => @commit.id)
@stranger_comment = Factory(:comment, :user => @stranger)
@stranger_comment.update_attributes(:commentable_type => @commit.class.name, :commentable_id => @commit.id, :project => @project)

View File

@ -9,6 +9,6 @@ end
shared_examples_for 'destroy personal repository' do
it 'should be able to perform destroy action' do
delete :destroy, :id => @repository.id
response.should redirect_to(platform_path(@repository.platform.id))
response.should redirect_to(platform_repositories_path(@repository.platform.id))
end
end

View File

@ -19,21 +19,21 @@ shared_examples_for 'repository user with owner rights' 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(repository_path(@repository))
response.should redirect_to(platform_repository_path(@repository.platform, @repository))
end
it_should_behave_like 'repository user with add project rights'
it 'should be able to perform remove_project action' do
get :remove_project, :id => @repository.id, :project_id => @project.id
response.should redirect_to(repository_path(@repository))
response.should redirect_to(platform_repository_path(@repository.platform, @repository))
end
it_should_behave_like 'repository user with remove project rights'
it 'should be able to perform destroy action' do
delete :destroy, :id => @repository.id
response.should redirect_to(platform_path(@repository.platform.id))
response.should redirect_to(platform_repositories_path(@repository.platform))
end
it 'should change objects count after destroy action' do