doop 0.0.4.2 → 0.0.5

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 (101) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +126 -12
  3. data/app/helpers/doop_helper.rb +4 -0
  4. data/demo/.gitignore +19 -0
  5. data/demo/.rspec +2 -0
  6. data/demo/Gemfile +70 -0
  7. data/demo/Gemfile.lock +237 -0
  8. data/demo/README.md +50 -0
  9. data/demo/Rakefile +6 -0
  10. data/demo/app/assets/images/.keep +0 -0
  11. data/demo/app/assets/images/cert_sample.jpg +0 -0
  12. data/demo/app/assets/javascripts/application.js +16 -0
  13. data/{lib/generators/doopgovuk/templates → demo}/app/assets/javascripts/demo.js.coffee +0 -0
  14. data/{lib/generators/doopgovuk/templates → demo}/app/assets/javascripts/demo/analytics.js.erb +0 -0
  15. data/demo/app/assets/javascripts/demo/application.js +8 -0
  16. data/demo/app/assets/stylesheets/application.css +15 -0
  17. data/{lib/generators/doopgovuk/templates → demo}/app/assets/stylesheets/demo.css.scss +39 -0
  18. data/{lib/generators/doopgovuk/templates → demo}/app/assets/stylesheets/demo/application.css +1 -0
  19. data/demo/app/controllers/application_controller.rb +5 -0
  20. data/demo/app/controllers/concerns/.keep +0 -0
  21. data/{lib/generators/doopgovuk/templates → demo}/app/controllers/demo_controller.rb +84 -53
  22. data/demo/app/helpers/application_helper.rb +2 -0
  23. data/demo/app/helpers/demo_helper.rb +2 -0
  24. data/demo/app/mailers/.keep +0 -0
  25. data/demo/app/models/.keep +0 -0
  26. data/demo/app/models/concerns/.keep +0 -0
  27. data/{lib/generators/doopgovuk/templates → demo}/app/views/demo/_about_you.html.erb +0 -0
  28. data/{lib/generators/doopgovuk/templates → demo}/app/views/demo/_before_you_begin.html.erb +3 -3
  29. data/{lib/generators/doopgovuk/templates → demo}/app/views/demo/_children.html.erb +8 -6
  30. data/{lib/generators/doopgovuk/templates → demo}/app/views/demo/_declaration.html.erb +0 -0
  31. data/{lib/generators/doopgovuk/templates → demo}/app/views/demo/_preamble.html.erb +10 -0
  32. data/demo/app/views/demo/harness.html.erb +6 -0
  33. data/{lib/generators/doopgovuk/templates → demo}/app/views/demo/index.html.erb +0 -0
  34. data/{lib/generators/doopgovuk/templates → demo}/app/views/demo/index.js.erb +0 -0
  35. data/{lib/generators/doopgovuk/templates → demo}/app/views/doop/_change_answer_tooltip.html.erb +0 -0
  36. data/{lib/generators/doopgovuk/templates → demo}/app/views/doop/_debug.html.erb +1 -1
  37. data/{lib/generators/doopgovuk/templates → demo}/app/views/doop/_error.html.erb +0 -0
  38. data/demo/app/views/doop/_file_uploader.html.erb +58 -0
  39. data/{lib/generators/doopgovuk/templates → demo}/app/views/doop/_info_box.html.erb +0 -0
  40. data/{lib/generators/doopgovuk/templates → demo}/app/views/doop/_navbar.html.erb +0 -0
  41. data/{lib/generators/doopgovuk/templates → demo}/app/views/doop/_question.html.erb +0 -0
  42. data/{lib/generators/doopgovuk/templates → demo}/app/views/doop/_question_form.html.erb +1 -1
  43. data/{lib/generators/doopgovuk/templates → demo}/app/views/doop/_textfield.html.erb +0 -0
  44. data/{lib/generators/doopgovuk/templates → demo}/app/views/doop/_tooltip.html.erb +0 -0
  45. data/{lib/generators/doopgovuk/templates → demo}/app/views/layouts/application.html.erb +0 -0
  46. data/demo/bin/bundle +3 -0
  47. data/demo/bin/rails +8 -0
  48. data/demo/bin/rake +8 -0
  49. data/demo/bin/rspec +16 -0
  50. data/demo/bin/spring +18 -0
  51. data/demo/config.ru +4 -0
  52. data/demo/config/application.rb +23 -0
  53. data/demo/config/boot.rb +4 -0
  54. data/demo/config/database.yml +26 -0
  55. data/demo/config/environment.rb +5 -0
  56. data/demo/config/environments/development.rb +37 -0
  57. data/demo/config/environments/production.rb +78 -0
  58. data/demo/config/environments/test.rb +39 -0
  59. data/demo/config/initializers/assets.rb +8 -0
  60. data/demo/config/initializers/backtrace_silencers.rb +7 -0
  61. data/demo/config/initializers/cookies_serializer.rb +3 -0
  62. data/demo/config/initializers/filter_parameter_logging.rb +4 -0
  63. data/demo/config/initializers/inflections.rb +16 -0
  64. data/demo/config/initializers/mime_types.rb +4 -0
  65. data/demo/config/initializers/session_store.rb +3 -0
  66. data/demo/config/initializers/wrap_parameters.rb +14 -0
  67. data/demo/config/locales/en.yml +23 -0
  68. data/demo/config/routes.rb +63 -0
  69. data/demo/config/secrets.yml +22 -0
  70. data/demo/db/seeds.rb +7 -0
  71. data/demo/lib/assets/.keep +0 -0
  72. data/demo/lib/tasks/.keep +0 -0
  73. data/demo/log/.keep +0 -0
  74. data/demo/notes.txt +3 -0
  75. data/demo/public/404.html +67 -0
  76. data/demo/public/422.html +67 -0
  77. data/demo/public/500.html +66 -0
  78. data/demo/public/favicon.ico +0 -0
  79. data/demo/public/robots.txt +5 -0
  80. data/{lib/generators/doopgovuk/templates → demo}/spec/features/demo_spec.rb +24 -5
  81. data/{lib/generators/doopgovuk/templates → demo}/spec/rails_helper.rb +0 -0
  82. data/{lib/generators/doopgovuk/templates → demo}/spec/spec_helper.rb +0 -0
  83. data/demo/test/controllers/.keep +0 -0
  84. data/demo/test/fixtures/.keep +0 -0
  85. data/demo/test/helpers/.keep +0 -0
  86. data/demo/test/integration/.keep +0 -0
  87. data/demo/test/mailers/.keep +0 -0
  88. data/demo/test/models/.keep +0 -0
  89. data/demo/test/test_helper.rb +10 -0
  90. data/demo/vendor/assets/javascripts/.keep +0 -0
  91. data/demo/vendor/assets/stylesheets/.keep +0 -0
  92. data/doop.gemspec +1 -17
  93. data/lib/doop-rspec.rb +4 -0
  94. data/lib/doop/version.rb +1 -1
  95. data/lib/doop_controller.rb +19 -24
  96. data/lib/generators/doopgovuk/doopgovuk_generator.rb +23 -13
  97. data/lib/generators/doopgovuk/templates/.keep +0 -0
  98. data/notes/screenshots/doop_1.png +0 -0
  99. metadata +94 -31
  100. data/lib/generators/doopgovuk/templates/app/assets/javascripts/demo/application.js +0 -3
  101. data/lib/generators/doopgovuk/templates/app/views/demo/harness.html.erb +0 -6
