cloudfactory 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,51 +5,51 @@ module CF
5
5
  describe CF::RobotWorker do
6
6
  context "create a sentiment robot worker" do
7
7
  it "should create content_scraping_robot worker for first station in Block DSL way" do
8
- # WebMock.allow_net_connect!
9
- VCR.use_cassette "robot_worker/sentiment_robot/block/create-worker-single-station", :record => :new_episodes do
10
- line = CF::Line.create("sentiment_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, :settings => {:document => ["{{url}}"], :sanitize => true}, :type => "sentiment_robot"})
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, :settings => {:document => ["{{url}}"], :sanitize => true}, :type => "sentiment_robot"})
15
15
  end
16
- run = CF::Run.create(line, "sentiment_robot_run", [{"url"=> "http://www.thehappyguy.com/happiness-self-help-book.html"}])
17
- # sleep 20
18
- output = run.final_output
19
- output.first['sentiment_of_url'].should eql("positive")
20
- output.first['sentiment_relevance_of_url'].should eql(24.0408)
21
- line.stations.first.worker.class.should eql(CF::RobotWorker)
22
- line.stations.first.worker.reward.should eql(0.5)
23
- line.stations.first.worker.number.should eql(1)
24
- line.stations.first.worker.settings.should eql({:document => ["{{url}}"], :sanitize => true})
25
- line.stations.first.worker.type.should eql("SentimentRobot")
26
16
  end
17
+ run = CF::Run.create(line, "run-#{title}", [{"url"=> "http://www.thehappyguy.com/happiness-self-help-book.html"}])
18
+ sleep 10
19
+ output = run.final_output
20
+ output.first['sentiment_of_url'].should eql("positive")
21
+ output.first['sentiment_relevance_of_url'].should eql(25.7649)
22
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
23
+ line.stations.first.worker.reward.should eql(0.5)
24
+ line.stations.first.worker.number.should eql(1)
25
+ line.stations.first.worker.settings.should eql({:document => ["{{url}}"], :sanitize => true})
26
+ line.stations.first.worker.type.should eql("SentimentRobot")
27
27
  end
28
28
 
29
29
  it "should create content_scraping_robot worker for first station in plain ruby way" do
