[Groonga-commit] ranguba/chupa-text at 5ddf965 [master] Fix a bug that ContentTypeRegistry normalizes valid extension name to nil

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Jan 3 18:48:39 JST 2014


Kouhei Sutou	2014-01-03 18:48:39 +0900 (Fri, 03 Jan 2014)

  New Revision: 5ddf9654f0d1a0d01df56378bb0409636039e296
  https://github.com/ranguba/chupa-text/commit/5ddf9654f0d1a0d01df56378bb0409636039e296

  Message:
    Fix a bug that ContentTypeRegistry normalizes valid extension name to nil

  Copied files:
    test/test-content-type-registry.rb
      (from lib/chupa-text/content-type-registry.rb)
  Modified files:
    lib/chupa-text/content-type-registry.rb

  Modified: lib/chupa-text/content-type-registry.rb (+1 -1)
===================================================================
--- lib/chupa-text/content-type-registry.rb    2014-01-03 18:48:00 +0900 (20130a5)
+++ lib/chupa-text/content-type-registry.rb    2014-01-03 18:48:39 +0900 (361128b)
@@ -34,7 +34,7 @@ module ChupaText
 
     private
     def normalize_extension(extension)
-      return nil if extension
+      return nil if extension.nil?
       extension.to_s.downcase.gsub(/\A\./, "")
     end
   end

  Copied: test/test-content-type-registry.rb (+21 -14) 57%
===================================================================
--- lib/chupa-text/content-type-registry.rb    2014-01-03 18:48:00 +0900 (20130a5)
+++ test/test-content-type-registry.rb    2014-01-03 18:48:39 +0900 (161f785)
@@ -14,28 +14,35 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-module ChupaText
-  class ContentTypeRegistry
-    def initialize
-      @from_extension_map = {}
+class TestContentTypeRegistry < Test::Unit::TestCase
+  def setup
+    @registry = ChupaText::ContentTypeRegistry.new
+  end
+
+  sub_test_case("register") do
+    def test_multiple
+      @registry.register("csv", "text/csv")
+      @registry.register("txt", "text/plain")
+      assert_equal("text/csv", @registry.find("csv"))
     end
+  end
 
-    def register(extension, content_type)
-      @from_extension_map[normalize_extension(extension)] = content_type
+  sub_test_case("find") do
+    def setup
+      super
+      @registry.register("csv", "text/csv")
     end
 
-    def find(extension)
-      @from_extension_map[normalize_extension(extension)]
+    def test_nil
+      assert_nil(@registry.find(nil))
     end
 
-    def clear
-      @from_extension_map.clear
+    def test_nonexistent
+      assert_nil(@registry.find("txt"))
     end
 
-    private
-    def normalize_extension(extension)
-      return nil if extension
-      extension.to_s.downcase.gsub(/\A\./, "")
+    def test_existent
+      assert_equal("text/csv", @registry.find("csv"))
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index