Skip to content

Commit

Permalink
Don't unset a callback twice in a row.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Hardee authored and William Holt committed Mar 8, 2017
1 parent 49eefe6 commit f01b6ba
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions spec/api/v1/visit_groups/get_visit_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
RSpec.describe 'SPARCCWF::APIv1', type: :request do

describe 'GET /v1/visit_group/:id.json' do
before(:each) { VisitGroup.skip_callback(:save, :after, :set_arm_edited_flag_on_subjects) }
after(:each) { VisitGroup.set_callback(:save, :after, :set_arm_edited_flag_on_subjects) }

before do
VisitGroup.skip_callback(:save, :after, :set_arm_edited_flag_on_subjects)

protocol = create(:protocol_without_validations)
arm = create(:arm, protocol: protocol)
@visit_group = create(:visit_group, arm: arm)
Expand Down
6 changes: 5 additions & 1 deletion spec/factories/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@

trait :without_validations do
after(:build) do |user|
user.class.skip_callback(:create, :after, :send_admin_mail)
begin
user.class.skip_callback(:create, :after, :send_admin_mail)
rescue ArgumentError
# Do nothing. Callback has already been skipped.
end
end
to_create { |instance| instance.save(validate: false) }
end
Expand Down
9 changes: 7 additions & 2 deletions spec/factories/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@
end

trait :without_callback_notify_remote_service_after_create do
before(:create) { |service| service.class.skip_callback(:create, :after, :notify_remote_service_after_create) }
# after(:create) { Service.set_callback(:create, :after, :notify_remote_service_after_create) }
before(:create) do |service|
begin
service.class.skip_callback(:create, :after, :notify_remote_service_after_create)
rescue ArgumentError
# Do nothing. Callback has already been skipped.
end
end
end

trait :with_ctrc_organization do
Expand Down
7 changes: 3 additions & 4 deletions spec/lib/dashboard/arm_destroyer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
require "rails_helper"

RSpec.describe Dashboard::ArmDestroyer do
before(:each) { SubServiceRequest.skip_callback(:save, :after, :update_org_tree) }
after(:each) { SubServiceRequest.set_callback(:save, :after, :update_org_tree) }

describe "#destroy" do
context "Arm only Arm for ServiceRequest" do
before(:each) do
SubServiceRequest.skip_callback(:save, :after, :update_org_tree)
# build out a Protocol with PPPV LineItems, one Arm
protocol = create(:protocol_without_validations)
arm = create(:arm, :without_validations, protocol: protocol)
Expand All @@ -51,7 +53,6 @@

context "Arm not only Arm for ServiceRequest" do
before(:each) do
SubServiceRequest.skip_callback(:save, :after, :update_org_tree)
# build out a Protocol with PPPV LineItems, one Arm
protocol = create(:protocol_without_validations)
arm1 = create(:arm, :without_validations, protocol: protocol)
Expand Down Expand Up @@ -81,7 +82,6 @@
# these attribute accessors should be nil until #destroy invoked
describe "#sub_service_request" do
before(:each) do
SubServiceRequest.skip_callback(:save, :after, :update_org_tree)
# build out a Protocol with PPPV LineItems, one Arm
protocol = create(:protocol_without_validations)
arm = create(:arm, :without_validations, protocol: protocol)
Expand Down Expand Up @@ -111,7 +111,6 @@

describe "#service_request" do
before(:each) do
SubServiceRequest.skip_callback(:save, :after, :update_org_tree)
# build out a Protocol with PPPV LineItems, one Arm
protocol = create(:protocol_without_validations)
arm = create(:arm, :without_validations, protocol: protocol)
Expand Down
24 changes: 12 additions & 12 deletions spec/models/sub_service_request/distribute_surveys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
RSpec.describe SubServiceRequest, type: :model do

describe "#distribute_surveys" do
before { SubServiceRequest.skip_callback(:save, :after, :update_org_tree) }
after { SubServiceRequest.set_callback(:save, :after, :update_org_tree) }
before(:each) { SubServiceRequest.skip_callback(:save, :after, :update_org_tree) }
after(:each) { SubServiceRequest.set_callback(:save, :after, :update_org_tree) }

context 'we have available surveys' do
before :each do
@pi = create(:identity)
Expand All @@ -15,13 +15,13 @@
@service_request = create(:service_request_without_validations, protocol: @protocol)
@organization = create(:organization)
@survey = create(:survey, access_code: 'sctr-customer-satisfaction-survey')
@sub_service_request = create(:sub_service_request_without_validations,
service_request: @service_request,
organization: @organization,
@sub_service_request = create(:sub_service_request_without_validations,
service_request: @service_request,
organization: @organization,
service_requester_id: @service_requester.id)
@service = create(:service_without_validations, organization_id: @organization.id)
@line_item = create(:line_item_without_validations,
service_request_id: @service_request.id,
@line_item = create(:line_item_without_validations,
service_request_id: @service_request.id,
service_id: @service.id,
sub_service_request_id: @sub_service_request.id)
@organization.associated_surveys.create survey_id: @survey.id
Expand Down Expand Up @@ -51,9 +51,9 @@
@service_request = create(:service_request_without_validations, protocol: @protocol)
@organization = create(:organization)
@survey = create(:survey, access_code: 'sctr-customer-satisfaction-survey')
@sub_service_request = create(:sub_service_request_without_validations,
service_request: @service_request,
organization: @organization,
@sub_service_request = create(:sub_service_request_without_validations,
service_request: @service_request,
organization: @organization,
service_requester_id: @service_requester.id)
end

Expand All @@ -62,4 +62,4 @@
end
end
end
end
end

0 comments on commit f01b6ba

Please sign in to comment.