blacklight 3.0pre1 → 3.0pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/.gitmodules +0 -6
  2. data/README.rdoc +94 -87
  3. data/blacklight.gemspec +1 -1
  4. data/config/routes.rb +1 -1
  5. data/lib/blacklight.rb +2 -2
  6. data/lib/blacklight/catalog.rb +10 -12
  7. data/lib/blacklight/controller.rb +2 -2
  8. data/lib/blacklight/engine.rb +5 -2
  9. data/lib/blacklight/solr/document.rb +1 -1
  10. data/lib/blacklight/solr/document/marc.rb +1 -16
  11. data/lib/blacklight/solr_helper.rb +43 -14
  12. data/lib/blacklight/version.rb +1 -1
  13. data/lib/generators/blacklight/assets_generator.rb +25 -0
  14. data/lib/generators/blacklight/blacklight_generator.rb +16 -1
  15. data/lib/generators/blacklight/jetty_generator.rb +101 -0
  16. data/lib/generators/blacklight/solr_conf_generator.rb +25 -0
  17. data/lib/generators/blacklight/templates/catalog_controller.rb +0 -1
  18. data/lib/generators/blacklight/templates/config/solr.yml +14 -2
  19. data/lib/generators/blacklight/templates/public/images/{blacklight/bg.png → bg.png} +0 -0
  20. data/lib/generators/blacklight/templates/public/images/{blacklight/border.png → border.png} +0 -0
  21. data/lib/generators/blacklight/templates/public/images/{blacklight/bul_sq_gry.gif → bul_sq_gry.gif} +0 -0
  22. data/lib/generators/blacklight/templates/public/images/{blacklight/checkmark.gif → checkmark.gif} +0 -0
  23. data/lib/generators/blacklight/templates/public/images/{blacklight/logo.png → logo.png} +0 -0
  24. data/lib/generators/blacklight/templates/public/images/{blacklight/magnifying_glass.gif → magnifying_glass.gif} +0 -0
  25. data/lib/generators/blacklight/templates/public/images/{blacklight/remove.gif → remove.gif} +0 -0
  26. data/lib/generators/blacklight/templates/public/images/{blacklight/separator.gif → separator.gif} +0 -0
  27. data/lib/generators/blacklight/templates/public/images/{blacklight/start_over.gif → start_over.gif} +0 -0
  28. data/lib/generators/blacklight/templates/public/javascripts/blacklight.js +5 -0
  29. data/lib/generators/blacklight/templates/public/stylesheets/blacklight.css +9 -3
  30. data/lib/generators/blacklight/templates/solr_conf/schema.xml +339 -0
  31. data/lib/generators/blacklight/templates/solr_conf/solrconfig.xml +578 -0
  32. data/lib/railties/all_tests.rake +11 -0
  33. data/lib/railties/blacklight.rake +0 -52
  34. data/lib/railties/blacklight_cucumber.rake +125 -0
  35. data/lib/railties/blacklight_rspec.rake +128 -0
  36. data/lib/railties/{test_solr_server.rb → jetty_solr_server.rb} +22 -45
  37. data/lib/railties/solr_marc.rake +24 -5
  38. data/test_support/.rspec +1 -0
  39. data/test_support/data/test_data.utf8.mrc +1 -0
  40. data/test_support/features/bookmarks.feature +88 -0
  41. data/test_support/features/did_you_mean.feature +129 -0
  42. data/test_support/features/folder.feature +67 -0
  43. data/test_support/features/librarian_view.feature +17 -0
  44. data/test_support/features/record_view.feature +34 -0
  45. data/test_support/features/saved_searches.feature +49 -0
  46. data/test_support/features/search.feature +86 -0
  47. data/test_support/features/search_filters.feature +121 -0
  48. data/test_support/features/search_history.feature +95 -0
  49. data/test_support/features/search_results.feature +61 -0
  50. data/test_support/features/search_sort.feature +29 -0
  51. data/test_support/features/step_definitions/bookmarks_steps.rb +5 -0
  52. data/test_support/features/step_definitions/error_steps.rb +4 -0
  53. data/test_support/features/step_definitions/folder_steps.rb +26 -0
  54. data/test_support/features/step_definitions/general_steps.rb +49 -0
  55. data/test_support/features/step_definitions/record_view_steps.rb +11 -0
  56. data/test_support/features/step_definitions/saved_searches_steps.rb +21 -0
  57. data/test_support/features/step_definitions/search_facets_steps.rb +28 -0
  58. data/test_support/features/step_definitions/search_history_steps.rb +8 -0
  59. data/test_support/features/step_definitions/search_result_steps.rb +113 -0
  60. data/test_support/features/step_definitions/search_steps.rb +102 -0
  61. data/test_support/features/step_definitions/user_steps.rb +4 -0
  62. data/test_support/features/step_definitions/web_steps.rb +211 -0
  63. data/test_support/features/support/env.rb +49 -0
  64. data/test_support/features/support/paths.rb +55 -0
  65. data/test_support/features/support/selectors.rb +39 -0
  66. data/test_support/features/unapi.feature +30 -0
  67. data/test_support/spec/controllers/application_controller_spec.rb +22 -0
  68. data/test_support/spec/controllers/catalog_controller_spec.rb +480 -0
  69. data/test_support/spec/controllers/folder_controller_spec.rb +40 -0
  70. data/test_support/spec/controllers/search_history_controller_spec.rb +45 -0
  71. data/test_support/spec/data/sample_docs.yml +655 -0
  72. data/test_support/spec/data/test_data.utf8.mrc +1 -0
  73. data/test_support/spec/helpers/blacklight_helper_spec.rb +482 -0
  74. data/test_support/spec/helpers/hash_as_hidden_fields_spec.rb +23 -0
  75. data/test_support/spec/helpers/render_constraints_helper_spec.rb +64 -0
  76. data/test_support/spec/helpers/search_history_helper_spec.rb +11 -0
  77. data/test_support/spec/helpers/solr_helper_spec.rb +873 -0
  78. data/test_support/spec/lib/blacklight_email_spec.rb +23 -0
  79. data/test_support/spec/lib/blacklight_sms_spec.rb +23 -0
  80. data/test_support/spec/lib/blacklight_solr_document_dublin_core_spec.rb +41 -0
  81. data/test_support/spec/lib/blacklight_solr_document_marc_spec.rb +88 -0
  82. data/test_support/spec/lib/blacklight_solr_document_spec.rb +173 -0
  83. data/test_support/spec/lib/blacklight_spec.rb +39 -0
  84. data/test_support/spec/lib/configurable_spec.rb +97 -0
  85. data/test_support/spec/lib/facet_paginator_spec.rb +93 -0
  86. data/test_support/spec/lib/marc_export_spec.rb +444 -0
  87. data/test_support/spec/lib/search_fields_spec.rb +105 -0
  88. data/test_support/spec/lib/tasks/blacklight_task_spec.rb +21 -0
  89. data/test_support/spec/lib/tasks/solr_marc_task_spec.rb +59 -0
  90. data/test_support/spec/models/bookmark_spec.rb +37 -0
  91. data/test_support/spec/models/record_mailer_spec.rb +67 -0
  92. data/test_support/spec/models/search_spec.rb +55 -0
  93. data/test_support/spec/models/solr_docment_spec.rb +111 -0
  94. data/test_support/spec/rcov.opts +3 -0
  95. data/test_support/spec/spec.opts +4 -0
  96. data/test_support/spec/spec_helper.rb +38 -0
  97. data/test_support/spec/support/action_controller.rb +42 -0
  98. data/test_support/spec/support/assert_difference.rb +16 -0
  99. data/test_support/spec/support/include_text.rb +20 -0
  100. data/test_support/spec/views/catalog/_constraints_element.html.erb_spec.rb +59 -0
  101. data/test_support/spec/views/catalog/_document_list.html.erb_spec.rb +8 -0
  102. data/test_support/spec/views/catalog/_facets.html.erb_spec.rb +182 -0
  103. data/test_support/spec/views/catalog/_index_partials/_default.erb_spec.rb +70 -0
  104. data/test_support/spec/views/catalog/_show_partials/_default.html.erb_spec.rb +70 -0
  105. data/test_support/spec/views/catalog/index.atom.builder_spec.rb +141 -0
  106. data/test_support/spec/views/catalog/show.html.erb_spec.rb +100 -0
  107. data/test_support/spec/views/catalog/unapi.xml.builder_spec.rb +45 -0
  108. metadata +95 -98
  109. data/lib/blacklight/marc.rb +0 -46
  110. data/lib/blacklight/marc/citation.rb +0 -251
  111. data/lib/railties/cucumber.rake +0 -53
  112. data/lib/railties/rspec.rake +0 -188
  113. data/spec/helpers/catalog_helper_spec.rb +0 -111
  114. data/spec/views/catalog/_sms_form.html.erb_spec.rb +0 -19