30
- # WebMock.allow_net_connect!
31
- VCR.use_cassette "robot_worker/sentiment_robot/plain_ruby/create-worker-single-station", :record => :new_episodes do
32
- line = CF::Line.new("sentiment_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.new({:settings => {:document => ["{{url}}"], :sanitize => true}, :type => "sentiment_robot"})
40
- line.stations.first.worker = worker
40
+ worker = CF::RobotWorker.new({:settings => {:document => ["{{url}}"], :sanitize => true}, :type => "sentiment_robot"})
41
+ line.stations.first.worker = worker
41
42
 
42
- run = CF::Run.create(line, "sentiment_robot_run_1", [{"url"=> "http://www.thehappyguy.com/happiness-self-help-book.html"}])
43
- # sleep 20
44
- output = run.final_output
45
- output.first['sentiment_of_url'].should eql("positive")
46
- output.first['sentiment_relevance_of_url'].should eql(24.0408)
47
- line.stations.first.worker.class.should eql(CF::RobotWorker)
48
- line.stations.first.worker.reward.should eql(0.5)
49
- line.stations.first.worker.number.should eql(1)
50
- line.stations.first.worker.settings.should eql({:document => ["{{url}}"], :sanitize => true})
51
- line.stations.first.worker.type.should eql("SentimentRobot")
52
- end
43
+ run = CF::Run.create(line, "run-#{title}", [{"url"=> "http://www.thehappyguy.com/happiness-self-help-book.html"}])
44
+ sleep 10
45
+ output = run.final_output
46
+ output.first['sentiment_of_url'].should eql("positive")
47
+ output.first['sentiment_relevance_of_url'].should eql(25.7649)
48
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
49
+ line.stations.first.worker.reward.should eql(0.5)
50
+ line.stations.first.worker.number.should eql(1)
51
+ line.stations.first.worker.settings.should eql({:document => ["{{url}}"], :sanitize => true})
52
+ line.stations.first.worker.type.should eql("SentimentRobot")
53
53
  end
54
54
  end
55
55
  end
data/spec/station_spec.rb CHANGED
@@ -3,284 +3,286 @@ require 'spec_helper'
3
3
  describe CF::Station do
4
4
  context "create a station" do
5
5
  it "the plain ruby way" do
6
- # WebMock.allow_net_connect!
7
- VCR.use_cassette "stations/plain-ruby/create", :record => :new_episodes do
8
- line = CF::Line.new("Digitize--ard", "Digitization")
9
- CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
10
- station = CF::Station.new({:type => "work"})
11
- line.stations station
12
- line.stations.first.type.should eql("WorkStation")
13
- 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
+ CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
11
+ station = CF::Station.new({:type => "work"})
12
+ line.stations station
13
+ line.stations.first.type.should eql("WorkStation")
14
14
  end
15
15
 
16
16
  it "using the block variable" do
17
- # WebMock.allow_net_connect!
18
- VCR.use_cassette "stations/block/create-with-block-var", :record => :new_episodes do
19
- line = CF::Line.create("igitizeard", "Digitization") do
20
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
21
- CF::Station.create({:line => self, :type => "work"}) do |s|
22
- CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
23
- CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
24
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
25
- CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
26
- CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
27
- end
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
21
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
22
+ CF::Station.create({:line => self, :type => "work"}) do |s|
23
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
24
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
25
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
26
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
27
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
28
28
  end
29
29
  end
30
- line.stations.first.type.should eq("WorkStation")
31
- line.stations.first.worker.number.should eql(1)
32
- line.stations.first.worker.reward.should eql(20)
33
- line.stations.first.form.title.should eq("Enter text from a business card image")
34
- line.stations.first.form.instruction.should eq("Describe")
35
- line.stations.first.form.form_fields[0].label.should eq("First Name")
36
- line.stations.first.form.form_fields[1].label.should eq("Middle Name")
37
- line.stations.first.form.form_fields[2].label.should eq("Last Name")
38
30
  end
31
+ line.stations.first.type.should eq("WorkStation")
32
+ line.stations.first.worker.number.should eql(1)
33
+ line.stations.first.worker.reward.should eql(20)
34
+ line.stations.first.form.title.should eq("Enter text from a business card image")
35
+ line.stations.first.form.instruction.should eq("Describe")
36
+ line.stations.first.form.form_fields[0].label.should eq("First Name")
37
+ line.stations.first.form.form_fields[1].label.should eq("Middle Name")
38
+ line.stations.first.form.form_fields[2].label.should eq("Last Name")
39
39
  end
40
40
 
41
41
  it "using without the block variable also creating instruction without block variable" do
42
- # WebMock.allow_net_connect!
43
- VCR.use_cassette "stations/block/create-without-block-var", :record => :new_episodes do
44
- line = CF::Line.create("Digitizrd", "Digitization") do
45
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
46
- CF::Station.create({:line => self, :type => "work"}) do
47
- CF::HumanWorker.new({:station => self, :number => 1, :reward => 20})
48
- CF::TaskForm.create({:station => self, :title => "Enter text from a business card image", :instruction => "Describe"}) do
49
- CF::FormField.new({:form => self, :label => "First Name", :field_type => "short_answer", :required => "true"})
50
- CF::FormField.new({:form => self, :label => "Middle Name", :field_type => "short_answer"})
51
- CF::FormField.new({:form => self, :label => "Last Name", :field_type => "short_answer", :required => "true"})
52
- end
42
+ WebMock.allow_net_connect!
43
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
44
+ sleep 1
45
+ line = CF::Line.create(title, "Digitization") do
46
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
47
+ CF::Station.create({:line => self, :type => "work"}) do
48
+ CF::HumanWorker.new({:station => self, :number => 1, :reward => 20})
49
+ CF::TaskForm.create({:station => self, :title => "Enter text from a business card image", :instruction => "Describe"}) do
50
+ CF::FormField.new({:form => self, :label => "First Name", :field_type => "short_answer", :required => "true"})
51
+ CF::FormField.new({:form => self, :label => "Middle Name", :field_type => "short_answer"})
52
+ CF::FormField.new({:form => self, :label => "Last Name", :field_type => "short_answer", :required => "true"})
53
53
  end
54
54
  end
55
- line.stations.first.type.should eq("WorkStation")
56
- line.stations.first.worker.number.should eql(1)
57
- line.stations.first.worker.reward.should eql(20)
58
- line.stations.first.form.title.should eq("Enter text from a business card image")
59
- line.stations.first.form.instruction.should eq("Describe")
60
- line.stations.first.form.form_fields[0].label.should eq("First Name")
61
- line.stations.first.form.form_fields[1].label.should eq("Middle Name")
62
- line.stations.first.form.form_fields[2].label.should eq("Last Name")
63
55
  end
56
+ line.stations.first.type.should eq("WorkStation")
57
+ line.stations.first.worker.number.should eql(1)
58
+ line.stations.first.worker.reward.should eql(20)
59
+ line.stations.first.form.title.should eq("Enter text from a business card image")
60
+ line.stations.first.form.instruction.should eq("Describe")
61
+ line.stations.first.form.form_fields[0].label.should eq("First Name")
62
+ line.stations.first.form.form_fields[1].label.should eq("Middle Name")
63
+ line.stations.first.form.form_fields[2].label.should eq("Last Name")
64
64
  end
65
65
 
66
66
  it "should create a station of Tournament station" do
67
- # WebMock.allow_net_connect!
68
- VCR.use_cassette "stations/block/tournament-station", :record => :new_episodes do
69
- line = CF::Line.create("Digitized-9", "Digitization") do
70
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
71
- CF::Station.create({:line => self, :type => "tournament", :jury_worker=> {:max_judges => 10, :reward => 5}, :auto_judge => {:enabled => true}}) do |s|
72
- CF::HumanWorker.new({:station => s, :number => 3, :reward => 20})
73
- CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
74
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
75
- CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
76
- CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
77
- end
67
+ WebMock.allow_net_connect!
68
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
69
+ sleep 1
70
+ line = CF::Line.create(title, "Digitization") do
71
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
72
+ CF::Station.create({:line => self, :type => "tournament", :jury_worker=> {:max_judges => 10, :reward => 5}, :auto_judge => {:enabled => true}}) do |s|
73
+ CF::HumanWorker.new({:station => s, :number => 3, :reward => 20})
74
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
75
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
76
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
77
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
78
78
  end
79
79
  end
80
- line.stations.first.type.should eq("TournamentStation")
81
- line.stations.first.jury_worker.should eql({"max_judges"=>10, "confidence_level"=>0.65, "tournament_restarts"=>0, "number"=>2})
82
- line.stations.first.auto_judge.should eql({"enabled"=>true, "finalize_percentage"=>51})
83
- line.stations.first.worker.number.should eql(3)
84
- line.stations.first.worker.reward.should eql(20)
85
- line.stations.first.form.title.should eq("Enter text from a business card image")
86
- line.stations.first.form.instruction.should eq("Describe")
87
- line.stations.first.form.form_fields[0].label.should eq("First Name")
88
- line.stations.first.form.form_fields[1].label.should eq("Middle Name")
89
- line.stations.first.form.form_fields[2].label.should eq("Last Name")
90
80
  end
81
+ line.stations.first.type.should eq("TournamentStation")
82
+ line.stations.first.jury_worker.should eql({"max_judges"=>10, "confidence_level"=>0.65, "tournament_restarts"=>0, "number"=>2})
83
+ line.stations.first.auto_judge.should eql({"enabled"=>true, "finalize_percentage"=>51})
84
+ line.stations.first.worker.number.should eql(3)
85
+ line.stations.first.worker.reward.should eql(20)
86
+ line.stations.first.form.title.should eq("Enter text from a business card image")
87
+ line.stations.first.form.instruction.should eq("Describe")
88
+ line.stations.first.form.form_fields[0].label.should eq("First Name")
89
+ line.stations.first.form.form_fields[1].label.should eq("Middle Name")
90
+ line.stations.first.form.form_fields[2].label.should eq("Last Name")
91
91
  end
92
92
 
93
93
  it "should create a station of Improve station as first station of line" do
94
- # WebMock.allow_net_connect!
95
- VCR.use_cassette "stations/block/improve-as-first-station", :record => :new_episodes do
96
- line = CF::Line.new("Digitd", "Digitization")
97
- CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
98
- station = CF::Station.new({:type => "improve"})
99
- expect { line.stations station }.to raise_error(CF::ImproveStationNotAllowed)
100
- end
94
+ WebMock.allow_net_connect!
95
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
96
+ sleep 1
97
+ line = CF::Line.new(title, "Digitization")
98
+ CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
99
+ station = CF::Station.new({:type => "improve"})
100
+ expect { line.stations station }.to raise_error(CF::ImproveStationNotAllowed)
101
101
  end
102
-
102
+
103
103
  it "should only display the attributes which are mentioned in to_s method" do
104
- VCR.use_cassette "stations/block/display-to_s", :record => :new_episodes do
105
- # WebMock.allow_net_connect!
106
- line = CF::Line.create("Display_station", "Digitization") do
107
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
108
- CF::Station.create({:line => self, :type => "work"}) do |station|
109
- CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
110
- end
104
+ WebMock.allow_net_connect!
105
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
106
+ sleep 1
107
+ line = CF::Line.create(title, "Digitization") do
108
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
109
+ CF::Station.create({:line => self, :type => "work"}) do |station|
110
+ CF::HumanWorker.new({:station => station, :number => 1, :reward => 20})
111
111
  end
112
- line.stations.first.to_s.should eql("{:type => WorkStation, :index => 1, :line_title => Display_station, :station_input_formats => , :errors => }")
113
112
  end
113
+ line.stations.first.to_s.should eql("{:type => WorkStation, :index => 1, :line_title => #{title}, :station_input_formats => , :errors => }")
114
114
  end
115
-
115
+
116
116
  it "should only display the attributes which are mentioned in to_s method for tournament station" do
117
- VCR.use_cassette "stations/block/display-to_s-tournament", :record => :new_episodes do
118
- # WebMock.allow_net_connect!
119
- line = CF::Line.create("Display_station_tournament", "Digitization") do
120
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
121
- CF::Station.create({:line => self, :type => "tournament", :jury_worker=> {:max_judges => 10, :reward => 5}, :auto_judge => {:enabled => true}}) do |s|
122
- CF::HumanWorker.new({:station => s, :number => 2, :reward => 20})
123
- end
117
+ WebMock.allow_net_connect!
118
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
119
+ sleep 1
120
+ line = CF::Line.create(title, "Digitization") do
121
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
122
+ CF::Station.create({:line => self, :type => "tournament", :jury_worker=> {:max_judges => 10, :reward => 5}, :auto_judge => {:enabled => true}}) do |s|
123
+ CF::HumanWorker.new({:station => s, :number => 2, :reward => 20})
124
124
  end
125
- line.stations.first.to_s.should eql("{:type => TournamentStation, :index => 1, :line_title => Display_station_tournament, :station_input_formats => , :jury_worker => {\"max_judges\"=>10, \"confidence_level\"=>0.65, \"tournament_restarts\"=>0, \"number\"=>2}, auto_judge => {\"enabled\"=>true, \"finalize_percentage\"=>51}, :errors => }")
126
125
  end
126
+ line.stations.first.to_s.should eql("{:type => TournamentStation, :index => 1, :line_title => #{title}, :station_input_formats => , :jury_worker => {\"max_judges\"=>10, \"confidence_level\"=>0.65, \"tournament_restarts\"=>0, \"number\"=>2}, auto_judge => {\"enabled\"=>true, \"finalize_percentage\"=>51}, :errors => }")
127
127
  end
128
128
  end
129
129
 
130
130
  context "get station" do
131
131
  it "should get information about a single station" do
132
- # WebMock.allow_net_connect!
133
- VCR.use_cassette "stations/plain-ruby/get-station", :record => :new_episodes do
134
- line = CF::Line.new("Digitizerd1","Digitization")
135
- line.title.should eq("Digitizerd1")
136
- CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
137
- station = CF::Station.new(:type => "Work")
138
- line.stations station
139
- station.type.should eq("Work")
140
- line.stations.first.get.type.should eq("WorkStation")
141
- end
132
+ WebMock.allow_net_connect!
133
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
134
+ sleep 1
135
+ line = CF::Line.new(title,"Digitization")
136
+ line.title.should eq(title)
137
+ CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
138
+ station = CF::Station.new(:type => "Work")
139
+ line.stations station
140
+ station.type.should eq("Work")
141
+ line.stations.first.get['type'].should eq("WorkStation")
142
142
  end
143
143
 
144
144
  it "should get all existing stations of a line" do
145
- # WebMock.allow_net_connect!
146
- VCR.use_cassette "stations/plain-ruby/get-all-stations", :record => :new_episodes do
147
- line = CF::Line.new("Digitizrd11","Digitization")
148
- line.title.should eq("Digitizrd11")
149
- CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
150
- station = CF::Station.new(:type => "Work")
151
- line.stations station
152
- stations = CF::Station.all(line)
153
- stations[0].type.should eq("WorkStation")
154
- end
145
+ WebMock.allow_net_connect!
146
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
147
+ sleep 1
148
+ line = CF::Line.new(title,"Digitization")
149
+ line.title.should eq(title)
150
+ CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
151
+ station = CF::Station.new(:type => "Work")
152
+ line.stations station
153
+ stations = CF::Station.all(line)
154
+ stations.map {|s| s['type']}.join(",").should eq("WorkStation")
155
155
  end
156
156
  end
157
157
 
158
158
  context "create multiple station" do
159
159
  it "should create two stations using different input format" do
160
- # WebMock.allow_net_connect!
161
- VCR.use_cassette "stations/block/multiple-station-adding-input-format", :record => :new_episodes do
162
- line = CF::Line.create("Company-info-214","Digitization") do |l|
163
- CF::InputFormat.new({:line => l, :name => "Company", :required => true})
164
- CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
165
- CF::Station.create({:line => l, :type => "work", :input_formats=> {:station_0 => [{:name => "Company"},{:name => "Website", :except => true}]}}) do |s|
166
- CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
167
- CF::TaskForm.create({:station => s, :title => "Enter the name of CEO", :instruction => "Describe"}) do |i|
168
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
169
- CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
170
- CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
171
- end
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.create(title,"Digitization") do |l|
164
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true})
165
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
166
+ CF::Station.create({:line => l, :type => "work", :input_formats=> {:station_0 => [{:name => "Company"},{:name => "Website", :except => true}]}}) do |s|
167
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
168
+ CF::TaskForm.create({:station => s, :title => "Enter the name of CEO", :instruction => "Describe"}) do |i|
169
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
170
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
171
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
172
172
  end
