flying-sphinx 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ FLYING_SPHINX_IDENTIFIER=abc
2
+ FLYING_SPHINX_API_KEY=def
3
+ FLYING_SPHINX_SOCKETS_INSECURE=true
4
+ FLYING_SPHINX_SOCKETS_HOST=127.0.0.1
5
+ FLYING_SPHINX_SOCKETS_PORT=8080
data/.gitignore CHANGED
@@ -2,4 +2,5 @@
2
2
  Gemfile.lock
3
3
  *.tmproj
4
4
  *.sublime-*
5
+ gemfiles/*.lock
5
6
  pkg
@@ -1,4 +1,39 @@
1
+ language: ruby
1
2
  rvm:
2
3
  - 1.8.7
3
- - 1.9.2
4
4
  - ree
5
+ - 1.9.3
6
+ - 2.0
7
+ - 2.1.2
8
+ gemfile:
9
+ - gemfiles/rails_2.3.gemfile
10
+ - gemfiles/rails_3.0.gemfile
11
+ - gemfiles/rails_3.2.gemfile
12
+ - gemfiles/rails_4.0.gemfile
13
+ before_install:
14
+ - gem update --system
15
+ - gem install bundler
16
+ matrix:
17
+ exclude:
18
+ - rvm: 1.8.7
19
+ gemfile: gemfiles/rails_4.0.gemfile
20
+ - rvm: ree
21
+ gemfile: gemfiles/rails_4.0.gemfile
22
+ - rvm: 1.8.7
23
+ gemfile: gemfiles/rails_3.2.gemfile
24
+ - rvm: ree
25
+ gemfile: gemfiles/rails_3.2.gemfile
26
+ - rvm: 1.9.3
27
+ gemfile: gemfiles/rails_2.3.gemfile
28
+ - rvm: 2.0
29
+ gemfile: gemfiles/rails_2.3.gemfile
30
+ - rvm: 2.1.2
31
+ gemfile: gemfiles/rails_2.3.gemfile
32
+ - rvm: 1.9.3
33
+ gemfile: gemfiles/rails_3.0.gemfile
34
+ - rvm: 2.0
35
+ gemfile: gemfiles/rails_3.0.gemfile
36
+ - rvm: 2.1.2
37
+ gemfile: gemfiles/rails_3.0.gemfile
38
+ cache: bundler
39
+ script: bundle exec rspec
@@ -0,0 +1,23 @@
1
+ if RUBY_VERSION.to_f <= 1.8
2
+ appraise 'rails-2.3' do
3
+ gem 'rails', '~> 2.3.18'
4
+ gem 'faraday', '0.7.0'
5
+ gem 'riddle', '< 2.0.0'
6
+ end
7
+
8
+ appraise 'rails-3.0' do
9
+ gem 'rails', '~> 3.0.20'
10
+ gem 'faraday', '~> 0.8.0'
11
+ gem 'riddle', '< 2.0.0'
12
+ end
13
+ else
14
+ appraise 'rails-3.2' do
15
+ gem 'rails', '~> 3.2.18'
16
+ gem 'faraday', '~> 0.8.0'
17
+ end
18
+
19
+ appraise 'rails-4.0' do
20
+ gem 'rails', '~> 4.0.5'
21
+ gem 'faraday', '~> 0.9.0'
22
+ end
23
+ end
data/Gemfile CHANGED
@@ -1,3 +1,21 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem 'activesupport', '< 4.0.0' if RUBY_VERSION.to_f <= 1.8
6
+ gem 'riddle', '< 2.0.0' if RUBY_VERSION.to_f <= 1.8
7
+
8
+ if RUBY_VERSION.to_f <= 1.8
9
+ gem "public_suffix", "< 1.4.0"
10
+ elsif RUBY_VERSION.to_f <= 1.9
11
+ gem "public_suffix", "< 1.5.0"
12
+ elsif RUBY_VERSION.to_f <= 2.0
13
+ gem "public_suffix", "< 1.5.0"
14
+ else
15
+ gem "public_suffix"
16
+ end
17
+
18
+ gem 'appraisal', '~> 1.0.0',
19
+ :git => 'git://github.com/thoughtbot/appraisal',
20
+ :branch => 'master',
21
+ :ref => 'bd6eef4b6a'
data/Rakefile CHANGED
@@ -1,27 +1 @@
1
- require 'rubygems'
2
- begin
3
- require 'bundler'
4
- Bundler::GemHelper.install_tasks
5
- rescue LoadError
6
- puts "Although not required, it's recommended you use bundler during development"
7
- end
8
-
9
- require 'rake'
10
-
11
- task :default => :test
12
- task :test => :spec
13
-
14
- require 'rspec/core/rake_task'
15
-
16
- RSpec::Core::RakeTask.new do |t|
17
- t.pattern = 'spec/**/*_spec.rb'
18
- end
19
-
20
- RSpec::Core::RakeTask.new(:rspec) do |t|
21
- t.pattern = 'spec/**/*_spec.rb'
22
- t.rcov = true
23
- t.rcov_opts = [
24
- '--exclude', 'spec', '--exclude', 'gems',
25
- '--exclude', 'riddle', '--exclude', 'ruby'
26
- ]
27
- end
1
+ require 'bundler/gem_tasks'
@@ -18,21 +18,15 @@ Gem::Specification.new do |s|
18
18
  s.executables = ['flying-sphinx']
