All Files (98.1% covered at 3.55 hits/line)
61 files in total.
2268 relevant lines.
2225 lines covered and
43 lines missed
- 1
require 'bundler/setup'
- 1
require 'i18n'
- 1
require "search_kit/version"
- 1
require "search_kit/thor"
- 1
module SearchKit
- 1
autoload :CLI, 'search_kit/cli'
- 1
autoload :Clients, 'search_kit/clients'
- 1
autoload :Configuration, 'search_kit/configuration'
- 1
autoload :Errors, 'search_kit/errors'
- 1
autoload :Logger, 'search_kit/logger'
- 1
autoload :Messages, 'search_kit/messages'
- 1
autoload :Models, 'search_kit/models'
- 1
autoload :Polling, 'search_kit/polling'
- 1
def self.logger
- 35
@logger ||= Logger.new
end
- 1
extend Configuration
- 1
configure do |config|
- 1
config.app_dir = fetch("APP_DIR")
- 1
config.app_env = fetch("APP_ENV")
- 1
config.app_uri = fetch("APP_URI")
- 1
config.config_dir = File.join(config.app_dir, "config")
- 1
config.log_dir = fetch("LOG_DIR")
- 1
config.verbose = fetch("APP_VERBOSE")
end
- 1
I18n.load_path += Dir.glob(File.join(config.config_dir, "locales/*.yml"))
end
- 1
require 'ansi'
- 1
require 'highline'
- 1
require 'thor'
- 1
require 'search_kit/thor'
- 1
module SearchKit
- 1
module CLI
- 1
autoload :All, 'search_kit/cli/all'
- 1
autoload :Documents, 'search_kit/cli/documents'
- 1
autoload :Events, 'search_kit/cli/events'
- 1
autoload :Indices, 'search_kit/cli/indices'
- 1
autoload :Scaffolds, 'search_kit/cli/scaffolds'
- 1
autoload :Search, 'search_kit/cli/search'
- 1
autoload :Subscribers, 'search_kit/cli/subscribers'
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
require 'search_kit/thor'
- 1
require 'thor'
- 1
module SearchKit
- 1
module CLI
- 1
class Documents < Thor
- 1
namespace :documents
- 1
no_commands do
- 1
def client
- 62
@client ||= SearchKit::Clients::Documents.new
end
- 1
def messages
- 42
@messages ||= SearchKit::Messages.new
end
end
- 1
document :create
- 1
def create(slug, document)
- 8
document = JSON.parse(document, symbolize_names: true)
- 7
response = client.create(slug, document)
- 3
messages.info response.to_json
rescue Errors::IndexNotFound
- 1
messages.not_found
rescue Errors::BadRequest
- 1
messages.bad_request
rescue Errors::Unprocessable
- 1
messages.unprocessable
rescue Faraday::ConnectionFailed
- 1
messages.no_service
rescue JSON::ParserError
- 1
messages.json_parse_error
end
- 1
document :delete
- 1
def delete(slug, id)
- 4
response = client.delete(slug, id)
- 2
messages.info response.to_json
rescue Errors::IndexNotFound
- 1
messages.not_found
rescue Faraday::ConnectionFailed
- 1
messages.no_service
end
- 1
document :show
- 1
def show(slug, id)
- 4
response = client.show(slug, id)
- 2
messages.info response.to_json
rescue Errors::IndexNotFound
- 1
messages.not_found
rescue Faraday::ConnectionFailed
- 1
messages.no_service
end
- 1
document :update
- 1
def update(slug, id, document)
- 8
document = JSON.parse(document, symbolize_names: true)
- 7
response = client.update(slug, id, document)
- 3
messages.info response.to_json
rescue JSON::ParserError
- 1
messages.json_parse_error
rescue Errors::BadRequest
- 1
messages.bad_request
rescue Errors::IndexNotFound
- 1
messages.not_found
rescue Errors::Unprocessable
- 1
messages.unprocessable
rescue Faraday::ConnectionFailed
- 1
messages.no_service
end
end
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
require 'search_kit/thor'
- 1
require 'thor'
- 1
module SearchKit
- 1
module CLI
- 1
class Events < Thor
- 1
namespace :events
- 1
no_commands do
- 1
def client
- 73
@client ||= SearchKit::Clients::Events.new
end
- 1
def messages
- 40
@messages ||= SearchKit::Messages.new
end
end
- 1
document :complete
- 1
def complete(id)
- 4
client.complete(id)
- 2
messages.info I18n.t('cli.events.complete.success', id: id)
rescue Errors::EventNotFound
- 1
messages.not_found
rescue Faraday::ConnectionFailed
- 1
messages.no_service
end
- 1
document :pending
- 1
def pending(channel = nil)
- 7
events = channel ? client.pending(channel) : client.index
- 3
message_path = %w(cli events pending success)
- 3
message_path << (channel ? 'filtered' : 'index')
- 3
message_path << (events.any? ? 'discovered' : 'empty')
- 3
message = I18n.t(message_path.join('.'), channel: channel)
- 3
messages.info(message)
- 3
events.each { |event| messages.info(event.to_json) }
rescue Errors::BadRequest
- 1
messages.bad_request
rescue Errors::Unauthorized
- 1
messages.unauthorized
rescue Errors::Unprocessable
- 1
messages.unprocessable
rescue Faraday::ConnectionFailed
- 1
messages.no_service
end
- 1
document :publish
- 1
def publish(channel, payload)
- 8
payload = JSON.parse(payload, symbolize_names: true)
- 7
event = client.publish(channel, payload)
- 3
message = I18n.t('cli.events.publish.success',
channel: channel,
id: event.id
)
- 3
messages.info(message)
rescue Errors::BadRequest
- 1
messages.bad_request
rescue Errors::Unauthorized
- 1
messages.unauthorized
rescue Errors::Unprocessable
- 1
messages.unprocessable
rescue Faraday::ConnectionFailed
- 1
messages.no_service
rescue JSON::ParserError
- 1
messages.json_parse_error
end
- 1
document :status
- 1
def status(id)
- 4
event = client.show(id)
- 2
status = event.state
- 2
message = I18n.t('cli.events.status.success', id: id, status: status)
- 2
messages.info(message)
rescue Errors::EventNotFound
- 1
messages.not_found
rescue Faraday::ConnectionFailed
- 1
messages.no_service
end
end
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
require 'search_kit/thor'
- 1
require 'thor'
- 1
module SearchKit
- 1
module CLI
- 1
class Indices < Thor
- 1
namespace :indices
- 1
no_commands do
- 1
def client
- 59
@client ||= SearchKit::Clients::Indices.new
end
- 1
def messages
- 38
@messages ||= SearchKit::Messages.new
end
end
- 1
document :archive
- 1
def archive(slug)
- 5
response = client.archive(slug)
- 2
messages.info response.to_json
rescue Errors::Unauthorized
- 1
messages.unauthorized
rescue Errors::IndexNotFound
- 1
messages.not_found
rescue Faraday::ConnectionFailed
- 1
messages.no_service
end
- 1
document :create
- 1
def create(name)
- 5
response = client.create(name)
- 2
messages.info response.to_json
rescue Errors::Unauthorized
- 1
messages.unauthorized
rescue Errors::BadRequest
messages.bad_request
rescue Errors::Unprocessable
- 1
messages.unprocessable
rescue Faraday::ConnectionFailed
- 1
messages.no_service
end
- 1
document :show
- 1
def show(slug)
- 5
response = client.show(slug)
- 2
messages.info response.to_json
rescue Errors::Unauthorized
- 1
messages.unauthorized
rescue Errors::IndexNotFound
- 1
messages.not_found
rescue Faraday::ConnectionFailed
- 1
messages.no_service
end
- 1
document :update
- 1
def update(slug, update_json)
- 6
options = JSON.parse(update_json, symbolize_names: true)
- 6
response = client.update(slug, options)
- 2
messages.info response.to_json
rescue Errors::Unauthorized
- 1
messages.unauthorized
rescue Errors::BadRequest
messages.bad_request
rescue Errors::IndexNotFound
messages.not_found
rescue Errors::Unprocessable
- 1
messages.unprocessable
rescue Faraday::ConnectionFailed
- 1
messages.no_service
rescue JSON::ParserError
- 1
messages.json_parse_error
end
end
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
require 'search_kit/thor'
- 1
require 'thor'
- 1
module SearchKit
- 1
module CLI
- 1
class Scaffolds < Thor
- 1
namespace :scaffolds
- 1
no_commands do
- 1
def client
- 17
@client ||= SearchKit::Clients::Scaffold.new
end
- 1
def messages
- 11
@messages ||= SearchKit::Messages.new
end
end
- 1
document :scaffold
- 1
def create(name, json = "[]")
- 6
documents = JSON.parse(json, symbolize_names: true)
- 6
response = client.create(name, documents)
- 2
messages.info response.to_json
rescue Errors::Unauthorized
- 1
messages.unauthorized
rescue Errors::BadRequest
messages.bad_request
rescue Errors::Unprocessable
- 1
messages.unprocessable
rescue Faraday::ConnectionFailed
- 1
messages.no_service
rescue JSON::ParserError
- 1
messages.json_parse_error
end
end
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
require 'search_kit/thor'
- 1
require 'thor'
- 1
module SearchKit
- 1
module CLI
- 1
class Search < Thor
- 1
namespace :search
- 1
no_commands do
- 1
def client
- 20
@client ||= SearchKit::Clients::Search.new
end
- 1
def messages
- 13
@messages ||= SearchKit::Messages.new
end
end
- 1
document :create
- 1
option :display, aliases: ['-d'], type: :array, required: false
- 1
def create(slug, phrase)
- 7
search = client.search(slug, phrase: phrase)
- 2
head_path = 'cli.search.create.success.headline'
- 2
info_path = 'cli.search.create.success.info'
- 2
headline = I18n.t(head_path, slug: slug, phrase: phrase)
- 2
info = I18n.t(info_path, count: search.results, time: search.time)
- 2
lines = [ headline, info ]
- 2
display = options.fetch('display', [])
- 2
lines += search.documents.map do |document|
if display.any?
fields = display.map { |field| document.get(field) }
" -- #{fields.join(' | ')} | score: #{document.score}"
else
" -- #{document.id} | score: #{document.score}"
end
end
- 2
lines.each(&messages.method(:info))
rescue Errors::Unauthorized
- 1
messages.unauthorized
rescue Errors::IndexNotFound
- 1
messages.not_found
rescue Errors::BadRequest
- 1
messages.bad_request
rescue Errors::Unprocessable
- 1
messages.unprocessable
rescue Faraday::ConnectionFailed
- 1
messages.no_service
end
- 1
no_commands do
- 1
alias_method :search, :create
- 1
alias_method :c, :create
- 1
alias_method :s, :search
end
end
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
require 'search_kit/thor'
- 1
require 'thor'
- 1
module SearchKit
- 1
module CLI
- 1
class Subscribers < Thor
- 1
namespace :subscribers
- 1
no_commands do
- 1
def client
- 28
@client ||= SearchKit::Clients::Subscribers.new
end
- 1
def messages
- 18
@messages ||= SearchKit::Messages.new
end
end
- 1
document :create
- 1
def create(email, password)
- 5
subscriber = client.create(email: email, password: password)
- 2
messages.info(subscriber.to_json)
rescue Errors::BadRequest
- 1
messages.bad_request
rescue Errors::Unprocessable
- 1
messages.unprocessable
rescue Faraday::ConnectionFailed
- 1
messages.no_service
end
- 1
document :info
- 1
def info
- 5
subscriber = client.info
- 2
messages.info(subscriber.to_json)
rescue Errors::SubscriberNotFound
- 1
messages.not_found
rescue Errors::Unauthorized
- 1
messages.unauthorized
rescue Faraday::ConnectionFailed
- 1
messages.no_service
end
end
end
end
- 1
module SearchKit
- 1
module Clients
- 1
autoload :Documents, 'search_kit/clients/documents'
- 1
autoload :Events, 'search_kit/clients/events'
- 1
autoload :Indices, 'search_kit/clients/indices'
- 1
autoload :Keys, 'search_kit/clients/keys'
- 1
autoload :Populate, 'search_kit/clients/populate'
- 1
autoload :Scaffold, 'search_kit/clients/scaffold'
- 1
autoload :Search, 'search_kit/clients/search'
- 1
autoload :Subscribers, 'search_kit/clients/subscribers'
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
module SearchKit
- 1
module Clients
- 1
class Documents
- 1
attr_reader :connection, :token
- 1
def initialize
- 46
uri = [SearchKit.config.app_uri, "documents"].join("/")
- 46
@connection = Faraday.new(uri)
- 46
@token = SearchKit.config.app_token
end
- 1
def create(slug, options)
- 6
document = {
token: token,
data: { type: "documents", attributes: options }
}
- 6
response = connection.post(slug, document)
- 6
body = JSON.parse(response.body, symbolize_names: true)
- 6
fail Errors::BadRequest if response.status == 400
- 5
fail Errors::Unauthorized if response.status == 401
- 4
fail Errors::IndexNotFound if response.status == 404
- 3
fail Errors::Unprocessable if response.status == 422
- 2
body
end
- 1
def delete(slug, id)
- 4
response = connection.delete("#{slug}/#{id}", token: token)
- 4
body = JSON.parse(response.body, symbolize_names: true)
- 4
fail Errors::Unauthorized if response.status == 401
- 3
fail Errors::IndexNotFound if response.status == 404
- 2
body
end
- 1
def show(slug, id)
- 4
response = connection.get("#{slug}/#{id}", token: token)
- 4
body = JSON.parse(response.body, symbolize_names: true)
- 4
fail Errors::Unauthorized if response.status == 401
- 3
fail Errors::IndexNotFound if response.status == 404
- 2
body
end
- 1
def update(slug, id, options)
- 6
document = {
token: token,
data: { type: "documents", id: id, attributes: options }
}
- 6
response = connection.patch("#{slug}/#{id}", document)
- 6
body = JSON.parse(response.body, symbolize_names: true)
- 6
fail Errors::BadRequest if response.status == 400
- 5
fail Errors::Unauthorized if response.status == 401
- 4
fail Errors::IndexNotFound if response.status == 404
- 3
fail Errors::Unprocessable if response.status == 422
- 2
body
end
end
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
module SearchKit
- 1
module Clients
- 1
class Events
- 1
attr_reader :connection, :token
- 1
def initialize
- 54
uri = [ SearchKit.config.app_uri, "events" ].join("/")
- 54
@connection = Faraday.new(uri)
- 54
@token = SearchKit.config.app_token
end
- 1
def complete(id)
- 5
response = connection.delete(id, token: token)
- 5
body = JSON.parse(response.body, symbolize_names: true)
- 5
fail Errors::Unauthorized if response.status == 401
- 4
fail Errors::EventNotFound if response.status == 404
- 3
SearchKit::Models::Event.new body.fetch(:data, {})
end
- 1
def index
- 4
response = connection.get(token: token)
- 4
body = JSON.parse(response.body, symbolize_names: true)
- 4
fail Errors::Unauthorized if response.status == 401
- 3
SearchKit::Models::Events.new body.fetch(:data, [])
end
- 1
def pending(channel)
- 4
params = { "filter[channel]" => channel, token: token }
- 4
response = connection.get('', params)
- 4
body = JSON.parse(response.body, symbolize_names: true)
- 4
fail Errors::BadRequest if response.status == 400
- 4
fail Errors::Unauthorized if response.status == 401
- 3
fail Errors::Unprocessable if response.status == 422
- 3
SearchKit::Models::Events.new body.fetch(:data, [])
end
- 1
def publish(channel, payload)
- 6
params = {
token: token,
data: {
type: 'events',
attributes: { channel: channel, payload: payload }
}
}
- 6
response = connection.post("", params)
- 6
body = JSON.parse(response.body, symbolize_names: true)
- 6
fail Errors::BadRequest if response.status == 400
- 5
fail Errors::Unauthorized if response.status == 401
- 4
fail Errors::Unprocessable if response.status == 422
- 3
SearchKit::Models::Event.new body.fetch(:data, {})
end
- 1
def show(id)
- 4
response = connection.get(id, token: token)
- 4
body = JSON.parse(response.body, symbolize_names: true)
- 4
fail Errors::Unauthorized if response.status == 401
- 3
fail Errors::EventNotFound if response.status == 404
- 2
SearchKit::Models::Event.new body.fetch(:data, {})
end
end
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
module SearchKit
- 1
module Clients
- 1
class Indices
- 1
attr_reader :connection, :token
- 1
def initialize
- 42
uri = [SearchKit.config.app_uri, "indices"].join("/")
- 42
@connection = Faraday.new(uri)
- 42
@token = SearchKit.config.app_token
end
- 1
def archive(slug)
- 4
response = connection.delete(slug, token: token)
- 4
body = JSON.parse(response.body, symbolize_names: true)
- 4
fail Errors::Unauthorized if response.status == 401
- 3
fail Errors::IndexNotFound if response.status == 404
- 2
body
end
- 1
def create(name)
- 5
options = {
token: token,
data: { type: 'indices', attributes: { name: name } }
}
- 5
response = connection.post('', options)
- 5
body = JSON.parse(response.body, symbolize_names: true)
- 5
fail Errors::Unauthorized if response.status == 401
- 4
fail Errors::BadRequest if response.status == 400
- 3
fail Errors::Unprocessable if response.status == 422
- 2
body
end
- 1
def show(slug)
- 4
response = connection.get(slug, token: token)
- 4
body = JSON.parse(response.body, symbolize_names: true)
- 4
fail Errors::Unauthorized if response.status == 401
- 3
fail Errors::IndexNotFound if response.status == 404
- 2
body
end
- 1
def update(slug, options)
- 6
options = {
token: token,
data: { type: 'indices', attributes: options }
}
- 6
response = connection.patch(slug, options)
- 6
body = JSON.parse(response.body, symbolize_names: true)
- 6
fail Errors::BadRequest if response.status == 400
- 5
fail Errors::Unauthorized if response.status == 401
- 4
fail Errors::IndexNotFound if response.status == 404
- 3
fail Errors::Unprocessable if response.status == 422
- 2
body
end
end
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
module SearchKit
- 1
module Clients
- 1
class Keys
- 1
attr_reader :connection, :token
- 1
def initialize
- 24
uri = [SearchKit.config.app_uri, "keys"].join("/")
- 24
@connection = Faraday.new(uri)
- 24
@token = SearchKit.config.app_token
end
- 1
def create(name, options = {})
- 5
options = {
token: token,
data: { type: 'keys', attributes: { name: name }.merge(options) }
}
- 5
response = connection.post('', options)
- 5
body = JSON.parse(response.body, symbolize_names: true)
- 5
fail Errors::BadRequest if response.status == 400
- 4
fail Errors::Unauthorized if response.status == 401
- 3
fail Errors::Unprocessable if response.status == 422
- 2
body
end
- 1
def expire(id)
- 4
response = connection.delete(id, token: token)
- 4
body = JSON.parse(response.body, symbolize_names: true)
- 4
fail Errors::Unauthorized if response.status == 401
- 3
fail Errors::KeyNotFound if response.status == 404
- 2
body
end
- 1
def index
- 3
response = connection.get("", token: token)
- 3
body = JSON.parse(response.body, symbolize_names: true)
- 3
fail Errors::Unauthorized if response.status == 401
- 2
body
end
- 1
def show(id)
- 4
response = connection.get(id, token: token)
- 4
body = JSON.parse(response.body, symbolize_names: true)
- 4
fail Errors::Unauthorized if response.status == 401
- 3
fail Errors::KeyNotFound if response.status == 404
- 2
body
end
- 1
def update(id, options)
- 6
options = {
token: token, data: { type: 'keys', attributes: options }
}
- 6
response = connection.patch(id, options)
- 6
body = JSON.parse(response.body, symbolize_names: true)
- 6
fail Errors::BadRequest if response.status == 400
- 5
fail Errors::Unauthorized if response.status == 401
- 4
fail Errors::KeyNotFound if response.status == 404
- 3
fail Errors::Unprocessable if response.status == 422
- 2
body
end
end
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
module SearchKit
- 1
module Clients
- 1
class Populate
- 1
attr_reader :connection, :token
- 1
def initialize
- 20
uri = [SearchKit.config.app_uri, "populate"].join("/")
- 20
@connection = Faraday.new(uri)
- 20
@token = SearchKit.config.app_token
end
- 1
def create(slug, documents)
- 6
documents = documents.map do |document|
- 6
{ type: 'documents', attributes: document }
end
- 6
params = { token: token, data: documents }
- 6
response = connection.post(slug, params)
- 6
body = JSON.parse(response.body, symbolize_names: true)
- 6
fail Errors::BadRequest if response.status == 400
- 5
fail Errors::Unauthorized if response.status == 401
- 4
fail Errors::IndexNotFound if response.status == 404
- 3
fail Errors::Unprocessable if response.status == 422
- 2
body
end
- 1
def update(slug, documents)
- 6
documents = documents.map do |document|
{
type: 'documents',
id: document.fetch(:id, nil),
attributes: document
- 6
}
end
- 6
params = { token: token, data: documents }
- 6
response = connection.patch(slug, params)
- 6
body = JSON.parse(response.body, symbolize_names: true)
- 6
fail Errors::BadRequest if response.status == 400
- 5
fail Errors::Unauthorized if response.status == 401
- 4
fail Errors::IndexNotFound if response.status == 404
- 3
fail Errors::Unprocessable if response.status == 422
- 2
body
end
- 1
def delete(slug, ids)
- 6
documents = ids.map do |id|
- 6
{ type: 'documents', id: id, attributes: { id: id } }
end
- 6
params = { token: token, data: documents }
- 6
response = connection.delete(slug, params)
- 6
body = JSON.parse(response.body, symbolize_names: true)
- 6
fail Errors::BadRequest if response.status == 400
- 5
fail Errors::Unauthorized if response.status == 401
- 4
fail Errors::IndexNotFound if response.status == 404
- 3
fail Errors::Unprocessable if response.status == 422
- 2
body
end
end
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
module SearchKit
- 1
module Clients
- 1
class Scaffold
- 1
attr_reader :connection, :token
- 1
def initialize
- 12
uri = [SearchKit.config.app_uri, "scaffold"].join("/")
- 12
@connection = Faraday.new(uri)
- 12
@token = SearchKit.config.app_token
end
- 1
def create(name, documents)
- 5
options = {
token: token,
data: {
type: 'indices',
attributes: { name: name },
relationships: { documents: documents }
}
}
- 5
response = connection.post('', options)
- 5
body = JSON.parse(response.body, symbolize_names: true)
- 5
fail Errors::BadRequest if response.status == 400
- 4
fail Errors::Unauthorized if response.status == 401
- 3
fail Errors::Unprocessable if response.status == 422
- 2
body
end
end
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
module SearchKit
- 1
module Clients
- 1
class Search
- 1
attr_reader :connection, :token
- 1
def initialize
- 16
uri = [SearchKit.config.app_uri, "search"].join("/")
- 16
@connection = Faraday.new(uri)
- 16
@token = SearchKit.config.app_token
end
- 1
def search(slug, options)
- 7
params = {
token: token, data: { type: "searches", attributes: options }
}
- 7
response = connection.post(slug, params)
- 7
body = JSON.parse(response.body, symbolize_names: true)
- 7
fail Errors::BadRequest if response.status == 400
- 6
fail Errors::Unauthorized if response.status == 401
- 5
fail Errors::IndexNotFound if response.status == 404
- 4
fail Errors::Unprocessable if response.status == 422
- 3
SearchKit::Models::Search.new(body.fetch(:data, {}))
end
end
end
end
- 1
require 'faraday'
- 1
require 'json'
- 1
module SearchKit
- 1
module Clients
- 1
class Subscribers
- 1
attr_reader :connection, :token
- 1
def initialize
- 29
uri = [ SearchKit.config.app_uri, "subscribers" ].join("/")
- 29
@connection = Faraday.new(uri)
- 29
@token = SearchKit.config.app_token
end
- 1
def create(options = {})
- 5
options = { data: { type: 'subscribers', attributes: options } }
- 5
response = connection.post("", options)
- 5
body = JSON.parse(response.body, symbolize_names: true)
- 5
fail Errors::BadRequest if response.status == 400
- 4
fail Errors::Unprocessable if response.status == 422
- 3
SearchKit::Models::Subscriber.new body.fetch(:data, {})
end
- 1
def info
- 5
response = connection.get("", token: token)
- 5
body = JSON.parse(response.body, symbolize_names: true)
- 5
fail Errors::Unauthorized if response.status == 401
- 4
fail Errors::SubscriberNotFound if response.status == 404
- 3
SearchKit::Models::Subscriber.new body.fetch(:data, {})
end
- 1
def update(options = {})
- 7
options = {
token: token, data: { type: 'subscribers', attributes: options }
}
- 7
response = connection.patch("", options)
- 7
body = JSON.parse(response.body, symbolize_names: true)
- 7
fail Errors::BadRequest if response.status == 400
- 6
fail Errors::Unauthorized if response.status == 401
- 5
fail Errors::SubscriberNotFound if response.status == 404
- 4
fail Errors::Unprocessable if response.status == 422
- 3
SearchKit::Models::Subscriber.new body.fetch(:data, {})
end
end
end
end
- 1
require 'ostruct'
- 1
require 'yaml'
- 1
require 'user_config'
- 1
module SearchKit
- 1
module Configuration
- 1
def configure
- 3
yield(config) if block_given?
end
- 1
def config
- 557
return @config if @config
- 2
root = UserConfig.new(".search-kit")
- 2
yaml = root['config.yml']
- 2
config = OpenStruct.new
- 6
yaml.each { |key, value| config.send("#{key}=", value) }
- 2
@config = config
end
- 1
def set_config(key, value)
root = UserConfig.new(".search-kit")
yaml = root['config.yml']
yaml[key] = value
yaml.save
end
- 1
def show_config(key)
- 5
root = UserConfig.new(".search-kit")
- 5
root['config.yml'][key]
end
- 1
def fetch(key)
- 5
ENV.fetch(key, show_config(key.downcase) || default(key.to_sym))
end
- 1
private
- 1
def default(key)
- 4
default_table = {
APP_URI: "http://localhost:8080",
APP_ENV: "development",
APP_DIR: default_app_dir,
APP_VERBOSE: true,
LOG_DIR: default_log_dir
}.fetch(key, nil)
end
- 1
def default_app_dir
- 8
File.expand_path("../../", __dir__)
end
- 1
def default_log_dir
- 4
log_dir = File.join(default_app_dir, 'log')
- 4
Dir.mkdir(log_dir) unless Dir.exist?(log_dir)
- 4
log_dir
end
end
end
- 1
module SearchKit
- 1
module Errors
- 1
class BadRequest < StandardError; end
- 1
class EventNotFound < StandardError; end
- 1
class IndexNotFound < StandardError; end
- 1
class KeyNotFound < StandardError; end
- 1
class PublicationFailed < StandardError; end
- 1
class SubscriberNotFound < StandardError; end
- 1
class Unauthorized < StandardError; end
- 1
class Unprocessable < StandardError; end
end
end
- 1
require 'forwardable'
- 1
module SearchKit
# The SearchKit logger, handled in its own class mainly for the purpose
# of allowing the daemonized process to quickly and cleanly reinitialize its
# connection to logfiles even after its process has been decoupled.
#
- 1
class Logger
- 1
extend Forwardable
- 1
attr_reader :logger
- 1
def_delegators :logger, :info, :warn
- 1
def initialize
- 1
environment = SearchKit.config.app_env
- 1
loginfo = [
SearchKit.config.log_dir,
"search-kit-#{environment}.log"
]
- 1
logpath = File.join(*loginfo)
- 1
default = ::Logger.new(logpath, "daily")
- 1
@logger = SearchKit.config.logger || default
end
end
end
- 1
require 'ansi'
- 1
module SearchKit
- 1
class Messages
- 1
autoload :Messaging, 'search_kit/messages/messaging'
- 1
include Messaging
- 1
def unauthorized
warning(I18n.t('http.401'))
end
- 1
def bad_request
warning(I18n.t('http.400'))
end
- 1
def not_found(type = 'Resource')
message = I18n.t('http.404', type: type)
warning(message)
end
- 1
def json_parse_error(type = 'Argument')
message = I18n.t('cli.errors.json_parse', type: type)
warning(message)
end
- 1
def no_service
message = I18n.t('cli.errors.no_service', uri: SearchKit.config.app_uri)
warning(message)
end
- 1
def unprocessable
warning(I18n.t('http.422'))
end
- 1
def unreadable(error)
warning(I18n.t('cli.errors.unreadable', error: error))
end
end
end
- 1
require 'ansi'
- 1
module SearchKit
- 1
class Messages
# The goal of the Messaging module is to provide an easy to include internal
# interface which will allow a SearchKit gem to dutifully log and provide
# output of what it's up to and how it may be doing.
#
- 1
module Messaging
- 1
def info(message)
- 23
Message.new(message).info
end
- 1
def warning(message)
- 2
Message.new(message).warn
end
- 1
def prompt(message)
Message.new(message).prompt
end
- 1
def password_prompt(message)
Message.new(message).password_prompt
end
- 1
private
# Most of the logic for the Messaging module exists in this (not so)
# private class. This lets more complex handling of message logic enter
# into the module gracefully, for example silence or logging level.
#
- 1
class Message
- 1
attr_reader :cli, :message
- 1
def initialize(message)
- 25
@message = message
- 25
@cli = HighLine.new
end
- 1
def warn
- 2
Kernel.warn(Prefixed(message.ansi(:red))) if SearchKit.config.verbose
- 2
SearchKit.logger.warn message
end
- 1
def info
- 23
Kernel.puts(Prefixed(message.ansi(:cyan))) if SearchKit.config.verbose
- 23
SearchKit.logger.info message
end
- 1
def prompt
cli.ask(Prefixed(message.ansi(:cyan)))
end
- 1
def password_prompt
cli.ask(Prefixed(message.ansi(:cyan))) do |prompt|
prompt.echo = '*'
end
end
- 1
private
- 1
def Prefixed(*messages)
- 4
Prefixed.new.join(*messages)
end
- 1
class Prefixed
- 1
attr_reader :body
- 1
def initialize
- 4
env = SearchKit.config.app_env.to_s.ansi(:magenta)
- 4
@body = "--> [ #{env} ]: "
end
- 1
def join(*messages)
- 4
[body, *messages].join(" ")
end
end
end
end
end
end
- 1
require 'virtus'
- 1
module SearchKit
- 1
module Models
- 1
autoload :Document, 'search_kit/models/document'
- 1
autoload :Documents, 'search_kit/models/documents'
- 1
autoload :Event, 'search_kit/models/event'
- 1
autoload :Events, 'search_kit/models/events'
- 1
autoload :Key, 'search_kit/models/key'
- 1
autoload :Keys, 'search_kit/models/keys'
- 1
autoload :Search, 'search_kit/models/search'
- 1
autoload :Subscriber, 'search_kit/models/subscriber'
end
end
- 1
module SearchKit
- 1
module Models
- 1
class Document
- 1
class AttributeNotFound < StandardError; end
- 1
include Virtus.model
- 1
attribute :id
- 1
attribute :source
- 1
attribute :score
- 1
def initialize(document_data = {})
- 5
attributes = document_data.fetch(:attributes, {})
super(
source: attributes,
id: attributes.fetch(:id, nil),
score: attributes.fetch(:score, nil)
- 5
)
end
- 1
def get(field)
- 2
source.fetch(field.to_sym)
rescue KeyError
- 1
fail AttributeNotFound, field
end
end
end
end
- 1
module SearchKit
- 1
module Models
- 1
class Documents
- 1
include Enumerable
- 1
def self.[](*arguments)
- 1
new(arguments)
end
- 1
attr_reader :contents, :member_class
- 1
def initialize(contents = [])
- 23
@contents = contents
- 23
@member_class = SearchKit::Models::Document
end
- 1
def <<(new_doc)
case new_doc
when Hash then contents << member_class.new(new_doc)
when member_class then contents << new_doc
else contents
end
end
- 1
def each(&block)
- 15
contents.each(&block)
end
end
end
end
- 1
module SearchKit
- 1
module Models
- 1
class Event
- 1
include Virtus.model
- 1
attribute :id
- 1
attribute :channel
- 1
attribute :state
- 1
attribute :payload, Hash
- 1
def initialize(event_data = {})
- 28
attributes = event_data.fetch(:attributes, {})
- 28
super(attributes)
end
end
end
end
- 1
module SearchKit
- 1
module Models
- 1
class Events
- 1
include Enumerable
- 1
def self.[](*arguments)
new(arguments)
end
- 1
attr_reader :contents, :member_class
- 1
def initialize(contents = [])
- 15
@contents = contents
- 15
@member_class = SearchKit::Models::Event
end
- 1
def <<(new_event)
case new_event
when Hash then contents << member_class.new(new_event)
when member_class then contents << new_event
else contents
end
end
- 1
def each(&block)
- 6
contents.each(&block)
end
end
end
end
- 1
require 'virtus'
- 1
module SearchKit
- 1
module Models
- 1
class Key
- 1
include Virtus.model
- 1
attribute :id, String
- 1
attribute :name, String
- 1
attribute :privilege, String
- 1
attribute :token, String
- 1
attribute :uri, String
- 1
def initialize(key_data = {})
- 20
attributes = key_data.fetch(:attributes, {})
- 20
uri = key_data.fetch(:links, {}).fetch(:self, '')
- 20
super(attributes.merge(uri: uri))
end
- 1
def creator?
- 7
privilege == 'creator'
end
end
end
end
- 1
module SearchKit
- 1
module Models
- 1
class Keys
- 1
include Enumerable
- 1
def self.[](*arguments)
- 1
new(arguments)
end
- 1
attr_reader :contents, :member_class
- 1
def initialize(contents = [])
- 41
@contents = contents
- 41
@member_class = SearchKit::Models::Key
end
- 1
def <<(new_key)
- 8
case new_key
when Hash then contents << member_class.new(new_key)
- 8
when member_class then contents << new_key
else contents
end
end
- 1
def each(&block)
- 16
contents.each(&block)
end
- 1
def creator
- 4
self.class.new(select(&:creator?))
end
- 1
def tokens
- 3
contents.map(&:token)
end
end
end
end
- 1
module SearchKit
- 1
module Models
- 1
class Search
- 1
include Virtus.model
- 1
attribute :time
- 1
attribute :results
- 1
attribute :documents, Models::Documents[Models::Document]
- 1
def initialize(search_data = {})
- 10
attributes = search_data.fetch(:attributes, {})
- 10
super attributes
end
end
end
end
- 1
require 'virtus'
- 1
module SearchKit
- 1
module Models
- 1
class Subscriber
- 1
include Virtus.model
- 1
attribute :email, String
- 1
attribute :id, String
- 1
attribute :keys, SearchKit::Models::Keys[SearchKit::Models::Key]
- 1
attribute :uri, String
- 1
def initialize(subscriber_data = {})
- 32
attributes = subscriber_data.fetch(:attributes, {})
- 32
keys = subscriber_data.fetch(:relationships, {}).fetch(:keys, [])
- 32
uri = subscriber_data.fetch(:links, {}).fetch(:self, '')
- 32
super(attributes.merge(uri: uri, keys: keys))
end
- 1
def creator_tokens
- 2
keys.creator.tokens
end
end
end
end
- 1
module SearchKit
# This file houses the polling loop of the Event service.
#
- 1
class Polling
- 1
autoload :Process, 'search_kit/polling/process'
- 1
def self.perform(channel, &block)
new(channel, &block).perform
end
- 1
attr_reader :block, :channel
- 1
def initialize(channel, &block)
- 3
@block = block
- 3
@channel = channel
end
- 1
def perform
loop do
process_queue
sleep 1
end
end
- 1
def process_queue
- 1
SearchKit::Polling::Process.perform(channel, &block)
end
end
end
- 1
module SearchKit
- 1
class Polling
# The logic of interacting with the event service to retrieve and process
# events is contained here.
#
- 1
class Process
- 1
def self.perform(channel, &block)
new(channel, &block).perform
end
- 1
attr_reader :block, :channel, :client
- 1
def initialize(channel, &block)
- 6
@block = block
- 6
@channel = channel
- 6
@client = SearchKit::Clients::Events.new
end
- 1
def perform
- 3
events.each do |event|
- 3
begin
- 3
block.call(event)
rescue
- 1
raise
else
- 2
client.complete(event.id)
end
end
end
- 1
private
- 1
def events
- 3
response = client.pending(channel)
- 6
response.fetch(:data, []).map { |raw| OpenStruct.new(raw) }
end
end
end
end
- 1
require 'thor'
- 1
class Thor
- 1
def self.document(task)
- 16
usage = I18n.t("cli.#{namespace}.#{task}.command")
- 16
summary = I18n.t("cli.#{namespace}.#{task}.summary")
- 16
detail = I18n.t("cli.#{namespace}.#{task}.detail")
- 16
desc(usage, summary)
- 16
long_desc(detail)
end
end
- 1
module SearchKit
- 1
def self.gem_version
- 1
Gem::Version.new(version_string)
end
- 1
def self.version_string
- 2
VERSION::STRING
end
# A convenience measure for easy and quick-to-read version changes and lookup.
#
- 1
module VERSION
- 1
MAJOR = 0
- 1
MINOR = 0
- 1
TINY = 6
- 1
PRE = nil
- 1
STRING = [ MAJOR, MINOR, TINY, PRE ].compact.join(".")
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::CLI::Documents do
- 25
let(:cli) { described_class.new }
- 15
let(:json) { response.to_json }
- 25
let(:response) { {} }
- 25
let(:slug) { "an-index-slug" }
- 1
subject { cli }
- 1
describe '#create' do
- 9
before { allow(cli.client).to receive(:create).and_return(response) }
- 9
subject { cli.create(slug, json) }
- 1
it "parses the given document json" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
it "calls client.create with the slug and document" do
- 1
expect(cli.client).to receive(:create).with(slug, {})
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(response.to_json)
- 1
subject
end
- 1
context 'when given bad json' do
- 2
let(:json) { "Arglebargle" }
- 1
it "reports an error" do
- 1
expect(cli.messages).to receive(:json_parse_error)
- 1
subject
end
end
- 1
context 'error handling' do
- 5
before { allow(cli.client).to receive(:create).and_raise(*error) }
- 1
context 'not found error' do
- 2
let(:error) { SearchKit::Errors::IndexNotFound }
- 1
it do
- 1
expect(cli.messages).to receive(:not_found)
- 1
subject
end
end
- 1
context 'bad request error' do
- 2
let(:error) { SearchKit::Errors::BadRequest }
- 1
it do
- 1
expect(cli.messages).to receive(:bad_request)
- 1
subject
end
end
- 1
context 'unprocessable error' do
- 2
let(:error) { SearchKit::Errors::Unprocessable }
- 1
it do
- 1
expect(cli.messages).to receive(:unprocessable)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
- 1
describe '#delete' do
- 5
let(:id) { 1 }
- 5
before { allow(cli.client).to receive(:delete).and_return(response) }
- 5
subject { cli.delete(slug, id) }
- 1
it "calls client.create with the slug and document" do
- 1
expect(cli.client).to receive(:delete).with(slug, id)
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(response.to_json)
- 1
subject
end
- 1
context 'error handling' do
- 3
before { allow(cli.client).to receive(:delete).and_raise(*error) }
- 1
context 'not found error' do
- 2
let(:error) { SearchKit::Errors::IndexNotFound }
- 1
it do
- 1
expect(cli.messages).to receive(:not_found)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
- 1
describe '#show' do
- 5
let(:id) { 1 }
- 5
before { allow(cli.client).to receive(:show).and_return(response) }
- 5
subject { cli.show(slug, id) }
- 1
it "calls client.create with the slug and document" do
- 1
expect(cli.client).to receive(:show).with(slug, id)
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(response.to_json)
- 1
subject
end
- 1
context 'error handling' do
- 3
before { allow(cli.client).to receive(:show).and_raise(*error) }
- 1
context 'not found error' do
- 2
let(:error) { SearchKit::Errors::IndexNotFound }
- 1
it do
- 1
expect(cli.messages).to receive(:not_found)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
- 1
describe '#update' do
- 9
let(:id) { 1 }
- 9
before { allow(cli.client).to receive(:update).and_return(response) }
- 9
subject { cli.update(slug, id, json) }
- 1
it "parses the given document json" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
it "calls client.create with the slug and document" do
- 1
expect(cli.client).to receive(:update).with(slug, id, {})
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(response.to_json)
- 1
subject
end
- 1
context 'when given bad json' do
- 2
let(:json) { "Arglebargle" }
- 1
it "reports an error" do
- 1
expect(cli.messages).to receive(:json_parse_error)
- 1
subject
end
end
- 1
context 'error handling' do
- 5
before { allow(cli.client).to receive(:update).and_raise(*error) }
- 1
context 'not found error' do
- 2
let(:error) { SearchKit::Errors::IndexNotFound }
- 1
it do
- 1
expect(cli.messages).to receive(:not_found)
- 1
subject
end
end
- 1
context 'bad request error' do
- 2
let(:error) { SearchKit::Errors::BadRequest }
- 1
it do
- 1
expect(cli.messages).to receive(:bad_request)
- 1
subject
end
end
- 1
context 'unprocessable error' do
- 2
let(:error) { SearchKit::Errors::Unprocessable }
- 1
it do
- 1
expect(cli.messages).to receive(:unprocessable)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::CLI::Events do
- 15
let(:channel) { "colon:separated:values" }
- 24
let(:cli) { described_class.new }
- 1
let(:json) { response.to_json }
- 1
let(:response) { {} }
- 17
let(:event) { SearchKit::Models::Event.new }
- 8
let(:events) { SearchKit::Models::Events.new }
- 1
let(:slug) { "an-index-slug" }
- 1
subject { cli }
- 1
describe '#complete' do
- 5
let(:id) { 1 }
- 5
before { allow(cli.client).to receive(:complete).and_return(event) }
- 5
subject { cli.complete(id) }
- 1
it "calls client.complete with the event id" do
- 1
expect(cli.client).to receive(:complete).with(id)
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(an_instance_of(String))
- 1
subject
end
- 1
context 'error handling' do
- 3
before { allow(cli.client).to receive(:complete).and_raise(*error) }
- 1
context 'not found error' do
- 2
let(:error) { SearchKit::Errors::EventNotFound }
- 1
it do
- 1
expect(cli.messages).to receive(:not_found)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
- 1
describe '#pending' do
- 1
before do
- 7
allow(cli.client).to receive(:index).and_return(events)
- 7
allow(cli.client).to receive(:pending).and_return(events)
end
- 8
subject { cli.pending(channel) }
- 1
context 'when given a channel' do
- 1
it "calls client.pending with the channel" do
- 1
expect(cli.client).to receive(:pending).with(channel)
- 1
subject
end
end
- 1
context 'otherwise' do
- 2
let(:channel) { nil }
- 1
it "calls client.index" do
- 1
expect(cli.client).to receive(:index)
- 1
subject
end
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(an_instance_of(String))
- 1
subject
end
- 1
context 'error handling' do
- 1
before do
- 4
allow(cli.client).to receive(:index).and_raise(*error)
- 4
allow(cli.client).to receive(:pending).and_raise(*error)
end
- 1
context 'not found error' do
- 2
let(:error) { SearchKit::Errors::Unauthorized }
- 1
it do
- 1
expect(cli.messages).to receive(:unauthorized)
- 1
subject
end
end
- 1
context 'bad request error' do
- 2
let(:error) { SearchKit::Errors::BadRequest }
- 1
it do
- 1
expect(cli.messages).to receive(:bad_request)
- 1
subject
end
end
- 1
context 'unprocessable error' do
- 2
let(:error) { SearchKit::Errors::Unprocessable }
- 1
it do
- 1
expect(cli.messages).to receive(:unprocessable)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
- 1
describe '#publish' do
- 8
let(:payload) { { one_fish: true, two_fish: true } }
- 9
let(:payload_json) { payload.to_json }
- 1
before do
- 8
allow(cli.client).to receive(:publish).and_return(event)
end
- 9
subject { cli.publish(channel, payload_json) }
- 1
it "parses the given document json" do
- 1
expect(JSON).to receive(:parse).with(payload_json, symbolize_names: true)
- 1
subject
end
- 1
it "calls client.create with the slug and document" do
- 1
expect(cli.client).to receive(:publish).with(channel, payload)
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(an_instance_of(String))
- 1
subject
end
- 1
context 'when given bad json' do
- 2
let(:payload) { "Arglebargle" }
- 1
it "reports an error" do
- 1
expect(cli.messages).to receive(:json_parse_error)
- 1
subject
end
end
- 1
context 'error handling' do
- 5
before { allow(cli.client).to receive(:publish).and_raise(*error) }
- 1
context 'not found error' do
- 2
let(:error) { SearchKit::Errors::Unauthorized }
- 1
it do
- 1
expect(cli.messages).to receive(:unauthorized)
- 1
subject
end
end
- 1
context 'bad request error' do
- 2
let(:error) { SearchKit::Errors::BadRequest }
- 1
it do
- 1
expect(cli.messages).to receive(:bad_request)
- 1
subject
end
end
- 1
context 'unprocessable error' do
- 2
let(:error) { SearchKit::Errors::Unprocessable }
- 1
it do
- 1
expect(cli.messages).to receive(:unprocessable)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
- 1
describe '#status' do
- 5
let(:id) { 1 }
- 5
before { allow(cli.client).to receive(:show).and_return(event) }
- 5
subject { cli.status(id) }
- 1
it "calls client.show with the event id" do
- 1
expect(cli.client).to receive(:show).with(id)
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(an_instance_of(String))
- 1
subject
end
- 1
context 'error handling' do
- 3
before { allow(cli.client).to receive(:show).and_raise(*error) }
- 1
context 'not found error' do
- 2
let(:error) { SearchKit::Errors::EventNotFound }
- 1
it do
- 1
expect(cli.messages).to receive(:not_found)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::CLI::Indices do
- 22
let(:cli) { described_class.new }
- 1
let(:json) { response.to_json }
- 22
let(:response) { {} }
- 17
let(:slug) { "an-index-slug" }
- 1
subject { cli }
- 1
describe '#archive' do
- 6
before { allow(cli.client).to receive(:archive).and_return(response) }
- 6
subject { cli.archive(slug) }
- 1
it "calls client.complete with the index slug" do
- 1
expect(cli.client).to receive(:archive).with(slug)
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(an_instance_of(String))
- 1
subject
end
- 1
context 'error handling' do
- 4
before { allow(cli.client).to receive(:archive).and_raise(*error) }
- 1
context 'unauthorized error' do
- 2
let(:error) { SearchKit::Errors::Unauthorized }
- 1
it do
- 1
expect(cli.messages).to receive(:unauthorized)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { SearchKit::Errors::IndexNotFound }
- 1
it do
- 1
expect(cli.messages).to receive(:not_found)
- 1
subject
end
end
- 1
context 'no service error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
- 1
describe '#create' do
- 6
let(:name) { "Index Name" }
- 6
before { allow(cli.client).to receive(:create).and_return(response) }
- 6
subject { cli.create(name) }
- 1
it "calls client.create with the index name" do
- 1
expect(cli.client).to receive(:create).with(name)
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(an_instance_of(String))
- 1
subject
end
- 1
context 'error handling' do
- 4
before { allow(cli.client).to receive(:create).and_raise(*error) }
- 1
context 'unauthorized error' do
- 2
let(:error) { SearchKit::Errors::Unauthorized }
- 1
it do
- 1
expect(cli.messages).to receive(:unauthorized)
- 1
subject
end
end
- 1
context 'unprocessable error' do
- 2
let(:error) { SearchKit::Errors::Unprocessable }
- 1
it do
- 1
expect(cli.messages).to receive(:unprocessable)
- 1
subject
end
end
- 1
context 'no service error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
- 1
describe '#show' do
- 6
before { allow(cli.client).to receive(:show).and_return(response) }
- 6
subject { cli.show(slug) }
- 1
it "calls client.show with the index slug" do
- 1
expect(cli.client).to receive(:show).with(slug)
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(an_instance_of(String))
- 1
subject
end
- 1
context 'error handling' do
- 4
before { allow(cli.client).to receive(:show).and_raise(*error) }
- 1
context 'unauthorized error' do
- 2
let(:error) { SearchKit::Errors::Unauthorized }
- 1
it do
- 1
expect(cli.messages).to receive(:unauthorized)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { SearchKit::Errors::IndexNotFound }
- 1
it do
- 1
expect(cli.messages).to receive(:not_found)
- 1
subject
end
end
- 1
context 'no service error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
- 1
describe '#update' do
- 7
let(:update) { { name: "New Name" } }
- 7
let(:update_json) { update.to_json }
- 7
before { allow(cli.client).to receive(:update).and_return(response) }
- 7
subject { cli.update(slug, update_json) }
- 1
it "calls client.update with the index slug and given json" do
- 1
expect(cli.client).to receive(:update).with(slug, update)
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(an_instance_of(String))
- 1
subject
end
- 1
context 'error handling' do
- 5
before { allow(cli.client).to receive(:update).and_raise(*error) }
- 1
context 'unauthorized error' do
- 2
let(:error) { SearchKit::Errors::Unauthorized }
- 1
it do
- 1
expect(cli.messages).to receive(:unauthorized)
- 1
subject
end
end
- 1
context 'unprocessable error' do
- 2
let(:error) { SearchKit::Errors::Unprocessable }
- 1
it do
- 1
expect(cli.messages).to receive(:unprocessable)
- 1
subject
end
end
- 1
context 'json error' do
- 2
let(:error) { JSON::ParserError }
- 1
it do
- 1
expect(cli.messages).to receive(:json_parse_error)
- 1
subject
end
end
- 1
context 'no service error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::CLI::Scaffolds do
- 7
let(:cli) { described_class.new }
- 1
let(:json) { response.to_json }
- 7
let(:response) { {} }
- 1
let(:slug) { "an-index-slug" }
- 1
subject { cli }
- 1
describe '#create' do
- 7
let(:documents) { [{ title: "Yep", id: 1 }] }
- 7
let(:documents_json) { documents.to_json }
- 7
let(:name) { "Index Name" }
- 7
before { allow(cli.client).to receive(:create).and_return(response) }
- 7
subject { cli.create(name, documents_json) }
- 1
it "calls client.create with the index name" do
- 1
expect(cli.client).to receive(:create).with(name, documents)
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(an_instance_of(String))
- 1
subject
end
- 1
context 'error handling' do
- 5
before { allow(cli.client).to receive(:create).and_raise(*error) }
- 1
context 'unauthorized error' do
- 2
let(:error) { SearchKit::Errors::Unauthorized }
- 1
it do
- 1
expect(cli.messages).to receive(:unauthorized)
- 1
subject
end
end
- 1
context 'unprocessable error' do
- 2
let(:error) { SearchKit::Errors::Unprocessable }
- 1
it do
- 1
expect(cli.messages).to receive(:unprocessable)
- 1
subject
end
end
- 1
context 'json error' do
- 2
let(:error) { JSON::ParserError }
- 1
it do
- 1
expect(cli.messages).to receive(:json_parse_error)
- 1
subject
end
end
- 1
context 'no service error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::CLI::Search do
- 8
let(:cli) { described_class.new }
- 1
let(:json) { response.to_json }
- 8
let(:phrase) { "Michael Jackson" }
- 8
let(:response) { SearchKit::Models::Search.new }
- 8
let(:slug) { "an-index-slug" }
- 1
subject { cli }
- 1
describe '#create' do
- 8
before { allow(cli.client).to receive(:search).and_return(response) }
- 8
subject { cli.create(slug, phrase) }
- 1
it "calls client.search with the slug, and phrase" do
- 1
expect(cli.client).to receive(:search).with(slug, phrase: phrase)
- 1
subject
end
- 1
it "reports on its results" do
- 1
expect(cli.messages).to receive(:info).with(an_instance_of(String)).twice
- 1
subject
end
- 1
context 'error handling' do
- 6
before { allow(cli.client).to receive(:search).and_raise(*error) }
- 1
context 'unauthorized error' do
- 2
let(:error) { SearchKit::Errors::Unauthorized }
- 1
it do
- 1
expect(cli.messages).to receive(:unauthorized)
- 1
subject
end
end
- 1
context 'unprocessable error' do
- 2
let(:error) { SearchKit::Errors::Unprocessable }
- 1
it do
- 1
expect(cli.messages).to receive(:unprocessable)
- 1
subject
end
end
- 1
context 'bad request error' do
- 2
let(:error) { SearchKit::Errors::BadRequest }
- 1
it do
- 1
expect(cli.messages).to receive(:bad_request)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { SearchKit::Errors::IndexNotFound }
- 1
it do
- 1
expect(cli.messages).to receive(:not_found)
- 1
subject
end
end
- 1
context 'no service error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::CLI::Subscribers do
- 11
let(:cli) { described_class.new }
- 11
let(:subscriber) { SearchKit::Models::Subscriber.new }
- 1
subject { cli }
- 1
describe '#create' do
- 6
let(:email) { "email@example.com" }
- 6
let(:password) { "password" }
- 6
before { allow(cli.client).to receive(:create).and_return(subscriber) }
- 6
subject { cli.create(email, password) }
- 1
it "calls create on the client with the given parameters" do
- 1
expect(cli.client)
.to receive(:create)
.with(email: email, password: password)
- 1
subject
end
- 1
it "sends a message that the subscriber has been created" do
- 1
expect(cli.messages).to receive(:info).with(an_instance_of(String))
- 1
subject
end
- 1
describe 'error handling' do
- 4
before { allow(cli.client).to receive(:create).and_raise(*error) }
- 1
context 'bad request error' do
- 2
let(:error) { SearchKit::Errors::BadRequest }
- 1
it do
- 1
expect(cli.messages).to receive(:bad_request)
- 1
subject
end
end
- 1
context 'unprocessable error' do
- 2
let(:error) { SearchKit::Errors::Unprocessable }
- 1
it do
- 1
expect(cli.messages).to receive(:unprocessable)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
- 1
describe '#info' do
- 6
before { allow(cli.client).to receive(:info).and_return(subscriber) }
- 6
subject { cli.info }
- 1
it "calls info on the client" do
- 1
expect(cli.client).to receive(:info)
- 1
subject
end
- 1
it "sends a message that the subscriber has been created" do
- 1
expect(cli.messages).to receive(:info).with(an_instance_of(String))
- 1
subject
end
- 1
describe 'error handling' do
- 4
before { allow(cli.client).to receive(:info).and_raise(*error) }
- 1
context 'unprocessable error' do
- 2
let(:error) { SearchKit::Errors::Unauthorized }
- 1
it do
- 1
expect(cli.messages).to receive(:unauthorized)
- 1
subject
end
end
- 1
context 'not found error' do
- 2
let(:error) { SearchKit::Errors::SubscriberNotFound }
- 1
it do
- 1
expect(cli.messages).to receive(:not_found)
- 1
subject
end
end
- 1
context 'no service error' do
- 2
let(:error) { [Faraday::ConnectionFailed, "Message"] }
- 1
it do
- 1
expect(cli.messages).to receive(:no_service)
- 1
subject
end
end
end
end
end
- 1
require 'ostruct'
- 1
require 'spec_helper'
- 1
describe SearchKit::Clients::Documents do
- 23
let(:body) { { data: [] } }
- 23
let(:client) { described_class.new }
- 21
let(:id) { 1 }
- 23
let(:json) { body.to_json }
- 23
let(:response) { OpenStruct.new(body: json, status: status) }
- 21
let(:slug) { "index-slug" }
- 11
let(:status) { 200 }
- 5
let(:token) { SearchKit.config.app_token }
- 1
before do
- 22
allow(client.connection).to receive(:delete).and_return(response)
- 22
allow(client.connection).to receive(:get).and_return(response)
- 22
allow(client.connection).to receive(:patch).and_return(response)
- 22
allow(client.connection).to receive(:post).and_return(response)
end
- 2
subject { client }
- 2
it { is_expected.to respond_to :token }
- 1
describe '#connection' do
- 2
subject { client.connection }
- 2
it { is_expected.to be_instance_of Faraday::Connection }
end
- 1
describe '#create' do
- 7
let(:document) { { id: id, title: "The first document" } }
- 1
let(:params) do
- 1
{ token: token, data: { type: "documents", attributes: document } }
end
- 7
subject { client.create(slug, document) }
- 1
it "calls #connection.post with the base path and a document" do
- 1
expect(client.connection).to receive(:post).with(slug, params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when the response status is 400' do
- 2
let(:status) { 400 }
- 1
it "raises a bad request error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
end
end
- 1
context 'when the response status is 401' do
- 2
let(:status) { 401 }
- 1
it "raises a not authorized error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
- 1
context 'when the response status is 404' do
- 2
let(:status) { 404 }
- 1
it "raises an index not found error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
end
end
- 1
context 'when the response status is 422' do
- 2
let(:status) { 422 }
- 1
it "raises an unprocessable error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
end
end
end
- 1
describe '#delete' do
- 5
subject { client.delete(slug, id) }
- 1
it "calls #connection.get with the base events path" do
- 1
expect(client.connection)
.to receive(:delete)
.with("#{slug}/#{id}", token: token)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when the response status is 401' do
- 2
let(:status) { 401 }
- 1
it "raises a not authorized error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
- 1
context 'when the response status is 404' do
- 2
let(:status) { 404 }
- 1
it "raises an index not found error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
end
end
end
- 1
describe '#show' do
- 5
subject { client.show(slug, id) }
- 1
it "calls #connection.get with the given id" do
- 1
expect(client.connection)
.to receive(:get)
.with("#{slug}/#{id}", token: token)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when the response status is 401' do
- 2
let(:status) { 401 }
- 1
it "raises a not authorized error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
- 1
context 'when the response status is 404' do
- 2
let(:status) { 404 }
- 1
it "raises an index not found error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
end
end
end
- 1
describe '#update' do
- 7
let(:document) { { id: id, title: "The first document" } }
- 1
let(:params) do
{
token: token,
data: { type: "documents", id: id, attributes: document }
- 1
}
end
- 7
subject { client.update(slug, id, document) }
- 1
it "calls #connection.patch with the slug, id and document" do
- 1
expect(client.connection)
.to receive(:patch)
.with("#{slug}/#{id}", params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when the response status is 400' do
- 2
let(:status) { 400 }
- 1
it "raises a bad request error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
end
end
- 1
context 'when the response status is 401' do
- 2
let(:status) { 401 }
- 1
it "raises a not authorized error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
- 1
context 'when the response status is 422' do
- 2
let(:status) { 422 }
- 1
it "raises an unprocessable error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
end
end
- 1
context 'when the response status is 404' do
- 2
let(:status) { 404 }
- 1
it "raises an index not found error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
end
end
end
end
- 1
require 'ostruct'
- 1
require 'spec_helper'
- 1
describe SearchKit::Clients::Events do
- 26
let(:client) { described_class.new }
- 10
let(:id) { 1 }
- 26
let(:hash) { {} }
- 26
let(:json) { hash.to_json }
- 26
let(:response) { OpenStruct.new(status: status, body: json) }
- 17
let(:status) { 200 }
- 6
let(:token) { SearchKit.config.app_token }
- 1
before do
- 25
allow(client.connection).to receive(:delete).and_return(response)
- 25
allow(client.connection).to receive(:get).and_return(response)
- 25
allow(client.connection).to receive(:post).and_return(response)
- 25
allow(JSON).to receive(:parse).and_return(hash)
end
- 2
subject { client }
- 2
it { is_expected.to respond_to :token }
- 1
describe '#connection' do
- 2
subject { client.connection }
- 2
it { is_expected.to be_instance_of Faraday::Connection }
end
- 1
describe '#complete' do
- 6
subject { client.complete(id) }
- 2
it { is_expected.to be_instance_of SearchKit::Models::Event }
- 1
it "calls #connection.get with the base events path" do
- 1
expect(client.connection).to receive(:delete).with(id, token: token)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
- 1
context 'when given status 404' do
- 2
let(:status) { 404 }
- 1
it do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::EventNotFound)
end
end
end
- 1
describe '#index' do
- 5
subject { client.index }
- 2
it { is_expected.to be_instance_of SearchKit::Models::Events }
- 1
it "calls #connection.get with the base events path" do
- 1
expect(client.connection).to receive(:get).with(token: token)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
end
- 1
describe '#pending' do
- 5
let(:channel) { "colon:separated:string" }
- 5
subject { client.pending(channel) }
- 2
it { is_expected.to be_instance_of SearchKit::Models::Events }
- 1
it "calls #connection.get with the base events path" do
- 1
expect(client.connection)
.to receive(:get)
.with('', "filter[channel]" => channel, token: token)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
end
- 1
describe '#publish' do
- 7
let(:channel) { "colon:separated:string" }
- 1
let(:options) { { channel: channel, payload: payload } }
- 1
let(:payload) do
- 6
{ one_key: true, two_key: true, red_key: true, blue_key: true }
end
- 1
let(:params) do
{
token: token,
data: {
type: 'events',
attributes: { channel: channel, payload: payload }
}
- 1
}
end
- 7
subject { client.publish(channel, payload) }
- 2
it { is_expected.to be_instance_of SearchKit::Models::Event }
- 1
it "calls #connection.get with the base events path" do
- 1
expect(client.connection).to receive(:post).with('', params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 400' do
- 2
let(:status) { 400 }
- 1
it do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
end
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
- 1
context 'when given status 404' do
- 2
let(:status) { 422 }
- 1
it do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
end
end
end
- 1
describe '#show' do
- 5
subject { client.show(id) }
- 1
it "calls #connection.get with the base events path / id" do
- 1
expect(client.connection).to receive(:get).with(id, token: token)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
- 1
context 'when given status 404' do
- 2
let(:status) { 404 }
- 1
it do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::EventNotFound)
end
end
end
end
- 1
require 'ostruct'
- 1
require 'spec_helper'
- 1
describe SearchKit::Clients::Indices do
- 22
let(:json) { response_body.to_json }
- 22
let(:response) { OpenStruct.new(status: status, body: json) }
- 11
let(:status) { 200 }
- 22
let(:client) { described_class.new }
- 22
let(:response_body) { { data: [] } }
- 5
let(:token) { SearchKit.config.app_token }
- 1
before do
- 21
allow(client.connection).to receive(:delete).and_return(response)
- 21
allow(client.connection).to receive(:get).and_return(response)
- 21
allow(client.connection).to receive(:patch).and_return(response)
- 21
allow(client.connection).to receive(:post).and_return(response)
end
- 2
subject { client }
- 2
it { is_expected.to respond_to :token }
- 1
describe '#connection' do
- 2
subject { client.connection }
- 2
it { is_expected.to be_instance_of Faraday::Connection }
end
- 1
describe '#archive' do
- 5
let(:slug) { "slug" }
- 5
subject { client.archive(slug) }
- 1
it "calls #connection.delete with given slug" do
- 1
expect(client.connection).to receive(:delete).with(slug, token: token)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it "throws an unauthorized error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
end
end
- 1
context 'when given status 404' do
- 2
let(:status) { 404 }
- 1
it "throws a not found error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::IndexNotFound
end
end
end
- 1
describe '#create' do
- 6
let(:name) { "name" }
- 1
let(:params) do
- 1
{ token: token, data: { type: 'indices', attributes: { name: name } } }
end
- 6
subject { client.create(name) }
- 1
it "calls #connection.post with given name" do
- 1
expect(client.connection).to receive(:post).with('', params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 400' do
- 2
let(:status) { 400 }
- 1
it "throws a Bad Request error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::BadRequest
end
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it "throws an unauthorized error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
end
end
- 1
context 'when given status 422' do
- 2
let(:status) { 422 }
- 1
it "throws an Unprocessable error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
end
end
end
- 1
describe '#show' do
- 5
let(:slug) { "slug" }
- 5
subject { client.show(slug) }
- 1
it "calls #connection.get with given slug" do
- 1
expect(client.connection).to receive(:get).with(slug, token: token)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it "throws an unauthorized error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
end
end
- 1
context 'when given status 404' do
- 2
let(:status) { 404 }
- 1
it "throws a not found error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::IndexNotFound
end
end
end
- 1
describe '#update' do
- 7
let(:new_name) { "New name" }
- 7
let(:slug) { "name" }
- 1
let(:params) do
{
token: token,
data: { type: 'indices', attributes: { name: new_name } }
- 1
}
end
- 7
subject { client.update(slug, name: new_name) }
- 1
it "calls #connection.patch with given slug and attributes" do
- 1
expect(client.connection).to receive(:patch).with(slug, params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 400' do
- 2
let(:status) { 400 }
- 1
it "throws a bad request error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::BadRequest
end
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it "throws an unauthorized error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
end
end
- 1
context 'when given status 404' do
- 2
let(:status) { 404 }
- 1
it "throws a not found error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::IndexNotFound
end
end
- 1
context 'when given status 422' do
- 2
let(:status) { 422 }
- 1
it "throws an unprocessable error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
end
end
end
end
- 1
require 'ostruct'
- 1
require 'spec_helper'
- 1
describe SearchKit::Clients::Keys do
- 25
let(:response) { OpenStruct.new(status: status, body: json) }
- 25
let(:json) { response_body.to_json }
- 13
let(:status) { 200 }
- 25
let(:client) { described_class.new }
- 25
let(:response_body) { { data: [] } }
- 6
let(:token) { SearchKit.config.app_token }
- 1
before do
- 24
allow(client.connection).to receive(:delete).and_return(response)
- 24
allow(client.connection).to receive(:get).and_return(response)
- 24
allow(client.connection).to receive(:patch).and_return(response)
- 24
allow(client.connection).to receive(:post).and_return(response)
end
- 2
subject { client }
- 2
it { is_expected.to respond_to :token }
- 1
describe '#connection' do
- 2
subject { client.connection }
- 2
it { is_expected.to be_instance_of Faraday::Connection }
end
- 1
describe '#create' do
- 6
let(:name) { "name" }
- 1
let(:params) do
- 1
{ token: token, data: { type: 'keys', attributes: { name: name } } }
end
- 6
subject { client.create(name) }
- 1
it "calls #connection.post with given name" do
- 1
expect(client.connection).to receive(:post).with('', params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 400' do
- 2
let(:status) { 400 }
- 1
it "throws a bad request error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::BadRequest
end
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it "throws an unauthorized error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
end
end
- 1
context 'when given status 422' do
- 2
let(:status) { 422 }
- 1
it "throws an unprocessable error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
end
end
end
- 1
describe '#expire' do
- 5
let(:id) { 1 }
- 5
subject { client.expire(id) }
- 1
it "calls #connection.delete with given slug" do
- 1
expect(client.connection).to receive(:delete).with(id, token: token)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it "throws an unauthorized error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
end
end
- 1
context 'when given status 404' do
- 2
let(:status) { 404 }
- 1
it "throws a not found error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::KeyNotFound
end
end
end
- 1
describe '#index' do
- 4
subject { client.index }
- 1
it "calls #connection.get" do
- 1
expect(client.connection).to receive(:get).with("", token: token)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it "throws an unauthorized error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
end
end
end
- 1
describe '#show' do
- 5
let(:id) { 1 }
- 5
subject { client.show(id) }
- 1
it "calls #connection.get with given id" do
- 1
expect(client.connection).to receive(:get).with(id, token: token)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it "throws an unauthorized error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
end
end
- 1
context 'when given status 404' do
- 2
let(:status) { 404 }
- 1
it "throws a not found error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::KeyNotFound
end
end
end
- 1
describe '#update' do
- 1
let(:name) { "name" }
- 7
let(:new_name) { "New name" }
- 7
let(:id) { 1 }
- 1
let(:params) do
{
token: token,
data: { type: 'keys', attributes: { name: new_name } }
- 1
}
end
- 7
subject { client.update(id, name: new_name) }
- 1
it "calls #connection.patch with given id and attributes" do
- 1
expect(client.connection).to receive(:patch).with(id, params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 400' do
- 2
let(:status) { 400 }
- 1
it "throws a bad request error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::BadRequest
end
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it "throws an unauthorized error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
end
end
- 1
context 'when given status 404' do
- 2
let(:status) { 404 }
- 1
it "throws a not found error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::KeyNotFound
end
end
- 1
context 'when given status 422' do
- 2
let(:status) { 422 }
- 1
it "throws an Unprocessable error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
end
end
end
end
- 1
require 'ostruct'
- 1
require 'spec_helper'
- 1
describe SearchKit::Clients::Populate do
- 21
let(:response) { OpenStruct.new(status: status, body: json) }
- 21
let(:json) { response_body.to_json }
- 9
let(:status) { 200 }
- 21
let(:client) { described_class.new }
- 19
let(:id) { 1 }
- 21
let(:response_body) { { data: [] } }
- 19
let(:slug) { "an-index-slug" }
- 4
let(:token) { SearchKit.config.app_token }
- 1
before do
- 20
allow(client.connection).to receive(:delete).and_return(response)
- 20
allow(client.connection).to receive(:get).and_return(response)
- 20
allow(client.connection).to receive(:patch).and_return(response)
- 20
allow(client.connection).to receive(:post).and_return(response)
end
- 2
subject { client }
- 2
it { is_expected.to respond_to :token }
- 1
describe '#connection' do
- 2
subject { client.connection }
- 2
it { is_expected.to be_instance_of Faraday::Connection }
end
- 1
describe '#create' do
- 7
let(:document) { { id: id, title: "The first document" } }
- 7
let(:documents) { [document] }
- 1
let(:params) do
{
token: token,
data: [{ type: "documents", attributes: document }]
- 1
}
end
- 7
subject { client.create(slug, documents) }
- 1
it "calls #connection.post with the base path and a document" do
- 1
expect(client.connection).to receive(:post).with(slug, params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when the response status is 400' do
- 2
let(:status) { 400 }
- 1
it "raises a bad request error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
end
end
- 1
context 'when the response status is 401' do
- 2
let(:status) { 401 }
- 1
it "raises an index not found error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
- 1
context 'when the response status is 404' do
- 2
let(:status) { 404 }
- 1
it "raises an index not found error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
end
end
- 1
context 'when the response status is 422' do
- 2
let(:status) { 422 }
- 1
it "raises an unprocessable error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
end
end
end
- 1
describe '#update' do
- 7
let(:document) { { id: id, title: "The first document" } }
- 7
let(:documents) { [document] }
- 1
let(:params) do
{
token: token,
data: [{ type: "documents", id: id, attributes: document }]
- 1
}
end
- 7
subject { client.update(slug, documents) }
- 1
it "calls #connection.patch with the slug and documents" do
- 1
expect(client.connection).to receive(:patch).with(slug, params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when the response status is 400' do
- 2
let(:status) { 400 }
- 1
it "raises a bad request error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
end
end
- 1
context 'when the response status is 401' do
- 2
let(:status) { 401 }
- 1
it "raises an index not found error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
- 1
context 'when the response status is 404' do
- 2
let(:status) { 404 }
- 1
it "raises an index not found error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
end
end
- 1
context 'when the response status is 422' do
- 2
let(:status) { 422 }
- 1
it "raises an unprocessable error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
end
end
end
- 1
describe '#delete' do
- 1
let(:params) do
{
token: token,
data: [{ type: 'documents', id: id, attributes: { id: id } }]
- 1
}
end
- 7
subject { client.delete(slug, [id]) }
- 1
it "calls #connection.get with the correct params" do
- 1
expect(client.connection).to receive(:delete).with(slug, params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when the response status is 400' do
- 2
let(:status) { 400 }
- 1
it "raises a bad request error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
end
end
- 1
context 'when the response status is 401' do
- 2
let(:status) { 401 }
- 1
it "raises an index not found error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
- 1
context 'when the response status is 404' do
- 2
let(:status) { 404 }
- 1
it "raises an index not found error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
end
end
- 1
context 'when the response status is 422' do
- 2
let(:status) { 422 }
- 1
it "raises an unprocessable error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
end
end
end
end
- 1
require 'ostruct'
- 1
require 'spec_helper'
- 1
describe SearchKit::Clients::Scaffold do
- 7
let(:client) { described_class.new }
- 7
let(:json) { response_body.to_json }
- 7
let(:response_body) { { data: [] } }
- 7
let(:response) { OpenStruct.new(status: status, body: json) }
- 4
let(:status) { 200 }
- 2
let(:token) { SearchKit.config.app_token }
- 7
before { allow(client.connection).to receive(:post).and_return(response) }
- 2
subject { client }
- 2
it { is_expected.to respond_to :token }
- 1
describe '#create' do
- 6
let(:name) { "My Favorite Scaffolded Index" }
- 6
let(:documents) { [{ its: "A", plain: "Hash", with: "An", id: 1 }] }
- 1
let(:params) do
{
token: token,
data: {
type: 'indices',
attributes: { name: name },
relationships: { documents: documents }
}
- 1
}
end
- 6
subject { client.create(name, documents) }
- 1
it "calls #connection.post with given name" do
- 1
expect(client.connection).to receive(:post).with('', params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when gven status 400' do
- 2
let(:status) { 400 }
- 1
it "throws a bad request error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::BadRequest
end
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it "throws an unprocessable error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
end
end
- 1
context 'when given status 422' do
- 2
let(:status) { 422 }
- 1
it "throws an unprocessable error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
end
end
end
end
- 1
require 'ostruct'
- 1
require 'spec_helper'
- 1
describe SearchKit::Clients::Search do
- 10
let(:client) { described_class.new }
- 10
let(:json) { response_body.to_json }
- 10
let(:response_body) { { data: {} } }
- 10
let(:response) { OpenStruct.new(body: json, status: status) }
- 6
let(:status) { 200 }
- 2
let(:token) { SearchKit.config.app_token }
- 1
before do
- 9
allow(client.connection).to receive(:post).and_return(response)
- 9
allow(JSON).to receive(:parse).and_return(response_body)
end
- 2
subject { client }
- 2
it { is_expected.to respond_to :token }
- 1
describe '#connection' do
- 2
subject { client.connection }
- 2
it { is_expected.to be_instance_of Faraday::Connection }
end
- 1
describe '#search' do
- 8
let(:filters) { { size: 10.5, width: "Wide", gender: "Mens" } }
- 8
let(:options) { { phrase: phrase, filters: filters } }
- 8
let(:phrase) { "red boots" }
- 8
let(:slug) { "an-index-slug" }
- 1
let(:params) do
{
token: token,
data: { type: 'searches', attributes: options }
- 1
}
end
- 8
subject { client.search(slug, options) }
- 2
it { is_expected.to be_instance_of SearchKit::Models::Search }
- 1
it "calls #connection.get with the base events path" do
- 1
expect(client.connection).to receive(:post).with(slug, params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when the response status is 400' do
- 2
let(:status) { 400 }
- 1
it "raises a bad request error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
end
end
- 1
context 'when the response status is 401' do
- 2
let(:status) { 401 }
- 1
it "raises an unauthorized error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
end
end
- 1
context 'when the response status is 404' do
- 2
let(:status) { 404 }
- 1
it "raises an index not found error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
end
end
- 1
context 'when the response status is 422' do
- 2
let(:status) { 422 }
- 1
it "raises an unprocessable error" do
- 2
expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
end
end
end
end
- 1
require 'ostruct'
- 1
require 'spec_helper'
- 1
describe SearchKit::Clients::Subscribers do
- 20
let(:client) { described_class.new }
- 13
let(:email) { "email@example.com" }
- 20
let(:json) { response_body.to_json }
- 13
let(:password) { "password" }
- 20
let(:response_body) { { data: {} } }
- 20
let(:response) { OpenStruct.new(status: status, body: json) }
- 1
let(:subscriber) { SearchKit::Models::Subscriber.new }
- 12
let(:status) { 200 }
- 3
let(:token) { SearchKit.config.app_token }
- 1
before do
- 19
allow(client.connection).to receive(:get).and_return(response)
- 19
allow(client.connection).to receive(:patch).and_return(response)
- 19
allow(client.connection).to receive(:post).and_return(response)
- 19
allow(JSON).to receive(:parse).and_return(response_body)
end
- 2
subject { client }
- 2
it { is_expected.to respond_to :token }
- 1
describe '#connection' do
- 2
subject { client.connection }
- 2
it { is_expected.to be_instance_of Faraday::Connection }
end
- 1
describe '#create' do
- 1
let(:params) do
{
data: {
type: 'subscribers',
attributes: { email: email, password: password }
}
- 1
}
end
- 6
subject { client.create(email: email, password: password) }
- 2
it { is_expected.to be_instance_of SearchKit::Models::Subscriber }
- 1
it "calls #connection.post with given name" do
- 1
expect(client.connection).to receive(:post).with('', params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 400' do
- 2
let(:status) { 400 }
- 1
it "throws a bad request error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::BadRequest
end
end
- 1
context 'when given status 422' do
- 2
let(:status) { 422 }
- 1
it "throws an unprocessable error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
end
end
end
- 1
describe '#info' do
- 6
subject { client.info }
- 2
it { is_expected.to be_instance_of SearchKit::Models::Subscriber }
- 1
it "calls #connection.get" do
- 1
expect(client.connection).to receive(:get).with("", token: token)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it "throws an unauthorized error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
end
end
- 1
context 'when given status 404' do
- 2
let(:status) { 404 }
- 1
it "throws a not found error" do
- 2
expect { subject }
.to raise_exception SearchKit::Errors::SubscriberNotFound
end
end
end
- 1
describe '#update' do
- 1
let(:params) do
{
token: token,
data: {
type: 'subscribers',
attributes: { email: email, password: password }
}
- 1
}
end
- 8
subject { client.update(email: email, password: password) }
- 2
it { is_expected.to be_instance_of SearchKit::Models::Subscriber }
- 1
it "calls #connection.patch with given id and attributes" do
- 1
expect(client.connection).to receive(:patch).with("", params)
- 1
subject
end
- 1
it "parses the json response" do
- 1
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
- 1
subject
end
- 1
context 'when given status 400' do
- 2
let(:status) { 400 }
- 1
it "throws a bad request error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::BadRequest
end
end
- 1
context 'when given status 401' do
- 2
let(:status) { 401 }
- 1
it "throws a not found error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
end
end
- 1
context 'when given status 404' do
- 2
let(:status) { 404 }
- 1
it "throws a not found error" do
- 2
expect { subject }
.to raise_exception SearchKit::Errors::SubscriberNotFound
end
end
- 1
context 'when given status 422' do
- 2
let(:status) { 422 }
- 1
it "throws an Unprocessable error" do
- 2
expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
end
end
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::Configuration do
- 4
let(:klass) { Class.new }
- 4
before { klass.extend(described_class) }
- 3
subject { klass }
- 2
it { is_expected.to respond_to :config }
- 2
it { is_expected.to respond_to :configure }
- 1
describe "Arbitrary assignment" do
- 1
it "allows any arbitrary setting to hold a value" do
- 1
expect {
- 1
klass.configure do |config|
- 1
config.arbitrary_setting = "value"
end
- 2
}.to change { klass.config.arbitrary_setting }
.from(nil)
.to("value")
end
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::Messages do
- 5
let(:messages) { described_class.new }
- 5
let(:message) { "Just about any string" }
- 1
before do
- 4
SearchKit.config.verbose = true
- 4
allow(Kernel).to receive(:warn)
- 4
allow(Kernel).to receive(:puts)
- 4
allow(SearchKit.logger).to receive(:warn)
- 4
allow(SearchKit.logger).to receive(:info)
end
- 5
after { SearchKit.config.verbose = false }
- 1
describe "#info" do
- 3
subject { messages.info(message) }
- 1
it "warns in stderr" do
- 1
expect(Kernel).to receive(:puts)
- 1
subject
end
- 1
it "logs a warning" do
- 1
expect(SearchKit.logger).to receive(:info).with(message)
- 1
subject
end
end
- 1
describe "#warning" do
- 3
subject { messages.warning(message) }
- 1
it "warns in stderr" do
- 1
expect(Kernel).to receive(:warn)
- 1
subject
end
- 1
it "logs a warning" do
- 1
expect(SearchKit.logger).to receive(:warn).with(message)
- 1
subject
end
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::Models::Document do
- 5
let(:document_data) { {} }
- 6
let(:document) { described_class.new(document_data) }
- 4
subject { document }
- 2
it { is_expected.to respond_to :id }
- 2
it { is_expected.to respond_to :source }
- 2
it { is_expected.to respond_to :score }
- 1
describe '#get' do
- 3
let(:key) { :a_key }
- 3
subject { document.get(key) }
- 1
context 'when the source has the available content' do
- 2
let(:content) { :key_content }
- 2
let(:document_data) { { attributes: { key => content } } }
- 1
it "returns the content" do
- 1
expect(subject).to eq content
end
end
- 1
context 'otherwise' do
- 1
it "raises an attribute not found error" do
- 2
expect { subject }
.to raise_exception(described_class::AttributeNotFound)
end
end
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::Models::Documents do
- 3
let(:document_data) { [{}] }
- 3
let(:documents) { described_class.new(document_data) }
- 3
subject { documents }
- 2
it { is_expected.to respond_to :contents }
- 2
it { is_expected.to respond_to :each }
end
- 1
require 'spec_helper'
- 1
describe SearchKit::Models::Event do
- 5
let(:event_data) { {} }
- 5
let(:event) { described_class.new(event_data) }
- 5
subject { event }
- 2
it { is_expected.to respond_to :id }
- 2
it { is_expected.to respond_to :channel }
- 2
it { is_expected.to respond_to :payload }
- 2
it { is_expected.to respond_to :state }
end
- 1
require 'spec_helper'
- 1
describe SearchKit::Models::Events do
- 3
let(:event_data) { [{}] }
- 3
let(:events) { described_class.new(event_data) }
- 3
subject { events }
- 2
it { is_expected.to respond_to :contents }
- 2
it { is_expected.to respond_to :each }
end
- 1
require 'spec_helper'
- 1
describe SearchKit::Models::Key do
- 7
let(:model) { described_class.new }
- 5
subject { model }
- 2
it { is_expected.to be_instance_of SearchKit::Models::Key }
- 2
it { is_expected.to respond_to :uri }
- 2
it { is_expected.to respond_to :token }
- 2
it { is_expected.to respond_to :name }
- 1
describe '#creator?' do
- 3
subject { model.creator? }
- 1
context 'when #privilege is set to "creator"' do
- 2
before { model.privilege = 'creator' }
- 2
it { is_expected.to be true }
end
- 1
context 'otherwise' do
- 2
it { is_expected.to be false }
end
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::Models::Keys do
- 1
let(:creator_key) do
- 3
SearchKit::Models::Key.new(
attributes: {
privilege: 'creator',
token: creator_token
}
)
end
- 1
let(:consumer_key) do
- 3
SearchKit::Models::Key.new(
attributes: {
privilege: 'consumer',
token: consumer_token
}
)
end
- 4
let(:creator_token) { "12345" }
- 4
let(:consumer_token) { "67890" }
- 4
let(:keys) { [ creator_key, consumer_key ] }
- 4
let(:model) { described_class.new(keys) }
- 1
subject { model }
- 1
describe "#creator" do
- 3
subject { model.creator }
- 2
it { is_expected.to be_instance_of described_class }
- 2
it { is_expected.to match described_class.new([creator_key]) }
end
- 1
describe "#tokens" do
- 2
subject { model.tokens }
- 2
it { is_expected.to match [creator_token, consumer_token] }
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::Models::Subscriber do
- 6
let(:model) { described_class.new }
- 4
subject { model }
- 2
it { is_expected.to respond_to :id }
- 2
it { is_expected.to respond_to :email }
- 2
it { is_expected.to respond_to :uri }
- 1
describe '#creator_tokens' do
- 2
subject { model.creator_tokens }
- 2
it { is_expected.to be_instance_of Array }
end
- 1
describe '#keys' do
- 2
subject { model.keys }
- 2
it { is_expected.to be_instance_of SearchKit::Models::Keys }
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::Polling::Process do
- 7
let(:block) { -> x { true } }
- 7
let(:channel) { "mail" }
- 7
let(:process) { described_class.new(channel, &block) }
- 4
subject { process }
- 2
it { is_expected.to respond_to :channel }
- 2
it { is_expected.to respond_to :client }
- 2
it { is_expected.to respond_to :block }
- 1
describe '#perform' do
- 4
let(:event_id) { 345 }
- 1
let(:event) do
{
data: [{
type: 'events',
id: event_id,
attributes: {
channel: channel,
payload: { id: event_id, title: "Gee willikers" }
}
}]
- 3
}
end
- 1
before do
- 3
allow(process.client).to receive(:pending).and_return(event)
- 3
allow(process.client).to receive(:complete)
end
- 4
subject { process.perform }
- 1
it "calls the block with every event" do
- 1
expect(process.block)
.to receive(:call)
.and_return(process.block)
.with(instance_of(OpenStruct))
.once
- 1
subject
end
- 1
it "completes the event" do
- 1
expect(process.client)
.to receive(:complete)
.with(event_id)
.once
- 1
subject
end
- 1
context "if something fails" do
- 1
let(:block) do
- 2
-> * { fail("Generic failure") }
end
- 1
it "raises an exception" do
- 2
expect { subject }.to raise_exception(StandardError)
end
end
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit::Polling do
- 4
let(:channel) { 'mail' }
- 5
let(:block) { Proc.new { |x| true } }
- 4
let(:service) { described_class.new(channel, &block) }
- 3
subject { service }
- 2
it { is_expected.to respond_to :channel }
- 2
it { is_expected.to respond_to :block }
- 1
describe '#process_queue' do
- 2
subject { service.process_queue }
- 1
it "performs a Process action" do
- 1
expect(SearchKit::Polling::Process)
.to receive(:perform)
.with(channel, &block)
- 1
subject
end
end
end
- 1
require 'spec_helper'
- 1
describe SearchKit do
- 1
it 'has a version number' do
- 1
expect(described_class.gem_version).not_to be nil
end
end