@@ -51,4 +51,53 @@ class ArticleTest < ActiveSupport::TestCase
5151 assert_includes featured , articles ( :featured_article )
5252 assert_not_includes featured , articles ( :rails_performance )
5353 end
54+
55+ test "archived? returns true when archived_at is set" do
56+ article = articles ( :rails_performance )
57+ assert_not article . archived?
58+
59+ article . archive!
60+ assert article . archived?
61+ end
62+
63+ test "archive! sets archived_at" do
64+ article = articles ( :rails_performance )
65+ assert_nil article . archived_at
66+
67+ article . archive!
68+ assert_not_nil article . reload . archived_at
69+ end
70+
71+ test "unarchive! clears archived_at" do
72+ article = articles ( :rails_performance )
73+ article . update! ( archived_at : Time . current )
74+
75+ article . unarchive!
76+ assert_nil article . reload . archived_at
77+ end
78+
79+ test "archived scope returns only archived articles" do
80+ article = articles ( :rails_performance )
81+ article . update! ( archived_at : Time . current )
82+
83+ assert_includes Article . archived , article
84+ assert_not_includes Article . not_archived , article
85+ end
86+
87+ test "not_archived scope excludes archived articles" do
88+ article = articles ( :rails_performance )
89+ assert_includes Article . not_archived , article
90+
91+ article . update! ( archived_at : Time . current )
92+ assert_not_includes Article . not_archived , article
93+ end
94+
95+ test "archived_last scope puts archived articles at the end" do
96+ recent = articles ( :martians_article )
97+ older = articles ( :rails_performance )
98+ recent . update! ( archived_at : Time . current )
99+
100+ results = Article . archived_last . by_publish_date . to_a
101+ assert results . index ( older ) < results . index ( recent )
102+ end
54103end
0 commit comments