19
19
 
20
20
  s.add_runtime_dependency 'thinking-sphinx'
21
- s.add_runtime_dependency 'riddle', ['>= 1.5.6']
22
- s.add_runtime_dependency 'multi_json', ['>= 1.3.0']
23
- s.add_runtime_dependency 'faraday', ['>= 0.9']
24
- s.add_runtime_dependency 'pusher-client', ['~> 0.3']
21
+ s.add_runtime_dependency 'riddle', '>= 1.5.6'
22
+ s.add_runtime_dependency 'multi_json', '>= 1.3.0'
23
+ s.add_runtime_dependency 'faraday', '>= 0.7'
24
+ s.add_runtime_dependency 'pusher-client', '~> 0.3'
25
25
 
26
- s.add_development_dependency 'rake', ['~> 0.9.2']
27
- s.add_development_dependency 'rspec', ['~> 2.11']
28
- s.add_development_dependency 'rspec-fire', ['~> 1.1.0']
29
- s.add_development_dependency 'yajl-ruby', ['~> 0.8.2']
30
- s.add_development_dependency 'fakeweb', ['~> 1.3.0']
31
- s.add_development_dependency 'fakeweb-matcher', ['~> 1.2.2']
32
-
33
- s.post_install_message = <<-MESSAGE
34
- If you're upgrading, you should rebuild your Sphinx setup when deploying:
35
-
36
- $ heroku rake fs:rebuild
37
- MESSAGE
26
+ s.add_development_dependency 'dotenv', '~> 0.11.1'
27
+ s.add_development_dependency 'em-websocket', '~> 0.5.1'
28
+ s.add_development_dependency 'mysql2', '~> 0.3.15'
29
+ s.add_development_dependency 'rspec', '~> 2.14'
30
+ s.add_development_dependency 'rspec-retry', '~> 0.4'
31
+ s.add_development_dependency 'webmock', '~> 1.17.4'
38
32
  end
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "< 4.0.0"
6
+ gem "appraisal", "~> 1.0.0", :ref => "bd6eef4b6a", :git => "git://github.com/thoughtbot/appraisal", :branch => "master"
7
+ gem "rails", "~> 2.3.18"
8
+ gem "faraday", "0.7.0"
9
+ gem "websocket", "< 1.2.0"
10
+ gem "riddle", "< 2.0.0"
11
+ if RUBY_VERSION.to_f <= 1.8
12
+ gem "public_suffix", "< 1.4.0"
13
+ elsif RUBY_VERSION.to_f <= 1.9
14
+ gem "public_suffix", "< 1.5.0"
15
+ elsif RUBY_VERSION.to_f <= 2.0
16
+ gem "public_suffix", "< 1.5.0"
17
+ else
18
+ gem "public_suffix"
19
+ end
20
+
21
+ gemspec :path => "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "< 4.0.0"
6
+ gem "appraisal", "~> 1.0.0", :ref => "bd6eef4b6a", :git => "git://github.com/thoughtbot/appraisal", :branch => "master"
7
+ gem "rails", "~> 3.0.20"
8
+ gem "faraday", "~> 0.8.0"
9
+ gem "websocket", "< 1.2.0"
10
+ gem "riddle", "< 2.0.0"
11
+ if RUBY_VERSION.to_f <= 1.8
12
+ gem "public_suffix", "< 1.4.0"
13
+ elsif RUBY_VERSION.to_f <= 1.9
14
+ gem "public_suffix", "< 1.5.0"
15
+ elsif RUBY_VERSION.to_f <= 2.0
16
+ gem "public_suffix", "< 1.5.0"
17
+ else
18
+ gem "public_suffix"
19
+ end
20
+
21
+ gemspec :path => "../"
@@ -0,0 +1,18 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "~> 1.0.0", :git => "git://github.com/thoughtbot/appraisal", :branch => "master", :ref => "bd6eef4b6a"
6
+ gem "rails", "~> 3.2.18"
7
+ gem "faraday", "~> 0.8.0"
8
+ if RUBY_VERSION.to_f <= 1.8
9
+ gem "public_suffix", "< 1.4.0"
10
+ elsif RUBY_VERSION.to_f <= 1.9
11
+ gem "public_suffix", "< 1.5.0"
12
+ elsif RUBY_VERSION.to_f <= 2.0
13
+ gem "public_suffix", "< 1.5.0"
14
+ else
15
+ gem "public_suffix"
16
+ end
17
+
18
+ gemspec :path => "../"
@@ -0,0 +1,18 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "~> 1.0.0", :git => "git://github.com/thoughtbot/appraisal", :branch => "master", :ref => "bd6eef4b6a"
6
+ gem "rails", "~> 4.0.5"
7
+ gem "faraday", "~> 0.9.0"
8
+ if RUBY_VERSION.to_f <= 1.8
9
+ gem "public_suffix", "< 1.4.0"
10
+ elsif RUBY_VERSION.to_f <= 1.9
11
+ gem "public_suffix", "< 1.5.0"
12
+ elsif RUBY_VERSION.to_f <= 2.0
13
+ gem "public_suffix", "< 1.5.0"
14
+ else
15
+ gem "public_suffix"
16
+ end
17
+
18
+ gemspec :path => "../"
@@ -1,9 +1,8 @@
1
1
  require 'logger'
