[Groonga-commit] ranguba/chupa-text-http-server at c548973 [master] Add support for need_screenshot parameter

Back to archive index
Sutou Kouhei null+****@clear*****
Tue Jun 18 12:26:42 JST 2019


Sutou Kouhei	2019-06-18 12:26:42 +0900 (Tue, 18 Jun 2019)

  Revision: c54897325463b41378a588893867b1581cb4dbd5
  https://github.com/ranguba/chupa-text-http-server/commit/c54897325463b41378a588893867b1581cb4dbd5

  Message:
    Add support for need_screenshot parameter

  Added files:
    test/fixtures/files/hello.csv
  Modified files:
    app/controllers/extractions_controller.rb
    app/models/extraction.rb
    test/controllers/extractions_controller_test.rb

  Modified: app/controllers/extractions_controller.rb (+2 -1)
===================================================================
--- app/controllers/extractions_controller.rb    2019-06-14 16:31:54 +0900 (ed1bacd)
+++ app/controllers/extractions_controller.rb    2019-06-18 12:26:42 +0900 (12dacf7)
@@ -38,6 +38,7 @@ class ExtractionsController < ApplicationController
                          :timeout,
                          :limit_cpu,
                          :limit_as,
-                         :max_body_size)
+                         :max_body_size,
+                         :need_screenshot)
     end
 end

  Modified: app/models/extraction.rb (+12 -0)
===================================================================
--- app/models/extraction.rb    2019-06-14 16:31:54 +0900 (3d54f53)
+++ app/models/extraction.rb    2019-06-18 12:26:42 +0900 (7765a6d)
@@ -7,6 +7,7 @@ class Extraction
   attr_accessor :limit_cpu
   attr_accessor :limit_as
   attr_writer :max_body_size
+  attr_writer :need_screenshot
 
   validates :data, presence: true, if: ->(record) {record.uri.blank?}
   validates :max_body_size,
@@ -36,6 +37,7 @@ class Extraction
     @limit_cpu = nil
     @limit_as = nil
     @max_body_size = nil
+    @need_screenshot = nil
     super
   end
 
@@ -57,6 +59,15 @@ class Extraction
     end
   end
 
+  def need_screenshot?
+    case @need_screenshot
+    when "false", false
+      false
+    else
+      true
+    end
+  end
+
   def extract
     return nil unless valid?
 
@@ -119,5 +130,6 @@ class Extraction
     data.timeout = @timeout
     data.limit_cpu = @limit_cpu
     data.limit_as = @limit_as
+    data.need_screenshot = need_screenshot?
   end
 end

  Modified: test/controllers/extractions_controller_test.rb (+37 -0)
===================================================================
--- test/controllers/extractions_controller_test.rb    2019-06-14 16:31:54 +0900 (2c37da6)
+++ test/controllers/extractions_controller_test.rb    2019-06-18 12:26:42 +0900 (b90311a)
@@ -465,6 +465,43 @@ class ExtractionsControllerTest < ActionDispatch::IntegrationTest
                      },
                      JSON.parse(response.body))
       end
+
+      sub_test_case "need_screenshot" do
+        def extract(params={})
+          post(extraction_url(format: "json"),
+               params: {
+                 data: fixture_file_upload(file_fixture("hello.csv")),
+               }.merge(params))
+          assert_equal("application/json", response.content_type,
+                       response.body)
+          JSON.parse(response.body)["texts"].collect do |text|
+            {
+              text: text["body"],
+              have_screenshot: text.key?("screenshot"),
+            }
+          end
+        end
+
+        test "default" do
+          assert_equal([
+                         {
+                           text: "1\t2\n",
+                           have_screenshot: true,
+                         },
+                       ],
+                       extract)
+        end
+
+        test "false" do
+          assert_equal([
+                         {
+                           text: "1\t2\n",
+                           have_screenshot: false,
+                         },
+                       ],
+                       extract(need_screenshot: "false"))
+        end
+      end
     end
   end
 end

  Added: test/fixtures/files/hello.csv (+1 -0) 100644
===================================================================
--- /dev/null
+++ test/fixtures/files/hello.csv    2019-06-18 12:26:42 +0900 (d72f201)
@@ -0,0 +1 @@
+1,2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190618/1627adcb/attachment-0001.html>


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