]> git.openstreetmap.org Git - rails.git/commitdiff
Colour preview box: simplified key regex
authorŠtefan Baebler <stefan.baebler@gmail.com>
Wed, 7 Mar 2018 16:46:11 +0000 (17:46 +0100)
committerŠtefan Baebler <stefan.baebler@gmail.com>
Wed, 7 Mar 2018 16:46:11 +0000 (17:46 +0100)
and slightly reduced number of tests

app/helpers/browse_helper.rb
test/helpers/browse_helper_test.rb

index 8e0c7648f62c4b530b3794e7bf986c3135478dac..8baca1deeab6b8b6fe7b691c0a0bd8abb1792b85 100644 (file)
@@ -192,7 +192,7 @@ module BrowseHelper
   end
 
   def colour_preview(key, value)
-    return nil unless (key =~ /^(|building:|ref:|roof:)colour$/ || key =~ /^(int_)?ref:colour(_(bg|tx))?$/) && !value.nil?
+    return nil unless key =~ /^(?>.+:)?colour$/ && !value.nil? # see discussion at https://github.com/openstreetmap/openstreetmap-website/pull/1779
     # does value look like a colour? ( 3 or 6 digit hex code or w3c colour name)
     w3c_colors =
       %w[aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgrey darkgreen darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray
index 0c4f2b20302e7ea1d042eb6487168233d777ad5f..4cb7c4853b03baaf977795afa8dae666c4cf60d3 100644 (file)
@@ -375,32 +375,23 @@ class BrowseHelperTest < ActionView::TestCase
     colour = colour_preview("ref:colour", "#f00")
     assert_equal "#f00", colour
 
-    colour = colour_preview("ref:colour_bg", "#fF0")
-    assert_equal "#fF0", colour
-
-    colour = colour_preview("ref:colour_tx", "#fa0")
-    assert_equal "#fa0", colour
-
     colour = colour_preview("int_ref:colour", "green")
     assert_equal "green", colour
 
-    colour = colour_preview("int_ref:colour_bg", "#00f")
-    assert_equal "#00f", colour
-
-    colour = colour_preview("int_ref:colour_tx", "WHITE")
-    assert_equal "WHITE", colour
-
     colour = colour_preview("roof:colour", "#f00")
     assert_equal "#f00", colour
 
+    colour = colour_preview("seamark:beacon_lateral:colour", "#f00")
+    assert_equal "#f00", colour
+
     # negative tests:
-    colour = colour_preview("color", "")
+    colour = colour_preview("colour", "")
     assert_nil colour
 
-    colour = colour_preview("color", "   ")
+    colour = colour_preview("colour", "   ")
     assert_nil colour
 
-    colour = colour_preview("color", nil)
+    colour = colour_preview("colour", nil)
     assert_nil colour
 
     # ignore US spelling variant