hydra-collections 5.0.4 → 6.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36ddec8b1586e43c728658973979db06786efb05
4
- data.tar.gz: 07d3a47de4e1fac51cb63cbce5dcab0e7f1078e0
3
+ metadata.gz: a55e2a03471e0659271fbbbc73f0dd6233119390
4
+ data.tar.gz: 872f3f1d0fc426e335b870b1384ebd71d0c8ba78
5
5
  SHA512:
6
- metadata.gz: 008fb15b304508524d24bbf9c25246e6e32db12b744d974fe762659544acde8f2b266f8a641a6ba39491a9d6400096e382a3ff0e48930cdb587170fe500ae261
7
- data.tar.gz: 995ff18102b0a35df5e089ea1c45818323a7d16460f2c386993f4b64fe06b5d5321d73d393b34d513a5d9f4678d4c3e7ddf9b297bfbfaa4ccef54bd54db23c65
6
+ metadata.gz: 4a029879709867b6df79503628696e37bcdb5e68ef69abbae331266ffdc2b604a66c6632c9f53dae9f0b7441b6441228866b868c6551d60c606e3abef51929bc
7
+ data.tar.gz: de9b2cbbe3e68940bf208d8ff90db132ddfecd6adc1a8f3f785514b614d63078041125d2b959baa7d1a6dfde7d1b82d1057a4f7e9b0970398aba52248085b383
data/.gitignore CHANGED
@@ -18,5 +18,5 @@ spec/reports
18
18
  test/tmp
19
19
  test/version_tmp
20
20
  tmp
21
- .internal_test_app
21
+ spec/internal
22
22
  jetty
data/.travis.yml CHANGED
@@ -2,12 +2,13 @@ language: ruby
2
2
  cache: bundler
3
3
  sudo: false
4
4
  rvm:
5
- - 2.2
5
+ - 2.1
6
6
  env:
7
7
  global:
8
8
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
9
9
  matrix:
10
- - "RAILS_VERSION=4.2.5"
10
+ - "RAILS_VERSION=4.1.10"
11
+ - "RAILS_VERSION=4.2.1"
11
12
  notifications:
12
13
  email:
13
14
  recipients:
data/Gemfile CHANGED
@@ -3,8 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in hydra-collections.gemspec
4
4
  gemspec
5
5
 
6
- gem 'kaminari', github: 'jcoyne/kaminari', branch: 'sufia'
7
-
8
6
  group :development, :test do
9
7
  gem 'sqlite3'
10
8
  gem "factory_girl_rails"
@@ -16,28 +14,22 @@ group :development, :test do
16
14
  gem 'rspec-activemodel-mocks'
17
15
  end
18
16
 
19
- # BEGIN ENGINE_CART BLOCK
20
- # engine_cart: 0.8.0
21
- # engine_cart stanza: 0.8.0
22
- # the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app.
23
- file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path(".internal_test_app", File.dirname(__FILE__)))
24
- if File.exist?(file)
25
- begin
26
- eval_gemfile file
27
- rescue Bundler::GemfileError => e
28
- Bundler.ui.warn '[EngineCart] Skipping Rails application dependencies:'
29
- Bundler.ui.warn e.message
30
- end
17
+ gem 'slop', '~> 3.6' # because rails installs byebug in the Gemfile
18
+
19
+ file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path("../spec/internal", __FILE__))
20
+ if File.exists?(file)
21
+ puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
22
+ instance_eval File.read(file)
31
23
  else
32
- Bundler.ui.warn "[EngineCart] Unable to find test application dependencies in #{file}, using placeholder dependencies"
24
+ extra_file = File.expand_path("../spec/test_app_templates/Gemfile.extra", __FILE__)
25
+ instance_eval File.read(extra_file)
33
26
 
34
27
  gem 'rails', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']
35
28
 
36
- if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^4.2/
29
+ if ENV['RAILS_VERSION'] and ENV['RAILS_VERSION'] !~ /^4.2/
30
+ gem 'sass-rails', "< 5.0"
31
+ else
37
32
  gem 'responders', "~> 2.0"
38
33
  gem 'sass-rails', ">= 5.0"
39
- else
40
- gem 'sass-rails', "< 5.0"
41
34
  end
42
35
  end
43
- # END ENGINE_CART BLOCK
@@ -11,35 +11,16 @@ module Hydra::Collections::SelectsCollections
11
11
  { read: [:read, :edit], edit: [:edit] }
12
12
  end
13
13
 
14
- ##
15
- # Return list of collections for which the current user has read access.
16
- # Add this or find_collections_with_edit_access as a before filter on any page that shows the form_for_select_collection
17
- #
18
- # @return [Array<SolrDocument>] Solr documents for each collection the user has read access
14
+ # add one of the following methods as a before filter on any page that shows the form_for_select_collection
19
15
  def find_collections_with_read_access
20
16
  find_collections(:read)
21
17
  end
22
18
 
