optimizely_server_side 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2adc2d7c6755664a10e7a43109f478f172e10f0
4
- data.tar.gz: ca12b6071d0a8abcc9a2079c4bf366d066115001
3
+ metadata.gz: 7b974d9d401c8dff8321737ee17ee14c05799dc6
4
+ data.tar.gz: 8365698fc538b641ae6aa2938921347d7cfd8675
5
5
  SHA512:
6
- metadata.gz: 987383df683e78fadec0b58a9d3f3915b4105505049a33b20734a6a12ebd9d0881d814e2772d0ceda4dd9b30d0c90d48d1919724318b37ce9186298c10bd1a5f
7
- data.tar.gz: d4e8a60ab1672b8792f7305b26df719b401462536d0d6438dc2af0d334da36310cbe6db8420e6fd750d8ba32a06ddcd68effb2bd6cb0d7a042c110c96d264105
6
+ metadata.gz: 85a8e18f9b8b1cf339d90b824c56bcc56e2671d2811b09406cdd0b45b06e83ce24c8105660dbd96d771704632def7e755588446664e68cbb075ee7a2218b9066
7
+ data.tar.gz: c8d71fd9d761bb345ff2bd03f5cdae891fea13a3f286c00882824626d23798e03cf3d71d831a83a2eeaaf1c858d8eb7427dfb8ce004b2303d0b40c3a0931d0cf
data/Changelog.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.0.13
2
+
3
+ - Adding support for adding additional attributes via experiments.
4
+ - Adding a feature_flip method which is alias of experiment to distinguish between experiments and on/off feature.
5
+
6
+
1
7
  # 0.0.11
2
8
 
3
9
  Bug fix. Visitor id should not be passed in attributes.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- optimizely_server_side (0.0.12)
4
+ optimizely_server_side (0.0.13)
5
5
  activesupport (~> 4.2, >= 4.2.6)
6
6
  optimizely-sdk (~> 0.1.1)
7
7
 
data/Readme.md CHANGED
@@ -101,15 +101,15 @@ class ApplicationController < ActionController::Base
101
101
 
102
102
  ```ruby
103
103
  # in any app/view/foo.html.erb
104
- <% experiment(EXPERIMENT_KEY) do |config| %>
104
+ <%= experiment(EXPERIMENT_KEY) do |exp|
105
105
 
106
- <% config.variation_one(VARIATION_ONE_KEY) do %>
107
- <%= render partial: 'variation_one_experience' %>
108
- <% end %>
106
+ exp.variation_one(VARIATION_ONE_KEY) do
107
+ render partial: 'variation_one_experience'
108
+ end
109
109
 
110
- <% config.variation_default(VARIATION_DEFAULT_KEY, primary: true) do %>
111
- <%= render partial: 'variation_default_experience' %>
112
- <% end %>
110
+ exp.variation_default(VARIATION_DEFAULT_KEY, primary: true)
111
+ render partial: 'variation_default_experience'
112
+ end
113
113
 
114
114
  <% end %>
115
115
  ```
@@ -126,13 +126,13 @@ class Foo
126
126
  # any other rest endpoint.
127
127
  # Suppose you are doing a AB test on a new endpoint / data source.
128
128
  def get_me_some_data
129
- data = experiment(EXPERIMENT_KEY) do |config|
129
+ data = experiment(EXPERIMENT_KEY) do |exp|
130
130
 
131
- config.variation_one(VARIATION_ONE_KEY) do
131
+ exp.variation_one(VARIATION_ONE_KEY) do
132
132
  HTTParty.get('http://from_source_a.com/users')
133
133
  end
134
134
 
135
- config.variation_default(VARIATION_TWO_KEY, primary: true) do
135
+ exp.variation_default(VARIATION_TWO_KEY, primary: true) do
136
136
  HTTParty.get('http://from_source_b.com/users')
137
137
  end
138
138
  end
@@ -147,15 +147,15 @@ You can call you own method names with `variation_` . Below i have `config.varia
147
147
 
148
148
  ```ruby
149
149
  # in any app/view/foo.html.erb
150
- <% experiment(EXPERIMENT_KEY) do |config| %>
150
+ <%= experiment(EXPERIMENT_KEY) do |exp|
151
151
 
152
- <% config.variation_best_experience(VARIATION_ONE_KEY) do %>
153
- <%= render partial: 'variation_one_experience' %>
154
- <% end %>
152
+ config.variation_best_experience(VARIATION_ONE_KEY) do
153
+ render partial: 'variation_one_experience'
154
+ end
155
155
 