173
173
  end
174
+ end
174
175
 
175
- station = CF::Station.new(
176
- {:type => "work", :input_formats => {:station_0 => [{:name => "Website"}], :station_1 => [{:name => "Last Name", :except => true}]}})
177
- line.stations station
176
+ station = CF::Station.new(
177
+ {:type => "work", :input_formats => {:station_0 => [{:name => "Website"}], :station_1 => [{:name => "Last Name", :except => true}]}})
178
+ line.stations station
178
179
 
179
- worker = CF::HumanWorker.new({:number => 1, :reward => 10})
180
- line.stations.last.worker = worker
180
+ worker = CF::HumanWorker.new({:number => 1, :reward => 10})
181
+ line.stations.last.worker = worker
181
182
 
182
- form = CF::TaskForm.new({:title => "Enter the address of the given Person", :instruction => "Description"})
183
- line.stations.last.form = form
183
+ form = CF::TaskForm.new({:title => "Enter the address of the given Person", :instruction => "Description"})
184
+ line.stations.last.form = form
184
185
 
185
- form_fields_1 = CF::FormField.new({:label => "Street", :field_type => "short_answer", :required => "true"})
186
- line.stations.last.form.form_fields form_fields_1
187
- form_fields_2 = CF::FormField.new({:label => "City", :field_type => "short_answer", :required => "true"})
188
- line.stations.last.form.form_fields form_fields_2
189
- form_fields_3 = CF::FormField.new({:label => "Country", :field_type => "short_answer", :required => "true"})
190
- line.stations.last.form.form_fields form_fields_3
191
- station_1 = line.stations.first.get
192
- station_1.input_formats.count.should eql(1)
193
- station_1.input_formats.first.name.should eql("Company")
194
- station_1.input_formats.first.required.should eql(true)
195
- station_2 = line.stations.last.get
196
- station_2.input_formats.count.should eql(3)
197
- station_2.input_formats.map(&:name).should include("Website")
198
- station_2.input_formats.map(&:name).should include("First Name")
199
- station_2.input_formats.map(&:name).should include("Middle Name")
200
- station_2.input_formats.map(&:required).should include(true)
201
- station_2.input_formats.map(&:required).should include(false) #how to make it true
202
- station_2.input_formats.map(&:required).should include(false)
203
- station_2.input_formats.map(&:valid_type).should include("url")
204
- end
186
+ form_fields_1 = CF::FormField.new({:label => "Street", :field_type => "short_answer", :required => "true"})
187
+ line.stations.last.form.form_fields form_fields_1
188
+ form_fields_2 = CF::FormField.new({:label => "City", :field_type => "short_answer", :required => "true"})
189
+ line.stations.last.form.form_fields form_fields_2
190
+ form_fields_3 = CF::FormField.new({:label => "Country", :field_type => "short_answer", :required => "true"})
191
+ line.stations.last.form.form_fields form_fields_3
192
+ station_1 = line.stations.first.get
193
+ station_1['input_formats'].count.should eql(1)
194
+ station_1['input_formats'].first['name'].should eql("Company")
195
+ station_1['input_formats'].first['required'].should eql(true)
196
+ station_2 = line.stations.last.get
197
+ station_2['input_formats'].count.should eql(3)
198
+ names = station_2['input_formats'].map {|i| i['name']}.join(",")
199
+ required_states = station_2['input_formats'].map {|i| i['required']}.join(",")
200
+ names.should include("Website")
201
+ names.should include("First Name")
202
+ names.should include("Middle Name")
203
+ required_states.should include("true")
204
+ required_states.should include("false") #how to make it true
205
+ required_states.should include("false")
206
+ station_2['input_formats'].map {|i| i['valid_type']}.join(",").should include("url")
205
207
  end
