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,88 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
- require 'class_methods'
3
- require 'search_results'
4
- require 'active_support'
5
-
6
- class User
7
- attr_accessor :name, :id
8
- def self.find(*args)
9
- @paul ||= User.new
10
- @paul.name = "Paul"
11
- @paul.id = 1
12
- @paul
13
- end
14
-
15
- def self.find_by_id(id)
16
- find
17
- end
18
-
19
- def self.primary_key
20
- "id"
21
- end
22
- end
23
-
24
- class ClassMethodsTest < Test::Unit::TestCase
25
- include ActsAsSolr::ClassMethods
26
-
27
- def solr_configuration
28
- @solr_configuration ||= {:type_field => "type_t", :primary_key_field => "id"}
29
- end
30
-
31
- context "when multi-searching" do
32
- setup do
33
- stubs(:name).returns("User")
34
- end
35
-
36
- should "include the type field in the query" do
37
- expects(:parse_query).with("name:paul", {:results_format => :objects}, "AND (type_t:User)")
38
- multi_solr_search("name:paul")
39
- end
40
-
41
- should "add all models in the query" do
42
- expects(:parse_query).with("name:paul", {:results_format => :objects, :models => ["Movie", "DVD"]}, "AND (type_t:User OR type_t:Movie OR type_t:DVD)")
43
- multi_solr_search("name:paul", :models => ["Movie", "DVD"])
44
- end
45
-
46
- should "return an empty result set if no data was returned" do
47
- stubs(:parse_query).returns(nil)
48
- result = multi_solr_search("name:paul")
49
- assert_equal 0, result.docs.size
50
- end
51
-
52
- should "return an empty result set if no results were found" do
53
- stubs(:parse_query).returns(stub(:total_hits => 0, :hits => []))
54
- result = multi_solr_search("name:paul")
55
- assert_equal 0, result.docs.size
56
- end
57
-
58
- context "with results" do
59
- should "find the objects in the database" do
60
- stubs(:parse_query).returns(stub(:total_hits => 1, :hits => ["score" => 0.12956427, "id" => ["User:1"]]))
61
- result = multi_solr_search("name:paul")
62
-
63
- assert_equal(User.find, result.docs.first)
64
- assert_equal 1, result.docs.size
65
- end
66
-
67
- context "when requesting ids" do
68
- should "return only ids" do
69
- stubs(:parse_query).returns(stub(:total_hits => 1, :hits => ["score" => 0.12956427, "id" => ["User:1"]]))
70
- result = multi_solr_search("name:paul", :results_format => :ids)
71
- assert_equal "User:1", result.docs.first["id"]
72
- end
73
- end
74
-
75
- context "with scores" do
76
- setup do
77
- solr_configuration[:primary_key_field] = nil
78
- end
79
-
80
- should "add an accessor with the solr score" do
81
- stubs(:parse_query).returns(stub(:total_hits => 1, :hits => ["score" => 0.12956427, "id" => ["User:1"]]))
82
- result = multi_solr_search("name:paul", :scores => true)
83
- assert_equal 0.12956427, result.docs.first.solr_score
84
- end
85
- end
86
- end
87
- end
88
- end
@@ -1,112 +0,0 @@
1
- require 'test_helper'
2
- require 'common_methods'
3
-
4
- class CommonMethodsTest < Test::Unit::TestCase
5
- include ActsAsSolr::CommonMethods
6
-
7
- class << self
8
- def primary_key
9
- "id"
10
- end
11
- end
12
-
13
- def id
14
- 10
15
- end
16
-
17
- context "when determining the field type" do
18
- setup do
19
- end
20
-
21
- should "return i for an integer" do
22
- assert_equal "i", get_solr_field_type(:integer)
23
- end
24
-
25
- should "return f for a float" do
26
- assert_equal "f", get_solr_field_type(:float)
27
- end
28
-
29
- should "return b for a boolean" do
30
- assert_equal "b", get_solr_field_type(:boolean)
31
- end
32
-
33
- should "return s for a string" do
34
- assert_equal "s", get_solr_field_type(:string)
35
- end
36
-
37
- should "return t for a text" do
38
- assert_equal "t", get_solr_field_type(:text)
39
- end
40
-
41
- should "return d for a date" do
42
- assert_equal "d", get_solr_field_type(:date)
43
- end
44
-
45
- should "return ri for a range_integer" do
46
- assert_equal "ri", get_solr_field_type(:range_integer)
47
- end
48
-
49
- should "return rf for a range_float" do
50
- assert_equal "rf", get_solr_field_type(:range_float)
51
- end
52
-
53
- should "return facet for a facet field" do
54
- assert_equal "facet", get_solr_field_type(:facet)
55
- end
56
-
57
- should "return the string if one was given as an argument" do
58
- assert_equal "string", get_solr_field_type("string")
59
- end
60
-
61
- should "raise an error if invalid field type was specified" do
62
- assert_raise(RuntimeError) {get_solr_field_type(:something)}
63
- end
64
-
65
- should "raise an error if argument is not symbol or string" do
66
- assert_raise(RuntimeError) {get_solr_field_type(123)}
67
- end
68
- end
69
-
70
- context "when determining a default value for a field when it's nil" do
71
- should "return 0.00 for a float" do
72
- assert_equal 0.00, set_value_if_nil("f")
73
- assert_equal 0.00, set_value_if_nil(:float)
74
- assert_equal 0.00, set_value_if_nil("rf")
75
- assert_equal 0.00, set_value_if_nil(:range_float)
76
- end
77
-
78
- should "return 0 for an integer" do
79
- assert_equal 0, set_value_if_nil(:integer)
80
- assert_equal 0, set_value_if_nil(:range_integer)
81
- assert_equal 0, set_value_if_nil("i")
82
- assert_equal 0, set_value_if_nil("ri")
83
- end
84
-
85
- should "return false for a boolean" do
86
- assert_equal "false", set_value_if_nil(:boolean)
87
- assert_equal "false", set_value_if_nil("b")
88
- end
89
-
90
- should "return empty string for strings and text" do
91
- assert_equal "", set_value_if_nil(:string)
92
- assert_equal "", set_value_if_nil(:text)
93
- assert_equal "", set_value_if_nil("t")
94
- assert_equal "", set_value_if_nil("s")
95
- end
96
-
97
- should "return an empty string for a date" do
98
- assert_equal "", set_value_if_nil(:date)
99
- assert_equal "", set_value_if_nil("d")
100
- end
101
-
102
- should "return an empty string for everything else" do
103
- assert_equal "", set_value_if_nil("something")
104
- end
105
- end
106
-
107
- context "when determining the record id" do
108
- should "return the primary key value" do
109
- assert_equal 10, record_id(self)
110
- end
111
- end
112
- end
@@ -1,326 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
- require 'instance_methods'
3
- require 'logger'
4
- module Solr; end
5
- require 'solr/xml'
6
- require 'solr/field'
7
- require 'solr/document'
8
- require 'solr_instance'
9
- require 'erb'
10
- require 'ostruct'
11
-
12
- class InstanceMethodsTest < Test::Unit::TestCase
13
-
14
- context "With a Solr record instance" do
15
- setup do
16
- @instance = SolrInstance.new
17
- end
18
-
19
- context "when checking whether indexing is disabled" do
20
-
21
- setup do
22
- @instance.configuration = {:if => true}
23
- end
24
-
25
- should "return true if the specified proc returns true " do
26
- @instance.configuration[:offline] = proc {|record| true}
27
- assert @instance.indexing_disabled?
28
- end
29
-
30
- should "return false if the specified proc returns false" do
31
- @instance.configuration[:offline] = proc {|record| false}
32
- assert !@instance.indexing_disabled?
33
- end
34
-
35
- should "return true if no valid offline option was specified" do
36
- @instance.configuration[:offline] = nil
37
- @instance.configuration[:if] = proc {true}
38
- assert !@instance.indexing_disabled?
39
- end
40
- end
41
-
42
- context "when validating the boost" do
43
- setup do
44
- @instance.solr_configuration = {:default_boost => 10.0}
45
- @instance.configuration = {:if => true}
46
- end
47
-
48
- should "accept and evaluate a block" do
49
- @instance.configuration[:boost] = proc {|record| record.boost_rate}
50
- assert_equal 10.0, @instance.send(:validate_boost, @instance.configuration[:boost])
51
- end
52
-
53
- should "accept and return a float" do
54
- @instance.configuration[:boost] = 9.0
55
- assert_equal 9.0, @instance.send(:validate_boost, @instance.configuration[:boost])
56
- end
57
-
58
- should "return the default float when the specified is negative" do
59
- @instance.configuration[:boost] = -1.0
60
- assert_equal 10.0, @instance.send(:validate_boost, @instance.configuration[:boost])
61
- end
62
-
63
- should "execute the according method when value is a symbol" do
64
- @instance.configuration[:boost] = :irate
65
- assert_equal 8.0, @instance.send(:validate_boost, @instance.configuration[:boost])
66
- end
67
-
68
- should "return the default boost when there is no valid boost" do
69
- @instance.configuration[:boost] = "boost!"
70
- assert_equal 10.0, @instance.send(:validate_boost, @instance.configuration[:boost])
71
- end
72
- end
73
-
74
- context "when determining the solr document id" do
75
- should "combine class name and id" do
76
- assert_equal "SolrInstance:10", @instance.solr_id
77
- end
78
- end
79
-
80
- context "when saving the instance to solr" do
81
- context "with indexing disabled" do
82
- setup do
83
- @instance.configuration = {:fields => [:name], :if => nil}
84
- end
85
-
86
- should "just return and do nothing" do
87
- @instance.expects(:solr_add).never
88
- @instance.expects(:solr_destroy).never
89
- assert @instance.solr_save
90
- end
91
- end
92
-
93
- context "with indexing enabled" do
94
- setup do
95
- @instance.configuration = {:fields => [:name], :if => "true", :auto_commit => true}
96
- @instance.stubs(:solr_commit)
97
- @instance.stubs(:solr_add)
98
- @instance.stubs(:to_solr_doc).returns("My test document")
99
- end
100
-
101
- should "add the solr document" do
102
- @instance.expects(:solr_add).with("My test document").once
103
- @instance.solr_save
104
- end
105
-
106
- should "commit to solr" do
107
- @instance.expects(:solr_commit).once
108
- @instance.solr_save
109
- end
110
-
111
- should "not commit if auto_commit is disabled" do
112
- @instance.configuration.merge!(:auto_commit => false)
113
- @instance.expects(:solr_commit).never
114
- @instance.solr_save
115
- end
116
-
117
- should "destroy the document if :if clause is false" do
118
- @instance.configuration.merge!(:if => "false")
119
- @instance.expects(:solr_destroy).once
120
- @instance.solr_save
121
- end
122
- end
123
- end
124
-
125
- context "when destroying an instance in solr" do
126
- setup do
127
- @instance.configuration = {:if => true, :auto_commit => true}
128
- @instance.stubs(:solr_commit)
129
- @instance.stubs(:solr_delete)
130
- end
131
-
132
- should "delete the instance" do
133
- @instance.expects(:solr_delete).with("SolrInstance:10")
134
- @instance.solr_destroy
135
- end
136
-
137
- should "commit to solr" do
138
- @instance.expects(:solr_commit)
139
- @instance.solr_destroy
140
- end
141
-
142
- should "not commit if auto_commit is disabled" do
143
- @instance.configuration.merge!(:auto_commit => false)
144
- @instance.expects(:solr_commit).never
145
- @instance.solr_destroy
146
- end
147
-
148
- context "with indexing disabled" do
149
- should "not contact solr" do
150
- @instance.configuration.merge!(:offline => true, :if => nil)
151
- @instance.expects(:solr_delete).never
152
- @instance.solr_destroy
153
- end
154
- end
155
- end
156
-
157
- context "when converting an instance to a solr document" do
158
- setup do
159
- @instance.configuration = {:if => true, :auto_commit => true, :solr_fields => {:name => {:boost => 9.0}}, :boost => 10.0}
160
- @instance.solr_configuration = {:type_field => "type", :primary_key_field => "pk_id", :default_boost => 25.0}
161
- end
162
-
163
- should "add a document boost" do
164
- assert_equal 10, @instance.to_solr_doc.boost
165
- end
166
-
167
- should "set the solr id" do
168
- assert_equal "SolrInstance:10", @instance.to_solr_doc[:id]
169
- end
170
-
171
- should "set the type field" do
172
- assert_equal "SolrInstance", @instance.to_solr_doc[:type]
173
- end
174
-
175
- should "set the primary key fields" do
176
- assert_equal("10", @instance.to_solr_doc[:pk_id])
177
- end
178
-
179
- should "add the includes if they were configured" do
180
- @instance.configuration.merge! :include => [:author]
181
- @instance.expects(:add_includes)
182
- @instance.to_solr_doc
183
- end
184
-
185
- context "with indexed fields" do
186
- should "add fields with type" do
187
- assert_equal "Chunky bacon!", @instance.to_solr_doc[:name_s]
188
- end
189
-
190
- should "add the field boost" do
191
- field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "name_s"}
192
- assert_equal 9.0, field.boost
193
- end
194
-
195
- should "set the default boost for the field, if none is configured" do
196
- @instance.configuration[:solr_fields][:name][:boost] = nil
197
- field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "name_s"}
198
- assert_equal 25.0, field.boost
199
- end
200
-
201
- should "not overwrite the type or id field" do
202
- @instance.configuration[:solr_fields] = {:type => {}, :id => {}}
203
- doc = @instance.to_solr_doc
204
- assert_not_equal "humbug", doc[:type]
205
- assert_not_equal "bogus", doc[:id]
206
- end
207
-
208
- should "set the default value if field value is nil" do
209
- @instance.name = nil
210
- @instance.expects(:set_value_if_nil).with('s')
211
- @instance.to_solr_doc
212
- end
213
-
214
- should "not include nil values" do
215
- @instance.name = ""
216
- @instance.stubs(:set_value_if_nil).returns ""
217
- assert_nil @instance.to_solr_doc[:name_s]
218
- end
219
-
220
- should "escape the contents" do
221
- @instance.name = "<script>malicious()</script>"
222
- assert_equal "&lt;script&gt;malicious()&lt;/script&gt;", @instance.to_solr_doc[:name_s]
223
- end
224
-
225
- should "use an alternate field name if specified in options" do
226
- @instance.stubs(:nickname_for_solr).returns('Nick')
227
- @instance.configuration[:solr_fields].merge! :nickname => {:as => :alias}
228
- doc = @instance.to_solr_doc
229
- assert_not_nil @instance.to_solr_doc.fields.find {|f| f.name.to_s == "alias_s"}
230
- assert_nil @instance.to_solr_doc.fields.find {|f| f.name.to_s == "nickname_s"}
231
- end
232
-
233
- context "when associations are included" do
234
- setup do
235
- class AssocLabel < String
236
- @@singular = {'people' => 'person'}
237
- def to_s
238
- self
239
- end
240
- def singularize
241
- @@singular[self]
242
- end
243
- end
244
- @assoc = AssocLabel.new('people')
245
- person = {:name => 'Hank Venture', :address => 'Venture Compound'}
246
- @people = [OpenStruct.new(person.merge(:attributes => person))]
247
- @instance.stubs(:people).returns(@people)
248
- @reflection = OpenStruct.new(:macro => :has_many)
249
- @instance.class.stubs(:reflect_on_association).returns(@reflection)
250
- @instance.configuration[:solr_includes] = {@assoc => {}}
251
- @instance.solr_configuration.merge! :default_boost => 35.0
252
- end
253
-
254
- should "set the default name for the include, if none is configured" do
255
- @instance.configuration[:solr_includes] = {@assoc => {:type => :text}}
256
- doc = @instance.to_solr_doc
257
- assert_not_nil doc.fields.find {|f| f.name.to_s == "person_s"}
258
- end
259
-
260
- should "add the include alias" do
261
- @instance.configuration[:solr_includes] = {@assoc => {:as => :human, :type => :text}}
262
- doc = @instance.to_solr_doc
263
- assert_not_nil doc.fields.find {|f| f.name.to_s == "human_s"}
264
- assert_nil doc.fields.find {|f| f.name.to_s == "person_s"}
265
- end
266
-
267
- should "add the include type" do
268
- @instance.configuration[:solr_includes] = {@assoc => {:type => :date}}
269
- @instance.expects(:get_solr_field_type).with(){|v| true}.at_least_once.returns('s')
270
- @instance.expects(:get_solr_field_type).with(:date).once.returns('d')
271
- doc = @instance.to_solr_doc
272
- end
273
-
274
- should "set the default boost for the include, if none is configured" do
275
- # @instance.configuration[:solr_includes] = {@assoc => {}}
276
- field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "person_s"}
277
- assert_equal 35.0, field.boost
278
- end
279
-
280
- should "add the include boost" do
281
- @instance.configuration[:solr_includes] = {@assoc => {:boost => 10.0}}
282
- field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "person_s"}
283
- assert_equal 10.0, field.boost
284
- end
285
-
286
- should "default to a field value with all association attributes" do
287
- # @instance.configuration[:solr_includes] = {@assoc => {}}
288
- field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "person_s"}
289
- @people.first.attributes.each do |attr, value|
290
- assert_match /#{attr}=#{value}/, field.value
291
- end
292
- end
293
-
294
- should "use a field value from an association method, if one is configured" do
295
- @instance.configuration[:solr_includes] = {@assoc => {:using => :name}}
296
- field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "person_s"}
297
- assert_equal @people.first.name, field.value
298
- end
299
-
300
- should "use a field value from a proc, if one is configured" do
301
- @instance.configuration[:solr_includes] = {@assoc => {:using => lambda{|r| r.name.reverse}}}
302
- field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "person_s"}
303
- assert_equal @people.first.name.reverse, field.value
304
- end
305
-
306
- should "join multiple values into a single field unless the :multivalued options is specified" do
307
- @instance.configuration[:solr_includes] = {@assoc => {:multivalued => :true}}
308
- second_person = {:name => 'Dean Venture', :address => 'Venture Compound'}
309
- @people << OpenStruct.new(second_person.merge(:attributes => second_person))
310
- fields = @instance.to_solr_doc.fields.select {|f| f.name.to_s == "person_s"}
311
- assert_equal @people.size, fields.size
312
- end
313
-
314
- should "include multiple values separately if the :multivalued options is specified" do
315
- # @instance.configuration[:solr_includes] = {@assoc => {}}
316
- second_person = {:name => 'Dean Venture', :address => 'Venture Compound'}
317
- @people << OpenStruct.new(second_person.merge(:attributes => second_person))
318
- fields = @instance.to_solr_doc.fields.select {|f| f.name.to_s == "person_s"}
319
- assert_not_equal @people.size, fields.size
320
- assert_equal 1, fields.size
321
- end
322
- end
323
- end
324
- end
325
- end
326
- end