23
- ##
24
- # Return list of collections for which the current user has edit access. Optionally prepend with default
25
- # that can be used in a select menu to instruct user to select a collection.
26
- # Add this or find_collections_with_read_access as a before filter on any page that shows the form_for_select_collection
27
- #
28
- # @param [TrueClass|FalseClass] :include_default if true, prepends the default_option; otherwise, if false, returns only collections
29
- # @param [Fixnum] :default_id for select menus, this is the id of the first selection representing the instructions
30
- # @param [String] :default_title for select menus, this is the text displayed as the first item serving as instructions
31
- #
32
- # @return [Array<SolrDocument>] Solr documents for each collection the user has edit access, plus optional instructions
33
- def find_collections_with_edit_access(include_default=false, default_id=-1, default_title="Select collection...")
19
+ def find_collections_with_edit_access
34
20
  find_collections(:edit)
35
- default_option = SolrDocument.new(id: default_id, title_tesim: default_title)
36
- @user_collections.unshift(default_option) if include_default
37
21
  end
38
22
 
39
- ##
40
- # Return list of collections matching the passed in access_level for the current user.
41
- # @param [Symbol] :access_level one of :read or :edit
42
- # @return [Array<SolrDocument>] Solr documents for each collection the user has the appropriate access level
23
+ #
43
24
  def find_collections (access_level = nil)
44
25
  # need to know the user if there is an access level applied otherwise we are just doing public collections
45
26
  authenticate_user! unless access_level.blank?
@@ -66,7 +47,7 @@ module Hydra::Collections::SelectsCollections
66
47
  # Defines which search_params_logic should be used when searching for Collections
67
48
  def collection_search_params_logic
68
49
  [:default_solr_parameters, :add_query_to_solr, :add_access_controls_to_solr_params,
69
- :add_collection_filter, :some_rows, :sort_by_title]
50
+ :add_collection_filter, :some_rows]
70
51
  end
71
52
 
72
53
  end
@@ -172,7 +172,10 @@ module Hydra
172
172
 
173
173
  def add_members_to_collection collection = nil
174
174
  collection ||= @collection
175
- collection.add_members batch
175
+ batch.each do |id|
176
+ collection.child_generic_works << ActiveFedora::Base.find(id)
177
+ end
178
+ #TODO this old way was more efficient #collection.member_ids = batch.concat(collection.member_ids)
176
179
  end
177
180
 
178
181
  def remove_members_from_collection
@@ -2,28 +2,10 @@ module Hydra
2
2
  module Collection
3
3
  extend ActiveSupport::Concern
4
4
  extend Deprecation
5
+ include Hydra::Works::CollectionBehavior
5
6
  include Hydra::WithDepositor # for access to apply_depositor_metadata
6
7
  include Hydra::AccessControls::Permissions
7
- include Hydra::Collections::Collectible
8
8
  include Hydra::Collections::Metadata
9
- include Hydra::Collections::Relations
10
-
11
- def update_all_members
12
- Deprecation.warn(Collection, 'update_all_members is deprecated and will be removed in version 5.0')
13
- self.members.collect { |m| update_member(m) }
14
- end
15
-
16
- # TODO: Use solr atomic updates to accelerate this process
17
- def update_member member
18
- Deprecation.warn(Collection, 'update_member is deprecated and will be removed in version 5.0')
19
- # because the member may have its collections cached, reload that cache so that it indexes the correct fields.
20
- member.collections(true) if member.respond_to? :collections
21
- member.update_index
22
- end
23
-
24
- def add_members new_member_ids
25
- return if new_member_ids.nil? || new_member_ids.size < 1
26
- self.members << ActiveFedora::Base.find(new_member_ids)
27
- end
28
- end
9
+ include Hydra::Works::CollectionBehavior
10
+ end
29
11
  end
@@ -2,76 +2,61 @@ module Hydra::Collections
2
2
  module Metadata
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
- property :depositor, predicate: RDF::Vocab::MARCRelators.dpt, multiple: false do |index|
5
+ property :depositor, predicate: ::RDF::URI.new("http://id.loc.gov/vocabulary/relators/dpt"), multiple: false do |index|
6
6
  index.as :symbol, :stored_searchable
7
7
  end
8
8
 
9
- property :part_of, predicate: RDF::Vocab::DC.isPartOf
10
-
11
- property :contributor, predicate: RDF::Vocab::DC.contributor do |index|
9
+ property :part_of, predicate: RDF::DC.isPartOf
10
+ property :contributor, predicate: RDF::DC.contributor do |index|
12
11
  index.as :stored_searchable, :facetable
13
12
  end
14
-
15
- property :creator, predicate: RDF::Vocab::DC.creator do |index|
13
+ property :creator, predicate: RDF::DC.creator do |index|
16
14
  index.as :stored_searchable, :facetable
17
15
  end
18
-
19
- property :title, predicate: RDF::Vocab::DC.title, multiple: false do |index|
20
- index.as :stored_searchable, :sortable
16
+ property :title, predicate: RDF::DC.title, multiple: false do |index|
17
+ index.as :stored_searchable
21
18
  end
22
-
23
- property :description, predicate: RDF::Vocab::DC.description, multiple: false do |index|
19
+ property :description, predicate: RDF::DC.description, multiple: false do |index|
24
20
  index.type :text
