cloudfactory 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,51 +5,51 @@ module CF
5
5
  describe CF::RobotWorker do
6
6
  context "create an image processing robot worker" do
7
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
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.create(title,"Digitization") do |l|
12
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
13
+ CF::Station.create({:line => l, :type => "work"}) do |s|
14
+ CF::RobotWorker.create({:station => s, :type => "image_processing_robot", :settings => {:image => ["{{url}}"], :sharpen => {:radius => "10"}}})
15
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
- # sleep 20
18
- output = run.final_output
19
- converted_url = output.first['processed_image_of_url']
20
- File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url}").should eql(true)
21
- line.stations.first.worker.class.should eql(CF::RobotWorker)
22
- line.stations.first.worker.reward.should eql(0.01)
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
16
  end
17
+ run = CF::Run.create(line, "image_processing_robot_run", [{"url"=> "http://wwwdelivery.superstock.com/WI/223/1527/PreviewComp/SuperStock_1527R-020214.jpg"}])
18
+ sleep 10
19
+ output = run.final_output
20
+ converted_url = output.first['processed_image_of_url']
21
+ File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url}").should eql(true)
22
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
23
+ line.stations.first.worker.reward.should eql(0.01)
24
+ line.stations.first.worker.number.should eql(1)
25
+ line.stations.first.worker.settings.should eql({:image => ["{{url}}"], :sharpen => {:radius => "10"}})
26
+ line.stations.first.worker.type.should eql("ImageProcessingRobot")
27
27
  end
28
28
 
29
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
30
+ WebMock.allow_net_connect!
31
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
32
+ sleep 1
33
+ line = CF::Line.new(title,"Digitization")
34
+ input_format = CF::InputFormat.new({:name => "url", :required => true, :valid_type => "url"})
35
+ line.input_formats input_format
35
36
 
36
- station = CF::Station.new({:type => "work"})
37
- line.stations station
37
+ station = CF::Station.new({:type => "work"})
38
+ line.stations station
38
39
 
39
- worker = CF::RobotWorker.create({:type => "image_processing_robot", :settings => {:image => ["{{url}}"], :sharpen => {:radius => "10"}}})
40
- line.stations.first.worker = worker
40
+ worker = CF::RobotWorker.create({:type => "image_processing_robot", :settings => {:image => ["{{url}}"], :sharpen => {:radius => "10"}}})
41
+ line.stations.first.worker = worker
41
42
 
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
- # sleep 20
44
- output = run.final_output
45
- converted_url = output.first['processed_image_of_url']
46
- File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url}").should eql(true)
47
- line.stations.first.worker.class.should eql(CF::RobotWorker)
48
- line.stations.first.worker.reward.should eql(0.01)
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
43
+ run = CF::Run.create(line, "image_processing_robot_run_1", [{"url"=> "http://wwwdelivery.superstock.com/WI/223/1527/PreviewComp/SuperStock_1527R-020214.jpg"}])
44
+ sleep 10
45
+ output = run.final_output
46
+ converted_url = output.first['processed_image_of_url']
47
+ File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url}").should eql(true)
48
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
49
+ line.stations.first.worker.reward.should eql(0.01)
50
+ line.stations.first.worker.number.should eql(1)
51
+ line.stations.first.worker.settings.should eql({:image => ["{{url}}"], :sharpen => {:radius => "10"}})
52
+ line.stations.first.worker.type.should eql("ImageProcessingRobot")
53
53
  end
54
54
  end
55
55
  end
@@ -3,135 +3,135 @@ require 'spec_helper'
3
3
  describe CF::InputFormat do
4
4
  context "create an input header" do
5
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})
10
- line.input_formats input_format
11
- line.input_formats.first.name.should eql("Company")
12
- 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
+ input_format = CF::InputFormat.new({:name => "Company", :required => true})
11
+ line.input_formats input_format
12
+ line.input_formats.first.name.should eql("Company")
13
13
  end
14
14
 
15
15
  it "in plain ruby way within station" do
16
- # WebMock.allow_net_connect!
17
- VCR.use_cassette "input_formats/plain-ruby/create", :record => :new_episodes do
18
- attrs = {:name => "image_url",
19
- :required => true,
20
- :valid_type => "url"
21
- }
22
-
23
- line = CF::Line.new("Digitize-121","Digitization")
24
- input_format = CF::InputFormat.new(attrs)
25
- line.input_formats input_format
26
- input_format1 = CF::InputFormat.new({:name => "image", :required => true, :valid_type => "url"})
27
- line.input_formats input_format1
28
- station = CF::Station.new({:type => "work"})
29
- line.stations station
16
+ WebMock.allow_net_connect!
17
+ attrs = {:name => "image_url",
18
+ :required => true,
19
+ :valid_type => "url"
20
+ }
21
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
22
+ sleep 1
23
+ line = CF::Line.new(title,"Digitization")
24
+ input_format = CF::InputFormat.new(attrs)
25
+ line.input_formats input_format
26
+ input_format1 = CF::InputFormat.new({:name => "image", :required => true, :valid_type => "url"})
27
+ line.input_formats input_format1
28
+ station = CF::Station.new({:type => "work"})
29
+ line.stations station
30
30
 
31
- line.title.should eq("Digitize-121")
32
- line.input_formats.first.name.should eq("image_url")
33
- line.input_formats.first.required.should eq(true)
34
- line.input_formats.first.valid_type.should eq("url")
35
- line.input_formats.last.name.should eq("image")
36
- line.input_formats.last.required.should eq(true)
37
- line.input_formats.last.valid_type.should eq("url")
38
- end
31
+ line.title.should eq(title)
32
+ line.input_formats.first.name.should eq("image_url")
33
+ line.input_formats.first.required.should eq(true)
34
+ line.input_formats.first.valid_type.should eq("url")
35
+ line.input_formats.last.name.should eq("image")
36
+ line.input_formats.last.required.should eq(true)
37
+ line.input_formats.last.valid_type.should eq("url")
39
38
  end
40
39
 
41
40
  it "in block DSL way within line" do
42
- # WebMock.allow_net_connect!
43
- VCR.use_cassette "input_formats/block/create-input-headers-of-line", :record => :new_episodes do
44
- line = CF::Line.create("Digitize-2","Digitization") do |l|
45
- CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
46
- CF::InputFormat.new({:line => l, :name => "image", :required => true, :valid_type => "url"})
47
- end
48
- line.input_formats[0].name.should eq("image_url")
49
- line.input_formats[1].name.should eq("image")
41
+ WebMock.allow_net_connect!
42
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
43
+ sleep 1
44
+ line = CF::Line.create(title,"Digitization") do |l|
45
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
46
+ CF::InputFormat.new({:line => l, :name => "image", :required => true, :valid_type => "url"})
50
47
  end
48
+ line.input_formats[0].name.should eq("image_url")
49
+ line.input_formats[1].name.should eq("image")
51
50
  end
52
-
51
+
53
52
  it "in block DSL way within line without valid_type" do
54
- # WebMock.allow_net_connect!
55
- VCR.use_cassette "input_formats/block/create-input-headers-of-line-1", :record => :new_episodes do
56
- line = CF::Line.create("input_format_without_valid_type","Digitization") do |l|
57
- CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
58
- CF::InputFormat.new({:line => l, :name => "image", :required => true})
59
- end
60
- line.input_formats[0].name.should eq("image_url")
61
- line.input_formats[1].name.should eq("image")
53
+ WebMock.allow_net_connect!
54
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
55
+ sleep 1
56
+ line = CF::Line.create(title,"Digitization") do |l|
57
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
58
+ CF::InputFormat.new({:line => l, :name => "image", :required => true})
62
59
  end
60
+ line.input_formats[0].name.should eq("image_url")
61
+ line.input_formats[1].name.should eq("image")
63
62
  end
64
63
 
65
64
  it "in block DSL way within station" do
