octopusci 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. data/README.markdown +132 -0
  2. data/bin/octopusci-reset-redis +26 -0
  3. data/bin/octopusci-skel +2 -7
  4. data/bin/octopusci-tentacles +2 -2
  5. data/config.ru +1 -1
  6. data/lib/octopusci.rb +3 -7
  7. data/lib/octopusci/config.rb +63 -49
  8. data/lib/octopusci/errors.rb +2 -0
  9. data/lib/octopusci/helpers.rb +16 -15
  10. data/lib/octopusci/io.rb +70 -0
  11. data/lib/octopusci/job.rb +145 -34
  12. data/lib/octopusci/job_store.rb +67 -0
  13. data/lib/octopusci/notifier.rb +7 -17
  14. data/lib/octopusci/notifier/job_complete.html.erb +76 -3
  15. data/lib/octopusci/queue.rb +14 -10
  16. data/lib/octopusci/server.rb +17 -20
  17. data/lib/octopusci/server/views/index.erb +3 -4
  18. data/lib/octopusci/server/views/job.erb +3 -3
  19. data/lib/octopusci/server/views/job_summary.erb +18 -18
  20. data/lib/octopusci/server/views/layout.erb +6 -5
  21. data/lib/octopusci/stage_locker.rb +11 -7
  22. data/lib/octopusci/version.rb +1 -1
  23. data/lib/octopusci/worker_launcher.rb +1 -1
  24. data/spec/lib/octopusci/config_spec.rb +195 -0
  25. data/spec/lib/octopusci/io_spec.rb +64 -0
  26. data/spec/lib/octopusci/job_spec.rb +122 -0
  27. data/spec/lib/octopusci/job_store_spec.rb +155 -0
  28. data/spec/lib/octopusci/notifier_spec.rb +0 -15
  29. data/spec/lib/octopusci/queue_spec.rb +122 -0
  30. data/spec/lib/octopusci/server_spec.rb +92 -1
  31. data/spec/lib/octopusci/stage_locker_spec.rb +94 -0
  32. data/spec/spec_helper.rb +8 -0
  33. metadata +39 -58
  34. data/README +0 -63
  35. data/bin/octopusci-db-migrate +0 -10
  36. data/db/migrate/0001_init.rb +0 -29
  37. data/db/migrate/0002_add_status_job.rb +0 -19
  38. data/lib/octopusci/notifier/job_complete.text.erb +0 -5
  39. data/lib/octopusci/schema.rb +0 -140
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ describe Octopusci::Job do
4
+
5
+ describe "self.run" do
6
+ it "when not overridden should raise Ocotpusci::PureVirtualMethod" do
7
+ class SomeJob < Octopusci::Job; end
8
+ expect { SomeJob.run(nil) }.to raise_error(Octopusci::PureVirtualMethod)
9
+ end
10
+ end
11
+
12
+ describe "self.failed!" do
13
+ it "should create an instance of Octopusci::JobRunFailed with the given message" do
14
+ excep_bef_mock = Octopusci::JobRunFailed.new("foo bar")
15
+ Octopusci::JobRunFailed.should_receive(:new).with("a test failure message").and_return(excep_bef_mock)
16
+ class SomeJob < Octopusci::Job; end
17
+ begin
18
+ SomeJob.failed!("a test failure message")
19
+ rescue Octopusci::JobRunFailed
20
+ end
21
+ end
22
+
23
+ it "should raise Octopusci::JobRunFailed" do
24
+ class SomeJob < Octopusci::Job; end
25
+ expect { SomeJob.failed!("a test failure message") }.to raise_error(Octopusci::JobRunFailed)
26
+ end
27
+ end
28
+
29
+ describe "self.context" do
30
+ it "should push context string onto the context stack" do
31
+ class SomeJob < Octopusci::Job; end
32
+ SomeJob.stub(:output)
33
+ SomeJob.stub(:get_recip_email)
34
+ Octopusci::Notifier.stub_chain(:job_complete, :deliver)
35
+ SomeJob.context_stack.should_receive(:push).with("commit")
36
+ SomeJob.context("commit") {}
37
+ end
38
+
39
+ it "should execute the given block" do
40
+ class SomeJob < Octopusci::Job; end
41
+ SomeJob.stub(:output)
42
+ SomeJob.stub(:get_recip_email)
43
+ Octopusci::Notifier.stub_chain(:job_complete, :deliver)
44
+ @a = mock('some_inst_var_in_block')
45
+ @a.should_receive(:foo)
46
+ SomeJob.context("commit") { @a.foo }
47
+ end
48
+
49
+ it "should pop context string off the context stack" do
50
+ class SomeJob < Octopusci::Job; end
51
+ SomeJob.stub(:output)
52
+ SomeJob.stub(:get_recip_email)
53
+ Octopusci::Notifier.stub_chain(:job_complete, :deliver)
54
+ SomeJob.context_stack.should_receive(:pop)
55
+ SomeJob.context("commit") {}
56
+ end
57
+
58
+ it "should pop context even if an exception is thrown inside the context" do
59
+ class SomeJob < Octopusci::Job; end
60
+ class FooExcep < RuntimeError; end
61
+ SomeJob.stub(:output)
62
+ SomeJob.stub(:get_recip_email)
63
+ Octopusci::Notifier.stub_chain(:job_complete, :deliver)
64
+ SomeJob.context_stack.should_receive(:pop)
65
+ begin
66
+ SomeJob.context("commit") { raise FooExcep.new('aoeuaoee') }
67
+ rescue FooExcep
68
+ end
69
+ end
70
+
71
+ it "should raise a Octopusci::JobHalted exception if the failed! method is called inside the context" do
72
+ job_rec = stub('job_record')
73
+ class SomeJob < Octopusci::Job
74
+ def self.run(job_rec)
75
+ context("commit") do
76
+ failed!("some reason")
77
+ end
78
+ end
79
+ end
80
+ SomeJob.stub(:write_exception)
81
+ SomeJob.stub(:output)
82
+ SomeJob.stub(:get_recip_email)
83
+ Octopusci::Notifier.stub_chain(:job_complete, :deliver)
84
+ expect { SomeJob.run(job_rec) }.to raise_error(Octopusci::JobHalted)
85
+ end
86
+
87
+ it "should stop execution from continuing after the failed!" do
88
+ job_rec = mock('job_record')
89
+ job_rec.should_receive(:foo)
90
+ job_rec.should_not_receive(:bar)
91
+ class SomeJob < Octopusci::Job
92
+ def self.run(job_rec)
93
+ context("commit") do
94
+ job_rec.foo
95
+ failed!("some failure")
96
+ job_rec.bar
97
+ end
98
+ end
99
+ end
100
+ SomeJob.stub(:write_exception)
101
+ SomeJob.stub(:output)
102
+ SomeJob.stub(:get_recip_email)
103
+ Octopusci::Notifier.stub_chain(:job_complete, :deliver)
104
+ begin
105
+ SomeJob.run(job_rec)
106
+ rescue Octopusci::JobHalted
107
+ end
108
+ end
109
+ end
110
+
111
+ describe "self.run_shell_cmd" do
112
+
113
+ end
114
+
115
+ describe "self.log" do
116
+
117
+ end
118
+
119
+ describe "self.perform" do
120
+
121
+ end
122
+ end
@@ -0,0 +1,155 @@
1
+ require 'spec_helper'
2
+
3
+ describe Octopusci::JobStore do
4
+
5
+ describe "#prepend" do
6
+ it "should increment the job count" do
7
+ r = mock('redis').as_null_object
8
+ Octopusci::JobStore.stub(:redis).and_return(r)
9
+ r.should_receive(:incr).with('octopusci:job_count')
10
+ Octopusci::JobStore.prepend({ "stub_job" => "foo", 'ref' => 'refs/heads/master' })
11
+ end
12
+
13
+ it "should store the job record" do
14
+ r = mock('redis').as_null_object
15
+ Octopusci::JobStore.stub(:redis).and_return(r)
16
+ r.stub(:incr).and_return(1)
17
+ Octopusci::JobStore.should_receive(:set).with(1, { "stub_job" => "foo", 'ref' => 'refs/heads/master', 'id' => 1 })
18
+ Octopusci::JobStore.prepend({ "stub_job" => "foo", 'ref' => 'refs/heads/master' })
19
+ end
20
+
21
+ it "should prepend the job id to the job ids list" do
22
+ r = mock('redis').as_null_object
23
+ Octopusci::JobStore.stub(:redis).and_return(r)
24
+ r.stub(:incr).and_return(10)
25
+ r.should_receive(:lpush).with("octopusci:jobs", 10)
26
+ Octopusci::JobStore.prepend({ "stub_job" => "foo", 'ref' => 'refs/heads/master' })
27
+ end
28
+
29
+ it "should prepend the job id to the project, branch, job ids list" do
30
+ r = mock('redis').as_null_object
31
+ Octopusci::JobStore.stub(:redis).and_return(r)
32
+ r.stub(:incr).and_return(10)
33
+ r.should_receive(:lpush).with("octopusci:foo:bar:jobs", 10)
34
+ Octopusci::JobStore.prepend({ 'repo_name' => 'foo', 'ref' => 'refs/heads/bar' })
35
+ end
36
+
37
+ it "should return the prepended jobs id" do
38
+ r = mock('redis').as_null_object
39
+ r.stub(:incr).and_return(1)
40
+ Octopusci::JobStore.stub(:redis).and_return(r)
41
+ Octopusci::JobStore.prepend({ "stub_job" => "foo", 'ref' => 'refs/heads/foo' }).should == 1
42
+ end
43
+ end
44
+
45
+ describe "#set" do
46
+ it "should store the passed job record serialized at the proper key" do
47
+ r = mock('redis')
48
+ Octopusci::JobStore.stub(:redis).and_return(r)
49
+ r.should_receive(:set).with("octopusci:jobs:1", YAML.dump({ "stub_job" => "foo"}))
50
+ Octopusci::JobStore.set(1, { "stub_job" => "foo"})
51
+ end
52
+ end
53
+
54
+ describe "#get" do
55
+ it "should get the job record using the proper key" do
56
+ r = mock('redis')
57
+ Octopusci::JobStore.stub(:redis).and_return(r)
58
+ r.should_receive(:get).with("octopusci:jobs:1")
59
+ Octopusci::JobStore.get(1)
60
+ end
61
+ end
62
+
63
+ describe "#size" do
64
+ it "should get the number of jobs in the jobs list" do
65
+ r = mock('redis')
66
+ Octopusci::JobStore.stub(:redis).and_return(r)
67
+ r.should_receive(:llen).with("octopusci:jobs").and_return(8)
68
+ Octopusci::JobStore.size
69
+ end
70
+
71
+ it "should return the number of jobs in the jobs list" do
72
+ r = mock('redis')
73
+ Octopusci::JobStore.stub(:redis).and_return(r)
74
+ r.stub(:llen).and_return(8)
75
+ Octopusci::JobStore.size.should == 8
76
+ end
77
+ end
78
+
79
+ describe "#repo_branch_size" do
80
+ it "should get the number of jobs in the list for the branch name of the given repository" do
81
+ r = mock('redis')
82
+ Octopusci::JobStore.stub(:redis).and_return(r)
83
+ r.should_receive(:llen).with("octopusci:foo:bar:jobs").and_return(8)
84
+ Octopusci::JobStore.repo_branch_size("foo", "bar")
85
+ end
86
+
87
+ it "should return the number of jbos in the list for the branch name of the given repository" do
88
+ r = mock('redis')
89
+ Octopusci::JobStore.stub(:redis).and_return(r)
90
+ r.should_receive(:llen).with("octopusci:foo:bar:jobs").and_return(8)
91
+ Octopusci::JobStore.repo_branch_size("foo", "bar").should == 8
92
+ end
93
+ end
94
+
95
+ describe "#list_job_ids" do
96
+ it "should return a list of count job ids from the first index given" do
97
+ r = mock('redis')
98
+ Octopusci::JobStore.stub(:redis).and_return(r)
99
+ Octopusci::JobStore.stub(:size).and_return(2)
100
+ r.should_receive(:lrange).with("octopusci:jobs", 0, 1)
101
+ Octopusci::JobStore.list_job_ids(0, 2)
102
+ end
103
+
104
+ it "should return a list of all job ids from the first index given if count is larger than the start index to the end of the list" do
105
+ r = mock('redis')
106
+ Octopusci::JobStore.stub(:redis).and_return(r)
107
+ Octopusci::JobStore.stub(:size).and_return(2)
108
+ r.should_receive(:lrange).with("octopusci:jobs", 0, 1)
109
+ Octopusci::JobStore.list_job_ids(0, 3423)
110
+ end
111
+ end
112
+
113
+ describe "#list_repo_branch_job_ids" do
114
+ it "should return a list of count job ids from the first index given for the provided repo and branch" do
115
+ r = mock('redis')
116
+ Octopusci::JobStore.stub(:redis).and_return(r)
117
+ Octopusci::JobStore.stub(:repo_branch_size).and_return(2)
118
+ r.should_receive(:lrange).with("octopusci:foo:bar:jobs", 0, 1)
119
+ Octopusci::JobStore.list_repo_branch_job_ids('foo', 'bar', 0, 2)
120
+ end
121
+
122
+ it "should return a list of all job ids from the first index given if count is larger than the start index to the end of the repositories branch job list" do
123
+ r = mock('redis')
124
+ Octopusci::JobStore.stub(:redis).and_return(r)
125
+ Octopusci::JobStore.stub(:repo_branch_size).and_return(2)
126
+ r.should_receive(:lrange).with("octopusci:foo:bar:jobs", 0, 1)
127
+ Octopusci::JobStore.list_repo_branch_job_ids('foo', 'bar', 0, 4232)
128
+ end
129
+ end
130
+
131
+ describe "#list" do
132
+ it "should get a list of all the job ids given starting index and a count" do
133
+ Octopusci::JobStore.stub(:list_job_ids).and_return([1, 2, 3, 4, 5])
134
+ Octopusci::JobStore.stub(:get).with(1).and_return("foo1")
135
+ Octopusci::JobStore.stub(:get).with(2).and_return("foo2")
136
+ Octopusci::JobStore.stub(:get).with(3).and_return("foo3")
137
+ Octopusci::JobStore.stub(:get).with(4).and_return("foo4")
138
+ Octopusci::JobStore.stub(:get).with(5).and_return("foo5")
139
+ Octopusci::JobStore.list(0, 5).should == ["foo1", "foo2", "foo3", "foo4", "foo5"]
140
+ end
141
+ end
142
+
143
+ describe "#list_repo_branch" do
144
+ it "should get a list of all the job ids given starting index and a count" do
145
+ Octopusci::JobStore.stub(:list_repo_branch_job_ids).and_return([1, 2, 3, 4, 5])
146
+ Octopusci::JobStore.stub(:get).with(1).and_return("foo1")
147
+ Octopusci::JobStore.stub(:get).with(2).and_return("foo2")
148
+ Octopusci::JobStore.stub(:get).with(3).and_return("foo3")
149
+ Octopusci::JobStore.stub(:get).with(4).and_return("foo4")
150
+ Octopusci::JobStore.stub(:get).with(5).and_return("foo5")
151
+ Octopusci::JobStore.list_repo_branch("foo", "bar", 0, 5).should == ["foo1", "foo2", "foo3", "foo4", "foo5"]
152
+ end
153
+ end
154
+
155
+ end
@@ -8,20 +8,5 @@ describe Octopusci::Notifier do
8
8
  end