@@ -1,46 +0,0 @@
1
-
2
- ## This module and the ::Document class in it is DEPRECATED, and will go away.
3
- # It has been replaced by
4
- # code using the new document extension framework. See
5
- # Blacklight::Solr::Document::Marc and Blacklight::Solr::Document::MarcExport
6
- # This code should not really be changed, or used anymore. It is frozen
7
- # and deprecated until removed.
8
- module Blacklight::Marc
9
-
10
- autoload :Citation, 'blacklight/marc/citation.rb'
11
-
12
- class UnsupportedMarcFormatType < RuntimeError; end
13
-
14
- class Document
15
-
16
- attr_reader :marc
17
-
18
- include Citation
19
-
20
- def initialize(marc_data, marc_type)
21
- case marc_type.to_s
22
- when 'marcxml'
23
- reader = MARC::XMLReader.new(StringIO.new(marc_data)).to_a
24
- @marc = reader[0]
25
- when 'marc21'
26
- reader = MARC::Record.new_from_marc(marc_data)
27
- @marc = reader
28
- else
29
- raise UnsupportedMarcFormatType.new("Only marcxml and marc21 are supported.")
30
- end
31
- end
32
-
33
- def marc_xml
34
- @marc.to_xml.to_s
35
- end
36
-
37
- def to_xml
38
- if @marc
39
- self.marc_xml
40
- else
41
- "<not-implemented/>"
42
- end
43
- end
44
- end
45
-
46
- end
@@ -1,251 +0,0 @@
1
- ## This module is DEPRECATED, and will go away. It has been replaced by
2
- # code using the new document extension framework. See
3
- # Blacklight::Solr::Document::Marc and Blacklight::Solr::Document::MarcExport
4
- # This code should not really be changed, or used anymore. It is frozen
5
- # and deprecated until removed.
6
- module Blacklight::Marc::Citation
7
-
8
- def to_apa
9
- return nil if self.marc.blank?
10
- apa_citation(self.marc)
11
- end
12
-
13
- def to_mla
14
- return nil if self.marc.blank?
15
- mla_citation(self.marc)
16
- end
17
-
18
- def to_zotero(format)
19
- return nil if self.marc.blank?
20
- z3988_span(self.marc, format)
21
- end
22
-
23
- protected
24
-
25
- def mla_citation(record)
26
- text = ''
27
- authors_final = []
28
-
29
- #setup formatted author list
30
- authors = get_author_list(record)
31
-
32
- if authors.length < 4
33
- authors.each do |l|
34
- if l == authors.first #first
35
- authors_final.push(l)
36
- elsif l == authors.last #last
37
- authors_final.push(", and " + name_reverse(l) + ".")
38
- else #all others
39
- authors_final.push(", " + name_reverse(l))
40
- end
41
- end
42
- text += authors_final.join
43
- unless text.blank?
44
- if text[-1,1] != "."
45
- text += ". "
46
- else
47
- text += " "
48
- end
49
- end
50
- else
51
- text += authors.first + ", et al. "
52
- end
53
- # setup title
54
- title = setup_title_info(record)
55
- if !title.nil?
56
- text += "<i>" + mla_citation_title(title) + "</i> "
57
- end
58
-
59
- # Edition
60
- edition_data = setup_edition(record)
61
- text += edition_data + " " unless edition_data.nil?
62
-
63
- # Publication
64
- text += setup_pub_info(record) + ", " unless setup_pub_info(record).nil?
65
-
66
- # Get Pub Date
67
- text += setup_pub_date(record) unless setup_pub_date(record).nil?
68
- if text[-1,1] != "."
69
- text += "." unless text.nil? or text.blank?
70
- end
71
- text
72
- end
73
-
74
- def apa_citation(record)
75
- text = ''
76
- authors_list = []
77
- authors_list_final = []
78
-
79
- #setup formatted author list
80
- authors = get_author_list(record)
81
- authors.each do |l|
82
- authors_list.push(abbreviate_name(l)) unless l.nil?
83
- end
84
- authors_list.each do |l|
85
- if l == authors_list.first #first
86
- authors_list_final.push(l.strip)
87
- elsif l == authors_list.last #last
88
- authors_list_final.push(", &amp; " + l.strip)
89
- else #all others
90
- authors_list_final.push(", " + l.strip)
91
- end
92
- end
93
- text += authors_list_final.join
94
- unless text.blank?
95
- if text[-1,1] != "."
96
- text += ". "
97
- else
98
- text += " "
99
- end
100
- end
101
- # Get Pub Date
102
- text += "(" + setup_pub_date(record) + "). " unless setup_pub_date(record).nil?
103
-
104
- # setup title info
105
- title = setup_title_info(record)
106
- text += "<i>" + title + "</i> " unless title.nil?
107
-
108
- # Edition
109
- edition_data = setup_edition(record)
110
- text += edition_data + " " unless edition_data.nil?
111
-
112
- # Publisher info
113
- text += setup_pub_info(record) unless setup_pub_info(record).nil?
114
- unless text.blank?
115
- if text[-1,1] != "."
116
- text += "."
117
- end
118
- end
119
- text
120
- end
121
- def setup_pub_date(record)
122
- if !record.find{|f| f.tag == '260'}.nil?
123
- pub_date = record.find{|f| f.tag == '260'}
124
- if pub_date.find{|s| s.code == 'c'}
125
- date_value = pub_date.find{|s| s.code == 'c'}.value.gsub(/[^0-9]/, "") unless pub_date.find{|s| s.code == 'c'}.value.gsub(/[^0-9]/, "").blank?
126
- end
127
- return nil unless !date_value.nil?
128
- end
129
- date_value
130
- end
131
- def setup_pub_info(record)
132
- text = ''
133
- pub_info_field = record.find{|f| f.tag == '260'}
134
- if !pub_info_field.nil?
135
- a_pub_info = pub_info_field.find{|s| s.code == 'a'}
136
- b_pub_info = pub_info_field.find{|s| s.code == 'b'}
137
- a_pub_info = clean_end_punctuation(a_pub_info.value.strip) unless a_pub_info.nil?
138
- b_pub_info = b_pub_info.value.strip unless b_pub_info.nil?
139
- text += a_pub_info.strip unless a_pub_info.nil?
140
- if !a_pub_info.nil? and !b_pub_info.nil?
141
- text += ": "
142
- end
143
- text += b_pub_info.strip unless b_pub_info.nil?
144
- end
145
- return nil if text.strip.blank?
146
- clean_end_punctuation(text.strip)
147
- end
148
-
149
- def mla_citation_title(text)
150
- no_upcase = ["a","an","and","but","by","for","it","of","the","to","with"]
151
- new_text = []
152
- word_parts = text.split(" ")
153
- word_parts.each do |w|
154
- if !no_upcase.include? w
155
- new_text.push(w.capitalize)
156
- else
157
- new_text.push(w)
158
- end
159
- end
160
- new_text.join(" ")
161
- end
162
-
163
- def setup_title_info(record)
164
- text = ''
165
- title_info_field = record.find{|f| f.tag == '245'}
166
- if !title_info_field.nil?
167
- a_title_info = title_info_field.find{|s| s.code == 'a'}
168
- b_title_info = title_info_field.find{|s| s.code == 'b'}
169
- a_title_info = clean_end_punctuation(a_title_info.value.strip) unless a_title_info.nil?
170
- b_title_info = clean_end_punctuation(b_title_info.value.strip) unless b_title_info.nil?
171
- text += a_title_info unless a_title_info.nil?
172
- if !a_title_info.nil? and !b_title_info.nil?
173
- text += ": "
174
- end
175
- text += b_title_info unless b_title_info.nil?
176
- end
177
-
178
- return nil if text.strip.blank?
179
- clean_end_punctuation(text.strip) + "."
180
-
181
- end
182
-
183
- def clean_end_punctuation(text)
184
- if [".",",",":",";","/"].include? text[-1,1]
185
- return text[0,text.length-1]
186
- end
187
- text
188
- end
189
-
190
- def setup_edition(record)
191
- edition_field = record.find{|f| f.tag == '250'}
192
- edition_code = edition_field.find{|s| s.code == 'a'} unless edition_field.nil?
193
- edition_data = edition_code.value unless edition_code.nil?
194
- if edition_data.nil? or edition_data == '1st ed.'
195
- return nil
196
- else
197
- return edition_data
198
- end
199
- end
200
-
201
- def get_author_list(record)
202
- author_list = []
203
- authors_primary = record.find{|f| f.tag == '100'}
204
- author_primary = authors_primary.find{|s| s.code == 'a'}.value unless authors_primary.nil?
205
- author_list.push(clean_end_punctuation(author_primary)) unless author_primary.nil?
206
- authors_secondary = record.find_all{|f| ('700') === f.tag}
207
- if !authors_secondary.nil?
208
- authors_secondary.each do |l|
209
- author_list.push(clean_end_punctuation(l.find{|s| s.code == 'a'}.value)) unless l.find{|s| s.code == 'a'}.value.nil?
210
- end
211
- end
212
-
213
- author_list.uniq!
214
- author_list
215
- end
216
-
217
- def abbreviate_name(name)
218
- name_parts = name.split(", ")
219
- first_name_parts = name_parts.last.split(" ")
220
- temp_name = name_parts.first + ", " + first_name_parts.first[0,1] + "."
221
- first_name_parts.shift
222
- temp_name += " " + first_name_parts.join(" ") unless first_name_parts.empty?
223
- temp_name
224
- end
225
-
226
- def name_reverse(name)
227
- name = clean_end_punctuation(name)
228
- temp_name = name.split(", ")
229
- return temp_name.last + " " + temp_name.first
230
- end
231
-
232
- # Genrates a Z39.88 span element to pass the COinS metadata to Zotero
233
- def z3988_span(record,format)
234
- title = record.find{|field| field.tag == '245'}
235
- author = record.find{|field| field.tag == '100'}
236
- publisher_info = record.find{|field| field.tag == '260'}
237
- edition = record.find{|field| field.tag == '250'}
238
- isbn = record.find{|field| field.tag == '020'}
239
- issn = record.find{|field| field.tag == '022'}
240
- format.is_a?(Array) ? format = format[0].downcase.strip : format = format.downcase.strip
241
- text = "<span class='Z3988' "
242
- if format == 'book'
243
- text << "title='ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&amp;rft.genre=book&amp;rft.btitle=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&amp;rft.title=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&amp;rft.au=#{(author.nil? or author['a'].nil?) ? "" : CGI::escape(author['a'])}&amp;rft.date=#{(publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])}&amp;rft.pub=#{(publisher_info.nil? or publisher_info['a'].nil?) ? "" : CGI::escape(publisher_info['a'])}&amp;rft.edition=#{(edition.nil? or edition['a'].nil?) ? "" : CGI::escape(edition['a'])}&amp;rft.isbn=#{(isbn.nil? or isbn['a'].nil?) ? "" : isbn['a']}'"
244
- elsif format.include?('journal') # checking using include because institutions may use formats like Journal or Journal/Magazine
245
- text << "title='ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&amp;rft.genre=article&amp;rft.title=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&amp;rft.atitle=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&amp;rft.date=#{(publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])}&amp;rft.issn=#{(issn.nil? or issn['a'].nil?) ? "" : issn['a']}'"
246
- else
247
- text << "title='ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&amp;rft.title=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&amp;rft.creator=#{(author.nil? or author['a'].nil?) ? "" : CGI::escape(author['a'])}&amp;rft.date=#{(publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])}&amp;rft.pub=#{(publisher_info.nil? or publisher_info['a'].nil?) ? "" : CGI::escape(publisher_info['a'])}&amp;rft.format=#{CGI::escape(format)}'"
248
- end
249
- text << "></span>"
250
- end
251
- end
@@ -1,53 +0,0 @@
1
- # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
- # It is recommended to regenerate this file in the future when you upgrade to a
3
- # newer version of cucumber-rails. Consider adding your own code to a new file
4
- # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
- # files.
6
-
7
-
8
- unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
9
-
10
- vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
11
- $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
12
-
13
- begin
14
- require 'cucumber/rake/task'
15
-
16
- namespace :cucumber do
17
- Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
18
- t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
19
- t.fork = true # You may get faster startup if you set this to false
20
- t.profile = 'default'
21
- end
22
-
23
- Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
24
- t.binary = vendored_cucumber_bin
25
- t.fork = true # You may get faster startup if you set this to false
26
- t.profile = 'wip'
27
- end
28
-
29
- Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
30
- t.binary = vendored_cucumber_bin
31
- t.fork = true # You may get faster startup if you set this to false
32
- t.profile = 'rerun'
33
- end
34
-
35
- desc 'Run all features'
36
- task :all => [:ok, :wip]
37
- end
38
- desc 'Alias for cucumber:ok'
39
- task :cucumber => 'cucumber:ok'
40
-
41
- task :default => :cucumber
42
-
43
- task :features => :cucumber do
44
- STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
45
- end
46
- rescue LoadError
47
- desc 'cucumber rake task not available (cucumber not installed)'
48
- task :cucumber do
49
- abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
50
- end
51
- end
52
-
53
- end
@@ -1,188 +0,0 @@
1
- blacklight_plugin_dir = "#{File.dirname(__FILE__)}/../.."
2
-
3
- gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
4
- rspec_gem_dir = nil
5
- Dir["#{blacklight_plugin_dir}/vendor/gems/*"].each do |subdir|
6
- rspec_gem_dir = subdir if subdir.gsub("#{blacklight_plugin_dir}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb")
7
- end
8
- rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec')
9
-
10
- if rspec_gem_dir && (test ?d, rspec_plugin_dir)
11
- raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n"
12
- end
13
-
14
- if rspec_gem_dir
15
- $LOAD_PATH.unshift("#{rspec_gem_dir}/lib")
16
- elsif File.exist?(rspec_plugin_dir)
17
- $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib")
18
- end
19
-
20
- # Don't load rspec if running "rake gems:*"
21
- unless ARGV.any? {|a| a =~ /^gems/}
22
-
23
- begin
24
- require 'spec/rake/spectask'
25
- rescue MissingSourceFile
26
- module Spec
27
- module Rake
28
- class SpecTask
29
- def initialize(name)
30
- task name do
31
- # if rspec-rails is a configured gem, this will output helpful material and exit ...
32
- require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
33
-
34
- # ... otherwise, do this:
35
- raise <<-MSG
36
-
37
- #{"*" * 80}
38
- * You are trying to run an rspec rake task defined in
39
- * #{__FILE__},
40
- * but rspec can not be found in vendor/gems, vendor/plugins or system gems.
41
- #{"*" * 80}
42
- MSG
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
49
-
50
- # Rake.application.instance_variable_get('@tasks').delete('default')
51
-
52
- spec_prereq = File.exist?(File.join(::Rails.root.to_s, 'config', 'database.yml')) ? "db:test:prepare" : :noop
53
- task :noop do
54
- end
55
-
56
- # task :default => :spec
57
- task :stats => "spec:statsetup"
58
-
59
- desc "Run all specs in spec directory (excluding plugin specs)"
60
- Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
61
- t.spec_opts = ['--options', "\"#{blacklight_plugin_dir}/spec/spec.opts\""]
62
- t.spec_files = FileList['spec/**/*_spec.rb']
63
- t.rcov = true
64
- t.rcov_opts = lambda do
65
- IO.readlines("#{blacklight_plugin_dir}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
66
- end
67
- end
68
-
69
- namespace :spec do
70
- desc "Run all specs in spec directory with RCov (excluding plugin specs)"
71
- Spec::Rake::SpecTask.new(:rcov) do |t|
72
- t.spec_opts = ['--options', "\"#{blacklight_plugin_dir}/spec/spec.opts\""]
73
- t.spec_files = FileList['spec/**/*_spec.rb']
74
- t.rcov = true
75
- t.rcov_opts = lambda do
76
- IO.readlines("#{blacklight_plugin_dir}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
77
- end
78
- end
79
-
80
- desc "Print Specdoc for all specs (excluding plugin specs)"
81
- Spec::Rake::SpecTask.new(:doc) do |t|
82
- t.spec_opts = ["--format", "specdoc", "--dry-run"]
83
- t.spec_files = FileList['spec/**/*_spec.rb']
84
- end
85
-
86
- desc "Print Specdoc for all plugin examples"
87
- Spec::Rake::SpecTask.new(:plugin_doc) do |t|
88
- t.spec_opts = ["--format", "specdoc", "--dry-run"]
89
- t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
90
- end
91
-
92
- [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub|
93
- desc "Run the code examples in spec/#{sub}"
94
- Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
95
- t.spec_opts = ['--options', "\"#{blacklight_plugin_dir}/spec/spec.opts\""]
96
- t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
97
- end
98
- end
99
-
100
- desc "Run the code examples in vendor/plugins (except RSpec's own)"
101
- Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
102
- t.spec_opts = ['--options', "\"#{blacklight_plugin_dir}/spec/spec.opts\""]
103
- t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
104
- end
105
-
106
- namespace :plugins do
107
- desc "Runs the examples for rspec_on_rails"
108
- Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
109
- t.spec_opts = ['--options', "\"#{blacklight_plugin_dir}/spec/spec.opts\""]
110
- t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb']
111
- end
112
- end
113
-
114
- # Setup specs for stats
115
- task :statsetup do
116
- require 'code_statistics'
117
- ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
118
- ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
119
- ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
120
- ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
121
- ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
122
- ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
123
- ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration')
124
- ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
125
- ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
126
- ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
127
- ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
128
- ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
129
- ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
130
- ::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration')
131
- end
132
-
133
- namespace :db do
134
- namespace :fixtures do
135
- desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
136
- task :load => :environment do
137
- ActiveRecord::Base.establish_connection(Rails.env)
138
- base_dir = File.join(Rails.root, 'spec', 'fixtures')
139
- fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
140
-
141
- require 'active_record/fixtures'
142
- (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
143
- Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
144
- end
145
- end
146
- end
147
- end
148
-
149
- namespace :server do
150
- daemonized_server_pid = File.expand_path("#{blacklight_plugin_dir}/tmp/pids/spec_server.pid")
151
-
152
- desc "start spec_server."
153
- task :start do
154
- if File.exist?(daemonized_server_pid)
155
- $stderr.puts "spec_server is already running."
156
- else
157
- $stderr.puts %Q{Starting up spec_server ...}
158
- FileUtils.mkdir_p('tmp/pids') unless test ?d, 'tmp/pids'
159
- system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
160
- end
161
- end
162
-
163
- desc "stop spec_server."
164
- task :stop do
165
- unless File.exist?(daemonized_server_pid)
166
- $stderr.puts "No server running."
167
- else
168
- $stderr.puts "Shutting down spec_server ..."
169
- system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) &&
170
- File.delete(daemonized_server_pid)
171
- end
172
- end
173
-
174
- desc "restart spec_server."
175
- task :restart => [:stop, :start]
176
-
177
- desc "check if spec server is running"
178
- task :status do
179
- if File.exist?(daemonized_server_pid)
180
- $stderr.puts %Q{spec_server is running (PID: #{File.read(daemonized_server_pid).gsub("\n","")})}
181
- else
182
- $stderr.puts "No server running."
183
- end
184
- end
185
- end
186
- end
187
-
188
- end