66
- # WebMock.allow_net_connect!
67
- VCR.use_cassette "input_formats/block/create-input-headers-of-station", :record => :new_episodes do
68
- line = CF::Line.create("Digitize-3","Digitization") do |l|
69
- CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
70
- CF::InputFormat.new({:line => l, :name => "image", :required => true, :valid_type => "url"})
71
- CF::Station.new({:line => l, :type => "work"})
72
- end
73
- line.input_formats[0].name.should eq("image_url")
74
- line.input_formats[1].name.should eq("image")
65
+ WebMock.allow_net_connect!
66
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
67
+ sleep 1
68
+ line = CF::Line.create(title,"Digitization") do |l|
69
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
70
+ CF::InputFormat.new({:line => l, :name => "image", :required => true, :valid_type => "url"})
71
+ CF::Station.new({:line => l, :type => "work"})
75
72
  end
73
+ line.input_formats[0].name.should eq("image_url")
74
+ line.input_formats[1].name.should eq("image")
76
75
  end
77
-
76
+
78
77
  it "should only display the attributes which are mentioned in to_s method" do
79
- VCR.use_cassette "input_formats/block/display-to_s", :record => :new_episodes do
80
- # WebMock.allow_net_connect!
81
- line = CF::Line.create("Display_input_format", "Digitization") do
82
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
83
- CF::Station.create({:line => self, :type => "work"}) do |station|
84
- CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
85
- end
78
+ WebMock.allow_net_connect!
79
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
80
+ sleep 1
81
+ line = CF::Line.create(title, "Digitization") do
82
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
83
+ CF::Station.create({:line => self, :type => "work"}) do |station|
84
+ CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
86
85
  end
87
- line.input_formats.first.to_s.should eql("{:id => #{line.input_formats.first.id}, :name => image_url, :required => true, :valid_type => url, :errors => }")
88
86
  end
87
+ line.input_formats.first.to_s.should eql("{:id => #{line.input_formats.first.id}, :name => image_url, :required => true, :valid_type => url, :errors => }")
89
88
  end
90
89
  end
91
90
 
92
91
  context "return all the input headers" do
93
92
  it "should return all the input headers of a line " do
94
- # WebMock.allow_net_connect!
95
- VCR.use_cassette "input_formats/block/input-headers-of-line", :record => :new_episodes do
96
- line = CF::Line.create("Digitize-111","Digitization") do |l|
97
- CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
98
- CF::InputFormat.new({:line => l, :name => "image", :required => true, :valid_type => "url"})
99
- CF::Station.new({:line => l, :type => "work"})
100
- end
101
- input_formats_of_line = CF::InputFormat.all(line)
102
- # => getting input_formats response need to be modified
103
- input_formats_of_line.map(&:name).should include("image_url")
104
- input_formats_of_line.map(&:name).should include("image")
105
- input_formats_of_line.map(&:valid_type).should include("url")
93
+ WebMock.allow_net_connect!
94
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
95
+ sleep 1
96
+ line = CF::Line.create(title,"Digitization") do |l|
97
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
98
+ CF::InputFormat.new({:line => l, :name => "image", :required => true, :valid_type => "url"})
99
+ CF::Station.new({:line => l, :type => "work"})
106
100
  end
101
+ input_formats_of_line = CF::InputFormat.all(line)
102
+ # => getting input_formats response need to be modified
103
+ names = input_formats_of_line.map {|i| i['name']}.join(",")
104
+ names.should include("image_url")
105
+ names.should include("image")
106
+ input_formats_of_line.map {|i| i['valid_type']}.join(",").should include("url")
107
107
  end
108
108
  end
109
-
109
+
110
110
  context "create an input_format" do
111
111
  it "in Block DSL way without name to set the error attribute" do
112
- # WebMock.allow_net_connect!
113
- VCR.use_cassette "input_formats/block/create-invalid-input-formats", :record => :new_episodes do
114
- line = CF::Line.create("Digitize-2","Digitization") do |l|
115
- CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
116
- CF::InputFormat.new({:line => l, :required => true, :valid_type => "url"})
117
- end
118
- line.input_formats[0].name.should eq("image_url")
119
- line.input_formats[1].errors.should eql(["Name can't be blank"])
112
+ WebMock.allow_net_connect!
113
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
114
+ sleep 1
115
+ line = CF::Line.create(title,"Digitization") do |l|
116
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
117
+ CF::InputFormat.new({:line => l, :required => true, :valid_type => "url"})
120
118
  end
119
+ line.input_formats[0].name.should eq("image_url")
120
+ line.input_formats[1].errors.should eql(["Name can't be blank"])
121
121
  end
122
-
122
+
123
123
  it "in plain Ruby way with invalid data to set the error attribute" do
124
- # WebMock.allow_net_connect!
125
- VCR.use_cassette "input_formats/plain-ruby/create-invalid-input-formats", :record => :new_episodes do
126
- line = CF::Line.new("Digitize-3","Digitization")
127
- input_format_1 = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
128
- line.input_formats input_format_1
129
- input_format_2 = CF::InputFormat.new({:required => true, :valid_type => "url"})
130
- line.input_formats input_format_2
131
-
132
- line.input_formats[0].name.should eq("image_url")
133
- line.input_formats[1].errors.should eql(["Name can't be blank"])
134
- end
124
+ WebMock.allow_net_connect!
125
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
126
+ sleep 1
127
+ line = CF::Line.new(title,"Digitization")
128
+ input_format_1 = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
129
+ line.input_formats input_format_1
130
+ input_format_2 = CF::InputFormat.new({:required => true, :valid_type => "url"})
131
+ line.input_formats input_format_2
132
+
133
+ line.input_formats[0].name.should eq("image_url")
134
+ line.input_formats[1].errors.should eql(["Name can't be blank"])
135
135
  end
136
136
  end
137
137
  end
@@ -5,70 +5,70 @@ module CF
5
5
  describe CF::RobotWorker do
6
6
  context "create a keyword matching robot worker and text extraction robot" do
7
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
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.create(title,"Digitization") do |l|
12
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
13
+ CF::Station.create({:line => l, :type => "work"}) do |s|
14
+ CF::RobotWorker.create({:station => s, :type => "text_extraction_robot", :settings => {:url => ["{{url}}"]}})
15
+ end
16
+ CF::Station.create({:line => l, :type => "work"}) do |s1|
17
+ CF::RobotWorker.create({:station => s1, :type => "keyword_matching_robot", :settings => {:content => ["{{contents_of_url}}"], :keywords => ["SaaS","see","additional","deepak","saroj"]}})
18
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
- # sleep 20
21
- output = run.final_output
22
- output.first['included_keywords_count_in_contents_of_url'].should eql(["3", "2", "2"])
23
- output.first['keyword_included_in_contents_of_url'].should eql(["SaaS", "see", "additional"])
24
- line.stations.first.worker.class.should eql(CF::RobotWorker)
25
- line.stations.first.worker.reward.should eql(0.5)
26
- line.stations.first.worker.number.should eql(1)
27
- line.stations.first.worker.settings.should eql({:url => ["{{url}}"]})
28
- line.stations.first.worker.type.should eql("TextExtractionRobot")
29
- line.stations.last.worker.class.should eql(CF::RobotWorker)
30
- line.stations.last.worker.reward.should eql(0.5)
31
- line.stations.last.worker.number.should eql(1)
32
- line.stations.last.worker.settings.should eql({:content => ["{{contents_of_url}}"], :keywords => ["SaaS","see","additional","deepak","saroj"]})
33
- line.stations.last.worker.type.should eql("KeywordMatchingRobot")
34
19
  end
20
+ run = CF::Run.create(line, "run-#{title}", [{"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"}])
21
+ sleep 30
22
+ output = run.final_output
23
+ output.first['included_keywords_count_in_contents_of_url'].should eql(["3", "2", "2"])
24
+ output.first['keyword_included_in_contents_of_url'].should eql(["SaaS", "see", "additional"])
25
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
26
+ line.stations.first.worker.reward.should eql(0.5)
27
+ line.stations.first.worker.number.should eql(1)
28
+ line.stations.first.worker.settings.should eql({:url => ["{{url}}"]})
29
+ line.stations.first.worker.type.should eql("TextExtractionRobot")
30
+ line.stations.last.worker.class.should eql(CF::RobotWorker)
31
+ line.stations.last.worker.reward.should eql(0.5)
32
+ line.stations.last.worker.number.should eql(1)
33
+ line.stations.last.worker.settings.should eql({:content => ["{{contents_of_url}}"], :keywords => ["SaaS","see","additional","deepak","saroj"]})
34
+ line.stations.last.worker.type.should eql("KeywordMatchingRobot")
35
35
  end