9
9
 
10
10
  describe "#job_complete" do
11
- it "should send a multi-part email with the text version containing job status" do
12
- pending
13
- mail = Octopusci::Notifier.job_complete('joe@example.com', 'my output', 'my status').deliver()
14
-
15
- Octopusci::Notifier.deliveries.size.should == 1
16
- mail.parts[0].body.should =~ /my output/
17
- end
18
-
19
- it "should send a multi-part email with the html version containing job status" do
20
- pending
21
- mail = Octopusci::Notifier.job_complete('joe@example.com', 'my output', 'my status').deliver()
22
-
23
- Octopusci::Notifier.deliveries.size.should == 1
24
- mail.parts[1].body.should =~ /my output/
25
- end
26
11
  end
27
12
  end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Octopusci::Queueu" do
4
+ describe "#enqueue" do
5
+ it "should prepend the job to the job store if a matching job doesn't already exist" do
6
+ proj_info = { :some => 'proj_info' }
7
+ github_payload = { :some => 'github_payload' }
8
+ @mock_redis.stub(:set)
9
+ Resque.stub(:push)
10
+ Octopusci::Helpers.stub(:gh_payload_to_job_attrs).and_return({})
11
+ Octopusci::Queue.stub(:lismember).and_return(false)
12
+ Octopusci::JobStore.should_receive(:prepend)
13
+ Octopusci::Queue.enqueue('SomeTestJobKlass', 'repo-name', 'branch-name', github_payload, proj_info)
14
+ end
15
+
16
+ it "should store the github payload for the job if a matching job doesn't already exist" do
17
+ r = mock('redis')
18
+ proj_info = { :some => 'proj_info' }
19
+ github_payload = { :some => 'github_payload' }
20
+ Resque.stub(:push)
21
+ Octopusci::JobStore.stub(:prepend)
22
+ Octopusci::Queue.stub(:redis).and_return(r)
23
+ Octopusci::Helpers.stub(:gh_payload_to_job_attrs).and_return({})
24
+ Octopusci::Queue.stub(:lismember).and_return(false)
25
+ r.should_receive(:set)
26
+ Octopusci::Queue.enqueue('SomeTestJobKlass', 'repo-name', 'branch-name', github_payload, proj_info)
27
+ end
28
+
29
+ it "should enque the job in the octopusci Resque queue if a matching job doesn't already exist" do
30
+ proj_info = { :some => 'proj_info' }
31
+ github_payload = { :some => 'github_payload' }
32
+ Octopusci::JobStore.stub(:prepend)
33
+ @mock_redis.stub(:set)
34
+ Octopusci::Helpers.stub(:gh_payload_to_job_attrs).and_return({})
35
+ Octopusci::Queue.stub(:lismember).and_return(false)
36
+ Resque.should_receive(:push)
37
+ Octopusci::Queue.enqueue('SomeTestJobKlass', 'repo-name', 'branch-name', github_payload, proj_info)
38
+ end
39
+
40
+ it "should store the github payload if a matching job already exists" do
41
+ proj_info = { :some => 'proj_info' }
42
+ github_payload = { :some => 'github_payload' }
43
+ r = mock('redis')
44
+ Octopusci::JobStore.stub(:list_repo_branch).and_return([])
45
+ Octopusci::Queue.stub(:lismember).and_return(true)
46
+ Octopusci::Queue.stub(:redis).and_return(r)
47
+ r.should_receive(:set).with(Octopusci::Queue.github_payload_key('repo-name', 'branch-name'), Resque::encode(github_payload))
48
+ Octopusci::Queue.enqueue('SomeTestJobKlass', 'repo-name', 'branch-name', github_payload, proj_info)
49
+ end
50
+
51
+ it "should get the most recent job for the provided repo and branch combo if a matching job already exists" do
52
+ proj_info = { :some => 'proj_info' }
53
+ github_payload = { :some => 'github_payload' }
54
+ @mock_redis.stub(:set)
55
+ Octopusci::Queue.stub(:lismember).and_return(true)
56
+ Octopusci::JobStore.should_receive(:list_repo_branch).with('repo-name', 'branch-name', 0, 1).and_return([])
57
+ Octopusci::Queue.enqueue('SomeTestJobKlass', 'repo-name', 'branch-name', github_payload, proj_info)
58
+ end
59
+
60
+ it "should update the job record with the new data from the github payload if a matching job already exists" do
61
+ proj_info = { :some => 'proj_info' }
62
+ github_payload = { :some => 'github_payload' }
63
+ @mock_redis.stub(:set)
64
+ Octopusci::Queue.stub(:lismember).and_return(true)
65
+ Octopusci::Helpers.stub(:gh_payload_to_job_attrs).and_return(github_payload)
66
+ Octopusci::JobStore.stub(:list_repo_branch).and_return([ { 'id' => 23 }.merge(github_payload) ])
67
+ Octopusci::JobStore.should_receive(:set).with(23, { 'id' => 23 }.merge(github_payload))
68
+ Octopusci::Queue.enqueue('SomeTestJobKlass', 'repo-name', 'branch-name', github_payload, proj_info)
69
+ end
70
+
71
+ end
72
+
73
+ describe "#lismember" do
74
+ it "should get the size of the provided queue" do
75
+ @mock_redis.stub(:lrange)
76
+ Resque.should_receive(:size).with("test:queue").and_return(0)
77
+ Octopusci::Queue.lismember("test:queue", { :test => 'foo' })
78
+ end
79
+
80
+ it "should get the entire list of queued jobs" do
81
+ Resque.stub(:size).and_return(2)
82
+ Resque.should_receive(:peek).with("test:queue", 0, 2)
83
+ Octopusci::Queue.lismember("test:queue", { :test => 'foo' })
84
+ end
85
+
86
+ it "should return true if the provided item exists in the queue identified by the provided queue name" do
87
+ Resque.stub(:size).and_return(2)
88
+ Resque.stub(:peek).and_return([ { :test => 'foo' }, { :hoopty => 'bar' } ])
89
+ Octopusci::Queue.lismember("test:queue", { :hoopty => 'bar' }).should == true
90
+ end
91
+
92
+ it "should return false if the provided item does NOT exist in the queue identified by the given queue name" do
93
+ Resque.stub(:size).and_return(2)
94
+ Resque.stub(:peek).and_return([ { :test => 'foo' }, { :hoopty => 'bar' } ])
95
+ Octopusci::Queue.lismember("test:queue", { :jack => 'crack' }).should == false
96
+ end
97
+ end
98
+
99
+ describe "#github_payload" do
100
+ it "should get the currently stored github_payload for a given repository and branch" do
101
+ r = mock('redis')
102
+ r.should_receive(:get).with(Octopusci::Queue.github_payload_key('my-repo', 'my-branch')).and_return({ :my => 'git', :hub => 'payload' })
103
+ Resque.should_receive(:decode).with({ :my => 'git', :hub => 'payload' })
104
+ Octopusci::Queue.stub(:redis).and_return(r)
105
+ Octopusci::Queue.github_payload('my-repo', 'my-branch')
106
+ end
107
+
108
+ it "should return nil if there is no github_payload for a given repository and branch" do
109
+ r = mock('redis')
110
+ r.should_receive(:get).with(Octopusci::Queue.github_payload_key('my-repo', 'my-branch')).and_return(nil)
111
+ Octopusci::Queue.stub(:redis).and_return(r)
112
+ Octopusci::Queue.github_payload('my-repo', 'my-branch').should be_nil
113
+ end
114
+ end
115
+
116
+ describe "#github_payload_key" do
117
+ it "should return the key of where the github payload would be stored for a given repository and branch" do
118
+ Octopusci::Queue.github_payload_key("jackie-repo", "brown-branch").should == "octopusci:github_payload:jackie-repo:brown-branch"
119
+ end
120
+ end
121
+
122
+ end
@@ -10,6 +10,7 @@ describe "Octopusci::Server" do
10
10
  it "should parse the github payload using JSON" do
