inquisitio 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +3 -0
 - data/lib/inquisitio/configuration.rb +4 -0
 - data/lib/inquisitio/document.rb +7 -9
 - data/lib/inquisitio/indexer.rb +1 -1
 - data/lib/inquisitio/search_url_builder.rb +11 -3
 - data/lib/inquisitio/searcher.rb +5 -1
 - data/lib/inquisitio/version.rb +1 -1
 - data/test/configuration_test.rb +9 -0
 - data/test/test_document.rb +49 -0
 - data/test/{indexer_test.rb → test_indexer_for_2011.rb} +9 -3
 - data/test/{search_url_builder_test.rb → test_search_url_builder_for_2011.rb} +1 -1
 - data/test/test_search_url_builder_for_2013.rb +110 -0
 - data/test/{searcher_test.rb → test_searcher.rb} +32 -6
 - metadata +13 -11
 - data/test/document_test.rb +0 -68
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 89aae9dc681251070a23032fd2dab54af311e0cc
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 3bdf5147f6bd81d43164e38c700255263c58f981
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 0f6218f321736cfa15f6bebd2dc5456817ae118f3e8335929f1c73ab0bf9f0498d5b75db95f5ffe52cbb31a2fd4fd9fed24294995b062798bad30f49fe3aee9b
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 508afe8065da867c2d0eee4fadbdba18f66aabfc584f9998487f0b516ede922b4a21770eac2eefc7e63fc0d5725133d2b01ebcb3e65bcbd478e2cfc472030419
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
| 
         @@ -6,6 +6,7 @@ module Inquisitio 
     | 
|
| 
       6 
