Allow space as a language separator
authorTom Hughes <tom@compton.nu>
Tue, 31 Mar 2015 19:48:31 +0000 (20:48 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 31 Mar 2015 19:53:51 +0000 (20:53 +0100)
The separator is supposed to be comma, so technically having
space instead is user error, but it seems to be very common.

Fixes #942

app/models/user.rb
test/fixtures/users.yml
test/models/user_test.rb

index d8c5153b1053e1ccaa42e06e851d8b51888d3d65..2ac94b65bc2de0019fecbf645ad87f37f758a488 100644 (file)
@@ -120,7 +120,7 @@ class User < ActiveRecord::Base
   end
 
   def languages
-    attribute_present?(:languages) ? self[:languages].split(/ *, */) : []
+    attribute_present?(:languages) ? self[:languages].split(/ *[, ] */) : []
   end
 
   def languages=(languages)
index 2055faa13522a822647383afb3d0eddbac744880..32a4e03873e1511b95a8ba7e1beaedcd727c60ce 100644 (file)
@@ -30,7 +30,7 @@ public_user:
   home_zoom: 12
   terms_agreed: "2010-01-01 11:22:33"
   terms_seen: true
-  languages: en
+  languages: "en de"
   creation_ip: "4.5.6.7"
 
 inactive_user:
index 59445aee451e6382fb12f4bf18cb419c81ce0b7f..b5a9f45ff3d01a6b786118d1026be2300cc99d8c 100644 (file)
@@ -200,6 +200,8 @@ class UserTest < ActiveSupport::TestCase
     user.languages = %w(fr de sl)
     assert_equal "de", user.preferred_language
     assert_equal "de", user.preferred_language_from(%w(en sl de es))
+    user = users(:public_user)
+    assert_equal %w(en de), user.languages
   end
 
   def test_visible?