11
11
  parsed_github_payload = Octopusci::Helpers.decode(@github_test_payload)
12
12
  Octopusci::Helpers.should_receive(:decode).with(@github_test_payload).and_return(parsed_github_payload)
13
+ Octopusci::Queue.stub(:enqueue) # stub this out so test doesn't actually enqueue a job
13
14
  post '/github-build', :payload => @github_test_payload
14
15
  end
15
16
 
@@ -22,9 +23,99 @@ describe "Octopusci::Server" do
22
23
  it "should enqueue a job if the request is for a managed project" do
23
24
  test_proj_info = { 'name' => 'temp_pusc_test', 'owner' => 'cyphactor', 'job_klass' => 'MyTestJob' }
24
25
  Octopusci::Helpers.stub(:get_project_info).and_return(test_proj_info)
25
- Octopusci::Queue.should_receive(:enqueue).with(test_proj_info['job_klass'], "temp_pusci_test", "master", Octopusci::Helpers.decode(@github_test_payload))
26
+ Octopusci::Queue.should_receive(:enqueue).with(test_proj_info['job_klass'], "temp_pusci_test", "master", Octopusci::Helpers.decode(@github_test_payload), test_proj_info)
26
27
  post '/github-build', :payload => @github_test_payload
27
28
  last_response.status.should == 200