2
2
 
3
3
  module FlyingSphinx
4
- module Translators
5
- #
6
- end
4
+ module Response; end
5
+ module Translators; end
7
6
 
8
7
  @logger = Logger.new(STDOUT)
9
8
  @logger.level = Logger::INFO
@@ -48,6 +47,10 @@ require 'flying_sphinx/setting_files'
48
47
  require 'flying_sphinx/sphinxql'
49
48
  require 'flying_sphinx/version'
50
49
 
50
+ require 'flying_sphinx/response/invalid'
51
+ require 'flying_sphinx/response/json'
52
+ require 'flying_sphinx/response/logger'
53
+
51
54
  if defined?(Rails) && defined?(Rails::Railtie)
52
55
  require 'flying_sphinx/railtie'
53
56
  elsif defined?(Rails) && defined?(Rails::Plugin)
@@ -62,7 +62,7 @@ class FlyingSphinx::Action
62
62
  def response
63
63
  attempts = 0
64
64
  @response ||= begin
65
- block.call
65
+ block.call.body
66
66
  rescue
67
67
  attempts += 1
68
68
  retry if attempts <= 3
@@ -72,7 +72,10 @@ class FlyingSphinx::Action
72
72
 
73
73
  def socket
74
74
  @socket ||= PusherClient::Socket.new FlyingSphinx::API::PUSHER_KEY,
75
- :encrypted => true
75
+ :encrypted => ENV['FLYING_SPHINX_SOCKETS_INSECURE'].nil?,
76
+ :ws_host => ENV['FLYING_SPHINX_SOCKETS_HOST'],
77
+ :wss_port => ENV['FLYING_SPHINX_SOCKETS_PORT'],
78
+ :ws_port => ENV['FLYING_SPHINX_SOCKETS_PORT']
76
79
  end
77
80
 
78
81
  def start
@@ -19,23 +19,17 @@ class FlyingSphinx::API
19
19
  end
20
20
 
21
21
  def get(path, data = {})
22
- log('GET', path, data) do
23
- connection.get do |request|
24
- request.url normalize_path(path), data
25
- end
22
+ connection.get do |request|
23
+ request.url normalize_path(path), data
26
24
  end
27
25
  end
28
26
 
29
27
  def post(path, data = {})
30
- log('POST', path, data) do
31
- connection.post normalize_path(path), data
32
- end
28
+ connection.post normalize_path(path), data
33
29
  end
34
30
 
35
31
  def put(path, data = {})
36
- log('PUT', path, data) do
37
- connection.put normalize_path(path), data
38
- end
32
+ connection.put normalize_path(path), data
39
33
  end
40
34
 
41
35
  private
@@ -63,18 +57,16 @@ class FlyingSphinx::API
63
57
  }
64
58
 
65
59
  Faraday.new(options) do |builder|
60
+ # Built-in middleware
66
61
  builder.request :multipart
67
62
  builder.request :url_encoded
68
- builder.adapter adapter
69
- end
70
- end
71
63
 
72
- def log(method, path, data = {}, option = {}, &block)
73
- FlyingSphinx.logger.debug "API Request: #{method} '#{path}'; params: #{data.inspect}"
74
- response = block.call
75
- FlyingSphinx.logger.debug "API Response: #{response.body.inspect}"
76
- raise 'Invalid Flying Sphinx credentials' if response.status == 403
64
+ # Local middleware
65
+ builder.use FlyingSphinx::Response::Logger
66
+ builder.use FlyingSphinx::Response::Invalid
67
+ builder.use FlyingSphinx::Response::JSON
77
68
 
78
- MultiJson.load response.body
69
+ builder.adapter adapter
70
+ end
79
71
  end
80
72
  end
@@ -28,20 +28,8 @@ class FlyingSphinx::Configuration
28
28
 
29
29
  attr_reader :identifier, :api_key
30
30
 
31
- def change(initial, expected)
32
- api.post(initial)
33
-
34
- response = api.get('daemon')
35
- while response['status'] == initial
36
- sleep 0.5
37
- response = api.get('daemon')
38
- end
39
-
40
- response['status'] == expected
41
- end
42
-
43
31
  def response_body
