Merge pull request #58 from warpc/47-fork_bug

Fix #47. Problem with fork when project already exist in personal repository

* Allow to add only own projects to personal repository(solution);
* Fix tests;
* Remove deprected relation.
This commit is contained in:
Vladimir Sharshov 2011-12-15 14:08:03 -08:00
commit 021f1f8691
3 changed files with 7 additions and 6 deletions

View File

@ -26,8 +26,7 @@ class PersonalRepositoriesController < ApplicationController
def add_project
if params[:project_id]
@project = Project.find(params[:project_id])
# params[:project_id] = nil
@project = current_user.own_projects.find(params[:project_id])
unless @repository.projects.find_by_name(@project.name)
@repository.projects << @project
flash[:notice] = t('flash.repository.project_added')
@ -36,13 +35,13 @@ class PersonalRepositoriesController < ApplicationController
end
redirect_to personal_repository_path(@repository)
else
@projects = Project.addable_to_repository(@repository.id).paginate(:page => params[:project_page])
@projects = current_user.own_projects.addable_to_repository(@repository.id).paginate(:page => params[:project_page])
render 'projects_list'
end
end
def remove_project
@project = Project.find(params[:project_id])
@project = current_user.own_projects.find(params[:project_id])
ProjectToRepository.where(:project_id => @project.id, :repository_id => @repository.id).destroy_all
redirect_to personal_repository_path(@repository), :notice => t('flash.repository.project_removed')
end

View File

@ -6,8 +6,6 @@ class User < ActiveRecord::Base
has_many :authentications, :dependent => :destroy
has_many :roles, :through => :targets
has_many :relations, :as => :object, :dependent => :destroy
has_many :targets, :as => :object, :class_name => 'Relation'

View File

@ -67,6 +67,8 @@ describe PersonalRepositoriesController do
before(:each) do
@admin = Factory(:admin)
set_session_for(@admin)
@project.update_attribute(:owner, @admin)
end
it_should_behave_like 'personal repository owner'
@ -87,6 +89,8 @@ describe PersonalRepositoriesController do
@user = Factory(:user)
set_session_for(@user)
@project.update_attribute(:owner, @user)
@repository.update_attribute(:owner, @user)
@repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')