Resourcified repositories for CRUD operations to prepare for multiple SCM per project (#779).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8648 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-01-15 14:23:06 +00:00
parent 6f462d373f
commit fb1a2fd7cd
68 changed files with 393 additions and 227 deletions

View File

@ -176,7 +176,6 @@ class ProjectsController < ApplicationController
@issue_category ||= IssueCategory.new
@member ||= @project.members.new
@trackers = Tracker.all
@repository ||= @project.repository
@wiki ||= @project.wiki
end

View File

@ -24,44 +24,45 @@ class InvalidRevisionParam < Exception; end
class RepositoriesController < ApplicationController
menu_item :repository
menu_item :settings, :only => :edit
menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers]
default_search_scope :changesets
before_filter :find_repository, :except => :edit
before_filter :find_project, :only => :edit
before_filter :find_project_by_project_id, :only => [:new, :create]
before_filter :check_repository_uniqueness, :only => [:new, :create]
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
before_filter :find_project_repository, :except => [:new, :create, :edit, :update, :destroy, :committers]
before_filter :authorize
accept_rss_auth :revisions
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
def new
scm = params[:repository_scm] || Redmine::Scm::Base.all.first
@repository = Repository.factory(scm)
@repository.project = @project
render :layout => !request.xhr?
end
def create
@repository = Repository.factory(params[:repository_scm], params[:repository])
@repository.project = @project
if request.post? && @repository.save
redirect_to settings_project_path(@project, :tab => 'repositories')
else
render :action => 'new'
end
end
def edit
@repository = @project.repository
if !@repository && !params[:repository_scm].blank?
@repository = Repository.factory(params[:repository_scm])
@repository.project = @project if @repository
end
if request.post? && @repository
p1 = params[:repository]
p = {}
p_extra = {}
p1.each do |k, v|
if k =~ /^extra_/
p_extra[k] = v
else
p[k] = v
end
end
@repository.attributes = p
@repository.merge_extra_info(p_extra)
@repository.save
end
render(:update) do |page|
page.replace_html "tab-content-repository",
:partial => 'projects/settings/repository'
if @repository && !@project.repository
@project.reload # needed to reload association
page.replace_html "main-menu", render_main_menu(@project)
end
end
def update
@repository.attributes = params[:repository]
@repository.project = @project
if request.put? && @repository.save
redirect_to settings_project_path(@project, :tab => 'repositories')
else
render :action => 'edit'
end
end
@ -76,16 +77,13 @@ class RepositoriesController < ApplicationController
# Build a hash with repository usernames as keys and corresponding user ids as values
@repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'committers', :id => @project
redirect_to settings_project_path(@project, :tab => 'repositories')
end
end
def destroy
@repository.destroy
redirect_to :controller => 'projects',
:action => 'settings',
:id => @project,
:tab => 'repository'
@repository.destroy if request.delete?
redirect_to settings_project_path(@project, :tab => 'repositories')
end
def show
@ -250,9 +248,23 @@ class RepositoriesController < ApplicationController
private
def find_repository
@repository = Repository.find(params[:id])
@project = @repository.project
rescue ActiveRecord::RecordNotFound
render_404
end
# TODO: remove it when multiple SCM support is added
def check_repository_uniqueness
if @project.repository
redirect_to settings_project_path(@project, :tab => 'repositories')
end
end
REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
def find_repository
def find_project_repository
@project = Project.find(params[:id])
@repository = @project.repository
(render_404; return false) unless @repository

View File

