Commit dfeef6c22849c04ffd225a0356fd11fb8e4907f6

Authored by Dmitriy Zaporozhets
1 parent 413a310f

Fixed API file raw functionality, Fixed tree controller tests. Added BlobController specs

app/views/tree/_tree.html.haml
... ... @@ -12,30 +12,27 @@
12 12 = link_to title, '#'
13 13  
14 14 %div#tree-content-holder.tree-content-holder
15   - - if tree.is_blob?
16   - = render "tree/blob", blob: tree
17   - - else
18   - %table#tree-slider{class: "table_#{@hex_path} tree-table" }
19   - %thead
20   - %tr
21   - %th Name
22   - %th Last Update
23   - %th Last Commit
24   - %th= link_to "history", project_commits_path(@project, @id), class: "btn btn-tiny pull-right"
  15 + %table#tree-slider{class: "table_#{@hex_path} tree-table" }
  16 + %thead
  17 + %tr
  18 + %th Name
  19 + %th Last Update
  20 + %th Last Commit
  21 + %th= link_to "history", project_commits_path(@project, @id), class: "btn btn-tiny pull-right"
25 22  
26   - - if tree.up_dir?
27   - %tr.tree-item
28   - %td.tree-item-file-name
29   - = image_tag "file_empty.png", size: '16x16'
30   - = link_to "..", project_tree_path(@project, up_dir_path(tree))
31   - %td
32   - %td
33   - %td
  23 + - if tree.up_dir?
  24 + %tr.tree-item
  25 + %td.tree-item-file-name
  26 + = image_tag "file_empty.png", size: '16x16'
  27 + = link_to "..", project_tree_path(@project, up_dir_path(tree))
  28 + %td
  29 + %td
  30 + %td
34 31  
35   - = render_tree(tree)
  32 + = render_tree(tree)
36 33  
37   - - if tree.readme
38   - = render "tree/readme", readme: tree.readme
  34 + - if tree.readme
  35 + = render "tree/readme", readme: tree.readme
39 36  
40 37 %div.tree_progress
41 38  
... ...
lib/api/projects.rb
... ... @@ -493,14 +493,16 @@ module Gitlab
493 493  
494 494 ref = params[:sha]
495 495  
496   - commit = user_project.repository.commit ref
  496 + repo = user_project.repository
  497 +
  498 + commit = repo.commit(ref)
497 499 not_found! "Commit" unless commit
498 500  
499   - tree = Tree.new commit.tree, ref, params[:filepath]
500   - not_found! "File" unless tree.try(:tree)
  501 + blob = Gitlab::Git::Blob.new(repo, commit.id, ref, params[:filepath])
  502 + not_found! "File" unless blob.exists?
501 503  
502   - content_type tree.mime_type
503   - present tree.data
  504 + content_type blob.mime_type
  505 + present blob.data
504 506 end
505 507  
506 508 # Get a specific project's keys
... ...
spec/controllers/blob_controller_spec.rb 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +require 'spec_helper'
  2 +
  3 +describe BlobController do
  4 + let(:project) { create(:project_with_code) }
  5 + let(:user) { create(:user) }
  6 +
  7 + before do
  8 + sign_in(user)
  9 +
  10 + project.team << [user, :master]
  11 +
  12 + project.stub(:branches).and_return(['master', 'foo/bar/baz'])
  13 + project.stub(:tags).and_return(['v1.0.0', 'v2.0.0'])
  14 + controller.instance_variable_set(:@project, project)
  15 + end
  16 +
  17 + describe "GET show" do
  18 + render_views
  19 +
  20 + before { get :show, project_id: project.code, id: id }
  21 +
  22 + context "valid branch, valid file" do
  23 + let(:id) { 'master/README.md' }
  24 + it { should respond_with(:success) }
  25 + end
  26 +
  27 + context "valid branch, invalid file" do
  28 + let(:id) { 'master/invalid-path.rb' }
  29 + it { should respond_with(:not_found) }
  30 + end
  31 +
  32 + context "invalid branch, valid file" do
  33 + let(:id) { 'invalid-branch/README.md' }
  34 + it { should respond_with(:not_found) }
  35 + end
  36 + end
  37 +end
... ...
spec/controllers/tree_controller_spec.rb
... ... @@ -26,17 +26,17 @@ describe TreeController do
26 26 end
27 27  
28 28 context "valid branch, valid path" do
29   - let(:id) { 'master/README.md' }
  29 + let(:id) { 'master/app/' }
30 30 it { should respond_with(:success) }
31 31 end
32 32  
33 33 context "valid branch, invalid path" do
34   - let(:id) { 'master/invalid-path.rb' }
  34 + let(:id) { 'master/invalid-path/' }
35 35 it { should respond_with(:not_found) }
36 36 end
37 37  
38 38 context "invalid branch, valid path" do
39   - let(:id) { 'invalid-branch/README.md' }
  39 + let(:id) { 'invalid-branch/app/' }
40 40 it { should respond_with(:not_found) }
41 41 end
42 42 end
... ...
spec/models/commit_spec.rb
... ... @@ -38,10 +38,10 @@ describe Commit do
38 38 it { should respond_to(:message) }
39 39 it { should respond_to(:authored_date) }
40 40 it { should respond_to(:committed_date) }
  41 + it { should respond_to(:committer_email) }
  42 + it { should respond_to(:author_email) }
41 43 it { should respond_to(:parents) }
42 44 it { should respond_to(:date) }
43   - it { should respond_to(:committer) }
44   - it { should respond_to(:author) }
45 45 it { should respond_to(:diffs) }
46 46 it { should respond_to(:tree) }
47 47 it { should respond_to(:id) }
... ...