Feat: #3498 Display episode's published_at (#4272)

* feat: #3498 Display episode's published_at

* feat: #3498 Move methods to decorator

* feat: #3498 Add check if published_at present

* feat: #3498 Add testcase for showing published_at

* Fix build failure #3498

https://travis-ci.com/thepracticaldev/dev.to/builds/130734935

* feat: #3498 Fix testcase failed on Travis 130738295

* feat: #3498 Address comments on PR #4272

* feat: #3498 Delete unused

* feat: #3498 Refactor the use of decorate
This commit is contained in:
Duc Nguyen 2019-10-09 04:06:46 +07:00 committed by Ben Halpern
parent 14796a9b84
commit 2ebe70039a
10 changed files with 61 additions and 36 deletions

View file

@ -65,8 +65,7 @@
@media screen and ( min-width: 680px ){
font-size:40px;
line-height:44px;
margin-bottom:48px;
margin-bottom:28px;
}
@media screen and ( min-width: 800px ){
font-size:44px;
@ -82,8 +81,7 @@
@media screen and ( min-width: 680px ){
font-size:30px;
line-height:33px;
margin-bottom:40px;
margin-bottom:20px;
}
@media screen and ( min-width: 800px ){
font-size:40px;

View file

@ -6,9 +6,9 @@ class PodcastEpisodesController < ApplicationController
@podcast_index = true
@podcasts = Podcast.available.order("title asc")
@podcast_episodes = PodcastEpisode.
@podcast_episodes = PodcastEpisodeDecorator.decorate_collection(PodcastEpisode.
available.
includes(:podcast).order("published_at desc").first(20)
includes(:podcast).order("published_at desc").first(20))
if params[:q].blank?
surrogate_keys = ["podcast_episodes_all"] + @podcast_episodes.map(&:record_key)

View file

@ -141,7 +141,8 @@ class StoriesController < ApplicationController
@podcast_index = true
@article_index = true
@list_of = "podcast-episodes"
@podcast_episodes = @podcast.podcast_episodes.reachable.order("published_at DESC").limit(30)
@podcast_episodes = @podcast.podcast_episodes.
reachable.order("published_at DESC").limit(30).decorate
set_surrogate_key_header "podcast_episodes"
render template: "podcast_episodes/index"
end
@ -182,6 +183,7 @@ class StoriesController < ApplicationController
def handle_podcast_show
set_surrogate_key_header @episode.record_key
@episode = @episode.decorate
@podcast_episode_show = true
@comments_to_show_count = 25
@comment = Comment.new

View file

@ -8,4 +8,18 @@ class PodcastEpisodeDecorator < ApplicationDecorator
def cached_tag_list_array
(tag_list || "").split(", ")
end
def readable_publish_date
return unless published_at
if published_at.year == Time.current.year
published_at.strftime("%b %e")
else
published_at.strftime("%b %e '%y")
end
end
def published_timestamp
published_at&.utc&.iso8601
end
end

View file

@ -1,24 +0,0 @@
<% @podcast_episodes.each_with_index do |episode, i| %>
<a href="<%= episode.path %>" class="small-pic-link-wrapper" id="article-link-<%= episode.id %>">
<div class="single-article single-article-small-pic single-article-single-podcast">
<div class="small-pic">
<%= cl_image_tag(episode.image_url || episode.podcast.image_url,
type: "fetch",
crop: "imagga_scale",
width: 240,
height: 240,
quality: "auto",
flags: "progressive",
fetch_format: "auto",
sign_url: true,
alt: episode.title) %>
</div>
<div class="content">
<h3><span class="tag-identifier">podcast</span><%= episode.title %></h3>
</div>
<h4>
<%= episode.podcast.title %>
</h4>
</div>
</a>
<% end %>

View file

@ -19,6 +19,12 @@
<h4>
<a href="/<%= episode.podcast.slug %>">
<%= episode.podcast.title %>
<% if episode.published_at? %>
・<time class="published-at" datetime="<%= episode.published_timestamp %>">
<%= episode.readable_publish_date %>
</time>
<span class="time-ago-indicator-initial-placeholder" data-seconds="<%= episode.published_at_int %>"></span>
<% end %>
</a>
</h4>
</div>

View file

@ -50,6 +50,11 @@
<% else %>
<h1><%= @episode.title %></h1>
<% end %>
<% if @episode.published_at? %>
<time class="published-at" datetime="<%= @episode.published_timestamp %>">
<%= @episode.readable_publish_date %>
</time>
<% end %>
</div>
<div id="record-<%= @episode.slug %>" class="record-wrapper" data-podcast="<%= @podcast.slug %>" data-episode="<%= @episode.slug %>">
<div class="record" id="record">

View file

@ -8,6 +8,7 @@ RSpec.describe "User visits podcast show page", type: :system do
visit podcast_episode.path.to_s
expect(page).to have_text(podcast_episode.title)
expect(page).to have_css ".record"
expect(page).not_to have_css ".published-at"
end
it "see the new comment box on the page" do
@ -38,6 +39,15 @@ RSpec.describe "User visits podcast show page", type: :system do
end
end
context "when podcast has publish_at field" do
let!(:podcast_episode) { create(:podcast_episode, podcast_id: podcast.id, published_at: 7.hours.ago) }
it "sees published at" do
visit podcast_episode.path.to_s
expect(page).to have_css ".published-at"
end
end
context "when there're existing comments" do
let(:user) { create(:user) }
let(:comment) { create(:comment, user_id: user.id, commentable: podcast_episode) }

View file

@ -2,7 +2,7 @@ require "rails_helper"
RSpec.describe "User visits a podcast page", type: :system do
let(:podcast) { create(:podcast) }
let!(:podcast_episode) { create(:podcast_episode, podcast_id: podcast.id) }
let!(:podcast_episode1) { create(:podcast_episode, podcast_id: podcast.id, published_at: 2.hours.ago) }
let!(:podcast_episode2) { create(:podcast_episode, podcast_id: podcast.id) }
let(:another_episode) { create(:podcast_episode, podcast: create(:podcast)) }
let(:user) { create(:user) }
@ -19,8 +19,13 @@ RSpec.describe "User visits a podcast page", type: :system do
expect(page).to have_selector("div.single-article", visible: true, count: 2)
end
it "displays podcast publish_at" do
expect(page).to have_selector("time.published-at", count: 1)
expect(page).to have_selector("span.time-ago-indicator-initial-placeholder", count: 1)
end
it "displays correct episodes" do
expect(page).to have_link(nil, href: podcast_episode.path)
expect(page).to have_link(nil, href: podcast_episode1.path)
expect(page).to have_link(nil, href: podcast_episode2.path)
expect(page).not_to have_link(nil, href: another_episode.path)
end

View file

@ -1,8 +1,9 @@
require "rails_helper"
RSpec.describe "User visits /pod page", type: :system do
let!(:podcast_episode) { create(:podcast_episode) }
let!(:podcast_episode2) { create(:podcast_episode) }
let!(:podcast_episode1) { create(:podcast_episode, published_at: 7.hours.ago) }
let!(:podcast_episode2) { create(:podcast_episode, published_at: 7.days.ago) }
let!(:podcast_episode3) { create(:podcast_episode) }
let(:podcast) { create(:podcast, reachable: true, published: false) }
let(:unpublished_podcast) { create(:podcast, reachable: false) }
let!(:un_podcast_episode) { create(:podcast_episode, podcast: podcast, reachable: false) }
@ -12,8 +13,16 @@ RSpec.describe "User visits /pod page", type: :system do
it "displays the podcasts" do
within "#articles-list" do
expect(page).to have_link(nil, href: podcast_episode.path)
expect(page).to have_link(nil, href: podcast_episode1.path)
expect(page).to have_link(nil, href: podcast_episode2.path)
expect(page).to have_link(nil, href: podcast_episode3.path)
end
end
it "displays the podcasts with published_at" do
within "#articles-list" do
expect(page).to have_selector("time.published-at", count: 2)
expect(page).to have_selector("span.time-ago-indicator-initial-placeholder", count: 2)
end
end