Guest User

Untitled

a guest
Mar 3rd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. require "#{File.dirname(__FILE__)}/../test_helper"
  2.  
  3. class StudyTest < ActionController::IntegrationTest
  4.  
  5. def test_add_a_basic_new_protocol
  6. # login to begin integration test
  7. user = login("xxxx", "xxxx")
  8.  
  9. user.choose_create_new_protocol
  10. study = user.create_study
  11. user.add_participations(study)
  12. user.add_contacts(study)
  13.  
  14. # we are going to edit all regulatory info in this test
  15. user.add_regulatory_info(study, true)
  16. user.add_regulatory_cro_info(study)
  17.  
  18. user.add_financials(study)
  19. user.add_sponsors(study)
  20. end
  21. end
  22.  
  23. private
  24.  
  25. def login(user, pass)
  26. open_session do |sess|
  27. sess.extend(StudyTestDSL)
  28. sess.post_via_redirect "/user/login", :user => {:login => user, :password => pass}, :redirect_user_to => "", :redirect_key => ""
  29. end
  30. end
  31.  
  32. module StudyTestDSL
  33. def choose_create_new_protocol
  34. get "/studies/new"
  35. assert_response :success
  36. assert_template "studies/new"
  37. end
  38.  
  39. def create_study
  40. study_title = "new integration study"
  41. post "/studies/create", :commit=>"Next: Study Team", :study=>{ :title => "integration study", :gcrc=>"0", :study_status_id=>"7", :study_gender_id=>"3", :research_program_id=>"12"}, :pi=>{"name"=>"Damron, Dorothy"}
  42. study = assigns(:study)
  43. assert_not_nil study
  44. assert_valid study
  45. assert_valid study.study_status
  46. assert_redirected_to :controller => "participations", :action => "edit", :study_id => study.id
  47. study
  48. end
  49.  
  50. def add_participations(study)
  51. # TODO implement adding participants using XHR
  52.  
  53. # after adding participants...
  54. # there is a button here to use javascript to change the web page location
  55. get "/study_contacts/create_study_contacts?study_id=#{study.id}"
  56. assert_template "study_contacts/create_study_contacts"
  57. end
  58.  
  59. def add_contacts(study)
  60. # TODO implement adding internal/external contacts using XHR
  61.  
  62. # after adding contacts
  63. # there is a button here to use javascript to change the web page location
  64. get "/regulatory_non_cro/new?study_id=#{study.id}"
  65. assert_template "regulatory_non_cro/new"
  66. end
  67.  
  68. def add_regulatory_info(study, edit_all_cro = true)
  69. # TODO implement adding regulatory_non_cro info
  70.  
  71. redirect, post_options = case edit_all_cro
  72. when true
  73. [{:controller => "regulatory_cro", :action => "new", :study_id => study.id}, {:commit => "Next: CRO Info"}]
  74. else
  75. [{:controller => "study_financials", :action => "new", :study_id => study.id}, {:commit => "Next: Financial"}]
  76. end
  77.  
  78. post "/regulatory_non_cro/update?study_id=#{study.id}", post_options
  79. assert_redirected_to redirect
  80. end
  81.  
  82. def add_regulatory_cro_info(study)
  83. # TODO implement adding regulatory_cro info
  84.  
  85. post "/regulatory_cro/update?study_id=#{study.id}", :commit => "Next: Financial"
  86. assert_redirected_to :controller => "study_financials", :action => "new", :study_id => study.id
  87. end
  88.  
  89. def add_financials(study)
  90. # TODO implement adding financials
  91.  
  92. post "/study_financials/update?study_id=#{study.id}", :commit => "Next: Study Sponsors"
  93. assert_redirected_to :controller => "study_sponsorships", :action => "create_study_sponsorships", :study_id => study.id
  94. end
  95.  
  96. def add_sponsors(study)
  97. # TODO implement adding sponsors
  98.  
  99. get "/studies/show?study_id=#{study.id}"
  100. assert_template "studies/show"
  101. end
  102.  
  103.  
  104. end
Add Comment
Please, Sign In to add comment