cloudfactory 0.3.1 → 0.4.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.
@@ -3,176 +3,176 @@ require 'spec_helper'
3
3
  describe CF::FormField do
4
4
  context "create an form_field" do
5
5
  it "the plain ruby way" do
6
- # WebMock.allow_net_connect!
7
- VCR.use_cassette "form-fields/plain-ruby/create-form-fields", :record => :new_episodes do
8
- line = CF::Line.new("Digitize-0", "Digitization")
9
-
10
- input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
11
- line.input_formats input_format
12
-
13
- station = CF::Station.new({:type => "work"})
14
- line.stations station
15
-
16
- worker = CF::HumanWorker.new({:number => 1, :reward => 20})
17
- line.stations.first.worker = worker
18
-
19
- form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
20
- line.stations.first.form = form
21
-
22
- form_fields_1 = CF::FormField.new({:label => "First Name", :field_type => "short_answer", :required => "true"})
23
- line.stations.first.form.form_fields form_fields_1
24
- form_fields_2 = CF::FormField.new({:label => "Middle Name", :field_type => "short_answer"})
25
- line.stations.first.form.form_fields form_fields_2
26
- form_fields_3 = CF::FormField.new({:label => "Last Name", :field_type => "short_answer", :required => "true"})
27
- line.stations.first.form.form_fields form_fields_3
28
- form_fields_3 = CF::FormField.new({:label => "Gender", :field_type => "radio_button", :required => "true", :option_values => ["male","female"]})
29
- line.stations.first.form.form_fields form_fields_3
30
-
31
- line.stations.first.form.form_fields[0].label.should eq("First Name")
32
- line.stations.first.form.form_fields[0].field_type.should eq("short_answer")
33
- line.stations.first.form.form_fields[0].required.should eq(true)
34
- line.stations.first.form.form_fields[0].form_field_params.should eql({:label => "First Name", :field_type => "short_answer", :required => "true"})
35
- line.stations.first.form.form_fields[1].label.should eq("Middle Name")
36
- line.stations.first.form.form_fields[1].field_type.should eq("short_answer")
37
- line.stations.first.form.form_fields[1].form_field_params.should eql({:label => "Middle Name", :field_type => "short_answer"})
38
- line.stations.first.form.form_fields[2].label.should eq("Last Name")
39
- line.stations.first.form.form_fields[2].field_type.should eq("short_answer")
40
- line.stations.first.form.form_fields[2].required.should eq(true)
41
- line.stations.first.form.form_fields[2].form_field_params.should eql({:label => "Last Name", :field_type => "short_answer", :required => "true"})
42
- line.stations.first.form.form_fields[3].label.should eq("Gender")
43
- line.stations.first.form.form_fields[3].field_type.should eq("radio_button")
44
- line.stations.first.form.form_fields[3].required.should eq(true)
45
- line.stations.first.form.form_fields[3].form_field_params.should eql({:label => "Gender", :field_type => "radio_button", :required => "true", :option_values => ["male","female"]})
46
- end
6
+ WebMock.allow_net_connect!
7
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
8
+ sleep 1
9
+ line = CF::Line.new(title, "Digitization")
10
+
11
+ input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
12
+ line.input_formats input_format
13
+
14
+ station = CF::Station.new({:type => "work"})
15
+ line.stations station
16
+
17
+ worker = CF::HumanWorker.new({:number => 1, :reward => 20})
18
+ line.stations.first.worker = worker
19
+
20
+ form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
21
+ line.stations.first.form = form
22
+
23
+ form_fields_1 = CF::FormField.new({:label => "First Name", :field_type => "short_answer", :required => "true"})
24
+ line.stations.first.form.form_fields form_fields_1
25
+ form_fields_2 = CF::FormField.new({:label => "Middle Name", :field_type => "short_answer"})
26
+ line.stations.first.form.form_fields form_fields_2
27
+ form_fields_3 = CF::FormField.new({:label => "Last Name", :field_type => "short_answer", :required => "true"})
28
+ line.stations.first.form.form_fields form_fields_3
29
+ form_fields_3 = CF::FormField.new({:label => "Gender", :field_type => "radio_button", :required => "true", :option_values => ["male","female"]})
30
+ line.stations.first.form.form_fields form_fields_3
31
+
32
+ line.stations.first.form.form_fields[0].label.should eq("First Name")
33
+ line.stations.first.form.form_fields[0].field_type.should eq("short_answer")
34
+ line.stations.first.form.form_fields[0].required.should eq(true)
35
+ line.stations.first.form.form_fields[0].form_field_params.should eql({:label => "First Name", :field_type => "short_answer", :required => "true"})
36
+ line.stations.first.form.form_fields[1].label.should eq("Middle Name")
37
+ line.stations.first.form.form_fields[1].field_type.should eq("short_answer")
38
+ line.stations.first.form.form_fields[1].form_field_params.should eql({:label => "Middle Name", :field_type => "short_answer"})
39
+ line.stations.first.form.form_fields[2].label.should eq("Last Name")
40
+ line.stations.first.form.form_fields[2].field_type.should eq("short_answer")
41
+ line.stations.first.form.form_fields[2].required.should eq(true)
42
+ line.stations.first.form.form_fields[2].form_field_params.should eql({:label => "Last Name", :field_type => "short_answer", :required => "true"})
43
+ line.stations.first.form.form_fields[3].label.should eq("Gender")
44
+ line.stations.first.form.form_fields[3].field_type.should eq("radio_button")
45
+ line.stations.first.form.form_fields[3].required.should eq(true)
46
+ line.stations.first.form.form_fields[3].form_field_params.should eql({:label => "Gender", :field_type => "radio_button", :required => "true", :option_values => ["male","female"]})
47
47
  end
