blacklight 3.0pre1 → 3.0pre2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,105 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Blacklight::SearchFields do
4
+
5
+ class MockConfig
6
+ include Blacklight::SearchFields
7
+
8
+ # add in a #config method that includes search field config
9
+ # that will be used by SearchFields
10
+ def config
11
+ @config ||= {:search_fields => [ {:display_label => 'All Fields', :key => "all_fields"},
12
+ {:key => 'title', :qt => 'title_search'},
13
+ {:key => 'author', :qt => 'author_search'},
14
+ {:key => 'subject', :qt=> 'subject_search'},
15
+ ['Legacy Config', 'legacy_qt'],
16
+ {:key => "no_display", :qt=>"something", :include_in_simple_select => false}
17
+ ],
18
+ :default_qt => "search"
19
+ }
20
+ end
21
+
22
+ end
23
+
24
+ before(:all) do
25
+ @search_field_obj = MockConfig.new
26
+ end
27
+
28
+ it 'should convert legacy Array config to Hash properly' do
29
+ hash = @search_field_obj.search_field_def_for_key('legacy_qt')
30
+
31
+ hash.should be_kind_of(Hash)
32
+ hash[:key].should == hash[:qt]
33
+ hash[:display_label].should == 'Legacy Config'
34
+ end
35
+
36
+ it "should return search field list with calculated :display_label when needed" do
37
+ @search_field_obj.search_field_list.each do |hash|
38
+ hash[:display_label].should_not be_blank
39
+ end
40
+ end
41
+
42
+ it "should fill in default qt where needed" do
43
+ @search_field_obj.search_field_def_for_key("all_fields")[:qt].should == Blacklight.config[:default_qt]
44
+ end
45
+
46
+ it "should return proper options_for_select arguments" do
47
+ select_arguments = @search_field_obj.search_field_options_for_select
48
+
49
+ select_arguments.each_index do |index|
50
+ argument = select_arguments[index]
51
+ config_hash = @search_field_obj.search_field_list[index]
52
+
53
+ argument.length.should == 2
54
+ argument[0].should == config_hash[:display_label]
55
+ argument[1].should == config_hash[:key]
56
+ end
57
+ end
58
+
59
+ it "should not include fields in select if :display_in_simple_search=>false" do
60
+ select_arguments = @search_field_obj.search_field_options_for_select
61
+
62
+ select_arguments.should_not include(["No Display", "no_display"])
63
+ end
64
+
65
+
66
+
67
+ it "should lookup field definitions by key" do
68
+ @search_field_obj.search_field_def_for_key("title")[:key].should == "title"
69
+ end
70
+
71
+ it "should find display_label by key" do
72
+ @search_field_obj.label_for_search_field("title").should == "Title"
73
+ end
74
+
75
+ it "should supply default label for key not found" do
76
+ @search_field_obj.label_for_search_field("non_existent_key").should == "Keyword"
77
+ end
78
+
79
+ describe "for unspecified :key" do
80
+ before do
81
+ @bad_config = MockConfig.new
82
+ @bad_config.config[:search_fields] = [
83
+ {:display_label => 'All Fields', :qt => "all_fields"},
84
+ {:key => 'title', :qt => 'title_search'}
85
+ ]
86
+ end
87
+ it "should raise exception on #search_field_list" do
88
+ lambda {@bad_config.search_field_list}.should raise_error
89
+ end
90
+ end
91
+
92
+ describe "for duplicate keys" do
93
+ before do
94
+ @bad_config = MockConfig.new
95
+ @bad_config.config[:search_fields] = [
96
+ {:display_label => 'All Fields', :key => "my_key"},
97
+ {:key => 'title', :key => 'my_key'}
98
+ ]
99
+ end
100
+ it "should raise on #search_field_list" do
101
+ lambda {@bad_config.search_field_list}.should raise_error
102
+ end
103
+ end
104
+
105
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ require "rake"
4
+
5
+ describe "blacklight:delete_old_searches" do
6
+
7
+ before do
8
+ @rake = Rake::Application.new
9
+ Rake.application = @rake
10
+ Rake.application.rake_require "../lib/railties/blacklight"
11
+ Rake::Task.define_task(:environment)
12
+ @task_name = "blacklight:delete_old_searches"
13
+ end
14
+
15
+ it "should call Search.delete_old_searches" do
16
+ days_old = 7
17
+ Search.should_receive(:delete_old_searches).with(days_old)
18
+ @rake[@task_name].invoke(days_old)
19
+ end
20
+
21
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ require "rake"
4
+ describe "solr:marc:*" do
5
+ # saves original $stdout in variable
6
+ # set $stdout as local instance of StringIO
7
+ # yields to code execution
8
+ # returns the local instance of StringIO
9
+ # resets $stout to original value
10
+ def capture_stdout
11
+ out = StringIO.new
12
+ $stdout = out
13
+ yield
14
+ return out.string
15
+ ensure
16
+ $stdout = STDOUT
17
+ end
18
+
19
+ before do
20
+ @rake = Rake::Application.new
21
+ Rake.application = @rake
22
+ Rake.application.rake_require "../lib/railties/solr_marc"
23
+ Rake::Task.define_task(:environment)
24
+ end
25
+
26
+ describe 'solr:marc:index_test_data' do
27
+ it 'should print out usage using NOOP=true' do
28
+ root = Rails.root
29
+ ENV['NOOP'] = "true"
30
+ o = capture_stdout do
31
+ @rake['solr:marc:index_test_data'].invoke
32
+ end
33
+
34
+ o.should match(Regexp.escape("SolrMarc command that will be run:"))
35
+ end
36
+ end
37
+
38
+ describe "solr:marc:index" do
39
+ it "should produce proper java command" do
40
+ # can NOT figure out how to actually run solr:marc:index and trap
41
+ # it's backtick system call. So we'll run solr:marc:index:info and
42
+ # just test it's dry run output
43
+ ENV["MARC_FILE"] = "dummy.mrc"
44
+ output = capture_stdout do
45
+ @rake['solr:marc:index:info'].invoke
46
+ end
47
+ output =~ /SolrMarc command that will be run:\n\s*\n\s*(.*)\n/
48
+ java_cmd = $1
49
+
50
+ java_cmd.should_not be_nil
51
+ java_cmd.should match "java -Xmx512m"
52
+ java_cmd.should match "-jar #{Rails.root}/lib/SolrMarc.jar"
53
+ java_cmd.should match "#{Rails.root}/config/SolrMarc/config-test.properties dummy.mrc"
54
+ java_cmd.should match "-Dsolr.hosturl=http://127.0.0.1:[0-9]{4}/solr"
55
+ end
56
+
57
+ end
58
+ end
59
+
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ module BookmarkSpecHelper
4
+ def valid_bookmark_attributes
5
+ {
6
+ :id => 1,
7
+ :user_id => 1,
8
+ :document_id => 'u001'
9
+ }
10
+ end
11
+ end
12
+
13
+ describe Bookmark do
14
+ include BookmarkSpecHelper
15
+ before(:each) do
16
+ @bookmark = Bookmark.new
17
+ end
18
+
19
+ it "should be valid" do
20
+ @bookmark.attributes = valid_bookmark_attributes
21
+ @bookmark.should be_valid
22
+ end
23
+
24
+ it "should require user_id" do
25
+ @bookmark.should have(1).error_on(:user_id)
26
+ end
27
+
28
+ it "should belong to user" do
29
+ Bookmark.reflect_on_association(:user).should_not be_nil
30
+ end
31
+
32
+ it "should be valid after saving" do
33
+ @bookmark.attributes = valid_bookmark_attributes
34
+ @bookmark.save
35
+ @bookmark.should be_valid
36
+ end
37
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+
5
+ describe RecordMailer do
6
+ before(:each) do
7
+ SolrDocument.use_extension( Blacklight::Solr::Document::Email )
8
+ SolrDocument.use_extension( Blacklight::Solr::Document::Sms )
9
+ document = SolrDocument.new({:id=>"123456", :format=>["book"], :title_display => "The horn", :language_facet => "English", :author_display => "Janetzky, Kurt"})
10
+ @documents = [document]
11
+ end
12
+ describe "email" do
13
+ before(:each) do
14
+ details = {:to => 'test@test.com', :message => "This is my message"}
15
+ @email = RecordMailer.email_record(@documents,details,'projectblacklight.org',{:host =>'projectblacklight.org', :protocol => 'https'})
16
+ end
17
+ it "should receive the TO paramater and send the email to that address" do
18
+ @email.to.should == ['test@test.com']
19
+ end
20
+ it "should start the subject w/ Item Record:" do
21
+ @email.subject.should =~ /^Item Record:/
22
+ end
23
+ it "should put the title of the item in the subject" do
24
+ @email.subject.should =~ /The horn/
25
+ end
26
+ it "should have the correct from address (w/o the port number)" do
27
+ @email.from.should == ["no-reply@projectblacklight.org"]
28
+ end
29
+ it "should print out the correct body" do
30
+ @email.body.should =~ /Title: The horn/
31
+ @email.body.should =~ /Author: Janetzky, Kurt/
32
+ @email.body.should =~ /projectblacklight.org/
33
+ end
34
+ it "should use https URLs when protocol is set" do
35
+ details = {:to => 'test@test.com', :message => "This is my message"}
36
+ @https_email = RecordMailer.email_record(@documents,details,'projectblacklight.org',{:host =>'projectblacklight.org', :protocol => 'https'})
37
+ @https_email.body.should =~ %r|https://projectblacklight.org/|
38
+ end
39
+ end
40
+
41
+ describe "SMS" do
42
+ before(:each) do
43
+ details = {:to => '5555555555', :carrier => 'att'}
44
+ @sms = RecordMailer.sms_record(@documents,details,'projectblacklight.org',{:host =>'projectblacklight.org:3000'})
45
+ end
46
+ it "should create the correct TO address for the SMS email" do
47
+ @sms.to.should == ['5555555555@txt.att.net']
48
+ end
49
+ it "should not have a subject" do
50
+ @sms.subject.should == "" unless @sms.subject.nil?
51
+ end
52
+ it "should have the correct from address (w/o the port number)" do
53
+ @sms.from.should == ["no-reply@projectblacklight.org"]
54
+ end
55
+ it "should print out the correct body" do
56
+ @sms.body.should =~ /The horn/
57
+ @sms.body.should =~ /by Janetzky, Kurt/
58
+ @sms.body.should =~ /projectblacklight.org:300/
59
+ end
60
+ it "should use https URL when protocol is set" do
61
+ details = {:to => '5555555555', :carrier => 'att'}
62
+ @https_sms = RecordMailer.sms_record(@documents,details,'projectblacklight.org',{:host =>'projectblacklight.org', :protocol => 'https'})
63
+ @https_sms.body.should =~ %r|https://projectblacklight.org/|
64
+ end
65
+ end
66
+
67
+ end
@@ -0,0 +1,55 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Search do
4
+ describe "query_params" do
5
+ before(:each) do
6
+ @search = Search.new
7
+ @query_params = { :q => "query", :f => "facet" }
8
+ end
9
+ it "should accept a Hash as the value and save without error" do
10
+ @search.query_params = @query_params
11
+ assert @search.save
12
+ end
13
+ it "should return a Hash as the value" do
14
+ @search.query_params = @query_params
15
+ assert @search.save
16
+ Search.find(@search.id).query_params.should == @query_params
17
+ end
18
+ end
19
+
20
+ describe "saved?" do
21
+ it "should be true when user_id is not NULL and greater than 0" do
22
+ @search = Search.create(:user_id => 1)
23
+ @search.saved?.should be_true
24
+ end
25
+ it "should be false when user_id is NULL or less than 1" do
26
+ @search = Search.create
27
+ @search.saved?.should_not be_true
28
+ end
29
+ end
30
+
31
+ describe "delete_old_searches" do
32
+ it "should throw an ArgumentError if days_old is not a number" do
33
+ lambda { Search.delete_old_searches("blah") }.should raise_error(ArgumentError)
34
+ end
35
+ it "should throw an ArgumentError if days_old is equal to 0" do
36
+ lambda { Search.delete_old_searches(0) }.should raise_error(ArgumentError)
37
+ end
38
+ it "should throw an ArgumentError if days_old is less than 0" do
39
+ lambda { Search.delete_old_searches(-1) }.should raise_error(ArgumentError)
40
+ end
41
+ it "should destroy searches with no user_id that are older than X days" do
42
+ Search.destroy_all
43
+ days_old = 7
44
+ unsaved_search_today = Search.create(:user_id => nil, :created_at => Date.today)
45
+ unsaved_search_past = Search.create(:user_id => nil, :created_at => Date.today - (days_old + 1).days)
46
+ saved_search_today = Search.create(:user_id => 1, :created_at => Date.today)
47
+ saved_search_past = Search.create(:user_id => 1, :created_at => (Date.today - (days_old + 1).days))
48
+ lambda do
49
+ Search.delete_old_searches(days_old)
50
+ end.should change(Search, :count).by(-1)
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,111 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+ require 'rubygems'
5
+ require 'marc'
6
+
7
+ # WARNING!!!
8
+ # If you set any values in Blacklight here, you must reset them to the original
9
+ # values in an after() block so other tests get expected results.
10
+ # Blacklight is a Singleton for application configuration.
11
+
12
+ # NOTE the helper methods below that return hashes and call to_mash.
13
+ # this will NOT be needed if using RSolr::Ext >= version 0.9.6.3
14
+
15
+ ## TODO: ALL these specs probably really ought to be on the modules
16
+ # being tested, not on the bare SolrDocument class that has no logic
17
+ # of it's own, it just includes modules. No? jrochkind 29 Mar 2010
18
+
19
+ def get_hash_with_marcxml
20
+ {'responseHeader'=>{'status'=>0,'QTime'=>0,'params'=>{'q'=>'id:00282214','wt'=>'ruby'}},'response'=>{'numFound'=>1,'start'=>0,'docs'=>[{'id'=>'00282214', "marc_display" =>'<record xmlns=\'http://www.loc.gov/MARC21/slim\'><leader>00799cam a2200241 a 4500</leader><controlfield tag=\'001\'> 00282214 </controlfield><controlfield tag=\'003\'>DLC</controlfield><controlfield tag=\'005\'>20090120022042.0</controlfield><controlfield tag=\'008\'>000417s1998 pk 000 0 urdo </controlfield><datafield tag=\'010\' ind1=\' \' ind2=\' \'><subfield code=\'a\'> 00282214 </subfield></datafield><datafield tag=\'025\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>P-U-00282214; 05; 06</subfield></datafield><datafield tag=\'040\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>DLC</subfield><subfield code=\'c\'>DLC</subfield><subfield code=\'d\'>DLC</subfield></datafield><datafield tag=\'041\' ind1=\'1\' ind2=\' \'><subfield code=\'a\'>urd</subfield><subfield code=\'h\'>snd</subfield></datafield><datafield tag=\'042\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>lcode</subfield></datafield><datafield tag=\'050\' ind1=\'0\' ind2=\'0\'><subfield code=\'a\'>PK2788.9.A9</subfield><subfield code=\'b\'>F55 1998</subfield></datafield><datafield tag=\'100\' ind1=\'1\' ind2=\' \'><subfield code=\'a\'>Ayaz, Shaikh,</subfield><subfield code=\'d\'>1923-1997.</subfield></datafield><datafield tag=\'245\' ind1=\'1\' ind2=\'0\'><subfield code=\'a\'>Fikr-i Ayāz /</subfield><subfield code=\'c\'>murattibīn, Āṣif Farruk̲h̲ī, Shāh Muḥammad Pīrzādah.</subfield></datafield><datafield tag=\'260\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>Karācī :</subfield><subfield code=\'b\'>Dāniyāl,</subfield><subfield code=\'c\'>[1998]</subfield></datafield><datafield tag=\'300\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>375 p. ;</subfield><subfield code=\'c\'>23 cm.</subfield></datafield><datafield tag=\'546\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>In Urdu.</subfield></datafield><datafield tag=\'520\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>Selected poems and articles from the works of renowned Sindhi poet; chiefly translated from Sindhi.</subfield></datafield><datafield tag=\'700\' ind1=\'1\' ind2=\' \'><subfield code=\'a\'>Farruk̲h̲ī, Āṣif,</subfield><subfield code=\'d\'>1959-</subfield></datafield><datafield tag=\'700\' ind1=\'1\' ind2=\' \'><subfield code=\'a\'>Pīrzādah, Shāh Muḥammad.</subfield></datafield></record>','timestamp'=>'2009-03-26T18:15:31.074Z','material_type_display'=>['375 p'],'title_display'=>['Fikr-i Ayāz'],'author_display'=>['Farruk̲h̲ī, Āṣif','Pīrzādah, Shāh Muḥammad'],'language_facet'=>['Urdu'],'format'=>['Book'],'published_display'=>['Karācī']}]}}
21
+ end
22
+ def get_hash_without_marcxml
23
+ {'responseHeader'=>{'status'=>0,'QTime'=>0,'params'=>{'q'=>'id:00282214','wt'=>'ruby'}},'response'=>{'numFound'=>1,'start'=>0,'docs'=>[{'id'=>'00282214','timestamp'=>'2009-03-26T18:15:31.074Z','material_type_display'=>['375 p'],'title_display'=>['Fikr-i Ayāz'],'author_display'=>['Farruk̲h̲ī, Āṣif','Pīrzādah, Shāh Muḥammad'],'language_facet'=>['Urdu'],'format'=>['Book'],'published_display'=>['Karācī']}]}}
24
+ end
25
+
26
+ def get_hash_with_marc21
27
+ reader = MARC::Reader.new(File.dirname(__FILE__) + '/../data/test_data.utf8.mrc')
28
+ # doing weird i= stuff to get only first record. reader.first, or i = 0, i+1 didn't work and this was the only way I could get it working. Needs refactoring.
29
+ i = "1st"
30
+ for record in reader
31
+ if i == "1st"
32
+ first_rec = record.to_marc
33
+ end
34
+ i = "not1st"
35
+ end
36
+ return {'responseHeader'=>{'status'=>0,'QTime'=>0,'params'=>{'q'=>'id:00282214','wt'=>'ruby'}},'response'=>{'numFound'=>1,'start'=>0,'docs'=>[{'id'=>'00282214', "marc_display" => first_rec, 'timestamp'=>'2009-03-26T18:15:31.074Z','material_type_display'=>['375 p'],'title_display'=>['Fikr-i Ayāz'],'author_display'=>['Farruk̲h̲ī, Āṣif','Pīrzādah, Shāh Muḥammad'],'language_facet'=>['Urdu'],'format'=>['Book'],'published_display'=>['Karācī']}]}}
37
+ end
38
+
39
+ describe SolrDocument do
40
+
41
+ before(:each) do
42
+ @hash_with_marcxml = get_hash_with_marcxml['response']['docs'][0]
43
+ SolrDocument.extension_parameters[:marc_source_field] = :marc_display
44
+ SolrDocument.extension_parameters[:marc_format_type] = :marcxml
45
+
46
+ # rsolr seems to reload SolrDocument from time to time, so we can't
47
+ # count on the initializer to register the extension, need to re-register
48
+ # it.
49
+ SolrDocument.registered_extensions = nil
50
+ SolrDocument.use_extension( Blacklight::Solr::Document::Marc ) { |document| document.key?(:marc_display)}
51
+
52
+ @solrdoc = SolrDocument.new(@hash_with_marcxml)
53
+
54
+ end
55
+
56
+ describe "new" do
57
+ it "should take a Hash as the argument" do
58
+ lambda { SolrDocument.new(@hash_with_marcxml) }.should_not raise_error(ArgumentError)
59
+ end
60
+ end
61
+
62
+ describe "access methods" do
63
+
64
+ it "should have the right value for format" do
65
+ @solrdoc[:format][0].should == 'Book'
66
+ end
67
+
68
+ it "should provide the item's solr id" do
69
+ @solrdoc.id.should == '00282214'
70
+ end
71
+
72
+ it "should have access methods for all special function fields named in initializer" do
73
+ # the fields specified in Blacklight.config[:show] that
74
+ Blacklight.config[:show].each_key do |function|
75
+ @solrdoc[Blacklight.config[:show][function]].should_not be_nil
76
+ end
77
+ end
78
+
79
+ end
80
+
81
+ describe "ruby marc creation" do
82
+
83
+ it "should have a valid to_marc" do
84
+ @solrdoc = SolrDocument.new(@hash_with_marcxml)
85
+
86
+ @solrdoc.should respond_to(:to_marc)
87
+ @solrdoc.to_marc.should be_kind_of(MARC::Record)
88
+ end
89
+
90
+ it "should not try to create marc for objects w/out stored marc (marcxml test only at this time)" do
91
+ # TODO: Create another mock object that does not have marc-xml in it and make
92
+ # sure everything fails gracefully
93
+ @hash_without_marcxml = get_hash_without_marcxml['response']['docs'][0]
94
+ @solrdoc_without_marc = SolrDocument.new(@hash_without_marcxml)
95
+ @solrdoc_without_marc.should_not respond_to(:to_marc)
96
+ # legacy check
97
+ # @solrdoc_without_marc.should respond_to(:marc)
98
+ # @solrdoc_without_marc.marc.should == nil
99
+ end
100
+ end
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+ end