active-fedora 13.1.2 → 13.1.3

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 (140) hide show
  1. checksums.yaml +4 -4
  2. data/.github_changelog_generator +2 -0
  3. data/CHANGELOG.md +3362 -0
  4. data/CONTRIBUTING.md +23 -1
  5. data/README.md +4 -0
  6. data/active-fedora.gemspec +14 -13
  7. data/lib/active_fedora/version.rb +1 -1
  8. metadata +104 -206
  9. data/spec/config_helper.rb +0 -17
  10. data/spec/fixtures/dino.jpg +0 -0
  11. data/spec/fixtures/dino_jpg_no_file_ext +0 -0
  12. data/spec/fixtures/minivan.jpg +0 -0
  13. data/spec/fixtures/rails_root/config/fake_fedora.yml +0 -7
  14. data/spec/fixtures/rails_root/config/fedora.yml +0 -12
  15. data/spec/fixtures/rails_root/config/solr.yml +0 -15
  16. data/spec/fixtures/rails_root/config/solr_mappings.yml +0 -16
  17. data/spec/fixtures/rails_root/config/solr_mappings_af_0.1.yml +0 -9
  18. data/spec/fixtures/rails_root/config/solr_mappings_bl_2.4.yml +0 -17
  19. data/spec/integration/associations/rdf_spec.rb +0 -61
  20. data/spec/integration/associations_spec.rb +0 -680
  21. data/spec/integration/attached_files_spec.rb +0 -146
  22. data/spec/integration/attributes_spec.rb +0 -73
  23. data/spec/integration/autosave_association_spec.rb +0 -24
  24. data/spec/integration/base_spec.rb +0 -184
  25. data/spec/integration/basic_contains_association_spec.rb +0 -121
  26. data/spec/integration/belongs_to_association_spec.rb +0 -260
  27. data/spec/integration/caching_spec.rb +0 -59
  28. data/spec/integration/clean_connection_spec.rb +0 -21
  29. data/spec/integration/collection_association_spec.rb +0 -166
  30. data/spec/integration/date_time_properties_spec.rb +0 -41
  31. data/spec/integration/delete_all_spec.rb +0 -64
  32. data/spec/integration/direct_container_spec.rb +0 -250
  33. data/spec/integration/directly_contains_one_association_spec.rb +0 -96
  34. data/spec/integration/eradicate_spec.rb +0 -52
  35. data/spec/integration/fedora_solr_sync_spec.rb +0 -30
  36. data/spec/integration/file_fixity_spec.rb +0 -36
  37. data/spec/integration/file_spec.rb +0 -221
  38. data/spec/integration/generators/fedora_generator_spec.rb +0 -26
  39. data/spec/integration/generators/solr_generator_spec.rb +0 -23
  40. data/spec/integration/gone_spec.rb +0 -41
  41. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +0 -414
  42. data/spec/integration/has_many_associations_spec.rb +0 -436
  43. data/spec/integration/has_subresource_spec.rb +0 -34
  44. data/spec/integration/indexing/descendant_fetcher_spec.rb +0 -64
  45. data/spec/integration/indexing_spec.rb +0 -110
  46. data/spec/integration/indirect_container_spec.rb +0 -290
  47. data/spec/integration/json_serialization_spec.rb +0 -32
  48. data/spec/integration/marshal_spec.rb +0 -39
  49. data/spec/integration/nested_attribute_spec.rb +0 -177
  50. data/spec/integration/nested_hash_resources_spec.rb +0 -43
  51. data/spec/integration/persistence_spec.rb +0 -37
  52. data/spec/integration/query_result_builder_spec.rb +0 -37
  53. data/spec/integration/rdf_nested_attributes_spec.rb +0 -85
  54. data/spec/integration/relation_delegation_spec.rb +0 -52
  55. data/spec/integration/relation_spec.rb +0 -117
  56. data/spec/integration/scoped_query_spec.rb +0 -134
  57. data/spec/integration/scoping_spec.rb +0 -48
  58. data/spec/integration/solr_hit_spec.rb +0 -32
  59. data/spec/integration/versionable_spec.rb +0 -256
  60. data/spec/integration/with_metadata_spec.rb +0 -111
  61. data/spec/lib/active_fedora/null_logger_spec.rb +0 -10
  62. data/spec/rcov.opts +0 -2
  63. data/spec/spec.opts +0 -5
  64. data/spec/spec_helper.rb +0 -106
  65. data/spec/support/an_active_model.rb +0 -29
  66. data/spec/unit/active_fedora/indexing/inserter_spec.rb +0 -35
  67. data/spec/unit/active_fedora_spec.rb +0 -118
  68. data/spec/unit/aggregation/list_source_spec.rb +0 -134
  69. data/spec/unit/aggregation/ordered_reader_spec.rb +0 -43
  70. data/spec/unit/association_hash_spec.rb +0 -64
  71. data/spec/unit/attached_files_spec.rb +0 -218
  72. data/spec/unit/attributes_spec.rb +0 -146
  73. data/spec/unit/base_active_model_spec.rb +0 -28
  74. data/spec/unit/base_cma_spec.rb +0 -15
  75. data/spec/unit/base_extra_spec.rb +0 -33
  76. data/spec/unit/base_spec.rb +0 -328
  77. data/spec/unit/builder/has_and_belongs_to_many_spec.rb +0 -8
  78. data/spec/unit/callback_spec.rb +0 -65
  79. data/spec/unit/change_set_spec.rb +0 -60
  80. data/spec/unit/checksum_spec.rb +0 -25
  81. data/spec/unit/code_configurator_spec.rb +0 -41
  82. data/spec/unit/collection_proxy_spec.rb +0 -25
  83. data/spec/unit/config_spec.rb +0 -18
  84. data/spec/unit/core/fedora_id_translator_spec.rb +0 -29
  85. data/spec/unit/core/fedora_uri_translator_spec.rb +0 -19
  86. data/spec/unit/core/logger_spec.rb +0 -18
  87. data/spec/unit/core_spec.rb +0 -242
  88. data/spec/unit/default_model_mapper_spec.rb +0 -39
  89. data/spec/unit/fedora_spec.rb +0 -31
  90. data/spec/unit/file/streaming_spec.rb +0 -33
  91. data/spec/unit/file_configurator_spec.rb +0 -295
  92. data/spec/unit/file_io_spec.rb +0 -137
  93. data/spec/unit/file_path_builder_spec.rb +0 -18
  94. data/spec/unit/file_spec.rb +0 -489
  95. data/spec/unit/files_hash_spec.rb +0 -52
  96. data/spec/unit/filter_spec.rb +0 -133
  97. data/spec/unit/finder_methods_spec.rb +0 -154
  98. data/spec/unit/fixity_service_spec.rb +0 -128
  99. data/spec/unit/forbidden_attributes_protection_spec.rb +0 -50
  100. data/spec/unit/has_and_belongs_to_many_association_spec.rb +0 -125
  101. data/spec/unit/has_many_association_spec.rb +0 -131
  102. data/spec/unit/indexers/global_indexer_spec.rb +0 -41
  103. data/spec/unit/indexing/map/index_object_spec.rb +0 -25
  104. data/spec/unit/indexing/map_spec.rb +0 -27
  105. data/spec/unit/indexing_service_spec.rb +0 -28
  106. data/spec/unit/indexing_spec.rb +0 -86
  107. data/spec/unit/inheritance_spec.rb +0 -60
  108. data/spec/unit/ldp_resource_spec.rb +0 -15
  109. data/spec/unit/loadable_from_json_spec.rb +0 -40
  110. data/spec/unit/logger_spec.rb +0 -19
  111. data/spec/unit/model_classifier_spec.rb +0 -49
  112. data/spec/unit/ordered_spec.rb +0 -367
  113. data/spec/unit/orders/list_node_spec.rb +0 -151
  114. data/spec/unit/orders/ordered_list_spec.rb +0 -335
  115. data/spec/unit/orders/reflection_spec.rb +0 -22
  116. data/spec/unit/pathing_spec.rb +0 -35
  117. data/spec/unit/persistence_spec.rb +0 -115
  118. data/spec/unit/property_predicate_spec.rb +0 -35
  119. data/spec/unit/property_spec.rb +0 -25
  120. data/spec/unit/query_result_builder_spec.rb +0 -31
  121. data/spec/unit/query_spec.rb +0 -307
  122. data/spec/unit/querying_spec.rb +0 -24
  123. data/spec/unit/rdf/indexing_service_spec.rb +0 -114
  124. data/spec/unit/rdf_vocab_spec.rb +0 -30
  125. data/spec/unit/readonly_spec.rb +0 -24
  126. data/spec/unit/reflection_spec.rb +0 -42
  127. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +0 -37
  128. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +0 -38
  129. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +0 -38
  130. data/spec/unit/schema_indexing_strategy_spec.rb +0 -68
  131. data/spec/unit/scoping_spec.rb +0 -67
  132. data/spec/unit/serializers_spec.rb +0 -19
  133. data/spec/unit/solr_config_options_spec.rb +0 -57
  134. data/spec/unit/solr_hit_spec.rb +0 -57
  135. data/spec/unit/solr_query_builder_spec.rb +0 -18
  136. data/spec/unit/solr_service_spec.rb +0 -165
  137. data/spec/unit/sparql_insert_spec.rb +0 -31
  138. data/spec/unit/validations_spec.rb +0 -92
  139. data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +0 -29
  140. data/spec/unit/with_metadata/metadata_node_spec.rb +0 -69
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::Attributes::Serializers do
4
- describe "deserialize_dates_from_form" do
5
- before do
6
- class Foo < ActiveFedora::Base
7
- attr_accessor :birthday
8
- end
9
- end
10
- after do
11
- Object.send(:remove_const, :Foo)
12
- end
13
- subject(:serializer) { Foo.new }
14
- it "deserializes dates" do
15
- serializer.attributes = { 'birthday(1i)' => '2012', 'birthday(2i)' => '10', 'birthday(3i)' => '31' }
16
- expect(serializer.birthday).to eq '2012-10-31'
17
- end
18
- end
19
- end
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora do
4
- before(:all) do
5
- module SolrSpecModel
6
- class Basic < ActiveFedora::Base
7
- end
8
- end
9
- end
10
-
11
- subject(:test_object) { ActiveFedora::Base.new }
12
-
13
- describe ".id_field" do
14
- let(:field) { "MY_SAMPLE_ID".freeze }
15
- before do
16
- allow(described_class).to receive(:id_field).and_return(field)
17
- end
18
-
19
- it "is used by ActiveFedora::Base.to_solr" do
20
- allow(test_object).to receive(:id).and_return('changeme:123')
21
- expect(test_object.to_solr[field.to_sym]).to eq 'changeme:123'
22
- expect(test_object.to_solr[:id]).to be_nil
23
- end
24
-
25
- it "is used by ActiveFedora::Base#search_with_conditions" do
26
- mock_response = double("SolrResponse")
27
- expect(ActiveFedora::SolrService).to receive(:query)
28
- .with("_query_:\"{!raw f=has_model_ssim}SolrSpecModel::Basic\" AND " \
29
- "_query_:\"{!field f=#{field}}changeme:30\"",
30
- sort: ["#{described_class.index_field_mapper.solr_name('system_create', :stored_sortable, type: :date)} asc"])
31
- .and_return(mock_response)
32
-
33
- expect(SolrSpecModel::Basic.search_with_conditions(id: "changeme:30")).to equal(mock_response)
34
- end
35
- end
36
-
37
- describe ".enable_solr_updates?" do
38
- context 'with .enable_solr_updates? disabled' do
39
- before do
40
- allow(described_class).to receive(:enable_solr_updates?).and_return(false)
41
- end
42
-
43
- it "prevents Base.save from calling update_index if false" do
44
- allow(test_object).to receive(:new_record?).and_return(false)
45
- expect(test_object).to receive(:update_index).never
46
- expect(test_object).to receive(:refresh)
47
- test_object.save
48
- end
49
-
50
- it "prevents Base.delete from deleting the corresponding Solr document if false" do
51
- expect(ActiveFedora::SolrService.instance.conn).to receive(:delete).with(test_object.id).never
52
- expect(test_object).to receive(:delete)
53
- test_object.delete
54
- end
55
- end
56
- end
57
- end
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::SolrHit do
4
- before(:all) do
5
- class AudioRecord < ActiveFedora::Base
6
- attr_accessor :id
7
- def self.connection_for_id(_id); end
8
- end
9
- end
10
-
11
- subject(:solr_hit) { described_class.new "id" => "my:_ID1_", ActiveFedora.index_field_mapper.solr_name("has_model", :symbol) => ["AudioRecord"] }
12
-
13
- describe "#reify" do
14
- it "uses .find to instantiate objects" do
15
- expect(AudioRecord).to receive(:find).with("my:_ID1_", cast: true)
16
- solr_hit.reify
17
- end
18
- end
19
-
20
- describe "#id" do
21
- it "extracts the id from the solr hit" do
22
- expect(solr_hit.id).to eq "my:_ID1_"
23
- end
24
- end
25
-
26
- describe "#rdf_uri" do
27
- it "provides an RDF URI for the solr hit" do
28
- expect(solr_hit.rdf_uri).to eq ::RDF::URI.new(ActiveFedora::Base.id_to_uri("my:_ID1_"))
29
- end
30
- end
31
-
32
- describe "#model" do
33
- it "selects the appropriate model for the solr result" do
34
- expect(solr_hit.model).to eq AudioRecord
35
- end
36
- end
37
-
38
- describe "#models" do
39
- it "provides all the relevant models for the solr result" do
40
- expect(solr_hit.models).to match_array [AudioRecord]
41
- end
42
- end
43
-
44
- describe "#model?" do
45
- it 'is true if the object has the given model' do
46
- expect(solr_hit.model?(AudioRecord)).to eq true
47
- end
48
-
49
- it 'is true if the object has an ancestor of the given model' do
50
- expect(solr_hit.model?(ActiveFedora::Base)).to eq true
51
- end
52
-
53
- it 'is false if the given model is not in the ancestor tree for the models' do
54
- expect(solr_hit.model?(String)).to eq false
55
- end
56
- end
57
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::SolrQueryBuilder do
4
- describe "construct_query" do
5
- it "generates a query clause" do
6
- expect(described_class.construct_query('id' => "my:_ID1_")).to eq '_query_:"{!field f=id}my:_ID1_"'
7
- end
8
- end
9
-
10
- describe '#construct_query_for_ids' do
11
- it "generates a useable solr query from an array of Fedora ids" do
12
- expect(described_class.construct_query_for_ids(["my:_ID1_", "my:_ID2_", "my:_ID3_"])).to eq '{!terms f=id}my:_ID1_,my:_ID2_,my:_ID3_'
13
- end
14
- it "returns a valid solr query even if given an empty array as input" do
15
- expect(described_class.construct_query_for_ids([""])).to eq "id:NEVER_USE_THIS_ID"
16
- end
17
- end
18
- end
@@ -1,165 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::SolrService do
4
- before do
5
- described_class.reset!
6
- end
7
-
8
- after do
9
- described_class.reset!
10
- end
11
-
12
- let(:mock_conn) { instance_double(RSolr::Client) }
13
-
14
- describe '#options' do
15
- it 'is readable' do
16
- expect(described_class.instance.options).to include :read_timeout, :open_timeout, :url
17
- end
18
- end
19
-
20
- describe '#conn' do
21
- it "takes a n-arg constructor and configure for localhost" do
22
- expect(RSolr).to receive(:connect).with(read_timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr')
23
- described_class.register.conn
24
- end
25
- it "clobbers options" do
26
- expect(RSolr).to receive(:connect).with(read_timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr', autocommit: :off, foo: :bar)
27
- described_class.register(autocommit: :off, foo: :bar).conn
28
- end
29
- end
30
-
31
- describe '#conn=' do
32
- it 'is settable' do
33
- described_class.instance.conn = mock_conn
34
- expect(described_class.instance.conn).to eq mock_conn
35
- end
36
- end
37
-
38
- describe '.instance' do
39
- it "sets the threadlocal solr service" do
40
- ss = described_class.register(autocommit: :off, foo: :bar)
41
- expect(ActiveFedora::RuntimeRegistry.solr_service).to eq ss
42
- expect(described_class.instance).to eq ss
43
- end
44
- it "passes on solr_config when initializing the service" do
45
- allow(RSolr).to receive(:connect)
46
- allow(ActiveFedora).to receive(:solr_config).and_return(url: 'http://fubar', update_path: 'update_test')
47
- expect(described_class).to receive(:register).with(hash_including(url: 'http://fubar', update_path: 'update_test')).and_call_original
48
- described_class.instance
49
- end
50
- end
51
-
52
- describe "#get" do
53
- it "calls solr" do
54
- stub_result = double("Result")
55
- expect(mock_conn).to receive(:get).with('select', params: { q: 'querytext', qt: 'standard' }).and_return(stub_result)
56
- allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
57
- expect(described_class.get('querytext')).to eq stub_result
58
- end
59
- it "uses select_path" do
60
- stub_result = double("Result")
61
- expect(mock_conn).to receive(:get).with('select_test', params: { q: 'querytext', qt: 'standard' }).and_return(stub_result)
62
- expect(described_class).to receive(:select_path).and_return('select_test')
63
- allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
64
- expect(described_class.get('querytext')).to eq stub_result
65
- end
66
- end
67
-
68
- describe "#post" do
69
- it "calls solr" do
70
- stub_result = double("Result")
71
- expect(mock_conn).to receive(:post).with('select', data: { q: 'querytext', qt: 'standard' }).and_return(stub_result)
72
- allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
73
- expect(described_class.post('querytext')).to eq stub_result
74
- end
75
- it "uses select_path" do
76
- stub_result = double("Result")
77
- expect(mock_conn).to receive(:post).with('select_test', data: { q: 'querytext', qt: 'standard' }).and_return(stub_result)
78
- expect(described_class).to receive(:select_path).and_return('select_test')
79
- allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
80
- expect(described_class.post('querytext')).to eq stub_result
81
- end
82
- end
83
-
84
- describe "#query" do
85
- let(:doc) { { 'id' => 'x' } }
86
- let(:docs) { [doc] }
87
- let(:stub_result) { { 'response' => { 'docs' => docs } } }
88
-
89
- before do
90
- allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
91
- end
92
-
93
- it "defaults to HTTP GET method" do
94
- expect(mock_conn).to receive(:get).with('select', params: { rows: 2, q: 'querytext', qt: 'standard' }).and_return(stub_result)
95
- described_class.query('querytext', rows: 2)
96
- end
97
-
98
- it "allows callers to specify HTTP POST method" do
99
- expect(mock_conn).to receive(:post).with('select', data: { rows: 2, q: 'querytext', qt: 'standard' }).and_return(stub_result)
100
- described_class.query('querytext', rows: 2, method: :post)
101
- end
102
-
103
- it "raises if method not GET or POST" do
104
- expect(mock_conn).not_to receive(:head).with('select', data: { rows: 2, q: 'querytext', qt: 'standard' })
105
- expect {
106
- described_class.query('querytext', rows: 2, method: :head)
107
- }.to raise_error(RuntimeError, "Unsupported HTTP method for querying SolrService (:head)")
108
- end
109
-
110
- it "wraps the solr response documents in Solr hits" do
111
- expect(mock_conn).to receive(:get).with('select', params: { rows: 2, q: 'querytext', qt: 'standard' }).and_return(stub_result)
112
- result = described_class.query('querytext', rows: 2)
113
- expect(result.size).to eq 1
114
- expect(result.first.id).to eq 'x'
115
- end
116
-
117
- it "warns about not passing rows" do
118
- allow(mock_conn).to receive(:get).and_return(stub_result)
119
- expect(ActiveFedora::Base.logger).to receive(:warn).with(/^Calling ActiveFedora::SolrService\.get without passing an explicit value for ':rows' is not recommended/)
120
- described_class.query('querytext')
121
- end
122
- end
123
-
124
- describe ".count" do
125
- it "returns a count of matching records" do
126
- stub_result = { 'response' => { 'numFound' => '7' } }
127
- expect(mock_conn).to receive(:get).with('select', params: { rows: 0, q: 'querytext', qt: 'standard' }).and_return(stub_result)
128
- allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
129
- expect(described_class.count('querytext')).to eq 7
130
- end
131
- it "accepts query args" do
132
- stub_result = { 'response' => { 'numFound' => '7' } }
133
- expect(mock_conn).to receive(:get).with('select', params: { rows: 0, q: 'querytext', qt: 'standard', fq: 'filter' }).and_return(stub_result)
134
- allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
135
- expect(described_class.count('querytext', fq: 'filter', rows: 10)).to eq 7
136
- end
137
- end
138
- describe ".select_path" do
139
- it "gets :select_path from solr_config" do
140
- expect(ActiveFedora).to receive(:solr_config).and_return(select_path: 'select_test')
141
- expect(described_class.select_path).to eq 'select_test'
142
- end
143
- it "uses 'select' as default" do
144
- expect(ActiveFedora).to receive(:solr_config).and_return({})
145
- expect(described_class.select_path).to eq 'select'
146
- end
147
- end
148
-
149
- describe ".add" do
150
- it "calls solr" do
151
- doc = { 'id' => '1234' }
152
- expect(mock_conn).to receive(:add).with(doc, params: {})
153
- allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
154
- described_class.add(doc)
155
- end
156
- end
157
-
158
- describe ".commit" do
159
- it "calls solr" do
160
- expect(mock_conn).to receive(:commit)
161
- allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
162
- described_class.commit
163
- end
164
- end
165
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::SparqlInsert do
4
- subject(:sparql_insert) { described_class.new(change_set.changes) }
5
- let(:change_set) { ActiveFedora::ChangeSet.new(base, base.resource, base.changed_attributes.keys) }
6
-
7
- context "with a changed object" do
8
- before do
9
- class Library < ActiveFedora::Base
10
- end
11
-
12
- class Book < ActiveFedora::Base
13
- belongs_to :library, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasConstituent
14
- property :title, predicate: ::RDF::Vocab::DC.title
15
- end
16
-
17
- base.library_id = 'foo'
18
- base.title = ['bar']
19
- end
20
- after do
21
- Object.send(:remove_const, :Library)
22
- Object.send(:remove_const, :Book)
23
- end
24
-
25
- let(:base) { Book.create }
26
-
27
- it "returns the string" do
28
- expect(sparql_insert.build).to eq "DELETE { <> <info:fedora/fedora-system:def/relations-external#hasConstituent> ?change . }\n WHERE { <> <info:fedora/fedora-system:def/relations-external#hasConstituent> ?change . } ;\nDELETE { <> <http://purl.org/dc/terms/title> ?change . }\n WHERE { <> <http://purl.org/dc/terms/title> ?change . } ;\nINSERT { \n<> <info:fedora/fedora-system:def/relations-external#hasConstituent> <#{ActiveFedora.fedora.host}/test/foo> .\n<> <http://purl.org/dc/terms/title> \"bar\" .\n}\n WHERE { }"
29
- end
30
- end
31
- end
@@ -1,92 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::Base do
4
- before :all do
5
- class ValidationStub < ActiveFedora::Base
6
- property :fubar, predicate: ::RDF::URI('http://example.com/fubar')
7
- property :swank, predicate: ::RDF::URI('http://example.com/swank'), multiple: false
8
-
9
- validates_presence_of :fubar
10
- validates_length_of :swank, minimum: 5
11
-
12
- before_validation :before_validation_callback
13
- after_validation :after_validation_callback
14
-
15
- def before_validation_callback
16
- # no-op
17
- end
18
- def after_validation_callback
19
- # no-op
20
- end
21
- end
22
- end
23
-
24
- subject(:validation_stub) { ValidationStub.new }
25
-
26
- after :all do
27
- Object.send(:remove_const, :ValidationStub)
28
- end
29
-
30
- describe "a valid object" do
31
- before do
32
- validation_stub.attributes = { fubar: ['here'], swank: 'long enough' }
33
- end
34
-
35
- it { is_expected.to be_valid }
36
- end
37
- describe "an invalid object" do
38
- before do
39
- validation_stub.attributes = { swank: 'smal' }
40
- end
41
- it "has errors" do
42
- expect(validation_stub).to_not be_valid
43
- expect(validation_stub.errors[:fubar]).to eq ["can't be blank"]
44
- expect(validation_stub.errors[:swank]).to eq ["is too short (minimum is 5 characters)"]
45
- end
46
- end
47
-
48
- describe "required terms" do
49
- it { is_expected.to be_required(:fubar) }
50
- it { is_expected.to_not be_required(:swank) }
51
- end
52
-
53
- describe "#save!" do
54
- before { expect(validation_stub).to receive(:_create_record) } # prevent saving to Fedora/Solr
55
-
56
- it "validates only once" do
57
- expect(validation_stub).to receive(:perform_validations).once.and_return(true)
58
- validation_stub.save!
59
- end
60
- end
61
-
62
- describe "#update!" do
63
- before do
64
- allow(validation_stub).to receive(:new_record?).and_return(false)
65
- end
66
- context "when validations work" do
67
- it "saves the record" do
68
- expect(validation_stub).to receive(:_update_record) # prevent saving to Fedora/Solr
69
- expect(validation_stub).to receive(:perform_validations).once.and_return(true)
70
- validation_stub.update!(fubar: ['here'], swank: 'long enough')
71
- expect(validation_stub.fubar).to eq ['here']
72
- end
73
- end
74
-
75
- context "when validations fail" do
76
- it "raises an error" do
77
- expect(validation_stub).not_to receive(:_update_record)
78
- expect(validation_stub).to receive(:perform_validations).once.and_return(false)
79
- expect { validation_stub.update!(fubar: ['here'], swank: 'long enough') }.to raise_error ActiveFedora::RecordInvalid
80
- expect(validation_stub.fubar).to eq ['here']
81
- end
82
- end
83
- end
84
-
85
- describe 'validation callbacks' do
86
- it 'calls callbacks' do
87
- expect(validation_stub).to receive(:before_validation_callback)
88
- expect(validation_stub).to receive(:after_validation_callback)
89
- validation_stub.validate
90
- end
91
- end
92
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::WithMetadata::DefaultMetadataClassFactory do
4
- let(:parent) { class_double(ActiveFedora::File) }
5
- let(:object) { described_class.new }
6
-
7
- describe "default class attributes" do
8
- its(:metadata_base_class) { is_expected.to eq(ActiveFedora::WithMetadata::MetadataNode) }
9
- its(:file_metadata_schemas) { is_expected.to eq([ActiveFedora::WithMetadata::DefaultSchema]) }
10
- its(:file_metadata_strategy) { is_expected.to eq(ActiveFedora::WithMetadata::DefaultStrategy) }
11
- end
12
-
13
- describe "::build" do
14
- it "sets MetadataNode to the default schema using the default strategy" do
15
- expect(parent).to receive(:const_set)
16
- expect(parent).to receive(:delegate).with(:label, :label=, :label_changed?, to: :metadata_node)
17
- expect(parent).to receive(:delegate).with(:file_name, :file_name=, :file_name_changed?, to: :metadata_node)
18
- expect(parent).to receive(:delegate).with(:file_size, :file_size=, :file_size_changed?, to: :metadata_node)
19
- expect(parent).to receive(:delegate).with(:date_created, :date_created=, :date_created_changed?, to: :metadata_node)
20
- expect(parent).to receive(:delegate).with(:date_modified,
21
- :date_modified=,
22
- :date_modified_changed?,
23
- to: :metadata_node)
24
- expect(parent).to receive(:delegate).with(:byte_order, :byte_order=, :byte_order_changed?, to: :metadata_node)
25
- expect(parent).to receive(:delegate).with(:file_hash, :file_hash=, :file_hash_changed?, to: :metadata_node)
26
- object.class.build(parent)
27
- end
28
- end
29
- end