25
21
  index.as :stored_searchable
26
22
  end
27
-
28
- property :publisher, predicate: RDF::Vocab::DC.publisher do |index|
23
+ property :publisher, predicate: RDF::DC.publisher do |index|
29
24
  index.as :stored_searchable, :facetable
30
25
  end
31
-
32
- property :date_created, predicate: RDF::Vocab::DC.created do |index|
26
+ property :date_created, predicate: RDF::DC.created do |index|
33
27
  index.as :stored_searchable
34
28
  end
35
-
36
- property :date_uploaded, predicate: RDF::Vocab::DC.dateSubmitted, multiple: false do |index|
29
+ property :date_uploaded, predicate: RDF::DC.dateSubmitted, multiple: false do |index|
37
30
  index.type :date
38
31
  index.as :stored_sortable
39
32
  end
40
-
41
- property :date_modified, predicate: RDF::Vocab::DC.modified, multiple: false do |index|
33
+ property :date_modified, predicate: RDF::DC.modified, multiple: false do |index|
42
34
  index.type :date
43
35
  index.as :stored_sortable
44
36
  end
45
-
46
- property :subject, predicate: RDF::Vocab::DC.subject do |index|
37
+ property :subject, predicate: RDF::DC.subject do |index|
47
38
  index.as :stored_searchable, :facetable
48
39
  end
49
-
50
- property :language, predicate: RDF::Vocab::DC.language do |index|
40
+ property :language, predicate: RDF::DC.language do |index|
51
41
  index.as :stored_searchable, :facetable
52
42
  end
53
-
54
- property :rights, predicate: RDF::Vocab::DC.rights do |index|
43
+ property :rights, predicate: RDF::DC.rights do |index|
55
44
  index.as :stored_searchable
56
45
  end
57
-
58
- property :resource_type, predicate: RDF::Vocab::DC.type do |index|
46
+ property :resource_type, predicate: RDF::DC.type do |index|
59
47
  index.as :stored_searchable, :facetable
60
48
  end
61
-
62
- property :identifier, predicate: RDF::Vocab::DC.identifier do |index|
49
+ property :identifier, predicate: RDF::DC.identifier do |index|
63
50
  index.as :stored_searchable
64
51
  end
65
-
66
- property :based_near, predicate: RDF::Vocab::FOAF.based_near do |index|
52
+ property :based_near, predicate: RDF::FOAF.based_near do |index|
67
53
  index.as :stored_searchable, :facetable
68
54
  end
69
-
70
- property :tag, predicate: RDF::Vocab::DC.relation do |index|
55
+ property :tag, predicate: RDF::DC.relation do |index|
71
56
  index.as :stored_searchable, :facetable
72
57
  end
73
-
74
58
  property :related_url, predicate: RDF::RDFS.seeAlso
59
+
75
60
  end
76
61
  end
77
62
  end
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'hydra-head', '~> 9.1'
22
22
  spec.add_dependency 'deprecation', '~> 0.1'
23
23
  spec.add_dependency 'blacklight', '~> 5.10'
24
- spec.add_dependency 'rdf-vocab', '~> 0'
24
+ spec.add_dependency 'hydra-works', '~> 0.1'
25
25
 
26
- spec.add_development_dependency 'engine_cart', '~> 0.8'
26
+ spec.add_development_dependency 'engine_cart', '~> 0.5'
27
27
  spec.add_development_dependency 'rspec-rails', '~> 3.1'
28
28
  end
@@ -1,4 +1,5 @@
1
1
  require "hydra/head"
2
+ require 'hydra/works'
2
3
 
3
4
  module Hydra
4
5
  module Collections
@@ -19,4 +20,4 @@ module Hydra
19
20
  )
20
21
  end
21
22
  end
22
- end
23
+ end
@@ -1,36 +1,25 @@
1
1
  # This module adds a `has_many :collections` association to any models that you mix it into, using the :has_collection_member property
2
2
  # It also provides methods to help you index the information as a facet
3
3
  require 'deprecation'
4
- module Hydra::Collections::Collectible
5
- extend ActiveSupport::Concern
6
- extend Deprecation
7
- self.deprecation_horizon = "hydra-collections 4.0"
4
+ module Hydra::Collections
5
+ module Collectible
6
+ extend ActiveSupport::Concern
7
+ extend Deprecation
8
8
 
9
- included do
10
- has_many :collections, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasCollectionMember, class_name: "ActiveFedora::Base"
11
- end
9
+ included do
10
+ include Hydra::Works::GenericWorkBehavior
11
+ Deprecation.warn(Collectible, "Hydra::Collections::Collectible is deprecated. include Hydra::Works::GenericWorkBehavior instead. Hydra::Collections::Collectible will be removed in Hydra::Collections 7.0")
12
+ end
12
13
 
