cloudfactory 0.0.13
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.
- data/.gitignore +11 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/README.md +44 -0
- data/Rakefile +40 -0
- data/bin/cf +8 -0
- data/cf.gemspec +76 -0
- data/example/google_translate_app/Gemfile +12 -0
- data/example/google_translate_app/config.ru +7 -0
- data/example/google_translate_app/google_translate_input.csv +4 -0
- data/example/google_translate_app/google_translator_app.rb +53 -0
- data/example/google_translate_app/views/index.haml +2 -0
- data/example/google_translate_app/views/layout.haml +7 -0
- data/example/google_translate_app/views/run.haml +4 -0
- data/example/google_translate_app/views/style.sass +2 -0
- data/example/human_worker_app/Gemfile +12 -0
- data/example/human_worker_app/config.ru +7 -0
- data/example/human_worker_app/human_worker_app.rb +55 -0
- data/example/human_worker_app/human_worker_input.csv +5 -0
- data/example/human_worker_app/public/app.js +12 -0
- data/example/human_worker_app/temp.csv +3 -0
- data/example/human_worker_app/views/index.haml +15 -0
- data/example/human_worker_app/views/layout.haml +10 -0
- data/example/human_worker_app/views/result.haml +18 -0
- data/example/human_worker_app/views/run.haml +12 -0
- data/example/human_worker_app/views/style.sass +25 -0
- data/example/sample_yaml_files/concept_tagging_robot.yaml +18 -0
- data/example/sample_yaml_files/content_scraping_robot.yaml +19 -0
- data/example/sample_yaml_files/entity_extraction_robot.yaml +18 -0
- data/example/sample_yaml_files/google_translate_robot.yaml +20 -0
- data/example/sample_yaml_files/image_processing_robot.yaml +20 -0
- data/example/sample_yaml_files/keyword_matching_and_text_extraction_robot.yaml +26 -0
- data/example/sample_yaml_files/mailer_robot.yaml +21 -0
- data/example/sample_yaml_files/media_converter_robot.yaml +21 -0
- data/example/sample_yaml_files/media_splitting_robot.yaml +20 -0
- data/example/sample_yaml_files/multiple_skill_badge.yaml +75 -0
- data/example/sample_yaml_files/sentiment_robot.yaml +19 -0
- data/example/sample_yaml_files/skill_badge.yaml +56 -0
- data/example/sample_yaml_files/stat_badge.yaml +40 -0
- data/example/sample_yaml_files/term_extraction_robot.yaml +20 -0
- data/example/sample_yaml_files/tournament_station_and_form_fields.yaml +40 -0
- data/features/form_generation.feature +46 -0
- data/features/form_preview.feature +98 -0
- data/features/line_creation.feature +99 -0
- data/features/line_deletion.feature +50 -0
- data/features/line_generation.feature +57 -0
- data/features/run.feature +141 -0
- data/features/support/cli_steps.rb +16 -0
- data/features/support/env.rb +23 -0
- data/features/target_url.feature +82 -0
- data/fixtures/api_credentials_example.yml +4 -0
- data/fixtures/input_data/media_converter_robot.csv +2 -0
- data/fixtures/input_data/test.csv +2 -0
- data/lib/cf.rb +94 -0
- data/lib/cf/account.rb +32 -0
- data/lib/cf/cli.rb +52 -0
- data/lib/cf/cli/config.rb +87 -0
- data/lib/cf/cli/form.rb +82 -0
- data/lib/cf/cli/line.rb +237 -0
- data/lib/cf/cli/production.rb +62 -0
- data/lib/cf/cli/templates/css_file.css.erb +22 -0
- data/lib/cf/cli/templates/form_preview.html.erb +17 -0
- data/lib/cf/cli/templates/html_file.html.erb +21 -0
- data/lib/cf/cli/templates/js_file.js.erb +18 -0
- data/lib/cf/cli/templates/line.tt +55 -0
- data/lib/cf/cli/templates/sample-line/form.css +27 -0
- data/lib/cf/cli/templates/sample-line/form.html +26 -0
- data/lib/cf/cli/templates/sample-line/form.js +7 -0
- data/lib/cf/cli/templates/sample-line/line.yml.erb +67 -0
- data/lib/cf/cli/templates/sample-line/sample-line.csv +3 -0
- data/lib/cf/client.rb +56 -0
- data/lib/cf/custom_task_form.rb +136 -0
- data/lib/cf/department.rb +24 -0
- data/lib/cf/final_output.rb +20 -0
- data/lib/cf/form_field.rb +62 -0
- data/lib/cf/human_worker.rb +67 -0
- data/lib/cf/input_format.rb +134 -0
- data/lib/cf/line.rb +231 -0
- data/lib/cf/robot_worker.rb +31 -0
- data/lib/cf/run.rb +158 -0
- data/lib/cf/station.rb +340 -0
- data/lib/cf/task_form.rb +147 -0
- data/lib/cf/version.rb +3 -0
- data/lib/generators/cf/form/form_generator.rb +55 -0
- data/lib/generators/cf/form/templates/cf_form.html.erb +11 -0
- data/lib/generators/cf/install/install_generator.rb +22 -0
- data/lib/generators/cf/install/templates/README +13 -0
- data/lib/generators/cf/install/templates/cloud_factory.rb +7 -0
- data/spec/account_spec.rb +11 -0
- data/spec/badge_spec.rb +88 -0
- data/spec/concept_tagging_robot_spec.rb +54 -0
- data/spec/config_spec.rb +20 -0
- data/spec/content_scraping_robot_spec.rb +58 -0
- data/spec/custom_task_form_spec.rb +190 -0
- data/spec/department_spec.rb +14 -0
- data/spec/entity_extraction_robot_spec.rb +56 -0
- data/spec/form_field_spec.rb +126 -0
- data/spec/generators/form_generator_spec.rb +60 -0
- data/spec/generators/install_generator_spec.rb +35 -0
- data/spec/google_translate_robot_spec.rb +64 -0
- data/spec/human_worker_spec.rb +118 -0
- data/spec/image_processing_robot_spec.rb +56 -0
- data/spec/input_format_spec.rb +113 -0
- data/spec/keyword_matching_and_text_extraction_robot_spec.rb +73 -0
- data/spec/line_spec.rb +338 -0
- data/spec/mailer_robot_spec.rb +62 -0
- data/spec/media_converter_robot_spec.rb +72 -0
- data/spec/media_splitting_robot_spec.rb +62 -0
- data/spec/run_spec.rb +298 -0
- data/spec/sentiment_robot_spec.rb +56 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/station_spec.rb +256 -0
- data/spec/task_form_spec.rb +96 -0
- data/spec/term_extraction_robot_spec.rb +58 -0
- data/spec/text_appending_robot_spec.rb +86 -0
- metadata +472 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe CF::Department do
|
|
4
|
+
context "return category" do
|
|
5
|
+
it "should get all the departments" do
|
|
6
|
+
VCR.use_cassette "department/all", :record => :new_episodes do
|
|
7
|
+
departments = CF::Department.all
|
|
8
|
+
departments.map(&:name).should include("Digitization")
|
|
9
|
+
departments.map(&:name).should include("Data Processing")
|
|
10
|
+
departments.map(&:name).should include("Survey")
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
module CF
|
|
5
|
+
describe CF::RobotWorker do
|
|
6
|
+
context "create an entity extraction robot worker" do
|
|
7
|
+
it "should create entity extraction robot worker for first station in Block DSL way" do
|
|
8
|
+
# WebMock.allow_net_connect!
|
|
9
|
+
VCR.use_cassette "robot_worker/entity_extraction_robot/block/create-worker-single-station", :record => :new_episodes do
|
|
10
|
+
line = CF::Line.create("entity_extraction_robot","Digitization") do |l|
|
|
11
|
+
CF::InputFormat.new({:line => l, :name => "text", :valid_type => "general", :required => "true"})
|
|
12
|
+
CF::Station.create({:line => l, :type => "work"}) do |s|
|
|
13
|
+
CF::RobotWorker.create({:station => s, :type => "entity_extraction_robot", :settings => {:document => ["Franz Kafka and George Orwell are authors. Ludwig Von Beethoven and Mozart are musicians. China and Japan are countries"]}})
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
run = CF::Run.create(line, "entity_extraction_robot_run", [{"text"=> "Franz Kafka and George Orwell are authors. Ludwig Von Beethoven and Mozart are musicians. China and Japan are countries"}])
|
|
17
|
+
output = run.final_output
|
|
18
|
+
output.first.final_output.first.entity_counts_of_document.should eql([["2", "2", "1", "1", "2", "1"]])
|
|
19
|
+
output.first.final_output.first.entity_names_of_document.should eql([["Ludwig Von Beethoven", "Franz Kafka", "George Orwell", "Mozart", "China", "Japan"]])
|
|
20
|
+
output.first.final_output.first.entity_relevances_of_document.should eql([[92.12089999999999, 73.8997, 48.079100000000004, 28.9416, 27.1982, 21.1997]])
|
|
21
|
+
output.first.final_output.first.entity_types_of_document.should eql([["Person", "Person", "Person", "Person", "Country", "Country"]])
|
|
22
|
+
line.stations.first.worker.class.should eql(CF::RobotWorker)
|
|
23
|
+
line.stations.first.worker.reward.should eql(5)
|
|
24
|
+
line.stations.first.worker.number.should eql(1)
|
|
25
|
+
line.stations.first.worker.settings.should eql({:document => ["Franz Kafka and George Orwell are authors. Ludwig Von Beethoven and Mozart are musicians. China and Japan are countries"]})
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should create entity extraction robot worker for first station in a plain ruby way" do
|
|
30
|
+
# WebMock.allow_net_connect!
|
|
31
|
+
VCR.use_cassette "robot_worker/entity_extraction_robot/plain-ruby/create-worker-in-first-station", :record => :new_episodes do
|
|
32
|
+
line = CF::Line.new("entity_extraction_robot_1","Digitization")
|
|
33
|
+
input_format = CF::InputFormat.new({:name => "text", :required => "true", :valid_type => "general"})
|
|
34
|
+
line.input_formats input_format
|
|
35
|
+
|
|
36
|
+
station = CF::Station.new({:type => "work"})
|
|
37
|
+
line.stations station
|
|
38
|
+
|
|
39
|
+
worker = CF::RobotWorker.create({:type => "entity_extraction_robot", :settings => {:document => ["Franz Kafka and George Orwell are authors. Ludwig Von Beethoven and Mozart are musicians. China and Japan are countries"]}})
|
|
40
|
+
line.stations.first.worker = worker
|
|
41
|
+
|
|
42
|
+
run = CF::Run.create(line, "entity_extraction_robot_run_1", [{"text"=> "Franz Kafka and George Orwell are authors. Ludwig Von Beethoven and Mozart are musicians. China and Japan are countries"}])
|
|
43
|
+
output = run.final_output
|
|
44
|
+
output.first.final_output.first.entity_counts_of_document.should eql([["2", "2", "1", "1", "2", "1"]])
|
|
45
|
+
output.first.final_output.first.entity_names_of_document.should eql([["Ludwig Von Beethoven", "Franz Kafka", "George Orwell", "Mozart", "China", "Japan"]])
|
|
46
|
+
output.first.final_output.first.entity_relevances_of_document.should eql([[92.12089999999999, 73.8997, 48.079100000000004, 28.9416, 27.1982, 21.1997]])
|
|
47
|
+
output.first.final_output.first.entity_types_of_document.should eql([["Person", "Person", "Person", "Person", "Country", "Country"]])
|
|
48
|
+
line.stations.first.worker.class.should eql(CF::RobotWorker)
|
|
49
|
+
line.stations.first.worker.reward.should eql(5)
|
|
50
|
+
line.stations.first.worker.number.should eql(1)
|
|
51
|
+
line.stations.first.worker.settings.should eql({:document => ["Franz Kafka and George Orwell are authors. Ludwig Von Beethoven and Mozart are musicians. China and Japan are countries"]})
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe CF::FormField do
|
|
4
|
+
context "create an form_field" do
|
|
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
|
+
station = CF::Station.new({:type => "work"})
|
|
10
|
+
line.stations station
|
|
11
|
+
|
|
12
|
+
worker = CF::HumanWorker.new({:number => 2, :reward => 20})
|
|
13
|
+
line.stations.first.worker = worker
|
|
14
|
+
|
|
15
|
+
form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
|
|
16
|
+
line.stations.first.form = form
|
|
17
|
+
|
|
18
|
+
form_fields_1 = CF::FormField.new({:label => "First Name", :field_type => "SA", :required => "true"})
|
|
19
|
+
line.stations.first.form.form_fields form_fields_1
|
|
20
|
+
form_fields_2 = CF::FormField.new({:label => "Middle Name", :field_type => "SA"})
|
|
21
|
+
line.stations.first.form.form_fields form_fields_2
|
|
22
|
+
form_fields_3 = CF::FormField.new({:label => "Last Name", :field_type => "SA", :required => "true"})
|
|
23
|
+
line.stations.first.form.form_fields form_fields_3
|
|
24
|
+
form_fields_3 = CF::FormField.new({:label => "Gender", :field_type => "RB", :required => "true", :option_values => ["male","female"]})
|
|
25
|
+
line.stations.first.form.form_fields form_fields_3
|
|
26
|
+
|
|
27
|
+
line.stations.first.form.form_fields[0].label.should eq("First Name")
|
|
28
|
+
line.stations.first.form.form_fields[0].field_type.should eq("SA")
|
|
29
|
+
line.stations.first.form.form_fields[0].required.should eq(true)
|
|
30
|
+
line.stations.first.form.form_fields[0].form_field_params.should eql({:label => "First Name", :field_type => "SA", :required => "true"})
|
|
31
|
+
line.stations.first.form.form_fields[1].label.should eq("Middle Name")
|
|
32
|
+
line.stations.first.form.form_fields[1].field_type.should eq("SA")
|
|
33
|
+
line.stations.first.form.form_fields[1].form_field_params.should eql({:label => "Middle Name", :field_type => "SA"})
|
|
34
|
+
line.stations.first.form.form_fields[2].label.should eq("Last Name")
|
|
35
|
+
line.stations.first.form.form_fields[2].field_type.should eq("SA")
|
|
36
|
+
line.stations.first.form.form_fields[2].required.should eq(true)
|
|
37
|
+
line.stations.first.form.form_fields[2].form_field_params.should eql({:label => "Last Name", :field_type => "SA", :required => "true"})
|
|
38
|
+
line.stations.first.form.form_fields[3].label.should eq("Gender")
|
|
39
|
+
line.stations.first.form.form_fields[3].field_type.should eq("RB")
|
|
40
|
+
line.stations.first.form.form_fields[3].required.should eq(true)
|
|
41
|
+
line.stations.first.form.form_fields[3].form_field_params.should eql({:label => "Gender", :field_type => "RB", :required => "true", :option_values => ["male","female"]})
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "in block DSL way" do
|
|
46
|
+
# WebMock.allow_net_connect!
|
|
47
|
+
VCR.use_cassette "form-fields/block/create-using-block", :record => :new_episodes do
|
|
48
|
+
line = CF::Line.create("Digitize-0101111-final", "Digitization") do
|
|
49
|
+
CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
|
|
50
|
+
CF::Station.create({:line => self, :type => "work"}) do |station|
|
|
51
|
+
CF::HumanWorker.new({:station => station, :number => 2, :reward => 20})
|
|
52
|
+
CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
|
53
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
|
|
54
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
|
|
55
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
|
|
56
|
+
CF::FormField.new({:form => i, :label => "Gender", :field_type => "RB", :required => "true", :option_values => ["male","female"]})
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
line.title.should eq("Digitize-0101111-final")
|
|
61
|
+
line.department_name.should eq("Digitization")
|
|
62
|
+
line.input_formats.first.name.should eql("image_url")
|
|
63
|
+
line.stations.first.type.should eq("WorkStation")
|
|
64
|
+
line.stations.first.worker.number.should eq(2)
|
|
65
|
+
line.stations.first.form.instruction.should eq("Describe")
|
|
66
|
+
line.stations.first.form.form_fields[0].label.should eq("First Name")
|
|
67
|
+
line.stations.first.form.form_fields[0].field_type.should eq("SA")
|
|
68
|
+
line.stations.first.form.form_fields[0].required.should eq(true)
|
|
69
|
+
line.stations.first.form.form_fields[0].form_field_params.should eql({:label => "First Name", :field_type => "SA", :required => "true"})
|
|
70
|
+
line.stations.first.form.form_fields[1].label.should eq("Middle Name")
|
|
71
|
+
line.stations.first.form.form_fields[1].field_type.should eq("SA")
|
|
72
|
+
line.stations.first.form.form_fields[1].form_field_params.should eql({:label => "Middle Name", :field_type => "SA"})
|
|
73
|
+
line.stations.first.form.form_fields[2].label.should eq("Last Name")
|
|
74
|
+
line.stations.first.form.form_fields[2].field_type.should eq("SA")
|
|
75
|
+
line.stations.first.form.form_fields[2].required.should eq(true)
|
|
76
|
+
line.stations.first.form.form_fields[2].form_field_params.should eql({:label => "Last Name", :field_type => "SA", :required => "true"})
|
|
77
|
+
line.stations.first.form.form_fields[3].label.should eq("Gender")
|
|
78
|
+
line.stations.first.form.form_fields[3].field_type.should eq("RB")
|
|
79
|
+
line.stations.first.form.form_fields[3].required.should eq(true)
|
|
80
|
+
line.stations.first.form.form_fields[3].form_field_params.should eql({:label => "Gender", :field_type => "RB", :required => "true", :option_values => ["male","female"]})
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "in block DSL way with invalid form_field data" do
|
|
85
|
+
# WebMock.allow_net_connect!
|
|
86
|
+
VCR.use_cassette "form-fields/block/create-without-label", :record => :new_episodes do
|
|
87
|
+
line = CF::Line.create("Digitize-0101111-final", "Digitization") do
|
|
88
|
+
CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
|
|
89
|
+
CF::Station.create({:line => self, :type => "work"}) do |station|
|
|
90
|
+
CF::HumanWorker.new({:station => station, :number => 2, :reward => 20})
|
|
91
|
+
CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
|
92
|
+
CF::FormField.new({:form => i, :field_type => "SA", :required => "true"})
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
line.stations.first.type.should eql("WorkStation")
|
|
97
|
+
line.stations.first.form.form_fields.first.errors.should eql(["Label can't be blank"])
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "in plain Ruby way with invalid form_field data" do
|
|
102
|
+
# WebMock.allow_net_connect!
|
|
103
|
+
VCR.use_cassette "form-fields/plain-ruby/create-without-label", :record => :new_episodes do
|
|
104
|
+
line = CF::Line.new("Digitize-0", "Digitization")
|
|
105
|
+
input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
|
|
106
|
+
line.input_formats input_format
|
|
107
|
+
|
|
108
|
+
station = CF::Station.new({:type => "work"})
|
|
109
|
+
line.stations station
|
|
110
|
+
|
|
111
|
+
worker = CF::HumanWorker.new({:number => 2, :reward => 20})
|
|
112
|
+
line.stations.first.worker = worker
|
|
113
|
+
|
|
114
|
+
form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
|
|
115
|
+
line.stations.first.form = form
|
|
116
|
+
|
|
117
|
+
form_fields_1 = CF::FormField.new({:field_type => "SA", :required => "true"})
|
|
118
|
+
line.stations.first.form.form_fields form_fields_1
|
|
119
|
+
|
|
120
|
+
line.stations.first.type.should eql("WorkStation")
|
|
121
|
+
line.stations.first.form.form_fields.first.errors.should eql(["Label can't be blank"])
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'rails/all'
|
|
3
|
+
require 'rails/generators/test_case'
|
|
4
|
+
require 'generator_spec/test_case'
|
|
5
|
+
|
|
6
|
+
require 'generators/cf/form/form_generator'
|
|
7
|
+
|
|
8
|
+
module Cf
|
|
9
|
+
module Generators
|
|
10
|
+
describe FormGenerator, "Passing both the Labels and Field:Type" do
|
|
11
|
+
include GeneratorSpec::TestCase
|
|
12
|
+
destination File.expand_path("../tmp", __FILE__)
|
|
13
|
+
arguments %w([company,website] CEO:string Website:url)
|
|
14
|
+
|
|
15
|
+
before { prepare_destination }
|
|
16
|
+
|
|
17
|
+
specify "should generate the custom task form for a rails app with labels and fields" do
|
|
18
|
+
run_generator
|
|
19
|
+
destination_root.should have_structure {
|
|
20
|
+
directory "app" do
|
|
21
|
+
directory "cf_forms" do
|
|
22
|
+
file "company_website_form.html" do
|
|
23
|
+
contains "<!-- CloudFactory Custom Task Form -->"
|
|
24
|
+
contains "<label>{{company}}</label>"
|
|
25
|
+
contains "<label>{{website}}</label>"
|
|
26
|
+
contains '<p><label>CEO</label><input id="ceo" type="text" name="output[ceo]" data-valid-type="string" /></p>'
|
|
27
|
+
contains '<p><label>Website</label><input id="website" type="text" name="output[website]" data-valid-type="url" /></p>'
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe FormGenerator, "Passing only the Field:Type without Label. e.g. for forms like Survey" do
|
|
36
|
+
include GeneratorSpec::TestCase
|
|
37
|
+
destination File.expand_path("../tmp", __FILE__)
|
|
38
|
+
arguments %w(CEO:string Website:url)
|
|
39
|
+
|
|
40
|
+
before { prepare_destination }
|
|
41
|
+
|
|
42
|
+
specify "should generate the custom task form for a rails app with fields only" do
|
|
43
|
+
run_generator
|
|
44
|
+
destination_root.should have_structure {
|
|
45
|
+
directory "app" do
|
|
46
|
+
directory "cf_forms" do
|
|
47
|
+
file "custom_task_form.html" do
|
|
48
|
+
contains "<!-- CloudFactory Custom Task Form -->"
|
|
49
|
+
contains '<p><label>CEO</label><input id="ceo" type="text" name="output[ceo]" data-valid-type="string" /></p>'
|
|
50
|
+
contains '<p><label>Website</label><input id="website" type="text" name="output[website]" data-valid-type="url" /></p>'
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
}
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'rails/all'
|
|
3
|
+
require 'rails/generators/test_case'
|
|
4
|
+
require 'generator_spec/test_case'
|
|
5
|
+
|
|
6
|
+
require 'generators/cf/install/install_generator'
|
|
7
|
+
|
|
8
|
+
module Cf
|
|
9
|
+
module Generators
|
|
10
|
+
describe InstallGenerator, "using custom matcher" do
|
|
11
|
+
include GeneratorSpec::TestCase
|
|
12
|
+
destination File.expand_path("../tmp", __FILE__)
|
|
13
|
+
arguments %w(valid_api_key)
|
|
14
|
+
|
|
15
|
+
before do
|
|
16
|
+
prepare_destination
|
|
17
|
+
run_generator
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
specify "should generate the initializer for a rails app" do
|
|
21
|
+
run_generator
|
|
22
|
+
destination_root.should have_structure {
|
|
23
|
+
directory "config" do
|
|
24
|
+
directory "initializers" do
|
|
25
|
+
file "cloud_factory.rb" do
|
|
26
|
+
contains "# CloudFactory Initializer"
|
|
27
|
+
contains "valid_api_key"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
module CF
|
|
5
|
+
describe CF::RobotWorker do
|
|
6
|
+
context "create a google translator worker" do
|
|
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, :valid_type => "general"})
|
|
12
|
+
line.input_formats input_format
|
|
13
|
+
|
|
14
|
+
station = CF::Station.new({:type => "work"})
|
|
15
|
+
line.stations station
|
|
16
|
+
|
|
17
|
+
worker = CF::RobotWorker.create({:type => "google_translate_robot", :settings => {:data => ["{text}"], :from => "en", :to => "es"}})
|
|
18
|
+
line.stations.first.worker = worker
|
|
19
|
+
|
|
20
|
+
form = CF::TaskForm.new({:title => "Enter text", :instruction => "Describe"})
|
|
21
|
+
line.stations.first.form = form
|
|
22
|
+
|
|
23
|
+
form_fields = CF::FormField.new({:label => "Description", :field_type => "SA", :required => "true"})
|
|
24
|
+
line.stations.first.form.form_fields form_fields
|
|
25
|
+
line.title.should eql("google_translate_robot")
|
|
26
|
+
line.stations.first.worker.class.should eql(CF::RobotWorker)
|
|
27
|
+
line.stations.first.worker.number.should eql(1)
|
|
28
|
+
line.stations.first.worker.settings.should eql({:data => ["{text}"], :from => "en", :to => "es"})
|
|
29
|
+
line.stations.first.worker.type.should eql("GoogleTranslateRobot")
|
|
30
|
+
run = CF::Run.create(line, "google_translate_robot_run", [{"text"=> "I started loving Monsoon", "meta_data_text"=>"monsoon"}])
|
|
31
|
+
|
|
32
|
+
@final_output = run.final_output
|
|
33
|
+
line.stations.first.worker.number.should eq(1)
|
|
34
|
+
@final_output.first.final_output.first.translation_of_text.should eql('Empecé a amar a Monzón')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should create google_translate_robot in block DSL way" do
|
|
39
|
+
VCR.use_cassette "robot_worker/google_translate_robot/block/create-worker-block-dsl-way", :record => :new_episodes do
|
|
40
|
+
# WebMock.allow_net_connect!
|
|
41
|
+
line = CF::Line.create("google_translate_robot_1","Digitization") do |l|
|
|
42
|
+
CF::InputFormat.new({:line => l, :name => "text", :required => true, :valid_type => "general"})
|
|
43
|
+
CF::Station.create({:line => l, :type => "work"}) do |s|
|
|
44
|
+
CF::RobotWorker.create({:station => s, :type => "google_translate_robot", :settings => {:data => ["{text}"], :from => "en", :to => "es"}})
|
|
45
|
+
CF::TaskForm.create({:station => s, :title => "Enter text", :instruction => "Describe"}) do |i|
|
|
46
|
+
CF::FormField.new({:form => i, :label => "Description", :field_type => "SA", :required => "true"})
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
line.title.should eql("google_translate_robot_1")
|
|
51
|
+
line.stations.first.worker.class.should eql(CF::RobotWorker)
|
|
52
|
+
line.stations.first.worker.number.should eql(1)
|
|
53
|
+
line.stations.first.worker.settings.should eql({:data => ["{text}"], :from => "en", :to => "es"})
|
|
54
|
+
line.stations.first.worker.type.should eql("GoogleTranslateRobot")
|
|
55
|
+
run = CF::Run.create(line, "google_translate_robot_run_1", [{"text"=> "I started loving Monsoon", "meta_data_text"=>"monsoon"}])
|
|
56
|
+
|
|
57
|
+
@final_output = run.final_output
|
|
58
|
+
line.stations.first.worker.number.should eq(1)
|
|
59
|
+
@final_output.first.final_output.first.translation_of_text.should eql('Empecé a amar a Monzón')
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module CF
|
|
4
|
+
describe CF::HumanWorker do
|
|
5
|
+
context "create a worker" do
|
|
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 => 2, :reward => 20})
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
line.stations.first.type.should eql("WorkStation")
|
|
16
|
+
line.stations.first.worker.number.should eql(2)
|
|
17
|
+
line.stations.first.worker.reward.should eql(20)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
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
|
|
29
|
+
end
|
|
30
|
+
line.stations.first.type.should eql("WorkStation")
|
|
31
|
+
line.stations.first.worker.errors.should eql("[\"Reward is not a number\", \"Reward must not contain decimal places\"]")
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
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
|
|
41
|
+
|
|
42
|
+
station = CF::Station.new({:type => "work"})
|
|
43
|
+
line.stations station
|
|
44
|
+
|
|
45
|
+
worker = CF::HumanWorker.new()
|
|
46
|
+
line.stations.first.worker = worker
|
|
47
|
+
|
|
48
|
+
line.stations.first.type.should eql("WorkStation")
|
|
49
|
+
line.stations.first.worker.errors.should eql("[\"Reward is not a number\", \"Reward must not contain decimal places\"]")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "create a worker with skill_badge and skill_test" do
|
|
55
|
+
it "the Block DSL way" do
|
|
56
|
+
# WebMock.allow_net_connect!
|
|
57
|
+
VCR.use_cassette "human_worker/block/create-with-badge", :record => :new_episodes do
|
|
58
|
+
badge =
|
|
59
|
+
{
|
|
60
|
+
:title => 'Football Fanatic',
|
|
61
|
+
:description => "This qualification allows you to perform work at stations which have this badge.",
|
|
62
|
+
:max_badges => 3,
|
|
63
|
+
:test =>
|
|
64
|
+
{
|
|
65
|
+
:input => {:name => "Lionel Andres Messi", :country => "Argentina"},
|
|
66
|
+
:expected_output =>
|
|
67
|
+
[{: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 }}]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
line = CF::Line.create("human_worker3", "Digitization") do |l|
|
|
71
|
+
CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
|
|
72
|
+
CF::Station.create({:line =>l, :type => "work"}) do |s|
|
|
73
|
+
@worker = CF::HumanWorker.new({:station => s, :number => 2, :reward => 20, :skill_badge => badge})
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
line.stations.first.type.should eql("WorkStation")
|
|
77
|
+
line.stations.first.worker.number.should eql(2)
|
|
78
|
+
line.stations.first.worker.reward.should eql(20)
|
|
79
|
+
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, "speed"=>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}}]}}])
|
|
80
|
+
line.stations.first.worker.stat_badge.should eql({"approval_rating"=>80, "assignment_duration"=>3600, "abandonment_rate"=>30, "country"=>nil})
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "in plain ruby way" do
|
|
85
|
+
# WebMock.allow_net_connect!
|
|
86
|
+
VCR.use_cassette "human_worker/plain-ruby/create-with-badge", :record => :new_episodes do
|
|
87
|
+
skill_badge =
|
|
88
|
+
{
|
|
89
|
+
:title => 'Football Fanatic',
|
|
90
|
+
:description => "This qualification allows you to perform work at stations which have this badge.",
|
|
91
|
+
:max_badges => 3,
|
|
92
|
+
:test =>
|
|
93
|
+
{
|
|
94
|
+
:input => {:name => "Lionel Andres Messi", :country => "Argentina"},
|
|
95
|
+
:expected_output =>
|
|
96
|
+
[{: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 }}]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
line = CF::Line.new("human_worker4", "Digitization")
|
|
100
|
+
input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
|
|
101
|
+
line.input_formats input_format
|
|
102
|
+
|
|
103
|
+
station = CF::Station.new({:type => "work"})
|
|
104
|
+
line.stations station
|
|
105
|
+
|
|
106
|
+
worker = CF::HumanWorker.new({:number => 2, :reward => 20, :skill_badge => skill_badge})
|
|
107
|
+
line.stations.first.worker = worker
|
|
108
|
+
|
|
109
|
+
line.stations.first.type.should eql("WorkStation")
|
|
110
|
+
line.stations.first.worker.number.should eql(2)
|
|
111
|
+
line.stations.first.worker.reward.should eql(20)
|
|
112
|
+
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, "speed"=>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}}]}}])
|
|
113
|
+
line.stations.first.worker.stat_badge.should eql({"approval_rating"=>80, "assignment_duration"=>3600, "abandonment_rate"=>30, "country"=>nil})
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|