44
- @response_body ||= api.get '/'
32
+ @response_body ||= api.get('/').body
45
33
  end
46
34
 
47
35
  def identifier_from_env
@@ -78,6 +78,10 @@ class FlyingSphinx::Controller
78
78
  end
79
79
  end
80
80
 
81
+ def running?
82
+ true
83
+ end
84
+
81
85
  def sphinx_version
82
86
  '2.0.4'
83
87
  end
@@ -8,7 +8,7 @@ class FlyingSphinx::GzippedHash
8
8
  def to_gzipped_hash
9
9
  hash['gzip'] = 'true'
10
10
 
11
- keys.each { |key| hash[key] = gzip hash[key] }
11
+ keys.each { |key| hash[key] = gzip hash[key], key }
12
12
 
13
13
  hash
14
14
  end
@@ -23,11 +23,14 @@ class FlyingSphinx::GzippedHash
23
23
  keys
24
24
  end
25
25
 
26
- def gzip(string)
26
+ def gzip(string, key)
27
27
  io = StringIO.new 'w'
28
28
  writer = Zlib::GzipWriter.new io
29
29
  writer.write string
30
30
  writer.close
31
- Faraday::UploadIO.new StringIO.new(io.string, 'rb'), 'application/gzip'
31
+
32
+ Faraday::UploadIO.new(
33
+ StringIO.new(io.string, 'rb'), 'application/gzip', key
34
+ )
32
35
  end
33
36
  end
@@ -0,0 +1,7 @@
1
+ class FlyingSphinx::Response::Invalid < Faraday::Response::Middleware
2
+ def on_complete(environment)
3
+ return unless environment[:status] == 403
4
+
5
+ raise 'Invalid Flying Sphinx credentials'
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class FlyingSphinx::Response::JSON < Faraday::Response::Middleware
2
+ def on_complete(environment)
3
+ environment[:body] = MultiJson.load environment[:body]
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ class FlyingSphinx::Response::Logger < Faraday::Response::Middleware
2
+ extend Forwardable
3
+
4
+ def call(environment)
5
+ debug "API Request: #{environment[:method]} #{environment[:url]}"
6
+ debug "API Body: #{environment[:body].inspect}"
7
+
8
+ super
9
+ end
10
+
11
+ def on_complete(environment)
12
+ debug "API Status: #{environment[:status]}"
13
+ debug "API Response: #{environment[:body].inspect}"
14
+ end
15
+
16
+ private
17
+
18
+ def_delegators :logger, :debug
19
+
20
+ def logger
21
+ FlyingSphinx.logger
22
+ end
23
+ end
@@ -26,6 +26,6 @@ namespace :fs do
26
26
 
27
27
  desc "Stop, clear, configure, start then populate Sphinx"
28
28
  task :regenerate => :environment do
29
- FlyingSphinx::CLI.new('rebuild').regenerate
29
+ FlyingSphinx::CLI.new('regenerate').run
30
30
  end
31
31
  end
@@ -1,3 +1,3 @@
1
1
  module FlyingSphinx
2
- Version = '1.2.0'
2
+ Version = '1.2.1'
3
3
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Requesting customer information' do
4
+ let(:configuration) { FlyingSphinx::Configuration.new 'foo', 'bar' }
5
+
6
+ before :each do
7
+ stub_request(:get, 'https://flying-sphinx.com/api/my/app').to_return(
8
+ :status => 200,
9
+ :body => '{"server":"my.sphinx.server","port":9307}'
10
+ )
11
+ end
12
+
13
+ it { expect(configuration.host).to eq('my.sphinx.server') }
14
+ it { expect(configuration.port).to eq(9307) }
15
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Starting Sphinx' do
4
+ let(:cli) { FlyingSphinx::CLI.new 'start' }
5
+
6
+ before :each do
7
+ stub_request(:post, 'https://flying-sphinx.com/api/my/app/start').
8
+ to_return(:status => 200, :body => '{"id":429, "status":"OK"}')
9
+ end
10
+
11
+ it 'makes the request to the server', :retry => 3 do
12
+ expect { cli.run }.to be_successful_with 429
13
+ end
14
+ end
15
+
16
+ describe 'Stopping Sphinx', :retry => 3 do
17
+ let(:cli) { FlyingSphinx::CLI.new 'stop' }
18
+
19
+ before :each do
20
+ stub_request(:post, 'https://flying-sphinx.com/api/my/app/stop').
21
+ to_return(:status => 200, :body => '{"id":537, "status":"OK"}')
22
+ end
23
+
24
+ it 'makes the request to the server', :retry => 3 do
25
+ expect { cli.run }.to be_successful_with 537
26
+ end
27
+ end
@@ -1,6 +1,4 @@
1
- require 'light_spec_helper'
2
- require 'multi_json'
3
- require 'flying_sphinx/action'
1
+ require 'spec_helper'
4
2
 
