-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module FlipperHelper | ||
def should_add_tour(flipper_key, flipper_activation) | ||
return true if !flipper_defined? | ||
|
||
case process_activation_option(flipper_activation) | ||
when "enabled" | ||
return (flipper_key && Flipper.enabled?(flipper_key.to_sym)) || flipper_key.nil? | ||
when "disabled" | ||
return (flipper_key && !Flipper.enabled?(flipper_key.to_sym)) || flipper_key.nil? | ||
else | ||
return false | ||
end | ||
end | ||
|
||
private | ||
def flipper_defined? | ||
Object.const_defined?("Flipper") | ||
end | ||
|
||
def process_activation_option(flipper_activation) | ||
return "disabled" if flipper_activation == "disabled" | ||
"enabled" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Abraham | ||
VERSION = "2.5.0" | ||
VERSION = "2.5.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class FlipperHelperTest < ActionView::TestCase | ||
test "Add tour whenever all options nil" do | ||
assert should_add_tour(nil, nil) | ||
end | ||
|
||
test "Add tour whenever Flipper is disabled " do | ||
# Flipper is not enabled, so tour should be added regardless of options | ||
assert should_add_tour("foo", "enabled") | ||
assert should_add_tour("foo", "disabled") | ||
end | ||
|
||
test "Respect Flipper results if Flipper enabled" do | ||
mockFlipper = Object.new | ||
mockFlipper.stubs(:enabled?).returns(true) | ||
|
||
Kernel.const_set('Flipper', mockFlipper) | ||
assert_equal Flipper, mockFlipper | ||
|
||
assert should_add_tour("foo", "enabled") | ||
refute should_add_tour("foo", "disabled") | ||
|
||
mockFlipper.stubs(:enabled?).returns(false) | ||
|
||
refute should_add_tour("foo", "enabled") | ||
assert should_add_tour("foo", "disabled") | ||
|
||
Kernel.send(:remove_const, :Flipper) | ||
end | ||
end |