48
-
48
+
49
49
  it "in block DSL way" do
50
- # WebMock.allow_net_connect!
51
- VCR.use_cassette "form-fields/block/create-using-block", :record => :new_episodes do
52
- line = CF::Line.create("Digitize-0101111-final", "Digitization") do
53
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
54
- CF::Station.create({:line => self, :type => "work"}) do |station|
55
- CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
56
- CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
57
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
58
- CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
59
- CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
60
- CF::FormField.new({:form => i, :label => "Gender", :field_type => "radio_button", :required => "true", :option_values => ["male","female"]})
61
- end
50
+ WebMock.allow_net_connect!
51
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
52
+ sleep 1
53
+ line = CF::Line.create(title, "Digitization") do
54
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
55
+ CF::Station.create({:line => self, :type => "work"}) do |station|
56
+ CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
57
+ CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
58
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
59
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
60
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
61
+ CF::FormField.new({:form => i, :label => "Gender", :field_type => "radio_button", :required => "true", :option_values => ["male","female"]})
62
62
  end
63
63
  end
64
- line.title.should eq("Digitize-0101111-final")
65
- line.department_name.should eq("Digitization")
66
- line.input_formats.first.name.should eql("image_url")
67
- line.stations.first.type.should eq("WorkStation")
68
- line.stations.first.worker.number.should eq(1)
69
- line.stations.first.form.instruction.should eq("Describe")
70
- line.stations.first.form.form_fields[0].label.should eq("First Name")
71
- line.stations.first.form.form_fields[0].field_type.should eq("short_answer")
72
- line.stations.first.form.form_fields[0].required.should eq(true)
73
- line.stations.first.form.form_fields[0].form_field_params.should eql({:label => "First Name", :field_type => "short_answer", :required => "true"})
74
- line.stations.first.form.form_fields[1].label.should eq("Middle Name")
75
- line.stations.first.form.form_fields[1].field_type.should eq("short_answer")
76
- line.stations.first.form.form_fields[1].form_field_params.should eql({:label => "Middle Name", :field_type => "short_answer"})
77
- line.stations.first.form.form_fields[2].label.should eq("Last Name")
78
- line.stations.first.form.form_fields[2].field_type.should eq("short_answer")
79
- line.stations.first.form.form_fields[2].required.should eq(true)
80
- line.stations.first.form.form_fields[2].form_field_params.should eql({:label => "Last Name", :field_type => "short_answer", :required => "true"})
81
- line.stations.first.form.form_fields[3].label.should eq("Gender")
82
- line.stations.first.form.form_fields[3].field_type.should eq("radio_button")
83
- line.stations.first.form.form_fields[3].required.should eq(true)
84
- line.stations.first.form.form_fields[3].form_field_params.should eql({:label => "Gender", :field_type => "radio_button", :required => "true", :option_values => ["male","female"]})
85
64
  end
65
+ line.title.should eq(title)
66
+ line.department_name.should eq("Digitization")
67
+ line.input_formats.first.name.should eql("image_url")
68
+ line.stations.first.type.should eq("WorkStation")
69
+ line.stations.first.worker.number.should eq(1)
70
+ line.stations.first.form.instruction.should eq("Describe")
71
+ line.stations.first.form.form_fields[0].label.should eq("First Name")
72
+ line.stations.first.form.form_fields[0].field_type.should eq("short_answer")
73
+ line.stations.first.form.form_fields[0].required.should eq(true)
74
+ line.stations.first.form.form_fields[0].form_field_params.should eql({:label => "First Name", :field_type => "short_answer", :required => "true"})
75
+ line.stations.first.form.form_fields[1].label.should eq("Middle Name")
76
+ line.stations.first.form.form_fields[1].field_type.should eq("short_answer")
77
+ line.stations.first.form.form_fields[1].form_field_params.should eql({:label => "Middle Name", :field_type => "short_answer"})
78
+ line.stations.first.form.form_fields[2].label.should eq("Last Name")
79
+ line.stations.first.form.form_fields[2].field_type.should eq("short_answer")
80
+ line.stations.first.form.form_fields[2].required.should eq(true)
81
+ line.stations.first.form.form_fields[2].form_field_params.should eql({:label => "Last Name", :field_type => "short_answer", :required => "true"})
82
+ line.stations.first.form.form_fields[3].label.should eq("Gender")
83
+ line.stations.first.form.form_fields[3].field_type.should eq("radio_button")
84
+ line.stations.first.form.form_fields[3].required.should eq(true)
85
+ line.stations.first.form.form_fields[3].form_field_params.should eql({:label => "Gender", :field_type => "radio_button", :required => "true", :option_values => ["male","female"]})
86
86
  end
