cloudfactory 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/cf.gemspec +1 -0
  2. data/features/error_custom_task_form.feature +117 -0
  3. data/features/error_form_field.feature +58 -0
  4. data/features/error_task_form.feature +64 -0
  5. data/features/errors.feature +192 -0
  6. data/features/run.feature +136 -121
  7. data/features/support/cli_steps.rb +44 -0
  8. data/features/support/env.rb +2 -2
  9. data/lib/cf.rb +3 -4
  10. data/lib/cf/account.rb +12 -1
  11. data/lib/cf/cli.rb +2 -2
  12. data/lib/cf/cli/config.rb +2 -2
  13. data/lib/cf/cli/form.rb +5 -5
  14. data/lib/cf/cli/line.rb +40 -16
  15. data/lib/cf/cli/production.rb +50 -18
  16. data/lib/cf/cli/templates/sample-line/form.css +41 -17
  17. data/lib/cf/cli/templates/sample-line/form.html +27 -18
  18. data/lib/cf/cli/templates/sample-line/form.js +12 -3
  19. data/lib/cf/cli/templates/sample-line/line.yml.erb +42 -32
  20. data/lib/cf/client.rb +3 -3
  21. data/lib/cf/custom_task_form.rb +21 -91
  22. data/lib/cf/department.rb +1 -10
  23. data/lib/cf/final_output.rb +2 -16
  24. data/lib/cf/form_field.rb +11 -6
  25. data/lib/cf/human_worker.rb +93 -1
  26. data/lib/cf/input_format.rb +10 -62
  27. data/lib/cf/line.rb +46 -37
  28. data/lib/cf/robot_worker.rb +63 -2
  29. data/lib/cf/run.rb +37 -66
  30. data/lib/cf/station.rb +42 -104
  31. data/lib/cf/task_form.rb +17 -56
  32. data/lib/cf/version.rb +2 -2
  33. data/lib/generators/cf/form/form_generator.rb +3 -3
  34. data/lib/generators/cf/install/install_generator.rb +3 -3
  35. data/spec/custom_task_form_spec.rb +169 -1
  36. data/spec/generators/form_generator_spec.rb +2 -2
  37. data/spec/generators/install_generator_spec.rb +2 -2
  38. data/spec/run_spec.rb +3 -3
  39. data/spec/spec_helper.rb +1 -0
  40. data/spec/station_spec.rb +13 -1
  41. data/spec/task_form_spec.rb +38 -6
  42. metadata +63 -44
data/lib/cf/station.rb CHANGED
@@ -3,19 +3,35 @@ module CF
3
3
  require 'httparty'
4
4
  include Client
5
5
 
6
- # type of the station, e.g. station = Station.new(line, {:type => "Work"})
6
+ # type of the station, e.g. station = Station.new({:type => "Work"})
7
7
  attr_accessor :type
8
8
 
9
- # line attribute is parent attribute for station & is required for making Api call
9
+ # Title of line with which station is associated with
10
10
  attr_accessor :line_title
11
11
 
12
- # ID of the station
13
- attr_accessor :id, :extra, :except, :index, :line, :station_input_formats, :jury_worker, :auto_judge, :errors
12
+ # Index number of station
13
+ attr_accessor :index
14
+
15
+ # Line attribute of the station with which station is associated
16
+ attr_accessor :line
17
+
18
+ # Manual input format settings for the station
19
+ attr_accessor :station_input_formats
20
+
21
+ # Jury worker settings for the Tournament Station
22
+ attr_accessor :jury_worker
23
+
24
+ # Auto Judge settings for the Tournament Station
25
+ attr_accessor :auto_judge
26
+
27
+ # Contains Error Message if any
28
+ attr_accessor :errors
14
29
 
15
30
  # ==Initializes a new station
16
- # ===Usage Example
31
+ # ===Usage Example:
17
32
  # line = CF::Line.new("Digitize", "Survey")
18
- # station = CF::Station.new({:line => line, :type => "Work"})
33
+ # station = CF::Station.new({:type => "Work"})
34
+ # line.stations station
19
35
  def initialize(options={})