13
- # Add this method to your solrization logic (ie. in to_solr) in order to populate the 'collection' facet
14
- # with the pids of any collections that contain the current object.
15
- # @example
16
- # def to_solr(solr_doc={}, opts={})
17
- # super(solr_doc, opts)
18
- # index_collection_ids(solr_doc)
19
- # return solr_doc
20
- # end
21
- def index_collection_ids(solr_doc={})
22
- Deprecation.warn(Hydra::Collections::Collectible, 'index_collection_ids is deprecated and will be removed in version 5.0')
23
- # CollectionAssociation#ids_reader loads from solr on each call, so only call it once
24
- # see https://github.com/projecthydra/active_fedora/issues/644
25
- ids = collection_ids
26
- solr_doc[Solrizer.solr_name(:collection, :facetable)] = ids
27
- solr_doc[Solrizer.solr_name(:collection)] = ids
28
- solr_doc
29
- end
14
+ def collection_ids
15
+ Deprecation.warn(Collectible, "collection_ids is deprecated and will be removed in Hydra::Collections 7.0. Use parent_collections.map(&:id) instead.")
16
+ parent_collections.map(&:id)
17
+ end
30
18
 
31
- def index_collection_pids(solr_doc={})
32
- index_collection_ids(solr_doc)
33
- end
34
- deprecation_deprecate :index_collection_pids
19
+ def collections
20
+ Deprecation.warn(Collectible, "collections is deprecated and will be removed in Hydra::Collections 7.0. Use parent_collections instead.")
21
+ parent_collections
22
+ end
35
23
 
24
+ end
36
25
  end
@@ -1,4 +1,10 @@
1
1
  module Hydra::Collections::SearchBehaviors
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ class_attribute :from_field
6
+ self.from_field = 'member_ids_ssim'
7
+ end
2
8
 
3
9
  def collection
4
10
  scope.collection
@@ -7,7 +13,7 @@ module Hydra::Collections::SearchBehaviors
7
13
  # include filters into the query to only include the collection memebers
8
14
  def include_collection_ids(solr_parameters)
9
15
  solr_parameters[:fq] ||= []
10
- solr_parameters[:fq] << "{!join from=hasCollectionMember_ssim to=id}id:#{collection.id}"
16
+ solr_parameters[:fq] << "{!join from=#{from_field} to=id}id:#{collection.id}"
11
17
  end
12
18
 
13
19
  def some_rows(solr_parameters)
@@ -19,13 +25,6 @@ module Hydra::Collections::SearchBehaviors
19
25
  solr_parameters[:fq] << ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: ::Collection.to_class_uri)
20
26
  end
21
27
 
22
- # Sort results by title if no query was supplied.
23
- # This overrides the default 'relevance' sort.
24
- def sort_by_title(solr_parameters)
25
- return if solr_parameters[:q]
26
- solr_parameters[:sort] ||= "#{sort_field} asc"
27
- end
28
-
29
28
  def discovery_perms= perms
30
29
  @discovery_perms = perms
31
30
  end
@@ -34,8 +33,4 @@ module Hydra::Collections::SearchBehaviors
34
33
  @discovery_perms || super
35
34
  end
36
35
 
37
- def sort_field
38
- Solrizer.solr_name('title', :sortable)
39
- end
40
-
41
36
  end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module Collections
3
- VERSION = "5.0.4"
3
+ VERSION = "6.0.0.alpha"
4
4
  end
5
5
  end
@@ -10,11 +10,11 @@ describe CollectionsController, :type => :controller do
10
10
  config.default_solr_params = {:qf => 'label_tesim'}
11
11
  end
12
12
 
13
- class GenericFile < ActiveFedora::Base
14
- include Hydra::Collections::Collectible
13
+ class GenericWork < ActiveFedora::Base
15
14
  include Hydra::AccessControls::Permissions
15
+ include Hydra::Works::GenericWorkBehavior
16
16
 
17
- property :title, predicate: ::RDF::Vocab::DC.title, multiple: false
17
+ property :title, predicate: ::RDF::DC.title, multiple: false
18
18
 
19
19
  def to_solr(solr_doc={})
20
20
  super.tap do |solr_doc|
@@ -25,7 +25,7 @@ describe CollectionsController, :type => :controller do
25
25
  end
26
26
 
27
27
  after(:all) do
28
- Object.send(:remove_const, :GenericFile)
28
+ Object.send(:remove_const, :GenericWork)
29
29
  end
30
30
 
31
31
  let(:user) { FactoryGirl.create(:user) }
@@ -39,15 +39,15 @@ describe CollectionsController, :type => :controller do
39
39
  end
40
40
 
41
41
  describe "#index" do
42
- let!(:collection1) { Collection.create(title: 'Beta') { |c| c.apply_depositor_metadata(user.user_key) } }
43
- let!(:collection2) { Collection.create(title: 'Alpha') { |c| c.apply_depositor_metadata(user.user_key) } }
44
- let!(:generic_file) { GenericFile.create }
42
+ let!(:collection1) { Collection.create { |c| c.apply_depositor_metadata(user.user_key) } }
43
+ let!(:collection2) { Collection.create { |c| c.apply_depositor_metadata(user.user_key) } }
44
+ let!(:generic_file) { GenericWork.create }
45
45
 
46
- it "shows a list of collections sorted alphabetically" do
46
+ it "should show a list of collections" do
47
47
  get :index
