Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jw fixing email story part 3 #684

Merged
merged 2 commits into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/views/notifier/_user_information.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
%th.skinny-black-border= t(:notifier)[:name]
%th.skinny-black-border= t(:notifier)[:contact_info]
%th.skinny-black-border= t(:notifier)[:role]
- if !@protocol.selected_for_epic.nil?
- if @protocol.selected_for_epic == true
%th.skinny-black-border= t(:notifier)[:epic_access]
%tbody
- @protocol.project_roles.each do |pr|
Expand All @@ -38,7 +38,7 @@
%td.skinny-black-border.center= pr.role.upcase + " " + t(:notifier)[:requester]
- else
%td.skinny-black-border.center= pr.role.upcase
- if !@protocol.selected_for_epic.nil?
- if @protocol.selected_for_epic == true
%td.skinny-black-border.center= pr.epic_access == true ? "Yes" : "No"
%br
%br
2 changes: 0 additions & 2 deletions app/views/user_mailer/_intro.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
= t(:mailer)[:delete_intro]
- if @action == "add"
= t(:mailer)[:add_intro]
- if @action == "update"
= t(:mailer)[:update]
%p{ :style => 'display: inline;' }
%a{:style => "color: blue; font-weight: bold;", :href => @protocol_link}=t(:mailer)[:sparc_dashboard_period]
4 changes: 2 additions & 2 deletions app/views/user_mailer/_user_info_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
%th{:style => 'border: 1px solid black;'}= t(:notifier)[:contact_info]
%th{:style => 'border: 1px solid black;'}= t(:notifier)[:role]
%th{:style => 'border: 1px solid black;'}= t(:mailer)[:proxy]
- if !@protocol.selected_for_epic.nil?
- if @protocol.selected_for_epic == true
%th{:style => 'border: 1px solid black;'}= t(:notifier)[:epic_access]
%tbody
%tr{:style => 'border: 1px solid black;'}
%td{:style => 'border: 1px solid black; text-align: center;'}= @modified_role.identity.full_name
%td{:style => 'border: 1px solid black; text-align: center;'}= @modified_role.identity.email
%td{:style => 'border: 1px solid black; text-align: center;'}= @modified_role.role.upcase
%td{:style => 'border: 1px solid black; text-align: center;'}= @modified_role.display_rights
- if !@protocol.selected_for_epic.nil?
- if @protocol.selected_for_epic == true
%td{:style => 'border: 1px solid black; text-align: center;'}= @modified_role.epic_access == true ? "Yes" : "No"
1 change: 0 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,6 @@ en:
sparc_dashboard_period: "SPARCDashboard."
title1: "Short Title:"
title2: "Project Title:"
update: "An Authorized User has been modified in"
user_info: "User Information:"
user_modification: "User Modification"

Expand Down
1 change: 0 additions & 1 deletion lib/dashboard/associated_user_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def initialize(params)

# must come after the use of ActiveModel::Dirty methods above
@protocol_role.save
protocol.email_about_change_in_authorized_user(@protocol_role, "update")

if USE_EPIC && protocol.selected_for_epic && !QUEUE_EPIC
if access_removed
Expand Down
82 changes: 5 additions & 77 deletions spec/lib/dashboard/associated_user_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