20
36
  @input_formats =[]
21
37
  @line_title = options[:line].nil? ? nil : options[:line].title
@@ -63,35 +79,20 @@ module CF
63
79
  end
64
80
  end
65
81
 
66
- # ==Initializes a new station within block
82
+ # ==Creation of a new station
67
83
  # ===Usage Example
68
- # ===Creating station using block variable
69
84
  # line = CF::Line.create("Digitize Card","Digitization") do |l|
70
- # CF::InputFormat.new({:line => l, :label => "Company", :field_type => "text_data", :value => "Google", :required => true, :validation_format => "general"})
71
- # CF::InputFormat.new({:line => l, :label => "Website", :field_type => "text_data", :value => "www.google.com", :required => true, :validation_format => "url"})
85
+ # CF::InputFormat.new({:line => l, :label => "Company", :required => "true", :valid_type => "general"})
86
+ # CF::InputFormat.new({:line => l, :label => "Website", :required => "true", :valid_type => "url"})
72
87
  # CF::Station.create({:line => l, :type => "work") do |s|
73
88
  # CF::HumanWorker.new({:station => s, :number => 1, :reward => 20)
74
- # CF::Form.create({:station => s, :title => "Enter text from a business card image", :description => "Describe"}) do |i|
89
+ # CF::Form.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
75
90
  # CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
76
91
  # CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
77
92
  # CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
78
93
  # end
79
94
  # end
80
95
  # end
81
- #
82
- # ===OR creating without variable within block
83
- # line = CF::Line.create("Digitize Card","Digitization") do
84
- # CF::InputFormat.new({:line => self, :label => "Company", :field_type => "text_data", :value => "Google", :required => true, :validation_format => "general"})
85
- # CF::InputFormat.new({:line => self, :label => "Website", :field_type => "text_data", :value => "www.google.com", :required => true, :validation_format => "url"})
86
- # CF::Station.create({:line => self, :type => "work") do
87
- # CF::HumanWorker.new({:station => self, :number => 1, :reward => 20)
88
- # CF::Form.create({:station => self, :title => "Enter text from a business card image", :description => "Describe"}) do
89
- # CF::FormField.new({:form => self, :label => "First Name", :field_type => "SA", :required => "true"})
90
- # CF::FormField.new({:form => self, :label => "Middle Name", :field_type => "SA"})
91
- # CF::FormField.new({:form => self, :label => "Last Name", :field_type => "SA", :required => "true"})
92
- # end
93
- # end
94
- # end
95
96
  def self.create(options, &block)
96
97
  station = Station.new(options)
97
98
  if block.arity >= 1
@@ -102,12 +103,12 @@ module CF
102
103
  station
103
104
  end
104
105
 
105
- # ==Creates new form for station object
106
- # ===Usage of worker method for "station" object
106
+ # ==Creates new Worker for station object
107
+ # ===Usage Example:
107
108
  # line = CF::Line.new("line name", "Survey")
108
109
  # station = CF::Station.new({:type => "work"})
109
110
  # line.stations station
110
- # human_worker = CF::HumanWorker.new({:number => 1, :reawrd => 20})
111
+ # human_worker = CF::HumanWorker.new({:number => 1, :reward => 20})
111
112
  # line.stations.first.worker human_worker
112
113
  def worker worker_instance = nil
113
114
  if worker_instance
@@ -183,11 +184,11 @@ module CF
183
184
  end
184
185
 
185
186
  # ==Creates new form for station object
186
- # ===Usage of Instruction method for "station" object
187
+ # ===Usage Example:
187
188
  # line = CF::Line.new("line name", "Survey")
188
189
  # station = CF::Station.new({:type => "work"})
189
190
  # line.stations station
190
- # standard_form = CF::Form.new({:title => "title", :description => "description"})
191
+ # form = CF::Form.new({:title => "title", :instruction => "description"})
191
192
  # line.stations.first.form form
192
193
  def form form_instance = nil
193
194
  if form_instance
@@ -226,55 +227,18 @@ module CF
226
227
  @resp.to_hash.each_pair do |k,v|
