1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
RSpec.describe Flipper::UI::Actions::BooleanGate 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 'POST /features/:feature/boolean' do
context 'with enable' do
before do
flipper.disable :search
post 'features/search/boolean',
{ 'action' => 'Enable', 'authenticity_token' => token },
'rack.session' => session
end
it 'enables the feature' do
expect(flipper.enabled?(:search)).to be(true)
end
it 'redirects back to feature' do
expect(last_response.status).to be(302)
expect(last_response.headers['Location']).to eq('/features/search')
end
end
context "with space in feature name" do
before do
flipper.disable :search
post 'features/sp%20ace/boolean',
{ 'action' => 'Enable', 'authenticity_token' => token },
'rack.session' => session
end
it 'updates feature' do
expect(flipper.enabled?("sp ace")).to be(true)
end
it 'redirects back to feature' do
expect(last_response.status).to be(302)
expect(last_response.headers['Location']).to eq('/features/sp%20ace')
end
end
context 'with disable' do
before do
flipper.enable :search
post 'features/search/boolean',
{ 'action' => 'Disable', 'authenticity_token' => token },
'rack.session' => session
end
it 'disables the feature' do
expect(flipper.enabled?(:search)).to be(false)
end
it 'redirects back to feature' do
expect(last_response.status).to be(302)
expect(last_response.headers['Location']).to eq('/features/search')
end
end
end
end
|