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
@@ -0,0 +1,55 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in web_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the home\s?page/
12
+ '/'
13
+
14
+
15
+ when /the catalog page/
16
+ catalog_index_path
17
+
18
+ when /the folder page/
19
+ folder_index_path
20
+
21
+ when /the document page for id (.+)/
22
+ catalog_path($1)
23
+
24
+ when /the facet page for "([^\"]*)"/
25
+ catalog_facet_path($1)
26
+
27
+ when /the unAPI endpoint for "([^\"]+)" with format "([^\"]+)"/
28
+ unapi_path(:id => $1, :format => $2)
29
+
30
+ when /the unAPI endpoint for "([^\"]+)"/
31
+ unapi_path(:id => $1)
32
+
33
+ when /the unAPI endpoint/
34
+ unapi_path
35
+
36
+ # Add more mappings here.
37
+ # Here is an example that pulls values out of the Regexp:
38
+ #
39
+ # when /^(.*)'s profile page$/i
40
+ # user_profile_path(User.find_by_login($1))
41
+
42
+ else
43
+ begin
44
+ page_name =~ /the (.*) page/
45
+ path_components = $1.split(/\s+/)
46
+ self.send(path_components.push('path').join('_').to_sym)
47
+ rescue Object => e
48
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
49
+ "Now, go and add a mapping in #{__FILE__}"
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ World(NavigationHelpers)
@@ -0,0 +1,39 @@
1
+ module HtmlSelectorsHelpers
2
+ # Maps a name to a selector. Used primarily by the
3
+ #
4
+ # When /^(.+) within (.+)$/ do |step, scope|
5
+ #
6
+ # step definitions in web_steps.rb
7
+ #
8
+ def selector_for(locator)
9
+ case locator
10
+
11
+ when /the page/
12
+ "html > body"
13
+
14
+ # Add more mappings here.
15
+ # Here is an example that pulls values out of the Regexp:
16
+ #
17
+ # when /the (notice|error|info) flash/
18
+ # ".flash.#{$1}"
19
+
20
+ # You can also return an array to use a different selector
21
+ # type, like:
22
+ #
23
+ # when /the header/
24
+ # [:xpath, "//header"]
25
+
26
+ # This allows you to provide a quoted selector as the scope
27
+ # for "within" steps as was previously the default for the
28
+ # web steps:
29
+ when /"(.+)"/
30
+ $1
31
+
32
+ else
33
+ raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
34
+ "Now, go and add a mapping in #{__FILE__}"
35
+ end
36
+ end
37
+ end
38
+
39
+ World(HtmlSelectorsHelpers)
@@ -0,0 +1,30 @@
1
+ @unapi
2
+ Feature: unAPI
3
+ In order to discover underlying document data
4
+ As a user
5
+ I want to use an unAPI endpoint
6
+
7
+ Scenario: Search Page has unAPI discovery link and microformats
8
+ When I go to the catalog page
9
+ And I fill in the search box with ""
10
+ And I press "search"
11
+ Then I should see an unAPI discovery link
12
+ And I should see a "abbr" element with "class" = "unapi-id" exactly 10 times
13
+
14
+ Scenario: Document Page has an unAPI discovery link and microformat
15
+ Given I am on the document page for id 2007020969
16
+ Then I should see an unAPI discovery link
17
+ And I should see a "abbr" element with "class" = "unapi-id" at least 1 time
18
+
19
+ Scenario: unAPI endpoint with no parameters
20
+ When I go to the unAPI endpoint
21
+ Then I should see a "format" element with "name" = "oai_dc_xml" exactly 1 time
22
+
23
+ Scenario: Request list of formats for an object
24
+ When I go to the unAPI endpoint for "2007020969"
25
+ Then I should see a "format" element with "name" = "marc" exactly 1 time
26
+ Then I should see a "format" element with "name" = "oai_dc_xml" exactly 1 time
27
+
28
+ Scenario: Request format of object
29
+ When I go to the unAPI endpoint for "2007020969" with format "oai_dc_xml"
30
+ Then I should see "Strong Medicine speaks"
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ describe ApplicationController do
3
+
4
+ # HEAD CONTENT
5
+ describe "head content from variables" do
6
+
7
+ describe "#default_html_head" do
8
+ before(:each) do
9
+ controller.send(:default_html_head)
10
+ end
11
+ it "should setup js and css defaults" do
12
+ controller.javascript_includes.should include(["blacklight/jquery-1.4.2.min.js", "blacklight/jquery-ui-1.8.1.custom.min.js", "blacklight/blacklight"])#find do |item|
13
+ # item == ["jquery-1.4.2.min.js", "jquery-ui-1.7.2.custom.min.js", "blacklight", "application", "accordion", "lightbox", {:plugin=>:blacklight}]
14
+ #end
15
+
16
+ controller.stylesheet_links.should include(["blacklight/yui", "blacklight/jquery/ui-lightness/jquery-ui-1.8.1.custom.css", "blacklight/blacklight", {:media=>"all"}])
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+
@@ -0,0 +1,480 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'rubygems'
3
+ require 'marc'
4
+
5
+ describe CatalogController do
6
+ #=begin
7
+ # ROUTES and MAPPING
8
+ describe "Paths Generated by Custom Routes:" do
9
+ # paths generated by custom routes
10
+ it "should map {:controller => 'catalog', :action => 'email'} to /catalog/email" do
11
+ # RSpec <1.2.9: route_for(:controller => 'catalog', :action => 'email').should == '/catalog/email'
12
+ { :get => "/catalog/email" }.should route_to(:controller => 'catalog', :action => 'email')
13
+
14
+ end
15
+ it "should map {:controller => 'catalog', :action => 'sms'} to /catalog/sms" do
16
+ # RSpec <1.2.9: route_for(:controller => 'catalog', :action => 'sms').should == '/catalog/sms'
17
+ { :get => "/catalog/sms" }.should route_to(:controller => 'catalog', :action => 'sms')
18
+ end
19
+ it "should map { :controller => 'catalog', :action => 'show', :id => 666 } to /catalog/666" do
20
+ # RSpec <1.2.9: route_for(:controller => 'catalog', :action => 'show', :id => '666').should == '/catalog/666'
21
+ { :get => "/catalog/666" }.should route_to(:controller => 'catalog', :action => 'show', :id => "666")
22
+ end
23
+ it "should map {:controller => 'catalog', :id = '444', :action => 'image'} to /catalog/444/image" do
24
+ # RSpec <1.2.9: route_for(:controller => 'catalog', :action => 'image', :id => '444').should == '/catalog/444/image'
25
+ { :get => "/catalog/444/image" }.should route_to(:controller => "catalog", :action => "image", :id => "444")
26
+ end
27
+ it "should map {:controller => 'catalog', :id = '333', :action => 'status'} to /catalog/333/status" do
28
+ # RSpec <1.2.9: route_for(:controller => 'catalog', :action => 'status', :id => '333').should == '/catalog/333/status'
29
+ { :get => "/catalog/333/status" }.should route_to(:controller => 'catalog', :action => 'status', :id => "333")
30
+ end
31
+ it "should map {:controller => 'catalog', :id => '222', :action => 'availability'} to /catalog/222/availability" do
32
+ # RSpec <1.2.9: route_for(:controller => 'catalog', :action => 'availability', :id => '222').should == '/catalog/222/availability'
33
+ { :get => "/catalog/222/availability" }.should route_to(:controller => 'catalog', :action => 'availability', :id => "222")
34
+ end
35
+ it "should map {:controller => 'catalog', :id => '111', :action => 'librarian_view'} to /catalog/111/librarian_view" do
36
+ # RSpec <1.2.9: route_for(:controller => 'catalog', :action => 'librarian_view', :id => '111').should == '/catalog/111/librarian_view'
37
+ { :get => "/catalog/111/librarian_view" }.should route_to(:controller => 'catalog', :action => 'librarian_view', :id => "111")
38
+ end
39
+ end
40
+
41
+ # parameters generated from routes
42
+ describe "Parameters Generated from Routes:" do
43
+ it "should map /catalog/email to {:controller => 'catalog', :action => 'email'}" do
44
+ # RSpec <1.2.9: params_from(:get, '/catalog/email').should == {:controller => 'catalog', :action => 'email'}
45
+ { :get => "/catalog/email" }.should route_to(:controller => 'catalog', :action => 'email')
46
+ end
47
+ it "should map /catalog/sms to {:controller => 'catalog', :action => 'sms'}" do
48
+ #RSpec <1.2.9 :params_from(:get, '/catalog/sms').should == {:controller => 'catalog', :action => 'sms'}
49
+ { :get => "/catalog/sms" }.should route_to(:controller => 'catalog', :action => 'sms')
50
+ end
51
+ it "should map /catalog/666 to {:controller => 'catalog', :action => 'show', :id => 666}" do
52
+ #RSPEC <1.2.9 params_from(:get, '/catalog/666').should == {:controller => 'catalog', :action => 'show', :id => '666'}
53
+ { :get => "/catalog/666" }.should route_to(:controller => 'catalog', :action => 'show', :id => "666")
54
+ end
55
+ it "should map /catalog/444/image to {:controller => 'catalog', :action => 'image', :id => 444}" do
56
+ # params_from(:get, '/catalog/444/image').should == {:controller => 'catalog', :action => 'image', :id => '444'}
57
+ { :get => "/catalog/444/image" }.should route_to(:controller => 'catalog', :action => 'image', :id => "444")
58
+ end
59
+ it "should map /catalog/333/status to {:controller => 'catalog', :action => 'status', :id => 333}" do
60
+ #params_from(:get, '/catalog/333/status').should == {:controller => 'catalog', :action => 'status', :id => '333'}
61
+ { :get => "/catalog/333/status" }.should route_to(:controller => 'catalog', :action => 'status', :id => "333")
62
+ end
63
+ it "should map /catalog/222/availability to {:controller => 'catalog', :action => 'availability', :id => 222}" do
64
+ # params_from(:get, '/catalog/222/availability').should == {:controller => 'catalog', :action => 'availability', :id => '222'}
65
+ { :get => "/catalog/222/availability" }.should route_to(:controller => 'catalog', :action => 'availability', :id => "222")
66
+ end
67
+ it "should map /catalog/111/librarian_view to {:controller => 'catalog', :action => 'librarian_view', :id => 111}" do
68
+ # params_from(:get, '/catalog/111/librarian_view').should == {:controller => 'catalog', :action => 'librarian_view', :id => '111'}
69
+ { :get => "/catalog/111/librarian_view" }.should route_to(:controller => 'catalog', :action => 'librarian_view', :id => "111")
70
+ end
71
+ end
72
+
73
+
74
+
75
+ # INDEX ACTION
76
+ describe "index action" do
77
+ before(:each) do
78
+ @user_query = 'history' # query that will get results
79
+ @no_docs_query = 'sadfdsafasdfsadfsadfsadf' # query for no results
80
+ @facet_query = {"format" => 'Book'}
81
+ end
82
+
83
+ # in rails3, the assigns method within ActionDispathc::TestProcess
84
+ # kindly converts anything that desends from hash to a hash_With_indifferent_access
85
+ # which means that our solr resposne object gets replaced if we call
86
+ # assigns(:response) - so we can't do that anymore.
87
+ def assigns_response
88
+ @controller.instance_variable_get("@response")
89
+ end
90
+
91
+ it "should have no search history if no search criteria" do
92
+ session[:history] = []
93
+ get :index
94
+ session[:history].length.should == 0
95
+ end
96
+
97
+ # check each user manipulated parameter
98
+ it "should have docs and facets for query with results" do
99
+ get :index, :q => @user_query
100
+ assigns_response.docs.size.should > 1
101
+ assert_facets_have_values(assigns_response.facets)
102
+ end
103
+ it "should have docs and facets for existing facet value" do
104
+ get :index, :f => @facet_query
105
+ assigns_response.docs.size.should > 1
106
+ assert_facets_have_values(assigns_response.facets)
107
+ end
108
+ it "should have docs and facets for non-default results per page" do
109
+ num_per_page = 7
110
+ get :index, :per_page => num_per_page
111
+ assigns_response.docs.size.should == num_per_page
112
+ assert_facets_have_values(assigns_response.facets)
113
+ end
114
+
115
+ it "should have docs and facets for second page" do
116
+ page = 2
117
+ get :index, :page => page
118
+ assigns_response.docs.size.should > 1
119
+ assigns_response.params[:start].to_i.should == (page-1) * Blacklight.config[:default_solr_params][:per_page]
120
+ assert_facets_have_values(assigns_response.facets)
121
+ end
122
+
123
+ it "should have no docs or facet values for query without results" do
124
+ get :index, :q => @no_docs_query
125
+
126
+ assigns_response.docs.size.should == 0
127
+ assigns_response.facets.each do |facet|
128
+ facet.items.size.should == 0
129
+ end
130
+ end
131
+
132
+ it "should have a spelling suggestion for an appropriately poor query" do
133
+ get :index, :q => 'boo'
134
+ assigns_response.spelling.words.should_not be_nil
135
+ end
136
+
137
+ describe "session" do
138
+ it "should include :search key with hash" do
139
+ get :index
140
+ session[:search].should_not be_nil
141
+ session[:search].should be_kind_of(Hash)
142
+ end
143
+ it "should include search hash with key :q" do
144
+ get :index, :q => @user_query
145
+ session[:search].should_not be_nil
146
+ session[:search].keys.should include(:q)
147
+ session[:search][:q].should == @user_query
148
+ end
149
+ it "should include search hash with key :f" do
150
+ get :index, :f => @facet_query
151
+ session[:search].should_not be_nil
152
+ session[:search].keys.should include(:f)
153
+ session[:search][:f].should == @facet_query
154
+ end
155
+ it "should include search hash with key :per_page" do
156
+ get :index, :per_page => 10
157
+ session[:search].should_not be_nil
158
+ session[:search].keys.should include(:per_page)
159
+ session[:search][:per_page].should == "10"
160
+ end
161
+ it "should include search hash with key :page" do
162
+ get :index, :page => 2
163
+ session[:search].should_not be_nil
164
+ session[:search].keys.should include(:page)
165
+ session[:search][:page].should == "2"
166
+ end
167
+ it "should include search hash with random key" do
168
+ # cause a plugin might add an unpredictable one, we want to preserve it.
169
+ get :index, :some_weird_key => "value"
170
+ session[:search].should_not be_nil
171
+ session[:search].keys.should include(:some_weird_key)
172
+ session[:search][:some_weird_key].should == "value"
173
+ end
174
+ end
175
+
176
+ describe "with index action with arbitrary key" do
177
+ before(:each) do
178
+ session[:history] = []
179
+ get :index, :arbitrary_key_from_plugin => "value"
180
+ end
181
+ it "should save search history" do
182
+ session[:history].length.should_not == 0
183
+ end
184
+ end
185
+
186
+ # check with no user manipulation
187
+ describe "for default query" do
188
+ it "should get documents when no query" do
189
+ get :index
190
+ assigns_response.docs.size.should > 1
191
+ end
192
+ it "should get facets when no query" do
193
+ get :index
194
+ assert_facets_have_values(assigns_response.facets)
195
+ end
196
+ end
197
+
198
+ it "should get rss feed" do
199
+ get :index, :format => 'rss'
200
+ response.should be_success
201
+ end
202
+
203
+ it "should render index.html.erb" do
204
+ get :index
205
+ response.should render_template(:index)
206
+ end
207
+ # NOTE: status code is always 200 in isolation mode ...
208
+ it "HTTP status code for GET should be 200" do
209
+ get :index
210
+ response.should be_success
211
+ end
212
+
213
+ end # describe index action
214
+
215
+ describe "update action" do
216
+ doc_id = '2007020969'
217
+
218
+ it "should set counter value into session[:search]" do
219
+ put :update, :id => doc_id, :counter => 3
220
+ session[:search][:counter].should == "3"
221
+ end
222
+
223
+ it "should redirect to show action for doc id" do
224
+ put :update, :id => doc_id, :counter => 3
225
+ assert_redirected_to(catalog_path(doc_id))
226
+ end
227
+ end
228
+
229
+ # SHOW ACTION
230
+ describe "show action" do
231
+
232
+ doc_id = '2007020969'
233
+
234
+ it "should get document" do
235
+ get :show, :id => doc_id
236
+ assigns[:document].should_not be_nil
237
+ end
238
+ it "should set previous document if counter present in session" do
239
+ session[:search] = {:q => "", :counter => 2}
240
+ get :show, :id => doc_id
241
+ assigns[:previous_document].should_not be_nil
242
+ end
243
+ it "should not set previous document if counter is 1" do
244
+ session[:search] = {:counter => 1}
245
+ get :show, :id => doc_id
246
+ assigns[:previous_document].should be_nil
247
+ end
248
+ it "should not set previous or next document if session is blank" do
249
+ get :show, :id => doc_id
250
+ assigns[:previous_document].should be_nil
251
+ assigns[:next_document].should be_nil
252
+ end
253
+ it "should not set previous or next document if session[:search][:counter] is nil" do
254
+ session[:search] = {:q => ""}
255
+ get :show, :id => doc_id
256
+ assigns[:previous_document].should be_nil
257
+ assigns[:next_document].should be_nil
258
+ end
259
+ it "should set next document if counter present in session" do
260
+ session[:search] = {:q => "", :counter => 2}
261
+ get :show, :id => doc_id
262
+ assigns[:next_document].should_not be_nil
263
+ end
264
+ it "should not set next document if counter is >= number of docs" do
265
+ session[:search] = {:counter => 66666666}
266
+ get :show, :id => doc_id
267
+ assigns[:next_document].should be_nil
268
+ end
269
+
270
+ # NOTE: status code is always 200 in isolation mode ...
271
+ it "HTTP status code for GET should be 200" do
272
+ get :show, :id => doc_id
273
+ response.should be_success
274
+ end
275
+ it "should render show.html.erb" do
276
+ get :show, :id => doc_id
277
+ response.should render_template(:show)
278
+ end
279
+
280
+ describe "@document" do
281
+ before(:each) do
282
+ get :show, :id => doc_id
283
+ @document = assigns[:document]
284
+ end
285
+ it "should be a SolrDocument" do
286
+ @document.should be_instance_of(SolrDocument)
287
+ end
288
+ end
289
+
290
+ describe "with dynamic export formats" do
291
+ render_views
292
+ module FakeExtension
293
+ def self.extended(document)
294
+ document.will_export_as(:mock, "application/mock")
295
+ end
296
+
297
+ def export_as_mock
298
+ "mock_export"
299
+ end
300
+ end
301
+
302
+ before(:each) do
303
+
304
+ # Rails3 needs this to propertly setup a new mime type and
305
+ # render the results.
306
+ ActionController.add_renderer :mock do |template, options|
307
+ send_data "mock_export", :type => Mime::MOCK
308
+ end
309
+ Mime::Type.register "application/mock", :mock
310
+
311
+ SolrDocument.use_extension(FakeExtension)
312
+ end
313
+
314
+ it "should respond to an extension-registered format properly" do
315
+ get :show, :id => doc_id, :format => "mock" # This no longer works: :format => "mock"
316
+ response.should be_success
317
+ response.should contain("mock_export")
318
+ end
319
+
320
+
321
+ after(:each) do
322
+ SolrDocument.registered_extensions = nil
323
+ end
324
+ end # dynamic export formats
325
+
326
+ end # describe show action
327
+
328
+ describe "unapi" do
329
+ doc_id = '2007020969'
330
+ module FakeExtension
331
+ def self.extended(document)
332
+ document.will_export_as(:mock, "application/mock")
333
+ document.will_export_as(:mockxml, "text/xml")
334
+ end
335
+
336
+ def export_as_mock
337
+ "mock_export"
338
+ end
339
+
340
+ def export_as_mockxml
341
+ "<a><mock xml='document' /></a>"
342
+ end
343
+ end
344
+ before(:each) do
345
+ SolrDocument.registered_extensions = nil
346
+ SolrDocument.use_extension(FakeExtension)
347
+ end
348
+
349
+ it "should return an unapi formats list from config[:unapi]" do
350
+ Blacklight.config[:unapi] = { :mock => { :content_type => "application/mock" } }
351
+ get :unapi
352
+ response.should be_success
353
+ assigns[:export_formats][:mock][:content_type].should == "application/mock"
354
+ end
355
+
356
+
357
+ it "should return an unapi formats list for document" do
358
+ get :unapi, :id => doc_id
359
+ response.should be_success
360
+ assigns[:document].should be_kind_of(SolrDocument)
361
+ assigns[:export_formats].should_not be_nil
362
+ assigns[:export_formats].should be_kind_of(Hash)
363
+ assigns[:export_formats][:mock] == { :content_type => "application/mock" }
364
+ assigns[:export_formats][:mockxml] = { :content_type => 'text/xml' }
365
+ end
366
+
367
+ it "should return an unapi format export for document" do
368
+ get :unapi, :id => doc_id, :format => 'mock'
369
+ response.should be_success
370
+ response.should contain("mock_export")
371
+ end
372
+ end
373
+
374
+ describe "opensearch" do
375
+ it "should return an opensearch description" do
376
+ get :opensearch, :format => 'xml'
377
+ response.should be_success
378
+ end
379
+ it "should return valid JSON" do
380
+ get :opensearch,:format => 'json', :q => "a"
381
+ response.should be_success
382
+ end
383
+ end
384
+ #=end
385
+ describe "email/sms" do
386
+ doc_id = '2007020969'
387
+ before(:each) do
388
+ request.env["HTTP_REFERER"] = "/catalog/#{doc_id}"
389
+ SolrDocument.use_extension( Blacklight::Solr::Document::Email )
390
+ SolrDocument.use_extension( Blacklight::Solr::Document::Sms )
391
+ end
392
+ describe "email" do
393
+ it "should give error if no TO paramater" do
394
+ post :email, :id => doc_id
395
+ request.flash[:error].should == "You must enter a recipient in order to send this message"
396
+ end
397
+ it "should give an error if the email address is not valid" do
398
+ post :email, :id => doc_id, :to => 'test_bad_email'
399
+ request.flash[:error].should == "You must enter a valid email address"
400
+ end
401
+ it "should not give error if no Message paramater is set" do
402
+ post :email, :id => doc_id, :to => 'test_email@projectblacklight.org'
403
+ request.flash[:error].should be_nil
404
+ end
405
+ it "should redirect back to the record upon success" do
406
+ post :email, :id => doc_id, :to => 'test_email@projectblacklight.org'
407
+ request.flash[:error].should be_nil
408
+ request.should redirect_to(catalog_path(doc_id))
409
+ end
410
+ end
411
+ describe "sms" do
412
+ it "should give error if no phone number is given" do
413
+ post :sms, :id => doc_id, :carrier => 'att'
414
+ request.flash[:error].should == "You must enter a recipient's phone number in order to send this message"
415
+ end
416
+ it "should give an error when a carrier is not provided" do
417
+ post :sms, :id => doc_id, :to => '5555555555', :carrier => ''
418
+ request.flash[:error].should == "You must select a carrier"
419
+ end
420
+ it "should give an error when the phone number is not 10 digits" do
421
+ post :sms, :id => doc_id, :to => '555555555', :carrier => 'att'
422
+ request.flash[:error].should == "You must enter a valid 10 digit phone number"
423
+ end
424
+ it "should allow punctuation in phone number" do
425
+ post :sms, :id => doc_id, :to => '(555) 555-5555', :carrier => 'att'
426
+ request.flash[:error].should be_nil
427
+ request.should redirect_to(catalog_path(doc_id))
428
+ end
429
+ it "should redirect back to the record upon success" do
430
+ post :sms, :id => doc_id, :to => '5555555555', :carrier => 'att'
431
+ request.flash[:error].should be_nil
432
+ request.should redirect_to(catalog_path(doc_id))
433
+ end
434
+ end
435
+ describe "backwards compatbile send_record_email" do
436
+ it "should redirect to the sms action when the sms style param is passed" do
437
+ post :send_email_record, :style=>"sms"
438
+ request.should redirect_to(sms_catalog_path)
439
+ end
440
+ it "should redirect to the email action when the email style param is passed" do
441
+ post :send_email_record, :style=>"email"
442
+ request.should redirect_to(email_catalog_path)
443
+ end
444
+ it "should not do anything if a bad style is sent" do
445
+ post :send_email_record, :style=>"bad-style"
446
+ response.status.should == 404
447
+ end
448
+ end
449
+ end
450
+
451
+ describe "errors" do
452
+ it "should return status 404 for a record that doesn't exist" do
453
+ get :show, :id=>"987654321"
454
+ response.redirect_url.should == root_url
455
+ request.flash[:notice].should == "Sorry, you have requested a record that doesn't exist."
456
+ response.should_not be_success
457
+ response.status.should == 404
458
+ end
459
+ it "should return a status 500 for a bad search" do
460
+ get :index, :q=>"+"
461
+ response.redirect_url.should == root_url
462
+ request.flash[:notice].should == "Sorry, I don't understand your search."
463
+ response.should_not be_success
464
+ response.status.should == 500
465
+ end
466
+
467
+ end
468
+
469
+ end
470
+
471
+
472
+ # there must be at least one facet, and each facet must have at least one value
473
+ def assert_facets_have_values(facets)
474
+ facets.size.should > 1
475
+ # should have at least one value for each facet
476
+ facets.each do |facet|
477
+ facet.items.size.should >= 1
478
+ end
479
+ end
480
+