| 1 |
require File.dirname(__FILE__) + '/../spec_helper' |
| 2 |
|
| 3 |
describe RemoteController do |
| 4 |
include SpecHelpers |
| 5 |
include Parsers |
| 6 |
|
| 7 |
before(:each) do |
| 8 |
Git.reset_mock! |
| 9 |
@git = Git.singleton_new |
| 10 |
@git.config.stub!(:[]).with("git-tmbundle.log.limit").and_return(5) |
| 11 |
@git.config.stub!(:[]).with("branch.master.remote").and_return("origin") |
| 12 |
stub_current_branch(@git, :name => "refs/heads/master", :remote => "origin") |
| 13 |
@git.config |
| 14 |
end |
| 15 |
|
| 16 |
describe "fetching" do |
| 17 |
before(:each) do |
| 18 |
|
| 19 |
@git.should_receive(:log).with(:path=>".", :revisions=>["74c0fdf", "d1c6bdd"], :limit => 5, :git_path => @git.path).and_return(parse_log(fixture_file("log_with_diffs.txt"))) |
| 20 |
|
| 21 |
Git.command_response["fetch", "origin"] = fixture_file("fetch_1_5_4_3_output.txt") |
| 22 |
|
| 23 |
@output = capture_output do |
| 24 |
dispatch :controller => "remote", :action => "fetch" |
| 25 |
end |
| 26 |
end |
| 27 |
|
| 28 |
it "should use javascript to output the progress" do |
| 29 |
@output.should include("$('origin_Compressing_progress').update('Done')") |
| 30 |
end |
| 31 |
|
| 32 |
it "should output a log" do |
| 33 |
@output.should include("<h2>Log of changes fetched</h2>") |
| 34 |
@output.should include("<h2>Branch 'asdf': 74c0fdf..d1c6bdd</h2>") |
| 35 |
@output.should include("tim@email.com") |
| 36 |
end |
| 37 |
end |
| 38 |
|
| 39 |
describe "pulling" do |
| 40 |
before(:each) do |
| 41 |
|
| 42 |
@controller = RemoteController.singleton_new |
| 43 |
@git.branch.current.stub!(:merge).and_return("refs/heads/master") |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
Git.command_response["log", "-p", "791a587..4bfc230", "."] = fixture_file("log_with_diffs.txt") |
| 48 |
Git.command_response["log", "-p", "dc29d3d..05f9ad9", "."] = fixture_file("log_with_diffs.txt") |
| 49 |
Git.command_response["pull", "origin", "master"] = fixture_file("pull_1_5_4_3_output.txt") |
| 50 |
end |
| 51 |
|
| 52 |
it "should output log of changes pulled" do |
| 53 |
@output = capture_output do |
| 54 |
dispatch :controller => "remote", :action => "pull" |
| 55 |
end |
| 56 |
|
| 57 |
@output.should include("Log of changes pulled") |
| 58 |
@output.should include("Branch 'master': 791a587..4bfc230") |
| 59 |
@output.should include("Branch 'asdf': dc29d3d..05f9ad9") |
| 60 |
end |
| 61 |
|
| 62 |
it "should with_submodule_updating" do |
| 63 |
@controller.should_receive(:with_submodule_updating) |
| 64 |
capture_output { dispatch :controller => "remote", :action => "pull" } |
| 65 |
end |
| 66 |
end |
| 67 |
|
| 68 |
describe "pushing" do |
| 69 |
before(:each) do |
| 70 |
Git.command_response["push", "origin", "master"] = (fixture_file("push_1_5_4_3_output.txt")) |
| 71 |
Git.command_response["branch"] = "* master\n task" |
| 72 |
Git.command_response["log", ".", "865f920..f9ca10d"] = fixture_file("log.txt") |
| 73 |
end |
| 74 |
|
| 75 |
describe "to a server with one origin and no submodules" do |
| 76 |
before(:each) do |
| 77 |
@git.remote.stub!(:names).and_return(['origin']) |
| 78 |
@git.submodule.stub!(:all).and_return([]) |
| 79 |
@output = capture_output do |
| 80 |
dispatch :controller => "remote", :action => "push" |
| 81 |
end |
| 82 |
end |
| 83 |
|
| 84 |
it "should run all git commands" do |
| 85 |
Git.commands_ran.should == [["push", "origin", "master"], ["log", "-n", 5, "865f920..f9ca10d", "."]] |
| 86 |
end |
| 87 |
|
| 88 |
it "should output log with diffs" do |
| 89 |
|
| 90 |
@output.should include("Branch 'asdf': 865f920..f9ca10d") |
| 91 |
end |
| 92 |
|
| 93 |
it "should render the script on the top" do |
| 94 |
(Hpricot(@output) / "head / script").length.should >= 2 |
| 95 |
end |
| 96 |
end |
| 97 |
|
| 98 |
it "should push all submodules that are behind" do |
| 99 |
@behind_submodule = stub("submodule", :path => "behind", :git => stub("git", :path => "behind", :branch => stub("branch_command", :current => stub("branch", :remote_name => "origin", :name => "master", :tracking_branch_name => "master", :tracking_status => :behind)))) |
| 100 |
@ahead_submodule = stub("submodule", :path => "ahead", :git => stub("git", :path => "ahead" , :branch => stub("branch_command", :current => stub("branch", :remote_name => "origin", :name => "master", :tracking_branch_name => "master", :tracking_status => :ahead)))) |
| 101 |
@git.submodule.stub!(:all).and_return([@behind_submodule, @ahead_submodule]) |
| 102 |
|
| 103 |
@ahead_submodule.git.should_receive(:push).and_return("") |
| 104 |
@behind_submodule.git.should_not_receive(:push) |
| 105 |
|
| 106 |
@controller = RemoteController.singleton_new |
| 107 |
@controller.stub!(:display_push_output) |
| 108 |
@output = capture_output do |
| 109 |
dispatch :controller => "remote", :action => "push" |
| 110 |
end |
| 111 |
end |
| 112 |
end |
| 113 |
|
| 114 |
describe "pushing a tag" do |
| 115 |
before(:each) do |
| 116 |
@git = Git.singleton_new |
| 117 |
@git.remote.stub!(:names).and_return(["origin"]) |
| 118 |
@controller = RemoteController.singleton_new |
| 119 |
def @controller.for_each_selected_remote(options = {}, &block) |
| 120 |
yield "origin" |
| 121 |
end |
| 122 |
end |
| 123 |
|
| 124 |
it "should call run_push and then display_push_output" do |
| 125 |
@controller.should_receive(:run_push).with(@git, "origin", :tag => "mytag") |
| 126 |
@controller.should_receive(:display_push_output) |
| 127 |
@output = capture_output do |
| 128 |
dispatch(:controller => "remote", :action => "push_tag", :tag => "mytag") |
| 129 |
end |
| 130 |
end |
| 131 |
end |
| 132 |
end |