Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #120 from springernature/fix-redirection-after-del…
Browse files Browse the repository at this point in the history
…etion

Fix redirection after feature deletion
  • Loading branch information
dazoakley authored Oct 31, 2018
2 parents 122bc4e + b254a10 commit 76a117d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/bandiera/gui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,18 @@ def _put_update_feature_active_toggle

get '/groups/:group_name/features/:feature_name/delete' do |group_name, feature_name|
_get_delete_feature(group_name, feature_name)

group_page_path = "/groups/#{group_name}"
if request.referrer[group_page_path]
redirect group_page_path
else
redirect '/'
end
end

def _get_delete_feature(group_name, feature_name)
feature_service.remove_feature(audit_context, group_name, feature_name)
flash[:success] = 'Feature deleted.'
redirect '/'
end

##
Expand Down
29 changes: 26 additions & 3 deletions spec/lib/bandiera/gui_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,19 +388,42 @@
end

describe 'removing a feature flag' do
it 'deletes a flag' do
visit('/')

def click_delete_button
group_div = first('.bandiera-feature-group')
group_name = group_div.find('h3').text
feature_row = group_div.first('tr.bandiera-feature')
feature_name = feature_row.first('td').text

feature_row.find('.bandiera-delete-feature').click

[group_name, feature_name]
end

it 'deletes a flag' do
visit('/')
group_name, feature_name = click_delete_button

check_success_flash('Feature deleted')
expect { @service.fetch_feature(group_name, feature_name) }.to raise_error(Bandiera::FeatureService::FeatureNotFound)
end

context 'when on a group page' do
before do
@service.add_features(audit_context,
[{ group: 'acidburn', name: 'force_push', description: 'Enable force push', active: false }]
)

page.driver.browser.header('Referer', 'http://example.com/groups/acidburn')
end

it 'leaves you on a group page after deletion' do
visit('/groups/acidburn')
click_delete_button

check_success_flash('Feature deleted')
expect(page).to have_current_path('/groups/acidburn')
end
end
end

describe 'editing a feature flag' do
Expand Down

0 comments on commit 76a117d

Please sign in to comment.