Sha256: 07fa69fa66dfffa785ae388746a7639a10115b96b91b6d31e4f984301bfad692

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

require File.expand_path('../test_helper', __FILE__)
require 'json'

module Inquisitio
  class DocumentTest < Minitest::Test
    def setup
      @type = 'add'
      @id = '12345'
      @version = 1
      @fields = { :title => 'The Title', :author => 'The Author' }
      @document = Document.new(@type, @id, @version, @fields)

      @expected_SDF = 
        <<-EOS
{ "type": "add",
  "id":   "12345",
  "version": 1,
  "lang": "en",
  "fields": {
    "title": "The Title",
    "author": "The Author"
  }
}
        EOS
    end

    def test_initialization_sets_type
      assert_equal @type, @document.type
    end

    def test_initialization_sets_id
      assert_equal @id, @document.id
    end

    def test_initialization_sets_version
      assert_equal @version, @document.version
    end

    def test_initialization_sets_fields
      assert_equal @fields, @document.fields
    end

    def test_create_valid_SDF_json
      assert_equal JSON.parse(@expected_SDF).to_json,
                   JSON.parse(@document.to_SDF).to_json
    end

    def test_should_ignore_null_field_values_when_creating_SDF_json
      expected_SDF = 
        <<-EOS
{ "type": "add",
  "id":   "12345",
  "version": 1,
  "lang": "en",
  "fields": {
    "title": "The Title"
  }
}
        EOS
        
      fields = { :title => 'The Title', :author => nil }
      document = Document.new(@type, @id, @version, fields)
        
      assert_equal JSON.parse(expected_SDF).to_json,
                   JSON.parse(document.to_SDF).to_json
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
inquisitio-1.1.2 test/document_test.rb
inquisitio-1.1.1 test/document_test.rb
inquisitio-1.1.0 test/document_test.rb
inquisitio-1.0.0 test/document_test.rb
inquisitio-0.2.0 test/document_test.rb
inquisitio-0.1.7 test/document_test.rb
inquisitio-0.1.6 test/document_test.rb