Commit 219ac1898095355ad9fc5c9f2ae08d9428b33090
1 parent
4e5597b8
Exists in
master
and in
4 other branches
Updated specs for post_receive worker
Showing
1 changed file
with
24 additions
and
11 deletions
Show diff stats
spec/workers/post_receive_spec.rb
| ... | ... | @@ -8,24 +8,37 @@ describe PostReceive do |
| 8 | 8 | end |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | - context "web hooks" do | |
| 12 | - let(:project) { Factory :project } | |
| 13 | - before do | |
| 14 | - @key = Factory :key, :user => project.owner | |
| 15 | - @key_id = @key.identifier | |
| 11 | + context "web hook" do | |
| 12 | + let(:project) { Factory.create(:project) } | |
| 13 | + let(:key) { Factory.create(:key, :user => project.owner) } | |
| 14 | + let(:key_id) { key.identifier } | |
| 15 | + | |
| 16 | + it "fetches the correct project" do | |
| 17 | + Project.should_receive(:find_by_path).with(project.path).and_return(project) | |
| 18 | + PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master', key_id) | |
| 16 | 19 | end |
| 17 | 20 | |
| 18 | - it "it retrieves the correct project" do | |
| 19 | - Project.should_receive(:find_by_path).with(project.path) | |
| 20 | - Key.should_receive(:find_by_identifier).with(project.path) | |
| 21 | - PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master', @key_id) | |
| 21 | + it "does not run if the author is not in the project" do | |
| 22 | + Key.stub(find_by_identifier: nil) | |
| 23 | + | |
| 24 | + project.should_not_receive(:observe_push) | |
| 25 | + project.should_not_receive(:execute_web_hooks) | |
| 26 | + | |
| 27 | + PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master', key_id).should be_false | |
| 22 | 28 | end |
| 23 | 29 | |
| 24 | 30 | it "asks the project to execute web hooks" do |
| 25 | 31 | Project.stub(find_by_path: project) |
| 26 | - project.should_receive(:execute_web_hooks).with('sha-old', 'sha-new', 'refs/heads/master', @key_id) | |
| 32 | + project.should_receive(:execute_web_hooks).with('sha-old', 'sha-new', 'refs/heads/master', key_id) | |
| 33 | + | |
| 34 | + PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master', key_id) | |
| 35 | + end | |
| 36 | + | |
| 37 | + it "asks the project to observe push/create event data" do | |
| 38 | + Project.stub(find_by_path: project) | |
| 39 | + project.should_receive(:observe_push).with('sha-old', 'sha-new', 'refs/heads/master', key_id) | |
| 27 | 40 | |
| 28 | - PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master', @key_id) | |
| 41 | + PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master', key_id) | |
| 29 | 42 | end |
| 30 | 43 | end |
| 31 | 44 | end | ... | ... |