48
48
  expect(response).to be_successful
49
49
  expect(assigns[:document_list].map(&:id)).not_to include generic_file.id
50
- expect(assigns[:document_list].map(&:id)).to eq [collection2.id, collection1.id]
50
+ expect(assigns[:document_list].map(&:id)).to eq [collection1.id, collection2.id]
51
51
  end
52
52
  end
53
53
 
@@ -69,10 +69,10 @@ describe CollectionsController, :type => :controller do
69
69
  expect(response).to redirect_to collections.collection_path(assigns[:collection])
70
70
  end
71
71
  it "should add docs to collection if batch ids provided" do
72
- @asset1 = ActiveFedora::Base.create!
73
- @asset2 = ActiveFedora::Base.create!
72
+ @asset1 = GenericWork.create!
73
+ @asset2 = GenericWork.create!
74
74
  post :create, batch_document_ids: [@asset1, @asset2], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
75
- expect(assigns[:collection].members).to match_array [@asset1, @asset2]
75
+ expect(assigns[:collection].members).to eq([@asset1, @asset2])
76
76
  end
77
77
  it "should call after_create" do
78
78
  expect(controller).to receive(:after_create).and_call_original
@@ -80,26 +80,26 @@ describe CollectionsController, :type => :controller do
80
80
  end
81
81
 
82
82
  it "should add one doc to collection if batch ids provided and add the collection id to the document in the colledction" do
83
- @asset1 = GenericFile.create!
83
+ @asset1 = GenericWork.create!
84
84
  post :create, batch_document_ids: [@asset1], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
85
85
  expect(assigns[:collection].members).to eq [@asset1]
86
86
  asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset1.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
87
87
  expect(asset_results["response"]["numFound"]).to eq(1)
88
88
  doc = asset_results["response"]["docs"].first
89
89
  expect(doc["id"]).to eq(@asset1.id)
90
- afterupdate = GenericFile.find(@asset1.id)
90
+ afterupdate = GenericWork.find(@asset1.id)
91
91
  expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
92
92
  end
93
93
  it "should add docs to collection if batch ids provided and add the collection id to the documents int he colledction" do
94
- @asset1 = GenericFile.create!
95
- @asset2 = GenericFile.create!
94
+ @asset1 = GenericWork.create!
95
+ @asset2 = GenericWork.create!
96
96
  post :create, batch_document_ids: [@asset1,@asset2], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
97
- expect(assigns[:collection].members).to match_array [@asset1, @asset2]
97
+ expect(assigns[:collection].members).to eq([@asset1,@asset2])
98
98
  asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset1.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
99
99
  expect(asset_results["response"]["numFound"]).to eq(1)
100
100
  doc = asset_results["response"]["docs"].first
101
101
  expect(doc["id"]).to eq(@asset1.id)
102
- afterupdate = GenericFile.find(@asset1.id)
102
+ afterupdate = GenericWork.find(@asset1.id)
103
103
  expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
104
104
  end
105
105
  end
@@ -107,9 +107,9 @@ describe CollectionsController, :type => :controller do
107
107
  describe "#update" do
108
108
  before do
109
109
  @collection = Collection.create { |c| c.apply_depositor_metadata(user.user_key) }
110
- @asset1 = GenericFile.create!
111
- @asset2 = GenericFile.create!
112
- @asset3 = GenericFile.create!
110
+ @asset1 = GenericWork.create!
111
+ @asset2 = GenericWork.create!
112
+ @asset3 = GenericWork.create!
113
113
  allow(controller).to receive(:authorize!).and_return(true)
114
114
  expect(controller).to receive(:authorize!).at_least(:once)
115
115
  end
@@ -187,27 +187,25 @@ describe CollectionsController, :type => :controller do
187
187
  expect(controller).to receive(:authorize!).and_return(true)
188
188
  end
189
189
 
190
- it "should delete collection" do
190
+ it "deletes the collection" do
191
191
  delete :destroy, id: @collection
192
192
  expect(response).to redirect_to Rails.application.routes.url_helpers.catalog_index_path
193
193
  expect(flash[:notice]).to eq("Collection was successfully deleted.")
194
194
  end
195
195
 
196
- it "should after_destroy" do
196
+ it "calls after_destroy" do
197
197
  expect(controller).to receive(:after_destroy).and_call_original
198
198
  delete :destroy, id: @collection
199
199
  end
200
200
 
201
- it "should call update members" do
202
- @asset1 = GenericFile.create!
203
- @collection.members << @asset1
204
- @collection.save
205
- @asset1 = @asset1.reload
206
- @asset1.update_index
207
- expect(@asset1.collections).to eq [@collection]
201
+ it "updates members" do
202
+ asset1 = GenericWork.create!
203
+ @collection.members << asset1
204
+ @collection.save!
205
+ expect(asset1.parent_collections).to eq [@collection]
208
206
 
209
207
  delete :destroy, id: @collection
210
- expect(@asset1.reload.collections).to eq []
208
+ expect(asset1.parent_collections).to eq []
211
209
  end
212
210
  end
213
211
 