context "params[:project_role] describes a valid ProjectRole" do
it "should update ProjectRole from params[:id] with params[:project_role]" do
protocol = create(:study_without_validations, primary_pi: primary_pi)
create(:sub_service_request, status: 'not_draft', organization: create(:organization), service_request: create(:service_request_without_validations, protocol: protocol))
protocol = create(:protocol_without_validations, primary_pi: primary_pi)
project_role = ProjectRole.create(identity_id: identity.id,
protocol_id: protocol.id,
role: "important",
Expand All @@ -41,8 +40,7 @@

context "changing role to 'primary-pi'" do
it "should change current primary pi to a general-access-user" do
protocol = create(:study_without_validations, primary_pi: primary_pi)
create(:sub_service_request, status: 'not_draft', organization: create(:organization), service_request: create(:service_request_without_validations, protocol: protocol))
protocol = create(:protocol_without_validations, primary_pi: primary_pi)
project_role = ProjectRole.create(identity_id: identity.id,
protocol_id: protocol.id,
role: "primary-pi",
Expand All @@ -55,75 +53,9 @@
end
end

context "SEND_AUTHORIZED_USER_EMAILS == true && protocol has non-draft status" do
it "should notify associated users about user change" do
protocol = create(:study_without_validations, primary_pi: primary_pi)
user = create(:identity)
create(:sub_service_request, status: 'not_draft', organization: create(:organization), service_request: create(:service_request_without_validations, protocol: protocol))
stub_const("SEND_AUTHORIZED_USER_EMAILS", true)
project_role = ProjectRole.create(identity_id: identity.id,
protocol_id: protocol.id,
role: "important",
project_rights: "to-party")
expect(UserMailer).to receive(:authorized_user_changed) do
mailer_stub = double('mailer')
expect(mailer_stub).to receive(:deliver)
mailer_stub
end
expect(UserMailer).to receive(:authorized_user_changed) do
mailer_stub = double('mailer')
expect(mailer_stub).to receive(:deliver)
mailer_stub
end

Dashboard::AssociatedUserUpdater.new(id: project_role.id, project_role: { role: "not-important" })
end
end

context "SEND_AUTHORIZED_USER_EMAILS == true && protocol has draft status" do
it "should notify associated users about user change" do
protocol = create(:study_without_validations, primary_pi: primary_pi)
user = create(:identity)
create(:sub_service_request, status: 'draft', organization: create(:organization), service_request: create(:service_request_without_validations, protocol: protocol))
stub_const("SEND_AUTHORIZED_USER_EMAILS", true)
project_role = ProjectRole.create(identity_id: identity.id,
protocol_id: protocol.id,
role: "important",
project_rights: "to-party")
expect(UserMailer).not_to receive(:authorized_user_changed) do
mailer_stub = double('mailer')
expect(mailer_stub).to receive(:deliver)
mailer_stub
end
expect(UserMailer).not_to receive(:authorized_user_changed) do
mailer_stub = double('mailer')
expect(mailer_stub).to receive(:deliver)
mailer_stub
end

Dashboard::AssociatedUserUpdater.new(id: project_role.id, project_role: { role: "not-important" })
end
end

context "SEND_AUTHORIZED_USER_EMAILS == false" do
it "should not notify associated users about user change" do
protocol = create(:study_without_validations, primary_pi: primary_pi)
stub_const("SEND_AUTHORIZED_USER_EMAILS", false)
project_role = ProjectRole.create(identity_id: identity.id,
protocol_id: protocol.id,
role: "important",
project_rights: "to-party")
allow(UserMailer).to receive(:authorized_user_changed)

Dashboard::AssociatedUserUpdater.new(id: project_role.id, project_role: { role: "not-important" })

expect(UserMailer).not_to have_received(:authorized_user_changed)
end
end

context "USE_EPIC == true && Protocol selected for epic && QUEUE_EPIC == false" do
let(:protocol) do
create(:study_without_validations,
create(:protocol_without_validations,
primary_pi: primary_pi,
selected_for_epic: true)
end
Expand All @@ -141,7 +73,6 @@
project_rights: "to-party",
epic_access: true)

create(:sub_service_request, status: 'not_draft', organization: create(:organization), service_request: create(:service_request_without_validations, protocol: protocol))

expect(Notifier).to receive(:notify_for_epic_access_removal) do |p, pr|
# make sure the correct objects are being passed
Expand All @@ -166,7 +97,6 @@
project_rights: "to-party",
epic_access: false)

create(:sub_service_request, status: 'not_draft', organization: create(:organization), service_request: create(:service_request_without_validations, protocol: protocol))

expect(Notifier).to receive(:notify_for_epic_user_approval) do |p|
# make sure the correct objects are being passed
Expand All @@ -190,7 +120,6 @@
epic_access: false)
project_role.epic_rights.create(right: "left", position: 1)

create(:sub_service_request, status: 'not_draft', organization: create(:organization), service_request: create(:service_request_without_validations, protocol: protocol))

expect(Notifier).to receive(:notify_for_epic_rights_changes) do |p, pr, epic_rights|
# make sure the correct objects are being passed
Expand All @@ -209,7 +138,7 @@

describe "#protocol_role" do
it "should return updated ProjectRole, regardless of validity" do
protocol = create(:study_without_validations, primary_pi: primary_pi)
protocol = create(:protocol_without_validations, primary_pi: primary_pi)
project_role = ProjectRole.create(identity_id: identity.id,
protocol_id: protocol.id,
role: "important",
Expand All @@ -222,7 +151,7 @@
end

describe "#successful?" do
let(:protocol) { create(:study_without_validations, primary_pi: primary_pi) }
let(:protocol) { create(:protocol_without_validations, primary_pi: primary_pi) }

context "update resulted in invalid ProjectRole" do
it "should return false" do
Expand All @@ -244,7 +173,6 @@
role: "important",
project_rights: "to-party")

create(:sub_service_request, status: 'not_draft', organization: create(:organization), service_request: create(:service_request_without_validations, protocol: protocol))

updater = Dashboard::AssociatedUserUpdater.new(id: project_role.id, project_role: { role: "not-important" })

Expand Down
33 changes: 33 additions & 0 deletions spec/mailers/notifier/get_a_cost_estimate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@
assert_email_user_information_when_selected_for_epic(mail.body)
end
end

context 'when protocol is not selected for epic' do

before do
service_request.protocol.update_attribute(:selected_for_epic, false)
end

it 'should not show epic column' do
assert_email_user_information_when_not_selected_for_epic(mail.body)
end
end
end

context 'users' do
Expand Down Expand Up @@ -149,6 +160,17 @@
assert_email_user_information_when_selected_for_epic(mail.body.parts.first.body)
end
end

context 'when protocol is not selected for epic' do

before do
service_request.protocol.update_attribute(:selected_for_epic, false)
end