36
36
 
37
37
  it "should create keyword matching robot worker for first station in a plain ruby way" do
38
- # WebMock.allow_net_connect!
39
- VCR.use_cassette "robot_worker/keyword_matching_robot/plain-ruby/create-worker-in-first-station", :record => :new_episodes do
40
- line = CF::Line.new("keyword_matching_robot_1","Digitization")
41
- input_format = CF::InputFormat.new({:name => "url", :required => true, :valid_type => "url"})
42
- line.input_formats input_format
38
+ WebMock.allow_net_connect!
39
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
40
+ sleep 1
41
+ line = CF::Line.new(title,"Digitization")
42
+ input_format = CF::InputFormat.new({:name => "url", :required => true, :valid_type => "url"})
43
+ line.input_formats input_format
43
44
 
44
- station = CF::Station.new({:type => "work"})
45
- line.stations station
45
+ station = CF::Station.new({:type => "work"})
46
+ line.stations station
46
47
 
47
- worker = CF::RobotWorker.create({:type => "text_extraction_robot", :settings => {:url => ["{{url}}"]}})
48
- line.stations.first.worker = worker
49
-
50
- station_1 = CF::Station.new({:type => "work"})
51
- line.stations station
52
-
53
- worker = CF::RobotWorker.create({:type => "keyword_matching_robot", :settings => {:content => ["{{contents_of_url}}"], :keywords => ["SaaS","see","additional","deepak","saroj"]}})
54
- line.stations.last.worker = worker
48
+ worker = CF::RobotWorker.create({:type => "text_extraction_robot", :settings => {:url => ["{{url}}"]}})
49
+ line.stations.first.worker = worker
55
50
 
56
- 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"}])
57
- # sleep 20
58
- output = run.final_output
59
- output.first['included_keywords_count_in_contents_of_url'].should eql(["3", "2", "2"])
60
- output.first['keyword_included_in_contents_of_url'].should eql(["SaaS", "see", "additional"])
61
- line.stations.first.worker.class.should eql(CF::RobotWorker)
62
- line.stations.first.worker.reward.should eql(0.5)
63
- line.stations.first.worker.number.should eql(1)
64
- line.stations.first.worker.settings.should eql({:url => ["{{url}}"]})
65
- line.stations.first.worker.type.should eql("TextExtractionRobot")
66
- line.stations.last.worker.class.should eql(CF::RobotWorker)
67
- line.stations.last.worker.reward.should eql(0.5)
68
- line.stations.last.worker.number.should eql(1)
69
- line.stations.last.worker.settings.should eql({:content => ["{{contents_of_url}}"], :keywords => ["SaaS","see","additional","deepak","saroj"]})
70
- line.stations.last.worker.type.should eql("KeywordMatchingRobot")
71
- end
51
+ station_1 = CF::Station.new({:type => "work"})
52
+ line.stations station
53
+
54
+ worker = CF::RobotWorker.create({:type => "keyword_matching_robot", :settings => {:content => ["{{contents_of_url}}"], :keywords => ["SaaS","see","additional","deepak","saroj"]}})
55
+ line.stations.last.worker = worker
56
+
57
+ run = CF::Run.create(line, "run-#{title}", [{"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"}])
58
+ sleep 30
59
+ output = run.final_output
60
+ output.first['included_keywords_count_in_contents_of_url'].should eql(["3", "2", "2"])
61
+ output.first['keyword_included_in_contents_of_url'].should eql(["SaaS", "see", "additional"])
62
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
63
+ line.stations.first.worker.reward.should eql(0.5)
64
+ line.stations.first.worker.number.should eql(1)
65
+ line.stations.first.worker.settings.should eql({:url => ["{{url}}"]})
66
+ line.stations.first.worker.type.should eql("TextExtractionRobot")
67
+ line.stations.last.worker.class.should eql(CF::RobotWorker)
68
+ line.stations.last.worker.reward.should eql(0.5)
69
+ line.stations.last.worker.number.should eql(1)
70
+ line.stations.last.worker.settings.should eql({:content => ["{{contents_of_url}}"], :keywords => ["SaaS","see","additional","deepak","saroj"]})
71
+ line.stations.last.worker.type.should eql("KeywordMatchingRobot")
72
72
  end
73
73
  end
74
74
  end
data/spec/line_spec.rb CHANGED
@@ -5,556 +5,582 @@ describe CF::Line do
5
5
 
6
6
  context "create a line" do
7
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
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", {:public => false, :description => "this is description"})
12
+ line.title.should eq(title)
13
+ line.department_name.should eq("Digitization")
14
14
  end
15
15
 
16
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")
17
+ WebMock.allow_net_connect!
18
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
19
+ sleep 1
20
+ line = CF::Line.create(title,"Digitization") do |l|
21
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
22
+ CF::InputFormat.new({:line => l, :name => "image", :required => true, :valid_type => "url"})
23
+ CF::Station.new({:line => l, :type => "work"})
29
24
  end
25
+ line.title.should eq(title)
26
+ line.department_name.should eq("Digitization")
27
+ line.input_formats[0].name.should eql("image_url")
28
+ line.input_formats[1].name.should eql("image")
29
+ line.stations.first.type.should eq("WorkStation")
30
30
  end
31
31
 
32
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 => 1, :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
33
+ WebMock.allow_net_connect!
34
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
35
+ sleep 1
36
+ line = CF::Line.create(title, "Digitization") do
37
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
38
+ CF::Station.create({:line => self, :type => "work"}) do |station|
39
+ CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
40
+ CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
41
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
42
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
43
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
44
44
  end
45
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(1)
51
- line.stations.first.form.instruction.should eq("Describe")
52
- line.stations.first.form.form_fields.first.label.should eq("First Name")
53
46
  end
47
+ line.title.should eq(title)
48
+ line.department_name.should eq("Digitization")
49
+ line.input_formats.first.name.should eql("image_url")
50
+ line.stations.first.type.should eq("WorkStation")
51
+ line.stations.first.worker.number.should eq(1)
52
+ line.stations.first.form.instruction.should eq("Describe")
53
+ line.stations.first.form.form_fields.first.label.should eq("First Name")
54
54
  end
55
55
 
56
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
57
+ WebMock.allow_net_connect!
58
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
59
+ sleep 1
60
+ line = CF::Line.new(title, "Digitization", {:public => true, :description => "this is description"})
61
+ line.title.should eq(title)
62
+ line.department_name.should eq("Digitization")
63
+ line.public.should eql(true)
64
+ line.description.should eq("this is description")
65
65
  end
66
66
  end
67
67
 
68
68
  context "with 1 station" do
69
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 => 1, :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
70
+ WebMock.allow_net_connect!
71
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
72
+ sleep 1
73
+ line = CF::Line.create(title, "Digitization") do |l|
74
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
75
+ CF::Station.create({:line => l, :type => "work"}) do |station|
76
+ CF::HumanWorker.new({:line => l, :station => station, :number => 1, :reward => 20})
77
+ CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
78
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
79
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
80
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
81
81
  end
82
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(1)
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
83
  end
84
+ line.title.should eq(title)
85
+ line.department_name.should eq("Digitization")
86
+ line.input_formats.first.name.should eql("image_url")
87
+ line.stations.first.type.should eq("WorkStation")
88
+ line.stations.first.worker.number.should eq(1)
89
+ line.stations.first.worker.reward.should eq(20)
90
+ line.stations.first.form.title.should eq("Enter text from a business card image")
91
+ line.stations.first.form.instruction.should eq("Describe")
92
+ line.stations.first.form.form_fields.first.label.should eq("First Name")
93
+ line.stations.first.form.form_fields.first.field_type.should eq("short_answer")
94
+ line.stations.first.form.form_fields.first.required.should eq(true)
95
95
  end