@@ -232,9 +230,9 @@ describe CollectionsController, :type => :controller do
232
230
  end
233
231
 
234
232
  context "with a number of assets" do
235
- let(:asset1) { GenericFile.create!(title: "First of the Assets", read_users: [user.user_key]) }
236
- let(:asset2) { GenericFile.create!(title: "Second of the Assets", read_users: [user.user_key]) }
237
- let(:asset3) { GenericFile.create!(title: "Third of the Assets", read_users: [user.user_key]) }
233
+ let(:asset1) { GenericWork.create!(title: "First of the Assets", read_users: [user.user_key]) }
234
+ let(:asset2) { GenericWork.create!(title: "Second of the Assets", read_users: [user.user_key]) }
235
+ let(:asset3) { GenericWork.create!(title: "Third of the Assets", read_users: [user.user_key]) }
238
236
  let!(:collection) do
239
237
  Collection.create!(id: "abc123", title: "My collection",
240
238
  members: [asset1, asset2, asset3]) do |col|
@@ -256,7 +254,7 @@ describe CollectionsController, :type => :controller do
256
254
  end
257
255
 
258
256
  describe "additional collections" do
259
- let(:asset4) { GenericFile.create!(title: "#{asset1.id}", read_users: [user.user_key]) }
257
+ let(:asset4) { GenericWork.create!(title: "#{asset1.id}", read_users: [user.user_key]) }
260
258
  let!(:collection2) do
261
259
  Collection.create!(id: "abc1234", title: "Other collection", members: [asset4]) do |col|
262
260
  col.apply_depositor_metadata(user.user_key)
@@ -277,8 +275,8 @@ describe CollectionsController, :type => :controller do
277
275
 
278
276
  context "When there are search matches that are not in the collection" do
279
277
  before do
280
- GenericFile.create!(title: "#{asset1.id} #{asset1.title}")
281
- GenericFile.create!(title: asset1.title.to_s)
278
+ GenericWork.create!(title: "#{asset1.id} #{asset1.title}")
279
+ GenericWork.create!(title: asset1.title.to_s)
282
280
  end
283
281
  # NOTE: This test depends on title_tesim being in the qf in solrconfig.xml
284
282
  it "only shows the collection assets" do
@@ -5,13 +5,11 @@ describe OtherCollectionsController, :type => :controller do
5
5
  before(:all) do
6
6
  class OtherCollection < ActiveFedora::Base
7
7
  include Hydra::Collection
8
- include Hydra::Collections::Collectible
9
8
  end
10
9
 
11
10
  class Member < ActiveFedora::Base
12
11
  include Hydra::Collections::Collectible
13
12
  include Hydra::AccessControls::Permissions
14
- attr_accessor :title
15
13
  end
16
14
  end
17
15
 
@@ -20,19 +18,17 @@ describe OtherCollectionsController, :type => :controller do
20
18
  Object.send(:remove_const, :OtherCollection)
21
19
  end
22
20
 
23
- let(:user) { FactoryGirl.find_or_create(:user) }
21
+ let(:user) { FactoryGirl.create(:user) }
24
22
 
25
23
  before do
26
24
  allow(controller).to receive(:has_access?).and_return(true)
27
25
  sign_in user
28
- # allow_any_instance_of(User).to receive(:groups).and_return([])
29
- # allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
30
26
  end
31
27
 
32
28
  describe "#show" do
33
- let(:asset1) { Member.create!(title: "First of the Assets", read_users: [user.user_key]) }
34
- let(:asset2) { Member.create!(title: "Second of the Assets", read_users: [user.user_key]) }
35
- let(:asset3) { Member.create!(title: "Third of the Assets", read_users: [user.user_key]) }
29
+ let(:asset1) { Member.create!(read_users: [user.user_key]) }
30
+ let(:asset2) { Member.create!(read_users: [user.user_key]) }
31
+ let(:asset3) { Member.create!(read_users: [user.user_key]) }
36
32
  let(:collection) do
37
33
  OtherCollection.create(id: 'foo123', title: "My collection",
38
34
  members: [asset1, asset2, asset3]) do |collection|
@@ -44,7 +40,7 @@ describe OtherCollectionsController, :type => :controller do
44
40
  allow(controller).to receive(:apply_gated_search)
45
41
  end
46
42
 
47
- it "should show the collections" do
43
+ it "shows the collections" do
48
44
  get :show, id: collection
49
45
  expect(assigns[:collection].title).to eq collection.title
50
46
  ids = assigns[:member_docs].map(&:id)
@@ -11,8 +11,8 @@ end
11
11
  describe SelectsCollectionsController, :type => :controller do
12
12
 
13
13
  describe "#find_collections" do
14
- it "uses collection_search_params_logic" do
15
- expect(subject.collection_search_params_logic).to eq [:default_solr_parameters, :add_query_to_solr, :add_access_controls_to_solr_params, :add_collection_filter, :some_rows, :sort_by_title]
14
+ it "should use collection_search_params_logic" do
15
+ expect(subject.collection_search_params_logic).to eq([:default_solr_parameters, :add_query_to_solr, :add_access_controls_to_solr_params, :add_collection_filter, :some_rows])
16
16
  expect(Hydra::Collections::SearchBuilder).to receive(:new).with(subject.collection_search_params_logic, subject).and_call_original
