Commit e67574fe77dfb2ed4f6c9ed8ee96ddeef647f2ff

Authored by Dmitriy Zaporozhets
2 parents fede36f0 1101ceb3

Merge pull request #4829 from hiroponz/render-not-found-when-failing-to-look-for-commit

Render not found when failing to look for commit
app/controllers/projects/network_controller.rb
... ... @@ -8,10 +8,6 @@ class Projects::NetworkController < Projects::ApplicationController
8 8 before_filter :require_non_empty_project
9 9  
10 10 def show
11   - if @options[:q]
12   - @commit = @project.repository.commit(@options[:q]) || @commit
13   - end
14   -
15 11 respond_to do |format|
16 12 format.html
17 13  
... ...
app/views/projects/network/_head.html.haml
... ... @@ -4,7 +4,7 @@
4 4 .pull-left
5 5 = form_tag project_network_path(@project, @id), method: :get do |f|
6 6 .control-group
7   - = label_tag :filter_ref, "Show only selected ref", class: 'control-label light'
  7 + = label_tag :filter_ref, "Begin with the selected commit", class: 'control-label light'
8 8 .controls
9 9 = check_box_tag :filter_ref, 1, @options[:filter_ref]
10 10 - @options.each do |key, value|
... ... @@ -15,9 +15,9 @@
15 15 .control-group
16 16 = label_tag :search , "Looking for commit:", class: 'control-label light'
17 17 .controls
18   - = text_field_tag :q, @options[:q], placeholder: "Input SHA", class: "search-input input-xlarge"
  18 + = text_field_tag :extended_sha1, @options[:extended_sha1], placeholder: "Input an extended SHA1 syntax", class: "search-input input-xlarge"
19 19 = button_tag type: 'submit', class: 'btn vtop' do
20 20 %i.icon-search
21 21 - @options.each do |key, value|
22   - = hidden_field_tag(key, value, id: nil) unless key == "q"
  22 + = hidden_field_tag(key, value, id: nil) unless key == "extended_sha1"
23 23  
... ...
features/project/network.feature
... ... @@ -34,3 +34,7 @@ Feature: Project Network Graph
34 34 Then page should not have content not cotaining "v2.1.0"
35 35 When click "Show only selected branch" checkbox
36 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
... ... @@ -76,7 +76,7 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
76 76  
77 77 When 'I looking for a commit by SHA of "v2.1.0"' do
78 78 within ".content .search" do
79   - fill_in 'q', with: '98d6492'
  79 + fill_in 'extended_sha1', with: '98d6492'
80 80 find('button').click
81 81 end
82 82 sleep 2
... ... @@ -87,4 +87,11 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
87 87 page.should have_content 'v2.1.0'
88 88 end
89 89 end
  90 +
  91 + When 'I look for a commit by ";"' do
  92 + within ".content .search" do
  93 + fill_in 'extended_sha1', with: ';'
  94 + find('button').click
  95 + end
  96 + end
90 97 end
... ...
features/steps/shared/project.rb
... ... @@ -51,6 +51,10 @@ module SharedProject
51 51 page.should have_content("Features:")
52 52 end
53 53  
  54 + Then 'page status code should be 404' do
  55 + page.status_code.should == 404
  56 + end
  57 +
54 58 def current_project
55 59 @project ||= Project.first
56 60 end
... ...
lib/extracts_path.rb
... ... @@ -94,19 +94,23 @@ module ExtractsPath
94 94 # Automatically renders `not_found!` if a valid tree path could not be
95 95 # resolved (e.g., when a user inserts an invalid path or ref).
96 96 def assign_ref_vars
  97 + # assign allowed options
  98 + allowed_options = ["filter_ref", "extended_sha1"]
  99 + @options = params.select {|key, value| allowed_options.include?(key) && !value.blank? }
  100 + @options = HashWithIndifferentAccess.new(@options)
  101 +
97 102 @id = get_id
98 103 @ref, @path = extract_ref(@id)
99 104 @repo = @project.repository
100   - @commit = @repo.commit(@ref)
  105 + if @options[:extended_sha1].blank?
  106 + @commit = @repo.commit(@ref)
  107 + else
  108 + @commit = @repo.commit(@options[:extended_sha1])
  109 + end
101 110 @tree = Tree.new(@repo, @commit.id, @ref, @path)
102 111 @hex_path = Digest::SHA1.hexdigest(@path)
103 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 114 raise InvalidPathError unless @tree.exists?
111 115 rescue RuntimeError, NoMethodError, InvalidPathError
112 116 not_found!
... ...