Skip to content

Commit

Permalink
Adding back simple descriptions for researchers to be able to update.
Browse files Browse the repository at this point in the history
  • Loading branch information
blackjk3 committed Dec 15, 2015
1 parent ecd6412 commit e7b1f3d
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/controllers/researchers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion app/views/researchers/edit.html.haml
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
85 changes: 85 additions & 0 deletions spec/controllers/researchers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' })
Expand Down

0 comments on commit e7b1f3d

Please sign in to comment.