diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index 4d27cf2851effc97c546b1460c887a04c29ff94a..7100d679358813c0c094899e392c3c55e1135b4b 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -180,6 +180,17 @@ 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) + 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 + end + link_to "Browse Code »", project_tree_path(project, commit), class: "pull-right" + 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 74146b5f1963288fbd8de1dfa98799c41bcbed56..5adb6b9e3b119e7132175faa321eab8b5242ed4d 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -7,7 +7,8 @@ - if commit.description? %a.text-expander.js-toggle-button ... - = link_to "Browse Code »", project_tree_path(project, commit), class: "pull-right" + = link_to_browse_code(project, commit) + .notes_count - if @note_counts - note_count = @note_counts.fetch(commit.id, 0) diff --git a/features/project/source/browse_files.feature b/features/project/source/browse_files.feature index a204c3e10c7d08105c7c833b6c273a57e2cf9b14..4af2cc83581b1041d61da1eb4ae5f951f06f761f 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 7cdd1101ac5e7d6e3d51c7097876941cbba510d3..7134050da69c123f9ec40678c748f0cc7c817032 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