]> git.openstreetmap.org Git - rails.git/commitdiff
Use i18n for submit button for issue comments
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 12 Jun 2019 14:25:19 +0000 (16:25 +0200)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 12 Jun 2019 17:24:06 +0000 (19:24 +0200)
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.

app/views/issues/_comments.html.erb
config/locales/en.yml
test/application_system_test_case.rb
test/system/issues_test.rb

index 13f5bb1925d83c9321266df2a1722bcd718162e9..7ff0948db5e961fa53379ebea39e50c166aeb901 100644 (file)
@@ -20,6 +20,6 @@
   <%= label_tag :reassign, t(".reassign_param") %> <%= check_box_tag :reassign, true %>
   <br />
   <br />
   <%= label_tag :reassign, t(".reassign_param") %> <%= check_box_tag :reassign, true %>
   <br />
   <br />
-  <%= submit_tag "Submit" %>
+  <%= f.submit %>
   <% end %>
 </div>
   <% end %>
 </div>
index 6ff69733d12b607bbc1645c599a1ab557f96fd47..71abe1efe7a11eb7463e69f268b358e81884b3b3 100644 (file)
@@ -12,6 +12,8 @@ en:
       diary_entry:
         create: "Publish"
         update: "Update"
       diary_entry:
         create: "Publish"
         update: "Update"
+      issue_comment:
+        create: Add Comment
       message:
         create: Send
       redaction:
       message:
         create: Send
       redaction:
index 0f46ad3ec3df946d66b18cbb23b8068b94d5c9f3..60322763e133b329d8cfb4e23a018ba05b75cabb 100644 (file)
@@ -18,4 +18,10 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
       .to_return(:status => 404)
     super(*args)
   end
       .to_return(:status => 404)
     super(*args)
   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
index f2421599f9fc657f72aba5b90871623ef3f0e10c..08b1acb3460d1f7a7135d4bb0980771a2b887a15 100644 (file)
@@ -78,7 +78,7 @@ class IssuesTest < ApplicationSystemTestCase
     visit issue_path(issue)
 
     fill_in :issue_comment_body, :with => "test comment"
     visit issue_path(issue)
 
     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?("test comment")
 
     assert page.has_content?(I18n.t("issue_comments.create.comment_created"))
     assert page.has_content?("test comment")
 
@@ -95,7 +95,7 @@ class IssuesTest < ApplicationSystemTestCase
 
     fill_in :issue_comment_body, :with => "reassigning to moderators"
     check :reassign
 
     fill_in :issue_comment_body, :with => "reassigning to moderators"
     check :reassign
-    click_on "Submit"
+    click_on "Add Comment"
 
     issue.reload
     assert_equal "moderator", issue.assigned_role
 
     issue.reload
     assert_equal "moderator", issue.assigned_role