87
-
87
+
88
88
  it "in block DSL way without valid_type and some with valid_type" do
89
- # WebMock.allow_net_connect!
90
- VCR.use_cassette "form-fields/block/create-valid_type", :record => :new_episodes do
91
- line = CF::Line.create("form_fields_valid_type", "Digitization") do
92
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
93
- CF::Station.create({:line => self, :type => "work"}) do |station|
94
- CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
95
- CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
96
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
97
- CF::FormField.new({:form => i, :label => "email", :field_type => "short_answer", :valid_type => "email", :required => "true"})
98
- end
89
+ WebMock.allow_net_connect!
90
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
91
+ sleep 1
92
+ line = CF::Line.create(title, "Digitization") do
93
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
94
+ CF::Station.create({:line => self, :type => "work"}) do |station|
95
+ CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
96
+ CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
97
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
98
+ CF::FormField.new({:form => i, :label => "email", :field_type => "short_answer", :valid_type => "email", :required => "true"})
99
99
  end
100
100
  end
101
- line.title.should eq("form_fields_valid_type")
102
- line.department_name.should eq("Digitization")
103
- line.input_formats.first.name.should eql("image_url")
104
- line.stations.first.type.should eq("WorkStation")
105
- line.stations.first.worker.number.should eq(1)
106
- line.stations.first.form.instruction.should eq("Describe")
107
- line.stations.first.form.form_fields[0].label.should eq("First Name")
108
- line.stations.first.form.form_fields[0].field_type.should eq("short_answer")
109
- line.stations.first.form.form_fields[0].required.should eq(true)
110
- line.stations.first.form.form_fields[0].form_field_params.should eql({:label => "First Name", :field_type => "short_answer", :required => "true"})
111
- line.stations.first.form.form_fields[1].label.should eq("email")
112
- line.stations.first.form.form_fields[1].field_type.should eq("short_answer")
113
- line.stations.first.form.form_fields[1].required.should eq(true)
114
- line.stations.first.form.form_fields[1].valid_type.should eq("email")
115
- line.stations.first.form.form_fields[1].form_field_params.should eql({:label => "email", :field_type => "short_answer", :valid_type => "email", :required => "true"})
116
101
  end
102
+ line.title.should eq(title)
103
+ line.department_name.should eq("Digitization")
104
+ line.input_formats.first.name.should eql("image_url")
105
+ line.stations.first.type.should eq("WorkStation")
106
+ line.stations.first.worker.number.should eq(1)
107
+ line.stations.first.form.instruction.should eq("Describe")
108
+ line.stations.first.form.form_fields[0].label.should eq("First Name")
109
+ line.stations.first.form.form_fields[0].field_type.should eq("short_answer")
110
+ line.stations.first.form.form_fields[0].required.should eq(true)
111
+ line.stations.first.form.form_fields[0].form_field_params.should eql({:label => "First Name", :field_type => "short_answer", :required => "true"})
112
+ line.stations.first.form.form_fields[1].label.should eq("email")
113
+ line.stations.first.form.form_fields[1].field_type.should eq("short_answer")
114
+ line.stations.first.form.form_fields[1].required.should eq(true)
115
+ line.stations.first.form.form_fields[1].valid_type.should eq("email")
116
+ line.stations.first.form.form_fields[1].form_field_params.should eql({:label => "email", :field_type => "short_answer", :valid_type => "email", :required => "true"})
117
117
  end
118
-
118
+
119
119
  it "in block DSL way with invalid form_field data" do
120
- # WebMock.allow_net_connect!
121
- VCR.use_cassette "form-fields/block/create-without-label", :record => :new_episodes do
122
- line = CF::Line.create("Digitize-0101111-final", "Digitization") do
123
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
124
- CF::Station.create({:line => self, :type => "work"}) do |station|
125
- CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
126
- CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
127
- CF::FormField.new({:form => i, :field_type => "short_answer", :required => "true"})
128
- end
120
+ WebMock.allow_net_connect!
121
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
122
+ sleep 1
123
+ line = CF::Line.create(title, "Digitization") do
124
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
125
+ CF::Station.create({:line => self, :type => "work"}) do |station|
126
+ CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
127
+ CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
128
+ CF::FormField.new({:form => i, :field_type => "short_answer", :required => "true"})
129
129
  end
