Fixing tests

This commit is contained in:
2023-03-06 21:44:10 +11:00
parent fd3cf2dba1
commit 1ea4224fb5
4 changed files with 34 additions and 19 deletions

View File

@@ -4,15 +4,15 @@ div class="h-card prose dark:prose-invert mb-12 prose-a:decoration-wavy hover:pr
div class="mb-8 max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600" div class="mb-8 max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"
div class="mb-2 flex max-w-prose mx-auto" - if latest_status
p Latest status div class="mb-2 flex max-w-prose mx-auto"
div class="mb-12 p-2 grid grid-cols-7 gap-4 min-h-16 max-w-prose mx-auto bg-fuchsia-100 dark:bg-fuchsia-800 dark:text-gray-200 rounded" p Latest status
div class="col-span-4 sm:col-span-6 text-left" div class="mb-12 p-2 grid grid-cols-7 gap-4 min-h-16 max-w-prose mx-auto bg-fuchsia-100 dark:bg-fuchsia-800 dark:text-gray-200 rounded"
a class="block my-auto hover:underline decoration-wavy" href=latest_status.permalink div class="col-span-4 sm:col-span-6 text-left"
== "#{latest_status.content}" a class="block my-auto hover:underline decoration-wavy" href=latest_status.permalink
a class="col-span-3 sm:col-span-1 px-2 text-center transition-colors rounded bg-fuchsia-50 hover:bg-fuchsia-200 dark:bg-fuchsia-900 dark:hover:bg-fuchsia-700 inline-block grid content-center max-h-12 my-auto" href="/statuses" == latest_status.content
p See all a class="col-span-3 sm:col-span-1 px-2 text-center transition-colors rounded bg-fuchsia-50 hover:bg-fuchsia-200 dark:bg-fuchsia-900 dark:hover:bg-fuchsia-700 inline-block grid content-center max-h-12 my-auto" href="/statuses"
p See all
div class="mb-4 flex max-w-prose mx-auto" div class="mb-4 flex max-w-prose mx-auto"
h2 class="text-l text-gray-600 dark:text-gray-200" Posts h2 class="text-l text-gray-600 dark:text-gray-200" Posts
@@ -30,9 +30,10 @@ div class="grid grid-cols-3 gap-4 max-w-prose mx-auto"
- photo_posts.each do |post| - photo_posts.each do |post|
== render :photo_post, post: post == render :photo_post, post: post
div class="mb-12 mt-6 max-w-prose mx-auto text-gray-600 dark:text-gray-200 rounded p-2 bg-blue-50 dark:bg-blue-900/60" - if last_location
div div class="mb-12 mt-6 max-w-prose mx-auto text-gray-600 dark:text-gray-200 rounded p-2 bg-blue-50 dark:bg-blue-900/60"
= "🗺️ Last seen at " div
a class="text-blue-400 hover:text-blue-600" href=last_location.permalink = "🗺️ Last seen at "
= last_location.display_title a class="text-blue-400 hover:text-blue-600" href=last_location.permalink
= last_location.display_title
div class="max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600" div class="max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"

View File

@@ -23,11 +23,11 @@ module Adamantium
end end
expose :latest_status do expose :latest_status do
Decorators::Posts::Decorator.new(post_repo.latest_status) post_repo.latest_status ? Decorators::Posts::Decorator.new(post_repo.latest_status) : nil
end end
expose :last_location do expose :last_location do
Decorators::Posts::Decorator.new(post_repo.last_location) post_repo.last_location ? Decorators::Posts::Decorator.new(post_repo.last_location) : nil
end end
end end
end end

View File

@@ -3,6 +3,7 @@ require "digest"
require "tempfile" require "tempfile"
require "open-uri" require "open-uri"
require "dry/monads" require "dry/monads"
require "sanitize"
module Adamantium module Adamantium
module Client module Client
@@ -18,7 +19,7 @@ module Adamantium
content = if post[:name] content = if post[:name]
"#{post[:name]}#{settings.micropub_site_url}/post/#{post[:slug]}" "#{post[:name]}#{settings.micropub_site_url}/post/#{post[:slug]}"
else else
post[:content] sanitze_post(post[:content])
end end
tags = post[:category].map { |tag| "##{tag}" }.join(" ") tags = post[:category].map { |tag| "##{tag}" }.join(" ")
@@ -74,6 +75,19 @@ module Adamantium
JSON.parse(response.body, symbolize_names: true).fetch(:id, nil) JSON.parse(response.body, symbolize_names: true).fetch(:id, nil)
end end
private
def sanitze_post(content)
replace_links = lambda { |env|
return unless env[:node_name] == "a"
node = env[:node]
url = node[:href]
env[:node].replace(url)
}
Sanitize.fragment(content, transformers: [replace_links]).strip
end
end end
end end
end end

View File

@@ -38,8 +38,8 @@ RSpec.describe "Post creation", :db, :requests do
post "/micropub", params post "/micropub", params
expect(last_response).to be_successful expect(last_response).to be_successful
expect(post_repo.post_listing.count).to eq 1 expect(post_repo.statuses_listing.count).to eq 1
expect(post_repo.post_listing.first.tags.map(&:label)).to eq ["ruby", "rspec"] expect(post_repo.statuses_listing.first.tags.map(&:label)).to eq ["ruby", "rspec"]
end end
end end