websolr-rails 1.4.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/.gitignore +1 -10
  2. data/LICENSE +17 -16
  3. data/README.rdoc +16 -62
  4. data/Rakefile +2 -60
  5. data/VERSION +1 -1
  6. data/lib/websolr-rails.rb +54 -1
  7. data/lib/websolr.rb +2 -1
  8. metadata +12 -215
  9. data/CHANGELOG +0 -8
  10. data/TESTING_THE_PLUGIN +0 -25
  11. data/bin/websolr +0 -10
  12. data/config/solr.yml +0 -15
  13. data/config/solr_environment.rb +0 -22
  14. data/generate_rdoc.sh +0 -13
  15. data/lib/acts_as_solr.rb +0 -65
  16. data/lib/acts_methods.rb +0 -281
  17. data/lib/class_methods.rb +0 -243
  18. data/lib/common_methods.rb +0 -89
  19. data/lib/deprecation.rb +0 -61
  20. data/lib/instance_methods.rb +0 -181
  21. data/lib/lazy_document.rb +0 -18
  22. data/lib/parser_methods.rb +0 -230
  23. data/lib/search_results.rb +0 -72
  24. data/lib/solr.rb +0 -21
  25. data/lib/solr/connection.rb +0 -190
  26. data/lib/solr/document.rb +0 -78
  27. data/lib/solr/exception.rb +0 -13
  28. data/lib/solr/field.rb +0 -39
  29. data/lib/solr/importer.rb +0 -19
  30. data/lib/solr/importer/array_mapper.rb +0 -26
  31. data/lib/solr/importer/delimited_file_source.rb +0 -38
  32. data/lib/solr/importer/hpricot_mapper.rb +0 -27
  33. data/lib/solr/importer/mapper.rb +0 -51
  34. data/lib/solr/importer/solr_source.rb +0 -43
  35. data/lib/solr/importer/xpath_mapper.rb +0 -35
  36. data/lib/solr/indexer.rb +0 -52
  37. data/lib/solr/request.rb +0 -26
  38. data/lib/solr/request/add_document.rb +0 -63
  39. data/lib/solr/request/base.rb +0 -36
  40. data/lib/solr/request/commit.rb +0 -31
  41. data/lib/solr/request/delete.rb +0 -50
  42. data/lib/solr/request/dismax.rb +0 -46
  43. data/lib/solr/request/index_info.rb +0 -22
  44. data/lib/solr/request/modify_document.rb +0 -51
  45. data/lib/solr/request/optimize.rb +0 -21
  46. data/lib/solr/request/ping.rb +0 -36
  47. data/lib/solr/request/select.rb +0 -56
  48. data/lib/solr/request/spellcheck.rb +0 -30
  49. data/lib/solr/request/standard.rb +0 -402
  50. data/lib/solr/request/update.rb +0 -23
  51. data/lib/solr/response.rb +0 -27
  52. data/lib/solr/response/add_document.rb +0 -17
  53. data/lib/solr/response/base.rb +0 -42
  54. data/lib/solr/response/commit.rb +0 -17
  55. data/lib/solr/response/delete.rb +0 -13
  56. data/lib/solr/response/dismax.rb +0 -8
  57. data/lib/solr/response/index_info.rb +0 -26
  58. data/lib/solr/response/modify_document.rb +0 -17
  59. data/lib/solr/response/optimize.rb +0 -14
  60. data/lib/solr/response/ping.rb +0 -28
  61. data/lib/solr/response/ruby.rb +0 -42
  62. data/lib/solr/response/select.rb +0 -17
  63. data/lib/solr/response/spellcheck.rb +0 -20
  64. data/lib/solr/response/standard.rb +0 -64
  65. data/lib/solr/response/xml.rb +0 -42
  66. data/lib/solr/solrtasks.rb +0 -27
  67. data/lib/solr/util.rb +0 -32
  68. data/lib/solr/xml.rb +0 -44
  69. data/lib/solr_fixtures.rb +0 -13
  70. data/lib/tasks/database.rake +0 -18
  71. data/lib/tasks/solr.rake +0 -94
  72. data/lib/tasks/test.rake +0 -7
  73. data/lib/websolr_controller.rb +0 -233
  74. data/lib/websolr_option_parser.rb +0 -61
  75. data/lib/websolr_rails.rb +0 -1
  76. data/lib/websolr_rails/tasks.rb +0 -4
  77. data/lib/will_paginate_support.rb +0 -12
  78. data/solr/CHANGES.txt +0 -1207
  79. data/solr/LICENSE.txt +0 -712
  80. data/solr/NOTICE.txt +0 -90
  81. data/solr/etc/jetty.xml +0 -205
  82. data/solr/etc/webdefault.xml +0 -379
  83. data/solr/lib/easymock.jar +0 -0
  84. data/solr/lib/jetty-6.1.3.jar +0 -0
  85. data/solr/lib/jetty-util-6.1.3.jar +0 -0
  86. data/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
  87. data/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
  88. data/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
  89. data/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
  90. data/solr/lib/servlet-api-2.4.jar +0 -0
  91. data/solr/lib/servlet-api-2.5-6.1.3.jar +0 -0
  92. data/solr/lib/xpp3-1.1.3.4.O.jar +0 -0
  93. data/solr/logs/.empty-dir-for-git +0 -0
  94. data/solr/solr/README.txt +0 -52
  95. data/solr/solr/bin/abc +0 -176
  96. data/solr/solr/bin/abo +0 -176
  97. data/solr/solr/bin/backup +0 -108
  98. data/solr/solr/bin/backupcleaner +0 -142
  99. data/solr/solr/bin/commit +0 -128
  100. data/solr/solr/bin/optimize +0 -129
  101. data/solr/solr/bin/readercycle +0 -129
  102. data/solr/solr/bin/rsyncd-disable +0 -77
  103. data/solr/solr/bin/rsyncd-enable +0 -76
  104. data/solr/solr/bin/rsyncd-start +0 -145
  105. data/solr/solr/bin/rsyncd-stop +0 -105
  106. data/solr/solr/bin/scripts-util +0 -83
  107. data/solr/solr/bin/snapcleaner +0 -148
  108. data/solr/solr/bin/snapinstaller +0 -168
  109. data/solr/solr/bin/snappuller +0 -248
  110. data/solr/solr/bin/snappuller-disable +0 -77
  111. data/solr/solr/bin/snappuller-enable +0 -77
  112. data/solr/solr/bin/snapshooter +0 -109
  113. data/solr/solr/conf/admin-extra.html +0 -31
  114. data/solr/solr/conf/protwords.txt +0 -21
  115. data/solr/solr/conf/schema.xml +0 -126
  116. data/solr/solr/conf/scripts.conf +0 -24
  117. data/solr/solr/conf/solrconfig.xml +0 -458
  118. data/solr/solr/conf/stopwords.txt +0 -57
  119. data/solr/solr/conf/synonyms.txt +0 -31
  120. data/solr/solr/conf/xslt/example.xsl +0 -132
  121. data/solr/solr/conf/xslt/example_atom.xsl +0 -63
  122. data/solr/solr/conf/xslt/example_rss.xsl +0 -62
  123. data/solr/start.jar +0 -0
  124. data/solr/tmp/.empty-dir-for-git +0 -0
  125. data/solr/webapps/solr.war +0 -0
  126. data/test/config/solr.yml +0 -2
  127. data/test/db/connections/mysql/connection.rb +0 -10
  128. data/test/db/connections/sqlite/connection.rb +0 -8
  129. data/test/db/migrate/001_create_books.rb +0 -15
  130. data/test/db/migrate/002_create_movies.rb +0 -12
  131. data/test/db/migrate/003_create_categories.rb +0 -11
  132. data/test/db/migrate/004_create_electronics.rb +0 -16
  133. data/test/db/migrate/005_create_authors.rb +0 -12
  134. data/test/db/migrate/006_create_postings.rb +0 -9
  135. data/test/db/migrate/007_create_posts.rb +0 -13
  136. data/test/db/migrate/008_create_gadgets.rb +0 -11
  137. data/test/fixtures/authors.yml +0 -9
  138. data/test/fixtures/books.yml +0 -13
  139. data/test/fixtures/categories.yml +0 -7
  140. data/test/fixtures/db_definitions/mysql.sql +0 -41
  141. data/test/fixtures/electronics.yml +0 -49
  142. data/test/fixtures/movies.yml +0 -9
  143. data/test/fixtures/postings.yml +0 -10
  144. data/test/functional/acts_as_solr_test.rb +0 -413
  145. data/test/functional/association_indexing_test.rb +0 -37
  146. data/test/functional/faceted_search_test.rb +0 -163
  147. data/test/functional/multi_solr_search_test.rb +0 -51
  148. data/test/models/author.rb +0 -10
  149. data/test/models/book.rb +0 -10
  150. data/test/models/category.rb +0 -8
  151. data/test/models/electronic.rb +0 -21
  152. data/test/models/gadget.rb +0 -9
  153. data/test/models/movie.rb +0 -17
  154. data/test/models/novel.rb +0 -2
  155. data/test/models/post.rb +0 -3
  156. data/test/models/posting.rb +0 -11
  157. data/test/test_helper.rb +0 -51
  158. data/test/unit/acts_methods_shoulda.rb +0 -70
  159. data/test/unit/class_methods_shoulda.rb +0 -88
  160. data/test/unit/common_methods_shoulda.rb +0 -112
  161. data/test/unit/instance_methods_shoulda.rb +0 -326
  162. data/test/unit/lazy_document_shoulda.rb +0 -35
  163. data/test/unit/parser_instance.rb +0 -19
  164. data/test/unit/parser_methods_shoulda.rb +0 -278
  165. data/test/unit/solr_instance.rb +0 -46
  166. data/test/unit/test_helper.rb +0 -14
  167. data/websolr-rails.gemspec +0 -243