17
17
  subject.find_collections
18
18
  end
@@ -47,14 +47,13 @@ describe SelectsCollectionsController, :type => :controller do
47
47
  context "when there are more than 10" do
48
48
  before do
49
49
  11.times do |i|
50
- Collection.new(title:"Test Public #{i}").tap do |col|
50
+ Collection.create(title:"Test Public #{i}", read_groups: ["public"]) do |col|
51
51
  col.apply_depositor_metadata(@user.user_key)
52
- col.read_groups = ["public"]
53
- col.save!
54
52
  end
55
53
  end
56
54
  end
57
- it "should return all public collections" do
55
+
56
+ it "returns all public collections" do
58
57
  subject.find_collections
59
58
  expect(assigns[:user_collections].count).to eq(12)
60
59
  end
@@ -91,11 +90,6 @@ describe SelectsCollectionsController, :type => :controller do
91
90
  subject.find_collections_with_edit_access
92
91
  expect(assigns[:user_collections].map(&:id)).to match_array [@collection.id, @collection3.id]
93
92
  end
94
-
95
- it "should return only public or editable collections & instructions" do
96
- subject.find_collections_with_edit_access(true)
97
- expect(assigns[:user_collections].map(&:id)).to match_array [-1, @collection.id, @collection3.id]
98
- end
99
93
  end
100
94
  end
101
95
  end
@@ -7,33 +7,32 @@ describe Hydra::Collections::Collectible do
7
7
  end
8
8
  end
9
9
 
10
- let(:collection1) { FactoryGirl.create(:collection) }
10
+ let(:collection1) { FactoryGirl.build(:collection) }
11
11
  let(:collection2) { FactoryGirl.create(:collection) }
12
- let(:collectible) { CollectibleThing.new }
12
+ let(:collectible) { CollectibleThing.create }
13
13
 
14
14
  after do
15
15
  Object.send(:remove_const, :CollectibleThing)
16
16
  end
17
17
 
18
18
  describe "collections associations" do
19
- it "should allow adding and removing" do
20
- collectible.save
19
+ before do
21
20
  collection1.members << collectible
22
21
  collection1.save
23
- collectible.collections << collection2
24
- reloaded = CollectibleThing.find(collectible.id)
25
- expect(collection2.reload.members).to eq [collectible]
26
- expect(reloaded.collections).to eq [collection1, collection2]
22
+ collection2.members << collectible
23
+ collection2.save
24
+ end
25
+
26
+ it "queries the members" do
27
+ expect(collectible.reload.collections).to eq [collection1, collection2]
28
+ end
29
+
30
+ it "counts the members" do
31
+ expect(collectible.reload.collections.size).to eq 2
27
32
  end
28
- end
29
33
 
30
- describe "index_collection_ids" do
31
- it "should add ids for all associated collections" do
32
- collectible.save
33
- collectible.collections << collection1
34
- collectible.collections << collection2
35
- expect(Deprecation).to receive(:warn)
36
- expect(collectible.index_collection_ids["collection_sim"]).to eq [collection1.id, collection2.id]
34
+ it "queries the ids" do
35
+ expect(collectible.reload.collection_ids).to eq [collection1.id, collection2.id]
37
36
  end
38
37
  end
39
38
  end
@@ -14,7 +14,6 @@ describe Collection, :type => :model do
14
14
 
15
15
  let(:gf1) { GenericFile.create }
16
16
  let(:gf2) { GenericFile.create }
17
- let(:gf3) { GenericFile.create }
18
17
 
19
18
  let(:user) { @user }
20
19
 
@@ -23,9 +22,8 @@ describe Collection, :type => :model do
23
22
 
24
23
  subject { collection.to_solr }
25
24
 
26
- it "has title and depositor information" do
25
+ it "should have title and depositor information" do
27
26
  expect(subject['title_tesim']).to eq ['A good title']
28
- expect(subject['title_si']).to eq 'A good title'
29
27
  expect(subject['depositor_tesim']).to eq [user.user_key]
30
28
  expect(subject['depositor_ssim']).to eq [user.user_key]
31
29
  end
@@ -49,12 +47,8 @@ describe Collection, :type => :model do
49
47
  end
50
48
 
51
49
  describe "the ability" do
52
- let(:collection) do
53
- Collection.new.tap do |collection|
54
- collection.apply_depositor_metadata(user)
55
- collection.save
56
- end
57
- end
50
+ let(:collection) { Collection.create { |c| c.apply_depositor_metadata(user) } }
51
+
58
52
  subject { Ability.new(user) }
59
53
 
60
54
  it "should allow the depositor to edit and read" do
@@ -73,7 +67,7 @@ describe Collection, :type => :model do
73
67
  subject { Collection.create(members: [gf1, gf2]) }
74
68
 
75
69
  it "should have many files" do
76
- expect(subject.reload.members).to match_array [gf1, gf2]
70
+ expect(subject.reload.members).to eq [gf1, gf2]
77
71
  end