130
130
  end
131
- line.stations.first.type.should eql("WorkStation")
132
- line.stations.first.form.form_fields.first.errors.should eql(["Label can't be blank"])
133
131
  end
132
+ line.stations.first.type.should eql("WorkStation")
133
+ line.stations.first.form.form_fields.first.errors.should eql(["Label can't be blank"])
134
134
  end
135
-
135
+
136
136
  it "in plain Ruby way with invalid form_field data" do
137
- # WebMock.allow_net_connect!
138
- VCR.use_cassette "form-fields/plain-ruby/create-without-label", :record => :new_episodes do
139
- line = CF::Line.new("Digitize-0", "Digitization")
140
- input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
141
- line.input_formats input_format
142
-
143
- station = CF::Station.new({:type => "work"})
144
- line.stations station
145
-
146
- worker = CF::HumanWorker.new({:number => 1, :reward => 20})
147
- line.stations.first.worker = worker
148
-
149
- form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
150
- line.stations.first.form = form
151
-
152
- form_fields_1 = CF::FormField.new({:field_type => "short_answer", :required => "true"})
153
- line.stations.first.form.form_fields form_fields_1
154
-
155
- line.stations.first.type.should eql("WorkStation")
156
- line.stations.first.form.form_fields.first.errors.should eql(["Label can't be blank"])
157
- end
137
+ WebMock.allow_net_connect!
138
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
139
+ sleep 1
140
+ line = CF::Line.new(title, "Digitization")
141
+ input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
142
+ line.input_formats input_format
143
+
144
+ station = CF::Station.new({:type => "work"})
145
+ line.stations station
146
+
147
+ worker = CF::HumanWorker.new({:number => 1, :reward => 20})
148
+ line.stations.first.worker = worker
149
+
150
+ form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
151
+ line.stations.first.form = form
152
+
153
+ form_fields_1 = CF::FormField.new({:field_type => "short_answer", :required => "true"})
154
+ line.stations.first.form.form_fields form_fields_1
155
+
156
+ line.stations.first.type.should eql("WorkStation")
157
+ line.stations.first.form.form_fields.first.errors.should eql(["Label can't be blank"])
158
158
  end
159
-
159
+
160
160
  it "should only display the attributes which are mentioned in to_s method" do
161
- VCR.use_cassette "form-fields/block/display-to_s", :record => :new_episodes do
162
- # WebMock.allow_net_connect!
163
- line = CF::Line.create("Display_form_fields", "Digitization") do
164
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
165
- CF::Station.create({:line => self, :type => "work"}) do |station|
166
- CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
167
- CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
168
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
169
- CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
170
- CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
171
- end
161
+ WebMock.allow_net_connect!
162
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
163
+ sleep 1
164
+ line = CF::Line.create(title, "Digitization") do
165
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
166
+ CF::Station.create({:line => self, :type => "work"}) do |station|
167
+ CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
168
+ CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
169
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
170
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
171
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
172
172
  end
173
173
  end
174
- line.stations.first.form.form_fields.first.to_s.should eql("{:id => => #{line.stations.first.form.form_fields.first.id}, :label => First Name, :field_type => short_answer, :required => true, :errors => }")
175
174
  end
175
+ line.stations.first.form.form_fields.first.to_s.should eql("{:id => => #{line.stations.first.form.form_fields.first.id}, :label => First Name, :field_type => short_answer, :required => true, :errors => }")
176
176
  end
177
177
  end
178
178
  end
@@ -5,54 +5,54 @@ module CF
5
5
  describe CF::RobotWorker do
6
6
  context "create a google translator worker" do
7
7
  it "should create google_translate_robot worker for first station in a plain ruby way" do
8
- # WebMock.allow_net_connect!
9
- VCR.use_cassette "robot_worker/google_translate_robot/plain-ruby/create-worker-in-first-station", :record => :new_episodes do
10
- line = CF::Line.new("google_translate_robot","Digitization")
11
- input_format = CF::InputFormat.new({:name => "text", :required => true})
12
- line.input_formats input_format
8
+ WebMock.allow_net_connect!
9
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
10
+ sleep 1
11
+ line = CF::Line.new(title,"Digitization")
12
+ input_format = CF::InputFormat.new({:name => "text", :required => true})
13
+ line.input_formats input_format
13
14
 
14
- station = CF::Station.new({:type => "work"})
15
- line.stations station
15
+ station = CF::Station.new({:type => "work"})
16
+ line.stations station
16
17
 
