-
Notifications
You must be signed in to change notification settings - Fork 253
/
search_fields_spec.rb
57 lines (47 loc) · 1.83 KB
/
search_fields_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true
describe Blacklight::SearchFields do
class MockConfig
include Blacklight::SearchFields
end
before(:all) do
@config = Blacklight::Configuration.new do |config|
config.default_solr_params = { :qt => 'search' }
config.add_search_field 'all_fields', :label => 'All Fields'
config.add_search_field 'title', :qt => 'title_search'
config.add_search_field 'author', :qt => 'author_search'
config.add_search_field 'subject', :qt => 'subject_search'
config.add_search_field 'no_display', :qt => 'something', :include_in_simple_select => false
end
end
before(:each) do
@search_field_obj = MockConfig.new
allow(@search_field_obj).to receive(:blacklight_config).and_return(@config)
end
it "returns search field list with calculated :label when needed" do
@search_field_obj.search_field_list.each do |hash|
expect(hash.label).not_to be_blank
end
end
describe "for unspecified :key" do
before do
@bad_config = MockConfig.new
end
it "raises exception on #search_field_list" do
expect { allow(@bad_config).to receive(:blacklight_config).and_return(Blacklight::Configuration.new { |config|
config.add_search_field :label => 'All Fields', :qt => 'all_fields'
config.add_search_field 'title', :qt => 'title_search'
}) }.to raise_error ArgumentError
end
end
describe "for duplicate keys" do
before do
@bad_config = MockConfig.new
end
it "raises on #search_field_list" do
expect { allow(@bad_config).to receive(:blacklight_config).and_return(Blacklight::Configuration.new { |config|
config.add_search_field 'my_key', :label => 'All Fields'
config.add_search_field 'my_key', :label => 'title'
}) }.to raise_error RuntimeError
end
end
end