@ -30,7 +30,7 @@ module ProjectsHelper
{:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
{:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
{:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
{:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
{:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository},
{:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
{:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
]

View File

@ -139,13 +139,10 @@ module RepositoriesHelper
options_for_select(scm_options, repository.class.name.demodulize),
:disabled => (repository && !repository.new_record?),
:onchange => remote_function(
:url => {
:controller => 'repositories',
:action => 'edit',
:id => @project
},
:method => :get,
:with => "Form.serialize(this.form)")
:url => new_project_repository_path(@project),
:method => :get,
:update => 'content',
:with => "Form.serialize(this.form)")
)
end

View File

@ -48,6 +48,26 @@ class Repository < ActiveRecord::Base
super(attr_name, *args)
end
alias :attributes_without_extra_info= :attributes=
def attributes=(new_attributes, guard_protected_attributes = true)
return if new_attributes.nil?
attributes = new_attributes.dup
attributes.stringify_keys!
p = {}
p_extra = {}
attributes.each do |k, v|
if k =~ /^extra_/
p_extra[k] = v
else
p[k] = v
end
end
send :attributes_without_extra_info=, p, guard_protected_attributes
merge_extra_info(p_extra)
end
# Removes leading and trailing whitespace
def url=(arg)
write_attribute(:url, arg ? arg.to_s.strip : nil)

View File

@ -0,0 +1,36 @@
<% if @project.repository %>
<table class="list">
<thead>
<tr>
<th><%= l(:label_scm) %></th>
<th><%= l(:label_repository) %></th>
<th></th>
</tr>
</thead>
<tbody>
<% repository = @project.repository %>
<tr class="<%= cycle 'odd', 'even' %>">
<td><%=h repository.scm_name %></td>
<td><%=h repository.url %></td>
<td class="buttons">
<% if User.current.allowed_to?(:manage_repository, @project) %>
<%= link_to(l(:label_user_plural), committers_repository_path(repository),
:class => 'icon icon-user') %>
<%= link_to(l(:button_edit), edit_repository_path(repository),
:class => 'icon icon-edit') %>
<%= link_to(l(:button_delete), repository_path(repository),
:confirm => l(:text_are_you_sure),
:method => :delete,
:class => 'icon icon-del') %>
<% end %>
</td>
</tr>
</tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
<% if @project.repository.nil? && User.current.allowed_to?(:manage_repository, @project) %>
<p><%= link_to l(:label_repository_new), new_project_repository_path(@project), :class => 'icon icon-add' %></p>
<% end %>

View File

@ -0,0 +1,22 @@
<%= error_messages_for 'repository' %>
<div class="box tabular">
<p>
<%= label_tag('repository_scm', l(:label_scm)) %><%= scm_select_tag(@repository) %>
<% if @repository && ! @repository.class.scm_available %>
<br />
<em><%= content_tag 'span', l(:text_scm_command_not_available), :class => 'error' %></em>
<% end %>
</p>
<% button_disabled = true %>
<% if @repository %>
<% button_disabled = ! @repository.class.scm_available %>
<%= repository_field_tags(f, @repository)%>
<% end %>
</div>
<p>
<%= submit_tag(@repository.new_record? ? l(:button_create) : l(:button_save), :disabled => button_disabled) %>
<%= link_to l(:button_cancel), settings_project_path(@project, :tab => 'repositories') %>
</p>

View File

@ -0,0 +1,5 @@
<h2><%= l(:label_repository) %></h2>
<% labelled_form_for :repository, @repository, :url => repository_path(@path), :html => {:method => :put} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>

View File

@ -0,0 +1,5 @@
<h2><%= l(:label_repository_new) %></h2>
<% labelled_form_for :repository, @repository, :url => project_repositories_path(@project) do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>

View File

@ -1011,3 +1011,4 @@ ar:
zero: 0 قضية
one: 1 قضية
other: "%{count} قضايا"
label_repository_new: New repository

View File

@ -1009,3 +1009,4 @@ bg:
description_date_range_interval: Изберете диапазон чрез задаване на начална и крайна дати
description_date_from: Въведете начална дата
description_date_to: Въведете крайна дата
label_repository_new: New repository

View File

@ -1025,3 +1025,4 @@ bs:
zero: 0 aktivnost
one: 1 aktivnost
other: "%{count} aktivnosti"
label_repository_new: New repository

View File

@ -1013,3 +1013,4 @@ ca:
zero: 0 assumpte
one: 1 assumpte
other: "%{count} assumptes"
label_repository_new: New repository

View File

@ -1014,3 +1014,4 @@ cs:
zero: 0 Úkol
one: 1 Úkol
other: "%{count} Úkoly"
label_repository_new: New repository

View File

@ -1028,3 +1028,4 @@ da:
zero: 0 sag
one: 1 sag
other: "%{count} sager"
label_repository_new: New repository

View File

@ -1031,3 +1031,4 @@ de:
zero: 0 ticket
one: 1 ticket
other: "%{count} tickets"
label_repository_new: New repository

View File

@ -1011,3 +1011,4 @@ el:
zero: 0 Θέμα
one: 1 Θέμα
other: "%{count} Θέματα"
label_repository_new: New repository

View File

@ -1013,3 +1013,4 @@ en-GB:
zero: 0 issue
one: 1 issue
other: "%{count} issues"
label_repository_new: New repository

View File

@ -650,6 +650,7 @@ en:
label_not_contains: doesn't contain
label_day_plural: days
label_repository: Repository
label_repository_new: New repository
label_repository_plural: Repositories
label_browse: Browse
label_modification: "%{count} change"

View File

@ -1048,3 +1048,4 @@ es:
zero: 0 petición
one: 1 petición
other: "%{count} peticiones"
label_repository_new: New repository

View File

@ -1014,3 +1014,4 @@ eu:
zero: 0 zeregina
one: 1 zeregina
other: "%{count} zereginak"
label_repository_new: New repository

View File

@ -1013,3 +1013,4 @@ fa:
zero: 0 پیامد
one: 1 پیامد
other: "%{count} پیامد"
label_repository_new: New repository

View File

@ -1032,3 +1032,4 @@ fi:
zero: 0 tapahtuma
one: 1 tapahtuma
other: "%{count} tapahtumat"
label_repository_new: New repository

View File

@ -640,6 +640,7 @@ fr:
label_not_contains: ne contient pas
label_day_plural: jours
label_repository: Dépôt
label_repository_new: Nouveau dépôt
label_repository_plural: Dépôts
label_browse: Parcourir
label_modification: "%{count} modification"

View File

@ -1022,3 +1022,4 @@ gl:
zero: 0 petición
one: 1 petición
other: "%{count} peticións"
label_repository_new: New repository

View File

@ -1016,3 +1016,4 @@ he:
zero: 0 נושא
one: 1 נושא
other: "%{count} נושאים"
label_repository_new: New repository

View File

@ -1017,3 +1017,4 @@ hr:
zero: 0 predmet
one: 1 predmet
other: "%{count} predmeti"
label_repository_new: New repository

View File

@ -1030,3 +1030,4 @@
zero: 0 feladat
one: 1 feladat
other: "%{count} feladatok"
label_repository_new: New repository

View File

@ -1017,3 +1017,4 @@ id:
zero: 0 masalah
one: 1 masalah
other: "%{count} masalah"
label_repository_new: New repository

View File

@ -1012,3 +1012,4 @@ it:
zero: 0 segnalazione
one: 1 segnalazione
other: "%{count} segnalazioni"
label_repository_new: New repository

View File

@ -1041,3 +1041,4 @@ ja:
zero: 0 チケット
one: 1 チケット
other: "%{count} チケット"
label_repository_new: New repository

View File

@ -1063,3 +1063,4 @@ ko:
zero: 0 일감
one: 1 일감
other: "%{count} 일감"
label_repository_new: New repository

View File

@ -1071,3 +1071,4 @@ lt:
zero: 0 darbas
one: 1 darbas
other: "%{count} darbai"
label_repository_new: New repository

View File

@ -1005,3 +1005,4 @@ lv:
zero: 0 uzdevums
one: 1 uzdevums
other: "%{count} uzdevumi"
label_repository_new: New repository

View File

@ -1011,3 +1011,4 @@ mk:
zero: 0 Задача
one: 1 Задача
other: "%{count} Задачи"
label_repository_new: New repository

View File

@ -1011,3 +1011,4 @@ mn:
zero: 0 Асуудал
one: 1 Асуудал
other: "%{count} Асуудлууд"
label_repository_new: New repository

View File

@ -993,3 +993,4 @@ nl:
zero: 0 issue
one: 1 issue
other: "%{count} issues"
label_repository_new: New repository

View File

@ -1001,3 +1001,4 @@
zero: 0 sak
one: 1 sak
other: "%{count} saker"
label_repository_new: New repository

View File

@ -1028,3 +1028,4 @@ pl:
zero: 0 zagadnienie
one: 1 zagadnienie
other: "%{count} zagadnienia"
label_repository_new: New repository

View File

@ -1034,3 +1034,4 @@ pt-BR:
zero: 0 tarefa
one: 1 tarefa
other: "%{count} tarefas"
label_repository_new: New repository

View File

@ -1016,3 +1016,4 @@ pt:
zero: 0 tarefa
one: 1 tarefa
other: "%{count} tarefas"
label_repository_new: New repository

View File

@ -1003,3 +1003,4 @@ ro:
zero: 0 tichet
one: 1 tichet
other: "%{count} tichete"
label_repository_new: New repository

View File

@ -1124,3 +1124,4 @@ ru:
zero: 0 Задача
one: 1 Задача
other: "%{count} Задачи"
label_repository_new: New repository

View File

@ -1006,3 +1006,4 @@ sk:
zero: 0 Úloha
one: 1 Úloha
other: "%{count} Úlohy"
label_repository_new: New repository

View File

@ -1011,3 +1011,4 @@ sl:
zero: 0 zahtevek
one: 1 zahtevek
other: "%{count} zahtevki"
label_repository_new: New repository

View File

@ -1011,3 +1011,4 @@ sr-YU:
zero: 0 problem
one: 1 problem
other: "%{count} problemi"
label_repository_new: New repository

View File

@ -1012,3 +1012,4 @@ sr:
zero: 0 Проблем
one: 1 Проблем
other: "%{count} Проблеми"
label_repository_new: New repository

View File

@ -1052,3 +1052,4 @@ sv:
zero: 0 Ärende
one: 1 Ärende
other: "%{count} Ärenden"
label_repository_new: New repository

View File

@ -1008,3 +1008,4 @@ th:
zero: 0 ปัญหา
one: 1 ปัญหา
other: "%{count} ปัญหา"
label_repository_new: New repository

View File

@ -1030,3 +1030,4 @@ tr:
zero: 0 İş
one: 1 İş
other: "%{count} İşler"
label_repository_new: New repository

View File

@ -1008,3 +1008,4 @@ uk:
zero: 0 Питання
one: 1 Питання
other: "%{count} Питання"
label_repository_new: New repository

View File

@ -1062,3 +1062,4 @@ vi:
zero: 0 vấn đề
one: 1 vấn đề
other: "%{count} vấn đề"
label_repository_new: New repository

View File

@ -1091,3 +1091,4 @@
zero: 0 問題
one: 1 問題
other: "%{count} 問題清單"
label_repository_new: New repository

View File

@ -1013,3 +1013,4 @@ zh:
zero: 0 问题
one: 1 问题
other: "%{count} 问题"
label_repository_new: New repository

View File

@ -176,6 +176,8 @@ ActionController::Routing::Routes.draw do |map|
project.resources :issue_categories, :shallow => true
project.resources :documents, :shallow => true, :member => {:add_attachment => :post}
project.resources :boards
project.resources :repositories, :shallow => true, :except => [:index, :show],
:member => {:committers => [:get, :post]}
project.wiki_start_page 'wiki', :controller => 'wiki', :action => 'show', :conditions => {:method => :get}
project.wiki_index 'wiki/index', :controller => 'wiki', :action => 'index', :conditions => {:method => :get}
@ -272,16 +274,6 @@ ActionController::Routing::Routes.draw do |map|
repositories.connect 'projects/:id/repository/revision',
:action => 'revision',
:conditions => {:method => [:get, :post]}
repositories.connect 'projects/:id/repository/committers',
:action => 'committers',
:conditions => {:method => [:get, :post]}
repositories.connect 'projects/:id/repository/edit',
:action => 'edit',
:conditions => {:method => [:get, :post]}
repositories.connect 'projects/:id/repository/destroy',
:action => 'destroy',
:conditions => {:method => :post}
end
# additional routes for having the file name at the end of url

View File

@ -124,7 +124,7 @@ Redmine::AccessControl.map do |map|
end
map.project_module :repository do |map|
map.permission :manage_repository, {:repositories => [:edit, :committers, :destroy]}, :require => :member
map.permission :manage_repository, {:repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member
map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph]
map.permission :view_changesets, :repositories => [:show, :revisions, :revision]
map.permission :commit_access, {}

View File

@ -51,8 +51,8 @@ namespace :test do
(supported_scms - [:subversion, :mercurial]).each do |scm|
desc "Creates a test #{scm} repository"
task scm => :create_dir do
# system "gunzip < test/fixtures/repositories/#{scm}_repository.tar.gz | tar -xv -C tmp/test"
system "tar -xvz -C tmp/test -f test/fixtures/repositories/#{scm}_repository.tar.gz"
system "gunzip < test/fixtures/repositories/#{scm}_repository.tar.gz | tar -xv -C tmp/test"
#system "tar -xvz -C tmp/test -f test/fixtures/repositories/#{scm}_repository.tar.gz"
end
end

View File

@ -99,3 +99,7 @@ enabled_modules_025:
name: news
project_id: 2
id: 25
enabled_modules_026:
name: repository
project_id: 2
id: 26

View File

@ -37,15 +37,14 @@ class RepositoriesBazaarControllerTest < ActionController::TestCase
end
if File.directory?(REPOSITORY_PATH)
def test_get_edit
def test_get_new
@request.session[:user_id] = 1
@project.repository.destroy
xhr :get, :edit, :id => 'subproject1', :repository_scm => 'Bazaar'
get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar'
assert_response :success
assert_equal 'text/javascript', @response.content_type
assert_template 'new'
assert_kind_of Repository::Bazaar, assigns(:repository)
assert assigns(:repository).new_record?
assert_select_rjs :replace_html, 'tab-content-repository'
end
def test_browse_root
@ -157,10 +156,11 @@ class RepositoriesBazaarControllerTest < ActionController::TestCase
@request.session[:user_id] = 1 # admin
assert_equal 0, @repository.changesets.count
@repository.fetch_changesets
@project.reload
assert @repository.changesets.count > 0
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository
@ -168,26 +168,18 @@ class RepositoriesBazaarControllerTest < ActionController::TestCase
def test_destroy_invalid_repository
@request.session[:user_id] = 1 # admin
assert_equal 0, @repository.changesets.count
@repository.fetch_changesets
@project.reload
assert @repository.changesets.count > 0
get :destroy, :id => PRJ_ID
assert_response 302
@project.reload
assert_nil @project.repository
@repository = Repository::Bazaar.create(
@project.repository.destroy
@repository = Repository::Bazaar.create!(
:project => @project,
:url => "/invalid",
:log_encoding => 'UTF-8')
assert @repository
@repository.fetch_changesets
@repository.reload
assert_equal 0, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository

View File

@ -22,7 +22,7 @@ require 'repositories_controller'
class RepositoriesController; def rescue_action(e) raise e end; end
class RepositoriesControllerTest < ActionController::TestCase
fixtures :projects, :users, :roles, :members, :member_roles,
fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
:repositories, :issues, :issue_statuses, :changesets, :changes,
:issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
@ -33,6 +33,82 @@ class RepositoriesControllerTest < ActionController::TestCase
User.current = nil
end
def test_new
@request.session[:user_id] = 1
get :new, :project_id => 'subproject1'
assert_response :success
assert_template 'new'
assert_kind_of Repository::Subversion, assigns(:repository)
assert assigns(:repository).new_record?
assert_tag 'input', :attributes => {:name => 'repository[url]'}
end
# TODO: remove it when multiple SCM support is added
def test_new_with_existing_repository
@request.session[:user_id] = 1
get :new, :project_id => 'ecookbook'
assert_response 302
end
def test_create
@request.session[:user_id] = 1
assert_difference 'Repository.count' do
post :create, :project_id => 'subproject1',
:repository_scm => 'Subversion',
:repository => {:url => 'file:///test'}
end
assert_response 302
repository = Repository.first(:order => 'id DESC')
assert_kind_of Repository::Subversion, repository
assert_equal 'file:///test', repository.url
end
def test_create_with_failure
@request.session[:user_id] = 1
assert_no_difference 'Repository.count' do
post :create, :project_id => 'subproject1',
:repository_scm => 'Subversion',
:repository => {:url => 'invalid'}
end
assert_response :success
assert_template 'new'
assert_kind_of Repository::Subversion, assigns(:repository)
assert assigns(:repository).new_record?
end
def test_edit
@request.session[:user_id] = 1
get :edit, :id => 11
assert_response :success
assert_template 'edit'
assert_equal Repository.find(11), assigns(:repository)
assert_tag 'input', :attributes => {:name => 'repository[url]', :value => 'svn://localhost/test'}
end
def test_update
@request.session[:user_id] = 1
put :update, :id => 11, :repository => {:password => 'test_update'}
assert_response 302
assert_equal 'test_update', Repository.find(11).password
end
def test_update_with_failure
@request.session[:user_id] = 1
put :update, :id => 11, :repository => {:password => 'x'*260}
assert_response :success
assert_template 'edit'
assert_equal Repository.find(11), assigns(:repository)
end
def test_destroy
@request.session[:user_id] = 1
assert_difference 'Repository.count', -1 do
delete :destroy, :id => 11
end
assert_response 302
assert_nil Repository.find_by_id(11)
end
def test_revisions
get :revisions, :id => 1
assert_response :success
@ -71,7 +147,7 @@ class RepositoriesControllerTest < ActionController::TestCase
assert_equal 'image/svg+xml', @response.content_type
end
def test_committers
def test_get_committers
@request.session[:user_id] = 2
# add a commit with an unknown user
Changeset.create!(
@ -82,7 +158,7 @@ class RepositoriesControllerTest < ActionController::TestCase
:comments => 'Committed by foo.'
)
get :committers, :id => 1
get :committers, :id => 10
assert_response :success
assert_template 'committers'
@ -99,7 +175,7 @@ class RepositoriesControllerTest < ActionController::TestCase
:descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
end
def test_map_committers
def test_post_committers
@request.session[:user_id] = 2
# add a commit with an unknown user
c = Changeset.create!(
@ -110,8 +186,8 @@ class RepositoriesControllerTest < ActionController::TestCase
:comments => 'Committed by foo.'
)
assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
post :committers, :id => 1, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
assert_redirected_to '/projects/ecookbook/repository/committers'
post :committers, :id => 10, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
assert_response 302
assert_equal User.find(2), c.reload.user
end
end

View File

@ -43,15 +43,14 @@ class RepositoriesCvsControllerTest < ActionController::TestCase
end
if File.directory?(REPOSITORY_PATH)
def test_get_edit
def test_get_new
@request.session[:user_id] = 1
@project.repository.destroy
xhr :get, :edit, :id => 'subproject1', :repository_scm => 'Cvs'
get :new, :project_id => 'subproject1', :repository_scm => 'Cvs'
assert_response :success
assert_equal 'text/javascript', @response.content_type
assert_template 'new'
assert_kind_of Repository::Cvs, assigns(:repository)
assert assigns(:repository).new_record?
assert_select_rjs :replace_html, 'tab-content-repository'
end
def test_browse_root
@ -247,7 +246,9 @@ class RepositoriesCvsControllerTest < ActionController::TestCase
@project.reload
assert_equal NUM_REV, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository
@ -255,28 +256,20 @@ class RepositoriesCvsControllerTest < ActionController::TestCase
def test_destroy_invalid_repository
@request.session[:user_id] = 1 # admin
assert_equal 0, @repository.changesets.count
@repository.fetch_changesets
@project.reload
assert_equal NUM_REV, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_response 302
@project.reload
assert_nil @project.repository
@repository = Repository::Cvs.create(
@project.repository.destroy
@repository = Repository::Cvs.create!(
:project => Project.find(PRJ_ID),
:root_url => "/invalid",
:url => MODULE_NAME,
:log_encoding => 'UTF-8'
)
assert @repository
@repository.fetch_changesets
@project.reload
assert_equal 0, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository

View File

@ -39,15 +39,14 @@ class RepositoriesDarcsControllerTest < ActionController::TestCase
end
if File.directory?(REPOSITORY_PATH)
def test_get_edit
def test_get_new
@request.session[:user_id] = 1
@project.repository.destroy
xhr :get, :edit, :id => 'subproject1', :repository_scm => 'Darcs'
get :new, :project_id => 'subproject1', :repository_scm => 'Darcs'
assert_response :success
assert_equal 'text/javascript', @response.content_type
assert_template 'new'
assert_kind_of Repository::Darcs, assigns(:repository)
assert assigns(:repository).new_record?
assert_select_rjs :replace_html, 'tab-content-repository'
end
def test_browse_root
@ -130,7 +129,9 @@ class RepositoriesDarcsControllerTest < ActionController::TestCase
@project.reload
assert_equal NUM_REV, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository
@ -138,27 +139,19 @@ class RepositoriesDarcsControllerTest < ActionController::TestCase
def test_destroy_invalid_repository
@request.session[:user_id] = 1 # admin
assert_equal 0, @repository.changesets.count
@repository.fetch_changesets
@project.reload
assert_equal NUM_REV, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_response 302
@project.reload
assert_nil @project.repository
@repository = Repository::Darcs.create(
@project.repository.destroy
@repository = Repository::Darcs.create!(
:project => @project,
:url => "/invalid",
:log_encoding => 'UTF-8'
)
assert @repository
@repository.fetch_changesets
@project.reload
assert_equal 0, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository

View File

@ -41,15 +41,14 @@ class RepositoriesFilesystemControllerTest < ActionController::TestCase
end
if File.directory?(REPOSITORY_PATH)
def test_get_edit
def test_get_new
@request.session[:user_id] = 1
@project.repository.destroy
xhr :get, :edit, :id => 'subproject1', :repository_scm => 'Filesystem'
get :new, :project_id => 'subproject1', :repository_scm => 'Filesystem'
assert_response :success
assert_equal 'text/javascript', @response.content_type
assert_template 'new'
assert_kind_of Repository::Filesystem, assigns(:repository)
assert assigns(:repository).new_record?
assert_select_rjs :replace_html, 'tab-content-repository'
end
def test_browse_root
@ -126,7 +125,9 @@ class RepositoriesFilesystemControllerTest < ActionController::TestCase
def test_destroy_valid_repository
@request.session[:user_id] = 1 # admin
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository
@ -134,20 +135,16 @@ class RepositoriesFilesystemControllerTest < ActionController::TestCase
def test_destroy_invalid_repository
@request.session[:user_id] = 1 # admin
get :destroy, :id => PRJ_ID
assert_response 302
@project.reload
assert_nil @project.repository
@repository = Repository::Filesystem.create(
:project => Project.find(PRJ_ID),
@project.repository.destroy
@repository = Repository::Filesystem.create!(
:project => @project,
:url => "/invalid",
:path_encoding => ''
)
assert @repository
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository

View File

@ -58,15 +58,14 @@ class RepositoriesGitControllerTest < ActionController::TestCase
end
if File.directory?(REPOSITORY_PATH)
def test_get_edit
def test_get_new
@request.session[:user_id] = 1
@project.repository.destroy
xhr :get, :edit, :id => 'subproject1', :repository_scm => 'Git'
get :new, :project_id => 'subproject1', :repository_scm => 'Git'
assert_response :success
assert_equal 'text/javascript', @response.content_type
assert_template 'new'
assert_kind_of Repository::Git, assigns(:repository)
assert assigns(:repository).new_record?
assert_select_rjs :replace_html, 'tab-content-repository'
end
def test_browse_root
@ -424,7 +423,9 @@ class RepositoriesGitControllerTest < ActionController::TestCase
@project.reload
assert_equal NUM_REV, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository
@ -432,27 +433,19 @@ class RepositoriesGitControllerTest < ActionController::TestCase
def test_destroy_invalid_repository
@request.session[:user_id] = 1 # admin
assert_equal 0, @repository.changesets.count
@repository.fetch_changesets
@project.reload
assert_equal NUM_REV, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_response 302
@project.reload
assert_nil @project.repository
@repository = Repository::Git.create(
@project.repository.destroy
@repository = Repository::Git.create!(
:project => @project,
:url => "/invalid",
:path_encoding => 'ISO-8859-1'
)
assert @repository
@repository.fetch_changesets
@repository.reload
assert_equal 0, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository

View File

@ -60,15 +60,14 @@ class RepositoriesMercurialControllerTest < ActionController::TestCase
def test_fake; assert true end
elsif File.directory?(REPOSITORY_PATH)
def test_get_edit
def test_get_new
@request.session[:user_id] = 1
@project.repository.destroy
xhr :get, :edit, :id => 'subproject1', :repository_scm => 'Mercurial'
get :new, :project_id => 'subproject1', :repository_scm => 'Mercurial'
assert_response :success
assert_equal 'text/javascript', @response.content_type
assert_template 'new'
assert_kind_of Repository::Mercurial, assigns(:repository)
assert assigns(:repository).new_record?
assert_select_rjs :replace_html, 'tab-content-repository'
end
def test_show_root
@ -469,10 +468,11 @@ class RepositoriesMercurialControllerTest < ActionController::TestCase
@request.session[:user_id] = 1 # admin
assert_equal 0, @repository.changesets.count
@repository.fetch_changesets
@project.reload
assert_equal NUM_REV, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository
@ -480,27 +480,18 @@ class RepositoriesMercurialControllerTest < ActionController::TestCase
def test_destroy_invalid_repository
@request.session[:user_id] = 1 # admin
assert_equal 0, @repository.changesets.count
@repository.fetch_changesets
@project.reload
assert_equal NUM_REV, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_response 302
@project.reload
assert_nil @project.repository
@repository = Repository::Mercurial.create(
@project.repository.destroy
@repository = Repository::Mercurial.create!(
:project => Project.find(PRJ_ID),
:url => "/invalid",
:path_encoding => 'ISO-8859-1'
)
assert @repository
@repository.fetch_changesets
@project.reload
assert_equal 0, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository

View File

@ -38,40 +38,14 @@ class RepositoriesSubversionControllerTest < ActionController::TestCase
end
if repository_configured?('subversion')
def test_get_edit
def test_new
@request.session[:user_id] = 1
@project.repository.destroy
xhr :get, :edit, :id => 'subproject1', :repository_scm => 'Subversion'
get :new, :project_id => 'subproject1', :repository_scm => 'Subversion'
assert_response :success
assert_equal 'text/javascript', @response.content_type
assert_template 'new'
assert_kind_of Repository::Subversion, assigns(:repository)
assert assigns(:repository).new_record?
assert_select_rjs :replace_html, 'tab-content-repository'
end
def test_post_edit
@request.session[:user_id] = 1
@project.repository.destroy
assert_difference 'Repository.count' do
xhr :post, :edit, :id => 'subproject1', :repository_scm => 'Subversion', :repository => {:url => 'file:///svn/path'}
end
assert_response :success
assert_equal 'text/javascript', @response.content_type
assert_kind_of Repository::Subversion, assigns(:repository)
assert !assigns(:repository).new_record?
assert_select_rjs :replace_html, 'tab-content-repository'
end
def test_post_edit_existing_repository
@request.session[:user_id] = 1
assert_no_difference 'Repository.count' do
xhr :post, :edit, :id => 'subproject1', :repository_scm => 'Subversion', :repository => {:password => 'newpassword'}
end
assert_response :success
assert_equal 'text/javascript', @response.content_type
assert_kind_of Repository::Subversion, assigns(:repository)
assert_select_rjs :replace_html, 'tab-content-repository'
assert_equal 'newpassword', Project.find('subproject1').repository.password
end
def test_show
@ -381,10 +355,11 @@ class RepositoriesSubversionControllerTest < ActionController::TestCase
@request.session[:user_id] = 1 # admin
assert_equal 0, @repository.changesets.count
@repository.fetch_changesets
@project.reload
assert_equal NUM_REV, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository
@ -392,25 +367,16 @@ class RepositoriesSubversionControllerTest < ActionController::TestCase
def test_destroy_invalid_repository
@request.session[:user_id] = 1 # admin
assert_equal 0, @repository.changesets.count
@repository.fetch_changesets
@project.reload
assert_equal NUM_REV, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_response 302
@project.reload
assert_nil @project.repository
@repository = Repository::Subversion.create(
@project.repository.destroy
@repository = Repository::Subversion.create!(
:project => @project,
:url => "file:///invalid")
assert @repository
@repository.fetch_changesets
@project.reload
assert_equal 0, @repository.changesets.count
get :destroy, :id => PRJ_ID
assert_difference 'Repository.count', -1 do
delete :destroy, :id => @repository.id
end
assert_response 302
@project.reload
assert_nil @project.repository

View File

@ -84,13 +84,13 @@ class SysControllerTest < ActionController::TestCase
end
def test_fetch_changesets
Repository::Subversion.any_instance.expects(:fetch_changesets).returns(true)
Repository::Subversion.any_instance.expects(:fetch_changesets).twice.returns(true)
get :fetch_changesets
assert_response :success
end
def test_fetch_changesets_one_project
Repository::Subversion.any_instance.expects(:fetch_changesets).returns(true)
Repository::Subversion.any_instance.expects(:fetch_changesets).once.returns(true)
get :fetch_changesets, :id => 'ecookbook'
assert_response :success
end

View File

@ -24,19 +24,47 @@ class RoutingRepositoriesTest < ActionController::IntegrationTest
assert_equal %w[path to file.c], @path_hash[:param]
end
def test_repositories_resources
assert_routing(
{ :method => 'get',
:path => "/projects/redmine/repositories/new" },
{ :controller => 'repositories', :action => 'new', :project_id => 'redmine' }
)
assert_routing(
{ :method => 'post',
:path => "/projects/redmine/repositories" },
{ :controller => 'repositories', :action => 'create', :project_id => 'redmine' }
)
assert_routing(
{ :method => 'get',
:path => "/repositories/1/edit" },
{ :controller => 'repositories', :action => 'edit', :id => '1' }
)
assert_routing(
{ :method => 'put',
:path => "/repositories/1" },
{ :controller => 'repositories', :action => 'update', :id => '1' }
)
assert_routing(
{ :method => 'delete',
:path => "/repositories/1" },
{ :controller => 'repositories', :action => 'destroy', :id => '1' }
)
["get", "post"].each do |method|
assert_routing(
{ :method => method,
:path => "/repositories/1/committers" },
{ :controller => 'repositories', :action => 'committers', :id => '1' }
)
end
end
def test_repositories
assert_routing(
{ :method => 'get',
:path => "/projects/redmine/repository" },
{ :controller => 'repositories', :action => 'show', :id => 'redmine' }
)
["get", "post"].each do |method|
assert_routing(
{ :method => method,
:path => "/projects/redmine/repository/edit" },
{ :controller => 'repositories', :action => 'edit', :id => 'redmine' }
)
end
assert_routing(
{ :method => 'get',
:path => "/projects/redmine/repository/statistics" },