227
228
  form.send("#{k}=",v) if form.respond_to?(k)
228
229
  end
230
+ if @resp.code != 200
231
+ form.errors = @resp.error.message
232
+ end
229
233
  form.station = self
230
234
  @form_instance = form
231
235
  end
232
236
  end
233
237
 
234
- # ==Usage of line.input_formats(input_format)
235
- # line = CF::Line.new("line name", "Survey")
236
- # station = CF::Station.new({:type => "work"})
237
- # line.stations station
238
- # input_format = CF::InputFormat.new({:line => l, :label => "Website", :field_type => "text_data", :value => "www.google.com", :required => true, :validation_format => "url"})
239
- # line.stations.first.input_formats input_format
240
- # * returns
241
- # line.stationss.first.input_formats as an array of input_formats
242
- def input_formats input_formats_value = nil
243
- if input_formats_value
244
- name = input_formats_value.name
245
- required = input_formats_value.required
246
- valid_type = input_formats_value.valid_type
247
- resp = CF::InputFormat.post("/lines/#{CF.account_name}/#{self.line_title.downcase}/input_formats.json", :input_format => {:name => name, :required => required, :valid_type => valid_type})
248
- input_format = CF::InputFormat.new()
249
- resp.input_format.to_hash.each_pair do |k,v|
250
- input_format.send("#{k}=",v) if input_format.respond_to?(k)
251
- end
252
- @input_formats << input_format
253
- else
254
- @input_formats.first
255
- end
256
- end
257
- def input_formats=(input_formats_value) # :nodoc:
258
- @input_formats << input_formats_value
259
- end
260
- # ==Updates Standard Instruction of a station
261
- # ===Usage example
262
- # line = CF::Line.create("Digitize Card","Digitization") do |l|
263
- # CF::Station.create({:line => l, :type => "work") do |s|
264
- # CF::HumanWorker.new({:station => s, :number => 1, :reward => 20)
265
- # end
266
- # end
267
- # line.stations[0].update_form({:title => "Enter phone number from a business card image", :description => "Call"})
268
- def update_form(options={})
269
- @title = options[:title]
270
- @description = options[:description]
271
- self.class.put("/stations/#{self.id}/form.json", :form => {:title => @title, :description => @description, :type => "Form"})
272
- end
273
-
274
238
  # ==Returns a particular station of a line
275
- # ===Usage example for get_station() method
276
- # line = CF::Line.create("Digitize Card", "4dc8ad6572f8be0600000001")
277
- # station = CF::Station.new({:line => line, :type => "Work"})
239
+ # ===Usage Example:
240
+ # line = CF::Line.create("Digitize", "Department_name")
241
+ # station = CF::Station.new({:type => "Work"})
278
242
  # line.stations station
279
243
  #
280
244
  # got_station = line.stations[0].get
@@ -285,40 +249,14 @@ module CF
285
249
  end
286
250
 
287
251
  # ==Returns information of form
288
- # ===Usage example
289
- # line = CF::Line.create("Digitize Card","Digitization") do |l|
290
- # CF::InputFormat.new({:line => l, :label => "Company", :field_type => "text_data", :value => "Google", :required => true, :validation_format => "general"})
291
- # CF::InputFormat.new({:line => l, :label => "Website", :field_type => "text_data", :value => "www.google.com", :required => true, :validation_format => "url"})
292
- # CF::Station.create({:line => l, :type => "work") do |s|
293
- # CF::HumanWorker.new({:station => s, :number => 1, :reward => 20)
294
- # CF::Form.create({:station => s, :title => "Enter text from a business card image", :description => "Describe"}) do |i|
295
- # CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
296
- # CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
297
- # CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
298
- # end
299
- # end
300
- # end
301
- #
252
+ # ===Usage example:
302
253
  # @got_form = line.stations[0].get_form
303
254
  def get_form
304
255
  self.class.get("/lines/#{CF.account_name}/#{self.line_title.downcase}/stations/#{self.index}/form.json")
305
256
  end
306
257
 
307
258
  # ==Returns all the stations associated with a particular line
