Skip to content

Commit

Permalink
Update publishing api
Browse files Browse the repository at this point in the history
  • Loading branch information
syed-ali-tw committed Jul 7, 2024
1 parent 0d3c359 commit 4c0511a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/controllers/homepage_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/models/edition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/models/popular_links_edition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions app/services/edition_presenter_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def presenter_class(edition_class)
"Formats::SimpleSmartAnswerPresenter"
when "TransactionEdition"
"Formats::TransactionPresenter"
when "PopularLinksEdition"
"Formats::PopularLinksPresenter"
else
"Formats::GenericEditionPresenter"
end
Expand Down
19 changes: 19 additions & 0 deletions test/functional/homepage_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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" },
Expand Down
5 changes: 5 additions & 0 deletions test/unit/services/edition_presenter_factory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4c0511a

Please sign in to comment.