96
96
  end
97
97
 
98
98
  context "listing lines" do
99
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.class.should eql(Hash)
100
+ WebMock.allow_net_connect!
101
+ 5.times do |i|
102
+ title_i = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
103
+ sleep 1
104
+ CF::Line.new(title_i, "Digitization", {:public => false, :description => "#{i}-this is description"})
107
105
  end
106
+ lines = CF::Line.all
107
+ lines.class.should eql(Hash)
108
108
  end
109
109
 
110
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.map(&:title).should include("lineee-1")
122
- end
111
+ WebMock.allow_net_connect!
112
+ title_0 = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
113
+ sleep 1
114
+ title_10 = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
115
+ sleep 1
116
+ title_11 = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
117
+ sleep 1
118
+ CF::Line.new(title_0, "Digitization", {:public => false, :description => "this is description"})
119
+ CF::Line.new(title_10, "Digitization", {:public => true, :description => "this is description"})
120
+ CF::Line.new(title_11, "Digitization", {:public => true, :description => "this is description"})
121
+ lines = CF::Line.public_lines(:page => "all")
122
+ lines.map {|l| l['title'] }.join(",").should include(title_11)
123
123
  end
124
124
  end
125
125
 
126
126
  context "an existing line" do
127
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
128
+ WebMock.allow_net_connect!
129
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
130
+ sleep 1
131
+ line = CF::Line.new(title, "Digitization", {:public => true, :description => "this is description"})
132
+ get_line = CF::Line.info(line)
133
+ get_line['title'].should eql(title)
134
+ get_line['public'].should eql(true)
135
+ get_line['description'].should eql("this is description")
136
136
  end
137
-
137
+
138
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
139
+ WebMock.allow_net_connect!
140
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
141
+ sleep 1
142
+ line = CF::Line.new(title, "Digitization", {:public => true, :description => "this is description"})
143
+ get_line = CF::Line.info(line.title)
144
+ get_line['title'].should eql(title)
145
+ get_line['public'].should eql(true)
146
+ get_line['description'].should eql("this is description")
147
147
  end
148
148
 
149
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 not found for title: non-existing-line-title under your account")
155
- end
150
+ WebMock.allow_net_connect!
151
+ get_line = CF::Line.info("non-existing-line-title")
152
+ get_line['code'].should eql(404)
153
+ get_line['error']['message'].should match("Line not found for title: non-existing-line-title under your account")
156
154
  end
157
155
 
158
156
  end
159
157
 
160
158
  context "deleting" do
161
159
  it "should delete a line" do
162
- # WebMock.allow_net_connect!
163
- VCR.use_cassette "lines/block/delete-line", :record => :new_episodes do
164
- line = CF::Line.new("Digitizerd-2", "Digitization", {:public => true, :description => "this is description"})
165
- resp = line.destroy
166
- resp.code.should eql(200)
167
- deleted_resp = CF::Line.info(line)
168
- deleted_resp.error.message.should eql("Line not found for title: digitizerd-2 under your account")
169
- end
160
+ WebMock.allow_net_connect!
161
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
162
+ sleep 1
163
+ line = CF::Line.new(title, "Digitization", {:public => true, :description => "this is description"})
164
+ resp = line.destroy
165
+ resp['code'].should eql(200)
166
+ deleted_resp = CF::Line.info(line)
167
+ deleted_resp['error']['message'].should eql("Line not found for title: #{title} under your account")
170
168
  end
171
-
169
+
172
170
  it "should delete a line" do
173
- # WebMock.allow_net_connect!
174
- VCR.use_cassette "lines/block/delete-line-with-title", :record => :new_episodes do
175
- line = CF::Line.new("Digitizerd-2", "Digitization", {:public => true, :description => "this is description"})
176
- resp = CF::Line.destroy("Digitizerd-2")
177
- resp.code.should eql(200)
178
- deleted_resp = CF::Line.info(line)
179
- deleted_resp.error.message.should eql("Line not found for title: digitizerd-2 under your account")
180
- end
171
+ WebMock.allow_net_connect!
172
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
173
+ sleep 1
174
+ line = CF::Line.new(title, "Digitization", {:public => true, :description => "this is description"})
175
+ resp = CF::Line.destroy(title)
176
+ resp['code'].should eql(200)
177
+ deleted_resp = CF::Line.info(line)
178
+ deleted_resp['error']['message'].should eql("Line not found for title: #{title} under your account")
181
179
  end
182
180
  end
183
181
 
184
182
  context "create a basic line" do
185
183
  it "should create a basic line with one station" do
186
- # WebMock.allow_net_connect!
187
- VCR.use_cassette "lines/block/create-basic-line", :record => :new_episodes do
188
- line = CF::Line.create("Digiard-11","Digitization") do |l|
189
- CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
190
- CF::Station.create({:line => l, :type => "work"}) do |s|
191
- CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
192
- CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
193
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
194
- CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
195
- CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
196
- end
184
+ WebMock.allow_net_connect!
185
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
186
+ sleep 1
187
+ line = CF::Line.create(title,"Digitization") do |l|
188
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
189
+ CF::Station.create({:line => l, :type => "work"}) do |s|
190
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
191
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
192
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
193
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
194
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
197
195
  end
198
196
  end
199
- line.title.should eq("Digiard-11")
200
- line.input_formats.first.name.should eql("image_url")
201
- line.stations.first.type.should eq("WorkStation")
202
- line.stations.first.worker.number.should eq(1)
203
- line.stations.first.worker.reward.should eq(20)
204
- line.stations.first.form.title.should eq("Enter text from a business card image")
205
- line.stations.first.form.instruction.should eq("Describe")
206
- line.stations.first.form.form_fields[0].label.should eq("First Name")
207
- line.stations.first.form.form_fields[0].field_type.should eq("SA")
208
- line.stations.first.form.form_fields[0].required.should eq("true")
209
- line.stations.first.form.form_fields[1].label.should eq("Middle Name")
210
- line.stations.first.form.form_fields[1].field_type.should eq("SA")
211
- line.stations.first.form.form_fields[1].required.should eq(nil)
212
- line.stations.first.form.form_fields[2].label.should eq("Last Name")
213
- line.stations.first.form.form_fields[2].field_type.should eq("SA")
214
- line.stations.first.form.form_fields[2].required.should eq("true")
215
197
  end
198
+ line.title.should eq(title)
199
+ line.input_formats.first.name.should eql("image_url")
200
+ line.stations.first.type.should eq("WorkStation")
201
+ line.stations.first.worker.number.should eq(1)
202
+ line.stations.first.worker.reward.should eq(20)
203
+ line.stations.first.form.title.should eq("Enter text from a business card image")
204
+ line.stations.first.form.instruction.should eq("Describe")
205
+ line.stations.first.form.form_fields[0].label.should eq("First Name")
206
+ line.stations.first.form.form_fields[0].field_type.should eq("short_answer")
207
+ line.stations.first.form.form_fields[0].required.should eq(true)
208
+ line.stations.first.form.form_fields[1].label.should eq("Middle Name")
209
+ line.stations.first.form.form_fields[1].field_type.should eq("short_answer")
210
+ line.stations.first.form.form_fields[1].required.should eq(nil)
211
+ line.stations.first.form.form_fields[2].label.should eq("Last Name")
212
+ line.stations.first.form.form_fields[2].field_type.should eq("short_answer")
213
+ line.stations.first.form.form_fields[2].required.should eq(true)
216
214
  end
217
215
  end
218
216
 
219
217
  context "create line using plain ruby way" do
220
218
  it "should create a station " do
221
- # WebMock.allow_net_connect!
222
- VCR.use_cassette "lines/plain-ruby/create-station", :record => :new_episodes do
223
- line = CF::Line.new("Digitizeardd7", "Digitization")
224
- CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
225
- station = CF::Station.new({:type => "work"})
226
- line.stations station
227
- line.stations.first.type.should eql("WorkStation")
228
- end
219
+ WebMock.allow_net_connect!
220
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
221
+ sleep 1
222
+ line = CF::Line.new(title, "Digitization")
223
+ CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
224
+ station = CF::Station.new({:type => "work"})
225
+ line.stations station
226
+ line.stations.first.type.should eql("WorkStation")
229
227
  end
