Skip to content

Commit 609e13e

Browse files
committed
Fix AbPanel::Javascript if no properties are set
1 parent adea979 commit 609e13e

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

lib/ab_panel.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def scenarios(experiment)
3737
config.scenarios experiment
3838
end
3939

40+
def properties
41+
@env[:properties]
42+
end
43+
4044
def env
4145
@env ||= {
4246
'conditions' => conditions

lib/ab_panel/javascript.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module AbPanel
22
class Javascript
33
def self.environment
4-
props = {
5-
distinct_id: AbPanel.env["distinct_id"]
6-
}.merge(AbPanel.env[:properties])
4+
props = { distinct_id: AbPanel.env["distinct_id"] }
5+
props.merge!(AbPanel.properties) if AbPanel.properties
76

87
AbPanel.funnels.each { |f| props["funnel_#{f}"] = true }
98

spec/ab_panel/javascript_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require 'spec_helper'
2+
3+
describe AbPanel::Javascript do
4+
it 'returns json of all relevant properties, funnels and experiments' do
5+
AbPanel.set_env('distinct_id', 'distinct_id')
6+
AbPanel.set_env(:properties, { post_name: 'test' })
7+
result = JSON.parse(AbPanel::Javascript.environment)
8+
result['distinct_id'].should == 'distinct_id'
9+
end
10+
11+
it 'works without extra properties' do
12+
AbPanel.set_env(:properties, nil)
13+
result = JSON.parse(AbPanel::Javascript.environment)
14+
result['distinct_id'].should == 'distinct_id'
15+
end
16+
end

0 commit comments

Comments
 (0)