5
3
  describe FlyingSphinx::Action do
6
4
  let(:action) { FlyingSphinx::Action.new 'abc123', 1, &block }
@@ -8,7 +6,7 @@ describe FlyingSphinx::Action do
8
6
  let(:socket) { double 'socket', :connect => true, :disconnect => true,
9
7
  :subscribe => true, :[] => channel, :connected => true }
10
8
  let(:channel) { double 'channel', :bind => true }
11
- let(:response) { {'status' => 'OK', 'id' => 748} }
9
+ let(:response) { double :body => {'status' => 'OK', 'id' => 748} }
12
10
  let(:logger) { double 'logger', :debug => true }
13
11
 
14
12
  before :each do
@@ -50,7 +48,7 @@ describe FlyingSphinx::Action do
50
48
  block.should_receive(:call).and_return(response)
51
49
 
52
50
  perform_and_complete action
53
- end
51
+ end if RUBY_VERSION.to_f > 1.8
54
52
 
55
53
  it "raises an error if the response's status is BLOCKED" do
56
54
  response.stub :status => 'BLOCKED'
@@ -1,19 +1,16 @@
1
- require 'light_spec_helper'
2
- require 'flying_sphinx/api'
3
- require 'flying_sphinx/version'
1
+ require 'spec_helper'
4
2
 
5
3
  describe FlyingSphinx::API do
6
4
  let(:api) { FlyingSphinx::API.new 'foo', 'bar', adapter }
7
- let(:faraday) { fire_class_double('Faraday', :new => connection) }
5
+ let(:faraday) { double('Faraday', :new => connection) }
8
6
  let(:adapter) { double('adapter') }
9
7
  let(:connection) { double('connection') }
10
8
  let(:logger) { double :debug => true }
11
9
  let(:response) { double :body => '', :status => 200 }
12
10
 
13
11
  before :each do
14
- faraday.as_replaced_constant
15
-
16
12
  stub_const 'MultiJson', double(:load => {})
13
+ stub_const 'Faraday', faraday
17
14
  FlyingSphinx.stub :logger => logger
18
15
  end
19
16
 
@@ -1,15 +1,14 @@
1
- require 'light_spec_helper'
2
- require 'flying_sphinx/configuration'
1
+ require 'spec_helper'
3
2
 
4
3
  describe FlyingSphinx::Configuration do
5
- let(:api) { fire_double('FlyingSphinx::API', :get => body) }
4
+ let(:api) { double 'FlyingSphinx::API', :get => double(:body => body) }
6
5
  let(:body) { {'server' => 'foo.bar.com', 'port' => 9319} }
7
6
  let(:api_key) { 'foo-bar-baz' }
8
7
  let(:identifier) { 'my-identifier' }
9
8
  let(:config) { FlyingSphinx::Configuration.new identifier, api_key }
10
9
 
11
10
  before :each do
12
- fire_class_double('FlyingSphinx::API', :new => api).as_replaced_constant
11
+ stub_const 'FlyingSphinx::API', double(:new => api)
13
12
  end
14
13
 
15
14
  describe '#host' do
@@ -1,8 +1,4 @@
1
- require 'light_spec_helper'
2
- require 'faraday'
3
- require 'flying_sphinx/controller'
4
- require 'flying_sphinx/configuration_options'
5
- require 'flying_sphinx/gzipped_hash'
1
+ require 'spec_helper'
6
2
 
7
3
  describe FlyingSphinx::Controller do
8
4
  let(:controller) { FlyingSphinx::Controller.new api }
@@ -1,16 +1,15 @@
1
- require 'light_spec_helper'
2
- require 'flying_sphinx/setting_files'
1
+ require 'spec_helper'
3
2
 
4
3
  describe FlyingSphinx::SettingFiles do
5
4
  let(:files) { FlyingSphinx::SettingFiles.new indices }
6
5
  let(:indices) { [] }
7
6
 
8
7
  def index_double(methods)
9
- fire_double 'Riddle::Configuration::Index', methods
8
+ double 'Riddle::Configuration::Index', methods
10
9
  end
11
10
 
12
11
  def source_double(methods)
13
- fire_double 'Riddle::Configuration::SQLSource', methods
12
+ double 'Riddle::Configuration::SQLSource', methods
14
13
  end
15
14
 
16
15
  describe '#to_hash' do
@@ -42,11 +41,11 @@ describe FlyingSphinx::SettingFiles do
42
41
  indices << index_double(
43
42
  setting => '/my/file/foo.txt /my/file/bar.txt')
44
43
 
45
- files.to_hash.should == {
46
- "#{setting}:foo.txt" => 'blah',
47
- "#{setting}:bar.txt" => 'blah',
48
- 'extra' => "#{setting}:foo.txt;#{setting}:bar.txt"
49
- }
44
+ files.to_hash["#{setting}:foo.txt"].should == 'blah'
45
+ files.to_hash["#{setting}:bar.txt"].should == 'blah'
46
+ files.to_hash['extra'].split(';').should =~ [
47
+ "#{setting}:foo.txt", "#{setting}:bar.txt"
48
+ ]
50
49
  end
