picky-client 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -149,7 +149,7 @@ module Picky
149
149
  #
150
150
  def write_ids results
151
151
  move_to_ids
152
- write "=> #{results.total ? results.ids(@id_amount) : []}"
152
+ write "=> #{(results.total ? results.ids(@id_amount) : []).inspect}"
153
153
  rescue StandardError => e
154
154
  p e.message
155
155
  p e.backtrace
@@ -0,0 +1,25 @@
1
+ (defined?(RSpec) && RSpec || defined?(Spec) && Spec)::Matchers.define :have_categories do |*expected|
2
+
3
+ match do |results|
4
+ extract_categories(actual) == expected
5
+ end
6
+
7
+ failure_message_for_should do |results|
8
+ "expected categories #{extract_categories(results)} to be named and ordered as #{expected}"
9
+ end
10
+
11
+ failure_message_for_should_not do |results|
12
+ "expected categories #{extract_categories(results)} not to be named and ordered as #{expected}"
13
+ end
14
+
15
+ description do
16
+ "be categories named and ordered as #{expected}"
17
+ end
18
+
19
+ def extract_categories results
20
+ results.allocations.map do |allocation|
21
+ allocation[3].map { |combination| combination[0] }
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,34 @@
1
+ module Picky
2
+
3
+ class TestClient < Client
4
+
5
+ attr_reader :request
6
+
7
+ #
8
+ #
9
+ # Example:
10
+ # Picky::TestClient.new(BookSearch, :path => '/books')
11
+ #
12
+ def initialize rack_app, options = {}
13
+ super options
14
+
15
+ @request = Rack::MockRequest.new rack_app
16
+ end
17
+
18
+ # Wraps the search method to always extend the result with Convenience.
19
+ #
20
+ def search query, params = {}
21
+ super.extend Convenience
22
+ end
23
+
24
+ # Backend method that we override to not send a real search.
25
+ #
26
+ def send_search params = {}
27
+ params = defaultize params
28
+
29
+ request.get("#{self.path}?#{params.to_query}").body
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,3 @@
1
+ require File.expand_path '../../picky-client', __FILE__
2
+ require File.expand_path '../spec/test_client', __FILE__
3
+ require File.expand_path '../spec/support/matchers/have_categories', __FILE__
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rack'
4
+ require 'picky-client/spec'
5
+
6
+ describe Picky::TestClient do
7
+
8
+ class TestApplication; end
9
+
10
+ let(:client) { described_class.new(TestApplication, :path => '/some/path') }
11
+
12
+ context 'search' do
13
+ it 'does extract the hash' do
14
+ TestApplication.stub! :call => [200, { 'Content-Type' => 'application/json' }, ['{"allocations":[["boooookies",0.0,1,[["title","hell","hell"]],[313]]],"offset":0,"duration":0.000584,"total":1}']]
15
+
16
+ client.search('test').should == { :allocations => [['boooookies', 0.0, 1, [['title', 'hell', 'hell']], [313]]], :offset => 0, :duration => 0.000584, :total => 1 }
17
+ end
18
+ it 'does extend the result with convenience methods' do
19
+ TestApplication.stub! :call => [200, { 'Content-Type' => 'application/json' }, ['{"allocations":[["boooookies",0.0,1,[["title","hell","hell"]],[313]]],"offset":0,"duration":0.000584,"total":1}']]
20
+
21
+ client.search('test').total.should == 1
22
+ end
23
+ end
24
+
25
+ context 'send_search' do
26
+ it 'sends correctly' do
27
+ response = stub :response
28
+ request = stub :request
29
+ client.stub! :request => request
30
+
31
+ request.should_receive(:get).once.with('/some/path?query=some_query').and_return response
32
+ response.should_receive(:body).once.and_return :some_body
33
+
34
+ client.send_search(:query => :some_query).should == :some_body
35
+ end
36
+ end
37
+
38
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: picky-client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.2.1
5
+ version: 2.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Florian Hanke
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-15 00:00:00 +10:00
13
+ date: 2011-04-17 00:00:00 +10:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -38,6 +38,9 @@ files:
38
38
  - lib/picky-client/client.rb
39
39
  - lib/picky-client/convenience.rb
40
40
  - lib/picky-client/helper.rb
41
+ - lib/picky-client/spec/support/matchers/have_categories.rb
42
+ - lib/picky-client/spec/test_client.rb
43
+ - lib/picky-client/spec.rb
41
44
  - lib/picky-client/tasks/javascripts.rb
42
45
  - lib/picky-client/tasks.rb
43
46
  - lib/picky-client.rb
@@ -51,6 +54,7 @@ files:
51
54
  - spec/picky-client/client_spec.rb
52
55
  - spec/picky-client/convenience_spec.rb
53
56
  - spec/picky-client/helper_spec.rb
57
+ - spec/picky-client/spec/test_client_spec.rb
54
58
  has_rdoc: true
55
59
  homepage: http://floere.github.com/picky
56
60
  licenses: []
@@ -84,3 +88,4 @@ test_files:
84
88
  - spec/picky-client/client_spec.rb
85
89
  - spec/picky-client/convenience_spec.rb
86
90
  - spec/picky-client/helper_spec.rb
91
+ - spec/picky-client/spec/test_client_spec.rb