308
- # ===Usage example for station.all method is
309
- # line = CF::Line.create("Digitize Card","Digitization") do |l|
310
- # CF::InputFormat.new({:line => l, :label => "Company", :field_type => "text_data", :value => "Google", :required => true, :validation_format => "general"})
311
- # CF::InputFormat.new({:line => l, :label => "Website", :field_type => "text_data", :value => "www.google.com", :required => true, :validation_format => "url"})
312
- # CF::Station.create({:line => l, :type => "work") do |s|
313
- # CF::HumanWorker.new({:station => s, :number => 1, :reward => 20)
314
- # CF::Form.create({:station => s, :title => "Enter text from a business card image", :description => "Describe"}) do |i|
315
- # CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
316
- # CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
317
- # CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
318
- # end
319
- # end
320
- # end
321
- #
259
+ # ===Usage Example:
322
260
  # CF::Station.all(line)
323
261
  # returns all stations
324
262
  def self.all(line)
@@ -328,11 +266,11 @@ module CF
328
266
  # ==Deletes a station
329
267
  # * We need to pass line object with which desired station associated with as an argument to delete a station
330
268
  # ===Usage example for delete method
331
- # line = CF::Line.new("Digitize Card", "4dc8ad6572f8be0600000001")
332
- # station = CF::Station.new({:line =. line, :type => "Work"})
269
+ # line = CF::Line.new("Digitize", "Department_name")
270
+ # station = CF::Station.new({:type => "Work"})
333
271
  # line.stations station
334
272
  #
335
- # station.delete
273
+ # line.stations.first.delete
336
274
  def delete
337
275
  self.class.delete("/lines/#{CF.account_name}/#{self.line_title.downcase}/stations/#{self.index}.json")
338
276
  end
data/lib/cf/task_form.rb CHANGED
@@ -3,23 +3,23 @@ module CF
3
3
  require 'httparty'
4
4
  include Client
5
5
 
6
- # title of the standard_instruction
6
+ # title of the form
7
7
  attr_accessor :title
8
8
 
9
- # instruction about the instruction
9
+ # instruction of the form
10
10
  attr_accessor :instruction
11
11
 
12
- # form_fields for the Form
12
+ # form_fields of the Form
13
13
  attr_accessor :form_fields
14
14
 
15
15
  # station attributes required to store station information
16
16
  attr_accessor :station
17
17
 
18
- # ID of Standard Instruction
19
- attr_accessor :id
20
-
18
+ # Contains Error message if any
19
+ attr_accessor :errors
20
+
21
21
  # ==Initializes a new Form
22
- # ==Usage of standard_instruction.new
22
+ # ===Usage Example:
23
23
  # attrs = {:title => "Enter text from a business card image",
24
24
  # :instruction => "Describe"}
25
25
  #
@@ -34,40 +34,23 @@ module CF
34
34
  resp.to_hash.each_pair do |k,v|
35
35
  self.send("#{k}=",v) if self.respond_to?(k)
36
36
  end
37
+ if resp.code != 200
38
+ self.errors = resp.error.message
39
+ end
37
40
  @station.form = self
38
41
  end
39
42
  end
40
43
 
41
44
  # ==Initializes a new Form within block using Variable
42
- # ==Usage of "standard_instruction.create(hash) do |block|"
43
- # ===Creating Form using block variable
45
+ # ===Usage Example:
44
46
  # line = CF::Line.create("Digitize Card","Digitization") do |l|
45
- # CF::InputHeader.new({:line => l, :label => "Company", :field_type => "text_data", :value => "Google", :required => true, :validation_format => "general"})
46
- # CF::InputHeader.new({:line => l, :label => "Website", :field_type => "text_data", :value => "www.google.com", :required => true, :validation_format => "url"})
47
+ # CF::InputHeader.new({:line => l, :label => "Company", :required => true, :valid_type => "general"})
48
+ # CF::InputHeader.new({:line => l, :label => "Website", :required => true, :valid_type => "url"})
47
49
  # CF::Station.create({:line => l, :type => "work") do |s|
