Sha256: 0bd77011215630086de27aa731c3d16415ea84f38a42ce4b8bb402f0a16534f9

Contents?: true

Size: 1.91 KB

Versions: 8

Compression:

Stored size: 1.91 KB

Contents

require 'helper'

RSpec.describe Flipper::UI::Actions::Feature do
  let(:token) do
    if Rack::Protection::AuthenticityToken.respond_to?(:random_token)
      Rack::Protection::AuthenticityToken.random_token
    else
      'a'
    end
  end
  let(:session) do
    { :csrf => token, 'csrf' => token, '_csrf_token' => token }
  end

  describe 'DELETE /features/:feature' do
    before do
      flipper.enable :search
      delete '/features/search',
             { 'authenticity_token' => token },
             'rack.session' => session
    end

    it 'removes feature' do
      expect(flipper.features.map(&:key)).not_to include('search')
    end

    it 'redirects to features' do
      expect(last_response.status).to be(302)
      expect(last_response.headers['Location']).to eq('/features')
    end
  end

  describe 'POST /features/:feature with _method=DELETE' do
    before do
      flipper.enable :search
      post '/features/search',
           { '_method' => 'DELETE', 'authenticity_token' => token },
           'rack.session' => session
    end

    it 'removes feature' do
      expect(flipper.features.map(&:key)).not_to include('search')
    end

    it 'redirects to features' do
      expect(last_response.status).to be(302)
      expect(last_response.headers['Location']).to eq('/features')
    end
  end

  describe 'GET /features/:feature' do
    before do
      get '/features/search'
    end

    it 'responds with success' do
      expect(last_response.status).to be(200)
    end

    it 'renders template' do
      expect(last_response.body).to include('search')
      expect(last_response.body).to include('Enable')
      expect(last_response.body).to include('Disable')
      expect(last_response.body).to include('Actors')
      expect(last_response.body).to include('Groups')
      expect(last_response.body).to include('Percentage of Time')
      expect(last_response.body).to include('Percentage of Actors')
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
flipper-ui-0.11.0 spec/flipper/ui/actions/feature_spec.rb
flipper-ui-0.11.0.rc1 spec/flipper/ui/actions/feature_spec.rb
flipper-ui-0.11.0.beta9 spec/flipper/ui/actions/feature_spec.rb
flipper-ui-0.11.0.beta8 spec/flipper/ui/actions/feature_spec.rb
flipper-ui-0.11.0.beta7 spec/flipper/ui/actions/feature_spec.rb
flipper-ui-0.11.0.beta6 spec/flipper/ui/actions/feature_spec.rb
flipper-ui-0.11.0.beta5 spec/flipper/ui/actions/feature_spec.rb
flipper-ui-0.11.0.beta4 spec/flipper/ui/actions/feature_spec.rb