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

Add and remove features from the UI #30

Open
wants to merge 7 commits 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 Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GIT
PATH
remote: .
specs:
rollout_ui (0.2.0)
rollout_ui (0.3.0)
rollout

GEM
Expand Down
28 changes: 24 additions & 4 deletions lib/rollout_ui/engine/app/assets/stylesheets/rollout_ui/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ h1 img {
padding: 0 25px;
}

.add-feature {
margin: 30px 0;
}

#container {
width: 960px;
margin: 0 auto;
Expand All @@ -52,12 +56,28 @@ h1 img {
margin-bottom: 25px;
}

#features .feature header {
display: -webkit-box;
display: -moz-box;
display: box;
display: flex;
}

#features .feature h2 {
margin: 0px 0 23px;
text-align: center;
display: flex;
font-size: 20px;
font-weight: normal;
letter-spacing: 1px;
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
-webkit-flex: 1;
-moz-flex: 1;
-ms-flex: 1;
flex: 1;
padding: 0 25px;
}

#features .feature nav {
padding: 20px 29px;
}

#features .feature .groups {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
module RolloutUi
class FeaturesController < RolloutUi::ApplicationController
before_filter :wrapper, :only => [:index]
before_filter :wrapper, :only => [:index, :create, :destroy]

def index
@features = @wrapper.features.map{ |feature| RolloutUi::Feature.new(feature) }
end

def create
@wrapper.add_feature(params[:name])

redirect_to features_path
end

def update
@feature = RolloutUi::Feature.new(params[:id])

Expand All @@ -16,6 +22,12 @@ def update
redirect_to features_path
end

def destroy
@wrapper.remove_feature(params[:id])

redirect_to features_path
end

private

def wrapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<h2><%= feature.name %></h2>
<header class="feature-header">
<h2><%= feature.name %></h2>

<nav>
<%= form_tag feature_path(feature.name), method: :delete do %>
<button>remove</button>
<% end %>
</nav>
</header>

<div class="col">
<%= form_tag feature_path(feature.name), :class => "percentage_form", :method => :put, :remote => true do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
<% end %>
</ul>

<div class="add-feature">
<%= form_tag features_path do %>
<input name="name" placeholder="feature_name"></input>
<button>Add Feature</button>
<% end %>
</div>

<% content_for :onready do %>
$("select").chosen({no_results_text: "No groups matched"});
$("input.users").chosen();
Expand Down
2 changes: 1 addition & 1 deletion lib/rollout_ui/engine/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RolloutUi::Engine.routes.draw do
resources :features, :only => [:index, :update]
resources :features, :only => [:index, :create, :update, :destroy]

root :to => "features#index"
end
4 changes: 4 additions & 0 deletions lib/rollout_ui/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def add_feature(feature)
redis.sadd(:features, feature)
end

def remove_feature(feature)
redis.srem(:features, feature)
end

def features
features = redis.smembers(:features)
features ? features.sort : []
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/rollout_ui/wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@
@rollout_ui.features.should == ["featureA"]
end
end

describe "#remove_feature" do
it "removes a feature from the list of features" do
@rollout_ui.add_feature(:feature)

@rollout_ui.remove_feature(:feature)

@rollout_ui.features.should == []
end
end
end
25 changes: 25 additions & 0 deletions spec/requests/engine/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
page.should have_content("featureA")
end

describe "remove button" do
it "removes the feature" do
visit "/rollout"

within("#featureA .feature-header") do
click_button "remove"
end

$rollout.active?(:featureA, user).should be_false
end
end

describe "percentage" do
it "allows changing of the percentage" do
visit "/rollout"
Expand Down Expand Up @@ -104,6 +116,19 @@
page.body.should =~ Regexp.new("#{elements.join('.*')}.*", Regexp::MULTILINE)
end
end

describe "adding a feature" do
it "displays the added feature in the UI" do
visit "/rollout"

within(".add-feature") do
fill_in "name", with: "featureB"
click_button "Add Feature"
end

page.should have_content("featureB")
end
end
end
end