public
Description: The Git TextMate Bundle
Homepage: http://tim.theenchanter.com/
Clone URL: git://github.com/timcharper/git-tmbundle.git
git-tmbundle / Support / spec / controllers / commit_controller_spec.rb
100644 122 lines (101 sloc) 4.137 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
require File.dirname(__FILE__) + '/../spec_helper'
 
describe CommitController do
  include SpecHelpers
  before(:each) do
    Git.reset_mock!
    @controller = CommitController.singleton_new
    @git = Git.singleton_new
    Git.command_response["status"] = fixture_file("status_output.txt")
  end
  
  after(:each) do
    # puts Git.commands_ran.inspect
  end
  describe "normal commit (partial commit)" do
    before(:each) do
      @message = "My commit message"
      @git.should_receive(:merge_message).and_return(nil)
      @worker = PartialCommitWorker::Normal.singleton_new(@git)
      @worker.stub!(:show_commit_dialog).and_return([@message, ["file1.txt", "file2.txt"]])
      
      @git.should_receive(:commit).
        with("My commit message", ["file1.txt", "file2.txt"], :amend => false).
        and_return(:rev => "1234567")
        
      @git.should_receive(:diff).
        with(:path => ".", :revisions => "1234567^..1234567").
        and_return( Parsers.parse_diff(fixture_file("small.diff")) )
      
      @git.branch.stub!(:current_name).and_return("master")
      @output = capture_output do
        dispatch(:controller => "commit")
      end
    end
    
    after(:each) do
      # puts Git.commands_ran.inspect
    end
    
    it "should output the commit message" do
      @output.should include(@message)
    end
    
    it "should output the diff" do
      @output.should include("No newline at end of file")
    end
  end
  
  describe "Amend commit" do
    before(:each) do
      @message = "My commit message"
      @git.should_receive(:merge_message).and_return(nil)
      @worker = PartialCommitWorker::Amend.singleton_new(@git)
      @worker.stub!(:show_commit_dialog).and_return([@message, ["file1.txt", "file2.txt"]])
      
      @git.should_receive(:commit).
        with("My commit message", ["file1.txt", "file2.txt"], :amend => true).
        and_return(:rev => "1234567")
        
      @git.should_receive(:diff).
        with(:path => ".", :revisions => "1234567^..1234567").
        and_return( Parsers.parse_diff(fixture_file("small.diff")) )
        
      @git.branch.stub!(:current_name).and_return("master")
      
      @output = capture_output do
        dispatch(:controller => "commit", :type => "amend")
      end
    end
    
    after(:each) do
      # puts Git.commands_ran.inspect
    end
    
    it "should say mention we're amending a commit" do
      @output.should include("Amending")
    end
    
    it "should output the commit message" do
      @output.should include(@message)
    end
    
    it "should output the diff" do
      @output.should include("No newline at end of file")
    end
  end
  
  describe "when in the middle of a merge" do
    it "should run the mege dialog" do
      @merge_message = "Merged some branch into another branch..."
      @git.should_receive(:merge_message).twice.and_return(@merge_message)
      output = capture_output do
        dispatch(:controller => "commit")
      end
      output.should include(@merge_message)
    end
  end
  
  describe "when running a merge commit" do
    it "should run" do
      @merge_message = "Merged some branch into another branch..."
      output = capture_output do
        dispatch(:controller => "commit", :action => "merge_commit", :message => @merge_message)
      end
      output.should include(@merge_message)
    end
    
    it "should resolve auto add/rm merged files" do
      @merge_message = "Merged"
      @git.should_receive(:status).and_return([
         {:path => "/base/file.yml", :status => {:short => "M", :long => "modified", :foreground =>"#eb6400", :background=>"#f7e1ad"}, :display=> "file.yml"},
         {:path => "/base/deleted_file.yml", :status => {:short => "G", :long => "merged", :foreground =>"#eb6400", :background=>"#f7e1ad"}, :display=> "deleted_file.yml"}
       ])
       @git.should_receive(:auto_add_rm).with(["deleted_file.yml"])
       output = capture_output do
         dispatch(:controller => "commit", :action => "merge_commit", :message => @merge_message)
       end
       output.should include(@merge_message)
    end
  end
end