78
72
  end
79
73
 
@@ -86,14 +80,7 @@ describe Collection, :type => :model do
86
80
  subject.reload
87
81
  subject.members << gf2
88
82
  subject.save
89
- expect(subject.reload.members).to match_array [gf1, gf2]
90
- end
91
-
92
- it "should allow multiple files to be added" do
93
- subject.reload
94
- subject.add_members [gf2.id, gf3.id]
95
- subject.save
96
- expect(subject.reload.members).to match_array [gf1, gf2, gf3]
83
+ expect(subject.reload.members).to eq [gf1, gf2]
97
84
  end
98
85
  end
99
86
  end
@@ -102,11 +89,13 @@ describe Collection, :type => :model do
102
89
  context "removing members" do
103
90
  before do
104
91
  subject.members = [gf1, gf2]
105
- subject.save
92
+ subject.save!
106
93
  end
107
94
 
108
- it "should allow files to be removed" do
109
- expect(gf1.collections).to eq [subject] # This line forces the "collections" to be cached.
95
+ it "allows files to be removed" do
96
+ # force the "parent_collections" to be cached:
97
+ expect(gf1.parent_collections).to eq [subject]
98
+
110
99
  # We need to ensure that deleting causes the collection to be flushed.
111
100
  subject.reload.members.delete(gf1)
112
101
  subject.save
data/spec/spec_helper.rb CHANGED
@@ -5,11 +5,12 @@ else
5
5
  require 'byebug'
6
6
  end
7
7
 
8
- ENV["RAILS_ENV"] ||= 'test'
9
8
 
10
- require 'engine_cart'
11
- EngineCart.load_application!
9
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
11
+ ENV["RAILS_ENV"] ||= 'test'
12
12
 
13
+ require File.expand_path("config/environment", ENV['RAILS_ROOT'] || File.expand_path("../internal", __FILE__))
13
14
  require 'rspec/rails'
14
15
  require 'hydra-collections'
15
16
 
@@ -1,7 +1,7 @@
1
1
  require 'rails/generators'
2
2
 
3
3
  class TestAppGenerator < Rails::Generators::Base
4
- source_root File.expand_path("../../../../spec/test_app_templates", __FILE__)
4
+ source_root File.expand_path("../../../../test_app_templates", __FILE__)
5
5
 
6
6
  def update_gemfile
7
7
  append_to_file "Gemfile" do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'collections/_thumbnail_default.html.erb' do
4
- let(:document) { SolrDocument.new :id => 'xyz', :format => 'a', :thumbnail_url => 'http://localhost/logo.png' }
4
+ let(:document) { SolrDocument.new id: 'xyz', format: 'a', thumbnail_url: 'http://localhost/logo.png' }
5
5
  let :blacklight_config do
6
6
  Blacklight::Configuration.new do |config|
7
7
  config.index.thumbnail_field = :thumbnail_url
@@ -9,7 +9,7 @@ describe 'collections/_thumbnail_default.html.erb' do
9
9
  end
10
10
 
11
11
  before do
12
- assign :response, double(:params => {}, :start => 0)
12
+ assign :response, double(start: 0)
13
13
  allow(view).to receive(:blacklight_config).and_return(blacklight_config)
14
14
  allow(view).to receive(:render_grouped_response?).and_return(false)
15
15
  allow(view).to receive(:current_search_session).and_return nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-collections
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.4
4
+ version: 6.0.0.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carolyn Cole
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-14 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hydra-head
@@ -53,33 +53,33 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.10'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rdf-vocab
56
+ name: hydra-works
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '0.1'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '0.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: engine_cart
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.8'
75
+ version: '0.5'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.8'
82
+ version: '0.5'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec-rails
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +124,6 @@ files:
124
124
  - app/models/concerns/hydra/collection.rb
125
125
  - app/models/concerns/hydra/collections/actions.rb
126
126
  - app/models/concerns/hydra/collections/metadata.rb
127
- - app/models/concerns/hydra/collections/relations.rb
128
127
  - app/models/solr_document.rb
129
128
  - app/search_builders/hydra/collections/search_builder.rb
130
129
  - app/views/batch_select/_add_button.html.erb
@@ -214,12 +213,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
214
213
  version: '0'
215
214
  required_rubygems_version: !ruby/object:Gem::Requirement
216
215
  requirements:
217
- - - ">="
216
+ - - ">"
218
217
  - !ruby/object:Gem::Version
219
- version: '0'
218
+ version: 1.3.1
220
219
  requirements: []
221
220
  rubyforge_project:
222
- rubygems_version: 2.4.5.1
221
+ rubygems_version: 2.4.3
223
222
  signing_key:
224
223
  specification_version: 4
225
224
  summary: A rails engine for managing Hydra Collections
@@ -1,8 +0,0 @@
1
- module Hydra::Collections
2
- module Relations
3
- extend ActiveSupport::Concern
4
- included do
5
- has_and_belongs_to_many :members, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasCollectionMember, class_name: "ActiveFedora::Base"
6
- end
7
- end
8
- end