48
50
  # CF::HumanWorker.new({:station => s, :number => 1, :reward => 20)
49
- # CF::Form.create(:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
50
- # CF::FormField.new({:instruction => i, :label => "First Name", :field_type => "SA", :required => "true"})
51
- # CF::FormField.new({:instruction => i, :label => "Middle Name", :field_type => "SA"})
52
- # CF::FormField.new({:instruction => i, :label => "Last Name", :field_type => "SA", :required => "true"})
53
- # end
54
- # end
55
- # end
56
- #
57
- # ===OR without block variable
58
- # line = CF::Line.create("Digitize Card","Digitization") do
59
- # CF::InputHeader.new({:line => self, :label => "Company", :field_type => "text_data", :value => "Google", :required => true, :validation_format => "general"})
60
- # CF::InputHeader.new({:line => self, :label => "Website", :field_type => "text_data", :value => "www.google.com", :required => true, :validation_format => "url"})
61
- # CF::Station.create({:line => self, :type => "work") do
62
- # CF::HumanWorker.new({:station => self, :number => 1, :reward => 20)
63
- # CF::Form.create(:station => self, :title => "Enter text from a business card image", :instruction => "Describe"}) do
64
- # CF::FormField.new({:instruction => self, :label => "First Name", :field_type => "SA", :required => "true"})
65
- # CF::FormField.new({:instruction => self, :label => "Middle Name", :field_type => "SA"})
66
- # CF::FormField.new({:instruction => self, :label => "Last Name", :field_type => "SA", :required => "true"})
67
- # end
51
+ # CF::Form.create(:station => s, :title => "Enter text from a business card image", :instruction => "Describe"})
68
52
  # end
69
53
  # end
70
- #
71
54
  def self.create(options, &block)
72
55
  form = TaskForm.new(options)
73
56
  if block.arity >= 1
@@ -78,12 +61,12 @@ module CF
78
61
  form
79
62
  end
80
63
 
81
- # ==appending different form_fields
64
+ # ==Adding different form_fields
82
65
  # ===Syntax for FormField method is form_fields << form_field_values
83
66
  # ==Usage of form_fields method
84
67
  # line = CF::Line.create("Digitize Card","Digitization") do |l|
85
- # CF::InputHeader.new({:line => l, :label => "Company", :field_type => "text_data", :value => "Google", :required => true, :validation_format => "general"})
86
- # CF::InputHeader.new({:line => l, :label => "Website", :field_type => "text_data", :value => "www.google.com", :required => true, :validation_format => "url"})
68
+ # CF::InputHeader.new({:line => l, :label => "Company", :required => true, :valid_type => "general"})
69
+ # CF::InputHeader.new({:line => l, :label => "Website", :required => true, :valid_type => "url"})
87
70
  # CF::Station.create({:line => l, :type => "work") do |s|
88
71
  # CF::HumanWorker.new({:station => s, :number => 1, :reward => 20)
89
72
  # CF::Form.create(:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
@@ -93,7 +76,6 @@ module CF
93
76
  # end
94
77
  # end
95
78
  # end
96
- #
97
79
  def form_fields form_fields = nil
98
80
  if form_fields
99
81
  form_field_params = form_fields.form_field_params
@@ -122,26 +104,5 @@ module CF
122
104
  def form_fields=(form_fields) # :nodoc:
123
105
  @form_fields << form_fields
124
106
  end
125
- # ==Deletes Standard Instruction of a station
126
- # ==Usage example
127
- # line = CF::Line.create("Digitize Card","Digitization") do |l|
128
- # CF::InputHeader.new({:line => l, :label => "Company", :field_type => "text_data", :value => "Google", :required => true, :validation_format => "general"})
129
- # CF::InputHeader.new({:line => l, :label => "Website", :field_type => "text_data", :value => "www.google.com", :required => true, :validation_format => "url"})
130
- # CF::Station.create({:line => l, :type => "work") do |s|
131
- # CF::HumanWorker.new({:station => s, :number => 1, :reward => 20)
132
- # CF::Form.create(:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
133
- # CF::FormField.new({:instruction => i, :label => "First Name", :field_type => "SA", :required => "true"})
134
- # CF::FormField.new({:instruction => i, :label => "Middle Name", :field_type => "SA"})
135
- # CF::FormField.new({:instruction => i, :label => "Last Name", :field_type => "SA", :required => "true"})
136
- # end
137
- # end
138
- # end
139
- # station = line.stations[0]
140
- #
141
- # CF::Form.delete_instruction(station)
142
- # deletes standard_instruction of a station
143
- def self.delete_instruction(station)
144
- delete("/lines/#{CF.account_name}/#{station.line_title.downcase}/stations/#{station.index}/form.json")
145
- end
146
107
  end