it 'should not show epic column' do
assert_email_user_information_when_not_selected_for_epic(mail.body.parts.first.body)
end
end
end

context 'admin' do
Expand Down Expand Up @@ -191,5 +213,16 @@
assert_email_user_information_when_selected_for_epic(mail.body.parts.first.body)
end
end

context 'when protocol is not selected for epic' do

before do
service_request.protocol.update_attribute(:selected_for_epic, false)
end

it 'should not show epic column' do
assert_email_user_information_when_not_selected_for_epic(mail.body.parts.first.body)
end
end
end
end
38 changes: 34 additions & 4 deletions spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,23 @@
protocol_information_table
end

it "should display the User information table" do
user_information_table
context 'when protocol has selected for epic' do
before do
study.update_attribute(:selected_for_epic, true)
end

it 'should show epic column' do
user_information_table_with_epic_col
end
end

context 'when protocol does not have selected for epic' do
before do
study.update_attribute(:selected_for_epic, false)
end
it 'should not show epic col' do
user_information_table_without_epic_col
end
end

it "should display message conclusion" do
Expand Down Expand Up @@ -58,8 +73,23 @@
protocol_information_table
end

it "should display the User information table" do
user_information_table
context 'when protocol has selected for epic' do
before do
study.update_attribute(:selected_for_epic, true)
end

it 'should show epic column' do
user_information_table_with_epic_col
end
end

context 'when protocol does not have selected for epic' do
before do
study.update_attribute(:selected_for_epic, false)
end
it 'should not show epic col' do
user_information_table_without_epic_col
end
end

it "should display message conclusion" do
Expand Down
17 changes: 17 additions & 0 deletions spec/support/emails/tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ def assert_email_user_information_when_selected_for_epic(mail_response)
end
end

def assert_email_user_information_when_not_selected_for_epic(mail_response)
# Should display 'Epic Access' column
expect(mail_response).to have_xpath "//table//strong[text()='User Information']"
expect(mail_response).to have_xpath "//th[text()='User Name']/following-sibling::th[text()='Contact Information']/following-sibling::th[text()='Role']"
expect(mail_response).not_to have_xpath "//following-sibling::th[text()='Epic Access']"
service_request.protocol.project_roles.each do |role|
if identity.id == service_request.sub_service_requests.first.service_requester_id
requester_flag = " (Requester)"
else
requester_flag = ""
end
user_epic_access = role.epic_access == false ? "No" : "Yes"
expect(mail_response).to have_xpath "//td[text()='#{role.identity.full_name}']/following-sibling::td[text()='#{role.identity.email}']/following-sibling::td[text()='#{role.role.upcase}#{requester_flag}']"
expect(mail_response).not_to have_xpath "//following-sibling::td[text()='#{user_epic_access}']"
end
end

def assert_email_srid_information_for_service_provider
# Expect table to show only SSR's (hyper-link) that are associated with service provider
expect(mail.body).to have_xpath "//table//strong[text()='Service Request Information']"
Expand Down
15 changes: 14 additions & 1 deletion spec/support/user_mailer_emails/tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def protocol_information_table
expect(@mail).to have_xpath "//th[text()='Funding Source']/following-sibling::td[text()='#{study.funding_source.capitalize}']"
end

def user_information_table
def user_information_table_with_epic_col
expect(@mail).to have_xpath "//table//strong[text()='User Information']"
expect(@mail).to have_xpath "//th[text()='User Modification']/following-sibling::th[text()='Contact Information']/following-sibling::th[text()='Role']/following-sibling::th[text()='SPARC Proxy Rights']/following-sibling::th[text()='Epic Access']"
expect(@mail).to have_xpath "//td[text()='#{@modified_identity.full_name}']/following-sibling::td[text()='#{@modified_identity.email}']/following-sibling::td[text()='#{@modified_identity.project_roles.first.role.upcase}']/following-sibling::td[text()='#{@modified_identity.project_roles.first.display_rights}']"
Expand All @@ -19,6 +19,19 @@ def user_information_table
expect(@mail).to have_xpath "//td[text()='Yes']"
end
end

def user_information_table_without_epic_col
expect(@mail).to have_xpath "//table//strong[text()='User Information']"
expect(@mail).to have_xpath "//th[text()='User Modification']/following-sibling::th[text()='Contact Information']/following-sibling::th[text()='Role']/following-sibling::th[text()='SPARC Proxy Rights']"
expect(@mail).not_to have_xpath "//following-sibling::th[text()='Epic Access']"
expect(@mail).to have_xpath "//td[text()='#{@modified_identity.full_name}']/following-sibling::td[text()='#{@modified_identity.email}']/following-sibling::td[text()='#{@modified_identity.project_roles.first.role.upcase}']/following-sibling::td[text()='#{@modified_identity.project_roles.first.display_rights}']"

if @modified_identity.project_roles.first.epic_access == false
expect(@mail).not_to have_xpath "//td[text()='No']"
else
expect(@mail).not_to have_xpath "//td[text()='Yes']"
end
end
end

RSpec.configure do |config|
Expand Down