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,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Blacklight::Solr::Document::Email" do
4
+ before(:all) do
5
+ SolrDocument.use_extension( Blacklight::Solr::Document::Email )
6
+ end
7
+ it "should only return values that are available in the field semantics" do
8
+ doc = SolrDocument.new({:id=>"1234", :title_display=>"My Title"})
9
+ email_body = doc.to_email_text
10
+ email_body.should match(/Title: My Title/)
11
+ email_body.should_not match(/Author/)
12
+ end
13
+ it "should handle multi-values fields correctly" do
14
+ doc = SolrDocument.new({:id=>"1234", :title_display=>["My Title", "My Alt. Title"]})
15
+ email_body = doc.to_email_text
16
+ email_body.should match(/Title: My Title My Alt. Title/)
17
+ end
18
+ it "should return nil if there are no valid field semantics to build the email body from" do
19
+ doc = SolrDocument.new({:id=>"1234"})
20
+ doc.to_email_text.should be_nil
21
+ end
22
+ end
23
+
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Blacklight::Solr::Document::Email" do
4
+ before(:all) do
5
+ SolrDocument.use_extension( Blacklight::Solr::Document::Sms )
6
+ end
7
+ it "should only return values that are available in the field semantics" do
8
+ doc = SolrDocument.new({:id=>"1234", :title_display=>"My Title", :author_display=>"Joe Schmoe"})
9
+ sms_text = doc.to_sms_text
10
+ sms_text.should match(/My Title by Joe Schmoe/)
11
+ end
12
+ it "should handle multi-values fields correctly and only take the first" do
13
+ doc = SolrDocument.new({:id=>"1234", :title_display=>["My Title", "My Alt. Title"]})
14
+ sms_text = doc.to_sms_text
15
+ sms_text.should match(/My Title/)
16
+ sms_text.should_not match(/My Alt\. Title/)
17
+ end
18
+ it "should return nil if there are no valid field semantics to build the email body from" do
19
+ doc = SolrDocument.new({:id=>"1234"})
20
+ doc.to_sms_text.should be_nil
21
+ end
22
+ end
23
+
@@ -0,0 +1,41 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Blacklight::Solr::Document::DublinCore" do
4
+ before(:all) do
5
+ @mock_class = Class.new do
6
+ include Blacklight::Solr::Document
7
+ end
8
+ @mock_class.use_extension( Blacklight::Solr::Document::DublinCore )
9
+ @mock_class.field_semantics.merge!(
10
+ :title => :title_display,
11
+ :non_dc_title => :title_display
12
+ )
13
+ end
14
+
15
+
16
+ it "should register all its export formats" do
17
+ document = @mock_class.new
18
+ Set.new(document.export_formats.keys).should be_superset(Set.new([:oai_dc_xml,:dc_xml, :xml]))
19
+ end
20
+
21
+ it "should export oai_dc with the proper namespaces" do
22
+ document = @mock_class.new
23
+ document.export_as_oai_dc_xml.should match 'xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"'
24
+
25
+ end
26
+
27
+ it "should include 'dc:'-prefixed semantic fields" do
28
+ data = {'id'=>'123456','title_display'=>['654321'] }
29
+ document = @mock_class.new(data)
30
+ document.export_as_oai_dc_xml.should match 'xmlns:dc="http://purl.org/dc/elements/1.1/"'
31
+ document.export_as_oai_dc_xml.should match '<dc:title>654321</dc:title>'
32
+ end
33
+
34
+ it "should work with multi-value fields" do
35
+ data = {'id'=>'123456','title_display'=>['654321', '987'] }
36
+ document = @mock_class.new(data)
37
+ document.export_as_oai_dc_xml.should match '<dc:title>654321</dc:title>'
38
+ document.export_as_oai_dc_xml.should match '<dc:title>987</dc:title></oai_dc:dc>'
39
+ end
40
+ end
41
+
@@ -0,0 +1,88 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+
4
+ describe "Blacklight::Solr::Document::Marc" do
5
+ before(:all) do
6
+ @mock_class = Class.new do
7
+ include Blacklight::Solr::Document
8
+ end
9
+ @mock_class.use_extension( Blacklight::Solr::Document::Marc )
10
+ @mock_class.extension_parameters[:marc_source_field] = :marc
11
+ end
12
+
13
+ describe "marc binary mode" do
14
+ before(:each) do
15
+ @mock_class.extension_parameters[:marc_format_type] = :marc21
16
+ end
17
+ it "should read and parse a marc binary file" do
18
+ document = @mock_class.new(:marc => sample_marc_binary )
19
+ document.to_marc.should == marc_from_string(:binary => sample_marc_binary )
20
+ end
21
+ end
22
+
23
+ describe "marcxml mode" do
24
+ before(:each) do
25
+ @mock_class.extension_parameters[:marc_format_type] = :marcxml
26
+ end
27
+ it "should read and parse a marc xml file" do
28
+ document = @mock_class.new(:marc => sample_marc_xml)
29
+ document.to_marc.should == marc_from_string(:xml => sample_marc_xml)
30
+ end
31
+ end
32
+
33
+ it "should register all its export formats" do
34
+ document = @mock_class.new
35
+ Set.new(document.export_formats.keys).should be_superset(Set.new([:marc, :marcxml, :openurl_ctx_kev, :refworks_marc_txt, :endnote, :xml]))
36
+ end
37
+
38
+
39
+
40
+ def sample_marc_xml
41
+ "<record>
42
+ <leader>01182pam a22003014a 4500</leader>
43
+ <controlfield tag=\"001\">a4802615</controlfield>
44
+ <controlfield tag=\"003\">SIRSI</controlfield>
45
+ <controlfield tag=\"008\">020828s2003 enkaf b 001 0 eng </controlfield>
46
+
47
+ <datafield tag=\"245\" ind1=\"0\" ind2=\"0\">
48
+ <subfield code=\"a\">Apples :</subfield>
49
+ <subfield code=\"b\">botany, production, and uses /</subfield>
50
+ <subfield code=\"c\">edited by D.C. Ferree and I.J. Warrington.</subfield>
51
+ </datafield>
52
+
53
+ <datafield tag=\"260\" ind1=\" \" ind2=\" \">
54
+ <subfield code=\"a\">Oxon, U.K. ;</subfield>
55
+ <subfield code=\"a\">Cambridge, MA :</subfield>
56
+ <subfield code=\"b\">CABI Pub.,</subfield>
57
+ <subfield code=\"c\">c2003.</subfield>
58
+ </datafield>
59
+
60
+ <datafield tag=\"700\" ind1=\"1\" ind2=\" \">
61
+ <subfield code=\"a\">Ferree, David C.</subfield>
62
+ <subfield code=\"q\">(David Curtis),</subfield>
63
+ <subfield code=\"d\">1943-</subfield>
64
+ </datafield>
65
+
66
+ <datafield tag=\"700\" ind1=\"1\" ind2=\" \">
67
+ <subfield code=\"a\">Warrington, I. J.</subfield>
68
+ <subfield code=\"q\">(Ian J.)</subfield>
69
+ </datafield>
70
+ </record>"
71
+ end
72
+
73
+
74
+ def sample_marc_binary
75
+ "00386pam a22001094a 4500001000900000003000600009008004100015245008900056260005400145700004500199700003200244\036a4802615\036SIRSI\036020828s2003 enkaf b 001 0 eng \03600\037aApples :\037bbotany, production, and uses /\037cedited by D.C. Ferree and I.J. Warrington.\036 \037aOxon, U.K. ;\037aCambridge, MA :\037bCABI Pub.,\037cc2003.\0361 \037aFerree, David C.\037q(David Curtis),\037d1943-\0361 \037aWarrington, I. J.\037q(Ian J.)\036\035"
76
+ end
77
+ def marc_from_string(args = {})
78
+ if args[:binary]
79
+ reader = MARC::Reader.new(StringIO.new(args[:binary]))
80
+ reader.each {|rec| return rec }
81
+ elsif args[:xml]
82
+ reader = MARC::XMLReader.new(StringIO.new(args[:xml]))
83
+ reader.each {|rec| return rec }
84
+ end
85
+ return nil
86
+ end
87
+ end
88
+
@@ -0,0 +1,173 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'rubygems'
3
+
4
+ describe "Blacklight::Solr::Document" do
5
+ class MockDocument
6
+ include Blacklight::Solr::Document
7
+ end
8
+
9
+ module MockExtension
10
+ def my_extension_method
11
+ "my_extension_results"
12
+ end
13
+ end
14
+
15
+ module MockSecondExtension
16
+ def my_extension_method
17
+ "override"
18
+ end
19
+ end
20
+
21
+
22
+ context "Extendability" do
23
+ before(:each) do
24
+ #Clear extensions
25
+ MockDocument.registered_extensions = []
26
+ end
27
+
28
+ it "should let you register an extension" do
29
+ MockDocument.use_extension(MockExtension) { |doc| true }
30
+
31
+ MockDocument.registered_extensions.find {|a| a[:module_obj] == MockExtension}.should_not be_nil
32
+ end
33
+ it "should let you register an extension with a nil condition proc" do
34
+ MockDocument.use_extension(MockExtension) { |doc| true }
35
+ MockDocument.registered_extensions.find {|a| a[:module_obj] == MockExtension}.should_not be_nil
36
+ end
37
+ it "should apply an extension whose condition is met" do
38
+ MockDocument.use_extension(MockExtension) {|doc| true}
39
+ doc = MockDocument.new()
40
+
41
+ doc.methods.find {|name| name =="my_extension_method"}.should_not be_nil
42
+ doc.my_extension_method.should == "my_extension_results"
43
+ end
44
+ it "should apply an extension based on a Solr field" do
45
+ MockDocument.use_extension(MockExtension) {|doc| doc.key?(:required_key)}
46
+
47
+ with_extension = MockDocument.new(:required_key => "value")
48
+ with_extension.my_extension_method.should == "my_extension_results"
49
+
50
+ without_extension = MockDocument.new(:other_key => "value")
51
+ without_extension.methods.find {|name| name == "my_extension_method"}.should be_nil
52
+
53
+ end
54
+ it "should not apply an extension whose condition is not met" do
55
+ MockDocument.use_extension(MockExtension) {|doc| false}
56
+ doc = MockDocument.new()
57
+
58
+ doc.methods.find {|name| name == "my_extension_method"}.should be_nil
59
+ end
60
+ it "should treat a nil condition as always applyable" do
61
+ MockDocument.use_extension(MockExtension)
62
+
63
+ doc = MockDocument.new()
64
+
65
+ doc.methods.find {|name | name=="my_extension_method"}.should_not be_nil
66
+ doc.my_extension_method.should == "my_extension_results"
67
+ end
68
+ it "should let last extension applied override earlier extensions" do
69
+ MockDocument.use_extension(MockExtension)
70
+ MockDocument.use_extension(MockSecondExtension)
71
+
72
+ MockDocument.new().my_extension_method.should == "override"
73
+ end
74
+
75
+ describe "extension_parameters class-level hash" do
76
+ it "should provide an extension_parameters hash at the class level" do
77
+ MockDocument.extension_parameters[:key] = "value"
78
+ MockDocument.extension_parameters[:key].should == "value"
79
+ end
80
+
81
+ it "extension_parameters should not be shared between classes" do
82
+ class_one = Class.new do
83
+ include Blacklight::Solr::Document
84
+ end
85
+ class_two = Class.new do
86
+ include Blacklight::Solr::Document
87
+ end
88
+
89
+ class_one.extension_parameters[:key] = "class_one_value"
90
+ class_two.extension_parameters[:key] = "class_two_value"
91
+
92
+ class_one.extension_parameters[:key].should == "class_one_value"
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ context "Will export as" do
99
+ class MockDocument
100
+ include Blacklight::Solr::Document
101
+
102
+ def export_as_marc
103
+ "fake_marc"
104
+ end
105
+ end
106
+
107
+ it "reports it's exportable formats properly" do
108
+ doc = MockDocument.new
109
+ doc.will_export_as(:marc, "application/marc" )
110
+ doc.export_formats.should have_key(:marc)
111
+ doc.export_formats[:marc][:content_type].should == "application/marc"
112
+ end
113
+
114
+ it "looks up content-type from Mime::Type if not given in arg" do
115
+ doc = MockDocument.new
116
+ doc.will_export_as(:html)
117
+ doc.export_formats.should have_key(:html)
118
+ end
119
+
120
+ context "format not registered with Mime::Type" do
121
+ before(:all) do
122
+ @doc = MockDocument.new
123
+ @doc.will_export_as(:mock2, "application/mock2" )
124
+ # Mime::Type doesn't give us a good way to clean up our new
125
+ # registration in an after, sorry.
126
+ end
127
+ it "registers format" do
128
+ defined?("Mime::MOCK2").should be_true
129
+ end
130
+ it "registers as alias only" do
131
+ Mime::Type.lookup("application/mock2").should_not equal(Mime::Type.lookup_by_extension("mock2"))
132
+ end
133
+ end
134
+
135
+ it "export_as(:format) by calling export_as_format" do
136
+ doc = MockDocument.new
137
+ doc.will_export_as(:marc, "application/marc")
138
+ doc.export_as(:marc).should == "fake_marc"
139
+ end
140
+ end
141
+
142
+ context "to_semantic_fields" do
143
+ class MockDocument
144
+ include Blacklight::Solr::Document
145
+ end
146
+ before do
147
+ MockDocument.field_semantics.merge!( :title => "title_field", :author => "author_field", :something => "something_field" )
148
+
149
+ @doc1 = MockDocument.new(
150
+ "title_field" => "doc1 title",
151
+ "something_field" => ["val1", "val2"],
152
+ "not_in_list_field" => "weird stuff"
153
+ )
154
+ end
155
+
156
+ it "should return complete dictionary based on config'd fields" do
157
+ @doc1.to_semantic_values.should == {:title => ["doc1 title"], :something => ["val1", "val2"]}
158
+ end
159
+ it "should return empty array for a key without a value" do
160
+ @doc1.to_semantic_values[:author].should == []
161
+ @doc1.to_semantic_values[:nonexistent_token].should == []
162
+ end
163
+ it "should return an array even for a single-value field" do
164
+ @doc1.to_semantic_values[:title].should be_kind_of(Array)
165
+ end
166
+ it "should return complete array for a multi-value field" do
167
+ @doc1.to_semantic_values[:something].should == ["val1", "val2"]
168
+ end
169
+
170
+ end
171
+
172
+
173
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Blacklight do
4
+
5
+ context "locate_path" do
6
+
7
+ it "should find app/controllers/application_controller.rb" do
8
+ result = Blacklight.locate_path 'app', 'controllers', 'application_controller.rb'
9
+ result.should_not == nil
10
+ end
11
+
12
+ it "should not find blah.rb" do
13
+ result = Blacklight.locate_path 'blah.rb'
14
+ result.should == nil
15
+ end
16
+
17
+ end
18
+
19
+ context 'root' do
20
+
21
+ before(:all) do
22
+ @blroot = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
23
+ end
24
+
25
+ it 'should return the full path to the BL plugin' do
26
+ Blacklight.root.should == @blroot
27
+ end
28
+
29
+ it 'should return the full path to the model directory' do
30
+ Blacklight.models_dir.should == @blroot + "/app/models"
31
+ end
32
+
33
+ it 'should return the full path to the controllers directory' do
34
+ Blacklight.controllers_dir.should == @blroot + "/app/controllers"
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,97 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Blacklight::Configurable do
4
+
5
+ class TestConfig
6
+ extend Blacklight::Configurable
7
+ end
8
+
9
+ before(:each) do
10
+ TestConfig.reset_configs!
11
+ end
12
+
13
+ it "should respond to configure" do
14
+ TestConfig.respond_to? :configure
15
+ end
16
+
17
+ describe "the default state" do
18
+ describe "config" do
19
+ it "should be a Hash" do
20
+ TestConfig.config.should be_a Hash
21
+ end
22
+ end
23
+ describe "configs[:shared]" do
24
+ it "should be a Hash" do
25
+ TestConfig.configs[:shared].should be_a Hash
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "configs[:shared]" do
31
+ it "should not have the values of its members altered by other environments" do
32
+ TestConfig.configure do |config|
33
+ config[:key] = ":shared value"
34
+ end
35
+ TestConfig.configure(::Rails.env) do |config|
36
+ config[:key] = ":test value"
37
+ end
38
+ TestConfig.config[:key].should == ":test value"
39
+ TestConfig.configs[:shared][:key].should == ":shared value"
40
+ TestConfig.configs[::Rails.env][:key].should == ":test value"
41
+ end
42
+ end
43
+
44
+ describe "the #configure method behavior" do
45
+ it "requires a block" do
46
+ lambda{TestConfig.configure}.should raise_error(LocalJumpError)
47
+ end
48
+ it "yields a hash" do
49
+ TestConfig.configure{|config| config.should be_a(Hash) }
50
+ end
51
+ it "should clear the configs if reset_configs! is called" do
52
+ TestConfig.configure do |config|
53
+ config[:asdf] = 'asdf'
54
+ end
55
+ TestConfig.configs[:shared][:asdf].should == 'asdf'
56
+ TestConfig.reset_configs!
57
+ TestConfig.configs[:shared][:asdf].should == nil
58
+ end
59
+
60
+ it "should merge settings from the :shared environment" do
61
+ TestConfig.configure do |config|
62
+ config[:app_id] = 'Blacklight'
63
+ config[:mode] = :shared!
64
+ end
65
+ TestConfig.configure(::Rails.env) do |config|
66
+ config[:mode] = ::Rails.env
67
+ end
68
+ TestConfig.config[:app_id].should == 'Blacklight'
69
+ TestConfig.config[:mode].should_not == :shared!
70
+ TestConfig.config[:mode].should == ::Rails.env
71
+ end
72
+ end
73
+
74
+ describe "config" do
75
+ it "should return an empty Hash if nothing was configured" do
76
+ TestConfig.config.should == {}
77
+ end
78
+
79
+ it "should return only what is in configs[:shared] if no other environment was configured" do
80
+ TestConfig.configure(:shared) do |config|
81
+ config[:foo] = 'bar'
82
+ config[:baz] = 'dang'
83
+ end
84
+ TestConfig.config.should == {:foo => 'bar', :baz => 'dang'}
85
+ TestConfig.config.should == TestConfig.configs[:shared]
86
+ end
87
+
88
+ it "should return a merge of configs[:shared] and configs[RAILS_ENV]" do
89
+ TestConfig.configure(:shared) do |config|
90
+ config[:foo] = 'bar'
91
+ config[:baz] = 'dang'
92
+ end
93
+ end
94
+ end
95
+
96
+
97
+ end