bubble-wrap 1.1.5 → 1.2.0.pre

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.
@@ -1,7 +1,7 @@
1
1
  class AppDelegate
2
2
  def application(application, didFinishLaunchingWithOptions:launchOptions)
3
3
  @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
4
- camera_controller = CameraController.alloc.initWithNibName(nil, bundle:nil)
4
+ camera_controller = CameraController.alloc.init
5
5
  @window.rootViewController = camera_controller
6
6
  @window.makeKeyAndVisible
7
7
  end
@@ -1,61 +1,46 @@
1
1
  class CameraController < UIViewController
2
+ attr_accessor :buttons
3
+
4
+ def init
5
+ super.tap do
6
+ @buttons = []
7
+ end
8
+ end
2
9
 
3
10
  def viewDidLoad
4
11
  super
5
12
 
6
- @buttons = []
13
+ self.view.addSubview(build_button("Library", :any))
14
+ self.view.addSubview(build_button("Front", :front)) if BW::Device.camera.front?
15
+ self.view.addSubview(build_button("Rear", :rear)) if BW::Device.camera.rear?
16
+ end
7
17
 
8
- @library = UIButton.buttonWithType(UIButtonTypeRoundedRect)
9
- @library.setTitle("Library", forState:UIControlStateNormal)
10
- @library.sizeToFit
11
- @library.when UIControlEventTouchUpInside do
12
- BW::Device.camera.any.picture(media_types: [:image]) do |result|
13
- image_view = UIImageView.alloc.initWithImage(result[:original_image])
14
- add_image_view(image_view)
15
- end
16
- end
17
- self.view.addSubview(@library)
18
- @buttons << @library
19
-
20
- if BW::Device.camera.front?
21
- @front = UIButton.buttonWithType(UIButtonTypeRoundedRect)
22
- @front.setTitle("Front", forState:UIControlStateNormal)
23
- @front.sizeToFit
24
- last_button = @buttons.last
25
- @front.frame = [[last_button.frame.origin.x, last_button.frame.origin.y + last_button.frame.size.height + 10], @front.frame.size]
26
- @front.when UIControlEventTouchUpInside do
27
- BW::Device.camera.front.picture(media_types: [:image]) do |result|
28
- image_view = UIImageView.alloc.initWithImage(result[:original_image])
29
- add_image_view(image_view)
30
- end
31
- end
32
- self.view.addSubview(@front)
33
- @buttons << @front
34
- end
18
+ def build_button(title, camera_method)
19
+ button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
20
+ button.setTitle(title, forState:UIControlStateNormal)
21
+ button.sizeToFit
22
+
23
+ rect = self.buttons.empty? ? CGRectMake(0, 0, 0, 0) : self.buttons.last.frame
24
+
25
+ button.frame = [[rect.origin.x, rect.origin.y + rect.size.height + 10], button.frame.size]
35
26
 
36
- if BW::Device.camera.rear?
37
- @rear = UIButton.buttonWithType(UIButtonTypeRoundedRect)
38
- @rear.setTitle("Read", forState:UIControlStateNormal)
39
- @rear.sizeToFit
40
- last_button = @buttons.last
41
- @rear.frame = [[last_button.frame.origin.x, last_button.frame.origin.y + last_button.frame.size.height + 10], @rear.frame.size]
42
- @rear.when UIControlEventTouchUpInside do
43
- BW::Device.camera.rear.picture(media_types: [:image]) do |result|
44
- image_view = UIImageView.alloc.initWithImage(result[:original_image])
45
- add_image_view(image_view)
46
- end
27
+ button.when UIControlEventTouchUpInside do
28
+ BW::Device.camera.send(camera_method).picture(media_types: [:image]) do |result|
29
+ image_view = build_image_view(result[:original_image])
30
+ self.view.addSubview(image_view)
31
+
32
+ self.buttons.each { |button| self.view.bringSubviewToFront(button) }
47
33
  end
48
- self.view.addSubview(@rear)
49
- @buttons << @rear
50
34
  end
35
+
36
+ self.buttons << button
37
+ button
51
38
  end