206
208
  end
207
209
 
208
210
  context "create a station with errors" do
209
211
  it "in plain ruby way and it should display an error message" do
210
- # WebMock.allow_net_connect!
211
- VCR.use_cassette "stations/plain-ruby/create-without-type", :record => :new_episodes do
212
- line = CF::Line.new("Digitize--ard", "Digitization")
213
- station = CF::Station.new()
214
- line.stations station
215
- line.stations.first.errors.should eql("The Station type is invalid.")
216
- end
212
+ WebMock.allow_net_connect!
213
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
214
+ sleep 1
215
+ line = CF::Line.new(title, "Digitization")
216
+ station = CF::Station.new()
217
+ line.stations station
218
+ line.stations.first.errors.should eql("The Station type is invalid.")
217
219
  end
218
-
220
+
219
221
  it "in block DSL way and it should display an error message" do
220
- # WebMock.allow_net_connect!
221
- VCR.use_cassette "stations/block/create-without-type", :record => :new_episodes do
222
- line = CF::Line.create("Digitize--ard1", "Digitization") do |l|
223
- CF::Station.new({:line => l})
224
- end
225
- line.stations.first.errors.should eql("The Station type is invalid.")
222
+ WebMock.allow_net_connect!
223
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
224
+ sleep 1
225
+ line = CF::Line.create(title, "Digitization") do |l|
226
+ CF::Station.new({:line => l})
226
227
  end