230
228
 
231
229
  it "should create a human worker within station" do
232
- # WebMock.allow_net_connect!
233
- VCR.use_cassette "lines/plain-ruby/create-station-with-worker", :record => :new_episodes do
234
- line = CF::Line.new("Digitize-card6", "Digitization")
235
- CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
236
- station = CF::Station.new({:type => "work"})
237
- line.stations station
238
- worker = CF::HumanWorker.new({:number => 1, :reward => 20})
239
- line.stations.first.worker = worker
240
- line.stations.first.type.should eql("WorkStation")
241
- line.stations.first.worker.number.should eql(1)
242
- line.stations.first.worker.reward.should eql(20)
243
- end
230
+ WebMock.allow_net_connect!
231
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
232
+ sleep 1
233
+ line = CF::Line.new(title, "Digitization")
234
+ CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
235
+ station = CF::Station.new({:type => "work"})
236
+ line.stations station
237
+ worker = CF::HumanWorker.new({:number => 1, :reward => 20})
238
+ line.stations.first.worker = worker
239
+ line.stations.first.type.should eql("WorkStation")
240
+ line.stations.first.worker.number.should eql(1)
241
+ line.stations.first.worker.reward.should eql(20)
244
242
  end
245
243
 
246
244
  it "should create a TaskForm within station" do
247
- # WebMock.allow_net_connect!
248
- VCR.use_cassette "lines/plain-ruby/create-form", :record => :new_episodes do
249
- line = CF::Line.new("Diggard-1", "Digitization")
250
- CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
251
- station = CF::Station.new({:type => "work"})
252
- line.stations station
253
-
254
- worker = CF::HumanWorker.new({:number => 1, :reward => 20})
255
- line.stations.first.worker = worker
256
-
257
- form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
258
- line.stations.first.form = form
259
-
260
- line.stations.first.form.title.should eql("Enter text from a business card image")
261
- line.stations.first.form.instruction.should eql("Describe")
262
- end
245
+ WebMock.allow_net_connect!
246
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
247
+ sleep 1
248
+ line = CF::Line.new(title, "Digitization")
249
+ CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
250
+ station = CF::Station.new({:type => "work"})
251
+ line.stations station
252
+
253
+ worker = CF::HumanWorker.new({:number => 1, :reward => 20})
254
+ line.stations.first.worker = worker
255
+
256
+ form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
257
+ line.stations.first.form = form
258
+
259
+ line.stations.first.form.title.should eql("Enter text from a business card image")
260
+ line.stations.first.form.instruction.should eql("Describe")
263
261
  end
264
262
 
265
263
  it "should create an input_format within line" do
266
- # WebMock.allow_net_connect!
267
- VCR.use_cassette "lines/plain-ruby/create-input-header", :record => :new_episodes do
268
- line = CF::Line.new("Digard-2", "Digitization")
269
- input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
270
- line.input_formats input_format
271
- station = CF::Station.new({:type => "work"})
272
- line.stations station
273
- line.input_formats.first.name.should eq("image_url")
274
- line.input_formats.first.required.should eq(true)
275
- line.input_formats.first.valid_type.should eq("url")
276
- end
264
+ WebMock.allow_net_connect!
265
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
266
+ sleep 1
267
+ line = CF::Line.new(title, "Digitization")
268
+ input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
269
+ line.input_formats input_format
270
+ station = CF::Station.new({:type => "work"})
271
+ line.stations station
272
+ line.input_formats.first.name.should eq("image_url")
273
+ line.input_formats.first.required.should eq(true)
274
+ line.input_formats.first.valid_type.should eq("url")
277
275
  end
278
276
 
279
277
  it "should create form fields within the standard instruction" do
280
- # WebMock.allow_net_connect!
281
- VCR.use_cassette "lines/plain-ruby/create-form-fields", :record => :new_episodes do
282
- line = CF::Line.new("Digitized-4", "Digitization")
283
- CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
284
- station = CF::Station.new({:type => "work"})
285
- line.stations station
286
-
287
- worker = CF::HumanWorker.new({:number => 1, :reward => 20})
288
- line.stations.first.worker = worker
289
-
290
- form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
291
- line.stations.first.form = form
292
-
293
- form_fields_1 = CF::FormField.new({:label => "First Name", :field_type => "short_answer", :required => "true"})
294
- line.stations.first.form.form_fields form_fields_1
295
- form_fields_2 = CF::FormField.new({:label => "Middle Name", :field_type => "short_answer"})
296
- line.stations.first.form.form_fields form_fields_2
297
- form_fields_3 = CF::FormField.new({:label => "Last Name", :field_type => "short_answer", :required => "true"})
298
- line.stations.first.form.form_fields form_fields_3
299
-
300
- line.stations.first.form.form_fields[0].label.should eql("First Name")
301
- line.stations.first.form.form_fields[0].field_type.should eq("short_answer")
302
- line.stations.first.form.form_fields[0].required.should eq(true)
303
- line.stations.first.form.form_fields[1].label.should eql("Middle Name")
304
- line.stations.first.form.form_fields[1].field_type.should eq("short_answer")
305
- line.stations.first.form.form_fields[2].label.should eql("Last Name")
306
- line.stations.first.form.form_fields[2].field_type.should eq("short_answer")
307
- line.stations.first.form.form_fields[2].required.should eq(true)
308
- end
278
+ WebMock.allow_net_connect!
279
+ sleep 1
280
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
281
+ line = CF::Line.new(title, "Digitization")
282
+ CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
283
+ station = CF::Station.new({:type => "work"})
284
+ line.stations station
285
+
286
+ worker = CF::HumanWorker.new({:number => 1, :reward => 20})
287
+ line.stations.first.worker = worker
288
+
289
+ form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
290
+ line.stations.first.form = form
291
+
292
+ form_fields_1 = CF::FormField.new({:label => "First Name", :field_type => "short_answer", :required => "true"})
293
+ line.stations.first.form.form_fields form_fields_1
294
+ form_fields_2 = CF::FormField.new({:label => "Middle Name", :field_type => "short_answer"})
295
+ line.stations.first.form.form_fields form_fields_2
296
+ form_fields_3 = CF::FormField.new({:label => "Last Name", :field_type => "short_answer", :required => "true"})
297
+ line.stations.first.form.form_fields form_fields_3
298
+
299
+ line.stations.first.form.form_fields[0].label.should eql("First Name")
300
+ line.stations.first.form.form_fields[0].field_type.should eq("short_answer")
301
+ line.stations.first.form.form_fields[0].required.should eq(true)
302
+ line.stations.first.form.form_fields[1].label.should eql("Middle Name")
303
+ line.stations.first.form.form_fields[1].field_type.should eq("short_answer")
304
+ line.stations.first.form.form_fields[2].label.should eql("Last Name")
305
+ line.stations.first.form.form_fields[2].field_type.should eq("short_answer")
306
+ line.stations.first.form.form_fields[2].required.should eq(true)
309
307
  end
310
308
  end
311
-
309
+
312
310
  context "create a line" do
313
311
  it "the plain ruby way" do
314
- # WebMock.allow_net_connect!
315
- VCR.use_cassette "lines/plain-ruby/create-line-with-used-title", :record => :new_episodes do
316
- line = CF::Line.new("new_line", "Digitization")
317
- line_1 = CF::Line.new("new_line", "Digitization")
318
- line_1.errors.should eql(["Title is already taken for this account"])
319
- end
312
+ WebMock.allow_net_connect!
313
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
314
+ sleep 1
315
+ line = CF::Line.new(title, "Digitization")
316
+ line_1 = CF::Line.new(title, "Digitization")
317
+ line_1.errors.should eql(["Title is already taken for this account"])
320
318
  end
321
319
  end
322
-
320
+
323
321
  context "delete line whose production run is already created" do
324
322
  it "it should throw error and must be deleted if forced true is passed" do