52
39
 
53
- def add_image_view(image_view)
54
- image_view.frame = [CGPointZero, self.view.frame.size]
40
+ def build_image_view(image)
41
+ image_view = UIImageView.alloc.initWithImage(image)
42
+ image_view.frame = [CGPointZero, self.view.frame.size]
55
43
  image_view.center = [self.view.frame.size.width / 2, self.view.frame.size.height / 2]
56
- self.view.addSubview(image_view)
57
- @buttons.each do |button|
58
- self.view.bringSubviewToFront(button)
59
- end
44
+ image_view
60
45
  end
61
46
  end
@@ -227,4 +227,28 @@ describe BubbleWrap::App do
227
227
 
228
228
  end
229
229
 
230
+ describe ".environment" do
231
+
232
+ it 'returns current application environment' do
233
+ App.environment.should.equal "test"
234
+ end
235
+
236
+ end
237
+
238
+ describe ".test? .release? .development?" do
239
+
240
+ it 'tests if current application environment is test' do
241
+ App.test?.should.equal true
242
+ end
243
+
244
+ it 'tests if current application environment is release' do
245
+ App.release?.should.equal false
246
+ end
247
+
248
+ it 'tests if current application environment is development' do
249
+ App.development?.should.equal false
250
+ end
251
+
252
+ end
253
+
230
254
  end
