Commit 60a6e2fa authored by Alexandre Friquet's avatar Alexandre Friquet

Quick and durty feature flipping for platform module: refs #37.

parent 58f65ad1
class Features::Platform
def self.enabled?
settings = Settings.instance.reload
[
:mono_activity_collaborating_price,
:mono_activity_standard_price,
:multi_activities_collaborating_price,
:multi_activities_standard_price
].all? { |price| !settings.send(price).nil? }
end
end
......@@ -30,7 +30,9 @@
<li><%= link_to "Membres", members_path, :class => 'action_link' %></li>
<li><%= link_to "Newsletters", newsletters_path, :class => 'action_link' %></li>
<li><%= link_to "Partenaires", partners_path, :class => 'action_link' %></li>
<% if Features::Platform.enabled? %>
<li><%= link_to "Plateforme", platform_path, :class => 'action_link' %></li>
<% end %>
<li><%= link_to "Paramètres", edit_settings_path, :class => 'action_link' %></li>
</ul>
</nav>
......@@ -27,8 +27,10 @@
<% if current_member %>
<%= render partial: 'members/show/private_stuff' %>
<% if Features::Platform.enabled? %>
<%= render partial: 'members/show/performances' %>
<%= render partial: 'members/show/subscriptions' %>
<%- end %>
<%- end %>
<%= render partial: 'members/show/admin_stuff' %>
......@@ -30,5 +30,9 @@ FactoryGirl.define do
contact_email "contact@example.com"
contact_message "Message au niveau du formulaire de contact"
gcal_user "user@gcal.com"
mono_activity_collaborating_price 80
mono_activity_standard_price 90
multi_activities_collaborating_price 120
multi_activities_standard_price 150
end
end
\ No newline at end of file
end
require 'rails_helper'
RSpec.feature "FeatureFlipping", type: :feature do
context "Platform feature" do
context "when enabled" do
before { allow(Features::Platform).to receive(:enabled?).and_return(true) }
context "as an admin" do
before { login_as_admin }
it "displays admin link" do
visit root_path
within "nav#admin_links" do
expect(page).to have_link('Plateforme')
end
end
end
context "as a participating club" do
before { login_as_collaborating_club }
it "displays performances and subscriptions zones on her page" do
visit member_path(@member)
within "section#content" do
expect(page).to have_css("aside#performances")
expect(page).to have_css("aside#subscriptions")
end
end
end
end
context "when disabled" do
before { allow(Features::Platform).to receive(:enabled?).and_return(false) }
context "as an admin" do
before { login_as_admin }
it "does not display admin link" do
visit root_path
within "nav#admin_links" do
expect(page).not_to have_link('Plateforme')
end
end
end
context "as a participating club" do
before { login_as_collaborating_club }
it "does not display performances and subscriptions zones on her page" do
visit member_path(@member)
within "section#content" do
expect(page).not_to have_css("aside#performances")
expect(page).not_to have_css("aside#subscriptions")
end
end
end
end
end
end
require 'rails_helper.rb'
describe Features::Platform do
it "is enabled when all settings prices provided" do
expect(Features::Platform.enabled?).to be_truthy
end
it "is disabled when no settings price provided" do
# Given
platform_prices = {
mono_activity_collaborating_price: nil,
mono_activity_standard_price: nil,
multi_activities_collaborating_price: nil,
multi_activities_standard_price: nil
}
@settings.update_attributes(platform_prices)
# When
# Then
expect(Features::Platform.enabled?).to be_falsy
end
it "is disabled when any settings price not provided" do
@settings.update_attribute(:mono_activity_standard_price, nil)
# When
# Then
expect(Features::Platform.enabled?).to be_falsy
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment