|
Given(/^the following list of missions$/) do |table|
user = FactoryGirl.create(:user)
table.hashes.each do |hash|
mission = FactoryGirl.create("mission", hash)
mission.owner = user
mission.save
end
end
Given(/^the the mission "(.*?)" has the following agents$/) do |arg1, table|
mission = Mission.where(title: arg1).first
table.hashes.each do |hash|
agent = FactoryGirl.create("mission_agent", hash)
agent.update(mission_id: mission.id)
end
end
Given(/^the agent "(.*?)" in the mission "(.*?)" has the following steps$/) do |arg1, arg2, table|
mission = Mission.where(title: arg2).first
agent = MissionAgent.where(role: arg1, mission_id: mission).first
table.hashes.each do |hash|
step = FactoryGirl.create("agent_step", hash)
step.update(mission_agent_id: agent.id)
end
end
Given(/^the the mission "(.*?)" has the following rewards$/) do |arg1, table|
mission = Mission.where(title: arg1).first
table.hashes.each do |hash|
file_path = File.expand_path(('../../spec/fixtures/' + hash["img"]), File.dirname(__FILE__))
file = Rack::Test::UploadedFile.new(file_path)
hash["img"] = file
reward = FactoryGirl.create("reward", hash)
reward.update(mission_id: mission.id)
end
end
Given(/^the agent "(.*?)" in the mission "(.*?)" has the reward "(.*?)"$/) do |arg1, arg2, arg3|
mission = Mission.where(title: arg2).first
agent = MissionAgent.where(role: arg1, mission_id: mission).first
reward = Reward.where(title: arg3).first
reward.mission_agents << agent
reward.save
end
Given(/^the step "(.*?)" from agent "(.*?)" in the mission "(.*?)" has the following validations$/) do |arg1, arg2, arg3, table|
mission = Mission.where(title: arg3).first
agent = MissionAgent.where(role: arg2, mission_id: mission).first
step = agent.agent_steps.where(title: arg1, mission_agent_id: agent).first
table.hashes.each do |hash|
validation = FactoryGirl.create("step_validation", hash)
validation.agent_step = step
validation.save
end
end
Given(/^the user "(.*?)" has taken the role "(.*?)" in the mission "(.*?)"$/) do |arg1, arg2, arg3|
mission = Mission.where(title: arg3).first
agent = MissionAgent.where(role: arg2, mission_id: mission).first
user = User.where(email: arg1).first
agent.update(user_id: user.id)
end
When(/^I visit the agent page "(.*?)" from the mission "(.*?)"$/) do |arg1, arg2|
mission = Mission.where(title: arg2).first
agent = MissionAgent.where(role: arg1, mission_id: mission).first
visit mission_agent_details_path(mission, agent)
end
# VALIDATION
When(/^there should be (\d+) step waiting for validation on the "(.*?)" mission control page$/) do |arg1, arg2|
mission = Mission.where(title: arg2).first
step_count = mission.step_submissions.count
#puts "Found #{step_count.to_s} step#{step_count > 1 ? 's' : ''} in mission control"
if step_count != arg1.to_i
return false
end
end
|