51
50
  end
52
51
 
@@ -77,11 +76,11 @@ describe FlyingSphinx::SettingFiles do
77
76
  indices << index_double(:sources => [
78
77
  source_double(setting => '/my/file/foo.txt /my/file/bar.txt')])
79
78
 
80
- files.to_hash.should == {
81
- "#{setting}:foo.txt" => 'blah',
82
- "#{setting}:bar.txt" => 'blah',
83
- 'extra' => "#{setting}:foo.txt;#{setting}:bar.txt"
84
- }
79
+ files.to_hash["#{setting}:foo.txt"].should == 'blah'
80
+ files.to_hash["#{setting}:bar.txt"].should == 'blah'
81
+ files.to_hash['extra'].split(';').should =~ [
82
+ "#{setting}:foo.txt", "#{setting}:bar.txt"
83
+ ]
85
84
  end
86
85
  end
87
86
  end
@@ -1,13 +1,18 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
3
 
4
- require 'timeout'
5
- require 'thinking-sphinx'
4
+ require 'dotenv'
5
+ require 'webmock/rspec'
6
+ require 'em-websocket'
7
+
8
+ Dotenv.load '.env.test'
9
+ WebMock.disable_net_connect!
10
+
11
+ require 'thinking_sphinx'
6
12
  require 'flying_sphinx'
7
- require 'delayed_job'
8
13
 
9
- require 'fakeweb'
10
- require 'fakeweb_matcher'
14
+ unless FlyingSphinx.logger.level == Logger::DEBUG
15
+ FlyingSphinx.logger.level = Logger::WARN
16
+ end
11
17
 
12
- FakeWeb.allow_net_connect = false
13
- Delayed::Worker.backend = :active_record
18
+ Dir["spec/support/**/*.rb"].each { |file| require File.expand_path(file) }
@@ -0,0 +1,48 @@
1
+ class LocalPusher
2
+ attr_reader :connections
3
+
4
+ def initialize
5
+ @connections = []
6
+ end
7
+
8
+ def start
9
+ @server_thread ||= Thread.new do
10
+ EM.run { socket_server }
11
+ end
12
+ end
13
+
14
+ def stop
15
+ server_thread.kill
16
+ end
17
+
18
+ def send(event, data)
19
+ connections.each do |connection|
20
+ connection.send({
21
+ 'event' => event,
22
+ 'data' => data.to_json,
23
+ 'channel' => ENV['FLYING_SPHINX_IDENTIFIER']
24
+ }.to_json)
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :server_thread
31
+
32
+ def socket_server
33
+ EM::WebSocket.run(
34
+ :host => ENV['FLYING_SPHINX_SOCKETS_HOST'],
35
+ :port => ENV['FLYING_SPHINX_SOCKETS_PORT']
36
+ ) do |connection|
37
+ connection.onopen do |handshake|
38
+ connections << connection
39
+ connection.send({
40
+ 'event' => 'pusher:connection_established',
41
+ 'data' => {'socket_id' => 101}.to_json
42
+ }.to_json)
43
+ end
44
+
45
+ connection.onclose { connections.delete connection }
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,46 @@
1
+ class SuccessfulAction
2
+ attr_writer :result
3
+
4
+ def initialize(action_id)
5
+ @action_id = action_id
6
+ @result = nil
7
+ end
8
+
9
+ def matches?(block)
10
+ pusher.start
11
+ thread = Thread.new { call block }
12
+ sleep 1.0
13
+
14
+ pusher.send 'completion', 'id' => action_id
15
+ thread.join
16
+ pusher.stop
17
+
18
+ result
19
+ end
20
+
21
+ def failure_message_for_should
22
+ "Action failed"
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :action_id, :result
28
+
29
+ def call(block)
30
+ self.result = block.call
31
+ end
32
+
33
+ def pusher
34
+ @pusher ||= LocalPusher.new
35
+ end
36
+ end
37
+
38
+ module SuccessfulActionHelper
39
+ def be_successful_with(action_id)
40
+ SuccessfulAction.new action_id
41
+ end
42
+ end
43
+
44
+ RSpec.configure do |config|
45
+ config.include SuccessfulActionHelper
46
+ end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flying-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Pat Allan
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-03-30 00:00:00.000000000 Z
12
+ date: 2017-09-28 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: thinking-sphinx
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: riddle
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: multi_json
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
@@ -55,20 +62,23 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: faraday
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ! '>='
60
68
  - !ruby/object:Gem::Version
61
- version: '0.9'
69
+ version: '0.7'
62
70
  type: :runtime
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ! '>='
67
76
  - !ruby/object:Gem::Version
68
- version: '0.9'
77
+ version: '0.7'
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: pusher-client
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ~>
74
84
  - !ruby/object:Gem::Version
