File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,3 +14,26 @@ inactive:
1414 label : test link
1515 link : https://example.com
1616 active : false
17+
18+ timed_past :
19+ community : sample
20+ label : link in the past
21+ link : https://example.com
22+ active : true
23+ shown_before : 2019-01-01T00:00:00.000000Z
24+
25+ timed_present :
26+ community : sample
27+ label : link in the present
28+ link : https://example.com
29+ active : true
30+ shown_after : 2019-01-01T00:00:00.000000Z
31+ shown_before : <%= DateTime.now + 1 %>
32+
33+ timed_future :
34+ community : sample
35+ label : link in the future
36+ link : https://example.com
37+ active : true
38+ shown_after : <%= DateTime.now + 1 %>
39+ shown_before : <%= DateTime.now + 1 %>
Original file line number Diff line number Diff line change 11require 'test_helper'
22
33class PinnedLinkTest < ActiveSupport ::TestCase
4- # test "the truth" do
5- # assert true
6- # end
4+ test ':timed scope should only return time-constrained links' do
5+ timed = PinnedLink . timed
6+
7+ assert timed . any?
8+
9+ timed . each do |link |
10+ assert link . timed? , "link \" #{ link . label } \" is not timed"
11+ end
12+ end
13+
14+ test ':present scope should return non-timed or current links' do
15+ now = DateTime . now
16+ present = PinnedLink . present
17+
18+ assert present . any?
19+
20+ present . each do |link |
21+ assert !link . timed? || ( link . shown_before > now && link . shown_after <= now )
22+ end
23+ end
24+
25+ test ':past scope should only return past links' do
26+ now = DateTime . now
27+ past = PinnedLink . past
28+
29+ assert past . any?
30+
31+ past . each do |link |
32+ assert link . timed? && link . shown_before < now
33+ end
34+ end
35+
36+ test ':future scope should only return future links' do
37+ now = DateTime . now
38+ future = PinnedLink . future
39+
40+ assert future . any?
41+
42+ future . each do |link |
43+ assert link . timed? && link . shown_before > now && link . shown_after > now
44+ end
45+ end
746end
You can’t perform that action at this time.
0 commit comments