File tree Expand file tree Collapse file tree 3 files changed +55
-6
lines changed
spec/views/components/pages Expand file tree Collapse file tree 3 files changed +55
-6
lines changed Original file line number Diff line number Diff line change 4
4
<%= render Pages ::Header . new (
5
5
title : current_page . data . title! ,
6
6
description : current_page . data . description ,
7
- published_on : current_page . data . published &.to_date
7
+ published_on : current_page . data . published &.to_date ,
8
+ updated_on : current_page . data . updated &.to_date
8
9
) %>
9
10
<%- if current_page . data . toc -%>
10
11
< aside >
Original file line number Diff line number Diff line change @@ -4,10 +4,11 @@ class Pages::Header < ApplicationComponent
4
4
5
5
attr_accessor :current_page
6
6
7
- def initialize ( title : nil , description : nil , published_on : nil )
7
+ def initialize ( title : nil , description : nil , published_on : nil , updated_on : nil )
8
8
@title = title
9
9
@description = description
10
10
@published_on = published_on
11
+ @updated_on = updated_on
11
12
end
12
13
13
14
def view_template
@@ -19,11 +20,27 @@ def view_template
19
20
h1 { @title }
20
21
end
21
22
p ( class : "description" ) { @description } if @description
22
- if @published_on
23
+ if @published_on || @updated_on
23
24
span ( class : "block" ) do
24
- # <time datetime="2024-03-13T00:00:00Z" itemprop="datePublished" class="dt-published"> March 13th, 2024 </time>
25
- em do
26
- time_tag @published_on , itemprop : "datePublished" , class : "dt-published"
25
+ if @published_on && @updated_on
26
+ plain "Published:"
27
+ whitespace
28
+ end
29
+ if @published_on
30
+ em do
31
+ time_tag @published_on , itemprop : "datePublished" , class : "dt-published"
32
+ end
33
+ end
34
+ if @updated_on
35
+ if @published_on
36
+ plain " // "
37
+ end
38
+ plain "Updated:"
39
+ whitespace
40
+
41
+ em do
42
+ time_tag @updated_on , itemprop : "dateModified" , class : "dt-modified"
43
+ end
27
44
end
28
45
end
29
46
end
Original file line number Diff line number Diff line change
1
+ require "rails_helper"
2
+
3
+ RSpec . describe Pages ::Header , type : :view do
4
+ def render ( **kwargs )
5
+ described_class . new ( **kwargs ) . call ( view_context : view )
6
+ end
7
+
8
+ describe "#call" do
9
+ it "renders the header" do
10
+ expect ( render ( title : "Hello" ) ) . to have_css ( ".page-header h1" , text : "Hello" )
11
+ end
12
+
13
+ it "renders the description" do
14
+ expect ( render ( description : "Describe me" ) ) . to have_css ( ".page-header p" , text : "Describe me" )
15
+ end
16
+
17
+ it "renders the published date" do
18
+ expect ( render ( published_on : Date . today ) ) . to have_css ( "time.dt-published" , text : Date . today . to_fs ( :long ) )
19
+ end
20
+
21
+ it "renders the updated date" do
22
+ expect ( render ( updated_on : Date . today ) ) . to have_css ( "time.dt-modified" , text : Date . today . to_fs ( :long ) )
23
+ end
24
+
25
+ it "renders the published and updated date" do
26
+ rendered = render ( published_on : Date . yesterday , updated_on : Date . today )
27
+ expect ( rendered ) . to have_css ( "time.dt-published" , text : Date . yesterday . to_fs ( :long ) )
28
+ expect ( rendered ) . to have_css ( "time.dt-modified" , text : Date . today . to_fs ( :long ) )
29
+ end
30
+ end
31
+ end
You can’t perform that action at this time.
0 commit comments