Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions app/views/stories/_story_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@
<td class="px-4 py-2 text-sm text-gray-500"><%= story.updated_at.strftime("%b %d, %Y") %></td>

<td class="px-4 py-2 text-sm text-gray-500">
<%= link_to "View",
story_path(story, no_redirect: true),
target: story.external_link? ? "_blank" : "", rel: "noopener noreferrer",
class: "btn btn-secondary-outline" %>
<% if story.external_link? %>
<%= link_to "View", story.link_target,
target: "_blank", rel: "noopener noreferrer",
class: "btn btn-secondary-outline" %>
<% if allowed_to?(:edit?, story) %>
<%= link_to "Details", story_path(story, no_redirect: true),
class: "admin-only bg-blue-100 btn btn-secondary-outline" %>
<% end %>
<% else %>
<%= link_to "View", story_path(story),
class: "btn btn-secondary-outline" %>
<% end %>
<% if allowed_to?(:edit?, story) %>
<%= link_to "Edit", edit_story_path(story),
data: {turbo_frame: "_top"},
Expand Down
40 changes: 40 additions & 0 deletions spec/requests/stories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,39 @@
expect(response.body).to include(private_story.title)
end

describe "external link handling" do
let(:turbo_headers) { { "Turbo-Frame" => "story_results" } }

let!(:external_story) do
create(:story, :published, title: "External Story", website_url: "https://example.com/article")
end

let!(:internal_story) do
create(:story, :published, title: "Internal Story", website_url: nil)
end

it "View button links to external URL for stories with website_url" do
get stories_url, params: {}, headers: turbo_headers
expect(response.body).to include('href="https://example.com/article"')
end

it "View button links to show page for stories without website_url" do
get stories_url, params: {}, headers: turbo_headers
expect(response.body).to include(%(href="#{story_path(internal_story)}"))
end

it "shows admin-only Details button for stories with external URL" do
get stories_url, params: {}, headers: turbo_headers
expect(response.body).to include(%(href="#{story_path(external_story, no_redirect: true)}"))
expect(response.body).to include("Details")
end

it "does not show Details button for stories without external URL" do
get stories_url, params: {}, headers: turbo_headers
expect(response.body).not_to include(%(href="#{story_path(internal_story, no_redirect: true)}"))
end
end

describe "sorting" do
let(:turbo_headers) { { "Turbo-Frame" => "story_results" } }

Expand Down Expand Up @@ -182,6 +215,13 @@ def titles_in_response
expect(response.body).to include(public_story.title)
expect(response.body).not_to include(private_story.title)
end

it "does not show Details button for external stories" do
external_story = create(:story, :published, title: "External Story", website_url: "https://example.com")
get stories_url, params: {}, headers: { "Turbo-Frame" => "story_results" }
expect(response.body).not_to include("Details")
expect(response.body).to include('href="https://example.com"')
end
end

describe "GET /show" do
Expand Down