28
29
  end
29
30
  end
31
+
32
+ describe "GET /" do
33
+ it "should get the 20 most recently queued jobs" do
34
+ Octopusci::Server.any_instance.stub(:authorized?).and_return(true)
35
+ Octopusci::JobStore.should_receive(:list).with(0, 20).and_return([])
36
+ get '/'
37
+ last_response.status.should == 200
38
+ end
39
+ end
40
+
41
+ describe "GET /:repo_name/:branch_name/jobs" do
42
+ it "should get the 20 most recently queue jobs for the provided repo_name, branch_name combo" do
43
+ Octopusci::Server.any_instance.stub(:authorized?).and_return(true)
44
+ Octopusci::JobStore.should_receive(:list_repo_branch).with('foo-repo', 'bar-branch', 0, 20).and_return([])
45
+ get '/foo-repo/bar-branch/jobs'
46
+ last_response.status.should == 200
47
+ end
48
+ end
49
+
50
+ describe "job specific" do
51
+
52
+ before(:each) do
53
+ @job_id = "234"
54
+ @job = { 'id' => @job_id, 'status' => 'pending',
55
+ 'payload' => { 'repository' => { 'url' => 'http://somewhere.com' }, 'pusher' => { 'email' => 'bob@example.com' } },
56
+ 'repo_name' => 'bar', 'branch_name' => 'foo', 'created_at' => Time.now, 'started_at' => Time.now,
57
+ 'ended_at' => Time.now + 1000, 'compare' => 'http://compareurl.com', 'stage' => 'test_a', 'ref' => 'refs/heads/foo' }
58
+ end
59
+
60
+ describe "GET /jobs/:job_id" do
61
+ it "should get the job specified by :job_id" do
62
+ Octopusci::Server.any_instance.stub(:authorized?).and_return(true)
63
+ Octopusci::JobStore.should_receive(:get).with(@job_id).and_return(@job)
64
+ get "/jobs/#{@job_id}"
65
+ last_response.status.should == 200
66
+ end
67
+ end
68
+
69
+ describe "GET /jobs/:job_id/output" do
70
+ it "should get the job specified by :job_id" do
71
+ Octopusci::Server.any_instance.stub(:authorized?).and_return(true)
72
+ Octopusci::JobStore.should_receive(:get).with(@job_id).and_return(@job)
73
+ get "/jobs/#{@job_id}/output"
74
+ last_response.status.should == 200
75
+ end
76
+ end
77
+
78
+ describe "GET /jobs/:job_id/silent_output" do
79
+ it "should get the job specified by :job_id" do
80
+ Octopusci::Server.any_instance.stub(:authorized?).and_return(true)
81
+ Octopusci::JobStore.should_receive(:get).with(@job_id).and_return(@job)
82
+ get "/jobs/#{@job_id}/silent_output"
83
+ last_response.status.should == 200
84
+ end
85
+
86
+ it "should return the log output for the job identified by :job_id" do
87
+ Octopusci::Server.any_instance.stub(:authorized?).and_return(true)
88
+ Octopusci::JobStore.stub(:get).with(@job_id).and_return(@job)
89
+ Octopusci::IO.any_instance.stub(:read_all_log).and_return("log output")
90
+ get "/jobs/#{@job_id}/silent_output"
91
+ last_response.body.should == "log output"
92
+ end
93
+ end
94
+
95
+ describe "GET /jobs/:job_id/status" do
96
+ it "should get the job specified by :job_id" do
97
+ Octopusci::Server.any_instance.stub(:authorized?).and_return(true)
98
+ Octopusci::JobStore.should_receive(:get).with(@job_id).and_return(@job)
99
+ get "/jobs/#{@job_id}/status"
100
+ last_response.status.should == 200
101
+ end
102
+
103
+ it "should return the status of the current status of the job identified by :job_id" do
104
+ Octopusci::Server.any_instance.stub(:authorized?).and_return(true)
105
+ Octopusci::JobStore.stub(:get).with(@job_id).and_return(@job)
106
+ get "/jobs/#{@job_id}/status"
107
+ last_response.body.should == "pending"
108
+ end
109
+ end
110
+
111
+ describe "GET /jobs/:job_id/ajax_summary" do
112
+ it "should get the job specified by :job_id" do
113
+ Octopusci::Server.any_instance.stub(:authorized?).and_return(true)
114
+ Octopusci::JobStore.should_receive(:get).with(@job_id).and_return(@job)
115
+ get "/jobs/#{@job_id}/ajax_summary"
116
+ last_response.status.should == 200
117
+ end
118
+ end
119
+
120
+ end
30
121
  end