325
- VCR.use_cassette "lines/block/delete-line-of-active-run", :record => :new_episodes do
326
- # WebMock.allow_net_connect!
327
- line = CF::Line.create("delete_line_of_run","Digitization") do |l|
328
- CF::InputFormat.new({:line => l, :name => "Company", :required => true})
329
- CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
330
- CF::Station.create({:line => l, :type => "work"}) do |s|
331
- CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
332
- CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
333
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
334
- CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
335
- CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
336
- end
323
+ WebMock.allow_net_connect!
324
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
325
+ sleep 1
326
+ line = CF::Line.create(title,"Digitization") do |l|
327
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true})
328
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
329
+ CF::Station.create({:line => l, :type => "work"}) do |s|
330
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
331
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
332
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
333
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
334
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
337
335
  end
338
336
  end
337
+ end
339
338
 
340
- run = CF::Run.create(line, "delete_line_of_run_run", File.expand_path("../../fixtures/input_data/test.csv", __FILE__))
341
- delete = CF::Line.destroy("delete_line_of_run")
342
- delete.error.message.should eql("Cannot delete line. You have production runs using this line. Pass force option to enforce deletion.")
343
- delete.code.should_not eql(200)
344
-
345
- forced_delete = CF::Line.destroy("delete_line_of_run", :forced => true)
339
+ run = CF::Run.create(line, "run-#{title}", File.expand_path("../../fixtures/input_data/test.csv", __FILE__))
340
+ delete = CF::Line.destroy(title)
341
+ delete['error']['message'].should eql("Cannot delete line. You have production runs using this line. Pass force option to enforce deletion.")
342
+ delete['code'].should_not eql(200)
346
343
 
347
- search_line = CF::Line.find("delete_line_of_run")
348
- search_line['code'].should eql(404)
349
- search_line['error']['message'].should eql("Line not found for title: delete_line_of_run under your account")
350
- end
344
+ forced_delete = CF::Line.destroy(title, :forced => true)
345
+
346
+ search_line = CF::Line.find(title)
347
+ search_line['code'].should eql(404)
348
+ search_line['error']['message'].should eql("Line not found for title: #{title} under your account")
351
349
  end
352
350
  end
353
-
351
+
354
352
  context "returns all the associated elements of line" do
355
353
  it "it give details of line" do
356
- VCR.use_cassette "lines/block/line-details", :record => :new_episodes do
357
- # WebMock.allow_net_connect!
358
- line = CF::Line.create("line_details","Digitization") do |l|
359
- CF::InputFormat.new({:line => l, :name => "Company", :required => true})
360
- CF::Station.create({:line => l, :type => "work"}) do |s|
361
- CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
362
- CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
363
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
364
- end
354
+ WebMock.allow_net_connect!
355
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
356
+ sleep 1
357
+ line = CF::Line.create(title,"Digitization") do |l|
358
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true})
359
+ CF::Station.create({:line => l, :type => "work"}) do |s|
360
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
361
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
362
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
365
363
  end
366
364
  end
367
- line_details = CF::Line.inspect("line_details")
368
- line_input_format_id = line_details['input_formats'].first['id']
369
- worker_id = line_details['stations'].first['worker']['id']
370
- form_field_id = line_details['stations'].first['form_fields'].first['id']
371
- station_input_format_id = line_details['stations'].first['input_formats'].first['id']
372
- line_details.should eql({"title"=>"line_details", "description"=>"", "department"=>"Digitization", "code"=>200, "input_formats"=>[{"id"=>"#{line_input_format_id}", "name"=>"Company", "required"=>true, "valid_type"=>nil}], "stations"=>[{"index"=>1, "type"=>"WorkStation", "worker"=>{"id"=>"4e679284551127c825000203", "number"=>1, "reward"=>20, "type"=>"HumanWorker", "stat_badge"=>{"abandonment_rate"=>30, "approval_rating"=>80, "country"=>nil, "adult"=>nil}, "skill_badge"=>nil}, "form"=>{"title"=>"Enter text from a business card image", "instruction"=>"Describe"}, "form_fields"=>[{"id"=>"#{form_field_id}", "label"=>"First Name", "field_type"=>"short_answer", "hint"=>nil, "required"=>true, "unique"=>nil, "hide_label"=>nil, "value"=>nil}], "input_formats"=>[{"id"=>"#{station_input_format_id}", "name"=>"Company", "required"=>true, "valid_type"=>nil}]}]})
373
365
  end
366
+ line_details = CF::Line.inspect(title)
367
+ line_input_format_id = line_details['input_formats'].first['id']
368
+ worker_id = line_details['stations'].first['worker']['id']
369
+ form_field_id = line_details['stations'].first['form_fields'].first['id']
370
+ station_input_format_id = line_details['stations'].first['input_formats'].first['id']
371
+ line_details.should eql({"title"=>"#{title}", "description"=>"", "department"=>"Digitization", "code"=>200, "input_formats"=>[{"id"=>"#{line_input_format_id}", "name"=>"Company", "required"=>true, "valid_type"=>nil}], "stations"=>[{"index"=>1, "type"=>"WorkStation", "worker"=>{"id"=>"#{worker_id}", "number"=>1, "reward"=>20, "type"=>"HumanWorker", "stat_badge"=>{"abandonment_rate"=>30, "approval_rating"=>80, "country"=>nil, "adult"=>nil}, "skill_badge"=>nil}, "form"=>{"title"=>"Enter text from a business card image", "instruction"=>"Describe"}, "form_fields"=>[{"id"=>"#{form_field_id}", "label"=>"First Name", "field_type"=>"short_answer", "hint"=>nil, "required"=>true, "unique"=>nil, "hide_label"=>nil, "value"=>nil}], "input_formats"=>[{"id"=>"#{station_input_format_id}", "name"=>"Company", "required"=>true, "valid_type"=>nil}]}]})
374
372
  end
375
-
373
+
376
374
  it "for robot worker" do
377
- VCR.use_cassette "lines/block/line-details_robot_worker", :record => :new_episodes do
378
- # WebMock.allow_net_connect!
379
- line = CF::Line.create("line_details_robot","Digitization") do |l|
380
- CF::InputFormat.new({:line => l, :name => "text", :required => "true"})
381
- CF::Station.create({:line => l, :type => "work"}) do |s|
382
- 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"]}})
383
- end
375
+ WebMock.allow_net_connect!
376
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
377
+ sleep 1
378
+ line = CF::Line.create(title,"Digitization") do |l|
379
+ CF::InputFormat.new({:line => l, :name => "text", :required => "true"})
380
+ CF::Station.create({:line => l, :type => "work"}) do |s|
381
+ 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"]}})
384
382
  end
385
- line_details = CF::Line.inspect("line_details_robot")
386
- line_input_format_id = line_details['input_formats'].first['id']
387
- station_input_format_id = line_details['stations'].first['input_formats'].first['id']
388
- worker_id = line_details['stations'].first['worker']['id']
389
- line_details.should eql({"title"=>"line_details_robot", "description"=>"", "department"=>"Digitization", "code"=>200, "input_formats"=>[{"id"=>"#{line_input_format_id}", "name"=>"text", "required"=>true, "valid_type"=>nil}], "stations"=>[{"index"=>1, "type"=>"WorkStation", "worker"=>{"id"=>"#{worker_id}", "number"=>1, "reward"=>0.5, "type"=>"EntityExtractionRobot"}, "input_formats"=>[{"id"=>"#{station_input_format_id}", "name"=>"text", "required"=>true, "valid_type"=>nil}]}]})
390
383
  end
384
+ line_details = CF::Line.inspect(title)
385
+ line_input_format_id = line_details['input_formats'].first['id']
386
+ station_input_format_id = line_details['stations'].first['input_formats'].first['id']
387
+ worker_id = line_details['stations'].first['worker']['id']
388
+ line_details.should eql({"title"=>"#{title}", "description"=>"", "department"=>"Digitization", "code"=>200, "input_formats"=>[{"id"=>"#{line_input_format_id}", "name"=>"text", "required"=>true, "valid_type"=>nil}], "stations"=>[{"index"=>1, "type"=>"WorkStation", "worker"=>{"id"=>"#{worker_id}", "number"=>1, "reward"=>0.5, "type"=>"EntityExtractionRobot"}, "input_formats"=>[{"id"=>"#{station_input_format_id}", "name"=>"text", "required"=>true, "valid_type"=>nil}]}]})
391
389
  end
