|
71 | 71 | end |
72 | 72 |
|
73 | 73 | describe '.user_replied' do |
| 74 | + let(:response_by_user) { Fabricate(:user, name: "John Doe") } |
74 | 75 | let(:category) { Fabricate(:category, name: 'India') } |
75 | 76 | let(:topic) { Fabricate(:topic, category: category) } |
76 | 77 | let(:post) { Fabricate(:post, topic: topic) } |
77 | | - let(:response) { Fabricate(:post, topic: post.topic)} |
| 78 | + let(:response) { Fabricate(:post, topic: post.topic, user: response_by_user)} |
78 | 79 | let(:user) { Fabricate(:user) } |
79 | 80 | let(:notification) { Fabricate(:notification, user: user) } |
80 | 81 |
|
81 | 82 | it 'generates a correct email' do |
| 83 | + SiteSetting.stubs(:enable_names).returns(true) |
82 | 84 | mail = UserNotifications.user_replied(response.user, post: response, notification: notification) |
83 | 85 |
|
| 86 | + # from should include full user name |
| 87 | + expect(mail[:from].display_names).to eql(['John Doe']) |
| 88 | + |
84 | 89 | # subject should include category name |
85 | 90 | expect(mail.subject).to match(/India/) |
86 | 91 |
|
|
109 | 114 | end |
110 | 115 |
|
111 | 116 | describe '.user_posted' do |
| 117 | + let(:response_by_user) { Fabricate(:user, name: "John Doe") } |
112 | 118 | let(:post) { Fabricate(:post) } |
113 | | - let(:response) { Fabricate(:post, topic: post.topic)} |
| 119 | + let(:response) { Fabricate(:post, topic: post.topic, user: response_by_user)} |
114 | 120 | let(:user) { Fabricate(:user) } |
115 | 121 | let(:notification) { Fabricate(:notification, user: user) } |
116 | 122 |
|
117 | 123 | it 'generates a correct email' do |
| 124 | + SiteSetting.stubs(:enable_names).returns(false) |
118 | 125 | mail = UserNotifications.user_posted(response.user, post: response, notification: notification) |
119 | 126 |
|
| 127 | + # from should not include full user name if "show user full names" is disabled |
| 128 | + expect(mail[:from].display_names).to_not eql(['John Doe']) |
| 129 | + |
120 | 130 | # subject should not include category name |
121 | 131 | expect(mail.subject).not_to match(/Uncategorized/) |
122 | 132 |
|
|
133 | 143 | end |
134 | 144 |
|
135 | 145 | describe '.user_private_message' do |
| 146 | + let(:response_by_user) { Fabricate(:user, name: "John Doe") } |
136 | 147 | let(:topic) { Fabricate(:private_message_topic) } |
137 | | - let(:response) { Fabricate(:post, topic: topic)} |
| 148 | + let(:response) { Fabricate(:post, topic: topic, user: response_by_user)} |
138 | 149 | let(:user) { Fabricate(:user) } |
139 | 150 | let(:notification) { Fabricate(:notification, user: user) } |
140 | 151 |
|
141 | 152 | it 'generates a correct email' do |
| 153 | + SiteSetting.stubs(:enable_names).returns(true) |
142 | 154 | mail = UserNotifications.user_private_message(response.user, post: response, notification: notification) |
143 | 155 |
|
| 156 | + # from should include full user name |
| 157 | + expect(mail[:from].display_names).to eql(['John Doe']) |
| 158 | + |
144 | 159 | # subject should include "[PM]" |
145 | 160 | expect(mail.subject).to match("[PM]") |
146 | 161 |
|
@@ -224,7 +239,8 @@ def expects_build_with(condition) |
224 | 239 | end |
225 | 240 |
|
226 | 241 | it "has a from alias" do |
227 | | - expects_build_with(has_entry(:from_alias, "#{username}")) |
| 242 | + SiteSetting.stubs(:enable_names).returns(true) |
| 243 | + expects_build_with(has_entry(:from_alias, "#{user.name}")) |
228 | 244 | end |
229 | 245 |
|
230 | 246 | it "should explain how to respond" do |
|
0 commit comments