Use i18n for submit button for issue comments

Normally when an en-GB.yml translation is missing, rails falls back to en.yml. But when
using the submit helpers, if the en-GB translation is missing, rails knows how to create
a fallback like 'Create {model_name}' without touching the en.yml file. This string might
then be different from what the test expects, e.g. 'Add Comment'.

So it's important to set the language headers, to avoid phantomjs from picking up your desktop
preferences in this specific case.
This commit is contained in:
Andy Allan 2019-06-12 16:25:19 +02:00
parent 5450bade1a
commit 085412f624
4 changed files with 11 additions and 3 deletions

View file

@ -20,6 +20,6 @@
<%= label_tag :reassign, t(".reassign_param") %> <%= check_box_tag :reassign, true %> <%= label_tag :reassign, t(".reassign_param") %> <%= check_box_tag :reassign, true %>
<br /> <br />
<br /> <br />
<%= submit_tag "Submit" %> <%= f.submit %>
<% end %> <% end %>
</div> </div>

View file

@ -12,6 +12,8 @@ en:
diary_entry: diary_entry:
create: "Publish" create: "Publish"
update: "Update" update: "Update"
issue_comment:
create: Add Comment
message: message:
create: Send create: Send
redaction: redaction:

View file

@ -18,4 +18,10 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
.to_return(:status => 404) .to_return(:status => 404)
super(*args) super(*args)
end end
# Phantomjs can pick up browser Accept-Language preferences from your desktop environment.
# We don't want this to happen during the tests!
setup do
page.driver.add_headers("Accept-Language" => "en")
end
end end

View file

@ -78,7 +78,7 @@ class IssuesTest < ApplicationSystemTestCase
visit issue_path(issue) visit issue_path(issue)
fill_in :issue_comment_body, :with => "test comment" fill_in :issue_comment_body, :with => "test comment"
click_on "Submit" click_on "Add Comment"
assert page.has_content?(I18n.t("issue_comments.create.comment_created")) assert page.has_content?(I18n.t("issue_comments.create.comment_created"))
assert page.has_content?("test comment") assert page.has_content?("test comment")
@ -95,7 +95,7 @@ class IssuesTest < ApplicationSystemTestCase
fill_in :issue_comment_body, :with => "reassigning to moderators" fill_in :issue_comment_body, :with => "reassigning to moderators"
check :reassign check :reassign
click_on "Submit" click_on "Add Comment"
issue.reload issue.reload
assert_equal "moderator", issue.assigned_role assert_equal "moderator", issue.assigned_role