1 require "application_system_test_case"
3 class DiaryEntrySystemTest < ApplicationSystemTestCase
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)
12 test "reply to diary entry should prefill the message subject" do
13 sign_in_as(create(:user))
14 visit diary_entries_path
16 click_link "Send a message to the author"
18 assert_content "Send a new message"
19 assert_equal "Re: #{@diary_entry.title}", page.find_field("Subject").value
22 test "deleted diary entries should be hidden for regular users" do
23 @deleted_entry = create(:diary_entry, :visible => false)
25 sign_in_as(create(:user))
26 visit diary_entries_path
28 assert_no_content @deleted_entry.title
31 test "deleted diary entries should be shown to administrators for review" do
32 @deleted_entry = create(:diary_entry, :visible => false)
34 sign_in_as(create(:administrator_user))
35 visit diary_entries_path
37 assert_content @deleted_entry.title
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)
44 sign_in_as(create(:administrator_user))
45 visit diary_entries_path
47 assert_no_content @deleted_entry.title
50 test "deleted diary comments should be hidden for regular users" do
51 @deleted_comment = create(:diary_comment, :diary_entry => @diary_entry, :visible => false)
53 sign_in_as(create(:user))
54 visit diary_entry_path(@diary_entry.user, @diary_entry)
56 assert_no_content @deleted_comment.body
59 test "deleted diary comments should be shown to administrators" do
60 @deleted_comment = create(:diary_comment, :diary_entry => @diary_entry, :visible => false)
62 sign_in_as(create(:administrator_user))
63 visit diary_entry_path(@diary_entry.user, @diary_entry)
65 assert_content @deleted_comment.body
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
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"