17
- worker = CF::RobotWorker.create({:type => "google_translate_robot", :settings => {:data => ["{{text}}"], :from => "en", :to => "es"}})
18
- line.stations.first.worker = worker
18
+ worker = CF::RobotWorker.create({:type => "google_translate_robot", :settings => {:data => ["{{text}}"], :from => "en", :to => "es"}})
19
+ line.stations.first.worker = worker
19
20
 
20
- form = CF::TaskForm.new({:title => "Enter text", :instruction => "Describe"})
21
- line.stations.first.form = form
21
+ form = CF::TaskForm.new({:title => "Enter text", :instruction => "Describe"})
22
+ line.stations.first.form = form
22
23
 
23
- line.title.should eql("google_translate_robot")
24
- line.stations.first.worker.class.should eql(CF::RobotWorker)
25
- line.stations.first.worker.number.should eql(1)
26
- line.stations.first.worker.settings.should eql({:data => ["{{text}}"], :from => "en", :to => "es"})
27
- line.stations.first.worker.type.should eql("GoogleTranslateRobot")
28
- run = CF::Run.create(line, "google_translate_robot_run", [{"text"=> "I started loving Monsoon"}])
29
- # sleep 20
30
- @final_output = run.final_output
31
- line.stations.first.worker.number.should eq(1)
32
- @final_output.first['translation_of_text'].should eql('Empecé a amar a Monzón')
33
- end
24
+ line.title.should eql(title)
25
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
26
+ line.stations.first.worker.number.should eql(1)
27
+ line.stations.first.worker.settings.should eql({:data => ["{{text}}"], :from => "en", :to => "es"})
28
+ line.stations.first.worker.type.should eql("GoogleTranslateRobot")
29
+ run = CF::Run.create(line, "google_translate_robot_run", [{"text"=> "I started loving Monsoon"}])
30
+ sleep 10
31
+ @final_output = run.final_output
32
+ line.stations.first.worker.number.should eq(1)
33
+ @final_output.first['translation_of_text'].should eql('Empecé a amar a Monzón')
34
34
  end
35
-
35
+
36
36
  it "should create google_translate_robot in block DSL way" do
37
- VCR.use_cassette "robot_worker/google_translate_robot/block/create-worker-block-dsl-way", :record => :new_episodes do
38
- # WebMock.allow_net_connect!
39
- line = CF::Line.create("google_translate_robot_1","Digitization") do |l|
40
- CF::InputFormat.new({:line => l, :name => "text", :required => true})
41
- CF::Station.create({:line => l, :type => "work"}) do |s|
42
- CF::RobotWorker.create({:station => s, :type => "google_translate_robot", :settings => {:data => ["{{text}}"], :from => "en", :to => "es"}})
43
- end
37
+ WebMock.allow_net_connect!
38
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
39
+ sleep 1
40
+ line = CF::Line.create(title,"Digitization") do |l|
41
+ CF::InputFormat.new({:line => l, :name => "text", :required => true})
42
+ CF::Station.create({:line => l, :type => "work"}) do |s|
43
+ CF::RobotWorker.create({:station => s, :type => "google_translate_robot", :settings => {:data => ["{{text}}"], :from => "en", :to => "es"}})
44
44
  end
45
- line.title.should eql("google_translate_robot_1")
46
- line.stations.first.worker.class.should eql(CF::RobotWorker)
47
- line.stations.first.worker.number.should eql(1)
48
- line.stations.first.worker.settings.should eql({:data => ["{{text}}"], :from => "en", :to => "es"})
49
- line.stations.first.worker.type.should eql("GoogleTranslateRobot")
50
- run = CF::Run.create(line, "google_translate_robot_run_1", [{"text"=> "I started loving Monsoon"}])
51
- # sleep 20
52
- @final_output = run.final_output
53
- line.stations.first.worker.number.should eq(1)
54
- @final_output.first['translation_of_text'].should eql('Empecé a amar a Monzón')
55
45
  end
46
+ line.title.should eql(title)
47
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
48
+ line.stations.first.worker.number.should eql(1)
49
+ line.stations.first.worker.settings.should eql({:data => ["{{text}}"], :from => "en", :to => "es"})
50
+ line.stations.first.worker.type.should eql("GoogleTranslateRobot")
51
+ run = CF::Run.create(line, "google_translate_robot_run_1", [{"text"=> "I started loving Monsoon"}])
52
+ sleep 10
53
+ @final_output = run.final_output
54
+ line.stations.first.worker.number.should eq(1)
55
+ @final_output.first['translation_of_text'].should eql('Empecé a amar a Monzón')
56
56
  end
57
57
  end
58
58
  end
@@ -4,127 +4,127 @@ module CF
4
4
  describe CF::HumanWorker do
5
5
  context "create a worker" do
6
6
  it "the block DSL way" do
