From f460f77cbfa54ee19099e43f3115a6110fc25b17 Mon Sep 17 00:00:00 2001 From: Jippe Holwerda Date: Wed, 2 Mar 2016 14:27:51 +0100 Subject: [PATCH 1/3] Use isolated routes. --- app/controllers/flip/strategies_controller.rb | 4 ++-- config/routes.rb | 14 +++----------- lib/flip/engine.rb | 2 +- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/app/controllers/flip/strategies_controller.rb b/app/controllers/flip/strategies_controller.rb index 11a1920..f59d599 100644 --- a/app/controllers/flip/strategies_controller.rb +++ b/app/controllers/flip/strategies_controller.rb @@ -5,12 +5,12 @@ class StrategiesController < ApplicationController def update strategy.switch! feature_key, turn_on? - redirect_to features_url + redirect_to flip.features_url end def destroy strategy.delete! feature_key - redirect_to features_url + redirect_to flip.features_url end private diff --git a/config/routes.rb b/config/routes.rb index b4ae720..3f5a85d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,14 +1,6 @@ Flip::Engine.routes.draw do - - scope module: "flip" do - - resources :features, path: "", only: [ :index ] do - - resources :strategies, - only: [ :update, :destroy ] - - end - + resources :features, path: "", only: [ :index ] do + resources :strategies, + only: [ :update, :destroy ] end - end diff --git a/lib/flip/engine.rb b/lib/flip/engine.rb index 655d165..5444db0 100644 --- a/lib/flip/engine.rb +++ b/lib/flip/engine.rb @@ -1,9 +1,9 @@ module Flip class Engine < ::Rails::Engine + isolate_namespace Flip initializer "flip.blarg" do ActionController::Base.send(:include, Flip::CookieStrategy::Loader) end - end end From ea60de77f932a12a1d8830faace484bd516c2d8c Mon Sep 17 00:00:00 2001 From: Jippe Holwerda Date: Wed, 2 Mar 2016 14:28:13 +0100 Subject: [PATCH 2/3] Cookies can only be deleted if the domain specified when creating the cookie is provided. --- flip.gemspec | 2 ++ lib/flip/cookie_strategy.rb | 2 +- spec/cookie_strategy_spec.rb | 16 +++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/flip.gemspec b/flip.gemspec index 37f6ca5..7706c44 100644 --- a/flip.gemspec +++ b/flip.gemspec @@ -24,4 +24,6 @@ Gem::Specification.new do |s| s.add_development_dependency("rspec", "~> 2.5") s.add_development_dependency("rspec-its") s.add_development_dependency("rake") + s.add_development_dependency("rack") + s.add_development_dependency("actionpack", ">= 3.0", "< 5") end diff --git a/lib/flip/cookie_strategy.rb b/lib/flip/cookie_strategy.rb index e02cf7e..08b4245 100644 --- a/lib/flip/cookie_strategy.rb +++ b/lib/flip/cookie_strategy.rb @@ -28,7 +28,7 @@ def switch! key, on end def delete! key - cookies.delete cookie_name(key) + cookies.delete cookie_name(key), domain: :all end def self.cookies= cookies diff --git a/spec/cookie_strategy_spec.rb b/spec/cookie_strategy_spec.rb index 929548c..4b32f8c 100644 --- a/spec/cookie_strategy_spec.rb +++ b/spec/cookie_strategy_spec.rb @@ -1,18 +1,28 @@ require "spec_helper" +require "action_dispatch" +require "rack" class ControllerWithoutCookieStrategy; end class ControllerWithCookieStrategy def self.before_filter(_); end def self.after_filter(_); end - def cookies; []; end + def cookies; cookie_jar; end include Flip::CookieStrategy::Loader end +def cookie_jar + env = Rack::MockRequest.env_for("/example") + request = ActionDispatch::TestRequest.new(env) + ActionDispatch::Cookies::CookieJar.build(request) +end + describe Flip::CookieStrategy do let(:cookies) do - { strategy.cookie_name(:one) => "true", - strategy.cookie_name(:two) => "false" } + cookie_jar.tap do |jar| + jar[strategy.cookie_name(:one)] = "true" + jar[strategy.cookie_name(:two)] = "false" + end end let(:strategy) do Flip::CookieStrategy.new.tap do |s| From a069494f36944f91fd549ca3442b701c3707bbf7 Mon Sep 17 00:00:00 2001 From: Jippe Holwerda Date: Fri, 4 Mar 2016 11:08:01 +0100 Subject: [PATCH 3/3] Add css to asset pipeline. --- lib/flip/engine.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/flip/engine.rb b/lib/flip/engine.rb index 5444db0..03b7cbb 100644 --- a/lib/flip/engine.rb +++ b/lib/flip/engine.rb @@ -5,5 +5,9 @@ class Engine < ::Rails::Engine initializer "flip.blarg" do ActionController::Base.send(:include, Flip::CookieStrategy::Loader) end + + initializer "flip.assets.precompile" do |app| + app.config.assets.precompile += %w(flip.css) + end end end