Browse files

- Unescape URIs when the server receives the request.

- Added specs
  • Loading branch information...
1 parent 8a7bb13 commit 2bb9c3aa2fa7d6d08fee51618716577460cd3dd5 @gabceb gabceb committed May 14, 2013
Showing with 31 additions and 1 deletion.
  1. +2 −1 lib/flipper/ui/actions/gate.rb
  2. +29 −0 spec/flipper/ui_spec.rb
View
3 lib/flipper/ui/actions/gate.rb
@@ -2,6 +2,7 @@
require 'flipper/ui/action'
require 'flipper/ui/actions/index'
require 'flipper/ui/decorators/feature'
+require 'open-uri'
module Flipper
module UI
@@ -22,7 +23,7 @@ def get
# FIXME: Handle gate not found by name.
# FIXME: Return more than just the gate as json response?
def post
- feature_name, gate_name = request.path.split('/').pop(2)
+ feature_name, gate_name = request.path.split('/').pop(2).map{|value| URI.unescape value }
update_gate_method_name = "update_#{gate_name}"
unless respond_to?(update_gate_method_name)
View
29 spec/flipper/ui_spec.rb
@@ -2,6 +2,7 @@
require 'rack/test'
require 'flipper'
require 'flipper/adapters/memory'
+require 'open-uri'
describe Flipper::UI do
include Rack::Test::Methods
@@ -130,6 +131,34 @@
end
end
+ describe "POST /features/:id/boolean for values that are URI encoded" do
+ before do
+ feature = flipper["feature:v1"]
+ feature.enable
+ params = {
+ 'value' => 'false',
+ }
+ feature_encoded_name = URI.encode_www_form_component(feature.name)
+ post "/features/#{feature_encoded_name}/boolean", params
+ end
+
+ it "responds with 200" do
+ last_response.status.should be(200)
+ end
+
+ it "responds with json" do
+ result = json_response
+ result.should be_instance_of(Hash)
+ result['name'].should eq('boolean')
+ result['key'].should eq('boolean')
+ result['value'].should eq(false)
+ end
+
+ it "updates gate state" do
+ flipper["feature:v1"].state.should be(:off)
+ end
+ end
+
describe "POST /features/:id/percentage_of_actors" do
context "valid value" do
before do

0 comments on commit 2bb9c3a

Please sign in to comment.