@@ -13,16 +13,7 @@ class MissionsController < ApplicationController |
||
13 | 13 |
|
14 | 14 |
def mission_control |
15 | 15 |
@mission = Mission.friendly.find(params[:id]) |
16 |
- @submissions = Array.new |
|
17 |
- @mission.mission_agents.each do |agent| |
|
18 |
- agent.agent_steps.each do |step| |
|
19 |
- if step.step_submissions.count > 0 |
|
20 |
- if step.step_submissions.last.validated == nil |
|
21 |
- @submissions << step.step_submissions.last |
|
22 |
- end |
|
23 |
- end |
|
24 |
- end |
|
25 |
- end |
|
16 |
+ @submissions = @mission.step_submissions |
|
26 | 17 |
if current_user != @mission.owner |
27 | 18 |
redirect_to missions_path, alert: (t 'mission.access_denied_error') |
28 | 19 |
end |
@@ -199,4 +199,19 @@ class Mission < ActiveRecord::Base |
||
199 | 199 |
return array |
200 | 200 |
end |
201 | 201 |
|
202 |
+ # Step Submissions for Mission Control |
|
203 |
+ def step_submissions |
|
204 |
+ submissions = Array.new |
|
205 |
+ self.mission_agents.each do |agent| |
|
206 |
+ agent.agent_steps.each do |step| |
|
207 |
+ if step.step_submissions.count > 0 |
|
208 |
+ if step.step_submissions.last.validated == nil |
|
209 |
+ submissions << step.step_submissions.last |
|
210 |
+ end |
|
211 |
+ end |
|
212 |
+ end |
|
213 |
+ end |
|
214 |
+ return submissions |
|
215 |
+ end |
|
216 |
+ |
|
202 | 217 |
end |
@@ -2,4 +2,5 @@ class SubmissionText < ActiveRecord::Base |
||
2 | 2 |
belongs_to :validation |
3 | 3 |
has_one :submission_content, :as => :submission, dependent: :destroy |
4 | 4 |
accepts_nested_attributes_for :submission_content, allow_destroy:true |
5 |
+ validates_presence_of :content |
|
5 | 6 |
end |
@@ -3,7 +3,7 @@ |
||
3 | 3 |
<%= f.fields_for :submission_contents, SubmissionContent.new, show_empty: true do |f| %> |
4 | 4 |
<%= f.alert_message "Please fix the errors below." %> |
5 | 5 |
<%= f.fields_for SubmissionText.new, as: :submission, show_empty: true do |f| %> |
6 |
- <%= f.text_field :content, class: 'input-block-level' %> |
|
6 |
+ <%= f.text_field :content, :wrapper => {class: 'validation-text-form'}, class: 'input-block-level' %> |
|
7 | 7 |
<% end %> |
8 | 8 |
<% end %> |
9 | 9 |
<% end %> |
@@ -13,17 +13,21 @@ |
||
13 | 13 |
<%= content_tag(:div, class: 'page-header page-header-type') do %> |
14 | 14 |
<%= content_tag(:small, (t 'mission.agent')+':') %> |
15 | 15 |
<%= content_tag(:h2) do %> |
16 |
- <%= @agent.role %> |
|
16 |
+ <%= @agent.role != nil ? @agent.role : (t'agents.untitled_agent') %> |
|
17 | 17 |
<% end %> |
18 | 18 |
<% end %> |
19 | 19 |
<% end %> |
20 | 20 |
<% end %> |
21 | 21 |
<%= content_tag(:div, class: 'row') do %> |
22 | 22 |
<%= content_tag(:div, class: 'span8 mission-briefing') do %> |
23 |
- <%= content_tag(:h4, ((t 'mission.objective') + ':') ) %> |
|
24 |
- <%= content_tag(:p, @agent.objective.html_safe) %> |
|
25 |
- <%= content_tag(:h4, ((t 'mission.instructions') + ':') ) %> |
|
26 |
- <%= @agent.briefing.html_safe if @agent.briefing %> |
|
23 |
+ <% if @agent.objective != nil %> |
|
24 |
+ <%= content_tag(:h4, ((t 'mission.objective') + ':') ) %> |
|
25 |
+ <%= content_tag(:p, @agent.objective.html_safe) %> |
|
26 |
+ <% end %> |
|
27 |
+ <% if @agent.briefing != nil %> |
|
28 |
+ <%= content_tag(:h4, ((t 'mission.instructions') + ':') ) %> |
|
29 |
+ <%= @agent.briefing.html_safe if @agent.briefing %> |
|
30 |
+ <% end %> |
|
27 | 31 |
<% end %> |
28 | 32 |
<%= content_tag(:div, class: 'span4') do %> |
29 | 33 |
<% if @agent.is_assigned %> |
@@ -8,6 +8,8 @@ en: |
||
8 | 8 |
no_missions_yet: 'There are no missions yet. Create the first.' |
9 | 9 |
take_agent_role: 'Take Agent Role' |
10 | 10 |
take_agent_profile_confirmation: 'You have taken the agent role' |
11 |
+ step_submission_confirmation: 'Your step information has been submited for aproval by the mission director.' |
|
12 |
+ step_submission_error: 'There was an error with the submission. Please try again.' |
|
11 | 13 |
step: |
12 | 14 |
validated: 'Validated' |
13 | 15 |
step_validated: 'Step validated' |
@@ -8,6 +8,8 @@ pt-BR: |
||
8 | 8 |
no_missions_yet: 'Não existem missões ainda. Crie a primeira.' |
9 | 9 |
take_agent_role: 'Pegar o papel de agente' |
10 | 10 |
take_agent_profile_confirmation: 'Você se registrou para o papel de agente' |
11 |
+ step_submission_confirmation: 'As informações foram enviadas para aprovação pelo diretor da missão.' |
|
12 |
+ step_submission_error: 'Houve um erro ao enviar as informações do passo. Por favor tente de novo.' |
|
11 | 13 |
step: |
12 | 14 |
validated: 'Validado' |
13 | 15 |
step_validated: 'Passo validado' |
@@ -99,8 +99,8 @@ Feature: Missions |
||
99 | 99 |
And I should see "Get the money" |
100 | 100 |
And I should see "Leave the bank" |
101 | 101 |
|
102 |
- Scenario: Take agent role from agents page |
|
103 |
- Given the user "Monty" "Cantsin" with email "monty_cantsin@canada.com" and password "12345678" exists and is logged in |
|
102 |
+ Scenario: Take agent role from agents list page |
|
103 |
+ Given the user "Monty" "Cantsin" with email "monty_cantsin@canada.com" has signed up and is logged in |
|
104 | 104 |
And I go to the missions page |
105 | 105 |
And I click in the link "Bank Robbery" |
106 | 106 |
And within "#mission-tabs-nav" I click in the link "Agents" |
@@ -111,7 +111,7 @@ Feature: Missions |
||
111 | 111 |
And within ".assigned-agent-role" I should see "Monty Cantsin" |
112 | 112 |
|
113 | 113 |
Scenario: Take agent role from agent page |
114 |
- Given the user "Monty" "Cantsin" with email "monty_cantsin@canada.com" and password "12345678" exists and is logged in |
|
114 |
+ Given the user "Monty" "Cantsin" with email "monty_cantsin@canada.com" has signed up and is logged in |
|
115 | 115 |
And I go to the missions page |
116 | 116 |
And I click in the link "Bank Robbery" |
117 | 117 |
And within "#mission-tabs-nav" I click in the link "Agents" |
@@ -129,4 +129,26 @@ Feature: Missions |
||
129 | 129 |
And I click in the link "Bank Robbery" |
130 | 130 |
And within "#mission-tabs-nav" I click in the link "Agents" |
131 | 131 |
When within "#agent-mr-pink" I click in the link "Apply For Position" |
132 |
- Then I should see "Please login first before completing this action." |
|
132 |
+ Then I should see "Please login first before completing this action." |
|
133 |
+ |
|
134 |
+ Scenario: Agent submits a step with a text validation |
|
135 |
+ Given the user "Monty" "Cantsin" with email "monty_cantsin@canada.com" has signed up and is logged in |
|
136 |
+ And the user "monty_cantsin@canada.com" has taken the role "Mr. Pink" in the mission "Bank Robbery" |
|
137 |
+ When I visit the agent page "Mr. Pink" from the mission "Bank Robbery" |
|
138 |
+ And within "#step-1" I click in the link "Get to the bank" |
|
139 |
+ And within "#step-1" I click in the link "What time did you arrive?" |
|
140 |
+ And within the ".fields" number "1" I fill in "Content" with "I arrived at 15:00." |
|
141 |
+ And within "#step-1" I click in the button "submit" |
|
142 |
+ And I should see "Your step information has been submited for aproval by the mission director" |
|
143 |
+ And within "#step-1" I should see "Waiting for validation" |
|
144 |
+ And there should be 1 step waiting for validation on the "Bank Robbery" mission control page |
|
145 |
+ |
|
146 |
+ Scenario: Agent submits a step with an empty text validation |
|
147 |
+ Given the user "Monty" "Cantsin" with email "monty_cantsin@canada.com" has signed up and is logged in |
|
148 |
+ And the user "monty_cantsin@canada.com" has taken the role "Mr. Pink" in the mission "Bank Robbery" |
|
149 |
+ When I visit the agent page "Mr. Pink" from the mission "Bank Robbery" |
|
150 |
+ And within "#step-1" I click in the link "Get to the bank" |
|
151 |
+ And within "#step-1" I click in the link "What time did you arrive?" |
|
152 |
+ And within "#step-1" I click in the button "submit" |
|
153 |
+ And I should see "There was an error with the submission. Please try again." |
|
154 |
+ And there should be 0 step waiting for validation on the "Bank Robbery" mission control page |
@@ -65,4 +65,10 @@ Given(/^the following files where uploaded$/) do |table| |
||
65 | 65 |
attach_file "upload_file", @test_file_path |
66 | 66 |
click_button "Save" |
67 | 67 |
end |
68 |
+end |
|
69 |
+ |
|
70 |
+# Wait |
|
71 |
+ |
|
72 |
+Given /^I wait for (\d+) seconds?$/ do |n| |
|
73 |
+ sleep(n.to_i) |
|
68 | 74 |
end |
@@ -20,6 +20,12 @@ Then(/^within "(.*?)" I click in the link "(.*?)"$/) do |arg1, arg2| |
||
20 | 20 |
end |
21 | 21 |
end |
22 | 22 |
|
23 |
+Then(/^within "(.*?)" I click in the button "(.*?)"$/) do |arg1, arg2| |
|
24 |
+ within(arg1) do |
|
25 |
+ click_button(arg2) |
|
26 |
+ end |
|
27 |
+end |
|
28 |
+ |
|
23 | 29 |
Then(/^within the "(.*?)" number "(\d+)" I click in the link "(.*?)"$/) do |arg1, arg2, arg3| |
24 | 30 |
items = page.all(arg1) |
25 | 31 |
within(items[arg2.to_i - 1]) do |
@@ -38,19 +38,24 @@ Then(/^I log out$/) do |
||
38 | 38 |
# end |
39 | 39 |
end |
40 | 40 |
|
41 |
-# Create user |
|
42 |
-Given(/^the user "(.*?)" "(.*?)" with email "(.*?)" and password "(.*?)" exists$/) do |arg1, arg2, arg3, arg4| |
|
43 |
- user_hash = { "first_name" => arg1, "last_name" => arg2, "email" => arg3, "password" => arg4 } |
|
44 |
- if User.find_by_email(arg3) == nil |
|
41 |
+# Create and log in user |
|
42 |
+Given(/^the user "(.*?)" "(.*?)" with email "(.*?)" has signed up and is logged in$/) do |arg1, arg2, arg3| |
|
43 |
+ user_hash = { "first_name" => arg1, "last_name" => arg2, "email" => arg3 } |
|
44 |
+ if User.where(email: arg1).first == nil |
|
45 | 45 |
user = FactoryGirl.create(:user, user_hash) |
46 | 46 |
end |
47 | 47 |
if User.last.email != arg3 |
48 | 48 |
return false |
49 | 49 |
end |
50 |
+ visit new_user_session_path |
|
51 |
+ fill_in "user_email", :with => arg3 |
|
52 |
+ fill_in "user_password", :with => '12345678' |
|
53 |
+ click_button "Submit" |
|
54 |
+ login_as user, scope: :user |
|
50 | 55 |
end |
51 | 56 |
|
52 |
-# Create and log in user |
|
53 |
-Given(/^the user "(.*?)" "(.*?)" with email "(.*?)" and password "(.*?)" exists and is logged in$/) do |arg1, arg2, arg3, arg4| |
|
57 |
+# Create user |
|
58 |
+Given(/^the user "(.*?)" "(.*?)" with email "(.*?)" and password "(.*?)" exists$/) do |arg1, arg2, arg3, arg4| |
|
54 | 59 |
user_hash = { "first_name" => arg1, "last_name" => arg2, "email" => arg3, "password" => arg4 } |
55 | 60 |
if User.find_by_email(arg3) == nil |
56 | 61 |
user = FactoryGirl.create(:user, user_hash) |
@@ -58,11 +63,6 @@ Given(/^the user "(.*?)" "(.*?)" with email "(.*?)" and password "(.*?)" exists |
||
58 | 63 |
if User.last.email != arg3 |
59 | 64 |
return false |
60 | 65 |
end |
61 |
- visit new_user_session_path |
|
62 |
- fill_in "user_email", :with => arg1 |
|
63 |
- fill_in "user_password", :with => arg2 |
|
64 |
- click_button "Submit" |
|
65 |
- login_as user, scope: :user |
|
66 | 66 |
end |
67 | 67 |
|
68 | 68 |
# Fixes for devise post bug |
@@ -52,4 +52,28 @@ Given(/^the step "(.*?)" from agent "(.*?)" in the mission "(.*?)" has the follo |
||
52 | 52 |
validation.agent_step = step |
53 | 53 |
validation.save |
54 | 54 |
end |
55 |
+end |
|
56 |
+ |
|
57 |
+Given(/^the user "(.*?)" has taken the role "(.*?)" in the mission "(.*?)"$/) do |arg1, arg2, arg3| |
|
58 |
+ mission = Mission.where(title: arg3).first |
|
59 |
+ agent = MissionAgent.where(role: arg2, mission_id: mission).first |
|
60 |
+ user = User.where(email: arg1).first |
|
61 |
+ agent.update(user_id: user.id) |
|
62 |
+end |
|
63 |
+ |
|
64 |
+When(/^I visit the agent page "(.*?)" from the mission "(.*?)"$/) do |arg1, arg2| |
|
65 |
+ mission = Mission.where(title: arg2).first |
|
66 |
+ agent = MissionAgent.where(role: arg1, mission_id: mission).first |
|
67 |
+ visit mission_agent_details_path(mission, agent) |
|
68 |
+end |
|
69 |
+ |
|
70 |
+# VALIDATION |
|
71 |
+ |
|
72 |
+When(/^there should be (\d+) step waiting for validation on the "(.*?)" mission control page$/) do |arg1, arg2| |
|
73 |
+ mission = Mission.where(title: arg2).first |
|
74 |
+ step_count = mission.step_submissions.count |
|
75 |
+ #puts "Found #{step_count.to_s} step#{step_count > 1 ? 's' : ''} in mission control" |
|
76 |
+ if step_count != arg1.to_i |
|
77 |
+ return false |
|
78 |
+ end |
|
55 | 79 |
end |