Skip to content

Commit

Permalink
Fix exclude option in #field_test helper method (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
falusi94 committed Dec 17, 2021
1 parent eca4941 commit 18f1f1c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
## 0.5.2 (unreleased)

- Fixed error with `events` association
- Fixed explicit exclusion by custom logic

## 0.5.1 (2021-09-22)

Expand Down
2 changes: 1 addition & 1 deletion lib/field_test/helpers.rb
Expand Up @@ -13,7 +13,7 @@ def field_test(experiment, **options)
end

if FieldTest.exclude_bots?
options[:exclude] = Browser.new(request.user_agent).bot?
options[:exclude] ||= Browser.new(request.user_agent).bot?
end

options[:exclude] ||= FieldTest.excluded_ips.any? { |ip| ip.include?(request.remote_ip) }
Expand Down
7 changes: 7 additions & 0 deletions test/controller_test.rb
Expand Up @@ -45,6 +45,13 @@ def test_bad_param
refute_includes response.body, "Button: bad"
end

def test_custom_exclude_logic
get users_url("exclude" => "true")
assert_response :success

assert_equal 0, FieldTest::Membership.count
end

def test_exclude_bots
get users_url, headers: {"HTTP_USER_AGENT" => "Googlebot"}
assert_response :success
Expand Down
2 changes: 1 addition & 1 deletion test/internal/app/controllers/users_controller.rb
@@ -1,6 +1,6 @@
class UsersController < ActionController::Base
def index
@button_color = field_test(:button_color)
@button_color = field_test(:button_color, exclude: params[:exclude])
field_test_converted(:button_color)
@experiments = field_test_experiments
end
Expand Down
2 changes: 1 addition & 1 deletion test/internal/app/views/users/index.html.erb
@@ -1,3 +1,3 @@
<p>Button: <%= field_test(:button_color) %></p>
<p>Button: <%= @button_color %></p>
<p>Converted: <%= field_test_converted(:button_color) %></p>
<p>Experiments: <%= field_test_experiments %></p>

0 comments on commit 18f1f1c

Please sign in to comment.