@@ -76,94 +86,107 @@ dependencies:
76
86
  type: :runtime
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ~>
81
92
  - !ruby/object:Gem::Version
82
93
  version: '0.3'
83
94
  - !ruby/object:Gem::Dependency
84
- name: rake
95
+ name: dotenv
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
99
  - - ~>
88
100
  - !ruby/object:Gem::Version
89
- version: 0.9.2
101
+ version: 0.11.1
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
107
  - - ~>
95
108
  - !ruby/object:Gem::Version
96
- version: 0.9.2
109
+ version: 0.11.1
97
110
  - !ruby/object:Gem::Dependency
98
- name: rspec
111
+ name: em-websocket
99
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
100
114
  requirements:
101
115
  - - ~>
102
116
  - !ruby/object:Gem::Version
103
- version: '2.11'
117
+ version: 0.5.1
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
107
122
  requirements:
108
123
  - - ~>
109
124
  - !ruby/object:Gem::Version
110
- version: '2.11'
125
+ version: 0.5.1
111
126
  - !ruby/object:Gem::Dependency
112
- name: rspec-fire
127
+ name: mysql2
113
128
  requirement: !ruby/object:Gem::Requirement
129
+ none: false
114
130
  requirements:
115
131
  - - ~>
116
132
  - !ruby/object:Gem::Version
117
- version: 1.1.0
133
+ version: 0.3.15
118
134
  type: :development
119
135
  prerelease: false
120
136
  version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
121
138
  requirements:
122
139
  - - ~>
123
140
  - !ruby/object:Gem::Version
124
- version: 1.1.0
141
+ version: 0.3.15
125
142
  - !ruby/object:Gem::Dependency
126
- name: yajl-ruby
143
+ name: rspec
127
144
  requirement: !ruby/object:Gem::Requirement
145
+ none: false
128
146
  requirements:
129
147
  - - ~>
130
148
  - !ruby/object:Gem::Version
131
- version: 0.8.2
149
+ version: '2.14'
132
150
  type: :development
133
151
  prerelease: false
134
152
  version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
135
154
  requirements:
136
155
  - - ~>
137
156
  - !ruby/object:Gem::Version
138
- version: 0.8.2
157
+ version: '2.14'
139
158
  - !ruby/object:Gem::Dependency
140
- name: fakeweb
159
+ name: rspec-retry
141
160
  requirement: !ruby/object:Gem::Requirement
161
+ none: false
142
162
  requirements:
143
163
  - - ~>
144
164
  - !ruby/object:Gem::Version
145
- version: 1.3.0
165
+ version: '0.4'
146
166
  type: :development
147
167
  prerelease: false
148
168
  version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
149
170
  requirements:
150
171
  - - ~>
151
172
  - !ruby/object:Gem::Version
152
- version: 1.3.0
173
+ version: '0.4'
153
174
  - !ruby/object:Gem::Dependency
154
- name: fakeweb-matcher
175
+ name: webmock
155
176
  requirement: !ruby/object:Gem::Requirement
177
+ none: false
156
178
  requirements:
157
179
  - - ~>
158
180
  - !ruby/object:Gem::Version
159
- version: 1.2.2
181
+ version: 1.17.4
160
182
  type: :development
161
183
  prerelease: false
162
184
  version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
163
186
  requirements:
164
187
  - - ~>
165
188
  - !ruby/object:Gem::Version
166
- version: 1.2.2
189
+ version: 1.17.4
167
190
  description: Hooks Thinking Sphinx into the Flying Sphinx service
168
191
  email: pat@freelancing-gods.com
169
192
  executables:
@@ -172,8 +195,10 @@ extensions: []
172
195
  extra_rdoc_files:
173
196
  - README.textile
174
197
  files:
198
+ - .env.test
175
199
  - .gitignore
176
200
  - .travis.yml
201
+ - Appraisals
177
202
  - Gemfile
178
203
  - HISTORY
179
204
  - LICENCE
@@ -181,6 +206,10 @@ files:
181
206
  - Rakefile
182
207
  - bin/flying-sphinx
183
208
  - flying-sphinx.gemspec
209
+ - gemfiles/rails_2.3.gemfile
210
+ - gemfiles/rails_3.0.gemfile
211
+ - gemfiles/rails_3.2.gemfile
212
+ - gemfiles/rails_4.0.gemfile
184
213
  - keys/key
185
214
  - lib/flying-sphinx.rb
186
215
  - lib/flying_sphinx.rb
@@ -195,48 +224,57 @@ files:
195
224
  - lib/flying_sphinx/gzipped_hash.rb
196
225
  - lib/flying_sphinx/rails.rb
197
226
  - lib/flying_sphinx/railtie.rb
227
+ - lib/flying_sphinx/response/invalid.rb
228
+ - lib/flying_sphinx/response/json.rb
229
+ - lib/flying_sphinx/response/logger.rb
198
230
  - lib/flying_sphinx/setting_files.rb
