defunkt-integrity 0.1.1

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.
@@ -0,0 +1,130 @@
1
+ require File.dirname(__FILE__) + '/../lib/integrity'
2
+ require 'spec'
3
+
4
+ module NotifierSpecHelper
5
+ def self.included(mod)
6
+ mod.before(:each) { Integrity.stub!(:config).and_return(:base_uri => "http://localhost:4567") }
7
+ end
8
+
9
+ class Integrity::Notifier::Stub < Integrity::Notifier::Base
10
+ def self.to_haml
11
+ ""
12
+ end
13
+
14
+ def deliver!
15
+ nil
16
+ end
17
+ end
18
+
19
+ def mock_build(messages={})
20
+ messages = {
21
+ :project => stub("project", :name => "Integrity", :permalink => "integrity"),
22
+ :commit_identifier => "e7e02bc669d07064cdbc7e7508a21a41e040e70d",
23
+ :short_commit_identifier => "e7e02b",
24
+ :status => :success,
25
+ :successful? => true,
26
+ :commit_message => "the commit message",
27
+ :commit_author => stub("author", :name => "Nicolás Sanguinetti"),
28
+ :commited_at => Time.mktime(2008, 07, 25, 18, 44),
29
+ :output => "the output \e[31mwith color coding\e[0m"
30
+ }.merge(messages)
31
+ @build ||= stub("build", messages)
32
+ end
33
+
34
+ def notifier_config(overrides={})
35
+ @config ||= overrides
36
+ end
37
+
38
+ def notifier
39
+ @notifier ||= stub("notifier", :method_missing => nil)
40
+ end
41
+
42
+ def the_form(locals = {})
43
+ locals = { :config => {} }.merge(locals)
44
+ require 'haml'
45
+ @form ||= Haml::Engine.new(klass.to_haml).render(self, locals)
46
+ end
47
+ end
48
+
49
+ describe "A notifier", :shared => true do
50
+ it "should have a `notify_of_build' class method" do
51
+ klass.should respond_to(:notify_of_build)
52
+ end
53
+
54
+ it "should have a `to_haml' class method" do
55
+ klass.should respond_to(:to_haml)
56
+ end
57
+ end
58
+
59
+ module DatabaseSpecHelper
60
+ def self.included(mod)
61
+ mod.before(:each) { setup_database! }
62
+ end
63
+
64
+ def setup_database!
65
+ DataMapper.setup(:default, 'sqlite3::memory:')
66
+ DataMapper.auto_migrate!
67
+ end
68
+ end
69
+
70
+ module AppSpecHelper
71
+ def self.included(mod)
72
+ require 'rspec_hpricot_matchers'
73
+ require Integrity.root / 'spec/form_field_matchers'
74
+
75
+ mod.send(:include, DatabaseSpecHelper)
76
+ mod.send(:include, RspecHpricotMatchers)
77
+ mod.send(:include, FormFieldHpricotMatchers)
78
+ end
79
+
80
+ def mock_project(messages={})
81
+ messages = {
82
+ :name => "Integrity",
83
+ :permalink => "integrity",
84
+ :new_record? => false,
85
+ :uri => "git://github.com/foca/integrity.git",
86
+ :branch => "master",
87
+ :command => "rake",
88
+ :public? => true,
89
+ :builds => [],
90
+ :config_for => {},
91
+ :build => nil,
92
+ :update_attributes => true,
93
+ :save => true,
94
+ :destroy => nil,
95
+ :errors => stub("errors", :on => nil),
96
+ :notifies? => false,
97
+ :enable_notifiers => nil,
98
+ :building? => true
99
+ }.merge(messages)
100
+
101
+ @project ||= stub("project", messages)
102
+ end
103
+
104
+ def mock_build(messages={})
105
+ messages = {
106
+ :status => :success,
107
+ :successful? => true,
108
+ :output => 'output',
109
+ :project => @project,
110
+ :commit_identifier => '9f6302002d2259c05a64767e0dedb15d280a4848',
111
+ :commit_author => mock("author",
112
+ :name => 'Nicolás Sanguinetti',
113
+ :email => 'contacto@nicolassanguinetti.info',
114
+ :full =>'Nicolás Sanguinetti <contacto@nicolassanguinetti.info>'
115
+ ),
116
+ :commited_at => Time.mktime(2008, 7, 24, 17, 15),
117
+ :commit_message => "Add Object#tap for versions of ruby that don't have it"
118
+ }.merge(messages)
119
+ messages[:short_commit_identifier] = messages[:commit_identifier][0..5]
120
+ mock('build', messages)
121
+ end
122
+
123
+ def disable_basic_auth!
124
+ Integrity.stub!(:config).and_return(:use_basic_auth => false)
125
+ end
126
+
127
+ def enable_basic_auth!
128
+ Integrity.stub!(:config).and_return(:use_basic_auth => true, :admin_username => 'user', :admin_password => 'pass')
129
+ end
130
+ end
@@ -0,0 +1,49 @@
1
+ module Sinatra
2
+ class EventContext
3
+ def params
4
+ @params ||= ParamsParser.new(@route_params.merge(@request.params)).to_hash
5
+ end
6
+
7
+ private
8
+
9
+ class ParamsParser
10
+ attr_reader :hash
11
+
12
+ def initialize(hash)
13
+ @hash = nested(hash)
14
+ end
15
+
16
+ alias :to_hash :hash
17
+
18
+ protected
19
+
20
+ def nested(hash)
21
+ hash.inject(indifferent_hash) do |par, (key,val)|
22
+ if key =~ /([^\[]+)\[([^\]]+)\](.*)/ # a[b] || a[b][c] ($1 == a, $2 == b, $3 == [c])
23
+ par[$1] ||= indifferent_hash
24
+ par[$1].merge_recursive nested("#{$2}#{$3}" => val)
25
+ else
26
+ par[key] = val
27
+ end
28
+ par
29
+ end
30
+ end
31
+
32
+ def indifferent_hash
33
+ Hash.new {|h,k| h[k.to_s] if Symbol === k}
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ class Hash
40
+ def merge_recursive(other)
41
+ update(other) do |key, old_value, new_value|
42
+ if Hash === old_value && Hash === new_value
43
+ old_value.merge_recursive(new_value)
44
+ else
45
+ new_value
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,2 @@
1
+ #build{ :class => @build.status }
2
+ = haml(:build_info, :layout => false)
@@ -0,0 +1,22 @@
1
+ %h1
2
+ Built
3
+ &= @build.short_commit_identifier
4
+ = @build.successful? ? "successfully" : "and failed"
5
+ %blockquote
6
+ %p&= @build.commit_message
7
+ %p.meta<
8
+ %span.who<
9
+ by:
10
+ &= @build.commit_author.name
11
+ |
12
+ %span.when{ :title => @build.commited_at.iso8601 }<
13
+ &= pretty_date @build.commited_at
14
+ |
15
+ %span.what<
16
+ commit:
17
+ &= @build.commit_identifier
18
+
19
+ %h2 Build Output:
20
+ %pre.output
21
+ :preserve
22
+ #{bash_color_codes h(@build.output)}
@@ -0,0 +1,22 @@
1
+ - if @projects.empty?
2
+ .blank_slate
3
+ %p None yet, huh?
4
+ %h1
5
+ Why don't you
6
+ = succeed "?" do
7
+ %a{ :href => "/new" } create your first project
8
+ - else
9
+ %ul#projects
10
+ - @projects.each do |project|
11
+ %li{ :class => cycle("even", "odd") + (project.building? ? ' building' : '') + (project.last_build ? (project.last_build.successful? ? ' success' : ' failed') : '') }
12
+ %a{ :href => project_url(project) }&= project.name
13
+ .meta
14
+ - if project.building?
15
+ Building!
16
+ - elsif project.last_build.nil?
17
+ Never built yet
18
+ - else
19
+ = "Built #{project.last_build.short_commit_identifier}"
20
+ = project.last_build.successful? ? "successfully" : "and failed"
21
+ %p#new
22
+ %a{ :href => "/new" } Add a new project
@@ -0,0 +1,391 @@
1
+ !default_fonts = "Helvetica Neue, Helvetica, Arial, sans-serif"
2
+ !nice_fonts = "Georgia, Times New Roman, serif"
3
+ !monospace_fonts = "Monaco, Deja Vu Sans Mono, Inconsolata, Consolas, monospace"
4
+
5
+ !page_bg = #e0e0e0
6
+ !content_bg = #eee
7
+ !header_bg = #fff
8
+ !text_color = #333
9
+ !light_color = #999
10
+ !title_color = #4e4e4e
11
+ !link_color = #ed1556
12
+ !link_bg = #fff
13
+ !rule_color = #c0c0c0
14
+ !watermark = #ccc
15
+ !quote_bg = #fff
16
+ !success_bg = #bbf8aa
17
+ !success_color = #337022
18
+ !failed_bg = #fba
19
+ !failed_color = #f10
20
+
21
+ html
22
+ :background-color = !page_bg
23
+
24
+ body
25
+ :font-size 100%
26
+ :font-family = !default_fonts
27
+ :color = !text_color
28
+
29
+ a
30
+ :color = !link_color
31
+ :text-decoration none
32
+ &:hover
33
+ :color = !link_bg
34
+ :background-color = !link_color
35
+
36
+ #header, #content, #footer
37
+ :width 40em
38
+ :margin 0 auto
39
+ :background = !content_bg
40
+ :padding 0 2em
41
+ :z-index 0
42
+ :position relative
43
+ :font-size 1em
44
+
45
+ #header
46
+ :background = !header_bg
47
+ h1
48
+ :font-weight bold
49
+ :font-size 1.5em
50
+ address.watermark
51
+ :position absolute
52
+ :font-weight bold
53
+ :right 3em
54
+ :top 0
55
+ :font-size .75em
56
+ :color = !watermark
57
+ a
58
+ :color = !watermark
59
+ :font-weight bold
60
+ :font-size 2em
61
+ &:hover
62
+ :background transparent
63
+ :color = !watermark - #222
64
+
65
+ #content
66
+ :padding-top 1em
67
+ :padding-bottom 2em
68
+
69
+ strong
70
+ :font-weight bold
71
+ em
72
+ :font-style italic
73
+
74
+ h1, h2, h3, h4, h5, h6
75
+ :color = !title_color
76
+ h1
77
+ :font-size 2em
78
+ :font-weight bold
79
+ :margin-bottom .75em
80
+ :padding .25em 0
81
+ :line-height 1.2
82
+ :border-bottom = 1px solid !rule_color
83
+ h2
84
+ :font-weight bold
85
+ :font-size 1.5em
86
+ :margin 1em 0 .2em
87
+ h3
88
+ :font-weight bold
89
+ :font-size 1.25em
90
+ :margin .25em 0
91
+ h4, h5, h6
92
+ :font-weight bold
93
+ :margin-top .5em
94
+
95
+ code, pre, textarea, input
96
+ :font-family = !monospace_fonts
97
+ pre
98
+ margin .5em :0
99
+ padding .5em
100
+
101
+ form
102
+ p
103
+ :margin-top 1em
104
+ :position relative
105
+ &.checkbox label
106
+ :margin-top 0 !important
107
+ input.text, textarea
108
+ :width 30em
109
+ :padding .2em .4em
110
+ :color = !title_color
111
+ :height 1.4em
112
+ label
113
+ :float left
114
+ :display block
115
+ :margin-top .5em
116
+ :width 8em
117
+ :margin-right .75em
118
+ .with_errors
119
+ label
120
+ :background red
121
+ :color white
122
+ :position relative
123
+ :top -.7em
124
+ &.required
125
+ label
126
+ :position static
127
+ :margin-right .25em
128
+ :padding 0 .2em
129
+ input, textarea
130
+ :border 2px solid #f22
131
+ :background #fee
132
+ :color = !text_color - #111
133
+ .required
134
+ label
135
+ :float none
136
+ :display block
137
+ :width auto
138
+ :position relative
139
+ :font-weight bold
140
+ :margin-top 1em
141
+ :text-indent -.65em
142
+ &:before
143
+ :content "* "
144
+ :color = !link_color
145
+ input.text
146
+ :width 25.6em
147
+ :font-size 24px
148
+ :font-weight bold
149
+ .normal
150
+ :margin-top 2em
151
+ h2.notifier label
152
+ :float none
153
+ :width auto
154
+ :margin-right 0
155
+ .warning
156
+ :font-size .5em
157
+ :font-weight normal
158
+ :color = !light_color
159
+ fieldset
160
+ :padding-bottom 1em
161
+ :margin-left 1.35em
162
+ :border-bottom = 1px solid !rule_color
163
+ :margin-bottom 1em
164
+ h3
165
+ :margin-top 1em
166
+ :margin-bottom 0
167
+ p.normal
168
+ :margin-top 1em
169
+ p label
170
+ :width 6.7em
171
+ p.submit
172
+ :margin-top 2em
173
+ &:after
174
+ :display block
175
+ :clear both
176
+ :float none
177
+ :content "."
178
+ :text-indent -9999em
179
+ :text-align left
180
+ &.destroy
181
+ :margin-top 0
182
+ button
183
+ :float none
184
+ :display inline
185
+
186
+ .blank_slate, .error
187
+ p
188
+ :position relative
189
+ :top .3em
190
+ h1
191
+ :border-width 0
192
+ :margin 0
193
+ :padding 0
194
+ button
195
+ :float none
196
+ :border 0 none
197
+ :background transparent
198
+ :display inline
199
+ :color = !link_color
200
+ :padding 0.25em 0
201
+ :margin 0
202
+ &:hover
203
+ :background = !link_color
204
+ :color = !link_bg
205
+
206
+ .error
207
+ dt
208
+ :margin
209
+ :top 1.4em
210
+ :bottom .3em
211
+ :font
212
+ :size 1.75em
213
+ :family = !nice_fonts
214
+ dd
215
+ :line-height 1.4
216
+
217
+ #projects
218
+ :margin 1em 0 2em
219
+ :border-top = 1px solid !rule_color
220
+ li
221
+ :position relative
222
+ :border-bottom = 1px solid !rule_color
223
+ &.odd
224
+ :background = !content_bg - #080808
225
+ &.building
226
+ :background transparent url(/spinner.gif) no-repeat scroll right
227
+ a
228
+ :font-size 2em
229
+ :padding .25em
230
+ :line-height 1.2
231
+ :font-weight bold
232
+ :display block
233
+ &.success
234
+ :color = !success_color
235
+ &.failed
236
+ :color = !failed_color
237
+ .meta
238
+ :position absolute
239
+ :right .6em
240
+ :top 1.5em
241
+ :font-size 0.8em
242
+ :color = !light_color
243
+ :text-align right
244
+ &.building .meta
245
+ :right 1.6em
246
+ &.success .meta
247
+ :color = !success_color
248
+ &.failed .meta
249
+ :color = !failed_color
250
+
251
+
252
+ #previous_builds
253
+ li
254
+ a
255
+ :display block
256
+ :padding .25em
257
+ :margin-bottom .25em
258
+ :border
259
+ :width 1px
260
+ :style solid
261
+ strong
262
+ :font-size 1.3em
263
+ .attribution
264
+ :font-size .9em
265
+
266
+ #projects, #previous_builds
267
+ li
268
+ &.success a
269
+ :background-color = !success_bg
270
+ :border-color = !success_bg - #222
271
+ :color = !success_color
272
+ .attribution
273
+ :color = !success_bg - #444
274
+ &:hover
275
+ :background-color = !success_bg + #222
276
+ &.failed a
277
+ :background-color = !failed_bg
278
+ :border-color = !failed_bg - #222
279
+ :color = !failed_color
280
+ .attribution
281
+ :color = !failed_bg - #444
282
+ &:hover
283
+ :background-color = !failed_bg + #222
284
+
285
+
286
+ #build, #last_build
287
+ h1, blockquote
288
+ :border
289
+ :width 0 1px
290
+ :style solid
291
+ h1
292
+ :border-top-width 1px
293
+ blockquote
294
+ :bottom-bottom-width 1px
295
+ :line-height 1.4
296
+
297
+ &.success
298
+ h1, blockquote
299
+ :background-color = !success_bg
300
+ :border-color = (!success_bg - #222) (!success_bg + #111) (!success_bg + #111) (!success_bg - #222)
301
+ h1
302
+ :color = !success_color
303
+ .meta
304
+ :color = !success_bg - #444
305
+
306
+ &.failed
307
+ h1, blockquote
308
+ :background-color = !failed_bg
309
+ :border-color = (!failed_bg - #222) (!failed_bg + #111) (!failed_bg + #111) (!failed_bg - #222)
310
+ h1
311
+ :color = !failed_color
312
+ .meta
313
+ :color = !failed_bg - #444
314
+
315
+ h1
316
+ :margin-top .5em
317
+ :margin-bottom 0
318
+ :padding .25em
319
+ :color = !success_color
320
+
321
+ blockquote
322
+ :padding .75em
323
+ :margin-bottom 2em
324
+ .meta
325
+ :margin-top 1em
326
+ :display block
327
+ :font-size .9em
328
+
329
+ pre.output
330
+ :background #111
331
+ :color #fff
332
+ :padding .5em
333
+ :overflow auto
334
+ :max-height 50em
335
+ :font-size .825em
336
+
337
+ .color30
338
+ :color #333
339
+ .color31
340
+ :color #e33
341
+ .color32
342
+ :color #3e3
343
+ .color33
344
+ :color #ee3
345
+ .color34
346
+ :color #33e
347
+ .color35
348
+ :color #e3e
349
+ .color36
350
+ :color #3ee
351
+ .color37
352
+ :color #fff
353
+
354
+ #building_marker
355
+ :position absolute
356
+ :right 2em
357
+ :top .8em
358
+ :padding
359
+ :top .2em
360
+ :bottom .2em
361
+ :right 1.2em
362
+ :background transparent url(/spinner.gif) no-repeat right
363
+ :font-weight bold
364
+
365
+ #push_url
366
+ :display block
367
+ :margin
368
+ :top 1em
369
+ :left 2em
370
+
371
+ a
372
+ &.success
373
+ :color = !success_bg
374
+ &:hover
375
+ :background-color = !success_bg
376
+ :color white
377
+ &.failed
378
+ :color = !failed_bg
379
+ &:hover
380
+ :background-color = !failed_bg
381
+ :color white
382
+
383
+ #footer
384
+ :padding 1.5em 2.5em
385
+ :border-top 1px solid #ccc
386
+ :font-size .8em
387
+ :width 50em !important
388
+ :color #666
389
+ :text-align right
390
+ strong
391
+ :font-weight bold