Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass feature to the switchable method #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class UserPreferenceStrategy < Flipflop::Strategies::AbstractStrategy
end
end

def switchable?
def switchable?(feature)
# Can only switch features on/off if we have the user's session.
# The `request` method is provided by AbstractStrategy.
request?
Expand Down
6 changes: 3 additions & 3 deletions app/views/flipflop/features/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@
name: "commit",
value: "1",
class: @feature_set.strategy_status(strategy, feature) == :enabled ? "active" : nil,
disabled: !strategy.switchable?
disabled: !strategy.switchable?(feature)
-%>

<%= button_tag t(:disabled, scope: [:flipflop, :feature_states]),
type: "submit",
name: "commit",
value: "0",
class: @feature_set.strategy_status(strategy, feature) == :disabled ? "active" : nil,
disabled: !strategy.switchable?
disabled: !strategy.switchable?(feature)
-%>
</div>
<% end -%>

<% if strategy.switchable? -%>
<% if strategy.switchable?(feature) -%>
<div class="group">
<% unless @feature_set.strategy_status(strategy, feature).blank? -%>
<%= form_tag(@feature_set.switch_url(strategy, feature), method: :delete) do -%>
Expand Down
2 changes: 1 addition & 1 deletion lib/flipflop/strategies/abstract_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def hidden?

# Return true iff this strategy is able to switch features on/off.
# Return false otherwise.
def switchable?
def switchable?(feature)
false
end

Expand Down
2 changes: 1 addition & 1 deletion lib/flipflop/strategies/active_record_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(**options)
super(**options)
end

def switchable?
def switchable?(feature)
true
end

Expand Down
2 changes: 1 addition & 1 deletion lib/flipflop/strategies/cookie_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(**options)
super(**options)
end

def switchable?
def switchable?(feature)
request?
end

Expand Down
2 changes: 1 addition & 1 deletion lib/flipflop/strategies/redis_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(**options)
super(**options)
end

def switchable?
def switchable?(feature)
true
end

Expand Down
2 changes: 1 addition & 1 deletion lib/flipflop/strategies/session_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(**options)
super(**options)
end

def switchable?
def switchable?(feature)
request?
end

Expand Down
2 changes: 1 addition & 1 deletion lib/flipflop/strategies/test_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(**options)
super(**options)
end

def switchable?
def switchable?(feature)
true
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/strategies/abstract_strategy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
end

it "should not be switchable" do
assert_equal false, subject.switchable?
assert_equal false, subject.switchable?(:test)
end

it "should not be hidden" do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/strategies/active_record_strategy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def save!
end

it "should be switchable" do
assert_equal true, subject.switchable?
assert_equal true, subject.switchable?(:test)
end

it "should have unique key" do
Expand Down
4 changes: 2 additions & 2 deletions test/unit/strategies/cookie_strategy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
end

it "should be switchable" do
assert_equal true, subject.switchable?
assert_equal true, subject.switchable?(:test)
end

it "should have unique key" do
Expand Down Expand Up @@ -124,7 +124,7 @@
end

it "should not be switchable" do
assert_equal false, subject.switchable?
assert_equal false, subject.switchable?(:test)
end

it "should not be able to switch feature on" do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/strategies/default_strategy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
end

it "should not be switchable" do
assert_equal false, subject.switchable?
assert_equal false, subject.switchable?(:test)
end

it "should have unique key" do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/strategies/lambda_strategy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
end

it "should not be switchable" do
assert_equal false, subject.switchable?
assert_equal false, subject.switchable?(:test)
end

it "should have unique key" do
Expand Down
4 changes: 2 additions & 2 deletions test/unit/strategies/query_string_strategy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
end

it "should not be switchable" do
assert_equal false, subject.switchable?
assert_equal false, subject.switchable?(:test)
end

it "should have unique key" do
Expand Down Expand Up @@ -84,7 +84,7 @@
end

it "should not be switchable" do
assert_equal false, subject.switchable?
assert_equal false, subject.switchable?(:test)
end
end
end
2 changes: 1 addition & 1 deletion test/unit/strategies/redis_strategy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
end

it "should be switchable" do
assert_equal true, subject.switchable?
assert_equal true, subject.switchable?(:test)
end

it "should have unique key" do
Expand Down
4 changes: 2 additions & 2 deletions test/unit/strategies/session_strategy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
end

it "should be switchable" do
assert_equal true, subject.switchable?
assert_equal true, subject.switchable?(:test)
end

it "should have unique key" do
Expand Down Expand Up @@ -109,7 +109,7 @@
end

it "should not be switchable" do
assert_equal false, subject.switchable?
assert_equal false, subject.switchable?(:test)
end

it "should not be able to switch feature on" do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/strategies/test_strategy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
end

it "should be switchable" do
assert_equal true, subject.switchable?
assert_equal true, subject.switchable?(:test)
end

it "should have unique key" do
Expand Down