active-fedora 13.1.2 → 13.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github_changelog_generator +2 -0
- data/CHANGELOG.md +3362 -0
- data/CONTRIBUTING.md +23 -1
- data/README.md +4 -0
- data/active-fedora.gemspec +14 -13
- data/lib/active_fedora/version.rb +1 -1
- metadata +104 -206
- data/spec/config_helper.rb +0 -17
- data/spec/fixtures/dino.jpg +0 -0
- data/spec/fixtures/dino_jpg_no_file_ext +0 -0
- data/spec/fixtures/minivan.jpg +0 -0
- data/spec/fixtures/rails_root/config/fake_fedora.yml +0 -7
- data/spec/fixtures/rails_root/config/fedora.yml +0 -12
- data/spec/fixtures/rails_root/config/solr.yml +0 -15
- data/spec/fixtures/rails_root/config/solr_mappings.yml +0 -16
- data/spec/fixtures/rails_root/config/solr_mappings_af_0.1.yml +0 -9
- data/spec/fixtures/rails_root/config/solr_mappings_bl_2.4.yml +0 -17
- data/spec/integration/associations/rdf_spec.rb +0 -61
- data/spec/integration/associations_spec.rb +0 -680
- data/spec/integration/attached_files_spec.rb +0 -146
- data/spec/integration/attributes_spec.rb +0 -73
- data/spec/integration/autosave_association_spec.rb +0 -24
- data/spec/integration/base_spec.rb +0 -184
- data/spec/integration/basic_contains_association_spec.rb +0 -121
- data/spec/integration/belongs_to_association_spec.rb +0 -260
- data/spec/integration/caching_spec.rb +0 -59
- data/spec/integration/clean_connection_spec.rb +0 -21
- data/spec/integration/collection_association_spec.rb +0 -166
- data/spec/integration/date_time_properties_spec.rb +0 -41
- data/spec/integration/delete_all_spec.rb +0 -64
- data/spec/integration/direct_container_spec.rb +0 -250
- data/spec/integration/directly_contains_one_association_spec.rb +0 -96
- data/spec/integration/eradicate_spec.rb +0 -52
- data/spec/integration/fedora_solr_sync_spec.rb +0 -30
- data/spec/integration/file_fixity_spec.rb +0 -36
- data/spec/integration/file_spec.rb +0 -221
- data/spec/integration/generators/fedora_generator_spec.rb +0 -26
- data/spec/integration/generators/solr_generator_spec.rb +0 -23
- data/spec/integration/gone_spec.rb +0 -41
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +0 -414
- data/spec/integration/has_many_associations_spec.rb +0 -436
- data/spec/integration/has_subresource_spec.rb +0 -34
- data/spec/integration/indexing/descendant_fetcher_spec.rb +0 -64
- data/spec/integration/indexing_spec.rb +0 -110
- data/spec/integration/indirect_container_spec.rb +0 -290
- data/spec/integration/json_serialization_spec.rb +0 -32
- data/spec/integration/marshal_spec.rb +0 -39
- data/spec/integration/nested_attribute_spec.rb +0 -177
- data/spec/integration/nested_hash_resources_spec.rb +0 -43
- data/spec/integration/persistence_spec.rb +0 -37
- data/spec/integration/query_result_builder_spec.rb +0 -37
- data/spec/integration/rdf_nested_attributes_spec.rb +0 -85
- data/spec/integration/relation_delegation_spec.rb +0 -52
- data/spec/integration/relation_spec.rb +0 -117
- data/spec/integration/scoped_query_spec.rb +0 -134
- data/spec/integration/scoping_spec.rb +0 -48
- data/spec/integration/solr_hit_spec.rb +0 -32
- data/spec/integration/versionable_spec.rb +0 -256
- data/spec/integration/with_metadata_spec.rb +0 -111
- data/spec/lib/active_fedora/null_logger_spec.rb +0 -10
- data/spec/rcov.opts +0 -2
- data/spec/spec.opts +0 -5
- data/spec/spec_helper.rb +0 -106
- data/spec/support/an_active_model.rb +0 -29
- data/spec/unit/active_fedora/indexing/inserter_spec.rb +0 -35
- data/spec/unit/active_fedora_spec.rb +0 -118
- data/spec/unit/aggregation/list_source_spec.rb +0 -134
- data/spec/unit/aggregation/ordered_reader_spec.rb +0 -43
- data/spec/unit/association_hash_spec.rb +0 -64
- data/spec/unit/attached_files_spec.rb +0 -218
- data/spec/unit/attributes_spec.rb +0 -146
- data/spec/unit/base_active_model_spec.rb +0 -28
- data/spec/unit/base_cma_spec.rb +0 -15
- data/spec/unit/base_extra_spec.rb +0 -33
- data/spec/unit/base_spec.rb +0 -328
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +0 -8
- data/spec/unit/callback_spec.rb +0 -65
- data/spec/unit/change_set_spec.rb +0 -60
- data/spec/unit/checksum_spec.rb +0 -25
- data/spec/unit/code_configurator_spec.rb +0 -41
- data/spec/unit/collection_proxy_spec.rb +0 -25
- data/spec/unit/config_spec.rb +0 -18
- data/spec/unit/core/fedora_id_translator_spec.rb +0 -29
- data/spec/unit/core/fedora_uri_translator_spec.rb +0 -19
- data/spec/unit/core/logger_spec.rb +0 -18
- data/spec/unit/core_spec.rb +0 -242
- data/spec/unit/default_model_mapper_spec.rb +0 -39
- data/spec/unit/fedora_spec.rb +0 -31
- data/spec/unit/file/streaming_spec.rb +0 -33
- data/spec/unit/file_configurator_spec.rb +0 -295
- data/spec/unit/file_io_spec.rb +0 -137
- data/spec/unit/file_path_builder_spec.rb +0 -18
- data/spec/unit/file_spec.rb +0 -489
- data/spec/unit/files_hash_spec.rb +0 -52
- data/spec/unit/filter_spec.rb +0 -133
- data/spec/unit/finder_methods_spec.rb +0 -154
- data/spec/unit/fixity_service_spec.rb +0 -128
- data/spec/unit/forbidden_attributes_protection_spec.rb +0 -50
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +0 -125
- data/spec/unit/has_many_association_spec.rb +0 -131
- data/spec/unit/indexers/global_indexer_spec.rb +0 -41
- data/spec/unit/indexing/map/index_object_spec.rb +0 -25
- data/spec/unit/indexing/map_spec.rb +0 -27
- data/spec/unit/indexing_service_spec.rb +0 -28
- data/spec/unit/indexing_spec.rb +0 -86
- data/spec/unit/inheritance_spec.rb +0 -60
- data/spec/unit/ldp_resource_spec.rb +0 -15
- data/spec/unit/loadable_from_json_spec.rb +0 -40
- data/spec/unit/logger_spec.rb +0 -19
- data/spec/unit/model_classifier_spec.rb +0 -49
- data/spec/unit/ordered_spec.rb +0 -367
- data/spec/unit/orders/list_node_spec.rb +0 -151
- data/spec/unit/orders/ordered_list_spec.rb +0 -335
- data/spec/unit/orders/reflection_spec.rb +0 -22
- data/spec/unit/pathing_spec.rb +0 -35
- data/spec/unit/persistence_spec.rb +0 -115
- data/spec/unit/property_predicate_spec.rb +0 -35
- data/spec/unit/property_spec.rb +0 -25
- data/spec/unit/query_result_builder_spec.rb +0 -31
- data/spec/unit/query_spec.rb +0 -307
- data/spec/unit/querying_spec.rb +0 -24
- data/spec/unit/rdf/indexing_service_spec.rb +0 -114
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/readonly_spec.rb +0 -24
- data/spec/unit/reflection_spec.rb +0 -42
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +0 -37
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +0 -38
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +0 -38
- data/spec/unit/schema_indexing_strategy_spec.rb +0 -68
- data/spec/unit/scoping_spec.rb +0 -67
- data/spec/unit/serializers_spec.rb +0 -19
- data/spec/unit/solr_config_options_spec.rb +0 -57
- data/spec/unit/solr_hit_spec.rb +0 -57
- data/spec/unit/solr_query_builder_spec.rb +0 -18
- data/spec/unit/solr_service_spec.rb +0 -165
- data/spec/unit/sparql_insert_spec.rb +0 -31
- data/spec/unit/validations_spec.rb +0 -92
- data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +0 -29
- data/spec/unit/with_metadata/metadata_node_spec.rb +0 -69
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::DefaultModelMapper do
|
4
|
-
subject(:mapper) { described_class.new classifier_class: classifier, solr_field: solr_field, predicate: predicate }
|
5
|
-
let(:classifier) { class_double(ActiveFedora::ModelClassifier) }
|
6
|
-
let(:classifier_instance) { instance_double(ActiveFedora::ModelClassifier) }
|
7
|
-
let(:solr_field) { 'solr_field' }
|
8
|
-
let(:predicate) { 'info:predicate' }
|
9
|
-
|
10
|
-
describe '#classifier' do
|
11
|
-
context 'with a solr document' do
|
12
|
-
let(:solr_document) { { 'solr_field' => ['xyz'] } }
|
13
|
-
|
14
|
-
before do
|
15
|
-
expect(classifier).to receive(:new).with(['xyz']).and_return(classifier_instance)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'creates a classifier from the solr field data' do
|
19
|
-
expect(mapper.classifier(solr_document)).to eq classifier_instance
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'with a resource' do
|
24
|
-
let(:graph) do
|
25
|
-
RDF::Graph.new << [:hello, predicate, 'xyz']
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:resource) { instance_double(ActiveFedora::LdpResource, graph: graph) }
|
29
|
-
|
30
|
-
before do
|
31
|
-
expect(classifier).to receive(:new).with(['xyz']).and_return(classifier_instance)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'creates a classifier from the resource model predicate' do
|
35
|
-
expect(mapper.classifier(resource)).to eq classifier_instance
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/spec/unit/fedora_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Fedora do
|
4
|
-
subject(:fedora) { described_class.new(config) }
|
5
|
-
describe "#authorized_connection" do
|
6
|
-
describe "with SSL options" do
|
7
|
-
let(:config) {
|
8
|
-
{ url: "https://example.com",
|
9
|
-
user: "fedoraAdmin",
|
10
|
-
password: "fedoraAdmin",
|
11
|
-
ssl: { ca_path: '/path/to/certs' } }
|
12
|
-
}
|
13
|
-
specify {
|
14
|
-
expect(Faraday).to receive(:new).with("https://example.com", ssl: { ca_path: '/path/to/certs' }).and_call_original
|
15
|
-
fedora.authorized_connection
|
16
|
-
}
|
17
|
-
end
|
18
|
-
describe "with request options" do
|
19
|
-
let(:config) {
|
20
|
-
{ url: "https://example.com",
|
21
|
-
user: "fedoraAdmin",
|
22
|
-
password: "fedoraAdmin",
|
23
|
-
request: { timeout: 600, open_timeout: 60 } }
|
24
|
-
}
|
25
|
-
specify {
|
26
|
-
expect(Faraday).to receive(:new).with("https://example.com", request: { timeout: 600, open_timeout: 60 }).and_call_original
|
27
|
-
fedora.authorized_connection
|
28
|
-
}
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::File::Streaming do
|
4
|
-
let(:test_class) do
|
5
|
-
tc = Class.new
|
6
|
-
tc.send(:include, described_class)
|
7
|
-
tc
|
8
|
-
end
|
9
|
-
let(:streamer) do
|
10
|
-
streamer = test_class.new
|
11
|
-
allow(streamer).to receive(:uri).and_return(uri)
|
12
|
-
allow(streamer).to receive(:authorization_key).and_return("authorization_key")
|
13
|
-
streamer
|
14
|
-
end
|
15
|
-
|
16
|
-
context "without ssl" do
|
17
|
-
let(:uri) { "http://localhost/file/1" }
|
18
|
-
|
19
|
-
it do
|
20
|
-
expect(Net::HTTP).to receive(:start).with('localhost', 80, use_ssl: false).and_return(nil)
|
21
|
-
streamer.stream.each
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "with ssl" do
|
26
|
-
let(:uri) { "https://localhost/file/1" }
|
27
|
-
|
28
|
-
it do
|
29
|
-
expect(Net::HTTP).to receive(:start).with('localhost', 443, use_ssl: true).and_return(nil)
|
30
|
-
streamer.stream.each
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,295 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'config_helper'
|
3
|
-
|
4
|
-
describe ActiveFedora::FileConfigurator do
|
5
|
-
subject(:configurator) { ActiveFedora.configurator }
|
6
|
-
|
7
|
-
after :all do
|
8
|
-
unstub_rails
|
9
|
-
# Restore to default fedora configs
|
10
|
-
restore_spec_configuration
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#initialize" do
|
14
|
-
it "triggers configuration reset (to empty defaults)" do
|
15
|
-
expect_any_instance_of(described_class).to receive(:reset!)
|
16
|
-
described_class.new
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "#config_options" do
|
21
|
-
before do
|
22
|
-
configurator.reset!
|
23
|
-
end
|
24
|
-
it "is an empty hash" do
|
25
|
-
expect(configurator.config_options).to eq({})
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#fedora_config" do
|
30
|
-
before do
|
31
|
-
configurator.reset!
|
32
|
-
end
|
33
|
-
it "triggers configuration to load" do
|
34
|
-
expect(configurator).to receive(:load_fedora_config)
|
35
|
-
configurator.fedora_config
|
36
|
-
end
|
37
|
-
end
|
38
|
-
describe "#solr_config" do
|
39
|
-
before do
|
40
|
-
configurator.reset!
|
41
|
-
end
|
42
|
-
it "triggers configuration to load" do
|
43
|
-
expect(configurator).to receive(:load_solr_config)
|
44
|
-
configurator.solr_config
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#reset!" do
|
49
|
-
before { configurator.reset! }
|
50
|
-
it "clears @fedora_config" do
|
51
|
-
expect(configurator.instance_variable_get(:@fedora_config)).to eq({})
|
52
|
-
end
|
53
|
-
it "clears @solr_config" do
|
54
|
-
expect(configurator.instance_variable_get(:@solr_config)).to eq({})
|
55
|
-
end
|
56
|
-
it "clears @config_options" do
|
57
|
-
expect(configurator.instance_variable_get(:@config_options)).to eq({})
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "initialization methods" do
|
62
|
-
describe "config_path(:fedora)" do
|
63
|
-
it "uses the config_options[:config_path] if it exists" do
|
64
|
-
expect(configurator).to receive(:config_options).and_return(fedora_config_path: "/path/to/fedora.yml")
|
65
|
-
expect(File).to receive(:file?).with("/path/to/fedora.yml").and_return(true)
|
66
|
-
expect(configurator.config_path(:fedora)).to eql("/path/to/fedora.yml")
|
67
|
-
end
|
68
|
-
|
69
|
-
it "looks in Rails.root/config/fedora.yml if it exists and no fedora_config_path passed in" do
|
70
|
-
expect(configurator).to receive(:config_options).and_return({})
|
71
|
-
stub_rails(root: "/rails/root")
|
72
|
-
expect(File).to receive(:file?).with("/rails/root/config/fedora.yml").and_return(true)
|
73
|
-
expect(configurator.config_path(:fedora)).to eql("/rails/root/config/fedora.yml")
|
74
|
-
unstub_rails
|
75
|
-
end
|
76
|
-
|
77
|
-
it "looks in ./config/fedora.yml if neither rails.root nor :fedora_config_path are set" do
|
78
|
-
expect(configurator).to receive(:config_options).and_return({})
|
79
|
-
allow(Dir).to receive(:getwd).and_return("/current/working/directory")
|
80
|
-
expect(File).to receive(:file?).with("/current/working/directory/config/fedora.yml").and_return(true)
|
81
|
-
expect(configurator.config_path(:fedora)).to eql("/current/working/directory/config/fedora.yml")
|
82
|
-
end
|
83
|
-
|
84
|
-
it "returns default fedora.yml that ships with active-fedora if none of the above" do
|
85
|
-
expect(configurator).to receive(:config_options).and_return({})
|
86
|
-
expect(Dir).to receive(:getwd).and_return("/current/working/directory")
|
87
|
-
expect(File).to receive(:file?).with("/current/working/directory/config/fedora.yml").and_return(false)
|
88
|
-
expect(File).to receive(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"), 'config', 'fedora.yml'))).and_return(true)
|
89
|
-
expect(ActiveFedora::Base.logger).to receive(:warn).with("Using the default fedora.yml that comes with active-fedora. If you want to override this, pass the path to fedora.yml to ActiveFedora - ie. ActiveFedora.init(:fedora_config_path => '/path/to/fedora.yml') - or set Rails.root and put fedora.yml into \#{Rails.root}/config.")
|
90
|
-
expect(configurator.config_path(:fedora)).to eql(File.expand_path(File.join(File.dirname("__FILE__"), 'config', 'fedora.yml')))
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "config_path(:solr)" do
|
95
|
-
it "returns the solr_config_path if set in config_options hash" do
|
96
|
-
allow(configurator).to receive(:config_options).and_return(solr_config_path: "/path/to/solr.yml")
|
97
|
-
expect(File).to receive(:file?).with("/path/to/solr.yml").and_return(true)
|
98
|
-
expect(configurator.config_path(:solr)).to eql("/path/to/solr.yml")
|
99
|
-
end
|
100
|
-
|
101
|
-
it "returns the solr.yml file in the same directory as the fedora.yml if it exists" do
|
102
|
-
expect(configurator).to receive(:path).and_return("/path/to/fedora/config/fedora.yml")
|
103
|
-
expect(File).to receive(:file?).with("/path/to/fedora/config/solr.yml").and_return(true)
|
104
|
-
expect(configurator.config_path(:solr)).to eql("/path/to/fedora/config/solr.yml")
|
105
|
-
end
|
106
|
-
|
107
|
-
context "no solr.yml in same directory as fedora.yml and fedora.yml does not contain solr url" do
|
108
|
-
before do
|
109
|
-
allow(configurator).to receive(:config_options).and_return({})
|
110
|
-
expect(configurator).to receive(:path).and_return("/path/to/fedora/config/fedora.yml")
|
111
|
-
expect(File).to receive(:file?).with("/path/to/fedora/config/solr.yml").and_return(false)
|
112
|
-
end
|
113
|
-
after do
|
114
|
-
unstub_rails
|
115
|
-
end
|
116
|
-
|
117
|
-
it "does not raise an error if there is not a solr.yml in the same directory as the fedora.yml and the fedora.yml has a solr url defined and look in rails.root" do
|
118
|
-
stub_rails(root: "/rails/root")
|
119
|
-
expect(File).to receive(:file?).with("/rails/root/config/solr.yml").and_return(true)
|
120
|
-
expect(configurator.config_path(:solr)).to eql("/rails/root/config/solr.yml")
|
121
|
-
end
|
122
|
-
|
123
|
-
it "looks in ./config/solr.yml if no rails root" do
|
124
|
-
allow(Dir).to receive(:getwd).and_return("/current/working/directory")
|
125
|
-
expect(File).to receive(:file?).with("/current/working/directory/config/solr.yml").and_return(true)
|
126
|
-
expect(configurator.config_path(:solr)).to eql("/current/working/directory/config/solr.yml")
|
127
|
-
end
|
128
|
-
|
129
|
-
it "returns the default solr.yml file that ships with active-fedora if no other option is set" do
|
130
|
-
allow(Dir).to receive(:getwd).and_return("/current/working/directory")
|
131
|
-
expect(File).to receive(:file?).with("/current/working/directory/config/solr.yml").and_return(false)
|
132
|
-
expect(File).to receive(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"), 'config', 'solr.yml'))).and_return(true)
|
133
|
-
expect(ActiveFedora::Base.logger).to receive(:warn).with("Using the default solr.yml that comes with active-fedora. If you want to override this, pass the path to solr.yml to ActiveFedora - ie. ActiveFedora.init(:solr_config_path => '/path/to/solr.yml') - or set Rails.root and put solr.yml into \#{Rails.root}/config.")
|
134
|
-
expect(configurator.config_path(:solr)).to eql(File.expand_path(File.join(File.dirname("__FILE__"), 'config', 'solr.yml')))
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe "load_fedora_config" do
|
140
|
-
before do
|
141
|
-
configurator.reset!
|
142
|
-
end
|
143
|
-
it "loads the file specified in fedora_config_path" do
|
144
|
-
expect(configurator).to receive(:config_path).with(:fedora).and_return("/path/to/fedora.yml")
|
145
|
-
expect(configurator).to receive(:load_solr_config)
|
146
|
-
expect(IO).to receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:8983\ntest:\n url: http://myfedora:8080")
|
147
|
-
expect(configurator.load_fedora_config).to eq(url: "http://myfedora:8080")
|
148
|
-
expect(configurator.fedora_config).to eq(url: "http://myfedora:8080")
|
149
|
-
end
|
150
|
-
|
151
|
-
it "allows sharding" do
|
152
|
-
expect(configurator).to receive(:config_path).with(:fedora).and_return("/path/to/fedora.yml")
|
153
|
-
expect(configurator).to receive(:load_solr_config)
|
154
|
-
expect(IO).to receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:8983\ntest:\n- url: http://myfedora:8080\n- url: http://myfedora:8081")
|
155
|
-
expect(configurator.load_fedora_config).to eq [{ url: "http://myfedora:8080" }, { url: "http://myfedora:8081" }]
|
156
|
-
expect(configurator.fedora_config).to eq [{ url: "http://myfedora:8080" }, { url: "http://myfedora:8081" }]
|
157
|
-
end
|
158
|
-
|
159
|
-
it "parses the file using ERb" do
|
160
|
-
expect(configurator).to receive(:config_path).with(:fedora).and_return("/path/to/fedora.yml")
|
161
|
-
expect(configurator).to receive(:load_solr_config)
|
162
|
-
expect(IO).to receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:<%= 8983 %>\ntest:\n url: http://myfedora:<%= 8081 %>")
|
163
|
-
expect(configurator.load_fedora_config).to eq(url: "http://myfedora:8081")
|
164
|
-
expect(configurator.fedora_config).to eq(url: "http://myfedora:8081")
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
describe "load_solr_config" do
|
169
|
-
before do
|
170
|
-
configurator.reset!
|
171
|
-
end
|
172
|
-
it "loads the file specified in solr_config_path" do
|
173
|
-
expect(configurator).to receive(:config_path).with(:solr).and_return("/path/to/solr.yml")
|
174
|
-
expect(configurator).to receive(:load_fedora_config)
|
175
|
-
expect(IO).to receive(:read).with("/path/to/solr.yml").and_return("development:\n default:\n url: http://devsolr:8983\ntest:\n default:\n url: http://mysolr:8080")
|
176
|
-
expect(configurator.load_solr_config).to eq(url: "http://mysolr:8080")
|
177
|
-
expect(configurator.solr_config).to eq(url: "http://mysolr:8080")
|
178
|
-
end
|
179
|
-
|
180
|
-
it "parses the file using ERb" do
|
181
|
-
expect(configurator).to receive(:config_path).with(:solr).and_return("/path/to/solr.yml")
|
182
|
-
expect(configurator).to receive(:load_fedora_config)
|
183
|
-
expect(IO).to receive(:read).with("/path/to/solr.yml").and_return("development:\n default:\n url: http://devsolr:<%= 8983 %>\ntest:\n default:\n url: http://mysolr:<%= 8081 %>")
|
184
|
-
expect(configurator.load_solr_config).to eq(url: "http://mysolr:8081")
|
185
|
-
expect(configurator.solr_config).to eq(url: "http://mysolr:8081")
|
186
|
-
end
|
187
|
-
|
188
|
-
it "includes update_path and select_path in solr_config" do
|
189
|
-
expect(configurator).to receive(:config_path).with(:solr).and_return("/path/to/solr.yml")
|
190
|
-
expect(configurator).to receive(:load_fedora_config)
|
191
|
-
expect(IO).to receive(:read).with("/path/to/solr.yml").and_return("test:\n url: http://mysolr:8080\n update_path: update_test\n select_path: select_test\n")
|
192
|
-
expect(configurator.solr_config[:update_path]).to eq('update_test')
|
193
|
-
expect(configurator.solr_config[:select_path]).to eq('select_test')
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
describe "load_configs" do
|
198
|
-
describe "when config is not loaded" do
|
199
|
-
before do
|
200
|
-
configurator.instance_variable_set :@config_loaded, nil
|
201
|
-
end
|
202
|
-
it "loads the fedora and solr configs" do
|
203
|
-
expect(configurator).to_not be_config_loaded
|
204
|
-
configurator.load_configs
|
205
|
-
expect(configurator).to be_config_loaded
|
206
|
-
end
|
207
|
-
end
|
208
|
-
describe "when config is loaded" do
|
209
|
-
before do
|
210
|
-
configurator.instance_variable_set :@config_loaded, true
|
211
|
-
end
|
212
|
-
it "loads the fedora and solr configs" do
|
213
|
-
expect(configurator).to receive(:load_config).never
|
214
|
-
expect(configurator).to be_config_loaded
|
215
|
-
configurator.load_configs
|
216
|
-
expect(configurator).to be_config_loaded
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
describe "check_fedora_path_for_solr" do
|
222
|
-
it "finds the solr.yml file and return it if it exists" do
|
223
|
-
expect(configurator).to receive(:path).and_return("/path/to/fedora/fedora.yml")
|
224
|
-
expect(File).to receive(:file?).with("/path/to/fedora/solr.yml").and_return(true)
|
225
|
-
expect(configurator.check_fedora_path_for_solr).to eq "/path/to/fedora/solr.yml"
|
226
|
-
end
|
227
|
-
it "returns nil if the solr.yml file is not there" do
|
228
|
-
expect(configurator).to receive(:path).and_return("/path/to/fedora/fedora.yml")
|
229
|
-
expect(File).to receive(:file?).with("/path/to/fedora/solr.yml").and_return(false)
|
230
|
-
expect(configurator.check_fedora_path_for_solr).to be_nil
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
describe "setting the environment and loading configuration" do
|
236
|
-
before(:all) do
|
237
|
-
@fake_rails_root = File.expand_path(File.dirname(__FILE__) + '/../fixtures/rails_root')
|
238
|
-
end
|
239
|
-
|
240
|
-
after(:all) do
|
241
|
-
config_file = File.join(File.dirname(__FILE__), "..", "..", "config", "fedora.yml")
|
242
|
-
environment = "test"
|
243
|
-
ActiveFedora.init(environment: environment, fedora_config_path: config_file)
|
244
|
-
end
|
245
|
-
|
246
|
-
it "can tell its config paths" do
|
247
|
-
configurator.init
|
248
|
-
expect(configurator).to respond_to(:solr_config_path)
|
249
|
-
end
|
250
|
-
|
251
|
-
it "loads a config from the current working directory as a second choice" do
|
252
|
-
allow(Dir).to receive(:getwd).and_return(@fake_rails_root)
|
253
|
-
configurator.init
|
254
|
-
expect(configurator.config_path(:fedora)).to eql("#{@fake_rails_root}/config/fedora.yml")
|
255
|
-
expect(configurator.solr_config_path).to eql("#{@fake_rails_root}/config/solr.yml")
|
256
|
-
end
|
257
|
-
|
258
|
-
it "loads the config that ships with this gem as a last choice" do
|
259
|
-
allow(Dir).to receive(:getwd).and_return("/fake/path")
|
260
|
-
expect(ActiveFedora::Base.logger).to receive(:warn).with("Using the default fedora.yml that comes with active-fedora. If you want to override this, pass the path to fedora.yml to ActiveFedora - ie. ActiveFedora.init(:fedora_config_path => '/path/to/fedora.yml') - or set Rails.root and put fedora.yml into \#{Rails.root}/config.").exactly(3).times
|
261
|
-
configurator.init
|
262
|
-
expected_config = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config"))
|
263
|
-
expect(configurator.config_path(:fedora)).to eql(expected_config + '/fedora.yml')
|
264
|
-
expect(configurator.solr_config_path).to eql(expected_config + '/solr.yml')
|
265
|
-
end
|
266
|
-
it "raises an error if you pass in a string" do
|
267
|
-
expect(lambda { configurator.init("#{@fake_rails_root}/config/fake_fedora.yml") }).to raise_exception(ArgumentError)
|
268
|
-
end
|
269
|
-
it "raises an error if you pass in a non-existant config file" do
|
270
|
-
expect(lambda { configurator.init(fedora_config_path: "really_fake_fedora.yml") }).to raise_exception(ActiveFedora::ConfigurationError)
|
271
|
-
end
|
272
|
-
|
273
|
-
describe "within Rails" do
|
274
|
-
before do
|
275
|
-
stub_rails(root: File.dirname(__FILE__) + '/../fixtures/rails_root')
|
276
|
-
end
|
277
|
-
|
278
|
-
after do
|
279
|
-
unstub_rails
|
280
|
-
end
|
281
|
-
|
282
|
-
it "loads a config from Rails.root as a first choice" do
|
283
|
-
configurator.init
|
284
|
-
expect(configurator.config_path(:fedora)).to eql("#{Rails.root}/config/fedora.yml")
|
285
|
-
expect(configurator.solr_config_path).to eql("#{Rails.root}/config/solr.yml")
|
286
|
-
end
|
287
|
-
|
288
|
-
it "can tell what environment it is set to run in" do
|
289
|
-
stub_rails(env: "development")
|
290
|
-
configurator.init
|
291
|
-
expect(ActiveFedora.environment).to eql("development")
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|
data/spec/unit/file_io_spec.rb
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::FileIO do
|
4
|
-
# 300,000 byte test string
|
5
|
-
test_file = (0..300_000).reduce('') do |s, c| s << (c % 256).chr end
|
6
|
-
|
7
|
-
let(:file_contents) { test_file }
|
8
|
-
let(:fedora_file) {
|
9
|
-
ActiveFedora::File.new .tap do |file|
|
10
|
-
file.content = file_contents
|
11
|
-
file.save
|
12
|
-
end
|
13
|
-
}
|
14
|
-
let(:io) { described_class.new(fedora_file) }
|
15
|
-
|
16
|
-
describe "#read" do
|
17
|
-
it "reads the entire file when called without parameters" do
|
18
|
-
expect(io.read).to eql(file_contents)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns nil at end of file when requested with length" do
|
22
|
-
io.read
|
23
|
-
expect(io.read(10)).to be_nil
|
24
|
-
end
|
25
|
-
|
26
|
-
it "returns only requested amount of bytes" do
|
27
|
-
expect(io.read(5)).to eql(file_contents[0..4])
|
28
|
-
expect(io.read(5)).to eql(file_contents[5..9])
|
29
|
-
expect(io.read(100_000)).to eql(file_contents[10..100_009])
|
30
|
-
expect(io.read(200_000)).to eql(file_contents[100_010..-1])
|
31
|
-
end
|
32
|
-
|
33
|
-
it "returns an empty string if 0 bytes is requested" do
|
34
|
-
expect(io.read(0)).to eql('')
|
35
|
-
end
|
36
|
-
|
37
|
-
it "raises an error with negative length parameter" do
|
38
|
-
expect { io.read(-1) }.to raise_error(ArgumentError)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "returns ASCII-8BIT strings" do
|
42
|
-
expect(io.read(10).encoding.to_s).to eql("ASCII-8BIT")
|
43
|
-
expect(io.read.encoding.to_s).to eql("ASCII-8BIT")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "can take a buffer parameter" do
|
47
|
-
buffer = ''
|
48
|
-
expect(io.read(100, buffer)).to eql(file_contents[0..99])
|
49
|
-
expect(buffer).to eql(file_contents[0..99])
|
50
|
-
# IO.read will clear the buffer if it's not empty
|
51
|
-
expect(io.read(100, buffer)).to eql(file_contents[100..199])
|
52
|
-
expect(buffer).to eql(file_contents[100..199])
|
53
|
-
end
|
54
|
-
|
55
|
-
context "with empty file" do
|
56
|
-
let(:file_contents) { '' }
|
57
|
-
it "returns an empty string when called without parameters" do
|
58
|
-
expect(io.read).to eql('')
|
59
|
-
end
|
60
|
-
|
61
|
-
it "returns nil when called with length parameter" do
|
62
|
-
expect(io.read(10)).to be_nil
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "edge cases" do
|
67
|
-
let(:stream) {
|
68
|
-
instance_double(ActiveFedora::File::Streaming::FileBody).tap do |stream|
|
69
|
-
allow(stream).to receive(:each) do |&block|
|
70
|
-
['abcd', 'efghijkl', 'mnopqrst', 'uvwxy', 'z'].each(&block)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
}
|
74
|
-
before {
|
75
|
-
allow(fedora_file).to receive(:stream).and_return(stream)
|
76
|
-
}
|
77
|
-
let(:file_contents) { 'abcdefghijklmnopqrstuvwxyz' }
|
78
|
-
it "are handled correctly" do
|
79
|
-
expect(io.read(4)).to eql('abcd')
|
80
|
-
expect(io.read(7)).to eql('efghijk')
|
81
|
-
expect(io.read(9)).to eql('lmnopqrst')
|
82
|
-
expect(io.read(6)).to eql('uvwxyz')
|
83
|
-
expect(io.read(4)).to be_nil
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "#pos" do
|
89
|
-
it "returns current position" do
|
90
|
-
expect(io.pos).to be(0)
|
91
|
-
io.read(5)
|
92
|
-
expect(io.pos).to be(5)
|
93
|
-
io.read(100_000)
|
94
|
-
expect(io.pos).to be(100_005)
|
95
|
-
io.read
|
96
|
-
expect(io.pos).to be(file_contents.length)
|
97
|
-
io.rewind
|
98
|
-
expect(io.pos).to be(0)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe "#rewind" do
|
103
|
-
it "restarts the stream" do
|
104
|
-
io.read(10)
|
105
|
-
io.rewind
|
106
|
-
expect(io.read(10)).to eql(file_contents[0..9])
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe "#close" do
|
111
|
-
it "closes the stream" do
|
112
|
-
io.read(10)
|
113
|
-
io.close
|
114
|
-
expect { io.read(10) } .to raise_error(IOError)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "#binmode" do
|
119
|
-
it "responds to binmode" do
|
120
|
-
expect { io.binmode } .not_to raise_error
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "#binmode?" do
|
125
|
-
it "returns true" do
|
126
|
-
expect(io.binmode?).to be(true)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "working with IO.copy_stream" do
|
131
|
-
let(:output_stream) { StringIO.new .tap(&:binmode) }
|
132
|
-
it "copies the stream" do
|
133
|
-
IO.copy_stream(io, output_stream)
|
134
|
-
expect(output_stream.string).to eql(file_contents)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|