rails-timeago 2.18.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,210 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Rails::Timeago::Helper do
6
- before { @stub = TimeagoStub.new }
7
- let(:time) { Time.now }
8
-
9
- context '#timeago_tag' do
10
- let(:kwargs) { {} }
11
- subject { @stub.timeago_tag(time, **kwargs) }
12
-
13
- it 'creates a time tag' do
14
- is_expected.to match %r{<time.*>.*</time>}
15
- end
16
-
17
- it 'has a title attribute' do
18
- is_expected.to match %r{<time.*title=".*".*>.*</time>}
19
- end
20
-
21
- it 'has a human readable datetime as title attribute' do
22
- is_expected.to include "title=\"#{I18n.l time}\""
23
- end
24
-
25
- it 'has a data-time-ago attribute' do
26
- is_expected.to match %r{<time.*data-time-ago=".*".*>.*</time>}
27
- end
28
-
29
- context 'with nil as timestamp' do
30
- let(:time) { nil }
31
- it 'returns default string' do
32
- is_expected.to eq '-'
33
- end
34
- end
35
-
36
- describe 'format parameter' do
37
- let(:kwargs) { {format: format} }
38
-
39
- context 'with symbolic format' do
40
- let(:format) { :short }
41
- it { is_expected.to include "title=\"#{I18n.l time, format: :short}\"" }
42
- end
43
-
44
- context 'with proc format' do
45
- let(:format) { proc {|_time, _options| :long } }
46
- it { is_expected.to include "title=\"#{I18n.l time, format: :long}\"" }
47
- end
48
- end
49
-
50
- describe 'format global configuration' do
51
- before { Rails::Timeago.default_options format: format }
52
-
53
- context 'with symbolic format' do
54
- let(:format) { :short }
55
- it { is_expected.to include "title=\"#{I18n.l time, format: :short}\"" }
56
- end
57
-
58
- context 'with proc format' do
59
- let(:format) { proc {|_time, _options| :long } }
60
- it { is_expected.to include "title=\"#{I18n.l time, format: :long}\"" }
61
- end
62
- end
63
-
64
- describe 'title parameter' do
65
- let(:kwargs) { {title: title} }
66
-
67
- context 'with title disable' do
68
- let(:title) { false }
69
- it { is_expected.to_not match %r{<time.*title=".*".*>.*</time>} }
70
- end
71
-
72
- context 'with title set to nil' do
73
- let(:title) { nil }
74
- it { is_expected.to_not match %r{<time.*title=".*".*>.*</time>} }
75
- end
76
-
77
- context 'with title set to proc' do
78
- let(:title) { proc {|_, o| o[:format] } }
79
- let(:kwargs) { super().merge format: :short }
80
- it { is_expected.to match %r{<time.*title="short".*>.*</time>} }
81
- end
82
- end
83
-
84
- describe 'title global configuration' do
85
- before { Rails::Timeago.default_options title: title }
86
-
87
- context 'with title disabled' do
88
- let(:title) { false }
89
- it { is_expected.to_not match %r{<time.*title=".*".*>.*</time>} }
90
- end
91
-
92
- context 'with title set to nil' do
93
- let(:title) { nil }
94
- it { is_expected.to_not match %r{<time.*title=".*".*>.*</time>} }
95
- end
96
-
97
- context 'with title set to proc' do
98
- let(:title) { proc {|_, o| o[:format] } }
99
- let(:kwargs) { {format: :short} }
100
- it { is_expected.to match %r{<time.*title="short".*>.*</time>} }
101
- end
102
- end
103
-
104
- describe 'limit' do
105
- let(:time) { 5.days.ago }
106
-
107
- it 'should not have data-time-ago attribute for times before limit' do
108
- is_expected.to_not match %r{<time.*data-time-ago=".*".*>.*</time>}
109
- end
110
-
111
- context 'with given limit' do
112
- let(:kwargs) { {limit: limit} }
113
-
114
- context 'in past' do
115
- let(:limit) { 6.days.ago }
116
-
117
- context 'and past timestamp after limit' do
118
- let(:time) { 5.days.ago }
119
- it { is_expected.to match %r{<time.*data-time-ago=".*".*>.*</time>} }
120
- end
121
-
122
- context 'and past timestamp before limit' do
123
- let(:time) { 8.days.ago }
124
- it { is_expected.to_not match %r{<time.*data-time-ago=".*".*>.*</time>} }
125
-
126
- context 'when forced' do
127
- let(:kwargs) { super().merge force: true }
128
- it { is_expected.to match %r{<time.*data-time-ago=".*".*>.*</time>} }
129
- end
130
- end
131
- end
132
-
133
- context 'in future' do
134
- let(:limit) { 5.days.from_now }
135
-
136
- context 'and future timestamp after limit' do
137
- let(:time) { 7.days.from_now }
138
- it { is_expected.to_not match %r{<time.*data-time-ago=".*".*>.*</time>} }
139
- end
140
-
141
- context 'and future timestamp before limit' do
142
- let(:time) { 3.days.from_now }
143
- it { is_expected.to match %r{<time.*data-time-ago=".*".*>.*</time>} }
144
- end
145
-
146
- context 'and past timestamp' do
147
- let(:time) { 3.days.ago }
148
- it { is_expected.to_not match %r{<time.*data-time-ago=".*".*>.*</time>} }
149
- end
150
- end
151
- end
152
- end
153
-
154
- describe 'content' do
155
- let(:time) { 3.days.ago }
156
-
157
- it 'has localized date as content' do
158
- is_expected.to include ">#{I18n.l time.to_date}<"
159
- end
160
-
161
- context 'with :format option' do
162
- let(:kwargs) { {format: :short} }
163
-
164
- it 'has correctly formatted date as content' do
165
- is_expected.to include ">#{I18n.l time.to_date, format: :short}<"
166
- end
167
- end
168
-
169
- context 'with :date_only set to false' do
170
- let(:kwargs) { {date_only: false} }
171
-
172
- it 'has localized time as content' do
173
- is_expected.to include ">#{I18n.l time}<"
174
- end
175
- end
176
- end
177
-
178
- describe ':nojs set to true' do
179
- let(:time) { 3.days.ago }
180
- let(:kwargs) { {nojs: true} }
181
-
182
- it 'has time in words as content' do
183
- is_expected.to match %r{<time.*>%time_ago_in_words%</time>}
184
- end
185
-
186
- context 'with limit' do
187
- let(:kwargs) { super().merge limit: 2.days.ago }
188
- it { is_expected.to_not match %r{<time.*data-time-ago=".*".*>.*</time>} }
189
- it { is_expected.to include ">#{I18n.l time.to_date}<" }
190
- end
191
- end
192
-
193
- context 'with HTML options' do
194
- let(:kwargs) { {myattr: 'abc'} }
195
-
196
- it 'passes them to #tag_helper' do
197
- is_expected.to match %r{<time.*myattr="abc".*>.*<\/time>}
198
- end
199
- end
200
- end
201
-
202
- context '#timeago_script_tag' do
203
- subject { @stub.timeago_script_tag }
204
-
205
- it 'should return a javascript snippet to set jQuery timeago locale' do
206
- I18n.locale = 'en'
207
- is_expected.to eq '<script>jQuery.timeago.settings.lang="en";</script>'
208
- end
209
- end
210
- end