mwmitchell-rsolr 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,47 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'test_helpers')
2
-
3
- class ResponsePaginationTest < RSolrBaseTest
4
-
5
- def create_response(params={})
6
- response = RSolr::Response::Query::Base.new(mock_query_response)
7
- response.params.merge! params
8
- response
9
- end
10
-
11
- # test the Solr::Connection pagination methods
12
- def test_connection_calculate_start
13
- dummy_connection = RSolr::Connection::Base.new(nil)
14
- #assert_equal 15, dummy_connection.send(:calculate_start, 2, 15)
15
- #assert_equal 450, dummy_connection.send(:calculate_start, 10, 50)
16
- #assert_equal 0, dummy_connection.send(:calculate_start, 0, 50)
17
- end
18
-
19
- def test_math
20
- response = create_response({'rows'=>5})
21
- assert_equal response.params['rows'], response.per_page
22
- assert_equal 26, response.total
23
- assert_equal 1, response.current_page
24
- assert_equal 6, response.total_pages
25
-
26
- # now switch the rows (per_page)
27
- # total and current page should remain the same value
28
- # page_count should change
29
-
30
- response = create_response({'rows'=>2})
31
- assert_equal response.params['rows'], response.per_page
32
- assert_equal 26, response.total
33
- assert_equal 1, response.current_page
34
- assert_equal 13, response.total_pages
35
-
36
- # now switch the start
37
-
38
- response = create_response({'rows'=>3})
39
- response.instance_variable_set '@start', 4
40
- assert_equal response.params['rows'], response.per_page
41
- assert_equal 26, response.total
42
- # 2 per page, currently on the 10th item
43
- assert_equal 2, response.current_page
44
- assert_equal 9, response.total_pages
45
- end
46
-
47
- end
@@ -1,44 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'test_helpers')
2
-
3
- class ResponseQueryTest < RSolrBaseTest
4
-
5
- def query_response
6
- RSolr::Response::Query::Base.new(mock_query_response)
7
- end
8
-
9
- def test_accessors
10
- r = query_response
11
- assert r.response
12
- assert_class Array, r.docs
13
-
14
- # total and num_found are the same
15
- assert_equal 26, r.num_found
16
- assert_equal r.total, r.num_found
17
-
18
- # start and offset are the same
19
- assert_equal 0, r.start
20
- assert_equal r.offset, r.start
21
- end
22
-
23
- # make sure the docs respond to key and symbol access (using the Mash class)
24
- def test_doc_string_and_symbol_key_access
25
- response = query_response
26
- response.docs.each do |doc|
27
- assert doc.is_a?(Mash)
28
- assert_equal doc['id'], doc[:id]
29
- assert doc.key?(:id)
30
- assert doc.key?('id')
31
- if doc[:cat]
32
- # if this doc has a cat (multiValues) of memory and electronics
33
- # test the has? method
34
- if doc[:cat].include?('memory') and doc[:cat].include?('electronics')
35
- assert doc.has?(:cat, 'memory')
36
- assert doc.has?(:cat, /elec/)
37
- assert doc.has?('cat', 'memory')
38
- assert doc.has?('cat', /elec/)
39
- end
40
- end
41
- end
42
- end
43
-
44
- end
data/test/test_helpers.rb DELETED
@@ -1,61 +0,0 @@
1
- $: << File.dirname(__FILE__)
2
- require File.join(File.dirname(__FILE__), '..', 'lib', 'rsolr')
3
- require 'test/unit'
4
-
5
- #
6
- class Test::Unit::TestCase
7
-
8
- def self.test(name, &block)
9
- test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
10
- defined = instance_method(test_name) rescue false
11
- raise "#{test_name} is already defined in #{self}" if defined
12
- if block_given?
13
- define_method(test_name, &block)
14
- else
15
- define_method(test_name) do
16
- flunk "No implementation provided for #{name}"
17
- end
18
- end
19
- end
20
-
21
- end
22
-
23
- class RSolrBaseTest < Test::Unit::TestCase
24
-
25
- def assert_class(expected, instance)
26
- assert_equal expected, instance.class
27
- end
28
-
29
- def default_test
30
-
31
- end
32
-
33
- end
34
-
35
- #begin
36
- # require 'rubygems'
37
- # require 'redgreen'
38
- #rescue LoadError
39
- #end
40
-
41
- def mock_query_response
42
- %({'responseHeader'=>{
43
- 'status'=>0,'QTime'=>43,'params'=>{
44
- 'q'=>'*:*','wt'=>'ruby','echoParams'=>'EXPLICIT'
45
- }
46
- },
47
- 'response'=>{
48
- 'numFound'=>26,'start'=>0,'docs'=>[
49
- {'id'=>'SP2514N','inStock'=>true,'manu'=>'Samsung Electronics Co. Ltd.','name'=>'Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133','popularity'=>6,'price'=>92.0,'sku'=>'SP2514N','timestamp'=>'2008-11-21T17:21:55.601Z','cat'=>['electronics','hard drive'],'spell'=>['Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133'],'features'=>['7200RPM, 8MB cache, IDE Ultra ATA-133','NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor']},
50
- {'id'=>'6H500F0','inStock'=>true,'manu'=>'Maxtor Corp.','name'=>'Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300','popularity'=>6,'price'=>350.0,'sku'=>'6H500F0','timestamp'=>'2008-11-21T17:21:55.617Z','cat'=>['electronics','hard drive'],'spell'=>['Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300'],'features'=>['SATA 3.0Gb/s, NCQ','8.5ms seek','16MB cache']},
51
- {'id'=>'F8V7067-APL-KIT','inStock'=>false,'manu'=>'Belkin','name'=>'Belkin Mobile Power Cord for iPod w/ Dock','popularity'=>1,'price'=>19.95,'sku'=>'F8V7067-APL-KIT','timestamp'=>'2008-11-21T17:21:55.652Z','weight'=>4.0,'cat'=>['electronics','connector'],'spell'=>['Belkin Mobile Power Cord for iPod w/ Dock'],'features'=>['car power adapter, white']},
52
- {'id'=>'IW-02','inStock'=>false,'manu'=>'Belkin','name'=>'iPod & iPod Mini USB 2.0 Cable','popularity'=>1,'price'=>11.5,'sku'=>'IW-02','timestamp'=>'2008-11-21T17:21:55.657Z','weight'=>2.0,'cat'=>['electronics','connector'],'spell'=>['iPod & iPod Mini USB 2.0 Cable'],'features'=>['car power adapter for iPod, white']},
53
- {'id'=>'MA147LL/A','inStock'=>true,'includes'=>'earbud headphones, USB cable','manu'=>'Apple Computer Inc.','name'=>'Apple 60 GB iPod with Video Playback Black','popularity'=>10,'price'=>399.0,'sku'=>'MA147LL/A','timestamp'=>'2008-11-21T17:21:55.681Z','weight'=>5.5,'cat'=>['electronics','music'],'spell'=>['Apple 60 GB iPod with Video Playback Black'],'features'=>['iTunes, Podcasts, Audiobooks','Stores up to 15,000 songs, 25,000 photos, or 150 hours of video','2.5-inch, 320x240 color TFT LCD display with LED backlight','Up to 20 hours of battery life','Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video','Notes, Calendar, Phone book, Hold button, Date display, Photo wallet, Built-in games, JPEG photo playback, Upgradeable firmware, USB 2.0 compatibility, Playback speed control, Rechargeable capability, Battery level indication']},
54
- {'id'=>'TWINX2048-3200PRO','inStock'=>true,'manu'=>'Corsair Microsystems Inc.','name'=>'CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail','popularity'=>5,'price'=>185.0,'sku'=>'TWINX2048-3200PRO','timestamp'=>'2008-11-21T17:21:55.706Z','cat'=>['electronics','memory'],'spell'=>['CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail'],'features'=>['CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader']},
55
- {'id'=>'VS1GB400C3','inStock'=>true,'manu'=>'Corsair Microsystems Inc.','name'=>'CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail','popularity'=>7,'price'=>74.99,'sku'=>'VS1GB400C3','timestamp'=>'2008-11-21T17:21:55.71Z','cat'=>['electronics','memory'],'spell'=>['CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail']},
56
- {'id'=>'VDBDB1A16','inStock'=>true,'manu'=>'A-DATA Technology Inc.','name'=>'A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM','popularity'=>5,'sku'=>'VDBDB1A16','timestamp'=>'2008-11-21T17:21:55.712Z','cat'=>['electronics','memory'],'spell'=>['A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM'],'features'=>['CAS latency 3, 2.7v']},
57
- {'id'=>'3007WFP','inStock'=>true,'includes'=>'USB cable','manu'=>'Dell, Inc.','name'=>'Dell Widescreen UltraSharp 3007WFP','popularity'=>6,'price'=>2199.0,'sku'=>'3007WFP','timestamp'=>'2008-11-21T17:21:55.724Z','weight'=>401.6,'cat'=>['electronics','monitor'],'spell'=>['Dell Widescreen UltraSharp 3007WFP'],'features'=>['30" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast']},
58
- {'id'=>'VA902B','inStock'=>true,'manu'=>'ViewSonic Corp.','name'=>'ViewSonic VA902B - flat panel display - TFT - 19"','popularity'=>6,'price'=>279.95,'sku'=>'VA902B','timestamp'=>'2008-11-21T17:21:55.734Z','weight'=>190.4,'cat'=>['electronics','monitor'],'spell'=>['ViewSonic VA902B - flat panel display - TFT - 19"'],'features'=>['19" TFT active matrix LCD, 8ms response time, 1280 x 1024 native resolution']}]
59
- }
60
- })
61
- end