7
- # WebMock.allow_net_connect!
8
- VCR.use_cassette "human_worker/block/create", :record => :new_episodes do
9
- line = CF::Line.create("human_worker", "Digitization") do |l|
10
- CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
11
- CF::Station.create({:line =>l, :type => "work"}) do |s|
12
- @worker = CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
13
- end
7
+ WebMock.allow_net_connect!
8
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
9
+ sleep 1
10
+ line = CF::Line.create(title, "Digitization") do |l|
11
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
12
+ CF::Station.create({:line =>l, :type => "work"}) do |s|
13
+ @worker = CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
14
14
  end
15
- line.stations.first.type.should eql("WorkStation")
16
- line.stations.first.worker.number.should eql(1)
17
- line.stations.first.worker.reward.should eql(20)
18
15
  end
16
+ line.stations.first.type.should eql("WorkStation")
17
+ line.stations.first.worker.number.should eql(1)
18
+ line.stations.first.worker.reward.should eql(20)
19
19
  end
20
20
 
21
21
  it "in block DSL way with invalid data and should set the error" do
22
- VCR.use_cassette "human_worker/block/create-with-invalid-data", :record => :new_episodes do
23
- # WebMock.allow_net_connect!
24
- line = CF::Line.create("human_worker1", "Digitization") do |l|
25
- CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
26
- CF::Station.create({:line =>l, :type => "work"}) do |s|
27
- @worker = CF::HumanWorker.new({:station => s})
28
- end
22
+ WebMock.allow_net_connect!
23
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
24
+ sleep 1
25
+ line = CF::Line.create(title, "Digitization") do |l|
26
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
27
+ CF::Station.create({:line =>l, :type => "work"}) do |s|
28
+ @worker = CF::HumanWorker.new({:station => s})
29
29
  end
30
- line.stations.first.type.should eql("WorkStation")
31
- line.stations.first.worker.errors.should eql("[\"Reward is not a number\", \"Reward can't be blank\"]")
32
30
  end
31
+ line.stations.first.type.should eql("WorkStation")
32
+ line.stations.first.worker.errors.should eql("[\"Reward is not a number\", \"Reward can't be blank\"]")
33
33
  end
34
34
 
35
35
  it "in plain ruby way with invalid data and should set the error" do
36
- # WebMock.allow_net_connect!
37
- VCR.use_cassette "human_worker/plain-ruby/create-with-invalid-data", :record => :new_episodes do
38
- line = CF::Line.new("human_worker2", "Digitization")
39
- input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
40
- line.input_formats input_format
36
+ WebMock.allow_net_connect!
37
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
38
+ sleep 1
39
+ line = CF::Line.new(title, "Digitization")
40
+ input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
41
+ line.input_formats input_format
41
42
 
42
- station = CF::Station.new({:type => "work"})
43
- line.stations station
43
+ station = CF::Station.new({:type => "work"})
44
+ line.stations station
44
45
 
45
- worker = CF::HumanWorker.new()
46
- line.stations.first.worker = worker
46
+ worker = CF::HumanWorker.new()
47
+ line.stations.first.worker = worker
47
48
 
48
- line.stations.first.type.should eql("WorkStation")
49
- line.stations.first.worker.errors.should eql("[\"Reward is not a number\", \"Reward can't be blank\"]")
50
- end
49
+ line.stations.first.type.should eql("WorkStation")
50
+ line.stations.first.worker.errors.should eql("[\"Reward is not a number\", \"Reward can't be blank\"]")
51
51
  end
52
-
52
+
53
53
  it "should only display the attributes which are mentioned in to_s method" do
54
- VCR.use_cassette "human_worker/block/display-to_s", :record => :new_episodes do
55
- # WebMock.allow_net_connect!
56
- line = CF::Line.create("Display_human_worker", "Digitization") do
57
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
58
- CF::Station.create({:line => self, :type => "work"}) do |station|
59
- CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
60
- end
54
+ WebMock.allow_net_connect!
55
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
56
+ sleep 1
57
+ line = CF::Line.create(title, "Digitization") do
58
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
59
+ CF::Station.create({:line => self, :type => "work"}) do |station|
60
+ CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
61
61
  end
62
- line.stations.first.worker.to_s.should eql("{:id => => #{line.stations.first.worker.id}, :number => 1, :reward => 20, :stat_badge => {\"approval_rating\"=>80, \"assignment_duration\"=>3600, \"abandonment_rate\"=>30, \"country\"=>nil}, :skill_badges => [nil], :errors => }")
63
62
  end
63
+ line.stations.first.worker.to_s.should eql("{:id => => #{line.stations.first.worker.id}, :number => 1, :reward => 20, :stat_badge => {\"approval_rating\"=>80, \"assignment_duration\"=>3600, \"abandonment_rate\"=>30, \"country\"=>nil}, :skill_badges => [nil], :errors => }")
64
64
  end
