diff --git a/app/controllers/mappings_controller.rb b/app/controllers/mappings_controller.rb index 69bf8afcf..59aab8e0e 100644 --- a/app/controllers/mappings_controller.rb +++ b/app/controllers/mappings_controller.rb @@ -14,7 +14,13 @@ def new def create @mapping = @site.mappings.build(params[:mapping]) if @mapping.save - redirect_to site_mappings_path(@site), notice: 'Mapping saved.' + if @mapping.redirect? + link = ActionController::Base.helpers.link_to @mapping.new_url, @mapping.new_url + notice = "Mapping created. #{@mapping.path} redirects to #{link}" + else + notice = "Mapping created. #{@mapping.path} has been archived" + end + redirect_to edit_site_mapping_path(@site, @mapping), notice: notice.html_safe else render action: 'new' end @@ -31,7 +37,7 @@ def edit def update @mapping = @site.mappings.find(params[:id]) if @mapping.update_attributes(params[:mapping]) - redirect_to site_mappings_path(@site), notice: 'Mapping saved.' + redirect_to edit_site_mapping_path(@site, @mapping), notice: 'Mapping saved.' else render action: 'edit' end diff --git a/features/mapping_create.feature b/features/mapping_create.feature index c9c3cd843..a8b444589 100644 --- a/features/mapping_create.feature +++ b/features/mapping_create.feature @@ -11,9 +11,10 @@ Feature: Create a mapping Then I should see "http://bis.gov.uk" When I make the mapping a redirect from /Needs/Canonicalizing/q=1 to http://gov.uk/organisations/bis And I create the mapping - Then I should be returned to the mappings list for bis - And I should see "Mapping saved." + Then I should be returned to the edit mapping page with a success message + And I should see "Mapping created." And I should see "/needs/canonicalizing" + And I should see "http://gov.uk/organisations/bis" Scenario: I don't have access Given I have logged in as a member of another organisation diff --git a/features/mapping_edit.feature b/features/mapping_edit.feature index 92f79da3c..642c981b9 100644 --- a/features/mapping_edit.feature +++ b/features/mapping_edit.feature @@ -18,9 +18,9 @@ Feature: Edit a site's mapping Then I should see redirect fields But I should not see archive fields When I save the mapping - Then I should be returned to the mappings list for bis + Then I should be returned to the edit mapping page with a success message And I should see "Mapping saved" - And I should see "https://gov.uk/new-url" + And I should be editing the mapping for "/about" @javascript Scenario: Editing a site mapping that is an archive diff --git a/features/step_definitions/mappings_assertion_steps.rb b/features/step_definitions/mappings_assertion_steps.rb index 42f2f846a..83f569b45 100644 --- a/features/step_definitions/mappings_assertion_steps.rb +++ b/features/step_definitions/mappings_assertion_steps.rb @@ -6,6 +6,15 @@ step 'I should see "Edit mapping"' end +Then(/^I should be editing the mapping for "([^"]*)"$/) do |path| + expect(page).to have_selector("form a[href*='#{path}']") +end + +Then(/^I should be returned to the edit mapping page with a success message$/) do + step 'I should see "Edit mapping"' + page.should satisfy {|page| page.has_content?('Mapping created') or page.has_content?('Mapping saved')} +end + Then(/^the filter box should contain "([^"]*)"$/) do |path| expect(page).to have_field('Filter by path', with: path) end