392
-
390
+
393
391
  it "with skill test feature" do
394
- VCR.use_cassette "lines/block/line-details_skill_test", :record => :new_episodes do
395
- # WebMock.allow_net_connect!
396
- badge =
392
+ WebMock.allow_net_connect!
393
+ badge =
394
+ {
395
+ :title => 'Football Fanatic',
396
+ :description => "This qualification allows you to perform work at stations which have this badge.",
397
+ :max_badges => 3,
398
+ :test =>
397
399
  {
398
- :title => 'Football Fanatic',
399
- :description => "This qualification allows you to perform work at stations which have this badge.",
400
- :max_badges => 3,
401
- :test =>
402
- {
403
- :input => {:name => "Lionel Andres Messi", :country => "Argentina"},
404
- :expected_output =>
405
- [{: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 }}]
406
- }
400
+ :input => {:name => "Lionel Andres Messi", :country => "Argentina"},
401
+ :expected_output =>
402
+ [{: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 }}]
407
403
  }
408
- line = CF::Line.create("line_details_skill_test", "Digitization") do |l|
409
- CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
410
- CF::Station.create({:line =>l, :type => "work"}) do |s|
411
- CF::HumanWorker.new({:station => s, :number => 1, :reward => 20, :skill_badge => badge})
412
- CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
413
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
414
- end
404
+ }
405
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
406
+ sleep 2
407
+ line = CF::Line.create(title, "Digitization") do |l|
408
+ CF::InputFormat.new({:line => l, :name => "image_url", :required => true, :valid_type => "url"})
409
+ CF::Station.create({:line =>l, :type => "work"}) do |s|
410
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20, :skill_badge => badge})
411
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
412
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
415
413
  end
416
414
  end
417
- line_details = CF::Line.inspect("line_details_skill_test")
418
- line_input_format_id = line_details['input_formats'].first['id']
419
- station_input_format_id = line_details['stations'].first['input_formats'].first['id']
420
- form_field_id = line_details['stations'].first['form_fields'].first['id']
421
- worker_id = line_details['stations'].first['worker']['id']
422
- line_details.should eql({"title"=>"line_details_skill_test", "description"=>"", "department"=>"Digitization", "code"=>200, "input_formats"=>[{"id"=>"#{line_input_format_id}", "name"=>"image_url", "required"=>true, "valid_type"=>"url"}], "stations"=>[{"index"=>1, "type"=>"WorkStation", "worker"=>{"id"=>"#{worker_id}", "number"=>1, "reward"=>20, "type"=>"HumanWorker", "stat_badge"=>{"abandonment_rate"=>30, "approval_rating"=>80, "country"=>nil, "adult"=>nil}, "skill_badge"=>nil}, "form"=>{"title"=>"Enter text from a business card image", "instruction"=>"Describe"}, "form_fields"=>[{"id"=>"#{form_field_id}", "label"=>"First Name", "field_type"=>"short_answer", "hint"=>nil, "required"=>true, "unique"=>nil, "hide_label"=>nil, "value"=>nil}], "input_formats"=>[{"id"=>"#{station_input_format_id}", "name"=>"image_url", "required"=>true, "valid_type"=>"url"}]}]})
423
415
  end
416
+ line_details = CF::Line.inspect(title)
417
+ line_input_format_id = line_details['input_formats'].first['id']
418
+ station_input_format_id = line_details['stations'].first['input_formats'].first['id']
419
+ form_field_id = line_details['stations'].first['form_fields'].first['id']
420
+ worker_id = line_details['stations'].first['worker']['id']
421
+ line_details.should eql({"title"=>"#{title}", "description"=>"", "department"=>"Digitization", "code"=>200, "input_formats"=>[{"id"=>"#{line_input_format_id}", "name"=>"image_url", "required"=>true, "valid_type"=>"url"}], "stations"=>[{"index"=>1, "type"=>"WorkStation", "worker"=>{"id"=>"#{worker_id}", "number"=>1, "reward"=>20, "type"=>"HumanWorker", "stat_badge"=>{"abandonment_rate"=>30, "approval_rating"=>80, "country"=>nil, "adult"=>nil}, "skill_badge"=>nil}, "form"=>{"title"=>"Enter text from a business card image", "instruction"=>"Describe"}, "form_fields"=>[{"id"=>"#{form_field_id}", "label"=>"First Name", "field_type"=>"short_answer", "hint"=>nil, "required"=>true, "unique"=>nil, "hide_label"=>nil, "value"=>nil}], "input_formats"=>[{"id"=>"#{station_input_format_id}", "name"=>"image_url", "required"=>true, "valid_type"=>"url"}]}]})
424
422
  end
425
-
423
+
426
424
  it "should get all lines with pagination" do
427
- VCR.use_cassette "lines/plain-ruby/line_pagination", :record => :new_episodes do
428
- # WebMock.allow_net_connect!
429
- line = CF::Line.all(:page => 1)
430
- line.class.should eql(Hash)
431
- end
425
+ WebMock.allow_net_connect!
426
+ line = CF::Line.all(:page => 1)
427
+ line.class.should eql(Hash)
432
428
  end
433
-
429
+
434
430
  it "should get all lines with pagination all" do
435
- VCR.use_cassette "lines/plain-ruby/line_pagination_all", :record => :new_episodes do
436
- # WebMock.allow_net_connect!
437
- 25.times do |i|
438
- CF::Line.new("lines-listing--#{i}", "Digitization", {:public => true, :description => "#{i}-this is description"})
439
- end
440
- line = CF::Line.all(:page => "all")
441
- line['total_pages'].should eql(1)
442
- line['lines'].class.should eql(Array)
431
+ WebMock.allow_net_connect!
432
+ 25.times do |i|
433
+ title_i = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
434
+ sleep 1
435
+ CF::Line.new(title_i, "Digitization", {:public => true, :description => "#{i}-this is description"})
443
436
  end
437
+ line = CF::Line.all(:page => "all")
438
+ line['total_pages'].should eql(1)
439
+ line['lines'].class.should eql(Array)
444
440
  end
445
441
  end
446
-
442
+
447
443
  context "get a line of other account" do
448
444
  it "as public line" do
449
- VCR.use_cassette "lines/plain-ruby/public-line", :record => :new_episodes do
450
- # WebMock.allow_net_connect!
451
- got_line = CF::Line.find("hero/dummy")
452
- got_line['title'].should eql("dummy")
453
- got_line['public'].should eql(true)
454
-
455
- run = CF::Run.create("hero/dummy", "dummy_run", [{"text" => "run for public line of another account"}])
456
- run.title.should eql("dummy_run")
457
- run.input.should eql([{"text" => "run for public line of another account"}])
445
+ WebMock.allow_net_connect!
446
+ CF.configure do |config|
447
+ config.api_key = "1d38e382894338beda100736808f5a06083063e2"
448
+ config.account_name = "hero"
449
+ end
450
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
451
+ sleep 1
452
+ line = CF::Line.create(title, "Digitization") do
453
+ CF::InputFormat.new({:line => self, :name => "text", :required => true})
454
+ CF::Station.create({:line => self, :type => "work"}) do |station|
455
+ CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
456
+ CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
457
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
458
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
459
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
460
+ end
461
+ end
458
462
  end
463
+ got_line = CF::Line.find("hero/#{title}")
464
+ got_line['title'].should eql("#{title}")
465
+ got_line['public'].should eql(true)
466
+ CF.configure do |config|
467
+ config.account_name = API_CONFIG['account_name']
468
+ config.api_version = API_CONFIG['api_version']
469
+ config.api_url = API_CONFIG['api_url']
470
+ config.api_key = API_CONFIG['api_key']
471
+ end
472
+ run = CF::Run.create("hero/#{title}", "run-#{title}", [{"text" => "run for public line of another account"}])
473
+ run.title.should eql("run-#{title}")
474
+ run.input.should eql([{"text" => "run for public line of another account"}])
459
475
  end