65
65
  end
66
66
 
67
67
  context "create a worker with skill_badge and skill_test" do
68
68
  it "the Block DSL way" do
69
- # WebMock.allow_net_connect!
70
- VCR.use_cassette "human_worker/block/create-with-badge", :record => :new_episodes do
71
- badge =
69
+ WebMock.allow_net_connect!
70
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
71
+ sleep 1
72
+ badge =
73
+ {
74
+ :title => 'Football Fanatic',
75
+ :description => "This qualification allows you to perform work at stations which have this badge.",
76
+ :max_badges => 3,
77
+ :test =>
72
78
  {
73
- :title => 'Football Fanatic',
74
- :description => "This qualification allows you to perform work at stations which have this badge.",
75
- :max_badges => 3,
76
- :test =>
77
- {
78
- :input => {:name => "Lionel Andres Messi", :country => "Argentina"},
79
- :expected_output =>
80
- [{:birthplace => "Rosario, Santa Fe, Argentina",:match_options => {:tolerance => 10, :ignore_case => true }},{:position => "CF",:match_options => {:tolerance => 1 }},{:"current-club" => "Barcelona",:match_options => {:tolerance => 1, :ignore_case => false }}]
81
- }
79
+ :input => {:name => "Lionel Andres Messi", :country => "Argentina"},
80
+ :expected_output =>
81
+ [{:birthplace => "Rosario, Santa Fe, Argentina",:match_options => {:tolerance => 10, :ignore_case => true }},{:position => "CF",:match_options => {:tolerance => 1 }},{:"current-club" => "Barcelona",:match_options => {:tolerance => 1, :ignore_case => false }}]
82
82
  }
83
- line = CF::Line.create("human_worker3", "Digitization") do |l|
84
- CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
85
- CF::Station.create({:line =>l, :type => "work"}) do |s|
86
- @worker = CF::HumanWorker.new({:station => s, :number => 1, :reward => 20, :skill_badge => badge})
87
- end
83
+ }
84
+ line = CF::Line.create(title, "Digitization") do |l|
85
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
86
+ CF::Station.create({:line =>l, :type => "work"}) do |s|
87
+ @worker = CF::HumanWorker.new({:station => s, :number => 1, :reward => 20, :skill_badge => badge})
88
88
  end
89
- line.stations.first.type.should eql("WorkStation")
90
- line.stations.first.worker.number.should eql(1)
91
- line.stations.first.worker.reward.should eql(20)
92
- line.stations.first.worker.skill_badges.first.should eql([{"title"=>"Football Fanatic", "description"=>"This qualification allows you to perform work at stations which have this badge.", "score"=>nil, "quality_rating"=>nil, "max_badges"=>3, "skill_test"=>{"score_after"=>"submit", "manual_scoring"=>false, "display_answers"=>false, "edit_answers"=>true, "retries"=>0, "pass_percentage"=>100, "test_units"=>[{"input"=>{"name"=>"Lionel Andres Messi", "country"=>"Argentina"}, "expected_output"=>[{"birthplace"=>"Rosario, Santa Fe, Argentina", "match_options"=>{"tolerance"=>"1", "ignore_case"=>"false"}, "position"=>"CF", "current-club"=>"Barcelona"}], "match_options"=>{"tolerance"=>0, "ignore_case"=>false}}]}}])
93
- line.stations.first.worker.stat_badge.should eql({"approval_rating"=>80, "assignment_duration"=>3600, "abandonment_rate"=>30, "country"=>nil})
94
89
  end
90
+ line.stations.first.type.should eql("WorkStation")
91
+ line.stations.first.worker.number.should eql(1)
92
+ line.stations.first.worker.reward.should eql(20)
93
+ line.stations.first.worker.skill_badges.first.should eql([{"title"=>"Football Fanatic", "description"=>"This qualification allows you to perform work at stations which have this badge.", "score"=>nil, "quality_rating"=>nil, "max_badges"=>3, "skill_test"=>{"score_after"=>"submit", "manual_scoring"=>false, "display_answers"=>false, "edit_answers"=>true, "retries"=>0, "pass_percentage"=>100, "test_units"=>[{"input"=>{"name"=>"Lionel Andres Messi", "country"=>"Argentina"}, "expected_output"=>[{"birthplace"=>"Rosario, Santa Fe, Argentina", "match_options"=>{"tolerance"=>"1", "ignore_case"=>"false"}, "position"=>"CF", "current-club"=>"Barcelona"}], "match_options"=>{"tolerance"=>0, "ignore_case"=>false}}]}}])
94
+ line.stations.first.worker.stat_badge.should eql({"approval_rating"=>80, "assignment_duration"=>3600, "abandonment_rate"=>30, "country"=>nil})
95
95
  end
96
96
 
97
97
  it "in plain ruby way" do
