Class: PlanMyStuff::TestingProjectItems::ResultsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/plan_my_stuff/testing_project_items/results_controller.rb

Overview

Handles Pass/Fail outcomes for testing project items.

Pass is submitted directly via button_to with result: “pass”. Fail renders a form (new) to capture result_notes before posting to create.

Instance Method Summary collapse

Instance Method Details

#createObject

POST /testing_projects/:testing_project_id/items/:item_id/result



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/plan_my_stuff/testing_project_items/results_controller.rb', line 18

def create
  project_number = params[:testing_project_id].to_i
  item = find_project_item(project_number)

  case params[:result]
  when 'pass'
    item.mark_passed!(pms_current_user)
    flash[:success] = 'Item marked as Passed.'
  when 'fail'
    item.mark_failed!(pms_current_user, result_notes: params[:result_notes])
    flash[:success] = 'Item marked as Failed.'
  else
    raise(ArgumentError, "Invalid result: #{params[:result].inspect}")
  end

  redirect_to(plan_my_stuff.testing_project_path(project_number))
rescue PlanMyStuff::ValidationError => e
  pms_handle_rescue(e)
  if params[:result] == 'fail'
    flash.now[:error] = e.message
    @project_number = params[:testing_project_id].to_i
    @item_id = params[:item_id]
    render(:new, status: PlanMyStuff.unprocessable_status)
  else
    flash[:error] = e.message
    redirect_to(plan_my_stuff.testing_project_path(params[:testing_project_id].to_i))
  end
rescue ArgumentError, PlanMyStuff::Error, Octokit::Error => e
  pms_handle_rescue(e)
  flash[:error] = e.message
  redirect_to(plan_my_stuff.testing_project_path(params[:testing_project_id].to_i))
end

#newObject

GET /testing_projects/:testing_project_id/items/:item_id/result/new



12
13
14
15
# File 'app/controllers/plan_my_stuff/testing_project_items/results_controller.rb', line 12

def new
  @project_number = params[:testing_project_id].to_i
  @item_id = params[:item_id]
end