File: update_spec.rb

package info (click to toggle)
ruby-riddle 2.3.1-2~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,752 kB
  • sloc: sql: 25,022; php: 5,992; ruby: 4,757; sh: 59; makefile: 5
file content (43 lines) | stat: -rw-r--r-- 1,355 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

require 'spec_helper'

describe "Sphinx Updates", :live => true do
  before :each do
    @client = Riddle::Client.new("localhost", 9313)
  end
  
  it "should update a single record appropriately" do
    # check existing birthday
    result = @client.query("Ellie K Ford")
    result[:matches].should_not be_empty
    result[:matches].length.should == 1
    ellie = result[:matches].first
    ellie[:attributes]["birthday"].should == Time.local(1970, 1, 23).to_i
    
    # make Ellie younger by 6 years
    @client.update("people", ["birthday"], {ellie[:doc] => [Time.local(1976, 1, 23).to_i]})
    
    # check attribute's value
    result = @client.query("Ellie K Ford")
    result[:matches].should_not be_empty
    result[:matches].length.should == 1
    ellie = result[:matches].first
    ellie[:attributes]["birthday"].should == Time.local(1976, 1, 23).to_i
  end
  
  it "should update multiple records appropriately" do
    result = @client.query("Steele")
    pairs = {}
    result[:matches].each do |match|
      pairs[match[:doc]] = [match[:attributes]["birthday"] + (365*24*60*60)]
    end
    
    @client.update "people", ["birthday"], pairs
    
    result = @client.query("Steele")
    result[:matches].each do |match|
      match[:attributes]["birthday"].should == pairs[match[:doc]].first
    end
  end
end