199
231
  - lib/flying_sphinx/sinatra.rb
200
232
  - lib/flying_sphinx/sphinxql.rb
201
233
  - lib/flying_sphinx/sphinxql/translator.rb
202
234
  - lib/flying_sphinx/tasks.rb
203
235
  - lib/flying_sphinx/version.rb
204
- - spec/light_spec_helper.rb
236
+ - spec/acceptance/get_info_spec.rb
237
+ - spec/acceptance/start_or_stop_sphinx_spec.rb
238
+ - spec/flying_sphinx/action_spec.rb
239
+ - spec/flying_sphinx/api_spec.rb
240
+ - spec/flying_sphinx/configuration_spec.rb
241
+ - spec/flying_sphinx/controller_spec.rb
242
+ - spec/flying_sphinx/setting_files_spec.rb
205
243
  - spec/spec_helper.rb
206
- - spec/specs/action_spec.rb
207
- - spec/specs/api_spec.rb
208
- - spec/specs/configuration_spec.rb
209
- - spec/specs/controller_spec.rb
210
- - spec/specs/setting_files_spec.rb
244
+ - spec/support/local_pusher.rb
245
+ - spec/support/successful_action.rb
211
246
  homepage: https://flying-sphinx.com
212
247
  licenses: []
213
- metadata: {}
214
- post_install_message: ! "If you're upgrading, you should rebuild your Sphinx setup
215
- when deploying:\n\n $ heroku rake fs:rebuild\n"
248
+ post_install_message:
216
249
  rdoc_options: []
217
250
  require_paths:
218
251
  - lib
219
252
  required_ruby_version: !ruby/object:Gem::Requirement
253
+ none: false
220
254
  requirements:
221
255
  - - ! '>='
222
256
  - !ruby/object:Gem::Version
223
257
  version: '0'
224
258
  required_rubygems_version: !ruby/object:Gem::Requirement
259
+ none: false
225
260
  requirements:
226
261
  - - ! '>='
227
262
  - !ruby/object:Gem::Version
228
263
  version: '0'
229
264
  requirements: []
230
265
  rubyforge_project:
231
- rubygems_version: 2.1.11
266
+ rubygems_version: 1.8.30
232
267
  signing_key:
233
- specification_version: 4
268
+ specification_version: 3
234
269
  summary: Sphinx in the Cloud
235
270
  test_files:
236
- - spec/light_spec_helper.rb
271
+ - spec/acceptance/get_info_spec.rb
272
+ - spec/acceptance/start_or_stop_sphinx_spec.rb
273
+ - spec/flying_sphinx/action_spec.rb
274
+ - spec/flying_sphinx/api_spec.rb
275
+ - spec/flying_sphinx/configuration_spec.rb
276
+ - spec/flying_sphinx/controller_spec.rb
277
+ - spec/flying_sphinx/setting_files_spec.rb
237
278
  - spec/spec_helper.rb
238
- - spec/specs/action_spec.rb
239
- - spec/specs/api_spec.rb
240
- - spec/specs/configuration_spec.rb
241
- - spec/specs/controller_spec.rb
242
- - spec/specs/setting_files_spec.rb
279
+ - spec/support/local_pusher.rb
280
+ - spec/support/successful_action.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MmFjZTkzNjBhNTJjNTBlYzI1ZmE4ODNlNDZmNTViMTk5MWM4ZmExNw==
5
- data.tar.gz: !binary |-
6
- Zjg1ZTkzYTM0MDE0ODcyYTg0ODBlMDZlMjQwNmI0ZGIyM2E2ODg3ZA==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- M2MxZWNkYzYzOTE4ZDVhNDc1YTIyMDcwNzA3M2Q4OTIwMjlmMTViMTU1M2Vj
10
- OWQ5MjdlNWQ1M2MxNTM4YzUyYWJlNDNhOWE3MzE4ZTJhMGFhM2QyOTU3ZGJm
11
- YjFkZjg2MzkxYjBkZTY2YWM4YTAxOGQ3ODVjMzkyZTE5OTRiOTE=
12
- data.tar.gz: !binary |-
13
- ZDUzYTA3ZjVmZTQwZmNiMDk4NjVhNTE5ZTExMjE4NmE5ZGRiYjA5ODUyNWRi
14
- MGEyOGM1ZjUzYmYxYjY2YzJlMTdhMWI5ZDIzMjc0MzUwNDBlZjlkOGIxYzUw
15
- Mzk0N2Q2YzY2MGJmZTA3OGNlYzMwMDk0NzZmOTQwNTNlYWJhNzk=
@@ -1,9 +0,0 @@
1
- require 'bundler/setup'
2
- require 'rspec/fire'
3
-
4
- module FlyingSphinx; end
5
-
6
- RSpec.configure do |config|
7
- config.mock_with :rspec
8
- config.include(RSpec::Fire)
9
- end