@@ -0,0 +1,50 @@
1
+ # Doop Demo
2
+ An example doop-rails project which is used as the template for the doopgovuk generator.
3
+
4
+
5
+ ## Development
6
+
7
+ git clone git@github.com:coder36/doop.git
8
+ cd doop
9
+ git submodule init
10
+ cd ..
11
+ git clone git@github.com:coder36/doop_demo.git
12
+ cd doop_demo
13
+ bundle install
14
+ rails s
15
+
16
+
17
+ ## Publishing to Heroku
18
+
19
+ touch heroku
20
+ bundle install
21
+ git add .
22
+ git commit -m"Heroku build"
23
+ heroku login (provide email and password)
24
+ git push heroku
25
+
26
+
27
+ # Testing
28
+
29
+ I've used cucmber extensively in the past, but found that inveitably the customer would never actually read the gherkin, so immediatly the rational
30
+ for using gherkins would be invalid. One of the issues that I found with gherkins was the lure towards writing hundreds of different flows, but
31
+ all that would happen is that the testing feedback loop increased to hours! Also cucmber matchers feel very artificial and can lead you down a
32
+ rabbit hole!
33
+
34
+
35
+ I would suggest to use (capybara)[https://github.com/jnicklas/capybara] with rspec, along with a headless browser. Rspec gives much more control to the developer, so that accurate and concise testing can be done, without the overhead of creating cucumber matchers.
36
+
37
+
38
+ ## Headless web driver
39
+
40
+ sudo apt-get install qt4-dev-tools libqt4-dev libqt4-core libqt4-gui xvfb
41
+
42
+
43
+ ## Chromedriver
44
+
45
+ Download the (chromedriver)[http://chromedriver.storage.googleapis.com/index.html].
46
+
47
+ chromdriver --white-listed-ips 192.168.33.11
48
+
49
+ This allows the chromedriver to be used remotely from 192.168.33.11. This type of setup is ideal for a CI pipeline.
50
+
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
File without changes
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require turbolinks
16
+ //= require_tree .
@@ -0,0 +1,8 @@
1
+ //
2
+ //= require jquery-ui/dialog
3
+ //= require_tree .
4
+ //= require blueimp-gallery
5
+ //= require jquery.blueimp-gallery
6
+ //= require jquery-fileupload/basic
7
+ //= require jquery-fileupload/vendor/load-image
8
+ //= require jquery-fileupload/vendor/canvas-to-blob
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -137,6 +137,12 @@ button {
137
137
 
138
138
  }
139
139
 
140
+ .button {
141
+ @include button;
142
+ margin: 16px 0 0 0;
143
+
144
+ }
145
+
140
146
  .button-secondary{
141
147
  @include button($grey-3);
142
148
  }
@@ -288,3 +294,36 @@ select {
288
294
  @include core-16();
289
295
  }
290
296
 
297
+ .bar {
298
+ height: 18px;
299
+ background: green;
300
+ }
301
+
302
+ .uploaded_image {
303
+ float: left;
304
+ padding: 0 0 5px 0;
305
+ margin: 0 2px 0 0;
306
+ width: auto;
307
+ border: 1px solid #ccc;
308
+ img {
309
+ padding: 0 0 0 0;
310
+ margin: 8px 0 0 0;
311
+ }
312
+ button {
313
+
314
+ margin: 0 0 0 0;
315
+
316
+ }
317
+ }
318
+
319
+ .clear {
320
+ clear: both;
321
+ }
322
+
323
+ .progress-bar {
324
+ margin: 10px 0 0 0;
325
+ height: 20px;
326
+ width: 0;
327
+ background: url(progressbar.gif);
328
+ display: none;
329
+ }
@@ -1,3 +1,4 @@
1
1
  /*
2
2
  *= require jquery-ui/dialog
3
+ *= require blueimp-gallery
3
4
  */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
File without changes
@@ -9,18 +9,16 @@ class DemoController < ApplicationController
9
9
  delegate :index, :answer, to: :@doop_controller
10
10
  before_filter :setup_doop
11
11
 
12
+ def harness
13
+ return if request.get?
14
+ @doop_controller.inject_yaml params["yaml"]
15
+ index
16
+ end
17
+
12
18
  def setup_doop
13
19
  @doop_controller = Doop::DoopController.new self do |doop|
14
20
 
15
- load_yaml do
16
- data = params["doop_data"]
17
- if data != nil
18
- if Rails.env.development? || Rails.env.test? || params.include?("harness")
19
- next data
20
- else
21
- next ActiveSupport::MessageEncryptor.new(Rails.application.secrets.secret_key_base).decrypt_and_verify data if !Rails.env.development?
22
- end
23
- end
21
+ yaml do
24
22
 
25
23
  <<-EOS
26
24
  page: {
@@ -37,7 +35,12 @@ class DemoController < ApplicationController
37
35
  },
38
36
  do_you_still_want_to_apply: {
39
37
  _question: "Do you still want to apply for child benefit?"
38
+ },
39
+ proof_of_id: {
40
+ _question: "We need proof of your identity",
41
+ _answer: {}
40
42
  }
43
+
41
44
  },
42
45
  about_you: {
43
46
  _page: "about_you",
@@ -82,9 +85,6 @@ class DemoController < ApplicationController
82
85
  children: {
83
86
  _page: "children",
84
87
  _nav_name: "Children",
85
- how_many_birth_certs: {
86
- _question: "How many birth certificates are you sending us?"
87
- },
88
88
  #{child_yaml}
89
89
  },
90
90
  declaration: {
@@ -112,23 +112,18 @@ class DemoController < ApplicationController
112
112
  },
113
113
  own_child: {
114
114
  _question: "Is this child your own child ?"
115
+ },
116
+ birth_certificate: {
117
+ _question: "We need a photo of the birth certificate",
118
+ _answer: {}
115
119
  }
116
120
  }
117
121
  EOS
118
122
  end
119
123
 
120
- save_yaml do |yaml|
121
- if Rails.env.development? || Rails.env.test?
122
- request["doop_data"] = yaml
123
- else
124
- crypt = ActiveSupport::MessageEncryptor.new(Rails.application.secrets.secret_key_base)
125
- data = crypt.encrypt_and_sign(yaml)
126
- request["doop_data"] = data
127
- end
128
- end
129
-
130
124
 
131
125
  # PREAMBLE callbacks
126
+
132
127
 
133
128
  on_answer "/page/preamble/income_more_than_50000" do |question,path, params, answer|
134
129
  answer_with( question, { "_summary" => answer } )
@@ -139,6 +134,9 @@ class DemoController < ApplicationController
139
134
  answer_with( question, { "_summary" => "Yes" } )
140
135
  end
141
136
 
137
+ on_answer "/page/preamble/proof_of_id" do |question,path, params, answer|
138
+ file_upload_control question, path, params, answer
139
+ end
142
140
 
143
141
 
144
142
  # ABOUT YOU callbacks
@@ -207,15 +205,6 @@ class DemoController < ApplicationController
207
205
  answer_with( question, { "_summary" => answer } )
208
206
  end
209
207
 
210
- on_answer "/page/children/how_many_birth_certs" do |question,path, params, answer|
211
- res = validate( answer )
212
- next res if !res.empty?
213
- next { :answer_error => "Must be a number" } if !is_number answer
214
-
215
-
216
- answer_with( question, { "_summary" => answer } )
217
- end
218
-
219
208
  on_answer "/page/children/child__(\\d+)/name" do |question,path, params, answer|
220
209
  res = validate( answer, ["firstname", "surname"] )
221
210
  next res if !res.empty?
@@ -239,6 +228,10 @@ class DemoController < ApplicationController
239
228
  answer_with( question, { "_summary" => answer } )
240
229
  end
241
230
 
231
+ on_answer "/page/children/child__(\\d+)/birth_certificate" do |question,path, params, answer|
232
+ file_upload_control question, path, params, answer
233
+ end
234
+
242
235
  on_answer "/page/children/child__(\\d+)" do |question,path, params, answer|
243
236
  if params.include?("remove_child")
244
237
  remove path
@@ -259,38 +252,76 @@ class DemoController < ApplicationController
259
252
  end
260
253
 
261
254
  on_answer "/page/declaration" do |question, path, params, answer |
262
- { :redirect => "https://github.com/coder36/doop" }
255
+ #{ :redirect => "https://github.com/coder36/doop" }
263
256
  end
264
257
 
265
- end
266
- end
267
258
 
268
- end
269
259
 
270
260
 
271
- def format_date d
272
- begin
273
- return nil if d.length != 10
274
- Date.strptime( d, "%d/%m/%Y" ).strftime( "%-d %B %Y" )
275
- rescue
276
- nil
261
+ def file_upload_control question, path, params, answer
262
+
263
+ if params.include? "remove_file"
264
+ answer.delete( params["remove_file"] )
265
+ end
266
+
267
+ a = answer.values
268
+ if params.include? "files"
269
+ params["files"].each do |uploaded_io|
270
+ if File.directory? Rails.root.join('public','uploads')
271
+ ext = uploaded_io.original_filename[/.*\.(\w+)/,1]
272
+ filename = (0...16).map { (65 + rand(26)).chr }.join + ".#{ext}"
273
+ filename.downcase!
274
+
275
+ File.open(Rails.root.join('public', 'uploads', filename), 'wb') do |file|
276
+ file.write(uploaded_io.read)
277
+ end
278
+ a << "/uploads/#{filename}"
279
+ else
280
+ a << view_context.image_path("cert_sample.jpg")
281
+ end
282
+ end
283
+ end
284
+ file_count = 0
285
+ answer.clear
286
+ a.each do |n|
287
+ file_count += 1
288
+ answer[ "file__#{file_count}" ] = n
289
+ end
290
+
291
+ if params.include? "continue"
292
+ summary = file_count==0 ? "None provided" : "#{file_count} image#{file_count>1 ? 's' : ''} provided"
293
+ answer_with( question, { "_summary" => summary } )
294
+ end
295
+ end
296
+
297
+ end
277
298
  end
278
- end
279
299
 
280
- def validate answer,fields=nil
281
- res = {}
300
+ def format_date d
301
+ begin
302
+ return nil if d.length != 10
303
+ Date.strptime( d, "%d/%m/%Y" ).strftime( "%-d %B %Y" )
304
+ rescue
305
+ nil
306
+ end
307
+ end
308
+
309
+ def validate answer,fields=nil
310
+ res = {}
311
+
312
+ if fields == nil
313
+ res["answer_error".to_sym] = "Can not be empty" if answer.squish.empty?
314
+ return res
315
+ end
282
316
 
283
- if fields == nil
284
- res["answer_error".to_sym] = "Can not be empty" if answer.squish.empty?
285
- return res
317
+ fields.each do |f|
318
+ res["#{f}_error".to_sym] = "Can not be empty" if answer[f].squish.empty?
319
+ end
320
+ res
286
321
  end
287
322
 
288
- fields.each do |f|
289
- res["#{f}_error".to_sym] = "Can not be empty" if answer[f].squish.empty?
323
+ def is_number num
324
+ num =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
290
325
  end
291
- res
292
- end
293
326
 
294
- def is_number num
295
- num =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
296
327
  end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module DemoHelper
2
+ end
File without changes
File without changes
File without changes
@@ -15,9 +15,9 @@
15
15
  <h2>The code</h2>
16
16
  <p>As you progress through the questionnaire, you can follow along in the code:<br/><br/>
17
17
  <%
18
- view_url = "https://github.com/coder36/doop/tree/master/lib/generators/doopgovuk/templates/app/views/demo"
19
- cont_url = "https://github.com/coder36/doop/tree/master/lib/generators/doopgovuk/templates/app/controllers"
20
- rspec_url = "https://github.com/coder36/doop/blob/master/lib/generators/doopgovuk/templates/spec/features/demo_spec.rb"
18
+ view_url = "https://github.com/coder36/doop/tree/master/demo/app/views/demo"
19
+ cont_url = "https://github.com/coder36/doop/tree/master/demo/app/controllers"
20
+ rspec_url = "https://github.com/coder36/doop/blob/master/demo/spec/features/demo_spec.rb"
21
21
  %>
22
22
 
23
23
  <strong><a href='<%="#{cont_url}/demo_controller.rb"%>'>demo_controller.rb</a></strong><br/>
@@ -13,12 +13,6 @@
13
13
  <% end %>
14
14
  <p>You don't need to tell us about any children you already get Child Benefit for.</p>
15
15
 
16
- <%=question "/page/children/how_many_birth_certs" do |root,answer| %>
17
- <p>We don't need to see a birth certificate for a child that has been claimed for by you or someone else in the past</p>
18
- <%=doop_textfield "answer", answer, res %>
19
- <button>Continue</button>
20
- <% end %>
21
-
22
16
  <% list "/page/children/child__(\\d+)" do |path,index| %>
23
17
 
24
18
  <%=question "#{path}", :title => "Child #{index}" do |root,answer| %>
@@ -46,6 +40,14 @@
46
40
  <button name="b_answer" value="No">No, this is someone elses child</button>
47
41
  <% end %>
48
42
 
43
+ <%=question "#{path}/birth_certificate" do |root,answer| %>
44
+ <%=info_box do %>
45
+ <p>Please upload a photo, of the birth certificate or adoption papers.</p>
46
+ <p>If you are applying using a mobile device with a camera, when you click the upload button, your camera will be activated.</p>
47
+ <% end %>
48
+ <%=file_uploader answer%>
49
+ <% end %>
50
+
49
51
  <% when_answered path do %>
50
52
  <% if index > 1 %>
51
53
  <button class="button-secondary" name="remove_child">Remove child</button><br/>
@@ -14,6 +14,7 @@
14
14
  <h3>Your information</h3>
15
15
  <p>By applying for child benefit online, you consent that we may process your personal data (including sensitive personal data) that we collect from you.</p>
16
16
 
17
+
17
18
  <% when_question :changed => "/page/preamble/income_more_than_50000" do |current_answer, id| %>
18
19
  <%=change_answer_tooltip id do %>
19
20
  <p>If you change this answer, additional questions may be asked</p>
@@ -48,6 +49,15 @@
48
49
  <button name="b_answer" value="Yes">Yes, I still want to apply for child benefit</button><br/>
49
50
  <% end %>
50
51
 
52
+ <%=question "/page/preamble/proof_of_id" do |root,answer| %>
53
+ <%=info_box do %>
54
+ <p>Please upload a photo, of either your passport, driving license and a utility bill
55
+ with your name and address visible.</p>
56
+ <p>If you are applying using a mobile device with a camera, when you click the upload button, your camera will be activated.</p>
57
+ <% end %>
58
+ <%=file_uploader answer%>
59
+ <% end %>
60
+
51
61
  <% when_answered "/page/preamble" do %>
52
62
  <button>Continue and Save</button>
53
63
  <% end %>