Sha256: 4f371432af074ca17e51454d21a82a6bc8cdd6fff1b5d2ff6904e8f21ef6f02f

Contents?: true

Size: 1.56 KB

Versions: 11

Compression:

Stored size: 1.56 KB

Contents

require "test_helper"

class CommentTest < ActiveSupport::TestCase
  # test "the truth" do
  #   assert true
  # end
  setup do
    @user = FactoryBot.create(:user)
    @stop_word_hello = FactoryBot.create(:stop_word_hello)
  end

  # test "could censor text by text_authen" do
  #   model = Comment.create(:content => "hello world", user: @user)

  #   assert_equal model.reload.content, "goodbye world"
  # end

  test "could censor image by image_authen" do
    # model = Comment.create(:content => "", user: @user)
  end

  test "could invoke callback when controller received message" do
    model = Comment.create(:content => "", user: @user)

    class ::Comment
      alias_method :tmp_image_censor_answer_func, :image_censor_answer_func

      def image_censor_answer_func(image_censor_answer_dict)
        self.censor_info = image_censor_answer_dict
      end
    end

    content = { "code": 200, "dataId": "#{model.class}-#{model.id}", "extras": {}, "msg": "OK", "results": [{ "label": "sexy", "rate": 77.57, "scene": "porn", "suggestion": "review" }, { "label": "normal", "rate": 100.0, "scene": "terrorism", "suggestion": "pass" }], "taskId": "img20Y846E9bi96RASKO7wXOW-1wBEXo", "url": "https://img-blog.csdn.net/20161015114557738" }

    model = CensorBear::Aliyun::ImageCheck.analysis_response_content(content)

    assert_equal model.censor_info["https://img-blog.csdn.net/20161015114557738"][:is_mod], true

    class ::Comment
      def image_censor_answer_func(image_censor_answer_dict)
        tmp_image_censor_answer_func(image_censor_answer_dict)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
censor_bear-0.1.29 test/dummy/test/models/comment_test.rb
censor_bear-0.1.28 test/dummy/test/models/comment_test.rb
censor_bear-0.1.27 test/dummy/test/models/comment_test.rb
censor_bear-0.1.26 test/dummy/test/models/comment_test.rb
censor_bear-0.1.25 test/dummy/test/models/comment_test.rb
censor_bear-0.1.24 test/dummy/test/models/comment_test.rb
censor_bear-0.1.23 test/dummy/test/models/comment_test.rb
censor_bear-0.1.22 test/dummy/test/models/comment_test.rb
censor_bear-0.1.21 test/dummy/test/models/comment_test.rb
censor_bear-0.1.20 test/dummy/test/models/comment_test.rb
censor_bear-0.1.19 test/dummy/test/models/comment_test.rb