Commit ddb7399ac424222719ebfddb239abb3abac4b7eb
1 parent
3b7c2adf
Exists in
master
and in
4 other branches
Add specs for exporting commits as diff or patch
Showing
1 changed file
with
74 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,74 @@ | @@ -0,0 +1,74 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe CommitController do | ||
4 | + let(:project) { create(:project) } | ||
5 | + let(:user) { create(:user) } | ||
6 | + let(:commit) { project.last_commit_for("master") } | ||
7 | + | ||
8 | + before do | ||
9 | + sign_in(user) | ||
10 | + | ||
11 | + project.add_access(user, :read, :admin) | ||
12 | + end | ||
13 | + | ||
14 | + describe "#show" do | ||
15 | + shared_examples "export as" do |format| | ||
16 | + it "should generally work" do | ||
17 | + get :show, project_id: project.code, id: commit.id, format: format | ||
18 | + | ||
19 | + expect(response).to be_success | ||
20 | + end | ||
21 | + | ||
22 | + it "should generate it" do | ||
23 | + Commit.any_instance.should_receive(:"to_#{format}") | ||
24 | + | ||
25 | + get :show, project_id: project.code, id: commit.id, format: format | ||
26 | + end | ||
27 | + | ||
28 | + it "should render it" do | ||
29 | + get :show, project_id: project.code, id: commit.id, format: format | ||
30 | + | ||
31 | + expect(response.body).to eq(commit.send(:"to_#{format}")) | ||
32 | + end | ||
33 | + | ||
34 | + it "should not escape Html" do | ||
35 | + Commit.any_instance.stub(:"to_#{format}").and_return('HTML entities &<>" ') | ||
36 | + | ||
37 | + get :show, project_id: project.code, id: commit.id, format: format | ||
38 | + | ||
39 | + expect(response.body).to_not include('&') | ||
40 | + expect(response.body).to_not include('>') | ||
41 | + expect(response.body).to_not include('<') | ||
42 | + expect(response.body).to_not include('"') | ||
43 | + end | ||
44 | + end | ||
45 | + | ||
46 | + describe "as diff" do | ||
47 | + include_examples "export as", :diff | ||
48 | + let(:format) { :diff } | ||
49 | + | ||
50 | + it "should really only be a git diff" do | ||
51 | + get :show, project_id: project.code, id: commit.id, format: format | ||
52 | + | ||
53 | + expect(response.body).to start_with("diff --git") | ||
54 | + end | ||
55 | + end | ||
56 | + | ||
57 | + describe "as patch" do | ||
58 | + include_examples "export as", :patch | ||
59 | + let(:format) { :patch } | ||
60 | + | ||
61 | + it "should really be a git email patch" do | ||
62 | + get :show, project_id: project.code, id: commit.id, format: format | ||
63 | + | ||
64 | + expect(response.body).to start_with("From #{commit.id}") | ||
65 | + end | ||
66 | + | ||
67 | + it "should contain a git diff" do | ||
68 | + get :show, project_id: project.code, id: commit.id, format: format | ||
69 | + | ||
70 | + expect(response.body).to match(/^diff --git/) | ||
71 | + end | ||
72 | + end | ||
73 | + end | ||
74 | +end |