Sha256: ad65b202abbcbf47d3ffc0cd9fdee5ec0fe9e0f1ef3966db371869bcc3c2a360

Contents?: true

Size: 1.66 KB

Versions: 11

Compression:

Stored size: 1.66 KB

Contents

require "test_helper"

module CensorBear
  class AliyunTextCheckTest < ActiveSupport::TestCase
    setup do
      init_aliyun
      @comment = FactoryBot.create(:comment)
      @raw_id = TextDataId.encode(@comment, user_id: @comment.user.id, ip_address: "127.0.0.1")
    end

    test "could check content correctly" do
      content = "hello world"

      answer = CensorBear::CheckText.new(content, @raw_id).scan

      assert_equal answer.review, false
      assert_equal 0, ReviewLogs::Text.all.count
      assert_equal answer.original, content
    end

    test "could check content with review" do
      content = "日你妈,退钱"
      answer = CensorBear::CheckText.new(content, @raw_id).scan

      assert_equal answer.review, true
      assert_equal 1, ReviewLogs::Text.all.count

      # raw_data {"msg"=>"OK", "code"=>200, "data"=>[{"msg"=>"OK", "code"=>200, "dataId"=>"Comment-79-178-127.0.0.1", "taskId"=>"txt1lmM9srAXM16q7cMAq8wHk-1wRc2A", "content"=>"日你妈,退钱", "results"=>[{"rate"=>99.91, "label"=>"abuse", "scene"=>"antispam", "details"=>[{"label"=>"abuse", "contexts"=>[{"context"=>"日你妈", "positions"=>[{"endPos"=>3, "startPos"=>0}]}]}], "suggestion"=>"block"}], "filteredContent"=>"***,退钱"}], "requestId"=>"801F2870-8F8E-5BA1-A04C-4470503F3ECE"}

      assert_equal "日你妈,退钱", answer.original
      assert_equal "***,退钱", answer.filtered
    end

    test "could check content without data_id" do
      content = "经典国骂\"操你妈\" 与 四川话\"你妈卖麻花\"的联系"
      answer = CensorBear::CheckText.new(content).scan
      assert_equal answer.review, true
      assert_equal 1, ReviewLogs::Text.all.count
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
censor_bear-0.1.29 test/libs/aliyun_text_check_test.rb
censor_bear-0.1.28 test/libs/aliyun_text_check_test.rb
censor_bear-0.1.27 test/libs/aliyun_text_check_test.rb
censor_bear-0.1.26 test/libs/aliyun_text_check_test.rb
censor_bear-0.1.25 test/libs/aliyun_text_check_test.rb
censor_bear-0.1.24 test/libs/aliyun_text_check_test.rb
censor_bear-0.1.23 test/libs/aliyun_text_check_test.rb
censor_bear-0.1.22 test/libs/aliyun_text_check_test.rb
censor_bear-0.1.21 test/libs/aliyun_text_check_test.rb
censor_bear-0.1.20 test/libs/aliyun_text_check_test.rb
censor_bear-0.1.19 test/libs/aliyun_text_check_test.rb