From 4e0afce6a70aa8d2f56706ce1304104b4f136c60 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 7 Jul 2014 11:12:41 +0200 Subject: Show browse file if we are browsing file history. --- app/views/projects/commits/_commit.html.haml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index 74146b5f196..2beb7495ed2 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -7,7 +7,10 @@ - if commit.description? %a.text-expander.js-toggle-button ... - = link_to "Browse Code »", project_tree_path(project, commit), class: "pull-right" + - if @path.present? + = link_to "Browse File »", project_blob_path(project, tree_join(commit.id, @path)), class: "pull-right" + - else + = link_to "Browse Code »", project_tree_path(project, commit), class: "pull-right" .notes_count - if @note_counts - note_count = @note_counts.fetch(commit.id, 0) -- cgit v1.2.1 From de229135011c8012acf157e1e8b10e4dc443dcd4 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 7 Jul 2014 13:11:48 +0200 Subject: Check if blob is requested. --- app/views/projects/commits/_commit.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index 2beb7495ed2..106d95ee10d 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -7,7 +7,7 @@ - if commit.description? %a.text-expander.js-toggle-button ... - - if @path.present? + - if @repo.blob_at(commit.id, @path) = link_to "Browse File »", project_blob_path(project, tree_join(commit.id, @path)), class: "pull-right" - else = link_to "Browse Code »", project_tree_path(project, commit), class: "pull-right" -- cgit v1.2.1 From 5d25f3d9b12203c3010ba92d7dacfcbeaf51781e Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Tue, 8 Jul 2014 16:12:06 +0200 Subject: Differentiate between dirs, files and general code. --- app/views/projects/commits/_commit.html.haml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index 106d95ee10d..20fe2688fb4 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -7,10 +7,13 @@ - if commit.description? %a.text-expander.js-toggle-button ... - - if @repo.blob_at(commit.id, @path) + - if @repo && @repo.blob_at(commit.id, @path) = link_to "Browse File »", project_blob_path(project, tree_join(commit.id, @path)), class: "pull-right" - - else + - elsif @path.blank? = link_to "Browse Code »", project_tree_path(project, commit), class: "pull-right" + - else + = link_to "Browse Dir »", project_tree_path(project, tree_join(commit.id, @path)), class: "pull-right" + .notes_count - if @note_counts - note_count = @note_counts.fetch(commit.id, 0) -- cgit v1.2.1 From 6b121aa5a7d2a02bf758c13cb9b5ef9845700b08 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Tue, 8 Jul 2014 17:28:02 +0200 Subject: Move the links decision to helper. --- app/helpers/commits_helper.rb | 12 ++++++++++++ app/views/projects/commits/_commit.html.haml | 7 +------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index 4d27cf2851e..9643a0a965c 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -180,6 +180,18 @@ module CommitsHelper return old_lines, new_lines end + def link_to_browse_code(project, commit) + if current_controller?(:projects, :commits) + if @repo.blob_at(commit.id, @path) + link_to "Browse File »", project_blob_path(project, tree_join(commit.id, @path)), class: "pull-right" + else + link_to "Browse Dir »", project_tree_path(project, tree_join(commit.id, @path)), class: "pull-right" + end + else + link_to "Browse Code »", project_tree_path(project, commit), class: "pull-right" + end + end + protected # Private: Returns a link to a person. If the person has a matching user and diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index 20fe2688fb4..5adb6b9e3b1 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -7,12 +7,7 @@ - if commit.description? %a.text-expander.js-toggle-button ... - - if @repo && @repo.blob_at(commit.id, @path) - = link_to "Browse File »", project_blob_path(project, tree_join(commit.id, @path)), class: "pull-right" - - elsif @path.blank? - = link_to "Browse Code »", project_tree_path(project, commit), class: "pull-right" - - else - = link_to "Browse Dir »", project_tree_path(project, tree_join(commit.id, @path)), class: "pull-right" + = link_to_browse_code(project, commit) .notes_count - if @note_counts -- cgit v1.2.1 From 91e01275cb7c63e8f101c016d83f725d0e7e6cb9 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Wed, 9 Jul 2014 10:12:02 +0200 Subject: Add tests to check for correct browse link name. --- app/helpers/commits_helper.rb | 9 ++++----- features/project/source/browse_files.feature | 14 +++++++++++++- features/steps/project/browse_files.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index 9643a0a965c..7100d679358 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -183,13 +183,12 @@ module CommitsHelper def link_to_browse_code(project, commit) if current_controller?(:projects, :commits) if @repo.blob_at(commit.id, @path) - link_to "Browse File »", project_blob_path(project, tree_join(commit.id, @path)), class: "pull-right" - else - link_to "Browse Dir »", project_tree_path(project, tree_join(commit.id, @path)), class: "pull-right" + return link_to "Browse File »", project_blob_path(project, tree_join(commit.id, @path)), class: "pull-right" + elsif @path.present? + return link_to "Browse Dir »", project_tree_path(project, tree_join(commit.id, @path)), class: "pull-right" end - else - link_to "Browse Code »", project_tree_path(project, commit), class: "pull-right" end + link_to "Browse Code »", project_tree_path(project, commit), class: "pull-right" end protected diff --git a/features/project/source/browse_files.feature b/features/project/source/browse_files.feature index a204c3e10c7..4af2cc83581 100644 --- a/features/project/source/browse_files.feature +++ b/features/project/source/browse_files.feature @@ -38,4 +38,16 @@ Feature: Project Browse files And I click link "Diff" Then I see diff - + Scenario: I can browse directory with Browse Dir + Given I click on app directory + And I click on history link + Then I see Browse dir link + + Scenario: I can browse file with Browse File + Given I click on readme file + And I click on history link + Then I see Browse file link + + Scenario: I can browse code with Browse Code + Given I click on history link + Then I see Browse code link diff --git a/features/steps/project/browse_files.rb b/features/steps/project/browse_files.rb index 7cdd1101ac5..7134050da69 100644 --- a/features/steps/project/browse_files.rb +++ b/features/steps/project/browse_files.rb @@ -62,4 +62,32 @@ class ProjectBrowseFiles < Spinach::FeatureSteps page.should have_content "File name" page.should have_content "Commit message" end + + step 'I click on app directory' do + click_link 'app' + end + + step 'I click on history link' do + click_link 'history' + end + + step 'I see Browse dir link' do + page.should have_link 'Browse Dir »' + page.should_not have_link 'Browse Code »' + end + + step 'I click on readme file' do + click_link 'README.md' + end + + step 'I see Browse file link' do + page.should have_link 'Browse File »' + page.should_not have_link 'Browse Code »' + end + + step 'I see Browse code link' do + page.should have_link 'Browse Code »' + page.should_not have_link 'Browse File »' + page.should_not have_link 'Browse Dir »' + end end -- cgit v1.2.1