From e7b1f3d5ecf32c594bf72a91d0be11e625787f4c Mon Sep 17 00:00:00 2001 From: blackjk3 Date: Tue, 15 Dec 2015 11:40:06 -0600 Subject: [PATCH] Adding back simple descriptions for researchers to be able to update. --- app/controllers/researchers_controller.rb | 3 +- app/views/researchers/edit.html.haml | 11 ++- .../researchers_controller_spec.rb | 85 +++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) diff --git a/app/controllers/researchers_controller.rb b/app/controllers/researchers_controller.rb index cff1373..43b9c53 100644 --- a/app/controllers/researchers_controller.rb +++ b/app/controllers/researchers_controller.rb @@ -27,10 +27,11 @@ def edit def update @trial = StudyFinder::Trial.find_by(system_id: params[:id]) - unless params[:secret_key].blank? + if !params[:secret_key].blank? && params[:secret_key] == @system_info.secret_key if @trial.update(trial_params) redirect_to edit_researcher_path(params[:id]), flash: { success: 'Trial updated successfully' } else + flash[:notice] = 'There was an error updating the record.' render 'edit' end else diff --git a/app/views/researchers/edit.html.haml b/app/views/researchers/edit.html.haml index 5bcf10b..db4d1dc 100644 --- a/app/views/researchers/edit.html.haml +++ b/app/views/researchers/edit.html.haml @@ -1,8 +1,17 @@ %h3 Edit Trial %p.lead= @trial.display_title = simple_form_for @trial, url: researcher_path, method: :put do |f| - =# f.input :simple_description + %label Simple Description + %p.help-block + %strong FORMAT: + This is a study of (population) with/without (condition) between ages (X-Y) years old. This study is trying to figure out (aim of study). + %br + %strong NOTE: + Your simple description must be IRB approved. + = f.input :simple_description, label: false + + %hr %label Contact override email %small %i (If populated, this will override any contact email from clinialtrials.gov for this trial) diff --git a/spec/controllers/researchers_controller_spec.rb b/spec/controllers/researchers_controller_spec.rb index 83f70f5..257a2d2 100644 --- a/spec/controllers/researchers_controller_spec.rb +++ b/spec/controllers/researchers_controller_spec.rb @@ -10,6 +10,21 @@ last_name: 'Kadrmas', role: 'researcher' }) + + @system_info = StudyFinder::SystemInfo.create({ + initials: 'UMN', + school_name: 'University of Minnesota', + system_name: 'Study Finder', + system_header: 'Make A Difference. Get Involved.', + system_description: "Test Description", + researcher_description: "Test", + search_term: 'University of Minnesota', + default_url: 'http://studyfinder.umn.edu', + default_email: 'sfinder@umn.edu', + display_all_locations: false, + secret_key: 'test', + contact_email_suffix: '@umn.edu' + }) } describe "GET #index" do @@ -50,6 +65,76 @@ end end + describe "PUT #update" do + it "trial with override information" do + trial = StudyFinder::Trial.create({ brief_title: 'Testing a title', system_id: 'NCT000001' }) + + simple_description = 'Testing adding a simple_description' + contact_override = 'jim@aol.com' + contact_override_first_name = 'Jim' + contact_override_last_name = 'Smith' + + study_finder_trial = { + simple_description: simple_description, + contact_override: contact_override, + contact_override_first_name: contact_override_first_name, + contact_override_last_name: contact_override_last_name + } + + put :update, id: trial.system_id, study_finder_trial: study_finder_trial, secret_key: @system_info.secret_key + + expect( assigns(:trial).simple_description ).to eq(simple_description) + expect( assigns(:trial).contact_override ).to eq(contact_override) + expect( assigns(:trial).contact_override_first_name ).to eq(contact_override_first_name) + expect( assigns(:trial).contact_override_last_name ).to eq(contact_override_last_name) + + expect(response).to redirect_to(edit_researcher_path(trial.system_id)) + expect(flash[:success]).to eq('Trial updated successfully') + end + + it "fails when a secret_key is not provided" do + trial = StudyFinder::Trial.create({ brief_title: 'Testing a title', system_id: 'NCT000001' }) + + simple_description = 'Testing adding a simple_description' + contact_override = 'jim@aol.com' + contact_override_first_name = 'Jim' + contact_override_last_name = 'Smith' + + study_finder_trial = { + simple_description: simple_description, + contact_override: contact_override, + contact_override_first_name: contact_override_first_name, + contact_override_last_name: contact_override_last_name + } + + put :update, id: trial.system_id, study_finder_trial: study_finder_trial + expect(response).to be_success + expect(response).to have_http_status(200) + expect(flash[:notice]).to eq('The secret key you entered was incorrect.') + end + + it "fails when an invalid secret_key is added" do + trial = StudyFinder::Trial.create({ brief_title: 'Testing a title', system_id: 'NCT000001' }) + + simple_description = 'Testing adding a simple_description' + contact_override = 'jim@aol.com' + contact_override_first_name = 'Jim' + contact_override_last_name = 'Smith' + + study_finder_trial = { + simple_description: simple_description, + contact_override: contact_override, + contact_override_first_name: contact_override_first_name, + contact_override_last_name: contact_override_last_name + } + + put :update, id: trial.system_id, study_finder_trial: study_finder_trial, secret_key: 'invalid_key' + expect(response).to be_success + expect(response).to have_http_status(200) + expect(flash[:notice]).to eq('The secret key you entered was incorrect.') + end + end + # describe "PUT #update" do # before :each do # @group = StudyFinder::Group.create({ group_name: 'Test' })