460
-
476
+
461
477
  it "as private line" do
462
- VCR.use_cassette "lines/plain-ruby/private-line", :record => :new_episodes do
463
- # WebMock.allow_net_connect!
464
- got_line = CF::Line.find("hero/dummy_false")
465
- got_line['code'].should eql(404)
466
- got_line['error']['message'].should eql("Line with title: dummy_false under account hero is not public")
478
+ WebMock.allow_net_connect!
479
+ CF.configure do |config|
480
+ config.api_key = "1d38e382894338beda100736808f5a06083063e2"
481
+ config.account_name = "hero"
482
+ end
483
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
484
+ sleep 1
485
+ line = CF::Line.new(title, "Digitization", {:public => false, :description => "this is description"})
486
+ CF.configure do |config|
487
+ config.account_name = API_CONFIG['account_name']
488
+ config.api_version = API_CONFIG['api_version']
489
+ config.api_url = API_CONFIG['api_url']
490
+ config.api_key = API_CONFIG['api_key']
467
491
  end
492
+ got_line = CF::Line.find("hero/#{title}")
493
+ got_line['code'].should eql(404)
494
+ got_line['error']['message'].should eql("Line with title: #{title} under account hero is not public")
468
495
  end
469
496
  end
470
-
497
+
471
498
  context "create line with output format" do
472
499
  it "should create in block Dsl way with two stations" do
473
- # WebMock.allow_net_connect!
474
- VCR.use_cassette "lines/block/create-output-format", :record => :new_episodes do
475
- line = CF::Line.create("line_with_output_format","Digitization") do |l|
476
- CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
477
- CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
478
- CF::Station.create({:line => l, :type => "work"}) do |s|
479
- CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
480
- CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
481
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
482
- CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
483
- CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
484
- end
500
+ WebMock.allow_net_connect!
501
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
502
+ sleep 1
503
+ line = CF::Line.create(title,"Digitization") do |l|
504
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
505
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
506
+ CF::Station.create({:line => l, :type => "work"}) do |s|
507
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
508
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
509
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
510
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
511
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
485
512
  end
486
- CF::Station.create({:line => l, :type => "work"}) do |s|
487
- CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
488
- CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
489
- CF::FormField.new({:form => i, :label => "Address", :field_type => "short_answer", :required => "true"})
490
- CF::FormField.new({:form => i, :label => "Mobile", :field_type => "short_answer"})
491
- CF::FormField.new({:form => i, :label => "Email", :field_type => "email", :required => "true"})
492
- end
513
+ end
514
+ CF::Station.create({:line => l, :type => "work"}) do |s|
515
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
516
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
517
+ CF::FormField.new({:form => i, :label => "Address", :field_type => "short_answer", :required => "true"})
518
+ CF::FormField.new({:form => i, :label => "Mobile", :field_type => "short_answer"})
519
+ CF::FormField.new({:form => i, :label => "Email", :field_type => "email", :required => "true"})
493
520
  end
494
- CF::OutputFormat.new({:line => l, :station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
495
521
  end
496
- line.title.should eq("line_with_output_format")
497
- line.input_formats.first.name.should eql("Company")
498
- line.stations.first.type.should eq("WorkStation")
499
- line.stations.first.worker.number.should eq(1)
500
- line.stations.first.worker.reward.should eq(10)
501
- line.output_formats.settings.should eql({:station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
522
+ CF::OutputFormat.new({:line => l, :station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
502
523
  end
524
+ line.title.should eq(title)
525
+ line.input_formats.first.name.should eql("Company")
526
+ line.stations.first.type.should eq("WorkStation")
527
+ line.stations.first.worker.number.should eq(1)
528
+ line.stations.first.worker.reward.should eq(10)
529
+ line.output_formats.settings.should eql({:station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
503
530
  end
504
-
531
+
505
532
  it "should create in plain ruby way with two stations" do
506
- # WebMock.allow_net_connect!
507
- VCR.use_cassette "lines/plain-ruby/create-output-format", :record => :new_episodes do
508
- line = CF::Line.create("line_with_output_format_1","Digitization") do |l|
509
- CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
510
- CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
511
- CF::Station.create({:line => l, :type => "work"}) do |s|
512
- CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
513
- CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
514
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
515
- CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
516
- CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
517
- end
533
+ WebMock.allow_net_connect!
534
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
535
+ sleep 1
536
+ line = CF::Line.create(title,"Digitization") do |l|
537
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
538
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
539
+ CF::Station.create({:line => l, :type => "work"}) do |s|
540
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
541
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
542
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
543
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
544
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
518
545
  end
519
- CF::Station.create({:line => l, :type => "work"}) do |s|
520
- CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
521
- CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
522
- CF::FormField.new({:form => i, :label => "Address", :field_type => "short_answer", :required => "true"})
523
- CF::FormField.new({:form => i, :label => "Mobile", :field_type => "short_answer"})
524
- CF::FormField.new({:form => i, :label => "Email", :field_type => "email", :required => "true"})
525
- end
546
+ end
547
+ CF::Station.create({:line => l, :type => "work"}) do |s|
548
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
549
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
550
+ CF::FormField.new({:form => i, :label => "Address", :field_type => "short_answer", :required => "true"})
551
+ CF::FormField.new({:form => i, :label => "Mobile", :field_type => "short_answer"})
552
+ CF::FormField.new({:form => i, :label => "Email", :field_type => "email", :required => "true"})
526
553
  end
527
554
  end
528
- output_format = CF::OutputFormat.new({:station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
529
- line.output_formats output_format
530
- line.title.should eq("line_with_output_format_1")
531
- line.input_formats.first.name.should eql("Company")
532
- line.stations.first.type.should eq("WorkStation")
533
- line.stations.first.worker.number.should eq(1)
534
- line.stations.first.worker.reward.should eq(10)
535
- line.output_formats.settings.should eql({:station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
536
555
  end
556
+ output_format = CF::OutputFormat.new({:station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
557
+ line.output_formats output_format
558
+ line.title.should eq(title)
559
+ line.input_formats.first.name.should eql("Company")
560
+ line.stations.first.type.should eq("WorkStation")
561
+ line.stations.first.worker.number.should eq(1)
562
+ line.stations.first.worker.reward.should eq(10)
563
+ line.output_formats.settings.should eql({:station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
537
564
  end
538
-
565
+
539
566
  it "should through error if line is incomplete" do
540
- # WebMock.allow_net_connect!
541
- VCR.use_cassette "lines/block/create-output-format-error", :record => :new_episodes do
542
- line = CF::Line.create("line_with_output_format","Digitization") do |l|
543
- CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
544
- CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
545
- CF::Station.create({:line => l, :type => "work"}) do |s|
546
- CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
547
- # CF::TaskForm.new({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"})
548
- end
549
- CF::OutputFormat.new({:line => l, :station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
567
+ WebMock.allow_net_connect!
568
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
569
+ sleep 1
570
+ line = CF::Line.create(title,"Digitization") do |l|
571
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
572
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
573
+ CF::Station.create({:line => l, :type => "work"}) do |s|
574
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
550
575
  end
551
- line.title.should eq("line_with_output_format")
552
- line.input_formats.first.name.should eql("Company")
553
- line.stations.first.type.should eq("WorkStation")
554
- line.stations.first.worker.number.should eq(1)
555
- line.stations.first.worker.reward.should eq(10)
556
- line.output_formats.errors.should eql("Line is not complete or valid")
576
+ CF::OutputFormat.new({:line => l, :station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
557
577
  end
578
+ line.title.should eq(title)
579
+ line.input_formats.first.name.should eql("Company")
580
+ line.stations.first.type.should eq("WorkStation")
581
+ line.stations.first.worker.number.should eq(1)
582
+ line.stations.first.worker.reward.should eq(10)
583
+ line.output_formats.errors.should eql("Line is not complete or valid")
558
584
  end
559
585
  end
560
586
  end