@@ -1,37 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper')
2
-
3
- class AssociationIndexingTest < Test::Unit::TestCase
4
-
5
- fixtures :categories, :books
6
-
7
- # Testing the association indexing with has_many:
8
- #
9
- # class Category < ActiveRecord::Base
10
- # has_many :books
11
- # acts_as_solr :include => [:books]
12
- # end
13
- #
14
- # Note that some of the search terms below are from the 'books'
15
- # table, but get indexed as being a part of Category
16
- def test_search_on_fields_in_has_many_association
17
- ['thriller', 'novel', 'splinter', 'clancy', 'tom clancy thriller'].each do |term|
18
- assert_equal 1, Category.count_by_solr(term), "expected one result: #{term}"
19
- end
20
- end
21
-
22
- # Testing the association indexing with belongs_to:
23
- #
24
- # class Book < ActiveRecord::Base
25
- # belongs_to :category
26
- # acts_as_solr :include => [:category]
27
- # end
28
- #
29
- # Note that some of the search terms below are from the 'categories'
30
- # table, but get indexed as being a part of Book
31
- def test_search_on_fields_in_belongs_to_association
32
- ['splinter', 'clancy', 'tom clancy thriller', 'splinter novel'].each do |term|
33
- assert_equal 1, Book.count_by_solr(term), "expected one result: #{term}"
34
- end
35
- end
36
-
37
- end
@@ -1,163 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper')
2
-
3
- class FacetedSearchTest < Test::Unit::TestCase
4
-
5
- fixtures :electronics
6
-
7
- # The tests below are for faceted search, but make sure you setup
8
- # the fields on your model you'd like to index as a facet field:
9
- #
10
- # class Electronic < ActiveRecord::Base
11
- # acts_as_solr :facets => [:category, :manufacturer]
12
- # end
13
- #
14
- # A basic faceted search using just one facet field
15
- def test_faceted_search_basic
16
- records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]}
17
- assert_equal 4, records.docs.size
18
- assert_match /Apple 60 GB Memory iPod/, records.docs.first.name
19
- assert_equal({"category_facet" => {"Electronics" => 1,
20
- "Memory" => 2,
21
- "Hard Drive" => 1}},
22
- records.facets['facet_fields'])
23
- end
24
-
25
- # Making sure the empty result returned what we expected
26
- def test_faceted_search_no_matches
27
- records = Electronic.find_by_solr "not found", :facets => { :fields => [:category]}
28
- assert_equal [], records.docs
29
- assert_equal [], records.facets['facet_fields']
30
- end
31
-
32
- # A basic faceted search using multiple facet fields
33
- def test_faceted_search_multiple_fields
34
- records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category, :manufacturer]}
35
- assert_equal 4, records.docs.size
36
- assert_equal({"category_facet" => {"Electronics" => 1,
37
- "Memory" => 2,
38
- "Hard Drive" => 1},
39
- "manufacturer_facet" => {"Dell, Inc" => 0,
40
- "Samsung Electronics Co. Ltd." => 1,
41
- "Corsair Microsystems Inc." => 1,
42
- "A-DATA Technology Inc." => 1,
43
- "Apple Computer Inc." => 1}}, records.facets['facet_fields'])
44
- end
45
-
46
- # A basic faceted search using facet queries to get counts.
47
- # Here are the facets search query meaning:
48
- # "price:[* TO 200]" - Price up to 200
49
- # "price:[200 TO 500]" - Price from 200 to 500
50
- # "price:[500 TO *]" - Price higher than 500
51
- def test_facet_search_with_query
52
- records = Electronic.find_by_solr "memory", :facets => {:query => ["price:[* TO 200.00]",
53
- "price:[200.00 TO 500.00]",
54
- "price:[500.00 TO *]"]}
55
- assert_equal 4, records.docs.size
56
- assert_equal({"facet_queries" => {"price_rf:[* TO 200.00]"=>2,
57
- "price_rf:[200.00 TO 500.00]"=>1,
58
- "price_rf:[500.00 TO *]"=>1},
59
- "facet_fields" => {}, "facet_dates" => {}}, records.facets)
60
- end
61
-
62
- # Faceted search specifying the query and fields
63
- def test_facet_search_with_query_and_field
64
- records = Electronic.find_by_solr "memory", :facets => {:query => ["price:[* TO 200.00]",
65
- "price:[200.00 TO 500.00]",
66
- "price:[500.00 TO *]"],
67
- :fields => [:category, :manufacturer]}
68
-
69
- q = records.facets["facet_queries"]
70
- assert_equal 2, q["price_rf:[* TO 200.00]"]
71
- assert_equal 1, q["price_rf:[500.00 TO *]"]
72
- assert_equal 1, q["price_rf:[200.00 TO 500.00]"]
73
-
74
- f = records.facets["facet_fields"]
75
- assert_equal 1, f["category_facet"]["Electronics"]
76
- assert_equal 2, f["category_facet"]["Memory"]
77
- assert_equal 1, f["category_facet"]["Hard Drive"]
78
- assert_equal 1, f["manufacturer_facet"]["Samsung Electronics Co. Ltd."]
79
- assert_equal 1, f["manufacturer_facet"]["Corsair Microsystems Inc."]
80
- assert_equal 1, f["manufacturer_facet"]["A-DATA Technology Inc."]
81
- assert_equal 1, f["manufacturer_facet"]["Apple Computer Inc."]
82
- end
83
-
84
- # Faceted searches with :sort and :zeros options turned on/off
85
- def test_faceted_search_using_zero_and_sort
86
- records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]}
87
- assert_equal({"category_facet"=>{"Electronics"=>1, "Memory"=>2, "Hard Drive"=>1}}, records.facets['facet_fields'])
88
-
89
- records = Electronic.find_by_solr "memory", :facets => {:sort => true, :fields =>[:category]}
90
- assert_equal({"category_facet"=>{"Memory"=>2, "Electronics"=>1, "Hard Drive"=>1}}, records.facets['facet_fields'])
91
-
92
- records = Electronic.find_by_solr "memory", :facets => {:fields =>[:manufacturer]}
93
- assert_equal({"manufacturer_facet" => {"Dell, Inc" => 0,
94
- "Samsung Electronics Co. Ltd." => 1,
95
- "Corsair Microsystems Inc." => 1,
96
- "A-DATA Technology Inc." => 1,
97
- "Apple Computer Inc." => 1}}, records.facets['facet_fields'])
98
-
99
- records = Electronic.find_by_solr "memory", :facets => {:zeros => false, :fields =>[:manufacturer]}
100
- assert_equal({"manufacturer_facet" => {"Samsung Electronics Co. Ltd." => 1,
101
- "Corsair Microsystems Inc." => 1,
102
- "A-DATA Technology Inc." => 1,
103
- "Apple Computer Inc." => 1}}, records.facets['facet_fields'])
104
- end
105
-
106
- # Faceted search with 'drill-down' option being passed.
107
- # The :browse option receives the argument in the format:
108
- # "facet_field:term". You can drill-down to as many
109
- # facet fields as you like
110
- def test_faceted_search_with_drill_down
111
- records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]}
112
- assert_equal 4, records.docs.size
113
- assert_equal({"category_facet"=>{"Electronics"=>1, "Memory"=>2, "Hard Drive"=>1}}, records.facets['facet_fields'])
114
-
115
- records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category],
116
- :browse => "category:Memory",
117
- :zeros => false}
118
- assert_equal 2, records.docs.size
119
- assert_equal({"category_facet"=>{"Memory"=>2}}, records.facets['facet_fields'])
120
- end
121
-
122
- def test_faceted_search_with_dates
123
- records = Electronic.find_by_solr "memory", :facets => {:dates => {:fields => [:created_at, :updated_at],
124
- :start => (Date.today - 7.years).strftime("%Y-%m-%dT%H:%M:%SZ"), :end => Date.today.strftime("%Y-%m-%dT%H:%M:%SZ"), :gap => '+1YEAR', :other => :all}}
125
-
126
- assert_equal 4, records.docs.size
127
-
128
- assert_equal 0, records.facets["facet_dates"]["created_at_d"]["after"]
129
- assert_equal 1, records.facets["facet_dates"]["created_at_d"]["before"]
130
- assert_equal 3, records.facets["facet_dates"]["created_at_d"]["between"]
131
-
132
- assert_equal 0, records.facets["facet_dates"]["updated_at_d"]["after"]
133
- assert_equal 0, records.facets["facet_dates"]["updated_at_d"]["before"]
134
- assert_equal 4, records.facets["facet_dates"]["updated_at_d"]["between"]
135
- end
136
-
137
- def test_faceted_search_with_dates_filter
138
- records = Electronic.find_by_solr "memory", :facets => {:dates => {:filter => ["updated_at:[#{(Date.today - 3.months).strftime("%Y-%m-%dT%H:%M:%SZ")} TO NOW-1MONTH/DAY]"]}}
139
-
140
- assert_equal 2, records.docs.size
141
-
142
- records.docs.each { |r|
143
- assert r.updated_at >= (Date.today - 3.month)
144
- assert r.updated_at <= (Date.today - 1.month)
145
- }
146
- end
147
-
148
- def test_faceted_search_with_dates_filter_and_facets
149
- # this is a very contrived example but gives us data to validate
150
- records = Electronic.find_by_solr "memory", :facets => {:dates => {:filter => ["updated_at:[#{(Date.today - 3.months).strftime("%Y-%m-%dT%H:%M:%SZ")} TO NOW-1MONTH/DAY]"],
151
- :fields => [:created_at, :updated_at], :start => 'NOW-2MONTHS/DAY', :end => 'NOW-1MONTH/DAY', :gap => '+1MONTH', :other => :all}}
152
-
153
- assert_equal 2, records.docs.size
154
-
155
- assert_equal 0, records.facets["facet_dates"]["created_at_d"]["after"]
156
- assert_equal 2, records.facets["facet_dates"]["created_at_d"]["before"]
157
- assert_equal 0, records.facets["facet_dates"]["created_at_d"]["between"]
158
-
159
- assert_equal 0, records.facets["facet_dates"]["updated_at_d"]["after"]
160
- assert_equal 1, records.facets["facet_dates"]["updated_at_d"]["before"]
161
- assert_equal 1, records.facets["facet_dates"]["updated_at_d"]["between"]
162
- end
163
- end
@@ -1,51 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper')
2
-
3
- class ActsAsSolrTest < Test::Unit::TestCase
4
-
5
- fixtures :books, :movies
6
-
7
- # Testing the multi_solr_search with the returning results being objects
8
- def test_multi_solr_search_return_objects
9
- records = Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :objects
10
- assert_equal 2, records.total
11
- assert_equal Movie, records.docs.first.class
12
- assert_equal Book, records.docs.last.class
13
- end
14
-
15
- # Testing the multi_solr_search with the returning results being ids
16
- def test_multi_solr_search_return_ids
17
- records = Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :ids
18
- assert_equal 2, records.total
19
- assert records.docs.include?({"id" => "Movie:1"})
20
- assert records.docs.include?({"id" => "Book:1"})
21
- end
22
-
23
- # Testing the multi_solr_search with multiple models
24
- def test_multi_solr_search_multiple_models
25
- records = Book.multi_solr_search "Napoleon OR Tom OR Thriller", :models => [Movie, Category], :results_format => :ids
26
- assert_equal 4, records.total
27
- [{"id" => "Category:1"}, {"id" =>"Book:1"}, {"id" => "Movie:1"}, {"id" =>"Book:3"}].each do |result|
28
- assert records.docs.include?(result)
29
- end
30
- end
31
-
32
- # Testing empty result set format
33
- def test_returns_no_matches
34
- records = Book.multi_solr_search "not found", :models => [Movie, Category]
35
- assert_equal [], records.docs
36
- assert_equal 0, records.total
37
- end
38
-
39
- def test_search_on_empty_string_does_not_return_nil
40
- records = Book.multi_solr_search('', :models => [Movie, Category])
41
- assert_not_nil records
42
- assert_equal [], records.docs
43
- assert_equal 0, records.total
44
- end
45
-
46
- def test_search_with_score_should_set_score
47
- records = Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :objects, :scores => true
48
- assert_equal 1.0112731, records.docs.first.solr_score
49
- assert_equal 0.6723396, records.docs.last.solr_score
50
- end
51
- end
@@ -1,10 +0,0 @@
1
- # Table fields for 'movies'
2
- # - id
3
- # - name
4
- # - biography
5
-
6
- class Author < ActiveRecord::Base
7
-
8
- acts_as_solr :auto_commit => false
9
-
10
- end
data/test/models/book.rb DELETED
@@ -1,10 +0,0 @@
1
- # Table fields for 'books'
2
- # - id
3
- # - category_id
4
- # - name
5
- # - author
6
-
7
- class Book < ActiveRecord::Base
8
- belongs_to :category
9
- acts_as_solr :include => [:category]
10
- end
@@ -1,8 +0,0 @@
1
- # Table fields for 'categories'
2
- # - id
3
- # - name
4
-
5
- class Category < ActiveRecord::Base
6
- has_many :books
7
- acts_as_solr :include => [:books]
8
- end
@@ -1,21 +0,0 @@
1
- # Table fields for 'electronics'
2
- # - id
3
- # - name
4
- # - manufacturer
5
- # - features
6
- # - category
7
- # - price
8
- # - created_on
9
-
10
- class Electronic < ActiveRecord::Base
11
- acts_as_solr :facets => [:category, :manufacturer],
12
- :fields => [:name, :manufacturer, :features, :category, {:created_at => :date}, {:updated_at => :date}, {:price => {:type => :range_float, :boost => 10.0}}],
13
- :boost => 5.0,
14
- :exclude_fields => [:features]
15
-
16
- # The following example would also convert the :price field type to :range_float
17
- #
18
- # acts_as_solr :facets => [:category, :manufacturer],
19
- # :fields => [:name, :manufacturer, :features, :category, {:price => :range_float}],
20
- # :boost => 5.0
21
- end
@@ -1,9 +0,0 @@
1
- class Gadget < ActiveRecord::Base
2
- cattr_accessor :search_disabled
3
-
4
- acts_as_solr :offline => proc {|record| Gadget.search_disabled?}, :format => :ids
5
-
6
- def self.search_disabled?
7
- search_disabled
8
- end
9
- end
data/test/models/movie.rb DELETED
@@ -1,17 +0,0 @@
1
- # Table fields for 'movies'
2
- # - id
3
- # - name
4
- # - description
5
-
6
- class Movie < ActiveRecord::Base
7
- acts_as_solr :additional_fields => [:current_time, {:time_on_xml => :date}]
8
-
9
- def current_time
10
- Time.now.to_s
11
- end
12
-
13
- def time_on_xml
14
- Time.now
15
- end
16
-
17
- end
data/test/models/novel.rb DELETED
@@ -1,2 +0,0 @@
1
- class Novel < Book
2
- end
data/test/models/post.rb DELETED
@@ -1,3 +0,0 @@
1
- class Post < ActiveRecord::Base
2
- acts_as_solr
3
- end
@@ -1,11 +0,0 @@
1
- # Table fields for 'movies'
2
- # - guid
3
- # - name
4
- # - description
5
-
6
- class Posting < ActiveRecord::Base
7
-
8
- set_primary_key 'guid'
9
- acts_as_solr({},{:primary_key_field => 'pk_s'})
10
-
11
- end
data/test/test_helper.rb DELETED
@@ -1,51 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'active_record'
4
- require 'active_record/fixtures'
5
-
6
- begin
7
- require 'active_support/test_case'
8
- rescue
9
- end
10
-
11
- RAILS_ROOT = File.dirname(__FILE__) unless defined? RAILS_ROOT
12
- RAILS_ENV = 'test' unless defined? RAILS_ENV
13
-
14
- require File.dirname(__FILE__) + '/../lib/acts_as_solr'
15
- require File.dirname(__FILE__) + '/../config/solr_environment.rb'
16
-
17
- # Load Models
18
- models_dir = File.join(File.dirname( __FILE__ ), 'models')
19
- Dir[ models_dir + '/*.rb'].each { |m| require m }
20
-
21
- if defined?(ActiveSupport::TestCase)
22
- class ActiveSupport::TestCase
23
- include ActiveRecord::TestFixtures
24
- self.fixture_path = File.dirname(__FILE__) + "/fixtures/"
25
- end unless ActiveSupport::TestCase.respond_to?(:fixture_path=)
26
- else
27
- Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
28
- end
29
-
30
- class Test::Unit::TestCase
31
- def self.fixtures(*table_names)
32
- fixture_path = defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase.fixture_path : Test::Unit::TestCase.fixture_path
33
- if block_given?
34
- Fixtures.create_fixtures(fixture_path, table_names) { yield }
35
- else
36
- Fixtures.create_fixtures(fixture_path, table_names)
37
- end
38
- table_names.each do |table_name|
39
- clear_from_solr(table_name)
40
- klass = instance_eval table_name.to_s.capitalize.singularize
41
- klass.find(:all).each{|content| content.solr_save}
42
- end
43
-
44
- clear_from_solr(:novels)
45
- end
46
-
47
- private
48
- def self.clear_from_solr(table_name)
49
- ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "type_s:#{table_name.to_s.capitalize.singularize}"))
50
- end
51
- end
@@ -1,70 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
- require 'acts_methods'
3
- require 'mocha'
4
-
5
- class ActsMethodsTest < Test::Unit::TestCase
6
- class Model
7
- attr_accessor :birthdate
8
-
9
- def initialize(birthdate)
10
- @birthdate = birthdate
11
- end
12
-
13
- def self.configuration
14
- @configuration ||= {:solr_fields => {}}
15
- end
16
-
17
- def self.columns_hash=(columns_hash)
18
- @columns_hash = columns_hash
19
- end
20
-
21
- def self.columns_hash
22
- @columns_hash
23
- end
24
-
25
- def [](key)
26
- @birthday
27
- end
28
-
29
- self.extend ActsAsSolr::ActsMethods
30
- end
31
-
32
-
33
- context "when getting field values" do
34
- setup do
35
- Model.columns_hash = {"birthdate" => stub("column", :type => :date)}
36
- Model.send(:get_field_value, :birthdate)
37
- end
38
-
39
- should "define an accessor methods for a solr converted value" do
40
- assert Model.instance_methods.include?("birthdate_for_solr")
41
- end
42
-
43
- context "for date types" do
44
- setup do
45
- @model = Model.new(Date.today)
46
- end
47
-
48
- should "return nil when field is nil" do
49
- @model.birthdate = nil
50
- assert_nil @model.birthdate_for_solr
51
- end
52
-
53
- should "return the formatted date" do
54
- assert_equal Date.today.strftime("%Y-%m-%dT%H:%M:%SZ"), @model.birthdate_for_solr
55
- end
56
- end
57
-
58
- context "for timestamp types" do
59
- setup do
60
- @now = Time.now
61
- @model = Model.new(@now)
62
- end
63
-
64
- should "return a formatted timestamp string for timestamps" do
65
- assert_equal @now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"), @model.birthdate_for_solr
66
- end
67
- end
68
- end
69
-
70
- end