Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ specs

  • Loading branch information...
commit bfeee5fe497c2229a49299635a2a41326933ea5c 1 parent dc4aee5
@floere authored
View
1  client/lib/picky-client/client.rb
@@ -106,7 +106,6 @@ def search_unparsed query, params = {}
#
# Note: For live queries, parsing is actually not really necessary.
#
-
def send_search params = {}
params = defaultize params
::Net::HTTP.get self.host, "#{self.path}?#{params.to_query}", self.port
View
6 client/lib/picky-client/client_index.rb
@@ -8,7 +8,7 @@ class Client
# * data: A hash in the form of { :id => 1234, :attr1 => 'attr1', :attr2 => 'attr2', ... }.
#
def replace index_name, data
- request Net::HTTP::Post.new(self.path), index_name, data
+ send_off Net::HTTP::Post.new(self.path), index_name, data
end
# TODO Rename?
@@ -18,14 +18,14 @@ def replace index_name, data
# * data: A hash in the form of { :id => 1234 }.
#
def remove index_name, data
- request Net::HTTP::Delete.new(self.path), index_name, data
+ send_off Net::HTTP::Delete.new(self.path), index_name, data
end
# Sends a request to the Picky server.
#
# Note: Data is JSON encoded.
#
- def request request, index_name, data
+ def send_off request, index_name, data
request.form_data = { :index => index_name, :data => ActiveSupport::JSON.encode(data) }
Net::HTTP.new(self.host, self.port).start { |http| http.request request }
end
View
4 client/spec/picky-client/client_index_spec.rb
@@ -6,7 +6,7 @@
describe 'replace' do
it 'delegates to the request method' do
- client.should_receive(:request).once.with anything, :some_index_name, :some_data
+ client.should_receive(:send_off).once.with anything, :some_index_name, :some_data
client.replace :some_index_name, :some_data
end
@@ -14,7 +14,7 @@
describe 'remove' do
it 'delegates to the request method' do
- client.should_receive(:request).once.with anything, :some_index_name, :some_data
+ client.should_receive(:send_off).once.with anything, :some_index_name, :some_data
client.remove :some_index_name, :some_data
end
View
47 server/spec/integration/sinatra_index_actions_spec.rb
@@ -1,6 +1,7 @@
require 'yajl'
require 'sinatra'
-require 'picky-client'
+require_relative '../../../client/lib/picky-client'
+require_relative '../../../client/lib/picky-client/spec'
require 'spec_helper'
describe 'Sinatra Index Actions' do
@@ -32,7 +33,7 @@ class MyIndexActionsPickyServer < Sinatra::Base
Picky::Indexes.clear
end
let(:request) { ::Rack::MockRequest.new MyIndexActionsPickyServer }
- it 'should update the index correctly' do
+ it 'updates the index correctly' do
request.post('/', params: {
index: 'some_index',
data: %Q{{ "id":"1", "name":"Florian", "surname":"Hanke" }}
@@ -49,7 +50,35 @@ class MyIndexActionsPickyServer < Sinatra::Base
results = Yajl::Parser.parse request.get('/people', params: { query: 'florian' }).body
results['total'].should == 2
end
- it 'should delete entries from the index correctly' do
+ it 'updates the index correctly' do
+ request.post('/', params: {
+ index: 'some_index',
+ data: %Q{{ "id":"1", "name":"Flarian", "surname":"Hanke" }}
+ })
+
+ results = Yajl::Parser.parse request.get('/people', params: { query: 'hanke' }).body
+ results['total'].should == 1
+
+ results = Yajl::Parser.parse request.get('/people', params: { query: 'florian' }).body
+ results['total'].should == 0
+
+ # Whoops, typo. Let's fix it.
+ #
+ request.post('/', params: {
+ index: 'some_index',
+ data: %Q{{ "id":"1", "name":"Florian", "surname":"Hanke" }}
+ })
+
+ results = Yajl::Parser.parse request.get('/people', params: { query: 'hanke' }).body
+ results['total'].should == 1
+
+ results = Yajl::Parser.parse request.get('/people', params: { query: 'flarian' }).body
+ results['total'].should == 0
+
+ results = Yajl::Parser.parse request.get('/people', params: { query: 'florian' }).body
+ results['total'].should == 1
+ end
+ it 'deletes entries from the index correctly' do
request.post('/', params: {
index: 'some_index',
data: %Q{{ "id":"1", "name":"Florian", "surname":"Hanke" }}
@@ -70,7 +99,7 @@ class MyIndexActionsPickyServer < Sinatra::Base
results = Yajl::Parser.parse request.get('/people', params: { query: 'florian' }).body
results['total'].should == 1
end
- it 'should have no problem with a superfluous delete' do
+ it 'has no problem with a superfluous delete' do
request.delete('/', params: {
index: 'some_index',
data: %Q{{ "id":"1" }}
@@ -79,6 +108,16 @@ class MyIndexActionsPickyServer < Sinatra::Base
results = Yajl::Parser.parse request.get('/people', params: { query: 'florian' }).body
results['total'].should == 0
end
+ it 'works with the (test) client' do
+ client = Picky::TestClient.new MyIndexActionsPickyServer, :path => '/people'
+
+ request.post('/', params: {
+ index: 'some_index',
+ data: %Q{{ "id":"1", "name":"Florian", "surname":"Hanke" }}
+ })
+
+ client.search('florian').total.should == 1
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.