6 
     | 
    
         
             
              class Configuration
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                SETTINGS = [
         
     | 
| 
      
 9 
     | 
    
         
            +
                  :api_version,
         
     | 
| 
       9 
10 
     | 
    
         
             
                  :search_endpoint,
         
     | 
| 
       10 
11 
     | 
    
         
             
                  :document_endpoint,
         
     | 
| 
       11 
12 
     | 
    
         
             
                  :default_search_size,
         
     | 
| 
         @@ -32,6 +33,9 @@ module Inquisitio 
     | 
|
| 
       32 
33 
     | 
    
         | 
| 
       33 
34 
     | 
    
         
             
                def get_or_raise(setting)
         
     | 
| 
       34 
35 
     | 
    
         
             
                  val = instance_variable_get("@#{setting.to_s}")
         
     | 
| 
      
 36 
     | 
    
         
            +
                  if setting == :api_version && val.nil?
         
     | 
| 
      
 37 
     | 
    
         
            +
                    val = '2011-02-01'
         
     | 
| 
      
 38 
     | 
    
         
            +
                  end
         
     | 
| 
       35 
39 
     | 
    
         
             
                  val.nil?? raise(InquisitioConfigurationError.new("Configuration for #{setting} is not set")) : val
         
     | 
| 
       36 
40 
     | 
    
         
             
                end
         
     | 
| 
       37 
41 
     | 
    
         
             
              end
         
     | 
    
        data/lib/inquisitio/document.rb
    CHANGED
    
    | 
         @@ -3,22 +3,20 @@ module Inquisitio 
     | 
|
| 
       3 
3 
     | 
    
         
             
              class Document
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
                attr_reader :type, :id, :version, :fields
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       6 
7 
     | 
    
         
             
                def initialize(type, id, version, fields)
         
     | 
| 
       7 
8 
     | 
    
         
             
                  @type = type
         
     | 
| 
       8 
9 
     | 
    
         
             
                  @id = id
         
     | 
| 
       9 
10 
     | 
    
         
             
                  @version = version
         
     | 
| 
       10 
     | 
    
         
            -
                  @fields = fields.reject {|k,v| v.nil?}
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @fields = fields.reject { |k, v| v.nil? }
         
     | 
| 
       11 
12 
     | 
    
         
             
                end
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
14 
     | 
    
         
             
                def to_SDF
         
     | 
| 
       14 
     | 
    
         
            -
                   
     | 
| 
       15 
     | 
    
         
            -
            { "type": "#{type}",
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
              "fields": #{fields.to_json}
         
     | 
| 
       20 
     | 
    
         
            -
            }
         
     | 
| 
       21 
     | 
    
         
            -
                  EOS
         
     | 
| 
      
 15 
     | 
    
         
            +
                  if Inquisitio.config.api_version == '2011-02-01'
         
     | 
| 
      
 16 
     | 
    
         
            +
                    "{ \"type\": \"#{type}\", \"id\": \"#{id}\", \"version\": #{version}, \"lang\": \"en\", \"fields\": #{fields.to_json} }"
         
     | 
| 
      
 17 
     | 
    
         
            +
                  elsif Inquisitio.config.api_version == '2013-01-01'
         
     | 
| 
      
 18 
     | 
    
         
            +
                    "{ \"type\": \"#{type}\", \"id\": \"#{id}\", \"fields\": #{fields.to_json} }"
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
       22 
20 
     | 
    
         
             
                end
         
     | 
| 
       23 
21 
     | 
    
         
             
              end
         
     | 
| 
       24 
22 
     | 
    
         
             
            end
         
     | 
    
        data/lib/inquisitio/indexer.rb
    CHANGED
    
    
| 
         @@ -49,7 +49,11 @@ module Inquisitio 
     | 
|
| 
       49 
49 
     | 
    
         
             
                    end
         
     | 
| 
       50 
50 
     | 
    
         
             
                  end
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
                   
     | 
| 
      
 52 
     | 
    
         
            +
                  if Inquisitio.config.api_version == '2011-02-01'
         
     | 
| 
      
 53 
     | 
    
         
            +
                    "bq=#{URI.encode("(and #{query_blocks.join(' ')})").gsub('&', '%26')}"
         
     | 
| 
      
 54 
     | 
    
         
            +
                  elsif Inquisitio.config.api_version == '2013-01-01'
         
     | 
| 
      
 55 
     | 
    
         
            +
                    "q=#{URI.encode("(and #{query_blocks.join(' ')})").gsub('&', '%26')}&q.parser=structured"
         
     | 
| 
      
 56 
     | 
    
         
            +
                  end
         
     | 
| 
       53 
57 
     | 
    
         
             
                end
         
     | 
| 
       54 
58 
     | 
    
         | 
| 
       55 
59 
     | 
    
         
             
                def sanitise(value)
         
     | 
| 
         @@ -58,7 +62,11 @@ module Inquisitio 
     | 
|
| 
       58 
62 
     | 
    
         | 
| 
       59 
63 
     | 
    
         
             
                def return_fields_query_string
         
     | 
| 
       60 
64 
     | 
    
         
             
                  return "" if @return_fields.nil?
         
     | 
| 
       61 
     | 
    
         
            -
                   
     | 
| 
      
 65 
     | 
    
         
            +
                  if Inquisitio.config.api_version == '2011-02-01'
         
     | 
| 
      
 66 
     | 
    
         
            +
                    "&return-fields=#{URI::encode(@return_fields.join(',').gsub('\'',''))}"
         
     | 
| 
      
 67 
     | 
    
         
            +
                  elsif Inquisitio.config.api_version == '2013-01-01'
         
     | 
| 
      
 68 
     | 
    
         
            +
                    "&return=#{URI::encode(@return_fields.join(',').gsub('\'',''))}"
         
     | 
| 
      
 69 
     | 
    
         
            +
                  end
         
     | 
| 
       62 
70 
     | 
    
         
             
                end
         
     | 
| 
       63 
71 
     | 
    
         | 
| 
       64 
72 
     | 
    
         
             
                def arguments
         
     | 
| 
         @@ -67,7 +75,7 @@ module Inquisitio 
     | 
|
| 
       67 
75 
     | 
    
         
             
                end
         
     | 
| 
       68 
76 
     | 
    
         | 
| 
       69 
77 
     | 
    
         
             
                def url_root
         
     | 
| 
       70 
     | 
    
         
            -
                  "#{Inquisitio.config.search_endpoint}/ 
     | 
| 
      
 78 
     | 
    
         
            +
                  "#{Inquisitio.config.search_endpoint}/#{Inquisitio.config.api_version}/search?"
         
     | 
| 
       71 
79 
     | 
    
         
             
                end
         
     | 
| 
       72 
80 
     | 
    
         | 
| 
       73 
81 
     | 
    
         
             
                def add_default_size
         
     | 
    
        data/lib/inquisitio/searcher.rb
    CHANGED
    
    | 
         @@ -143,7 +143,11 @@ module Inquisitio 
     | 
|
| 
       143 
143 
     | 
    
         | 
| 
       144 
144 
     | 
    
         
             
                def search_url
         
     | 
| 
       145 
145 
     | 
    
         
             
                  @search_url ||= begin
         
     | 
| 
       146 
     | 
    
         
            -
                     
     | 
| 
      
 146 
     | 
    
         
            +
                    if Inquisitio.config.api_version == '2011-02-01'
         
     | 
| 
      
 147 
     | 
    
         
            +
                      return_fields = params[:returns].empty? ? [:type, :id] : params[:returns]
         
     | 
| 
      
 148 
     | 
    
         
            +
                    elsif Inquisitio.config.api_version == '2013-01-01'
         
     | 
| 
      
 149 
     | 
    
         
            +
                      return_fields = params[:returns].empty? ? nil : params[:returns]
         
     | 
| 
      
 150 
     | 
    
         
            +
                    end
         
     | 
| 
       147 
151 
     | 
    
         | 
| 
       148 
152 
     | 
    
         
             
                    SearchUrlBuilder.build(
         
     | 
| 
       149 
153 
     | 
    
         
             
                      query: params[:criteria],
         
     | 
    
        data/lib/inquisitio/version.rb
    CHANGED
    
    
    
        data/test/configuration_test.rb
    CHANGED
    
    | 
         @@ -19,6 +19,15 @@ module Inquisitio 
     | 
|
| 
       19 
19 
     | 
    
         
             
                  assert_equal test_search_endpoint, Inquisitio.config.search_endpoint
         
     | 
| 
       20 
20 
     | 
    
         
             
                end
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
      
 22 
     | 
    
         
            +
                def test_api_version
         
     | 
| 
      
 23 
     | 
    
         
            +
                  assert_equal '2011-02-01', Inquisitio.config.api_version
         
     | 
| 
      
 24 
     | 
    
         
            +
                  Inquisitio.config.api_version = '2013-01-01'
         
     | 
| 
      
 25 
     | 
    
         
            +
                  assert_equal '2013-01-01', Inquisitio.config.api_version
         
     | 
| 
      
 26 
     | 
    
         
            +
                  Inquisitio.config.api_version = nil
         
     | 
| 
      
 27 
     | 
    
         
            +
                  assert_equal '2011-02-01', Inquisitio.config.api_version
         
     | 
| 
      
 28 
     | 
    
         
            +
                  Inquisitio.config.api_version = '2011-02-01'
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
       22 
31 
     | 
    
         
             
                def test_search_endpoint
         
     | 
| 
       23 
32 
     | 
    
         
             
                  assert_equal 3, Inquisitio.config.max_attempts
         
     | 
| 
       24 
33 
     | 
    
         
             
                end
         
     | 
| 
         @@ -0,0 +1,49 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path('../test_helper', __FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            module Inquisitio
         
     | 
| 
      
 5 
     | 
    
         
            +
              class TestDocument < Minitest::Test
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                def test_initialization_sets_type
         
     | 
| 
      
 8 
     | 
    
         
            +
                  document = Document.new('add', '12345', 1, {:title => 'The Title', :author => 'The Author'})
         
     | 
| 
      
 9 
     | 
    
         
            +
                  assert_equal 'add', document.type
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                def test_initialization_sets_id
         
     | 
| 
      
 13 
     | 
    
         
            +
                  document = Document.new('add', '12345', 1, {:title => 'The Title', :author => 'The Author'})
         
     | 
| 
      
 14 
     | 
    
         
            +
                  assert_equal '12345', document.id
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                def test_initialization_sets_version
         
     | 
| 
      
 18 
     | 
    
         
            +
                  document = Document.new('add', '12345', 1, {:title => 'The Title', :author => 'The Author'})
         
     | 
| 
      
 19 
     | 
    
         
            +
                  assert_equal 1, document.version
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                def test_initialization_sets_fields
         
     | 
| 
      
 23 
     | 
    
         
            +
                  fields = {:title => 'The Title', :author => 'The Author'}
         
     | 
| 
      
 24 
     | 
    
         
            +
                  document = Document.new('add', '12345', 1, fields)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  assert_equal fields, document.fields
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def test_create_valid_SDF_json_for_2011
         
     | 
| 
      
 29 
     | 
    
         
            +
                  expected_SDF = '{ "type": "add", "id": "12345", "version": 1, "lang": "en", "fields": { "title": "The Title", "author": "The Author" } }'
         
     | 
| 
      
 30 
     | 
    
         
            +
                  document = Document.new('add', '12345', 1, {:title => 'The Title', :author => 'The Author'})
         
     | 
| 
      
 31 
     | 
    
         
            +
                  assert_equal JSON.parse(expected_SDF).to_json, JSON.parse(document.to_SDF).to_json
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                def test_create_valid_SDF_json_for_2013
         
     | 
| 
      
 35 
     | 
    
         
            +
                  Inquisitio.config.api_version = '2013-01-01'
         
     | 
| 
      
 36 
     | 
    
         
            +
                  expected_SDF = '{ "type": "add", "id": "12345", "fields": { "title": "The Title", "author": "The Author" } }'
         
     | 
| 
      
 37 
     | 
    
         
            +
                  document = Document.new('add', '12345', 1, {:title => 'The Title', :author => 'The Author'})
         
     | 
| 
      
 38 
     | 
    
         
            +
                  assert_equal JSON.parse(expected_SDF).to_json, JSON.parse(document.to_SDF).to_json
         
     | 
| 
      
 39 
     | 
    
         
            +
                  Inquisitio.config.api_version = nil
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                def test_should_ignore_null_field_values_when_creating_SDF_json
         
     | 
| 
      
 43 
     | 
    
         
            +
                  expected_SDF = '{ "type": "add", "id": "12345", "version": 1, "lang": "en", "fields": { "title": "The Title" } }'
         
     | 
| 
      
 44 
     | 
    
         
            +
                  fields = {:title => 'The Title', :author => nil}
         
     | 
| 
      
 45 
     | 
    
         
            +
                  document = Document.new('add', '12345', 1, fields)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  assert_equal JSON.parse(expected_SDF).to_json, JSON.parse(document.to_SDF).to_json
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require File.expand_path('../test_helper', __FILE__)
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Inquisitio
         
     | 
| 
       4 
     | 
    
         
            -
              class  
     | 
| 
      
 4 
     | 
    
         
            +
              class TestIndexerFor2011 < Minitest::Test
         
     | 
| 
       5 
5 
     | 
    
         
             
                def setup
         
     | 
| 
       6 
6 
     | 
    
         
             
                  @document_endpoint = 'http://my.document-endpoint.com'
         
     | 
| 
       7 
7 
     | 
    
         
             
                  Inquisitio.config.document_endpoint = @document_endpoint
         
     | 
| 
         @@ -34,8 +34,14 @@ module Inquisitio 
     | 
|
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
                def test_create_correct_index_url
         
     | 
| 
       36 
36 
     | 
    
         
             
                  indexer = Indexer.new(@documents)
         
     | 
| 
       37 
     | 
    
         
            -
                   
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
                  assert_equal 'http://my.document-endpoint.com/2011-02-01/documents/batch', indexer.send(:batch_index_url)
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                def test_create_correct_index_url_2013
         
     | 
| 
      
 41 
     | 
    
         
            +
                  Inquisitio.config.api_version = '2013-01-01'
         
     | 
| 
      
 42 
     | 
    
         
            +
                  indexer = Indexer.new(@documents)
         
     | 
| 
      
 43 
     | 
    
         
            +
                  assert_equal 'http://my.document-endpoint.com/2013-01-01/documents/batch', indexer.send(:batch_index_url)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  Inquisitio.config.api_version = nil
         
     | 
| 
       39 
45 
     | 
    
         
             
                end
         
     | 
| 
       40 
46 
     | 
    
         | 
| 
       41 
47 
     | 
    
         
             
                def test_create_correct_body
         
     | 
| 
         @@ -0,0 +1,110 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path('../test_helper', __FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Inquisitio
         
     | 
| 
      
 4 
     | 
    
         
            +
              class TestSearchUrlBuilderFor2013 < Minitest::Test
         
     | 
| 
      
 5 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 6 
     | 
    
         
            +
                  super
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @search_endpoint = 'http://my.search-endpoint.com'
         
     | 
| 
      
 8 
     | 
    
         
            +
                  Inquisitio.config.api_version = '2013-01-01'
         
     | 
| 
      
 9 
     | 
    
         
            +
                  Inquisitio.config.search_endpoint = @search_endpoint
         
     | 
| 
      
 10 
     | 
    
         
            +
                  Inquisitio.config.default_search_size = '10'
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def test_create_correct_search_url_with_single_criteria_query
         
     | 
| 
      
 14 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star Wars'])
         
     | 
| 
      
 15 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star%20Wars&size=10'
         
     | 
| 
      
 16 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                def test_create_correct_search_url_with_ampersand
         
     | 
| 
      
 20 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star&Wars'])
         
     | 
| 
      
 21 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star%26Wars&size=10'
         
     | 
| 
      
 22 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                def test_create_correct_search_url_with_multiple_criteria_should_create_boolean_query
         
     | 
| 
      
 26 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star Wars', 'Episode One'])
         
     | 
| 
      
 27 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=(and%20(or%20\'Star%20Wars\'%20\'Episode%20One\'))&q.parser=structured&size=10'
         
     | 
| 
      
 28 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                def test_create_correct_search_url_with_multiple_criteria_with_ampersand
         
     | 
| 
      
 32 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star&Wars', 'Episode One'])
         
     | 
| 
      
 33 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=(and%20(or%20\'Star%26Wars\'%20\'Episode%20One\'))&q.parser=structured&size=10'
         
     | 
| 
      
 34 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                def test_create_correct_search_url_including_return_fields
         
     | 
| 
      
 39 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star Wars'], return_fields: [ 'title', 'year', '%' ] )
         
     | 
| 
      
 40 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star%20Wars&return=title,year,%25&size=10'
         
     | 
| 
      
 41 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                def test_create_boolean_query_search_url_with_only_filters
         
     | 
| 
      
 45 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(filters: {title: 'Star Wars'})
         
     | 
| 
      
 46 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=(and%20title:\'Star%20Wars\')&q.parser=structured&size=10'
         
     | 
| 
      
 47 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                def test_create_boolean_query_search_url_with_query_and_filters
         
     | 
| 
      
 51 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'})
         
     | 
| 
      
 52 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=(and%20\'Star%20Wars\'%20genre:\'Animation\')&q.parser=structured&size=10'
         
     | 
| 
      
 53 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                def test_create_boolean_query_search_url_with_query_and_filters_and_return_fields
         
     | 
| 
      
 57 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'}, return_fields: [ 'title', 'year', '%' ])
         
     | 
| 
      
 58 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=(and%20\'Star%20Wars\'%20genre:\'Animation\')&q.parser=structured&return=title,year,%25&size=10'
         
     | 
| 
      
 59 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                def test_create_search_url_with_added_arguments
         
     | 
| 
      
 63 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'}, :arguments => { facet: 'genre', 'facet-genre-constraints' => 'Animation', 'facet-genre-top-n' => '5'})
         
     | 
| 
      
 64 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=(and%20\'Star%20Wars\'%20genre:\'Animation\')&q.parser=structured&facet=genre&facet-genre-constraints=Animation&facet-genre-top-n=5&size=10'
         
     | 
| 
      
 65 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                def test_create_search_url_with_default_size
         
     | 
| 
      
 69 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star Wars'])
         
     | 
| 
      
 70 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star%20Wars&size=10'
         
     | 
| 
      
 71 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                def test_create_search_url_overriding_default_size
         
     | 
| 
      
 75 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { size: '200' })
         
     | 
| 
      
 76 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star%20Wars&size=200'
         
     | 
| 
      
 77 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                def test_create_search_url_with_start_and_default_size
         
     | 
| 
      
 81 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { start: '20' })
         
     | 
| 
      
 82 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star%20Wars&start=20&size=10'
         
     | 
| 
      
 83 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 84 
     | 
    
         
            +
                end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                def test_create_search_url_with_start_and_size
         
     | 
| 
      
 87 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { start: '2', size: '200' })
         
     | 
| 
      
 88 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star%20Wars&start=2&size=200'
         
     | 
| 
      
 89 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                def test_create_correct_search_url_with_sanatised_query_string
         
     | 
| 
      
 93 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star\' Wars'], filters: {genre: 'Anim\'ation'}, :arguments => { facet: 'ge\'nre', 'facet-genr\'e-constraints' => 'Anim\'ation', 'facet-gen\'re-top-n' => '\'5'}, return_fields: [ 't\'itle', 'y\'ear' ])
         
     | 
| 
      
 94 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=(and%20\'Star%20Wars\'%20genre:\'Animation\')&q.parser=structured&return=title,year&facet=genre&facet-genre-constraints=Animation&facet-genre-top-n=5&size=10'
         
     | 
| 
      
 95 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 96 
     | 
    
         
            +
                end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                def test_create_search_url_with_filter_array
         
     | 
| 
      
 99 
     | 
    
         
            +
                  url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: ['Animation', 'Action']})
         
     | 
| 
      
 100 
     | 
    
         
            +
                  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=(and%20\'Star%20Wars\'%20(or%20genre:\'Animation\'%20genre:\'Action\'))&q.parser=structured&size=10'
         
     | 
| 
      
 101 
     | 
    
         
            +
                  assert_equal expected_url, url
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                def test_throws_exception_when_using_unsupported_filter_value_type
         
     | 
| 
      
 105 
     | 
    
         
            +
                  assert_raises(InquisitioError) do
         
     | 
| 
      
 106 
     | 
    
         
            +
                    SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: {}})
         
     | 
| 
      
 107 
     | 
    
         
            +
                  end
         
     | 
| 
      
 108 
     | 
    
         
            +
                end
         
     | 
| 
      
 109 
     | 
    
         
            +
              end
         
     | 
| 
      
 110 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -16,11 +16,12 @@ module Inquisitio 
     | 
|
| 
       16 
16 
     | 
    
         
             
                end
         
     | 
| 
       17 
17 
     | 
    
         
             
              end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
              class  
     | 
| 
      
 19 
     | 
    
         
            +
              class TestSearcher < Minitest::Test
         
     | 
| 
       20 
20 
     | 
    
         
             
                def setup
         
     | 
| 
       21 
21 
     | 
    
         
             
                  super
         
     | 
| 
       22 
22 
     | 
    
         
             
                  @search_endpoint = 'http://my.search-endpoint.com'
         
     | 
| 
       23 
23 
     | 
    
         
             
                  Inquisitio.config.search_endpoint = @search_endpoint
         
     | 
| 
      
 24 
     | 
    
         
            +
                  Inquisitio.config.api_version = nil
         
     | 
| 
       24 
25 
     | 
    
         
             
                  @result_1 = {'data' => {'id' => ['1'], 'title' => ["Foobar"], 'type' => ["Cat"]}}
         
     | 
| 
       25 
26 
     | 
    
         
             
                  @result_2 = {'data' => {'id' => ['2'], 'title' => ["Foobar"], 'type' => ["Cat"]}}
         
     | 
| 
       26 
27 
     | 
    
         
             
                  @result_3 = {'data' => {'id' => ['20'], 'title' => ["Foobar2"], 'type' => ["Module_Dog"]}}
         
     | 
| 
         @@ -91,11 +92,17 @@ module Inquisitio 
     | 
|
| 
       91 
92 
     | 
    
         
             
                  assert searcher.send(:search_url).include? "q=Star%20Wars"
         
     | 
| 
       92 
93 
     | 
    
         
             
                end
         
     | 
| 
       93 
94 
     | 
    
         | 
| 
       94 
     | 
    
         
            -
                def  
     | 
| 
      
 95 
     | 
    
         
            +
                def test_where_gets_correct_url_with_filters_for_2011
         
     | 
| 
       95 
96 
     | 
    
         
             
                  searcher = Searcher.where(title: 'Star Wars')
         
     | 
| 
       96 
97 
     | 
    
         
             
                  assert searcher.send(:search_url).include? "bq=(and%20(or%20title:'Star%20Wars'))"
         
     | 
| 
       97 
98 
     | 
    
         
             
                end
         
     | 
| 
       98 
99 
     | 
    
         | 
| 
      
 100 
     | 
    
         
            +
                def test_where_gets_correct_url_with_filters_for_2013
         
     | 
| 
      
 101 
     | 
    
         
            +
                  Inquisitio.config.api_version = '2013-01-01'
         
     | 
| 
      
 102 
     | 
    
         
            +
                  searcher = Searcher.where(title: 'Star Wars')
         
     | 
| 
      
 103 
     | 
    
         
            +
                  assert searcher.send(:search_url).include? "q=(and%20(or%20title:'Star%20Wars'))&q.parser=structured"
         
     | 
| 
      
 104 
     | 
    
         
            +
                end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
       99 
106 
     | 
    
         
             
                def test_where_works_with_array_in_a_hash
         
     | 
| 
       100 
107 
     | 
    
         
             
                  criteria = {thing: ['foo', 'bar']}
         
     | 
| 
       101 
108 
     | 
    
         
             
                  searcher = Searcher.where(criteria)
         
     | 
| 
         @@ -181,21 +188,33 @@ module Inquisitio 
     | 
|
| 
       181 
188 
     | 
    
         
             
                  assert searcher.params[:returns].include?('foobar')
         
     | 
| 
       182 
189 
     | 
    
         
             
                end
         
     | 
| 
       183 
190 
     | 
    
         | 
| 
       184 
     | 
    
         
            -
                def  
     | 
| 
      
 191 
     | 
    
         
            +
                def test_returns_gets_correct_urlns_appends_variable_for_2011
         
     | 
| 
       185 
192 
     | 
    
         
             
                  searcher = Searcher.returns('foobar')
         
     | 
| 
       186 
193 
     | 
    
         
             
                  assert searcher.send(:search_url).include? "&return-fields=foobar"
         
     | 
| 
       187 
194 
     | 
    
         
             
                end
         
     | 
| 
       188 
195 
     | 
    
         | 
| 
      
 196 
     | 
    
         
            +
                def test_returns_gets_correct_urlns_appends_variable_for_2013
         
     | 
| 
      
 197 
     | 
    
         
            +
                  Inquisitio.config.api_version = '2013-01-01'
         
     | 
| 
      
 198 
     | 
    
         
            +
                  searcher = Searcher.returns('foobar')
         
     | 
| 
      
 199 
     | 
    
         
            +
                  assert searcher.send(:search_url).include? "&return=foobar"
         
     | 
| 
      
 200 
     | 
    
         
            +
                end
         
     | 
| 
      
 201 
     | 
    
         
            +
             
     | 
| 
       189 
202 
     | 
    
         
             
                def test_returns_with_array_sets_variable
         
     | 
| 
       190 
203 
     | 
    
         
             
                  searcher = Searcher.returns('dog', 'cat')
         
     | 
| 
       191 
204 
     | 
    
         
             
                  assert_equal ['dog', 'cat'], searcher.params[:returns]
         
     | 
| 
       192 
205 
     | 
    
         
             
                end
         
     | 
| 
       193 
206 
     | 
    
         | 
| 
       194 
     | 
    
         
            -
                def  
     | 
| 
      
 207 
     | 
    
         
            +
                def test_returns_with_array_gets_correct_url_for_2011
         
     | 
| 
       195 
208 
     | 
    
         
             
                  searcher = Searcher.returns('id', 'foobar')
         
     | 
| 
       196 
209 
     | 
    
         
             
                  assert searcher.send(:search_url).include? "&return-fields=id,foobar"
         
     | 
| 
       197 
210 
     | 
    
         
             
                end
         
     | 
| 
       198 
211 
     | 
    
         | 
| 
      
 212 
     | 
    
         
            +
                def test_returns_with_array_gets_correct_url_for_2013
         
     | 
| 
      
 213 
     | 
    
         
            +
                  Inquisitio.config.api_version = '2013-01-01'
         
     | 
| 
      
 214 
     | 
    
         
            +
                  searcher = Searcher.returns('id', 'foobar')
         
     | 
| 
      
 215 
     | 
    
         
            +
                  assert searcher.send(:search_url).include? "&return=id,foobar"
         
     | 
| 
      
 216 
     | 
    
         
            +
                end
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
       199 
218 
     | 
    
         
             
                def test_returns_appends_variable
         
     | 
| 
       200 
219 
     | 
    
         
             
                  searcher = Searcher.returns('id').returns('foobar')
         
     | 
| 
       201 
220 
     | 
    
         
             
                  assert_equal ['id', 'foobar'], searcher.params[:returns]
         
     | 
| 
         @@ -291,11 +310,18 @@ module Inquisitio 
     | 
|
| 
       291 
310 
     | 
    
         
             
                  2.times { searcher.search }
         
     | 
| 
       292 
311 
     | 
    
         
             
                end
         
     | 
| 
       293 
312 
     | 
    
         | 
| 
       294 
     | 
    
         
            -
                def  
     | 
| 
      
 313 
     | 
    
         
            +
                def test_should_return_type_and_id_by_default_for_2011
         
     | 
| 
       295 
314 
     | 
    
         
             
                  searcher = Searcher.where('Star Wars')
         
     | 
| 
       296 
315 
     | 
    
         
             
                  assert_equal [], searcher.params[:returns]
         
     | 
| 
       297 
316 
     | 
    
         
             
                  assert searcher.send(:search_url).include? "&return-fields=type,id"
         
     | 
| 
       298 
     | 
    
         
            -
             
     | 
| 
      
 317 
     | 
    
         
            +
                end
         
     | 
| 
      
 318 
     | 
    
         
            +
             
     | 
| 
      
 319 
     | 
    
         
            +
                def test_should_not_specify_return_by_default_for_2013
         
     | 
| 
      
 320 
     | 
    
         
            +
                  Inquisitio.config.api_version = '2013-01-01'
         
     | 
| 
      
 321 
     | 
    
         
            +
                  searcher = Searcher.where('Star Wars')
         
     | 
| 
      
 322 
     | 
    
         
            +
                  assert_equal [], searcher.params[:returns]
         
     | 
| 
      
 323 
     | 
    
         
            +
                  refute searcher.send(:search_url).include? "&return="
         
     | 
| 
      
 324 
     | 
    
         
            +
                  refute searcher.send(:search_url).include? "&return-fields="
         
     | 
| 
       299 
325 
     | 
    
         
             
                end
         
     | 
| 
       300 
326 
     | 
    
         | 
| 
       301 
327 
     | 
    
         
             
                def test_should_return_ids
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: inquisitio
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Jeremy Walker
         
     | 
| 
         @@ -10,7 +10,7 @@ authors: 
     | 
|
| 
       10 
10 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       11 
11 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       12 
12 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       13 
     | 
    
         
            -
            date: 2014-03 
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2014-06-03 00:00:00.000000000 Z
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies:
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       16 
16 
     | 
    
         
             
              name: excon
         
     | 
| 
         @@ -148,13 +148,14 @@ files: 
     | 
|
| 
       148 
148 
     | 
    
         
             
            - lib/inquisitio/searcher.rb
         
     | 
| 
       149 
149 
     | 
    
         
             
            - lib/inquisitio/version.rb
         
     | 
| 
       150 
150 
     | 
    
         
             
            - test/configuration_test.rb
         
     | 
| 
       151 
     | 
    
         
            -
            - test/document_test.rb
         
     | 
| 
       152 
     | 
    
         
            -
            - test/indexer_test.rb
         
     | 
| 
       153 
151 
     | 
    
         
             
            - test/logger_test.rb
         
     | 
| 
       154 
152 
     | 
    
         
             
            - test/results_test.rb
         
     | 
| 
       155 
     | 
    
         
            -
            - test/ 
     | 
| 
       156 
     | 
    
         
            -
            - test/searcher_test.rb
         
     | 
| 
      
 153 
     | 
    
         
            +
            - test/test_document.rb
         
     | 
| 
       157 
154 
     | 
    
         
             
            - test/test_helper.rb
         
     | 
| 
      
 155 
     | 
    
         
            +
            - test/test_indexer_for_2011.rb
         
     | 
| 
      
 156 
     | 
    
         
            +
            - test/test_search_url_builder_for_2011.rb
         
     | 
| 
      
 157 
     | 
    
         
            +
            - test/test_search_url_builder_for_2013.rb
         
     | 
| 
      
 158 
     | 
    
         
            +
            - test/test_searcher.rb
         
     | 
| 
       158 
159 
     | 
    
         
             
            homepage: https://github.com/meducation/inquisition
         
     | 
| 
       159 
160 
     | 
    
         
             
            licenses:
         
     | 
| 
       160 
161 
     | 
    
         
             
            - AGPL3
         
     | 
| 
         @@ -175,17 +176,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       175 
176 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       176 
177 
     | 
    
         
             
            requirements: []
         
     | 
| 
       177 
178 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       178 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 179 
     | 
    
         
            +
            rubygems_version: 2.0.14
         
     | 
| 
       179 
180 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       180 
181 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       181 
182 
     | 
    
         
             
            summary: This wraps AWS CloudSearch in a Ruby Gem
         
     | 
| 
       182 
183 
     | 
    
         
             
            test_files:
         
     | 
| 
       183 
184 
     | 
    
         
             
            - test/configuration_test.rb
         
     | 
| 
       184 
     | 
    
         
            -
            - test/document_test.rb
         
     | 
| 
       185 
     | 
    
         
            -
            - test/indexer_test.rb
         
     | 
| 
       186 
185 
     | 
    
         
             
            - test/logger_test.rb
         
     | 
| 
       187 
186 
     | 
    
         
             
            - test/results_test.rb
         
     | 
| 
       188 
     | 
    
         
            -
            - test/ 
     | 
| 
       189 
     | 
    
         
            -
            - test/searcher_test.rb
         
     | 
| 
      
 187 
     | 
    
         
            +
            - test/test_document.rb
         
     | 
| 
       190 
188 
     | 
    
         
             
            - test/test_helper.rb
         
     | 
| 
      
 189 
     | 
    
         
            +
            - test/test_indexer_for_2011.rb
         
     | 
| 
      
 190 
     | 
    
         
            +
            - test/test_search_url_builder_for_2011.rb
         
     | 
| 
      
 191 
     | 
    
         
            +
            - test/test_search_url_builder_for_2013.rb
         
     | 
| 
      
 192 
     | 
    
         
            +
            - test/test_searcher.rb
         
     | 
| 
       191 
193 
     | 
    
         
             
            has_rdoc: 
         
     | 
    
        data/test/document_test.rb
    DELETED
    
    | 
         @@ -1,68 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path('../test_helper', __FILE__)
         
     | 
| 
       2 
     | 
    
         
            -
            require 'json'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            module Inquisitio
         
     | 
| 
       5 
     | 
    
         
            -
              class DocumentTest < Minitest::Test
         
     | 
| 
       6 
     | 
    
         
            -
                def setup
         
     | 
| 
       7 
     | 
    
         
            -
                  @type = 'add'
         
     | 
| 
       8 
     | 
    
         
            -
                  @id = '12345'
         
     | 
| 
       9 
     | 
    
         
            -
                  @version = 1
         
     | 
| 
       10 
     | 
    
         
            -
                  @fields = { :title => 'The Title', :author => 'The Author' }
         
     | 
| 
       11 
     | 
    
         
            -
                  @document = Document.new(@type, @id, @version, @fields)
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                  @expected_SDF = 
         
     | 
| 
       14 
     | 
    
         
            -
                    <<-EOS
         
     | 
| 
       15 
     | 
    
         
            -
            { "type": "add",
         
     | 
| 
       16 
     | 
    
         
            -
              "id":   "12345",
         
     | 
| 
       17 
     | 
    
         
            -
              "version": 1,
         
     | 
| 
       18 
     | 
    
         
            -
              "lang": "en",
         
     | 
| 
       19 
     | 
    
         
            -
              "fields": {
         
     | 
| 
       20 
     | 
    
         
            -
                "title": "The Title",
         
     | 
| 
       21 
     | 
    
         
            -
                "author": "The Author"
         
     | 
| 
       22 
     | 
    
         
            -
              }
         
     | 
| 
       23 
     | 
    
         
            -
            }
         
     | 
| 
       24 
     | 
    
         
            -
                    EOS
         
     | 
| 
       25 
     | 
    
         
            -
                end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                def test_initialization_sets_type
         
     | 
| 
       28 
     | 
    
         
            -
                  assert_equal @type, @document.type
         
     | 
| 
       29 
     | 
    
         
            -
                end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                def test_initialization_sets_id
         
     | 
| 
       32 
     | 
    
         
            -
                  assert_equal @id, @document.id
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                def test_initialization_sets_version
         
     | 
| 
       36 
     | 
    
         
            -
                  assert_equal @version, @document.version
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                def test_initialization_sets_fields
         
     | 
| 
       40 
     | 
    
         
            -
                  assert_equal @fields, @document.fields
         
     | 
| 
       41 
     | 
    
         
            -
                end
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                def test_create_valid_SDF_json
         
     | 
| 
       44 
     | 
    
         
            -
                  assert_equal JSON.parse(@expected_SDF).to_json,
         
     | 
| 
       45 
     | 
    
         
            -
                               JSON.parse(@document.to_SDF).to_json
         
     | 
| 
       46 
     | 
    
         
            -
                end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                def test_should_ignore_null_field_values_when_creating_SDF_json
         
     | 
| 
       49 
     | 
    
         
            -
                  expected_SDF = 
         
     | 
| 
       50 
     | 
    
         
            -
                    <<-EOS
         
     | 
| 
       51 
     | 
    
         
            -
            { "type": "add",
         
     | 
| 
       52 
     | 
    
         
            -
              "id":   "12345",
         
     | 
| 
       53 
     | 
    
         
            -
              "version": 1,
         
     | 
| 
       54 
     | 
    
         
            -
              "lang": "en",
         
     | 
| 
       55 
     | 
    
         
            -
              "fields": {
         
     | 
| 
       56 
     | 
    
         
            -
                "title": "The Title"
         
     | 
| 
       57 
     | 
    
         
            -
              }
         
     | 
| 
       58 
     | 
    
         
            -
            }
         
     | 
| 
       59 
     | 
    
         
            -
                    EOS
         
     | 
| 
       60 
     | 
    
         
            -
                    
         
     | 
| 
       61 
     | 
    
         
            -
                  fields = { :title => 'The Title', :author => nil }
         
     | 
| 
       62 
     | 
    
         
            -
                  document = Document.new(@type, @id, @version, fields)
         
     | 
| 
       63 
     | 
    
         
            -
                    
         
     | 
| 
       64 
     | 
    
         
            -
                  assert_equal JSON.parse(expected_SDF).to_json,
         
     | 
| 
       65 
     | 
    
         
            -
                               JSON.parse(document.to_SDF).to_json
         
     | 
| 
       66 
     | 
    
         
            -
                end
         
     | 
| 
       67 
     | 
    
         
            -
              end
         
     | 
| 
       68 
     | 
    
         
            -
            end
         
     |