Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #23 from castle/more_options
Browse files Browse the repository at this point in the history
more js options
  • Loading branch information
bartes committed Jan 2, 2019
2 parents dcce356 + 5118c85 commit 23e2885
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
18 changes: 16 additions & 2 deletions lib/castle/middleware/body_modify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def js_commands(req)
resource = configuration.services.provide_user.call(req, false)
[
"\n",
autoforward_client_id_command,
cookie_domain_command,
tracker_url_command,
identify_command(resource),
secure_command(resource),
Expand All @@ -77,13 +79,25 @@ def js_options(req)
def tracker_url_command
return unless configuration.tracker_url

"_castle('setTrackerUrl', '#{configuration.tracker_url}');"
"_castle('setTrackerUrl','#{configuration.tracker_url}');"
end

def autoforward_client_id_command
return unless configuration.autoforward_client_id

"_castle('autoForwardClientId',#{!!configuration.autoforward_client_id});"
end

def cookie_domain_command
return unless configuration.cookie_domain

"_castle('setCookieDomain','#{configuration.cookie_domain}');"
end

def identify_command(resource)
return unless resource

"_castle('identify', '#{Identification.id(resource, configuration.identify)}');"
"_castle('identify','#{Identification.id(resource, configuration.identify)}');"
end

def secure_command(resource)
Expand Down
3 changes: 2 additions & 1 deletion lib/castle/middleware/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Configuration
attr_reader :options
def_delegators :@options,
:logger, :transport, :api_secret, :app_id,
:tracker_url, :services,
:tracker_url, :autoforward_client_id, :cookie_domain,
:services,
:events, :identify, :user_traits, :security_headers
def_delegators :@middleware, :log, :track

Expand Down
2 changes: 2 additions & 0 deletions lib/castle/middleware/configuration/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Options
api_secret
app_id
tracker_url
autoforward_client_id
cookie_domain
security_headers
file_path
logger
Expand Down
24 changes: 24 additions & 0 deletions spec/castle/middleware/sensor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def xhr?

allow(::Castle::Middleware.instance.configuration.services).to receive(:provide_user) { lambda { |_r, _s| user } }
allow(::Castle::Middleware.instance.configuration).to receive(:api_secret).and_return('secret')
allow(::Castle::Middleware.instance.configuration).to receive(:tracker_url).and_return('http://api.local')
allow(::Castle::Middleware.instance.configuration).to receive(:cookie_domain).and_return('dev.local')
allow(::Castle::Middleware.instance.configuration).to receive(:autoforward_client_id).and_return(true)
allow(app).to receive(:call).and_return(response)
end

Expand All @@ -72,6 +75,24 @@ def xhr?
end
end

matcher :inject_the_tracker_url_tag do
match_unless_raises do |subscriber|
expect(subscriber[2]).to include "_castle('setTrackerUrl','http://api.local');"
end
end

matcher :inject_the_cookie_domain_tag do
match_unless_raises do |subscriber|
expect(subscriber[2]).to include "_castle('setCookieDomain','dev.local');"
end
end

matcher :inject_the_autoforward_client_id_tag do
match_unless_raises do |subscriber|
expect(subscriber[2]).to include "_castle('autoForwardClientId',true);"
end
end

describe '#call' do
subject { described_class.new(app).call(env) }

Expand Down Expand Up @@ -105,6 +126,9 @@ def xhr?

it { is_expected.to inject_the_identify_tag }
it { is_expected.to inject_the_secure_tag }
it { is_expected.to inject_the_tracker_url_tag }
it { is_expected.to inject_the_cookie_domain_tag }
it { is_expected.to inject_the_autoforward_client_id_tag }
end
end
end

0 comments on commit 23e2885

Please sign in to comment.