156
- <% config.variation_pathetic_experience(VARIATION_DEFAULT_KEY, primary: true) do %>
157
- <%= render partial: 'variation_default_experience' %>
158
- <% end %>
156
+ config.variation_pathetic_experience(VARIATION_DEFAULT_KEY, primary: true) do
157
+ render partial: 'variation_default_experience'
158
+ end
159
159
 
160
160
  <% end %>
161
161
 
@@ -21,10 +21,13 @@ module OptimizelyServerSide
21
21
  # end
22
22
  #
23
23
  # end
24
- def experiment(experiment_key, &blk)
24
+ def experiment(experiment_key, options = {}, &blk)
25
+ # Merge any other options to user attributes
26
+ OptimizelyServerSide.configuration.user_attributes.merge!(options.stringify_keys)
25
27
  variation_key = optimizely_sdk_project_instance(experiment_key)
26
28
  OptimizelyServerSide::Experiment.new(experiment_key, variation_key).start(&blk)
27
29
  end
30
+ alias_method :feature_flip, :experiment
28
31
 
29
32
  def optimizely_sdk_project_instance(experiment_key)
30
33
  OptimizelyServerSide::OptimizelySdk
@@ -2,8 +2,8 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'optimizely_server_side'
5
- s.version = '0.0.12'
6
- s.date = '2016-08-28'
5
+ s.version = '0.0.13'
6
+ s.date = '2016-09-11'
7
7
  s.summary = "Optimizely server side. A wrapper on top of optimizely's ruby sdk for easy caching of server side config "
8
8
  s.description = "Optimizely server side. A A/B test wrapper on top of optimizely's ruby sdk for easy caching of server side config and exposing few more utility helpers. Handling of fallbacks and marking primary experiments. "
9
9
  s.authors = ["Ankit Gupta"]
@@ -8,12 +8,28 @@ RSpec.describe OptimizelyServerSide::Support do
8
8
  puts "Do nothing with #{url} and #{params}"
9
9
  end
10
10
  end
11
+
11
12
  class FakeKlass
12
13
 
13
14
  include OptimizelyServerSide::Support
14
15
 
16
+ def method_two_with_options
17
+
18
+ experiment('bar_experiment_key', state_code: 'ca', device_type: 'iPhone') do |config|
15
19
 
16
- def some_klass_method
20
+ config.variation_one('variation_one') do
21
+ 'Experience one'
22
+ end
23
+
24
+ config.variation_two('variation_two') do
25
+ 'Experience two'
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+ def method_one
17
33
 
18
34
  experiment('foo_experiment_key') do |config|
19
35
 
@@ -27,6 +43,19 @@ RSpec.describe OptimizelyServerSide::Support do
27
43
 
28
44
  end
29
45
  end
46
+
47
+
48
+ def method_with_feature_flip
49
+
50
+ feature_flip('baz_experiment_key') do |config|
51
+
52
+ config.variation_one('variation_one') do
53
+ 'Experience one'
54
+ end
55
+
56
+ end
57
+
58
+ end
30
59
  end
31
60
 
32
61
 
@@ -41,7 +70,7 @@ RSpec.describe OptimizelyServerSide::Support do
41
70
  allow(subject).to receive(:optimizely_sdk_project_instance).and_return('variation_one')
42
71
  end
43
72
 
44
- it { expect(subject.some_klass_method).to eq('Experience one')}
73
+ it { expect(subject.method_one).to eq('Experience one')}
45
74
  end
46
75
 
47
76
 
@@ -67,7 +96,42 @@ RSpec.describe OptimizelyServerSide::Support do
67
96
  end
68
97
 
69
98
 
70
- it { expect(subject.some_klass_method).to be_nil }
99
+ it { expect(subject.method_one).to be_nil }
71
100
  end
101
+
102
+
103
+ context 'when a options hash is passed' do
104
+
105
+
106
+ before do
107
+ subject.method_two_with_options
108
+ end
109
+
110
+ # Reset to empty
111
+ after do
112
+ OptimizelyServerSide.configuration.user_attributes = {}
113
+ end
114
+
115
+ it 'hash no user attributes when not passed' do
116
+ expect(OptimizelyServerSide.configuration.user_attributes).to eq({'state_code' => 'ca', 'device_type' => 'iPhone'})
117
+ end
118
+
119
+ end
120
+ end
121
+
122
+ describe '#feature_flip' do
123
+
124
+ subject { FakeKlass.new }
125
+
126
+
127
+ context 'feature flip' do
128
+
129
+ before do
130
+ allow(subject).to receive(:optimizely_sdk_project_instance).and_return('variation_one')
131
+ end
132
+
133
+ it { expect(subject.method_with_feature_flip).to eq('Experience one')}
134
+ end
135
+
72
136
  end
73
137
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optimizely_server_side
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ankit Gupta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-28 00:00:00.000000000 Z
11
+ date: 2016-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec