Commit 5f24bdb7d067df9204e08e126f43c071116089b0
1 parent
0a44ecf3
Exists in
master
and in
4 other branches
Render not found when failing to look for a commit
Showing
5 changed files
with
25 additions
and
10 deletions
Show diff stats
app/controllers/projects/network_controller.rb
| @@ -8,10 +8,6 @@ class Projects::NetworkController < Projects::ApplicationController | @@ -8,10 +8,6 @@ class Projects::NetworkController < Projects::ApplicationController | ||
| 8 | before_filter :require_non_empty_project | 8 | before_filter :require_non_empty_project |
| 9 | 9 | ||
| 10 | def show | 10 | def show |
| 11 | - if @options[:q] | ||
| 12 | - @commit = @project.repository.commit(@options[:q]) || @commit | ||
| 13 | - end | ||
| 14 | - | ||
| 15 | respond_to do |format| | 11 | respond_to do |format| |
| 16 | format.html | 12 | format.html |
| 17 | 13 |
features/project/network.feature
| @@ -34,3 +34,7 @@ Feature: Project Network Graph | @@ -34,3 +34,7 @@ Feature: Project Network Graph | ||
| 34 | Then page should not have content not cotaining "v2.1.0" | 34 | Then page should not have content not cotaining "v2.1.0" |
| 35 | When click "Show only selected branch" checkbox | 35 | When click "Show only selected branch" checkbox |
| 36 | Then page should have content not cotaining "v2.1.0" | 36 | Then page should have content not cotaining "v2.1.0" |
| 37 | + | ||
| 38 | + Scenario: I should fail to look for a commit | ||
| 39 | + When I look for a commit by ";" | ||
| 40 | + Then page status code should be 404 |
features/steps/project/project_network_graph.rb
| @@ -87,4 +87,11 @@ class ProjectNetworkGraph < Spinach::FeatureSteps | @@ -87,4 +87,11 @@ class ProjectNetworkGraph < Spinach::FeatureSteps | ||
| 87 | page.should have_content 'v2.1.0' | 87 | page.should have_content 'v2.1.0' |
| 88 | end | 88 | end |
| 89 | end | 89 | end |
| 90 | + | ||
| 91 | + When 'I look for a commit by ";"' do | ||
| 92 | + within ".content .search" do | ||
| 93 | + fill_in 'q', with: ';' | ||
| 94 | + find('button').click | ||
| 95 | + end | ||
| 96 | + end | ||
| 90 | end | 97 | end |
features/steps/shared/project.rb
| @@ -51,6 +51,10 @@ module SharedProject | @@ -51,6 +51,10 @@ module SharedProject | ||
| 51 | page.should have_content("Features:") | 51 | page.should have_content("Features:") |
| 52 | end | 52 | end |
| 53 | 53 | ||
| 54 | + Then 'page status code should be 404' do | ||
| 55 | + page.status_code.should == 404 | ||
| 56 | + end | ||
| 57 | + | ||
| 54 | def current_project | 58 | def current_project |
| 55 | @project ||= Project.first | 59 | @project ||= Project.first |
| 56 | end | 60 | end |
lib/extracts_path.rb
| @@ -94,19 +94,23 @@ module ExtractsPath | @@ -94,19 +94,23 @@ module ExtractsPath | ||
| 94 | # Automatically renders `not_found!` if a valid tree path could not be | 94 | # Automatically renders `not_found!` if a valid tree path could not be |
| 95 | # resolved (e.g., when a user inserts an invalid path or ref). | 95 | # resolved (e.g., when a user inserts an invalid path or ref). |
| 96 | def assign_ref_vars | 96 | def assign_ref_vars |
| 97 | + # assign allowed options | ||
| 98 | + allowed_options = ["filter_ref", "q"] | ||
| 99 | + @options = params.select {|key, value| allowed_options.include?(key) && !value.blank? } | ||
| 100 | + @options = HashWithIndifferentAccess.new(@options) | ||
| 101 | + | ||
| 97 | @id = get_id | 102 | @id = get_id |
| 98 | @ref, @path = extract_ref(@id) | 103 | @ref, @path = extract_ref(@id) |
| 99 | @repo = @project.repository | 104 | @repo = @project.repository |
| 100 | - @commit = @repo.commit(@ref) | 105 | + if @options[:q].blank? |
| 106 | + @commit = @repo.commit(@ref) | ||
| 107 | + else | ||
| 108 | + @commit = @repo.commit(@options[:q]) | ||
| 109 | + end | ||
| 101 | @tree = Tree.new(@repo, @commit.id, @ref, @path) | 110 | @tree = Tree.new(@repo, @commit.id, @ref, @path) |
| 102 | @hex_path = Digest::SHA1.hexdigest(@path) | 111 | @hex_path = Digest::SHA1.hexdigest(@path) |
| 103 | @logs_path = logs_file_project_ref_path(@project, @ref, @path) | 112 | @logs_path = logs_file_project_ref_path(@project, @ref, @path) |
| 104 | 113 | ||
| 105 | - # assign allowed options | ||
| 106 | - allowed_options = ["filter_ref", "q"] | ||
| 107 | - @options = params.select {|key, value| allowed_options.include?(key) && !value.blank? } | ||
| 108 | - @options = HashWithIndifferentAccess.new(@options) | ||
| 109 | - | ||
| 110 | raise InvalidPathError unless @tree.exists? | 114 | raise InvalidPathError unless @tree.exists? |
| 111 | rescue RuntimeError, NoMethodError, InvalidPathError | 115 | rescue RuntimeError, NoMethodError, InvalidPathError |
| 112 | not_found! | 116 | not_found! |