147
108
  end
data/lib/cf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module CF
2
- VERSION = "0.1.9"
1
+ module CF # :nodoc: all
2
+ VERSION = "0.1.10"
3
3
  end
@@ -1,5 +1,5 @@
1
- module Cf
2
- module Generators
1
+ module Cf # :nodoc: all
2
+ module Generators # :nodoc: all
3
3
 
4
4
  #
5
5
  # TODO: if the parameter like 'company' below is not provided, then its a survey form.
@@ -22,7 +22,7 @@ module Cf
22
22
  #
23
23
  #
24
24
 
25
- class FormGenerator < Rails::Generators::Base
25
+ class FormGenerator < Rails::Generators::Base # :nodoc: all
26
26
  source_root File.expand_path("../templates", __FILE__)
27
27
  argument :attributes, :type => :array, :default => [], :banner => "[label1,label2] field:type field:type"
28
28
 
@@ -1,6 +1,6 @@
1
- module Cf
2
- module Generators
3
- class InstallGenerator < Rails::Generators::Base
1
+ module Cf # :nodoc: all
2
+ module Generators # :nodoc: all
3
+ class InstallGenerator < Rails::Generators::Base # :nodoc: all
4
4
  source_root File.expand_path("../templates", __FILE__)
5
5
  # argument :account_name, :required => true,
6
6
  # :desc => "The account name that you used to signup at http://cloudfactory.com"
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CF::CustomTaskForm do
4
- context "create a standard_instruction" do
4
+ context "create a Custom Task Form" do
5
5
  it "in block DSL way" do
6
6
  # WebMock.allow_net_connect!
7
7
  VCR.use_cassette "custom-task-form/block/create", :record => :new_episodes do
@@ -187,4 +187,172 @@ describe CF::CustomTaskForm do
187
187
  end
188
188
  end
189
189
  end