@@ -0,0 +1,454 @@
1
+ describe BW::UIBarButtonItem do
2
+ describe ".styled" do
3
+ describe "given an unknown style" do
4
+ it "raises an exception" do
5
+ exception = should.raise(NameError) { BW::UIBarButtonItem.styled(:unknown, "object") }
6
+ exception.message.should.equal("uninitialized constant Kernel::UIBarButtonItemStyleUnknown")
7
+ end
8
+ end
9
+
10
+ describe "given an invalid object" do
11
+ it "raises an exception" do
12
+ exception = should.raise(ArgumentError) { BW::UIBarButtonItem.styled(:plain, :object) }
13
+ exception.message.should.equal("invalid object - :object")
14
+ end
15
+ end
16
+
17
+ ###############################################################################################
18
+
19
+ describe "given a String object" do
20
+ before do
21
+ @object = "Friends"
22
+ @target = -> { true }
23
+ @subject = BW::UIBarButtonItem.styled(:plain, @object, &@target)
24
+ end
25
+
26
+ it "has the correct class" do
27
+ @subject.class.should.equal(UIBarButtonItem)
28
+ end
29
+
30
+ it "has the correct style" do
31
+ @subject.style.should.equal(UIBarButtonItemStylePlain)
32
+ end
33
+
34
+ it "has the correct title" do
35
+ @subject.title.should.equal(@object)
36
+ end
37
+
38
+ it "has the correct target" do
39
+ @subject.target.should.equal(@target)
40
+ end
41
+
42
+ it "has the correct action" do
43
+ @subject.action.should.equal(:call)
44
+ end
45
+ end
46
+
47
+ ###############################################################################################
48
+
49
+ describe "given a String object but no block" do
50
+ before do
51
+ @object = "Friends"
52
+ @subject = BW::UIBarButtonItem.styled(:plain, @object)
53
+ end
54
+
55
+ it "has the correct class" do
56
+ @subject.class.should.equal(UIBarButtonItem)
57
+ end
58
+
59
+ it "has the correct style" do
60
+ @subject.style.should.equal(UIBarButtonItemStylePlain)
61
+ end
62
+
63
+ it "has the correct title" do
64
+ @subject.title.should.equal(@object)
65
+ end
66
+
67
+ it "has the correct target" do
68
+ @subject.target.should.equal(nil)
69
+ end
70
+
71
+ it "has the correct action" do
72
+ @subject.target.should.equal(nil)
73
+ end
74
+ end
75
+
76
+ ###############################################################################################
77
+
78
+ describe "given an UIImage object" do
79
+ before do
80
+ @object = UIImage.alloc.init
81
+ @target = -> { true }
82
+ @subject = BW::UIBarButtonItem.styled(:bordered, @object, &@target)
83
+ end
84
+
85
+ it "has the correct class" do
86
+ @subject.class.should.equal(UIBarButtonItem)
87
+ end
88
+
89
+ it "has the correct style" do
90
+ @subject.style.should.equal(UIBarButtonItemStyleBordered)
91
+ end
92
+
93
+ it "has the correct image" do
94
+ @subject.image.should.equal(@object)
95
+ end
96
+
97
+ it "has the correct target" do
98
+ @subject.target.should.equal(@target)
99
+ end
100
+
101
+ it "has the correct action" do
102
+ @subject.action.should.equal(:call)
103
+ end
104
+ end
105
+
106
+ ###############################################################################################
107
+
108
+ describe "given two UIImage objects" do
109
+ before do
110
+ @object1 = UIImage.alloc.init
111
+ @object2 = UIImage.alloc.init
112
+ @target = -> { true }
113
+ @subject = BW::UIBarButtonItem.styled(:done, @object1, @object2, &@target)
114
+ end
115
+
116
+ it "has the correct class" do
117
+ @subject.class.should.equal(UIBarButtonItem)
118
+ end
119
+
120
+ it "has the correct style" do
121
+ @subject.style.should.equal(UIBarButtonItemStyleDone)
122
+ end
123
+
124
+ it "has the correct image" do
125
+ @subject.image.should.equal(@object1)
126
+ end
127
+
128
+ it "has the correct iPhone landscape image" do
129
+ @subject.landscapeImagePhone.should.equal(@object2)
130
+ end
131
+
132
+ it "has the correct target" do
133
+ @subject.target.should.equal(@target)
134
+ end
135
+
136
+ it "has the correct action" do
137
+ @subject.action.should.equal(:call)
138
+ end
139
+ end
140
+ end
141
+
142
+ #################################################################################################
143
+
144
+ describe ".system" do
145
+ describe "given an unknown system item" do
146
+ it "raises an exception" do
147
+ exception = should.raise(NameError) { BW::UIBarButtonItem.system(:unknown) }
148
+ exception.message.should.equal("uninitialized constant Kernel::UIBarButtonSystemItemUnknown")
149
+ end
150
+ end
151
+
152
+ ###############################################################################################
153
+
154
+ describe "given a system item" do
155
+ before do
156
+ @target = -> { true }
157
+ @subject = BW::UIBarButtonItem.system(:save, &@target)
158
+ end
159
+
160
+ it "has the correct class" do
161
+ @subject.class.should.equal(UIBarButtonItem)
162
+ end
163
+
164
+ it "has the correct system item" do
165
+ # TIP: systemItem is an undocumented property
166
+ @subject.systemItem.should.equal(UIBarButtonSystemItemSave)
167
+ end
168
+
169
+ it "has the correct target" do
170
+ @subject.target.should.equal(@target)
171
+ end
172
+
173
+ it "has the correct action" do
174
+ @subject.action.should.equal(:call)
175
+ end
176
+ end
177
+
178
+ ###############################################################################################
179
+
180
+ describe "given a system item but no block" do
181
+ before do
182
+ @subject = BW::UIBarButtonItem.system(:save)
183
+ end
184
+
185
+ it "has the correct class" do
186
+ @subject.class.should.equal(UIBarButtonItem)
187
+ end
188
+
189
+ it "has the correct system item" do
190
+ @subject.systemItem.should.equal(UIBarButtonSystemItemSave)
191
+ end
192
+
193
+ it "has the correct target" do
194
+ @subject.target.should.equal(nil)
195
+ end
196
+
197
+ it "has the correct action" do
198
+ @subject.action.should.equal(nil)
199
+ end
200
+ end
201
+ end
202
+
203
+ #################################################################################################
204
+
205
+ describe ".custom" do
206
+ describe "given a custom view" do
207
+ before do
208
+ @view = UIView.alloc.init
209
+ @target = -> { true }
210
+ @subject = BW::UIBarButtonItem.custom(@view, &@target)
211
+ end
212
+
213
+ it "has the correct class" do
214
+ @subject.class.should.equal(UIBarButtonItem)
215
+ end
216
+
217
+ it "has a custom view" do
218
+ @subject.customView.should.equal(@view)
219
+ end
220
+
221
+ it "adds one, single tap gesture recognizer to the custom view" do
222
+ @view.gestureRecognizers.size.should.equal(1)
223
+ @view.gestureRecognizers.first.class.should.equal(UITapGestureRecognizer)
224
+ @view.gestureRecognizers.first.numberOfTapsRequired.should.equal(1)
225
+ end
226
+ end
227
+
228
+ ###############################################################################################
229
+
230
+ describe "given a custom view but no block" do
231
+ before do
232
+ @view = UIView.alloc.init
233
+ @subject = BW::UIBarButtonItem.custom(@view)
234
+ end
235
+
236
+ it "has the correct class" do
237
+ @subject.class.should.equal(UIBarButtonItem)
238
+ end
239
+
240
+ it "has a custom view" do
241
+ @subject.customView.should.equal(@view)
242
+ end
243
+
244
+ it "adds no gesture recognizers to the custom view" do
245
+ @view.gestureRecognizers.should.equal(nil)
246
+ end
247
+ end
248
+ end
249
+
250
+ #################################################################################################
251
+
252
+ describe ".build" do
253
+ describe "not given options" do
254
+ it "raises an exception" do
255
+ exception = should.raise(ArgumentError) { BW::UIBarButtonItem.build }
256
+ exception.message.should.equal("invalid options - {}")
257
+ end
258
+ end
259
+
260
+ describe "given unknown options" do
261
+ it "raises an exception" do
262
+ exception = should.raise(ArgumentError) { BW::UIBarButtonItem.build(:unknown => true) }
263
+ exception.message.should.equal("invalid options - {:unknown=>true}")
264
+ end
265
+ end
266
+
267
+ describe "given incompatible options for a styled item" do
268
+ before do
269
+ @options = {
270
+ :styled => :bordered,
271
+ :title => "Friends",
272
+ :image => UIImage.alloc.init
273
+ }
274
+ end
275
+
276
+ it "raises an exception" do
277
+ exception = should.raise(ArgumentError) { BW::UIBarButtonItem.build(@options) }
278
+ exception.message.should.equal("invalid object - #{@options.values_at(:title, :image)}")
279
+ end
280
+ end
281
+
282
+ ###############################################################################################
283
+
284
+ describe "given options for a styled item with a title" do
285
+ before do
286
+ @options = { :styled => :plain, :title => "Friends" }
287
+ @target = -> { true }
288
+ @subject = BW::UIBarButtonItem.build(@options, &@target)
289
+ end
290
+
291
+ it "has the correct class" do
292
+ @subject.class.should.equal(UIBarButtonItem)
293
+ end
294
+
295
+ it "has the correct style" do
296
+ @subject.style.should.equal(UIBarButtonItemStylePlain)
297
+ end
298
+
299
+ it "has the correct title" do
300
+ @subject.title.should.equal(@options[:title])
301
+ end
302
+
303
+ it "has the correct target" do
304
+ @subject.target.should.equal(@target)
305
+ end
306
+
307
+ it "has the correct action" do
308
+ @subject.action.should.equal(:call)
309
+ end
310
+ end
311
+
312
+ ###############################################################################################
313
+
314
+ describe "given options for a styled item with an image" do
315
+ before do
316
+ @options = { :styled => :bordered, :image => UIImage.alloc.init }
317
+ @target = -> { true }
318
+ @subject = BW::UIBarButtonItem.build(@options, &@target)
319
+ end
320
+
321
+ it "has the correct class" do
322
+ @subject.class.should.equal(UIBarButtonItem)
323
+ end
324
+
325
+ it "has the correct style" do
326
+ @subject.style.should.equal(UIBarButtonItemStyleBordered)
327
+ end
328
+
329
+ it "has the correct image" do
330
+ @subject.image.should.equal(@options[:image])
331
+ end
332
+
333
+ it "has the correct target" do
334
+ @subject.target.should.equal(@target)
335
+ end
336
+
337
+ it "has the correct action" do
338
+ @subject.action.should.equal(:call)
339
+ end
340
+ end
341
+
342
+ ###############################################################################################
343
+
344
+ describe "given options for a styled item with two images" do
345
+ before do
346
+ @options = {
347
+ :styled => :bordered,
348
+ :image => UIImage.alloc.init,
349
+ :landscape => UIImage.alloc.init
350
+ }
351
+ @target = -> { true }
352
+ @subject = BW::UIBarButtonItem.build(@options, &@target)
353
+ end
354
+
355
+ it "has the correct class" do
356
+ @subject.class.should.equal(UIBarButtonItem)
357
+ end
358
+
359
+ it "has the correct style" do
360
+ @subject.style.should.equal(UIBarButtonItemStyleBordered)
361
+ end
362
+
363
+ it "has the correct image" do
364
+ @subject.image.should.equal(@options[:image])
365
+ end
366
+
367
+ it "has the correct iPhone landscape image" do
368
+ @subject.landscapeImagePhone.should.equal(@options[:landscape])
369
+ end
370
+
371
+ it "has the correct target" do
372
+ @subject.target.should.equal(@target)
373
+ end
374
+
375
+ it "has the correct action" do
376
+ @subject.action.should.equal(:call)
377
+ end
378
+ end
379
+
380
+ ###############################################################################################
381
+
382
+ describe "given options for a system item" do
383
+ before do
384
+ @options = { :system => :save }
385
+ @target = -> { true }
386
+ @subject = BW::UIBarButtonItem.build(@options, &@target)
387
+ end
388
+
389
+ it "has the correct class" do
390
+ @subject.class.should.equal(UIBarButtonItem)
391
+ end
392
+
393
+ it "has the correct system item" do
394
+ @subject.systemItem.should.equal(UIBarButtonSystemItemSave)
395
+ end
396
+
397
+ it "has the correct target" do
398
+ @subject.target.should.equal(@target)
399
+ end
400
+
401
+ it "has the correct action" do
402
+ @subject.action.should.equal(:call)
403
+ end
404
+ end
405
+
406
+ ###############################################################################################
407
+
408
+ describe "given options for a custom view" do
409
+ before do
410
+ @options = { :custom => UIView.alloc.init }
411
+ @target = -> { true }
412
+ @subject = BW::UIBarButtonItem.build(@options, &@target)
413
+ end
414
+
415
+ it "has the correct class" do
416
+ @subject.class.should.equal(UIBarButtonItem)
417
+ end
418
+
419
+ it "has a custom view" do
420
+ @subject.customView.should.equal(@options[:custom])
421
+ end
422
+
423
+ it "adds one, single tap gesture recognizer to the custom view" do
424
+ @options[:custom].gestureRecognizers.size.should.equal(1)
425
+ @options[:custom].gestureRecognizers.first.class.should.equal(UITapGestureRecognizer)
426
+ @options[:custom].gestureRecognizers.first.numberOfTapsRequired.should.equal(1)
427
+ end
428
+ end
429
+
430
+ ###############################################################################################
431
+
432
+ describe "given options for a view" do
433
+ before do
434
+ @options = { :view => UIView.alloc.init }
435
+ @target = -> { true }
436
+ @subject = BW::UIBarButtonItem.build(@options, &@target)
437
+ end
438
+
439
+ it "has the correct class" do
440
+ @subject.class.should.equal(UIBarButtonItem)
441
+ end
442
+
443
+ it "has a custom view" do
444
+ @subject.customView.should.equal(@options[:view])
445
+ end
446
+
447
+ it "adds one, single tap gesture recognizer to the view" do
448
+ @options[:view].gestureRecognizers.size.should.equal(1)
449
+ @options[:view].gestureRecognizers.first.class.should.equal(UITapGestureRecognizer)
450
+ @options[:view].gestureRecognizers.first.numberOfTapsRequired.should.equal(1)
451
+ end
452
+ end
453
+ end
454
+ end