98
- # WebMock.allow_net_connect!
99
- VCR.use_cassette "human_worker/plain-ruby/create-with-badge", :record => :new_episodes do
100
- skill_badge =
98
+ WebMock.allow_net_connect!
99
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
100
+ sleep 1
101
+ skill_badge =
102
+ {
103
+ :title => 'Football Fanatic',
104
+ :description => "This qualification allows you to perform work at stations which have this badge.",
105
+ :max_badges => 3,
106
+ :test =>
101
107
  {
102
- :title => 'Football Fanatic',
103
- :description => "This qualification allows you to perform work at stations which have this badge.",
104
- :max_badges => 3,
105
- :test =>
106
- {
107
- :input => {:name => "Lionel Andres Messi", :country => "Argentina"},
108
- :expected_output =>
109
- [{:birthplace => "Rosario, Santa Fe, Argentina",:match_options => {:tolerance => 10, :ignore_case => true }},{:position => "CF",:match_options => {:tolerance => 1 }},{:"current-club" => "Barcelona",:match_options => {:tolerance => 1, :ignore_case => false }}]
110
- }
108
+ :input => {:name => "Lionel Andres Messi", :country => "Argentina"},
109
+ :expected_output =>
110
+ [{:birthplace => "Rosario, Santa Fe, Argentina",:match_options => {:tolerance => 10, :ignore_case => true }},{:position => "CF",:match_options => {:tolerance => 1 }},{:"current-club" => "Barcelona",:match_options => {:tolerance => 1, :ignore_case => false }}]
111
111
  }
112
- line = CF::Line.new("human_worker4", "Digitization")
113
- input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
114
- line.input_formats input_format
112
+ }
113
+ line = CF::Line.new(title, "Digitization")
114
+ input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
115
+ line.input_formats input_format
115
116
 
116
- station = CF::Station.new({:type => "work"})
117
- line.stations station
117
+ station = CF::Station.new({:type => "work"})
118
+ line.stations station
118
119
 
119
- worker = CF::HumanWorker.new({:number => 1, :reward => 20, :skill_badge => skill_badge})
120
- line.stations.first.worker = worker
120
+ worker = CF::HumanWorker.new({:number => 1, :reward => 20, :skill_badge => skill_badge})
121
+ line.stations.first.worker = worker
121
122
 
122
- line.stations.first.type.should eql("WorkStation")
123
- line.stations.first.worker.number.should eql(1)
124
- line.stations.first.worker.reward.should eql(20)
125
- line.stations.first.worker.skill_badges.first.should eql([{"title"=>"Football Fanatic", "description"=>"This qualification allows you to perform work at stations which have this badge.", "score"=>nil, "quality_rating"=>nil, "max_badges"=>3, "skill_test"=>{"score_after"=>"submit", "manual_scoring"=>false, "display_answers"=>false, "edit_answers"=>true, "retries"=>0, "pass_percentage"=>100, "test_units"=>[{"input"=>{"name"=>"Lionel Andres Messi", "country"=>"Argentina"}, "expected_output"=>[{"birthplace"=>"Rosario, Santa Fe, Argentina", "match_options"=>{"tolerance"=>"1", "ignore_case"=>"false"}, "position"=>"CF", "current-club"=>"Barcelona"}], "match_options"=>{"tolerance"=>0, "ignore_case"=>false}}]}}])
126
- line.stations.first.worker.stat_badge.should eql({"approval_rating"=>80, "assignment_duration"=>3600, "abandonment_rate"=>30, "country"=>nil})
127
- end
123
+ line.stations.first.type.should eql("WorkStation")
124
+ line.stations.first.worker.number.should eql(1)
125
+ line.stations.first.worker.reward.should eql(20)
126
+ line.stations.first.worker.skill_badges.first.should eql([{"title"=>"Football Fanatic", "description"=>"This qualification allows you to perform work at stations which have this badge.", "score"=>nil, "quality_rating"=>nil, "max_badges"=>3, "skill_test"=>{"score_after"=>"submit", "manual_scoring"=>false, "display_answers"=>false, "edit_answers"=>true, "retries"=>0, "pass_percentage"=>100, "test_units"=>[{"input"=>{"name"=>"Lionel Andres Messi", "country"=>"Argentina"}, "expected_output"=>[{"birthplace"=>"Rosario, Santa Fe, Argentina", "match_options"=>{"tolerance"=>"1", "ignore_case"=>"false"}, "position"=>"CF", "current-club"=>"Barcelona"}], "match_options"=>{"tolerance"=>0, "ignore_case"=>false}}]}}])
127
+ line.stations.first.worker.stat_badge.should eql({"approval_rating"=>80, "assignment_duration"=>3600, "abandonment_rate"=>30, "country"=>nil})
128
128
  end
129
129
  end
130
130
  end