BigW Consortium Gitlab

post_receive_spec.rb 1.55 KB
Newer Older
1 2 3
require 'spec_helper'

describe PostReceive do
4 5 6
  let(:changes) { "123456 789012 refs/heads/tést\n654321 210987 refs/tags/tag" }
  let(:wrongly_encoded_changes) { changes.encode("ISO-8859-1").force_encoding("UTF-8") }
  let(:base64_changes) { Base64.encode64(wrongly_encoded_changes) }
7

8 9
  context "as a resque worker" do
    it "reponds to #perform" do
10
      expect(PostReceive.new).to respond_to(:perform)
11 12 13
    end
  end

14
  context "web hook" do
15
    let(:project) { create(:project) }
16
    let(:key) { create(:key, user: project.owner) }
17
    let(:key_id) { key.shell_id }
18 19

    it "fetches the correct project" do
20
      expect(Project).to receive(:find_with_namespace).with(project.path_with_namespace).and_return(project)
21
      PostReceive.new.perform(pwd(project), key_id, base64_changes)
22
    end
23

24
    it "does not run if the author is not in the project" do
25
      allow(Key).to receive(:find_by).with(hash_including(id: anything())) { nil }
26

27
      expect(project).not_to receive(:execute_hooks)
28

29
      expect(PostReceive.new.perform(pwd(project), key_id, base64_changes)).to be_falsey
30 31
    end

32
    it "asks the project to trigger all hooks" do
33
      allow(Project).to receive(:find_with_namespace).and_return(project)
34 35
      expect(project).to receive(:execute_hooks).twice
      expect(project).to receive(:execute_services).twice
36
      expect(project).to receive(:update_merge_requests)
37

38
      PostReceive.new.perform(pwd(project), key_id, base64_changes)
39 40
    end
  end
41 42

  def pwd(project)
43
    File.join(Gitlab.config.gitlab_shell.repos_path, project.path_with_namespace)
44
  end
45
end