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

Call Devise RegistrationsController block #3286

Merged
merged 1 commit into from
Nov 28, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def create
**event_information.to_h
)
end

yield resource if block_given?
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ def try(value)
expect(Datadog::AppSec::Contrib::Devise::Tracking).to_not receive(:track_signup)
expect(controller.create).to eq(true)
end

context 'and a block is given' do
let(:canary) { proc { |resource| } }
let(:block) { proc { |resource| canary.call(resource) } }

it 'do not tracks event' do
expect(Datadog::AppSec::Contrib::Devise::Tracking).to_not receive(:track_signup)
expect(canary).to receive(:call).with(resource)
expect(controller.create(&block)).to eq(true)
end
end
end

context 'Automated user tracking is disabled' do
Expand All @@ -77,6 +88,17 @@ def try(value)
expect(Datadog::AppSec::Contrib::Devise::Tracking).to_not receive(:track_signup)
expect(controller.create).to eq(true)
end

context 'and a block is given' do
let(:canary) { proc { |resource| } }
let(:block) { proc { |resource| canary.call(resource) } }

it 'do not tracks event' do
expect(Datadog::AppSec::Contrib::Devise::Tracking).to_not receive(:track_signup)
expect(canary).to receive(:call).with(resource)
expect(controller.create(&block)).to eq(true)
end
end
end

context 'AppSec scope is nil ' do
Expand All @@ -89,6 +111,17 @@ def try(value)
expect(Datadog::AppSec::Contrib::Devise::Tracking).to_not receive(:track_signup)
expect(controller.create).to eq(true)
end

context 'and a block is given' do
let(:canary) { proc { |resource| } }
let(:block) { proc { |resource| canary.call(resource) } }

it 'do not tracks event' do
expect(Datadog::AppSec::Contrib::Devise::Tracking).to_not receive(:track_signup)
expect(canary).to receive(:call).with(resource)
expect(controller.create(&block)).to eq(true)
end
end
end

context 'with persisted resource' do
Expand All @@ -99,6 +132,41 @@ def try(value)
context 'with resource ID' do
let(:resource) { persited_resource }

context 'and a block is given' do
let(:canary) { proc { |resource| } }
let(:block) { proc { |resource| canary.call(resource) } }

context 'safe mode' do
let(:mode) { 'safe' }

it 'tracks event' do
expect(Datadog::AppSec::Contrib::Devise::Tracking).to receive(:track_signup).with(
appsec_scope.trace,
appsec_scope.service_entry_span,
user_id: resource.id,
**{}
)
expect(canary).to receive(:call).with(resource)
expect(controller.create(&block)).to eq(true)
end
end

context 'extended mode' do
let(:mode) { 'extended' }

it 'tracks event' do
expect(Datadog::AppSec::Contrib::Devise::Tracking).to receive(:track_signup).with(
appsec_scope.trace,
appsec_scope.service_entry_span,
user_id: resource.id,
**{ email: 'hello@gmail.com', username: 'John' }
)
expect(canary).to receive(:call).with(resource)
expect(controller.create(&block)).to eq(true)
end
end
end

context 'safe mode' do
let(:mode) { 'safe' }

Expand Down Expand Up @@ -131,6 +199,41 @@ def try(value)
context 'without resource ID' do
let(:resource) { mock_resource.new(nil, 'hello@gmail.com', 'John', true) }

context 'and a block is given' do
let(:canary) { proc { |resource| } }
let(:block) { proc { |resource| canary.call(resource) } }

context 'safe mode' do
let(:mode) { 'safe' }

it 'tracks event' do
expect(Datadog::AppSec::Contrib::Devise::Tracking).to receive(:track_signup).with(
appsec_scope.trace,
appsec_scope.service_entry_span,
user_id: nil,
**{}
)
expect(canary).to receive(:call).with(resource)
expect(controller.create(&block)).to eq(true)
end
end

context 'extended mode' do
let(:mode) { 'extended' }

it 'tracks event' do
expect(Datadog::AppSec::Contrib::Devise::Tracking).to receive(:track_signup).with(
appsec_scope.trace,
appsec_scope.service_entry_span,
user_id: nil,
**{ email: 'hello@gmail.com', username: 'John' }
)
expect(canary).to receive(:call).with(resource)
expect(controller.create(&block)).to eq(true)
end
end
end

context 'safe mode' do
let(:mode) { 'safe' }

Expand Down Expand Up @@ -174,6 +277,17 @@ def try(value)
expect(Datadog::AppSec::Contrib::Devise::Tracking).to_not receive(:track_signup)
expect(controller.create).to eq(true)
end

context 'and a block is given' do
let(:canary) { proc { |resource| } }
let(:block) { proc { |resource| canary.call(resource) } }

it 'do not tracks event' do
expect(Datadog::AppSec::Contrib::Devise::Tracking).to_not receive(:track_signup)
expect(canary).to receive(:call).with(resource)
expect(controller.create(&block)).to eq(true)
end
end
end

context 'extended mode' do
Expand All @@ -183,6 +297,17 @@ def try(value)
expect(Datadog::AppSec::Contrib::Devise::Tracking).to_not receive(:track_signup)
expect(controller.create).to eq(true)
end

context 'and a block is given' do
let(:canary) { proc { |resource| } }
let(:block) { proc { |resource| canary.call(resource) } }

it 'do not tracks event' do
expect(Datadog::AppSec::Contrib::Devise::Tracking).to_not receive(:track_signup)
expect(canary).to receive(:call).with(resource)
expect(controller.create(&block)).to eq(true)
end
end
end
end
end
Loading