active-fedora 6.4.3 → 6.4.4
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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +111 -0
- data/lib/active_fedora/associations/belongs_to_association.rb +30 -5
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
- data/lib/active_fedora/file_configurator.rb +7 -11
- data/lib/active_fedora/indexing.rb +5 -2
- data/lib/active_fedora/test_support.rb +1 -0
- data/lib/active_fedora/version.rb +1 -1
- data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +7 -7
- data/spec/integration/associations_spec.rb +123 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/an_active_model.rb +28 -0
- data/spec/unit/base_active_model_spec.rb +0 -1
- data/spec/unit/base_spec.rb +20 -2
- data/spec/unit/file_configurator_spec.rb +33 -13
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9682552f64d1274de9b4de8f26e12dc1ab04cab5
|
4
|
+
data.tar.gz: 0267bbbfcd15b12ab6593620aebab8e2e6322274
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fdd12fb3660f58afca86fa8f488d3da34db1e36ceb55b76d3cda5f33f6a87a2b668bbcc6841d07a7d62f14d32fb77e61811fad3a29cd1a268175b30dd536587
|
7
|
+
data.tar.gz: 96459b1261137d65d9f64e2dab39587aac41466f958b943da81a19799ec7d7f6a343b353332984d43de296d161172861fdea152854811056f04d2d1a64b60e85
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# How to Contribute
|
2
|
+
|
3
|
+
We want your help to make Project Hydra great.
|
4
|
+
There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
|
5
|
+
|
6
|
+
## Hydra Project Intellectual Property Licensing and Ownership
|
7
|
+
|
8
|
+
All code contributors must have an Individual Contributor License Agreement (iCLA) on file with the Hydra Project Steering Group.
|
9
|
+
If the contributor works for an institution, the institution must have a Corporate Contributor License Agreement (cCLA) on file.
|
10
|
+
|
11
|
+
https://wiki.duraspace.org/display/hydra/Hydra+Project+Intellectual+Property+Licensing+and+Ownership
|
12
|
+
|
13
|
+
You should also add yourself to the `CONTRIBUTORS.md` file in the root of the project.
|
14
|
+
|
15
|
+
## Contribution Tasks
|
16
|
+
|
17
|
+
* Reporting Issues
|
18
|
+
* Making Changes
|
19
|
+
* Submitting Changes
|
20
|
+
* Merging Changes
|
21
|
+
|
22
|
+
### Reporting Issues
|
23
|
+
|
24
|
+
* Make sure you have a [GitHub account](https://github.com/signup/free)
|
25
|
+
* Submit a [Github issue](./issues) by:
|
26
|
+
* Clearly describing the issue
|
27
|
+
* Provide a descriptive summary
|
28
|
+
* Explain the expected behavior
|
29
|
+
* Explain the actual behavior
|
30
|
+
* Provide steps to reproduce the actual behavior
|
31
|
+
|
32
|
+
### Making Changes
|
33
|
+
|
34
|
+
* Fork the repository on GitHub
|
35
|
+
* Create a topic branch from where you want to base your work.
|
36
|
+
* This is usually the master branch.
|
37
|
+
* To quickly create a topic branch based on master; `git branch fix/master/my_contribution master`
|
38
|
+
* Then checkout the new branch with `git checkout fix/master/my_contribution`.
|
39
|
+
* Please avoid working directly on the `master` branch.
|
40
|
+
* You may find the [hub suite of commands](https://github.com/defunkt/hub) helpful
|
41
|
+
* Make commits of logical units.
|
42
|
+
* Your commit should include a high level description of your work in HISTORY.textile
|
43
|
+
* Check for unnecessary whitespace with `git diff --check` before committing.
|
44
|
+
* Make sure your commit messages are [well formed](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
|
45
|
+
* If you created an issue, you can close it by including "Closes #issue" in your commit message. See [Github's blog post for more details](https://github.com/blog/1386-closing-issues-via-commit-messages)
|
46
|
+
|
47
|
+
```
|
48
|
+
Present tense short summary (50 characters or less)
|
49
|
+
|
50
|
+
More detailed description, if necessary. It should be wrapped to 72
|
51
|
+
characters. Try to be as descriptive as you can, even if you think that
|
52
|
+
the commit content is obvious, it may not be obvious to others. You
|
53
|
+
should add such description also if it's already present in bug tracker,
|
54
|
+
it should not be necessary to visit a webpage to check the history.
|
55
|
+
|
56
|
+
Include Closes #<issue-number> when relavent.
|
57
|
+
|
58
|
+
Description can have multiple paragraphs and you can use code examples
|
59
|
+
inside, just indent it with 4 spaces:
|
60
|
+
|
61
|
+
class PostsController
|
62
|
+
def index
|
63
|
+
respond_with Post.limit(10)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
You can also add bullet points:
|
68
|
+
|
69
|
+
- you can use dashes or asterisks
|
70
|
+
|
71
|
+
- also, try to indent next line of a point for readability, if it's too
|
72
|
+
long to fit in 72 characters
|
73
|
+
```
|
74
|
+
|
75
|
+
* Make sure you have added the necessary tests for your changes.
|
76
|
+
* Run _all_ the tests to assure nothing else was accidentally broken.
|
77
|
+
* When you are ready to submit a pull request
|
78
|
+
|
79
|
+
### Submitting Changes
|
80
|
+
|
81
|
+
* Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
|
82
|
+
* Make sure your branch is up to date with its parent branch (i.e. master)
|
83
|
+
* `git checkout master`
|
84
|
+
* `git pull --rebase`
|
85
|
+
* `git checkout <your-branch>`
|
86
|
+
* `git rebase master`
|
87
|
+
* It is likely a good idea to run your tests again.
|
88
|
+
* Squash the commits for your branch into one commit
|
89
|
+
* `git rebase --interactive HEAD~<number-of-commits>` ([See Github help](https://help.github.com/articles/interactive-rebase))
|
90
|
+
* To determine the number of commits on your branch: `git log master..<your-branch> --oneline | wc -l`
|
91
|
+
* Squashing your branch's changes into one commit is "good form" and helps the person merging your request to see everything that is going on.
|
92
|
+
* Push your changes to a topic branch in your fork of the repository.
|
93
|
+
* Submit a pull request from your fork to the project.
|
94
|
+
|
95
|
+
### Merging Changes
|
96
|
+
|
97
|
+
* It is considered "poor from" to merge your own request.
|
98
|
+
* Please take the time to review the changes and get a sense of what is being changed. Things to consider:
|
99
|
+
* Does the commit message explain what is going on?
|
100
|
+
* Does the code changes have tests? _Not all changes need new tests, some changes are refactorings_
|
101
|
+
* Does the commit contain more than it should? Are two separate concerns being addressed in one commit?
|
102
|
+
* Did the Travis tests complete successfully?
|
103
|
+
* If you are uncertain, bring other contributors into the conversation by creating a comment that includes their @username.
|
104
|
+
* If you like the pull request, but want others to chime in, create a +1 comment and tag a user.
|
105
|
+
|
106
|
+
# Additional Resources
|
107
|
+
|
108
|
+
* [General GitHub documentation](http://help.github.com/)
|
109
|
+
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
|
110
|
+
* [Pro Git](http://git-scm.com/book) is both a free and excellent book about Git.
|
111
|
+
* [A Git Config for Contributing](http://ndlib.github.io/practices/my-typical-per-project-git-config/)
|
@@ -12,11 +12,11 @@ module ActiveFedora
|
|
12
12
|
|
13
13
|
def replace(record)
|
14
14
|
if record.nil?
|
15
|
-
|
15
|
+
remove_matching_property_relationship
|
16
16
|
else
|
17
17
|
raise_on_type_mismatch(record)
|
18
18
|
|
19
|
-
|
19
|
+
remove_matching_property_relationship
|
20
20
|
|
21
21
|
@target = (AssociationProxy === record ? record.target : record)
|
22
22
|
@owner.add_relationship(@reflection.options[:property], record) unless record.new_record?
|
@@ -29,13 +29,38 @@ module ActiveFedora
|
|
29
29
|
|
30
30
|
private
|
31
31
|
def find_target
|
32
|
-
pid = @owner.ids_for_outbound(@reflection.options[:property])
|
33
|
-
return if pid.
|
34
|
-
|
32
|
+
pid = @owner.ids_for_outbound(@reflection.options[:property])
|
33
|
+
return if pid.empty?
|
34
|
+
class_name = @reflection.options[:class_name] ? @reflection.options[:class_name] : @reflection.class_name
|
35
|
+
query = construct_query(pid, class_name)
|
35
36
|
solr_result = SolrService.query(query)
|
36
37
|
return ActiveFedora::SolrService.reify_solr_results(solr_result).first
|
37
38
|
end
|
38
39
|
|
40
|
+
def construct_query pid, class_name
|
41
|
+
if class_name && class_name != "ActiveFedora::Base"
|
42
|
+
clauses = {}
|
43
|
+
clauses[:has_model] = class_name.constantize.to_class_uri
|
44
|
+
query = ActiveFedora::SolrService.construct_query_for_rel(clauses) + " AND (" + ActiveFedora::SolrService.construct_query_for_pids(pid) + ")"
|
45
|
+
else
|
46
|
+
query = ActiveFedora::SolrService.construct_query_for_pids(pid)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def remove_matching_property_relationship
|
51
|
+
class_name = @reflection.options[:class_name] ? @reflection.options[:class_name] : @reflection.class_name
|
52
|
+
ids = @owner.ids_for_outbound(@reflection.options[:property])
|
53
|
+
return if ids.empty?
|
54
|
+
ids.each do |id|
|
55
|
+
result = SolrService.query(ActiveFedora::SolrService.construct_query_for_pids([id]))
|
56
|
+
hit = ActiveFedora::SolrService.reify_solr_results(result).first
|
57
|
+
# We remove_relationship on subjects that match the same class, or if the subject is nil
|
58
|
+
if hit.class.to_s == class_name || hit.nil?
|
59
|
+
@owner.remove_relationship(@reflection.options[:property], hit)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
39
64
|
def foreign_key_present
|
40
65
|
!@owner.send(@reflection.primary_key_name).nil?
|
41
66
|
end
|
@@ -10,7 +10,7 @@ module ActiveFedora
|
|
10
10
|
pids = @owner.ids_for_outbound(@reflection.options[:property])
|
11
11
|
return [] if pids.empty?
|
12
12
|
query = ActiveFedora::SolrService.construct_query_for_pids(pids)
|
13
|
-
solr_result = SolrService.query(query)
|
13
|
+
solr_result = SolrService.query(query, rows: 1000)
|
14
14
|
return ActiveFedora::SolrService.reify_solr_results(solr_result)
|
15
15
|
end
|
16
16
|
|
@@ -48,7 +48,7 @@ module ActiveFedora
|
|
48
48
|
#
|
49
49
|
|
50
50
|
attr_accessor :config_env
|
51
|
-
attr_reader :config_options, :fedora_config_path, :solr_config_path
|
51
|
+
attr_reader :config_options, :fedora_config_path, :solr_config_path, :predicate_mappings_config_path
|
52
52
|
|
53
53
|
# The configuration hash that gets used by RSolr.connect
|
54
54
|
def initialize
|
@@ -208,22 +208,18 @@ module ActiveFedora
|
|
208
208
|
end
|
209
209
|
|
210
210
|
def predicate_config
|
211
|
-
@predicate_config_path ||= build_predicate_config_path
|
211
|
+
@predicate_config_path ||= build_predicate_config_path
|
212
212
|
YAMLAdaptor.load(File.open(@predicate_config_path)) if File.exist?(@predicate_config_path)
|
213
213
|
end
|
214
214
|
|
215
215
|
protected
|
216
216
|
|
217
|
-
def build_predicate_config_path
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
testfile = File.expand_path(File.join(path,"predicate_mappings.yml"))
|
222
|
-
if File.exist?(testfile) && valid_predicate_mapping?(testfile)
|
223
|
-
return testfile
|
224
|
-
end
|
217
|
+
def build_predicate_config_path
|
218
|
+
testfile = File.expand_path(get_config_path(:predicate_mappings))
|
219
|
+
if File.exist?(testfile) && valid_predicate_mapping?(testfile)
|
220
|
+
return testfile
|
225
221
|
end
|
226
|
-
raise PredicateMappingsNotFoundError
|
222
|
+
raise PredicateMappingsNotFoundError
|
227
223
|
end
|
228
224
|
|
229
225
|
def valid_predicate_mapping?(testfile)
|
@@ -87,9 +87,12 @@ module ActiveFedora
|
|
87
87
|
end
|
88
88
|
|
89
89
|
# Using the fedora search (not solr), get every object and reindex it.
|
90
|
-
|
90
|
+
# @param [String] a query string that conforms to the query param format
|
91
|
+
# of the underlying search's API
|
92
|
+
def reindex_everything(query = nil)
|
91
93
|
connections.each do |conn|
|
92
|
-
conn.search(
|
94
|
+
conn.search(query) do |object|
|
95
|
+
next if object.pid.start_with?('fedora-system:')
|
93
96
|
ActiveFedora::Base.find(object.pid, :cast=>true).update_index
|
94
97
|
end
|
95
98
|
end
|
@@ -4,16 +4,16 @@ require 'spec_helper'
|
|
4
4
|
require 'active_fedora/test_support'
|
5
5
|
|
6
6
|
describe <%= class_name %> do
|
7
|
+
it_behaves_like 'An ActiveModel'
|
7
8
|
include ActiveFedora::TestSupport
|
8
9
|
subject { <%= class_name %>.new }
|
9
10
|
|
10
|
-
|
11
|
-
subject.save!
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
subject.destroy
|
11
|
+
describe "when persisted to fedora" do
|
12
|
+
before { subject.save! }
|
13
|
+
after { subject.destroy }
|
14
|
+
it 'should exist' do
|
15
|
+
<%= class_name %>.exists?(subject.pid).should be_true
|
16
|
+
end
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should have a descMetadata datastream' do
|
@@ -10,6 +10,7 @@ describe ActiveFedora::Base do
|
|
10
10
|
class Book < ActiveFedora::Base
|
11
11
|
belongs_to :library, :property=>:has_constituent
|
12
12
|
belongs_to :author, :property=>:has_member, :class_name=>'Person'
|
13
|
+
belongs_to :publisher, :property=>:has_member
|
13
14
|
has_and_belongs_to_many :topics, :property=>:has_topic, :inverse_of=>:is_topic_of
|
14
15
|
has_and_belongs_to_many :collections, :property=>:is_member_of_collection
|
15
16
|
end
|
@@ -17,6 +18,9 @@ describe ActiveFedora::Base do
|
|
17
18
|
class Person < ActiveFedora::Base
|
18
19
|
end
|
19
20
|
|
21
|
+
class Publisher < ActiveFedora::Base
|
22
|
+
end
|
23
|
+
|
20
24
|
class Collection < ActiveFedora::Base
|
21
25
|
end
|
22
26
|
|
@@ -186,6 +190,17 @@ describe ActiveFedora::Base do
|
|
186
190
|
@book.topics.should == []
|
187
191
|
@topic1.books.should == []
|
188
192
|
end
|
193
|
+
it "Should allow for more than 10 items" do
|
194
|
+
|
195
|
+
(0..11).each do
|
196
|
+
@book.topics << Topic.create
|
197
|
+
end
|
198
|
+
@book.save
|
199
|
+
@book.topics.count.should == 12
|
200
|
+
book2 = Book.find(@book.pid)
|
201
|
+
book2.topics.count.should == 12
|
202
|
+
end
|
203
|
+
|
189
204
|
after do
|
190
205
|
@topic1.delete
|
191
206
|
@topic2.delete
|
@@ -205,6 +220,8 @@ describe ActiveFedora::Base do
|
|
205
220
|
@book.save
|
206
221
|
@person = Person.new
|
207
222
|
@person.save
|
223
|
+
@publisher = Publisher.new
|
224
|
+
@publisher.save
|
208
225
|
end
|
209
226
|
it "should have many books once it has been saved" do
|
210
227
|
@library.books << @book
|
@@ -236,6 +253,18 @@ describe ActiveFedora::Base do
|
|
236
253
|
Book.find(@book.id).author.send(:find_target).should be_kind_of Person
|
237
254
|
end
|
238
255
|
|
256
|
+
it "should respect multiple associations that share the same :property and respect associated class" do
|
257
|
+
@book.author = @person
|
258
|
+
@book.publisher = @publisher
|
259
|
+
@book.save
|
260
|
+
|
261
|
+
Book.find(@book.id).publisher_id.should == @publisher.pid
|
262
|
+
Book.find(@book.id).publisher.send(:find_target).should be_kind_of Publisher
|
263
|
+
|
264
|
+
Book.find(@book.id).author_id.should == @person.pid
|
265
|
+
Book.find(@book.id).author.send(:find_target).should be_kind_of Person
|
266
|
+
end
|
267
|
+
|
239
268
|
describe "when changing the belonger" do
|
240
269
|
before do
|
241
270
|
@book.library = @library
|
@@ -256,6 +285,8 @@ describe ActiveFedora::Base do
|
|
256
285
|
after do
|
257
286
|
@library.delete
|
258
287
|
@book.delete
|
288
|
+
@person.delete
|
289
|
+
@publisher.delete
|
259
290
|
end
|
260
291
|
end
|
261
292
|
describe "of has_many_and_belongs_to" do
|
@@ -321,6 +352,10 @@ describe ActiveFedora::Base do
|
|
321
352
|
@library = Library.new()
|
322
353
|
@library.save()
|
323
354
|
@book = Book.new
|
355
|
+
@author = Person.new
|
356
|
+
@author.save
|
357
|
+
@publisher = Publisher.new
|
358
|
+
@publisher.save
|
324
359
|
end
|
325
360
|
it "should set the association" do
|
326
361
|
@book.library = @library
|
@@ -351,6 +386,33 @@ describe ActiveFedora::Base do
|
|
351
386
|
|
352
387
|
end
|
353
388
|
|
389
|
+
it "should only replace the matching class association" do
|
390
|
+
@publisher2 = Publisher.new
|
391
|
+
@publisher2.save
|
392
|
+
|
393
|
+
@book.publisher = @publisher
|
394
|
+
@book.author = @author
|
395
|
+
@book.save
|
396
|
+
|
397
|
+
@book.publisher = @publisher2
|
398
|
+
@book.save
|
399
|
+
|
400
|
+
Book.find(@book.pid).publisher.pid.should == @publisher2.pid
|
401
|
+
Book.find(@book.pid).author.pid.should == @author.pid
|
402
|
+
end
|
403
|
+
|
404
|
+
it "should only clear the matching class association" do
|
405
|
+
@book.publisher = @publisher
|
406
|
+
@book.author = @author
|
407
|
+
@book.save
|
408
|
+
|
409
|
+
@book.author = nil
|
410
|
+
@book.save
|
411
|
+
|
412
|
+
Book.find(@book.pid).author.should be_nil
|
413
|
+
Book.find(@book.pid).publisher.pid.should == @publisher.pid
|
414
|
+
end
|
415
|
+
|
354
416
|
it "should be able to be set by id" do
|
355
417
|
@book.library_id = @library.pid
|
356
418
|
@book.library_id.should == @library.pid
|
@@ -362,7 +424,10 @@ describe ActiveFedora::Base do
|
|
362
424
|
after do
|
363
425
|
@library.delete
|
364
426
|
@book.delete
|
427
|
+
@author.delete
|
428
|
+
@publisher.delete
|
365
429
|
@library2.delete if @library2
|
430
|
+
@publisher2.delete if @publisher2
|
366
431
|
end
|
367
432
|
end
|
368
433
|
end
|
@@ -605,4 +670,61 @@ describe ActiveFedora::Base do
|
|
605
670
|
end
|
606
671
|
end
|
607
672
|
end
|
608
|
-
|
673
|
+
|
674
|
+
describe "casting when the class name is ActiveFedora::Base" do
|
675
|
+
describe "for habtm" do
|
676
|
+
before :all do
|
677
|
+
class Novel < ActiveFedora::Base
|
678
|
+
has_and_belongs_to_many :contents, property: :is_part_of, class_name: 'ActiveFedora::Base'
|
679
|
+
end
|
680
|
+
class TextBook < ActiveFedora::Base
|
681
|
+
has_and_belongs_to_many :contents, property: :is_part_of, class_name: 'ActiveFedora::Base'
|
682
|
+
end
|
683
|
+
class Text < ActiveFedora::Base
|
684
|
+
has_many :books, property: :is_part_of, class_name: 'ActiveFedora::Base'
|
685
|
+
end
|
686
|
+
class Image < ActiveFedora::Base
|
687
|
+
has_many :books, property: :is_part_of, class_name: 'ActiveFedora::Base'
|
688
|
+
end
|
689
|
+
|
690
|
+
end
|
691
|
+
after :all do
|
692
|
+
Object.send(:remove_const, :Novel)
|
693
|
+
Object.send(:remove_const, :TextBook)
|
694
|
+
Object.send(:remove_const, :Text)
|
695
|
+
Object.send(:remove_const, :Image)
|
696
|
+
end
|
697
|
+
|
698
|
+
describe "saving between the before and after hooks" do
|
699
|
+
let(:text1) { Text.create}
|
700
|
+
let(:image1) { Image.create}
|
701
|
+
let(:text2) { Text.create}
|
702
|
+
let(:image2) { Image.create}
|
703
|
+
let(:book1) { TextBook.create}
|
704
|
+
let(:book2) { Novel.create}
|
705
|
+
|
706
|
+
it "should work when added via the has_and_belongs_to_many" do
|
707
|
+
book1.contents = [text1, image1]
|
708
|
+
book1.save!
|
709
|
+
book2.contents = [text2, image2]
|
710
|
+
book2.save!
|
711
|
+
|
712
|
+
book1.reload.contents.should include(text1, image1)
|
713
|
+
text1.reload.books.should == [book1]
|
714
|
+
image1.reload.books.should == [book1]
|
715
|
+
|
716
|
+
book2.reload.contents.should include(text2, image2)
|
717
|
+
text2.reload.books.should == [book2]
|
718
|
+
image2.reload.books.should == [book2]
|
719
|
+
end
|
720
|
+
|
721
|
+
it "should work when added via the has_many" do
|
722
|
+
text2.books << book2
|
723
|
+
book2.save
|
724
|
+
book2.reload.contents.should == [text2]
|
725
|
+
text2.reload.books.should == [book2]
|
726
|
+
end
|
727
|
+
end
|
728
|
+
end
|
729
|
+
end
|
730
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
shared_examples_for "An ActiveModel" do
|
2
|
+
begin
|
3
|
+
require 'minitest/unit'
|
4
|
+
include Minitest::Assertions
|
5
|
+
rescue NameError
|
6
|
+
puts "Unable to load minitest, here's hoping these methods are adequate"
|
7
|
+
|
8
|
+
def assert(test, *args)
|
9
|
+
expect(test).to eq(true)
|
10
|
+
end
|
11
|
+
|
12
|
+
def assert_kind_of(klass, inspected_object)
|
13
|
+
expect(inspected_object).to be_kind_of(klass)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
include ActiveModel::Lint::Tests
|
17
|
+
|
18
|
+
ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
|
19
|
+
example m.gsub('_',' ') do
|
20
|
+
send m
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def model
|
25
|
+
subject
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/spec/unit/base_spec.rb
CHANGED
@@ -2,6 +2,8 @@ require 'spec_helper'
|
|
2
2
|
@@last_pid = 0
|
3
3
|
|
4
4
|
describe ActiveFedora::Base do
|
5
|
+
it_behaves_like "An ActiveModel"
|
6
|
+
|
5
7
|
describe 'descendants' do
|
6
8
|
it "should record the decendants" do
|
7
9
|
ActiveFedora::Base.descendants.should include(ModsArticle, SpecialThing)
|
@@ -82,9 +84,13 @@ describe ActiveFedora::Base do
|
|
82
84
|
end
|
83
85
|
|
84
86
|
describe "reindex_everything" do
|
85
|
-
it "should call update_index on every object" do
|
87
|
+
it "should call update_index on every object except for the fedora-system objects" do
|
86
88
|
Rubydora::Repository.any_instance.should_receive(:search).
|
87
|
-
and_yield(double(pid:'XXX')).and_yield(double(pid:'YYY')).and_yield(double(pid:'ZZZ'))
|
89
|
+
and_yield(double(pid:'XXX')).and_yield(double(pid:'YYY')).and_yield(double(pid:'ZZZ')).
|
90
|
+
and_yield(double(pid:'fedora-system:ServiceDeployment-3.0')).
|
91
|
+
and_yield(double(pid:'fedora-system:ServiceDefinition-3.0')).
|
92
|
+
and_yield(double(pid:'fedora-system:FedoraObject-3.0'))
|
93
|
+
|
88
94
|
mock_update = double(:mock_obj)
|
89
95
|
mock_update.should_receive(:update_index).exactly(3).times
|
90
96
|
ActiveFedora::Base.should_receive(:find).with('XXX', :cast=>true).and_return(mock_update)
|
@@ -92,6 +98,18 @@ describe ActiveFedora::Base do
|
|
92
98
|
ActiveFedora::Base.should_receive(:find).with('ZZZ', :cast=>true).and_return(mock_update)
|
93
99
|
ActiveFedora::Base.reindex_everything
|
94
100
|
end
|
101
|
+
|
102
|
+
it "should accept a query param for the search" do
|
103
|
+
query_string = "pid~*"
|
104
|
+
Rubydora::Repository.any_instance.should_receive(:search).with(query_string).
|
105
|
+
and_yield(double(pid:'XXX')).and_yield(double(pid:'YYY')).and_yield(double(pid:'ZZZ'))
|
106
|
+
mock_update = double(:mock_obj)
|
107
|
+
mock_update.should_receive(:update_index).exactly(3).times
|
108
|
+
ActiveFedora::Base.should_receive(:find).with('XXX', :cast=>true).and_return(mock_update)
|
109
|
+
ActiveFedora::Base.should_receive(:find).with('YYY', :cast=>true).and_return(mock_update)
|
110
|
+
ActiveFedora::Base.should_receive(:find).with('ZZZ', :cast=>true).and_return(mock_update)
|
111
|
+
ActiveFedora::Base.reindex_everything(query_string)
|
112
|
+
end
|
95
113
|
end
|
96
114
|
|
97
115
|
describe "With a test class" do
|
@@ -93,6 +93,38 @@ describe ActiveFedora::FileConfigurator do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
+
describe "get_config_path(:predicate_mappings)" do
|
97
|
+
it "should use the config_options[:config_path] if it exists" do
|
98
|
+
subject.should_receive(:config_options).and_return({:predicate_mappings_config_path => "/path/to/predicate_mappings.yml"})
|
99
|
+
File.should_receive(:file?).with("/path/to/predicate_mappings.yml").and_return(true)
|
100
|
+
subject.get_config_path(:predicate_mappings).should eql("/path/to/predicate_mappings.yml")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should look in Rails.root/config/predicate_mappings.yml if it exists and no predicate_mappings_config_path passed in" do
|
104
|
+
subject.should_receive(:config_options).and_return({})
|
105
|
+
stub_rails(:root => "/rails/root")
|
106
|
+
File.should_receive(:file?).with("/rails/root/config/predicate_mappings.yml").and_return(true)
|
107
|
+
subject.get_config_path(:predicate_mappings).should eql("/rails/root/config/predicate_mappings.yml")
|
108
|
+
unstub_rails
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should look in ./config/predicate_mappings.yml if neither rails.root nor :predicate_mappings_config_path are set" do
|
112
|
+
subject.should_receive(:config_options).and_return({})
|
113
|
+
Dir.stub(:getwd => "/current/working/directory")
|
114
|
+
File.should_receive(:file?).with("/current/working/directory/config/predicate_mappings.yml").and_return(true)
|
115
|
+
subject.get_config_path(:predicate_mappings).should eql("/current/working/directory/config/predicate_mappings.yml")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return default predicate_mappings.yml that ships with active-fedora if none of the above" do
|
119
|
+
subject.should_receive(:config_options).and_return({})
|
120
|
+
Dir.should_receive(:getwd).and_return("/current/working/directory")
|
121
|
+
File.should_receive(:file?).with("/current/working/directory/config/predicate_mappings.yml").and_return(false)
|
122
|
+
File.should_receive(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"),'config','predicate_mappings.yml'))).and_return(true)
|
123
|
+
logger.should_receive(:warn).with("Using the default predicate_mappings.yml that comes with active-fedora. If you want to override this, pass the path to predicate_mappings.yml to ActiveFedora - ie. ActiveFedora.init(:predicate_mappings_config_path => '/path/to/predicate_mappings.yml') - or set Rails.root and put predicate_mappings.yml into \#{Rails.root}/config.")
|
124
|
+
subject.get_config_path(:predicate_mappings).should eql(File.expand_path(File.join(File.dirname("__FILE__"),'config','predicate_mappings.yml')))
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
96
128
|
describe "get_config_path(:solr)" do
|
97
129
|
it "should return the solr_config_path if set in config_options hash" do
|
98
130
|
subject.stub(:config_options => {:solr_config_path => "/path/to/solr.yml"})
|
@@ -302,20 +334,8 @@ describe ActiveFedora::FileConfigurator do
|
|
302
334
|
|
303
335
|
describe ".build_predicate_config_path" do
|
304
336
|
it "should return the path to the default config/predicate_mappings.yml if no valid path is given" do
|
305
|
-
subject.send(:build_predicate_config_path
|
337
|
+
subject.send(:build_predicate_config_path).should == default_predicate_mapping_file
|
306
338
|
end
|
307
|
-
|
308
|
-
it "should return the path to the default config/predicate_mappings.yml if specified config file not found" do
|
309
|
-
File.should_receive(:exist?).with("/path/to/predicate_mappings.yml").and_return(false)
|
310
|
-
File.should_receive(:exist?).with(default_predicate_mapping_file).and_return(true)
|
311
|
-
subject.send(:build_predicate_config_path,"/path/to").should == default_predicate_mapping_file
|
312
|
-
end
|
313
|
-
|
314
|
-
it "should return the path to the specified config_path if it exists" do
|
315
|
-
File.should_receive(:exist?).with("/path/to/predicate_mappings.yml").and_return(true)
|
316
|
-
subject.should_receive(:valid_predicate_mapping?).and_return(true)
|
317
|
-
subject.send(:build_predicate_config_path,"/path/to").should == "/path/to/predicate_mappings.yml"
|
318
|
-
end
|
319
339
|
end
|
320
340
|
|
321
341
|
describe ".predicate_config" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-fedora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.4.
|
4
|
+
version: 6.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Zumwalt
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-07-
|
13
|
+
date: 2013-07-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rsolr
|
@@ -285,6 +285,7 @@ files:
|
|
285
285
|
- .mailmap
|
286
286
|
- .travis.yml
|
287
287
|
- CONSOLE_GETTING_STARTED.textile
|
288
|
+
- CONTRIBUTING.md
|
288
289
|
- CONTRIBUTORS.md
|
289
290
|
- Gemfile
|
290
291
|
- History.txt
|
@@ -477,6 +478,7 @@ files:
|
|
477
478
|
- spec/samples/special_thing.rb
|
478
479
|
- spec/spec.opts
|
479
480
|
- spec/spec_helper.rb
|
481
|
+
- spec/support/an_active_model.rb
|
480
482
|
- spec/support/mock_fedora.rb
|
481
483
|
- spec/unit/active_fedora_spec.rb
|
482
484
|
- spec/unit/association_proxy_spec.rb
|
@@ -637,6 +639,7 @@ test_files:
|
|
637
639
|
- spec/samples/special_thing.rb
|
638
640
|
- spec/spec.opts
|
639
641
|
- spec/spec_helper.rb
|
642
|
+
- spec/support/an_active_model.rb
|
640
643
|
- spec/support/mock_fedora.rb
|
641
644
|
- spec/unit/active_fedora_spec.rb
|
642
645
|
- spec/unit/association_proxy_spec.rb
|