diff --git a/app/controllers/homepage_controller.rb b/app/controllers/homepage_controller.rb index 743701685..f9c701fc4 100644 --- a/app/controllers/homepage_controller.rb +++ b/app/controllers/homepage_controller.rb @@ -17,6 +17,8 @@ def edit def update update_link_items + UpdateWorker.perform_async(@latest_popular_links.id.to_s, update_action_is_publish?) + flash[:success] = "Popular links draft saved.".html_safe redirect_to show_popular_links_path rescue StandardError @@ -51,4 +53,12 @@ def remove_leading_and_trailing_url_spaces(links) def publish_latest_popular_links @latest_popular_links.publish_popular_links end + + def update_action_is_publish? + attempted_activity == :publish + end + + def attempted_activity + Edition::ACTIONS.invert[params[:commit]] + end end diff --git a/app/models/edition.rb b/app/models/edition.rb index f58dfd2c6..e5248fb9b 100644 --- a/app/models/edition.rb +++ b/app/models/edition.rb @@ -123,7 +123,7 @@ class ResurrectionError < RuntimeError validates_with SafeHtml, unless: :popular_links_edition? validates_with LinkValidator, on: :update, unless: :archived_or_popular_links? validates_with ReviewerValidator - validates :change_note, presence: { if: :major_change } + validates :change_note, presence: { if: :major_change }, unless: :popular_links_edition? before_save do check_for_archived_artefact diff --git a/app/models/popular_links_edition.rb b/app/models/popular_links_edition.rb index bc0dd2a6a..693943c85 100644 --- a/app/models/popular_links_edition.rb +++ b/app/models/popular_links_edition.rb @@ -33,4 +33,8 @@ def create_draft_popular_links_from_last_record popular_links.save! popular_links end + + def content_id + "ad7968d0-0339-40b2-80bc-3ea1db8ef1b7".freeze + end end diff --git a/app/services/edition_presenter_factory.rb b/app/services/edition_presenter_factory.rb index 8ac040e54..0a6b1bf85 100644 --- a/app/services/edition_presenter_factory.rb +++ b/app/services/edition_presenter_factory.rb @@ -24,6 +24,8 @@ def presenter_class(edition_class) "Formats::SimpleSmartAnswerPresenter" when "TransactionEdition" "Formats::TransactionPresenter" + when "PopularLinksEdition" + "Formats::PopularLinksPresenter" else "Formats::GenericEditionPresenter" end diff --git a/test/functional/homepage_controller_test.rb b/test/functional/homepage_controller_test.rb index 75058352d..376eccb17 100644 --- a/test/functional/homepage_controller_test.rb +++ b/test/functional/homepage_controller_test.rb @@ -58,6 +58,8 @@ class HomepageControllerTest < ActionController::TestCase end should "update latest PopularLinksEdition with changed title and url" do + UpdateWorker.stubs(:perform_async) + assert_equal "title1", @popular_links.link_items[0][:title] assert_equal "https://www.url1.com", @popular_links.link_items[0][:url] @@ -76,8 +78,25 @@ class HomepageControllerTest < ActionController::TestCase assert_equal new_url, PopularLinksEdition.last.link_items[0][:url] end + should "update publishing API" do + Sidekiq::Testing.inline! do + Services.publishing_api.expects(:put_content) + + patch :update, params: { id: @popular_links.id, + "popular_links" => + { "1" => { "title" => "title", "url" => "url.com" }, + "2" => { "title" => "title2", "url" => "https://www.url2.com" }, + "3" => { "title" => "title3", "url" => "https://www.url3.com" }, + "4" => { "title" => "title4", "url" => "https://www.url4.com" }, + "5" => { "title" => "title5", "url" => "https://www.url5.com" }, + "6" => { "title" => "title6", "url" => "https://www.url6.com" } } } + end + end + should "redirect to show path on success" do + UpdateWorker.stubs(:perform_async) new_title = "title has changed" + patch :update, params: { id: @popular_links.id, "popular_links" => { "1" => { "title" => new_title, "url" => "https://www.url1.com" }, diff --git a/test/unit/services/edition_presenter_factory_test.rb b/test/unit/services/edition_presenter_factory_test.rb index 6dc0f1352..320750d7d 100644 --- a/test/unit/services/edition_presenter_factory_test.rb +++ b/test/unit/services/edition_presenter_factory_test.rb @@ -51,6 +51,11 @@ class EditionPresenterFactoryTest < ActiveSupport::TestCase assert result == "Formats::TransactionPresenter" end + should "return a presenter for PopularLinks" do + result = EditionPresenterFactory.presenter_class("PopularLinksEdition") + assert result == "Formats::PopularLinksPresenter" + end + should "return default presenter for other pages" do result = EditionPresenterFactory.presenter_class("any_other_format") assert result == "Formats::GenericEditionPresenter"