cloudfactory 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- 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,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module CF
|
5
|
+
describe CF::RobotWorker do
|
6
|
+
context "create an image processing robot worker" do
|
7
|
+
it "should create image processing robot worker for first station in Block DSL way" do
|
8
|
+
# WebMock.allow_net_connect!
|
9
|
+
VCR.use_cassette "robot_worker/image_processing_robot/block/create-worker-single-station", :record => :new_episodes do
|
10
|
+
line = CF::Line.create("image_processing_robot","Digitization") do |l|
|
11
|
+
CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
|
12
|
+
CF::Station.create({:line => l, :type => "work"}) do |s|
|
13
|
+
CF::RobotWorker.create({:station => s, :type => "image_processing_robot", :settings => {:image => ["{url}"], :sharpen => {:radius => "10"}}})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
run = CF::Run.create(line, "image_processing_robot_run", [{"url"=> "http://wwwdelivery.superstock.com/WI/223/1527/PreviewComp/SuperStock_1527R-020214.jpg"}])
|
17
|
+
output = run.final_output
|
18
|
+
converted_url = output.first.final_output.first.processed_image_of_url
|
19
|
+
File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url}").should eql(true)
|
20
|
+
output.first.final_output.first.sharpen.radius.should eql("10")
|
21
|
+
line.stations.first.worker.class.should eql(CF::RobotWorker)
|
22
|
+
line.stations.first.worker.reward.should eql(0)
|
23
|
+
line.stations.first.worker.number.should eql(1)
|
24
|
+
line.stations.first.worker.settings.should eql({:image => ["{url}"], :sharpen => {:radius => "10"}})
|
25
|
+
line.stations.first.worker.type.should eql("ImageProcessingRobot")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should create image processing robot worker for first station in a plain ruby way" do
|
30
|
+
# WebMock.allow_net_connect!
|
31
|
+
VCR.use_cassette "robot_worker/image_processing_robot/plain-ruby/create-worker-in-first-station", :record => :new_episodes do
|
32
|
+
line = CF::Line.new("image_processing_robot_1","Digitization")
|
33
|
+
input_format = CF::InputFormat.new({:name => "url", :required => true, :valid_type => "url"})
|
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 => "image_processing_robot", :settings => {:image => ["{url}"], :sharpen => {:radius => "10"}}})
|
40
|
+
line.stations.first.worker = worker
|
41
|
+
|
42
|
+
run = CF::Run.create(line, "image_processing_robot_run_1", [{"url"=> "http://wwwdelivery.superstock.com/WI/223/1527/PreviewComp/SuperStock_1527R-020214.jpg"}])
|
43
|
+
output = run.final_output
|
44
|
+
converted_url = output.first.final_output.first.processed_image_of_url
|
45
|
+
File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url}").should eql(true)
|
46
|
+
output.first.final_output.first.sharpen.radius.should eql("10")
|
47
|
+
line.stations.first.worker.class.should eql(CF::RobotWorker)
|
48
|
+
line.stations.first.worker.reward.should eql(0)
|
49
|
+
line.stations.first.worker.number.should eql(1)
|
50
|
+
line.stations.first.worker.settings.should eql({:image => ["{url}"], :sharpen => {:radius => "10"}})
|
51
|
+
line.stations.first.worker.type.should eql("ImageProcessingRobot")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CF::InputFormat do
|
4
|
+
context "create an input header" do
|
5
|
+
it "in plain ruby way within line" do
|
6
|
+
# WebMock.allow_net_connect!
|
7
|
+
VCR.use_cassette "input_formats/plain-ruby/create-within-line", :record => :new_episodes do
|
8
|
+
line = CF::Line.new("Digitize","Digitization")
|
9
|
+
input_format = CF::InputFormat.new({:name => "Company", :required => true, :valid_type => "general"})
|
10
|
+
line.input_formats input_format
|
11
|
+
line.input_formats.first.name.should eql("Company")
|
12
|
+
line.input_formats.first.valid_type.should eql("general")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "in plain ruby way within station" do
|
17
|
+
# WebMock.allow_net_connect!
|
18
|
+
VCR.use_cassette "input_formats/plain-ruby/create", :record => :new_episodes do
|
19
|
+
attrs = {:name => "image_url",
|
20
|
+
:required => true,
|
21
|
+
:valid_type => "url"
|
22
|
+
}
|
23
|
+
|
24
|
+
line = CF::Line.new("Digitize-121","Digitization")
|
25
|
+
input_format = CF::InputFormat.new(attrs)
|
26
|
+
line.input_formats input_format
|
27
|
+
input_format1 = CF::InputFormat.new({:name => "image", :required => true, :valid_type => "url"})
|
28
|
+
line.input_formats input_format1
|
29
|
+
station = CF::Station.new({:type => "work"})
|
30
|
+
line.stations station
|
31
|
+
|
32
|
+
line.title.should eq("Digitize-121")
|
33
|
+
line.input_formats.first.name.should eq("image_url")
|
34
|
+
line.input_formats.first.required.should eq(true)
|
35
|
+
line.input_formats.first.valid_type.should eq("url")
|
36
|
+
line.input_formats.last.name.should eq("image")
|
37
|
+
line.input_formats.last.required.should eq(true)
|
38
|
+
line.input_formats.last.valid_type.should eq("url")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "in block DSL way within line" do
|
43
|
+
# WebMock.allow_net_connect!
|
44
|
+
VCR.use_cassette "input_formats/block/create-input-headers-of-line", :record => :new_episodes do
|
45
|
+
line = CF::Line.create("Digitize-2","Digitization") do |l|
|
46
|
+
CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
|
47
|
+
CF::InputFormat.new({:line => l, :name => "image", :required => true, :valid_type => "url"})
|
48
|
+
end
|
49
|
+
line.input_formats[0].name.should eq("image_url")
|
50
|
+
line.input_formats[1].name.should eq("image")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "in block DSL way within station" do
|
55
|
+
# WebMock.allow_net_connect!
|
56
|
+
VCR.use_cassette "input_formats/block/create-input-headers-of-station", :record => :new_episodes do
|
57
|
+
line = CF::Line.create("Digitize-3","Digitization") do |l|
|
58
|
+
CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
|
59
|
+
CF::InputFormat.new({:line => l, :name => "image", :required => true, :valid_type => "url"})
|
60
|
+
CF::Station.new({:line => l, :type => "work"})
|
61
|
+
end
|
62
|
+
line.input_formats[0].name.should eq("image_url")
|
63
|
+
line.input_formats[1].name.should eq("image")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "return all the input headers" do
|
69
|
+
it "should return all the input headers of a line " do
|
70
|
+
# WebMock.allow_net_connect!
|
71
|
+
VCR.use_cassette "input_formats/block/input-headers-of-line", :record => :new_episodes do
|
72
|
+
line = CF::Line.create("Digitize-111","Digitization") do |l|
|
73
|
+
CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
|
74
|
+
CF::InputFormat.new({:line => l, :name => "image", :required => true, :valid_type => "url"})
|
75
|
+
CF::Station.new({:line => l, :type => "work"})
|
76
|
+
end
|
77
|
+
input_formats_of_line = CF::InputFormat.all(line)
|
78
|
+
# => getting input_formats response need to be modified
|
79
|
+
input_formats_of_line.map(&:name).should include("image_url")
|
80
|
+
input_formats_of_line.map(&:name).should include("image")
|
81
|
+
input_formats_of_line.map(&:valid_type).should include("url")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "create an input_format" do
|
87
|
+
it "in Block DSL way without name to set the error attribute" do
|
88
|
+
# WebMock.allow_net_connect!
|
89
|
+
VCR.use_cassette "input_formats/block/create-invalid-input-formats", :record => :new_episodes do
|
90
|
+
line = CF::Line.create("Digitize-2","Digitization") do |l|
|
91
|
+
CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
|
92
|
+
CF::InputFormat.new({:line => l, :required => true, :valid_type => "url"})
|
93
|
+
end
|
94
|
+
line.input_formats[0].name.should eq("image_url")
|
95
|
+
line.input_formats[1].errors.should eql(["Name can't be blank"])
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "in plain Ruby way with invalid data to set the error attribute" do
|
100
|
+
# WebMock.allow_net_connect!
|
101
|
+
VCR.use_cassette "input_formats/plain-ruby/create-invalid-input-formats", :record => :new_episodes do
|
102
|
+
line = CF::Line.new("Digitize-3","Digitization")
|
103
|
+
input_format_1 = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
|
104
|
+
line.input_formats input_format_1
|
105
|
+
input_format_2 = CF::InputFormat.new({:required => true, :valid_type => "url"})
|
106
|
+
line.input_formats input_format_2
|
107
|
+
|
108
|
+
line.input_formats[0].name.should eq("image_url")
|
109
|
+
line.input_formats[1].errors.should eql(["Name can't be blank"])
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module CF
|
5
|
+
describe CF::RobotWorker do
|
6
|
+
context "create a keyword matching robot worker and text extraction robot" do
|
7
|
+
it "should create keyword matching robot worker for first station in Block DSL way" do
|
8
|
+
# WebMock.allow_net_connect!
|
9
|
+
VCR.use_cassette "robot_worker/keyword_matching_robot/block/create-worker-single-station", :record => :new_episodes do
|
10
|
+
line = CF::Line.create("keyword_matching_robot","Digitization") do |l|
|
11
|
+
CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
|
12
|
+
CF::Station.create({:line => l, :type => "work"}) do |s|
|
13
|
+
CF::RobotWorker.create({:station => s, :type => "text_extraction_robot", :settings => {:url => ["{url}"]}})
|
14
|
+
end
|
15
|
+
CF::Station.create({:line => l, :type => "work"}) do |s1|
|
16
|
+
CF::RobotWorker.create({:station => s1, :type => "keyword_matching_robot", :settings => {:content => ["{contents_of_url}"], :keywords => ["SaaS","see","additional","deepak","saroj"]}})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
run = CF::Run.create(line, "keyword_matching_robot_run", [{"url"=> "http://techcrunch.com/2011/07/26/with-v2-0-assistly-brings-a-simple-pricing-model-rewards-and-a-bit-of-free-to-customer-service-software"}])
|
20
|
+
output = run.final_output
|
21
|
+
output.first.final_output.first.included_keywords_count_in_contents_of_url.should eql(["3", "2", "2"])
|
22
|
+
output.first.final_output.first.keyword_included_in_contents_of_url.should eql(["SaaS", "see", "additional"])
|
23
|
+
line.stations.first.worker.class.should eql(CF::RobotWorker)
|
24
|
+
line.stations.first.worker.reward.should eql(1)
|
25
|
+
line.stations.first.worker.number.should eql(1)
|
26
|
+
line.stations.first.worker.settings.should eql({:url => ["{url}"]})
|
27
|
+
line.stations.first.worker.type.should eql("TextExtractionRobot")
|
28
|
+
line.stations.last.worker.class.should eql(CF::RobotWorker)
|
29
|
+
line.stations.last.worker.reward.should eql(1)
|
30
|
+
line.stations.last.worker.number.should eql(1)
|
31
|
+
line.stations.last.worker.settings.should eql({:content => ["{contents_of_url}"], :keywords => ["SaaS","see","additional","deepak","saroj"]})
|
32
|
+
line.stations.last.worker.type.should eql("KeywordMatchingRobot")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should create keyword matching robot worker for first station in a plain ruby way" do
|
37
|
+
# WebMock.allow_net_connect!
|
38
|
+
VCR.use_cassette "robot_worker/keyword_matching_robot/plain-ruby/create-worker-in-first-station", :record => :new_episodes do
|
39
|
+
line = CF::Line.new("keyword_matching_robot_1","Digitization")
|
40
|
+
input_format = CF::InputFormat.new({:name => "url", :required => true, :valid_type => "url"})
|
41
|
+
line.input_formats input_format
|
42
|
+
|
43
|
+
station = CF::Station.new({:type => "work"})
|
44
|
+
line.stations station
|
45
|
+
|
46
|
+
worker = CF::RobotWorker.create({:type => "text_extraction_robot", :settings => {:url => ["{url}"]}})
|
47
|
+
line.stations.first.worker = worker
|
48
|
+
|
49
|
+
station_1 = CF::Station.new({:type => "work"})
|
50
|
+
line.stations station
|
51
|
+
|
52
|
+
worker = CF::RobotWorker.create({:type => "keyword_matching_robot", :settings => {:content => ["{contents_of_url}"], :keywords => ["SaaS","see","additional","deepak","saroj"]}})
|
53
|
+
line.stations.last.worker = worker
|
54
|
+
|
55
|
+
run = CF::Run.create(line, "keyword_matching_robot_run_1", [{"url"=> "http://techcrunch.com/2011/07/26/with-v2-0-assistly-brings-a-simple-pricing-model-rewards-and-a-bit-of-free-to-customer-service-software"}])
|
56
|
+
output = run.final_output
|
57
|
+
output.first.final_output.first.included_keywords_count_in_contents_of_url.should eql(["3", "2", "2"])
|
58
|
+
output.first.final_output.first.keyword_included_in_contents_of_url.should eql(["SaaS", "see", "additional"])
|
59
|
+
line.stations.first.worker.class.should eql(CF::RobotWorker)
|
60
|
+
line.stations.first.worker.reward.should eql(1)
|
61
|
+
line.stations.first.worker.number.should eql(1)
|
62
|
+
line.stations.first.worker.settings.should eql({:url => ["{url}"]})
|
63
|
+
line.stations.first.worker.type.should eql("TextExtractionRobot")
|
64
|
+
line.stations.last.worker.class.should eql(CF::RobotWorker)
|
65
|
+
line.stations.last.worker.reward.should eql(1)
|
66
|
+
line.stations.last.worker.number.should eql(1)
|
67
|
+
line.stations.last.worker.settings.should eql({:content => ["{contents_of_url}"], :keywords => ["SaaS","see","additional","deepak","saroj"]})
|
68
|
+
line.stations.last.worker.type.should eql("KeywordMatchingRobot")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/line_spec.rb
ADDED
@@ -0,0 +1,338 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CF::Line do
|
4
|
+
let(:input_format) { CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"}) }
|
5
|
+
|
6
|
+
context "create a line" do
|
7
|
+
it "the plain ruby way" do
|
8
|
+
VCR.use_cassette "lines/block/create", :record => :new_episodes do
|
9
|
+
# WebMock.allow_net_connect!
|
10
|
+
line = CF::Line.new("Digit-02", "Digitization", {:public => false, :description => "this is description"})
|
11
|
+
line.title.should eq("Digit-02")
|
12
|
+
line.department_name.should eq("Digitization")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "using block with variable" do
|
17
|
+
VCR.use_cassette "lines/block/create-block-var", :record => :new_episodes do
|
18
|
+
# WebMock.allow_net_connect!
|
19
|
+
line = CF::Line.create("Digitizecard-10","Digitization") do |l|
|
20
|
+
CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
|
21
|
+
CF::InputFormat.new({:line => l, :name => "image", :required => true, :valid_type => "url"})
|
22
|
+
CF::Station.new({:line => l, :type => "work"})
|
23
|
+
end
|
24
|
+
line.title.should eq("Digitizecard-10")
|
25
|
+
line.department_name.should eq("Digitization")
|
26
|
+
line.input_formats[0].name.should eql("image_url")
|
27
|
+
line.input_formats[1].name.should eql("image")
|
28
|
+
line.stations.first.type.should eq("WorkStation")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "using block without variable" do
|
33
|
+
VCR.use_cassette "lines/block/create-without-block-var", :record => :new_episodes do
|
34
|
+
# WebMock.allow_net_connect!
|
35
|
+
line = CF::Line.create("Digitizeard", "Digitization") do
|
36
|
+
CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
|
37
|
+
CF::Station.create({:line => self, :type => "work"}) do |station|
|
38
|
+
CF::HumanWorker.new({:station => station, :number => 2, :reward => 20})
|
39
|
+
CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
40
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
|
41
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
|
42
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
line.title.should eq("Digitizeard")
|
47
|
+
line.department_name.should eq("Digitization")
|
48
|
+
line.input_formats.first.name.should eql("image_url")
|
49
|
+
line.stations.first.type.should eq("WorkStation")
|
50
|
+
line.stations.first.worker.number.should eq(2)
|
51
|
+
line.stations.first.form.instruction.should eq("Describe")
|
52
|
+
line.stations.first.form.form_fields.first.label.should eq("First Name")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "with all the optional params" do
|
57
|
+
VCR.use_cassette "lines/block/create-optional-params", :record => :new_episodes do
|
58
|
+
# WebMock.allow_net_connect!
|
59
|
+
line = CF::Line.new("Lineame", "Digitization", {:public => true, :description => "this is description"})
|
60
|
+
line.title.should eq("Lineame")
|
61
|
+
line.department_name.should eq("Digitization")
|
62
|
+
line.public.should eql(true)
|
63
|
+
line.description.should eq("this is description")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "with 1 station" do
|
69
|
+
it "create with a new station" do
|
70
|
+
VCR.use_cassette "lines/block/create-one-station", :record => :new_episodes do
|
71
|
+
# WebMock.allow_net_connect!
|
72
|
+
line = CF::Line.create("Digitizer1", "Digitization") do |l|
|
73
|
+
CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
|
74
|
+
CF::Station.create({:line => l, :type => "work"}) do |station|
|
75
|
+
CF::HumanWorker.new({:line => l, :station => station, :number => 2, :reward => 20})
|
76
|
+
CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
77
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
|
78
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
|
79
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
line.title.should eq("Digitizer1")
|
84
|
+
line.department_name.should eq("Digitization")
|
85
|
+
line.input_formats.first.name.should eql("image_url")
|
86
|
+
line.stations.first.type.should eq("WorkStation")
|
87
|
+
line.stations.first.worker.number.should eq(2)
|
88
|
+
line.stations.first.worker.reward.should eq(20)
|
89
|
+
line.stations.first.form.title.should eq("Enter text from a business card image")
|
90
|
+
line.stations.first.form.instruction.should eq("Describe")
|
91
|
+
line.stations.first.form.form_fields.first.label.should eq("First Name")
|
92
|
+
line.stations.first.form.form_fields.first.field_type.should eq("SA")
|
93
|
+
line.stations.first.form.form_fields.first.required.should eq(true)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "listing lines" do
|
99
|
+
it "should list all the existing lines that belong to particular owner" do
|
100
|
+
# WebMock.allow_net_connect!
|
101
|
+
VCR.use_cassette "lines/block/listing-lines", :record => :new_episodes do
|
102
|
+
5.times do |i|
|
103
|
+
CF::Line.new("Digitizeard---#{i}", "Digitization", {:public => false, :description => "#{i}-this is description"})
|
104
|
+
end
|
105
|
+
lines = CF::Line.all
|
106
|
+
lines.last.title.should eq("digitizeard---4")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should list all the public lines" do
|
111
|
+
# WebMock.allow_net_connect!
|
112
|
+
VCR.use_cassette "lines/block/listing-public-lines", :record => :new_episodes do
|
113
|
+
1.times do |i|
|
114
|
+
CF::Line.new("Digitizecarr-#{i}", "Digitization", {:public => false, :description => "#{i}-this is description"})
|
115
|
+
end
|
116
|
+
2.times do |i|
|
117
|
+
CF::Line.new("Lineee-#{i}", "Digitization", {:public => true, :description => "#{i}-this is description"})
|
118
|
+
end
|
119
|
+
|
120
|
+
lines = CF::Line.public_lines
|
121
|
+
lines.last.title.should eq("lineee-1")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "an existing line" do
|
127
|
+
it "should get the line info by passing the line object" do
|
128
|
+
# WebMock.allow_net_connect!
|
129
|
+
VCR.use_cassette "lines/block/line-info", :record => :new_episodes do
|
130
|
+
line = CF::Line.new("Digitize-22", "Digitization", {:public => true, :description => "this is description"})
|
131
|
+
get_line = CF::Line.info(line)
|
132
|
+
get_line.title.should eql("digitize-22")
|
133
|
+
get_line.public.should eql(true)
|
134
|
+
get_line.description.should eql("this is description")
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should get the line info by passing just the title" do
|
139
|
+
# WebMock.allow_net_connect!
|
140
|
+
VCR.use_cassette "lines/block/line-info-title", :record => :new_episodes do
|
141
|
+
line = CF::Line.new("digitizee", "Digitization", {:public => true, :description => "this is description"})
|
142
|
+
get_line = CF::Line.info(line.title)
|
143
|
+
get_line.title.should eql("digitizee")
|
144
|
+
get_line.public.should eql(true)
|
145
|
+
get_line.description.should eql("this is description")
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should render the error sent via the API overriding the RestClient one" do
|
150
|
+
# WebMock.allow_net_connect!
|
151
|
+
VCR.use_cassette "lines/block/non-existing-line", :record => :new_episodes do
|
152
|
+
get_line = CF::Line.info("non-existing-line-title")
|
153
|
+
get_line.code.should eql(404)
|
154
|
+
get_line.error.message.should match("Line document not found using selector")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
context "Updating a line" do
|
161
|
+
it "updates an existing line" do
|
162
|
+
# WebMock.allow_net_connect!
|
163
|
+
VCR.use_cassette "lines/block/update-line", :record => :new_episodes do
|
164
|
+
line = CF::Line.new("Digitizd-14", "Digitization", {:public => true, :description => "this is description"})
|
165
|
+
line.update({:title => "Newtitle-1", :department_name => "Survey", :description => "this is new description"})
|
166
|
+
updated_line = CF::Line.info(line)
|
167
|
+
updated_line.title.should eql("newtitle-1")
|
168
|
+
updated_line.title.should_not eql("digitizd-14")
|
169
|
+
# department is not updated
|
170
|
+
# updated_line.department_name.should eql("Survey")
|
171
|
+
# updated_line.department_name.should_not eql("Digitization")
|
172
|
+
updated_line.description.should eql("this is new description")
|
173
|
+
updated_line.description.should_not eql("this is description")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "deleting" do
|
179
|
+
it "should delete a line" do
|
180
|
+
# WebMock.allow_net_connect!
|
181
|
+
VCR.use_cassette "lines/block/delete-line", :record => :new_episodes do
|
182
|
+
line = CF::Line.new("Digitizerd-2", "Digitization", {:public => true, :description => "this is description"})
|
183
|
+
resp = line.destroy
|
184
|
+
resp.code.should eql(200)
|
185
|
+
deleted_resp = CF::Line.info(line)
|
186
|
+
deleted_resp.error.message.should eql("Line document not found using selector: {:public=>true, :title=>\"digitizerd-2\"}")
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should delete a line" do
|
191
|
+
# WebMock.allow_net_connect!
|
192
|
+
VCR.use_cassette "lines/block/delete-line-with-title", :record => :new_episodes do
|
193
|
+
line = CF::Line.new("Digitizerd-2", "Digitization", {:public => true, :description => "this is description"})
|
194
|
+
resp = CF::Line.destroy("Digitizerd-2")
|
195
|
+
resp.code.should eql(200)
|
196
|
+
deleted_resp = CF::Line.info(line)
|
197
|
+
deleted_resp.error.message.should eql("Line document not found using selector: {:public=>true, :title=>\"digitizerd-2\"}")
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
context "create a basic line" do
|
203
|
+
it "should create a basic line with one station" do
|
204
|
+
# WebMock.allow_net_connect!
|
205
|
+
VCR.use_cassette "lines/block/create-basic-line", :record => :new_episodes do
|
206
|
+
line = CF::Line.create("Digiard-11","Digitization") do |l|
|
207
|
+
CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
|
208
|
+
CF::Station.create({:line => l, :type => "work"}) do |s|
|
209
|
+
CF::HumanWorker.new({:station => s, :number => 2, :reward => 20})
|
210
|
+
CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
211
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
|
212
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
|
213
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
line.title.should eq("Digiard-11")
|
218
|
+
line.input_formats.first.name.should eql("image_url")
|
219
|
+
line.stations.first.type.should eq("WorkStation")
|
220
|
+
line.stations.first.worker.number.should eq(2)
|
221
|
+
line.stations.first.worker.reward.should eq(20)
|
222
|
+
line.stations.first.form.title.should eq("Enter text from a business card image")
|
223
|
+
line.stations.first.form.instruction.should eq("Describe")
|
224
|
+
line.stations.first.form.form_fields[0].label.should eq("First Name")
|
225
|
+
line.stations.first.form.form_fields[0].field_type.should eq("SA")
|
226
|
+
line.stations.first.form.form_fields[0].required.should eq(true)
|
227
|
+
line.stations.first.form.form_fields[1].label.should eq("Middle Name")
|
228
|
+
line.stations.first.form.form_fields[1].field_type.should eq("SA")
|
229
|
+
line.stations.first.form.form_fields[1].required.should eq(nil)
|
230
|
+
line.stations.first.form.form_fields[2].label.should eq("Last Name")
|
231
|
+
line.stations.first.form.form_fields[2].field_type.should eq("SA")
|
232
|
+
line.stations.first.form.form_fields[2].required.should eq(true)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
context "create line using plain ruby way" do
|
238
|
+
it "should create a station " do
|
239
|
+
# WebMock.allow_net_connect!
|
240
|
+
VCR.use_cassette "lines/plain-ruby/create-station", :record => :new_episodes do
|
241
|
+
line = CF::Line.new("Digitizeardd7", "Digitization")
|
242
|
+
CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
|
243
|
+
station = CF::Station.new({:type => "work"})
|
244
|
+
line.stations station
|
245
|
+
line.stations.first.type.should eql("WorkStation")
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should create a human worker within station" do
|
250
|
+
# WebMock.allow_net_connect!
|
251
|
+
VCR.use_cassette "lines/plain-ruby/create-station-with-worker", :record => :new_episodes do
|
252
|
+
line = CF::Line.new("Digitize-card6", "Digitization")
|
253
|
+
CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
|
254
|
+
station = CF::Station.new({:type => "work"})
|
255
|
+
line.stations station
|
256
|
+
worker = CF::HumanWorker.new({:number => 2, :reward => 20})
|
257
|
+
line.stations.first.worker = worker
|
258
|
+
line.stations.first.type.should eql("WorkStation")
|
259
|
+
line.stations.first.worker.number.should eql(2)
|
260
|
+
line.stations.first.worker.reward.should eql(20)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should create a TaskForm within station" do
|
265
|
+
# WebMock.allow_net_connect!
|
266
|
+
VCR.use_cassette "lines/plain-ruby/create-form", :record => :new_episodes do
|
267
|
+
line = CF::Line.new("Diggard-1", "Digitization")
|
268
|
+
station = CF::Station.new({:type => "work"})
|
269
|
+
line.stations station
|
270
|
+
|
271
|
+
worker = CF::HumanWorker.new({:number => 2, :reward => 20})
|
272
|
+
line.stations.first.worker = worker
|
273
|
+
|
274
|
+
form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
|
275
|
+
line.stations.first.form = form
|
276
|
+
|
277
|
+
line.stations.first.form.title.should eql("Enter text from a business card image")
|
278
|
+
line.stations.first.form.instruction.should eql("Describe")
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should create an input_format within line" do
|
283
|
+
# WebMock.allow_net_connect!
|
284
|
+
VCR.use_cassette "lines/plain-ruby/create-input-header", :record => :new_episodes do
|
285
|
+
line = CF::Line.new("Digard-2", "Digitization")
|
286
|
+
input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
|
287
|
+
line.input_formats input_format
|
288
|
+
station = CF::Station.new({:type => "work"})
|
289
|
+
line.stations station
|
290
|
+
line.stations.first.input_formats.first['name'].should eq("image_url")
|
291
|
+
line.stations.first.input_formats.first['required'].should eq(true)
|
292
|
+
line.stations.first.input_formats.first['valid_type'].should eq("url")
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should create form fields within the standard instruction" do
|
297
|
+
# WebMock.allow_net_connect!
|
298
|
+
VCR.use_cassette "lines/plain-ruby/create-form-fields", :record => :new_episodes do
|
299
|
+
line = CF::Line.new("Digitized-4", "Digitization")
|
300
|
+
station = CF::Station.new({:type => "work"})
|
301
|
+
line.stations station
|
302
|
+
|
303
|
+
worker = CF::HumanWorker.new({:number => 2, :reward => 20})
|
304
|
+
line.stations.first.worker = worker
|
305
|
+
|
306
|
+
form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
|
307
|
+
line.stations.first.form = form
|
308
|
+
|
309
|
+
form_fields_1 = CF::FormField.new({:label => "First Name", :field_type => "SA", :required => "true"})
|
310
|
+
line.stations.first.form.form_fields form_fields_1
|
311
|
+
form_fields_2 = CF::FormField.new({:label => "Middle Name", :field_type => "SA"})
|
312
|
+
line.stations.first.form.form_fields form_fields_2
|
313
|
+
form_fields_3 = CF::FormField.new({:label => "Last Name", :field_type => "SA", :required => "true"})
|
314
|
+
line.stations.first.form.form_fields form_fields_3
|
315
|
+
|
316
|
+
line.stations.first.form.form_fields[0].label.should eql("First Name")
|
317
|
+
line.stations.first.form.form_fields[0].field_type.should eq("SA")
|
318
|
+
line.stations.first.form.form_fields[0].required.should eq(true)
|
319
|
+
line.stations.first.form.form_fields[1].label.should eql("Middle Name")
|
320
|
+
line.stations.first.form.form_fields[1].field_type.should eq("SA")
|
321
|
+
line.stations.first.form.form_fields[2].label.should eql("Last Name")
|
322
|
+
line.stations.first.form.form_fields[2].field_type.should eq("SA")
|
323
|
+
line.stations.first.form.form_fields[2].required.should eq(true)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
context "create a line" do
|
329
|
+
it "the plain ruby way" do
|
330
|
+
# WebMock.allow_net_connect!
|
331
|
+
VCR.use_cassette "lines/plain-ruby/create-line-with-used-title", :record => :new_episodes do
|
332
|
+
line = CF::Line.new("new_line", "Digitization")
|
333
|
+
line_1 = CF::Line.new("new_line", "Digitization")
|
334
|
+
line_1.errors.should eql("[\"Title is already taken for this account\"]")
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|