Sha256: a0e53f4a090f8cf82ccc8e5032e201d2c296209f7e2093e11ceb995c300230b6

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require "rails_helper"

describe Shamu::Rails::Features, type: :controller do
  controller ActionController::Base do

    public :feature_enabled?

    def show
      render plain: ""
    end
  end

  hunt( :features_service, Shamu::Features::FeaturesService ) do
    scorpion.new Shamu::Features::FeaturesService, File.expand_path( "../features.yml", __FILE__ ), {}
  end

  hunt( :session_store, Shamu::Sessions::CookieStore )

  it "resolves toggles" do
    expect( session_store ).to receive( :fetch ).and_return nil
    allow( session_store ).to receive( :set )

    expect( controller ).to receive( :show ) do
      expect( controller.feature_enabled?( "shopping/nux" ) ).to be_truthy
      controller.render plain: ""
    end

    get :show, params: { id: 1 }
  end

  it "allows toggles to be overridden by query param" do
    expect( session_store ).to receive( :fetch ).and_return nil
    allow( session_store ).to receive( :set )

    override = features_service.toggle_codec.pack( "shopping/discounts" => true )

    expect( controller ).to receive( :show ) do
      expect( controller.feature_enabled?( "shopping/discounts" ) ).to be_truthy
      controller.render plain: ""
    end

    get :show, params: { id: 1, Shamu::Features::EnvStore::RACK_PARAMS_KEY => override } 
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shamu-0.0.11 spec/lib/shamu/rails/features_spec.rb