]> git.openstreetmap.org Git - rails.git/blob - test/system/diary_entry_test.rb
Merge remote-tracking branch 'upstream/pull/5201'
[rails.git] / test / system / diary_entry_test.rb
1 require "application_system_test_case"
2
3 class DiaryEntrySystemTest < ApplicationSystemTestCase
4   def setup
5     create(:language, :code => "en")
6     create(:language, :code => "pt", :english_name => "Portuguese", :native_name => "Português")
7     create(:language, :code => "pt-BR", :english_name => "Brazilian Portuguese", :native_name => "Português do Brasil")
8     create(:language, :code => "ru", :english_name => "Russian", :native_name => "Русский")
9     @diary_entry = create(:diary_entry)
10   end
11
12   test "reply to diary entry should prefill the message subject" do
13     sign_in_as(create(:user))
14     visit diary_entries_path
15
16     click_on "Send a message to the author"
17
18     assert_content "Send a new message"
19     assert_equal "Re: #{@diary_entry.title}", page.find_field("Subject").value
20   end
21
22   test "deleted diary entries should be hidden for regular users" do
23     @deleted_entry = create(:diary_entry, :visible => false)
24
25     sign_in_as(create(:user))
26     visit diary_entries_path
27
28     assert_no_content @deleted_entry.title
29   end
30
31   test "deleted diary entries should be shown to administrators for review" do
32     @deleted_entry = create(:diary_entry, :visible => false)
33
34     sign_in_as(create(:administrator_user))
35     visit diary_entries_path
36
37     assert_content @deleted_entry.title
38   end
39
40   test "deleted diary entries should not be shown to admins when the user is also deleted" do
41     @deleted_user = create(:user, :deleted)
42     @deleted_entry = create(:diary_entry, :visible => false, :user => @deleted_user)
43
44     sign_in_as(create(:administrator_user))
45     visit diary_entries_path
46
47     assert_no_content @deleted_entry.title
48   end
49
50   test "deleted diary comments should be hidden for regular users" do
51     @deleted_comment = create(:diary_comment, :diary_entry => @diary_entry, :visible => false)
52
53     sign_in_as(create(:user))
54     visit diary_entry_path(@diary_entry.user, @diary_entry)
55
56     assert_no_content @deleted_comment.body
57   end
58
59   test "deleted diary comments should be shown to administrators" do
60     @deleted_comment = create(:diary_comment, :diary_entry => @diary_entry, :visible => false)
61
62     sign_in_as(create(:administrator_user))
63     visit diary_entry_path(@diary_entry.user, @diary_entry)
64
65     assert_content @deleted_comment.body
66   end
67
68   test "should have links to preferred languages" do
69     sign_in_as(create(:user, :languages => %w[en-US pt-BR]))
70     visit diary_entries_path
71
72     assert_link "Diary Entries in English", :href => "/diary/en"
73     assert_link "Diary Entries in Brazilian Portuguese", :href => "/diary/pt-BR"
74     assert_link "Diary Entries in Portuguese", :href => "/diary/pt"
75     assert_no_link "Diary Entries in Russian"
76   end
77
78   test "should have new diary entry link on own diary entry page" do
79     user = create(:user)
80     diary_entry = create(:diary_entry, :user => user)
81
82     sign_in_as(user)
83     visit diary_entry_path(diary_entry.user, diary_entry)
84
85     within_content_heading do
86       assert_link "New Diary Entry"
87     end
88   end
89
90   test "should not have new diary entry link on other user's diary entry page" do
91     user = create(:user)
92     diary_entry = create(:diary_entry)
93
94     sign_in_as(user)
95     visit diary_entry_path(diary_entry.user, diary_entry)
96
97     within_content_heading do
98       assert_no_link "New Diary Entry"
99     end
100   end
101
102   test "should not be hidden on the list page" do
103     body = SecureRandom.alphanumeric(1998)
104     create(:diary_entry, :body => body)
105
106     visit diary_entries_path
107
108     assert_content body
109     assert_no_content I18n.t("diary_entries.diary_entry.full_entry")
110   end
111
112   test "should be hidden on the list page" do
113     body = SecureRandom.alphanumeric(2000)
114     create(:diary_entry, :body => body)
115
116     visit diary_entries_path
117
118     assert_no_content body
119     assert_content I18n.t("diary_entries.diary_entry.full_entry")
120   end
121
122   test "should be partially hidden on the list page" do
123     text1 = "a" * 500
124     text2 = "b" * 500
125     text3 = "c" * 999
126     text4 = "dd"
127     text5 = "ff"
128
129     body = "<p>#{text1}</p><div><p>#{text2}</p><p>#{text3}<a href='#'>#{text4}</a></p></div><p>#{text5}</p>"
130     create(:diary_entry, :body => body)
131
132     visit diary_entries_path
133
134     assert_content text1
135     assert_content text2
136     assert_no_content text3
137     assert_no_content text4
138     assert_no_content text5
139     assert_content I18n.t("diary_entries.diary_entry.full_entry")
140   end
141
142   test "should not be hidden on the show page" do
143     body = SecureRandom.alphanumeric(2001)
144     diary_entry = create(:diary_entry, :body => body)
145
146     visit diary_entry_path(diary_entry.user, diary_entry)
147
148     assert_content body
149     assert_no_content I18n.t("diary_entries.diary_entry.full_entry")
150   end
151 end