228
+ line.stations.first.errors.should eql("The Station type is invalid.")
227
229
  end
228
-
230
+
229
231
  it "in block DSL way without creating input_format it should display an error message" do
230
- # WebMock.allow_net_connect!
231
- VCR.use_cassette "stations/block/create-without-input_type_error", :record => :new_episodes do
232
- line = CF::Line.create("Digitize--ard2", "Digitization") do |l|
233
- CF::Station.new({:line => l, :type => "work"})
234
- end
235
- line.stations.first.errors.should eql("Input formats not assigned for the line #{line.title.downcase}")
232
+ WebMock.allow_net_connect!
233
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
234
+ sleep 1
235
+ line = CF::Line.create(title, "Digitization") do |l|
236
+ CF::Station.new({:line => l, :type => "work"})
236
237
  end
238
+ line.stations.first.errors.should eql("Input formats not assigned for the line #{line.title.downcase}")
237
239
  end
238
-
240
+
239
241
  it "Tournament station displaying errors due to invalid settings" do
240
- # WebMock.allow_net_connect!
241
- VCR.use_cassette "stations/block/tournament-station-error", :record => :new_episodes do
242
- line = CF::Line.create("Digitized-91", "Digitization") do
243
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
244
- CF::Station.new({:line => self, :type => "tournament"})
245
- end
246
- line.stations.first.type.should eq("Tournament")
247
- line.stations.first.errors.should eql("[\"Jury worker can't be blank\"]")
242
+ WebMock.allow_net_connect!
243
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
244
+ sleep 1
245
+ line = CF::Line.create(title, "Digitization") do
246
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
247
+ CF::Station.new({:line => self, :type => "tournament"})
248
248
  end
