outoftime-sunspot 0.0.2 → 0.7.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.
@@ -1,76 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
-
3
- describe 'standard search builder' do
4
- before :each do
5
- stub_results
6
- end
7
-
8
- it 'should give access to order through hash and object' do
9
- search = session.search(Post, :order => 'sort_title asc')
10
- search.builder.params[:order].should == 'sort_title asc'
11
- search.builder.order.should == 'sort_title asc'
12
- end
13
-
14
- it 'should give nil order if no order set' do
15
- search = session.search(Post)
16
- search.builder.params.should have_key(:order)
17
- search.builder.params[:order].should be_nil
18
- search.builder.order.should be_nil
19
- end
20
-
21
- it 'should give access to page and per-page through hash and object' do
22
- search = session.search(Post, :page => 2, :per_page => 15)
23
- search.builder.params[:page].should == 2
24
- search.builder.params[:per_page].should == 15
25
- search.builder.page.should == 2
26
- search.builder.per_page.should == 15
27
- end
28
-
29
- it 'should give access to keywords' do
30
- search = session.search(Post, :keywords => 'some keywords')
31
- search.builder.params[:keywords].should == 'some keywords'
32
- search.builder.keywords.should == 'some keywords'
33
- end
34
-
35
- it 'should have nil keywords if no keywords given' do
36
- search = session.search(Post)
37
- search.builder.params.should have_key(:keywords)
38
- search.builder.params[:keywords].should be_nil
39
- search.builder.keywords.should be_nil
40
- end
41
-
42
- it 'should give access to conditions' do
43
- search = session.search(Post, :conditions => { :blog_id => 1 })
44
- search.builder.params[:conditions][:blog_id].should == 1
45
- search.builder.conditions.blog_id.should == 1
46
- end
47
-
48
- it 'should have nil values for fields with unspecified conditions' do
49
- search = session.search(Post)
50
- %w(title blog_id category_ids average_rating published_at sort_title).each do |field_name|
51
- search.builder.params[:conditions].should have_key(field_name.to_sym)
52
- search.builder.params[:conditions][field_name.to_sym].should == nil
53
- search.builder.conditions.should respond_to(field_name)
54
- search.builder.conditions.send(field_name).should == nil
55
- end
56
- end
57
-
58
- private
59
-
60
- def stub_results(*results)
61
- response = mock('response', :hits => [], :total_hits => 0)
62
- connection.stub!(:query).and_return(response)
63
- end
64
-
65
- def config
66
- @config ||= Sunspot::Configuration.build
67
- end
68
-
69
- def connection
70
- @connection ||= mock('connection')
71
- end
72
-
73
- def session
74
- @session ||= Sunspot::Session.new(config, connection)
75
- end
76
- end
@@ -1,53 +0,0 @@
1
- module Matchy
2
- module Expectations
3
- class HaveKeyExpectation < Base
4
- def matches?(receiver)
5
- @receiver = receiver
6
- receiver.has_key?(@expected)
7
- end
8
-
9
- def failure_message
10
- "Expected #{@receiver.inspect} to have key #{@expected.inspect}"
11
- end
12
-
13
- def negative_failure_message
14
- "Expected #{@receiver.inspect} not to have key #{@expected.inspect}"
15
- end
16
- end
17
-
18
- class BooleanExpectation < Base
19
- def initialize(method, args, test_case)
20
- @method = method
21
- @args = args
22
- @test_case = test_case
23
- end
24
-
25
- def matches?(receiver)
26
- @receiver = receiver
27
- receiver.send("#{@method}?", *@args)
28
- end
29
-
30
- def failure_message
31
- "Expected #{@receiver} to #{'be ' if @args.empty?}#{@method}#{@args.map { |arg| arg.inspect } * ', '}"
32
- end
33
-
34
- def negative_failure_message
35
- "Expected #{@receiver} to not #{'be ' if @args.empty?}#{@method}#{@args.map { |arg| arg.inspect } * ', '}"
36
- end
37
- end
38
-
39
- module TestCaseExtensions
40
- def have_key(key)
41
- Matchy::Expectations::HaveKeyExpectation.new(key, self)
42
- end
43
-
44
- def method_missing(method, *args, &block)
45
- if match = /be_(.*)/.match(method.to_s)
46
- Matchy::Expectations::BooleanExpectation.new(match[1], [], self)
47
- else
48
- Matchy::Expectations::BooleanExpectation.new(method.to_s, args, self)
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,62 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
-
3
- describe 'field types' do
4
- def self.test_field_type(name, field, *values)
5
- raise(ArgumentError, 'Please supply five values') unless values.length == 5
6
-
7
- context "with field of type #{name}" do
8
- before :all do
9
- Sunspot.remove_all
10
- @posts = values.map do |value|
11
- post = Post.new(field => value)
12
- Sunspot.index(post)
13
- post
14
- end
15
- end
16
-
17
- it 'should filter by exact match' do
18
- Sunspot.search(Post) { with.send(field, values[2]) }.results.should == [@posts[2]]
19
- end
20
-
21
- it 'should filter by less than' do
22
- results = Sunspot.search(Post) { with.send(field).less_than values[2] }.results
23
- (0..2).each { |i| results.should include(@posts[i]) }
24
- (3..4).each { |i| results.should_not include(@posts[i]) }
25
- end
26
-
27
- it 'should filter by greater than' do
28
- results = Sunspot.search(Post) { with.send(field).greater_than values[2] }.results
29
- (2..4).each { |i| results.should include(@posts[i]) }
30
- (0..1).each { |i| results.should_not include(@posts[i]) }
31
- end
32
-
33
- it 'should filter by between' do
34
- results = Sunspot.search(Post) { with.send(field).between(values[1]..values[3]) }.results
35
- (1..3).each { |i| results.should include(@posts[i]) }
36
- [0, 4].each { |i| results.should_not include(@posts[i]) }
37
- end
38
-
39
- it 'should filter by any of' do
40
- results = Sunspot.search(Post) { with.send(field).any_of(values.values_at(1, 3)) }.results
41
- [1, 3].each { |i| results.should include(@posts[i]) }
42
- [0, 2, 4].each { |i| results.should_not include(@posts[i]) }
43
- end
44
-
45
- it 'should order by field ascending' do
46
- results = Sunspot.search(Post) { order_by field, :asc }.results
47
- results.should == @posts
48
- end
49
-
50
- it 'should order by field descending' do
51
- results = Sunspot.search(Post) { order_by field, :desc }.results
52
- results.should == @posts.reverse
53
- end
54
- end
55
- end
56
-
57
- test_field_type 'String', :title, 'apple', 'banana', 'cherry', 'date', 'eggplant'
58
- test_field_type 'Integer', :blog_id, -2, 0, 3, 12, 20
59
- test_field_type 'Float', :average_rating, -2.5, 0.0, 3.2, 3.5, 16.0
60
- test_field_type 'Time', :published_at, *(['1970-01-01 00:00:00 UTC', '1983-07-08 04:00:00 UTC', '1983-07-08 02:00:00 -0500',
61
- '2005-11-05 10:00:00 UTC', Time.now.to_s].map { |t| Time.parse(t) })
62
- end