190
+
191
+ context "create a Custom Task Form for Error Handling;" do
192
+ it "creating with invalid Html content" do
193
+ # WebMock.allow_net_connect!
194
+ VCR.use_cassette "custom-task-form/block/invalid-html-content", :record => :new_episodes do
195
+ html = '<div id="form-content">
196
+ <div id="instructions">
197
+ <ul>
198
+ <li>Look at the business card properly and fill in asked data.</li>
199
+ <li>Make sure you enter everything found on business card.</li>
200
+ <li>Work may be rejected if it is incomplete or mistakes are found.</li>
201
+ </ul>
202
+ </div>
203
+ <div id="image-field-wrapper">
204
+ <div id = "image-panel" >
205
+ <img class="card-image" src="{{image_url}}">
206
+ </div>
207
+ <div id = "field-panel">
208
+ Name<br />
209
+ <input class="input-field first_name" type="text" name="final_output[first_name]" />
210
+ <input class="input-field middle_name" type="text" name="final_output[middle_name]" />
211
+ <input class="input-field last_name" type="text" name="final_output[last_name]" /><br />
212
+
213
+ <br />Contact<br />
214
+ <input class="input-field email" type="text" name="final_output[email]" placeholder="Email"/>
215
+ <input class="input-field phone" type="text" name="final_output[phone]" placeholder="Phone"/>
216
+ <input class="input-field mobile" type="text" name="final_output[mobile]" placeholder="Mobile"/><br />
217
+
218
+ </div>
219
+ </div>
220
+ </div>'
221
+ line = CF::Line.create("Digitizecustomform111", "Digitization") do
222
+ CF::InputFormat.new({:line => self, :name => "Name", :required => true, :valid_format => "general"})
223
+ CF::InputFormat.new({:line => self, :name => "Contact", :required => true, :valid_type => "url"})
224
+ CF::Station.create({:line => self, :type => "work", :max_judges => 10, :auto_judge => true}) do |s|
225
+ CF::HumanWorker.new({:station => s, :number => 3, :reward => 20})
226
+ CF::CustomTaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe", :raw_html => html})
227
+ end
228
+ end
229
+ line.title.should eql("Digitizecustomform111")
230
+ line.department_name.should eql("Digitization")
231
+ line.stations.first.form.errors.should eql("[\"Raw html should contain a Form tag\", \"Raw html The name 'final_output[first_name]' is not valid, it should be of format output[name]\", \"Raw html The name 'final_output[middle_name]' is not valid, it should be of format output[name]\", \"Raw html The name 'final_output[last_name]' is not valid, it should be of format output[name]\", \"Raw html The name 'final_output[email]' is not valid, it should be of format output[name]\", \"Raw html The name 'final_output[phone]' is not valid, it should be of format output[name]\", \"Raw html The name 'final_output[mobile]' is not valid, it should be of format output[name]\"]")
232
+ end
233
+ end
234
+
235
+ it "creating without title" do
236
+ # WebMock.allow_net_connect!
237
+ VCR.use_cassette "custom-task-form/block/without-title", :record => :new_episodes do
238
+ html = '<div id="form-content">
239
+ <div id="instructions">
240
+ <ul>
241
+ <li>Look at the business card properly and fill in asked data.</li>
242
+ <li>Make sure you enter everything found on business card.</li>
243
+ <li>Work may be rejected if it is incomplete or mistakes are found.</li>
244
+ </ul>
245
+ </div>
246
+ <div id="image-field-wrapper">
247
+ <div id = "image-panel" >
248
+ <img class="card-image" src="{{image_url}}">
249
+ </div>
250
+ <div id = "field-panel">
251
+ Name<br />
252
+ <input class="input-field first_name" type="text" name="output[first_name]" />
253
+ <input class="input-field middle_name" type="text" name="output[middle_name]" />
254
+ <input class="input-field last_name" type="text" name="output[last_name]" /><br />
255
+
256
+ <br />Contact<br />
257
+ <input class="input-field email" type="text" name="output[email]" placeholder="Email"/>
258
+ <input class="input-field phone" type="text" name="output[phone]" placeholder="Phone"/>
259
+ <input class="input-field mobile" type="text" name="output[mobile]" placeholder="Mobile"/><br />
260
+
261
+ </div>
262
+ </div>
263
+ </div>'
264
+ line = CF::Line.create("Digitizecustomform112", "Digitization") do
265
+ CF::InputFormat.new({:line => self, :name => "Name", :required => true, :valid_format => "general"})
266
+ CF::InputFormat.new({:line => self, :name => "Contact", :required => true, :valid_type => "url"})
267
+ CF::Station.create({:line => self, :type => "work", :max_judges => 10, :auto_judge => true}) do |s|
268
+ CF::HumanWorker.new({:station => s, :number => 3, :reward => 20})
269
+ CF::CustomTaskForm.create({:station => s, :instruction => "Describe", :raw_html => html})
270
+ end
271
+ end
272
+ line.title.should eql("Digitizecustomform112")
273
+ line.department_name.should eql("Digitization")
274
+ line.stations.first.form.errors.should eql("[\"Title can't be blank\", \"Raw html should contain a Form tag\"]")
275
+ end
276
+ end
277
+
278
+ it "creating without instruction" do
279
+ # WebMock.allow_net_connect!
280
+ VCR.use_cassette "custom-task-form/block/without-instruction", :record => :new_episodes do
281
+ html = '<div id="form-content">
282
+ <div id="instructions">
283
+ <ul>
284
+ <li>Look at the business card properly and fill in asked data.</li>
285
+ <li>Make sure you enter everything found on business card.</li>
286
+ <li>Work may be rejected if it is incomplete or mistakes are found.</li>
287
+ </ul>
288
+ </div>
289
+ <div id="image-field-wrapper">
290
+ <div id = "image-panel" >
291
+ <img class="card-image" src="{{image_url}}">
292
+ </div>
293
+ <div id = "field-panel">
294
+ Name<br />
295
+ <input class="input-field first_name" type="text" name="output[first_name]" />
296
+ <input class="input-field middle_name" type="text" name="output[middle_name]" />
297
+ <input class="input-field last_name" type="text" name="output[last_name]" /><br />
298
+
299
+ <br />Contact<br />
300
+ <input class="input-field email" type="text" name="output[email]" placeholder="Email"/>
301
+ <input class="input-field phone" type="text" name="output[phone]" placeholder="Phone"/>
302
+ <input class="input-field mobile" type="text" name="output[mobile]" placeholder="Mobile"/><br />
303
+
304
+ </div>
305
+ </div>
306
+ </div>'
307
+ line = CF::Line.create("Digitizecustomform113", "Digitization") do
308
+ CF::InputFormat.new({:line => self, :name => "Name", :required => true, :valid_format => "general"})
309
+ CF::InputFormat.new({:line => self, :name => "Contact", :required => true, :valid_type => "url"})
310
+ CF::Station.create({:line => self, :type => "work", :max_judges => 10, :auto_judge => true}) do |s|
311
+ CF::HumanWorker.new({:station => s, :number => 3, :reward => 20})
312
+ CF::CustomTaskForm.create({:station => s, :title => "title", :raw_html => html})
313
+ end
314
+ end
315
+ line.title.should eql("Digitizecustomform113")
316
+ line.department_name.should eql("Digitization")
317
+ line.stations.first.form.errors.should eql("[\"Instruction can't be blank\", \"Raw html should contain a Form tag\"]")
318
+ end
319
+ end
320
+
321
+ it "creating without any html data" do
322
+ # WebMock.allow_net_connect!
323
+ VCR.use_cassette "custom-task-form/block/without-html", :record => :new_episodes do
324
+ line = CF::Line.create("Digitizecustomform114", "Digitization") do
325
+ CF::InputFormat.new({:line => self, :name => "Name", :required => true, :valid_format => "general"})
326
+ CF::InputFormat.new({:line => self, :name => "Contact", :required => true, :valid_type => "url"})
327
+ CF::Station.create({:line => self, :type => "work", :max_judges => 10, :auto_judge => true}) do |s|
328
+ CF::HumanWorker.new({:station => s, :number => 3, :reward => 20})
329
+ CF::CustomTaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"})
330
+ end
331
+ end
332
+ line.title.should eql("Digitizecustomform114")
333
+ line.department_name.should eql("Digitization")
334
+ line.stations.first.form.errors.should eql("[\"Raw html is required\"]")
335
+ end
336
+ end
337
+
338
+ it "creating without any html data in plain ruby way" do
339
+ # WebMock.allow_net_connect!
340
+ VCR.use_cassette "custom-task-form/plain/without-html", :record => :new_episodes do
341
+ line = CF::Line.create("Digitizecustomform115", "Digitization") do
342
+ CF::InputFormat.new({:line => self, :name => "Name", :required => true, :valid_format => "general"})
343
+ CF::InputFormat.new({:line => self, :name => "Contact", :required => true, :valid_type => "url"})
344
+ CF::Station.create({:line => self, :type => "work", :max_judges => 10, :auto_judge => true}) do |s|
345
+ CF::HumanWorker.new({:station => s, :number => 3, :reward => 20})
346
+ end
347
+ end
348
+
349
+ form = CF::CustomTaskForm.create({:title => "Enter text from a business card image", :instruction => "Describe"})
350
+ line.stations.first.form = form
351
+
352
+ line.title.should eql("Digitizecustomform115")
353
+ line.department_name.should eql("Digitization")
354
+ line.stations.first.form.errors.should eql("[\"Raw html is required\"]")
355
+ end
356
+ end
357
+ end
190
358
  end