249
+ line.stations.first.type.should eq("Tournament")
250
+ line.stations.first.errors.should eql("[\"Jury worker can't be blank\"]")
249
251
  end
250
252
  end
251
-
253
+
252
254
  context "create station with batch size option" do
253
255
  it "for work station in block DSL way" do
254
- # WebMock.allow_net_connect!
255
- VCR.use_cassette "stations/block/create-with-batch-size", :record => :new_episodes do
256
- line = CF::Line.create("batch_size_line", "Digitization") do
257
- CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
258
- CF::Station.create({:line => self, :type => "work", :batch_size => 3}) do |s|
259
- CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
260
- CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
261
- CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
262
- CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
263
- CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
264
- end
256
+ WebMock.allow_net_connect!
257
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
258
+ sleep 1
259
+ line = CF::Line.create(title, "Digitization") do
260
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
261
+ CF::Station.create({:line => self, :type => "work", :batch_size => 3}) do |s|
262
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
263
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
264
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
265
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
266
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
265
267
  end
266
268
  end
267
- line.stations.first.type.should eql("WorkStation")
268
- line.stations.first.batch_size.should eql(3)
269
- line.stations.first.worker.number.should eql(1)
270
- line.stations.first.worker.reward.should eql(20)
271
269
  end
270
+ line.stations.first.type.should eql("WorkStation")
271
+ line.stations.first.batch_size.should eql(3)
272
+ line.stations.first.worker.number.should eql(1)
273
+ line.stations.first.worker.reward.should eql(20)
272
274
  end
273
-
275
+
274
276
  it "for work station in Plain Ruby way" do
275
- # WebMock.allow_net_connect!
276
- VCR.use_cassette "stations/plain-ruby/create-with-batch-size", :record => :new_episodes do
277
- line = CF::Line.new("batch_size_line_1", "Digitization")
278
- CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
279
- station = CF::Station.new({:type => "work", :batch_size => 3})
280
- line.stations station
281
- line.stations.first.type.should eql("WorkStation")
282
- line.stations.first.batch_size.should eql(3)
283
- end
277
+ WebMock.allow_net_connect!
278
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
279
+ sleep 1
280
+ line = CF::Line.new(title, "Digitization")
281
+ CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
282
+ station = CF::Station.new({:type => "work", :batch_size => 3})
283
+ line.stations station
284
+ line.stations.first.type.should eql("WorkStation")
285
+ line.stations.first.batch_size.should eql(3)
284
286
  end
285
287
  end
286
288
  end