Sha256: 0cdc4bd8320935e16d09928caddd372282a4ba245576edd851ca03d9b931c5a8

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

require "rails_helper"

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

    public :feature_enabled?

    def show
      render text: ""
    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 text: ""
    end

    get :show, 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 text: ""
    end

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

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shamu-0.0.9 spec/lib/shamu/rails/features_spec.rb
shamu-0.0.8 spec/lib/shamu/rails/features_spec.rb
shamu-0.0.7 spec/lib/shamu/rails/features_spec.rb
shamu-0.0.5 spec/lib/shamu/rails/features_spec.rb
shamu-0.0.4 spec/lib/shamu/rails/features_spec.rb
shamu-0.0.3 spec/lib/shamu/rails/features_spec.rb
shamu-0.0.2 spec/lib/shamu/rails/features_spec.rb