]> source.dussan.org Git - redmine.git/commitdiff
Repository tab is not displayed if no repository is set as the main repository (...
authorGo MAEDA <maeda@farend.jp>
Wed, 27 Jul 2022 15:35:25 +0000 (15:35 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 27 Jul 2022 15:35:25 +0000 (15:35 +0000)
Patch by Yuichi HARADA.

git-svn-id: https://svn.redmine.org/redmine/trunk@21741 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/repositories_controller.rb
lib/redmine/preparation.rb
test/functional/repositories_controller_test.rb
test/integration/lib/redmine/menu_manager_test.rb

index e6546df1e957af13b4bfcbf07ee9c2bcf2886dde..ff1230c88306aa3275ee9a72a31b84419bc052e2 100644 (file)
@@ -337,7 +337,7 @@ class RepositoriesController < ApplicationController
     if params[:repository_id].present?
       @repository = @project.repositories.find_by_identifier_param(params[:repository_id])
     else
-      @repository = @project.repository
+      @repository = @project.repository || @project.repositories.first
     end
     (render_404; return false) unless @repository
     @path = params[:path].is_a?(Array) ? params[:path].join('/') : params[:path].to_s
index d2249b03e78ac2c0c5b8d07cd7b5347addc8be7f..d006923bc94a08f5eebc3eae68383e2677abd8a1 100644 (file)
@@ -367,7 +367,7 @@ module Redmine
         menu.push :repository,
                   {:controller => 'repositories', :action => 'show',
                    :repository_id => nil, :path => nil, :rev => nil},
-                  :if => Proc.new {|p| p.repository && !p.repository.new_record?}
+                  :if => Proc.new {|p| p.repositories.any? {|r| !r.new_record?}}
         menu.push :settings, {:controller => 'projects', :action => 'settings'},
                   :last => true
       end
index 2765dd1a1cdc82ba90881e6145310a033f9de388..a68cfa641ad933da9608e6b12b6f7f28dc9018a5 100644 (file)
@@ -188,6 +188,26 @@ class RepositoriesControllerTest < Redmine::RepositoryControllerTest
     end
   end
 
+  def test_show_without_main_repository_should_display_first_repository
+    project = Project.find(1)
+    repos = project.repositories
+    repos << Repository::Subversion.create(:identifier => 'test', :url => 'svn://valid')
+    assert_equal true, repos.exists?(:is_default => true)
+
+    repos.update_all(:is_default => false)
+    repos.reload
+    assert_equal false, repos.exists?(:is_default => true)
+
+    repository = repos.first
+    @request.session[:user_id] = 2
+
+    get(:show, :params => {:id => 1})
+    assert_response :success
+    assert_select '#sidebar' do
+      assert_select 'a.repository.selected[href=?]', "/projects/#{project.identifier}/repository/#{repository.identifier_param}"
+    end
+  end
+
   def test_show_should_show_diff_button_depending_on_browse_repository_permission
     skip unless repository_configured?('subversion')
 
index 1f5a2b8b48d2b65a72d5fb4aec568dbb97ee18e8..c21d93c9ff598e7f54501770fea78069058e75d7 100644 (file)
@@ -28,7 +28,8 @@ class MenuManagerTest < Redmine::IntegrationTest
            :roles,
            :member_roles,
            :members,
-           :enabled_modules
+           :enabled_modules,
+           :repositories
 
   def test_project_menu_with_specific_locale
     get '/projects/ecookbook/issues',
@@ -80,6 +81,34 @@ class MenuManagerTest < Redmine::IntegrationTest
     end
   end
 
+  def test_project_menu_should_display_repository_tab_when_exists_repository
+    project = Project.find('ecookbook')
+    repos = project.repositories
+    assert_equal true, repos.exists?
+
+    log_user('jsmith', 'jsmith')
+
+    assert_equal true, repos.exists?(:is_default => true)
+    get '/projects/ecookbook'
+    assert_select '#main-menu' do
+      assert_select 'a.repository', :count => 1
+    end
+
+    repos.update_all(:is_default => false)
+    assert_equal false, repos.exists?(:is_default => true)
+    get '/projects/ecookbook'
+    assert_select '#main-menu' do
+      assert_select 'a.repository', :count => 1
+    end
+
+    repos.delete_all
+    assert_equal false, repos.exists?
+    get '/projects/ecookbook'
+    assert_select '#main-menu' do
+      assert_select 'a.repository', :count => 0
+    end
+  end
+
   def test_main_menu_should_select_projects_tab_on_project_list
     get '/projects'
     assert_select '#main-menu' do