easy_ab 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 068d106a909b0229bc7fc28960f275fca34bd5e9
4
- data.tar.gz: 411b8a8f520e4d4f1dd627065e1105b08175acee
3
+ metadata.gz: 3ae100dfd91abeb836a9e243f121814dbf88a50f
4
+ data.tar.gz: 50441d229531cd30df0044da02ffd816a975084d
5
5
  SHA512:
6
- metadata.gz: 4429ad954dcf221b315d43766c04446e72ee1bb21cef672510e1aebd17214d9224b0a20fa0af06755f52e8818c6da1f1cca317827085fe8c6b03ee956701cb8f
7
- data.tar.gz: 01924f52c1e3a40dde96fcfee2bf8e5d39b79b2f16df5b8c55a4a51e71e471ae60984a2452a06a8e6b51d03654c6d1e3ee539db45a141219b91a742e0e600916
6
+ metadata.gz: 8361270292aa091ab2ba65c0c9fc67ddc28a106c0bedbc52790930ff4ca9cc33134135e44ceb12342d238912a9099e2a4fc338f847751918f88fe0614b2db25c
7
+ data.tar.gz: d522edd22913964f74d34b5099410476110561182c5baa3a83c78be651b1980afb600eb099051bf568610478654c67287d98d48ceb423c3e882c9e9c1c835882
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 0.4.1 (2017-08-18)
2
+ - Provide helper to assign variant in rspec
3
+
1
4
  # 0.4.0 (2017-08-16)
2
5
  - You can specify user in `ab_test()` This useful when requests do not contain current_user. A well-known example is controllers which handle payment results by listening requests from 3rd party payment gateway.
3
6
 
data/README.md CHANGED
@@ -187,6 +187,12 @@ The return format of `all_participated_experiments`:
187
187
  }
188
188
  ```
189
189
 
190
+ # RSpec
191
+ You can easily assign variant to a user in your RSpec tests:
192
+ ```ruby
193
+ assign_variant(user, :button_color, 'red')
194
+ ```
195
+
190
196
  # Others
191
197
  ## Type of experiments
192
198
  Both String and Symbol are valid when defining experiment or passing to `ab_test`.
data/easy_ab.gemspec CHANGED
@@ -13,4 +13,8 @@ Gem::Specification.new do |s|
13
13
  end
14
14
  s.homepage = 'https://github.com/icarus4/easy_ab'
15
15
  s.license = 'MIT'
16
+
17
+ s.add_development_dependency 'rspec-core', '~> 3.0', '>= 3.0.0'
18
+ s.add_development_dependency 'rspec', '~> 3.0'
19
+ s.add_development_dependency 'activerecord', '~> 4.2', '>= 4.0.0'
16
20
  end
@@ -34,7 +34,7 @@ module EasyAb
34
34
  # 1. winner
35
35
  return winner if winner
36
36
 
37
- grouping = find_grouping_by_user_recognition(user_recognition) || ::EasyAb::Grouping.new(experiment: name, user_id: user_recognition[:id], cookie: user_recognition[:cookie])
37
+ grouping = find_grouping_by_user_recognition(user_recognition) || ::EasyAb::Grouping.new(experiment: name, user_id: user_recognition[:user_id], cookie: user_recognition[:cookie])
38
38
 
39
39
  # 2. url parameter or assign variant
40
40
  if options[:variant] && variants.include?(options[:variant].to_s)
@@ -66,7 +66,7 @@ module EasyAb
66
66
 
67
67
  # TODO: add spec
68
68
  def find_grouping_by_user_recognition(user_recognition)
69
- user_id = user_recognition[:id].presence
69
+ user_id = user_recognition[:user_id].presence
70
70
  cookie = user_recognition[:cookie].presence
71
71
  raise 'User not found: both user_id and cookie are empty' if user_id.nil? && cookie.nil?
72
72
 
@@ -27,8 +27,8 @@ module EasyAb
27
27
  options[:scope] = @scope
28
28
  end
29
29
 
30
- @variant_cache ||= {}
31
- @variant_cache[easy_ab_user_id(options)] ||= {}
30
+ @variant_cache ||= {}
31
+ @variant_cache[easy_ab_user_id(options)] ||= {}
32
32
  @variant_cache[easy_ab_user_id(options)][experiment_name] ||= experiment.assign_variant(user_recognition, options)
33
33
  variant = @variant_cache[easy_ab_user_id(options)][experiment_name]
34
34
  block_given? ? yield(variant) : variant
@@ -43,8 +43,8 @@ module EasyAb
43
43
  # }
44
44
  def all_participated_experiments(options = {})
45
45
  user_recognition = find_ab_test_user_recognition(options)
46
- groupings = if user_recognition[:id]
47
- EasyAb::Grouping.where("user_id = ? OR cookie = ?", user_recognition[:id], user_recognition[:cookie])
46
+ groupings = if user_recognition[:user_id]
47
+ EasyAb::Grouping.where(user_id: user_recognition[:user_id])
48
48
  else
49
49
  EasyAb::Grouping.where(cookie: user_recognition[:cookie])
50
50
  end
@@ -64,13 +64,7 @@ module EasyAb
64
64
  # TODO:
65
65
  # return (raise NotImplementedError) if options[:user] && (users << options[:user])
66
66
 
67
- # if options[:user] && options[:user].id
68
- # user_recognition[:id] = options[:user].id
69
- # else
70
- # user_recognition[:id] = current_user_id if current_user_signed_in?
71
- # end
72
-
73
- user_recognition[:id] = easy_ab_user_id(options)
67
+ user_recognition[:user_id] = easy_ab_user_id(options)
74
68
 
75
69
  # Controllers and views
76
70
  user_recognition[:cookie] = find_or_create_easy_ab_cookie if respond_to?(:request)
@@ -0,0 +1,11 @@
1
+ module EasyAb
2
+ module RSpec
3
+ module SpecHelper
4
+ def assign_variant(user, experiment, variant)
5
+ g = EasyAb::Grouping.find_or_initialize_by(user_id: user.id, experiment: experiment)
6
+ g.variant = variant
7
+ g.save!
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ require 'easy_ab/rspec/spec_helper'
2
+
3
+ RSpec.configure do |config|
4
+ config.include EasyAb::RSpec::SpecHelper, type: :controller
5
+ config.include EasyAb::RSpec::SpecHelper, type: :helper
6
+ config.include EasyAb::RSpec::SpecHelper, type: :request
7
+ config.include EasyAb::RSpec::SpecHelper, type: :feature
8
+ end
@@ -1,3 +1,3 @@
1
1
  module EasyAb
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
metadata CHANGED
@@ -1,15 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_ab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Chu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-16 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2017-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: activerecord
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '4.2'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 4.0.0
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '4.2'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 4.0.0
13
67
  description:
14
68
  email: icarus4.chu@gmail.com
15
69
  executables: []
@@ -29,6 +83,8 @@ files:
29
83
  - lib/easy_ab/experiment.rb
30
84
  - lib/easy_ab/helpers.rb
31
85
  - lib/easy_ab/participant.rb
86
+ - lib/easy_ab/rspec.rb
87
+ - lib/easy_ab/rspec/spec_helper.rb
32
88
  - lib/easy_ab/version.rb
33
89
  - lib/generators/easy_ab/install_generator.rb
34
90
  - lib/generators/easy_ab/templates/easy_ab.rb