active-fedora 6.8.0 → 7.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -5
  4. data/CONTRIBUTING.md +2 -0
  5. data/Gemfile +0 -2
  6. data/History.txt +2 -32
  7. data/README.md +143 -0
  8. data/Rakefile +5 -7
  9. data/active-fedora.gemspec +9 -9
  10. data/gemfiles/rails3.gemfile +11 -0
  11. data/gemfiles/rails4.gemfile +10 -0
  12. data/lib/active_fedora.rb +31 -4
  13. data/lib/active_fedora/association_relation.rb +18 -0
  14. data/lib/active_fedora/associations.rb +38 -171
  15. data/lib/active_fedora/associations/association.rb +163 -0
  16. data/lib/active_fedora/associations/association_scope.rb +39 -0
  17. data/lib/active_fedora/associations/belongs_to_association.rb +47 -25
  18. data/lib/active_fedora/associations/builder/association.rb +55 -0
  19. data/lib/active_fedora/associations/builder/belongs_to.rb +100 -0
  20. data/lib/active_fedora/associations/builder/collection_association.rb +56 -0
  21. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +30 -0
  22. data/lib/active_fedora/associations/builder/has_many.rb +63 -0
  23. data/lib/active_fedora/associations/builder/singular_association.rb +32 -0
  24. data/lib/active_fedora/associations/{association_collection.rb → collection_association.rb} +203 -53
  25. data/lib/active_fedora/associations/collection_proxy.rb +862 -0
  26. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +35 -25
  27. data/lib/active_fedora/associations/has_many_association.rb +36 -11
  28. data/lib/active_fedora/associations/singular_association.rb +62 -0
  29. data/lib/active_fedora/attributes.rb +43 -139
  30. data/lib/active_fedora/autosave_association.rb +317 -0
  31. data/lib/active_fedora/base.rb +10 -327
  32. data/lib/active_fedora/callbacks.rb +1 -3
  33. data/lib/active_fedora/content_model.rb +16 -0
  34. data/lib/active_fedora/core.rb +151 -0
  35. data/lib/active_fedora/datastream_attribute.rb +76 -0
  36. data/lib/active_fedora/datastream_hash.rb +8 -13
  37. data/lib/active_fedora/datastreams.rb +39 -26
  38. data/lib/active_fedora/digital_object.rb +2 -2
  39. data/lib/active_fedora/fedora_attributes.rb +45 -0
  40. data/lib/active_fedora/fixture_loader.rb +1 -1
  41. data/lib/active_fedora/indexing.rb +6 -1
  42. data/lib/active_fedora/model.rb +0 -17
  43. data/lib/active_fedora/nested_attributes.rb +2 -2
  44. data/lib/active_fedora/null_relation.rb +7 -0
  45. data/lib/active_fedora/om_datastream.rb +3 -4
  46. data/lib/active_fedora/persistence.rb +41 -29
  47. data/lib/active_fedora/querying.rb +2 -163
  48. data/lib/active_fedora/rdf.rb +1 -0
  49. data/lib/active_fedora/rdf/indexing.rb +67 -0
  50. data/lib/active_fedora/rdf_datastream.rb +2 -50
  51. data/lib/active_fedora/rdf_node.rb +12 -7
  52. data/lib/active_fedora/rdf_node/term_proxy.rb +30 -21
  53. data/lib/active_fedora/rdfxml_rdf_datastream.rb +1 -1
  54. data/lib/active_fedora/reflection.rb +163 -20
  55. data/lib/active_fedora/relation.rb +33 -130
  56. data/lib/active_fedora/relation/calculations.rb +19 -0
  57. data/lib/active_fedora/relation/delegation.rb +22 -0
  58. data/lib/active_fedora/relation/finder_methods.rb +247 -0
  59. data/lib/active_fedora/relation/merger.rb +22 -0
  60. data/lib/active_fedora/relation/query_methods.rb +58 -0
  61. data/lib/active_fedora/relation/spawn_methods.rb +46 -0
  62. data/lib/active_fedora/relationship_graph.rb +0 -2
  63. data/lib/active_fedora/rels_ext_datastream.rb +1 -4
  64. data/lib/active_fedora/rubydora_connection.rb +1 -1
  65. data/lib/active_fedora/scoping.rb +20 -0
  66. data/lib/active_fedora/scoping/default.rb +38 -0
  67. data/lib/active_fedora/scoping/named.rb +32 -0
  68. data/lib/active_fedora/semantic_node.rb +54 -106
  69. data/lib/active_fedora/serialization.rb +19 -0
  70. data/lib/active_fedora/sharding.rb +58 -0
  71. data/lib/active_fedora/solr_digital_object.rb +15 -5
  72. data/lib/active_fedora/solr_instance_loader.rb +1 -1
  73. data/lib/active_fedora/solr_service.rb +1 -1
  74. data/lib/active_fedora/unsaved_digital_object.rb +6 -4
  75. data/lib/active_fedora/version.rb +1 -1
  76. data/lib/tasks/active_fedora.rake +3 -0
  77. data/lib/tasks/active_fedora_dev.rake +6 -5
  78. data/spec/config_helper.rb +14 -14
  79. data/spec/integration/associations_spec.rb +168 -455
  80. data/spec/integration/attributes_spec.rb +12 -11
  81. data/spec/integration/auditable_spec.rb +11 -11
  82. data/spec/integration/autosave_association_spec.rb +25 -0
  83. data/spec/integration/base_spec.rb +163 -163
  84. data/spec/integration/belongs_to_association_spec.rb +166 -0
  85. data/spec/integration/bug_spec.rb +7 -7
  86. data/spec/integration/collection_association_spec.rb +58 -0
  87. data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
  88. data/spec/integration/datastream_collections_spec.rb +69 -69
  89. data/spec/integration/datastream_spec.rb +43 -43
  90. data/spec/integration/datastreams_spec.rb +63 -63
  91. data/spec/integration/delete_all_spec.rb +46 -39
  92. data/spec/integration/fedora_solr_sync_spec.rb +5 -5
  93. data/spec/integration/field_to_solr_name_spec.rb +34 -0
  94. data/spec/integration/full_featured_model_spec.rb +100 -101
  95. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +341 -0
  96. data/spec/integration/has_many_associations_spec.rb +172 -24
  97. data/spec/integration/json_serialization_spec.rb +31 -0
  98. data/spec/integration/load_from_solr_spec.rb +48 -0
  99. data/spec/integration/model_spec.rb +35 -40
  100. data/spec/integration/nested_attribute_spec.rb +42 -43
  101. data/spec/integration/ntriples_datastream_spec.rb +131 -113
  102. data/spec/integration/om_datastream_spec.rb +67 -67
  103. data/spec/integration/persistence_spec.rb +7 -7
  104. data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
  105. data/spec/integration/relation_delegation_spec.rb +26 -25
  106. data/spec/integration/relation_spec.rb +42 -0
  107. data/spec/integration/rels_ext_datastream_spec.rb +20 -20
  108. data/spec/integration/scoped_query_spec.rb +61 -51
  109. data/spec/integration/solr_instance_loader_spec.rb +5 -5
  110. data/spec/integration/solr_service_spec.rb +46 -46
  111. data/spec/samples/hydra-mods_article_datastream.rb +334 -334
  112. data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
  113. data/spec/samples/marpa-dc_datastream.rb +17 -17
  114. data/spec/samples/models/audio_record.rb +16 -16
  115. data/spec/samples/models/image.rb +2 -2
  116. data/spec/samples/models/mods_article.rb +5 -5
  117. data/spec/samples/models/oral_history.rb +18 -18
  118. data/spec/samples/models/seminar.rb +24 -24
  119. data/spec/samples/models/seminar_audio_file.rb +17 -17
  120. data/spec/samples/oral_history_sample_model.rb +21 -21
  121. data/spec/samples/special_thing.rb +14 -14
  122. data/spec/spec_helper.rb +11 -7
  123. data/spec/support/an_active_model.rb +2 -8
  124. data/spec/support/freeze_mocks.rb +12 -0
  125. data/spec/support/mock_fedora.rb +17 -16
  126. data/spec/unit/active_fedora_spec.rb +58 -60
  127. data/spec/unit/attributes_spec.rb +314 -0
  128. data/spec/unit/base_active_model_spec.rb +28 -27
  129. data/spec/unit/base_cma_spec.rb +5 -5
  130. data/spec/unit/base_datastream_management_spec.rb +27 -27
  131. data/spec/unit/base_extra_spec.rb +76 -48
  132. data/spec/unit/base_spec.rb +277 -348
  133. data/spec/unit/callback_spec.rb +18 -19
  134. data/spec/unit/code_configurator_spec.rb +17 -17
  135. data/spec/unit/config_spec.rb +8 -16
  136. data/spec/unit/content_model_spec.rb +79 -60
  137. data/spec/unit/datastream_collections_spec.rb +229 -229
  138. data/spec/unit/datastream_spec.rb +51 -63
  139. data/spec/unit/datastreams_spec.rb +87 -87
  140. data/spec/unit/file_configurator_spec.rb +217 -217
  141. data/spec/unit/has_and_belongs_to_many_collection_spec.rb +44 -25
  142. data/spec/unit/has_many_collection_spec.rb +26 -8
  143. data/spec/unit/inheritance_spec.rb +13 -12
  144. data/spec/unit/model_spec.rb +39 -45
  145. data/spec/unit/nom_datastream_spec.rb +15 -15
  146. data/spec/unit/ntriples_datastream_spec.rb +123 -118
  147. data/spec/unit/om_datastream_spec.rb +227 -233
  148. data/spec/unit/persistence_spec.rb +34 -15
  149. data/spec/unit/predicates_spec.rb +73 -73
  150. data/spec/unit/property_spec.rb +17 -9
  151. data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
  152. data/spec/unit/query_spec.rb +222 -198
  153. data/spec/unit/rdf_datastream_spec.rb +21 -28
  154. data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
  155. data/spec/unit/rdf_list_spec.rb +65 -64
  156. data/spec/unit/rdf_node_spec.rb +7 -7
  157. data/spec/unit/rdf_xml_writer_spec.rb +10 -10
  158. data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
  159. data/spec/unit/relationship_graph_spec.rb +51 -51
  160. data/spec/unit/rels_ext_datastream_spec.rb +68 -74
  161. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
  162. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
  163. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
  164. data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
  165. data/spec/unit/rubydora_connection_spec.rb +5 -5
  166. data/spec/unit/semantic_node_spec.rb +48 -107
  167. data/spec/unit/serializers_spec.rb +4 -4
  168. data/spec/unit/service_definitions_spec.rb +26 -26
  169. data/spec/unit/simple_datastream_spec.rb +17 -17
  170. data/spec/unit/solr_config_options_spec.rb +29 -28
  171. data/spec/unit/solr_digital_object_spec.rb +17 -25
  172. data/spec/unit/solr_service_spec.rb +95 -82
  173. data/spec/unit/unsaved_digital_object_spec.rb +24 -23
  174. data/spec/unit/validations_spec.rb +21 -21
  175. metadata +110 -159
  176. data/.rspec +0 -1
  177. data/.rubocop.yml +0 -1
  178. data/.rubocop_todo.yml +0 -938
  179. data/CONSOLE_GETTING_STARTED.textile +0 -1
  180. data/NOKOGIRI_DATASTREAMS.textile +0 -1
  181. data/README.textile +0 -116
  182. data/lib/active_fedora/associations/association_proxy.rb +0 -178
  183. data/lib/active_fedora/delegating.rb +0 -72
  184. data/lib/active_fedora/nokogiri_datastream.rb +0 -11
  185. data/spec/integration/delegating_spec.rb +0 -59
  186. data/spec/rails3_test_app/.gitignore +0 -4
  187. data/spec/rails3_test_app/.rspec +0 -1
  188. data/spec/rails3_test_app/Gemfile +0 -40
  189. data/spec/rails3_test_app/Rakefile +0 -7
  190. data/spec/rails3_test_app/app/controllers/application_controller.rb +0 -3
  191. data/spec/rails3_test_app/app/helpers/application_helper.rb +0 -2
  192. data/spec/rails3_test_app/app/views/layouts/application.html.erb +0 -14
  193. data/spec/rails3_test_app/config.ru +0 -4
  194. data/spec/rails3_test_app/config/application.rb +0 -42
  195. data/spec/rails3_test_app/config/boot.rb +0 -6
  196. data/spec/rails3_test_app/config/database.yml +0 -22
  197. data/spec/rails3_test_app/config/environment.rb +0 -5
  198. data/spec/rails3_test_app/config/environments/development.rb +0 -25
  199. data/spec/rails3_test_app/config/environments/production.rb +0 -49
  200. data/spec/rails3_test_app/config/environments/test.rb +0 -35
  201. data/spec/rails3_test_app/config/initializers/backtrace_silencers.rb +0 -7
  202. data/spec/rails3_test_app/config/initializers/inflections.rb +0 -10
  203. data/spec/rails3_test_app/config/initializers/mime_types.rb +0 -5
  204. data/spec/rails3_test_app/config/initializers/secret_token.rb +0 -7
  205. data/spec/rails3_test_app/config/initializers/session_store.rb +0 -8
  206. data/spec/rails3_test_app/config/locales/en.yml +0 -5
  207. data/spec/rails3_test_app/config/routes.rb +0 -58
  208. data/spec/rails3_test_app/db/seeds.rb +0 -7
  209. data/spec/rails3_test_app/run_tests +0 -3
  210. data/spec/rails3_test_app/script/rails +0 -6
  211. data/spec/rails3_test_app/spec/spec_helper.rb +0 -27
  212. data/spec/rails3_test_app/spec/unit/rails_3_init.rb +0 -15
  213. data/spec/unit/association_proxy_spec.rb +0 -12
  214. data/spec/unit/base_delegate_spec.rb +0 -197
  215. data/spec/unit/base_delegate_to_spec.rb +0 -73
@@ -48,7 +48,7 @@ module ActiveFedora
48
48
  def self.reify_solr_result(hit, opts = {})
49
49
  klass = class_from_solr_document(hit)
50
50
  if opts[:load_from_solr]
51
- klass.load_instance_from_solr(hit[SOLR_DOCUMENT_ID])
51
+ klass.load_instance_from_solr(hit[SOLR_DOCUMENT_ID], hit)
52
52
  else
53
53
  klass.find(hit[SOLR_DOCUMENT_ID], cast: true)
54
54
  end
@@ -26,10 +26,11 @@ module ActiveFedora
26
26
  @pid = pid
27
27
  end
28
28
 
29
- def new?
29
+ def new_record?
30
30
  true
31
31
  end
32
- alias new_record? new?
32
+
33
+ alias :new? :new_record?
33
34
 
34
35
  ### Change this into a real digital object
35
36
  def save
@@ -49,8 +50,9 @@ module ActiveFedora
49
50
  self.original_class.assign_pid(self)
50
51
  end
51
52
 
52
-
53
-
53
+ def delete
54
+ #nop
55
+ end
54
56
  end
55
57
  end
56
58
 
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "6.8.0"
2
+ VERSION = "7.0.0.pre1"
3
3
  end
@@ -1,5 +1,8 @@
1
1
  require "active-fedora"
2
2
  require "active_support" # This is just to load ActiveSupport::CoreExtensions::String::Inflections
3
+
4
+ ZIP_FILE = 'https://github.com/projecthydra/hydra-jetty/archive/v5.2.0.zip'
5
+
3
6
  namespace :repo do
4
7
 
5
8
  desc "Delete and re-import the object identified by pid"
@@ -1,10 +1,10 @@
1
1
  APP_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../")
2
2
 
3
3
  require 'jettywrapper'
4
+ JETTY_ZIP_BASENAME = 'master'
5
+ Jettywrapper.url = "https://github.com/projecthydra/hydra-jetty/archive/#{JETTY_ZIP_BASENAME}.zip"
4
6
 
5
7
  namespace :active_fedora do
6
- require 'active-fedora'
7
-
8
8
  # Use yard to build docs
9
9
  begin
10
10
  require 'yard'
@@ -14,8 +14,8 @@ namespace :active_fedora do
14
14
 
15
15
  YARD::Rake::YardocTask.new(:doc) do |yt|
16
16
  yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
17
- [ '-', File.join(project_root, 'README.textile'), File.join(project_root,'CONSOLE_GETTING_STARTED.textile'), File.join(project_root,'NOKOGIRI_DATASTREAMS.textile') ]
18
- yt.options = ['--output-dir', doc_destination, '--readme', 'README.textile']
17
+ [ '-', File.join(project_root, 'README.md')]
18
+ yt.options = ['--output-dir', doc_destination, '--readme', 'README.md']
19
19
  end
20
20
  rescue LoadError
21
21
  desc "Generate YARD Documentation"
@@ -24,10 +24,11 @@ namespace :active_fedora do
24
24
  end
25
25
  end
26
26
 
27
- require 'rspec/core/rake_task'
27
+ require 'rspec/core/rake_task'
28
28
  RSpec::Core::RakeTask.new(:rspec) do |spec|
29
29
  spec.pattern = FileList['spec/**/*_spec.rb']
30
30
  spec.pattern += FileList['spec/*_spec.rb']
31
+ spec.rspec_opts = ['--backtrace'] if ENV['CI']
31
32
  end
32
33
 
33
34
  RSpec::Core::RakeTask.new(:rcov) do |spec|
@@ -1,26 +1,26 @@
1
1
  def mock_yaml(hash, path)
2
- mock_file = double(path.split('/')[-1])
3
- allow(File).to receive(:exist?).with(path).and_return(true)
4
- allow(File).to receive(:open).with(path).and_return(mock_file)
5
- allow(YAMLAdaptor).to receive(:load).and_return(hash)
2
+ mock_file = double(path.split("/")[-1])
3
+ File.stub(:exist?).with(path).and_return(true)
4
+ File.stub(:open).with(path).and_return(mock_file)
5
+ YAMLAdaptor.stub(:load).and_return(hash)
6
6
  end
7
7
 
8
8
  def default_predicate_mapping_file
9
- File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'predicate_mappings.yml'))
9
+ File.expand_path(File.join(File.dirname(__FILE__),"..","config","predicate_mappings.yml"))
10
10
  end
11
11
 
12
- def stub_rails(opts = {})
13
- Object.const_set('Rails', Class)
14
- Rails.send(:undef_method, :env) if Rails.respond_to?(:env)
15
- Rails.send(:undef_method, :root) if Rails.respond_to?(:root)
16
- opts.each { |k, v| Rails.send(:define_method, k){ return v } }
12
+ def stub_rails(opts={})
13
+ Object.const_set("Rails",Class)
14
+ Rails.send(:undef_method,:env) if Rails.respond_to?(:env)
15
+ Rails.send(:undef_method,:root) if Rails.respond_to?(:root)
16
+ opts.each { |k,v| Rails.send(:define_method,k){ return v } }
17
17
  end
18
18
 
19
19
  def unstub_rails
20
- Object.send(:remove_const, :Rails) if defined?(Rails)
20
+ Object.send(:remove_const,:Rails) if defined?(Rails)
21
21
  end
22
-
22
+
23
23
  def setup_pretest_env
24
- ENV['RAILS_ENV'] = 'test'
25
- ENV['environment'] = 'test'
24
+ ENV['RAILS_ENV']='test'
25
+ ENV['environment']='test'
26
26
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::Base do
4
- describe 'use a URI as the property' do
4
+ describe "use a URI as the property" do
5
5
  before do
6
- class Book < ActiveFedora::Base
7
- belongs_to :author, :property => RDF::DC.creator, :class_name => 'Person'
6
+ class Book < ActiveFedora::Base
7
+ belongs_to :author, :property=>RDF::DC.creator, :class_name=>'Person'
8
8
  end
9
9
 
10
10
  class Person < ActiveFedora::Base
@@ -19,27 +19,22 @@ describe ActiveFedora::Base do
19
19
  let(:person) { Person.create}
20
20
  let(:book) { Book.new(author: person) }
21
21
 
22
- it 'should go' do
22
+ it "should go" do
23
23
  book.save
24
24
  end
25
25
 
26
26
  end
27
27
 
28
- describe 'complex example' do
28
+ describe "complex example" do
29
29
  before do
30
- class Library < ActiveFedora::Base
31
- has_many :books, :property => :has_constituent
30
+ class Library < ActiveFedora::Base
31
+ has_many :books, :property=>:has_constituent
32
32
  end
33
33
 
34
- class Book < ActiveFedora::Base
35
- belongs_to :library, :property => :has_constituent
36
- belongs_to :author, :property => :has_member, :class_name => 'Person'
37
- belongs_to :publisher, :property => :has_member
38
- has_and_belongs_to_many :topics, :property => :has_topic, :inverse_of => :is_topic_of
39
- has_and_belongs_to_many :collections, :property => :is_member_of_collection
40
- end
41
-
42
- class SpecialInheritedBook < Book
34
+ class Book < ActiveFedora::Base
35
+ belongs_to :library, :property=>:has_constituent
36
+ belongs_to :author, :property=>:has_member, :class_name=>'Person'
37
+ belongs_to :publisher, :property=>:has_member
43
38
  end
44
39
 
45
40
  class Person < ActiveFedora::Base
@@ -47,26 +42,17 @@ describe ActiveFedora::Base do
47
42
 
48
43
  class Publisher < ActiveFedora::Base
49
44
  end
50
-
51
- class Collection < ActiveFedora::Base
52
- end
53
-
54
- class Topic < ActiveFedora::Base
55
- has_and_belongs_to_many :books, :property => :is_topic_of
56
- end
57
45
  end
58
46
 
59
47
  after do
60
48
  Object.send(:remove_const, :Library)
61
49
  Object.send(:remove_const, :Book)
62
50
  Object.send(:remove_const, :Person)
63
- Object.send(:remove_const, :Collection)
64
- Object.send(:remove_const, :Topic)
65
- Object.send(:remove_const, :SpecialInheritedBook)
51
+ Object.send(:remove_const, :Publisher)
66
52
  end
67
53
 
68
- describe 'an unsaved instance' do
69
- describe 'of has_many' do
54
+ describe "an unsaved instance" do
55
+ describe "of has_many" do
70
56
  before do
71
57
  @library = Library.new()
72
58
  @book = Book.new
@@ -75,85 +61,90 @@ describe ActiveFedora::Base do
75
61
  @book2.save
76
62
  end
77
63
 
78
- it 'should build child' do
64
+ it "should build child" do
79
65
  new_book = @library.books.build({})
80
- expect(new_book).to be_new_record
81
- expect(new_book).to be_kind_of Book
82
- expect(new_book.library).to be_nil
83
- expect(@library.books).to eq([new_book])
84
- #TODO save the associated children too, requires something like ActiveRecord::AutosaveAssociation (ver 3.0.12)
85
- #@library.save
86
- #new_book.library.should == @library
66
+ new_book.should be_new_record
67
+ new_book.should be_kind_of Book
68
+ new_book.library.should be_kind_of Library
69
+ @library.books.should == [new_book]
70
+ end
71
+
72
+ it "should make a new child" do
73
+ new_book = @library.books.new
74
+ new_book.should be_new_record
75
+ new_book.should be_kind_of Book
76
+ new_book.library.should be_kind_of Library
77
+ @library.books.should == [new_book]
87
78
  end
88
79
 
89
80
  it "should not create children if the parent isn't saved" do
90
- expect {@library.books.create({})}.to raise_error ActiveFedora::RecordNotSaved, 'You cannot call create unless the parent is saved'
81
+ lambda {@library.books.create({})}.should raise_error ActiveFedora::RecordNotSaved, "You cannot call create unless the parent is saved"
91
82
  end
92
83
 
93
- it 'should create children' do
84
+ it "should create children" do
94
85
  @library.save!
95
86
  new_book = @library.books.create({})
96
- expect(new_book).not_to be_new_record
97
- expect(new_book).to be_kind_of Book
98
- expect(new_book.library).to eq(@library)
87
+ new_book.should_not be_new_record
88
+ new_book.should be_kind_of Book
89
+ new_book.library.should == @library
99
90
  end
100
91
 
101
- it 'should build parent' do
92
+ it "should build parent" do
102
93
  new_library = @book.build_library({})
103
- expect(new_library).to be_new_record
104
- expect(new_library).to be_kind_of Library
105
- expect(@book.library).to eq(new_library)
94
+ new_library.should be_new_record
95
+ new_library.should be_kind_of Library
96
+ @book.library.should == new_library
106
97
  end
107
98
 
108
- it 'should create parent' do
99
+ it "should create parent" do
109
100
  new_library = @book.create_library({})
110
- expect(new_library).not_to be_new_record
111
- expect(new_library).to be_kind_of Library
112
- expect(@book.library).to eq(new_library)
101
+ new_library.should_not be_new_record
102
+ new_library.should be_kind_of Library
103
+ @book.library.should == new_library
113
104
  end
114
105
 
115
- it 'should let you shift onto the association' do
116
- expect(@library.new_record?).to be_truthy
106
+ it "should let you shift onto the association" do
107
+ @library.new_record?.should be_true
117
108
  @library.books.size == 0
118
- expect(@library.books).to eq([])
119
- expect(@library.book_ids).to eq([])
109
+ @library.books.should == []
110
+ @library.book_ids.should ==[]
120
111
  @library.books << @book
121
- expect(@library.books).to eq([@book])
122
- expect(@library.book_ids).to eq([@book.pid])
112
+ @library.books.should == [@book]
113
+ @library.book_ids.should ==[@book.pid]
123
114
 
124
115
  end
125
116
 
126
- it 'should let you set an array of objects' do
117
+ it "should let you set an array of objects" do
127
118
  @library.books = [@book, @book2]
128
- expect(@library.books).to eq([@book, @book2])
119
+ @library.books.should == [@book, @book2]
129
120
  @library.save
130
121
 
131
122
  @library.books = [@book]
132
- expect(@library.books).to eq([@book])
133
-
123
+ @library.books.should == [@book]
124
+
134
125
  end
135
- it 'should let you set an array of object ids' do
126
+ it "should let you set an array of object ids" do
136
127
  @library.book_ids = [@book.pid, @book2.pid]
137
- expect(@library.books).to eq([@book, @book2])
128
+ @library.books.should == [@book, @book2]
138
129
  end
139
130
 
140
- it 'setter should wipe out previously saved relations' do
131
+ it "setter should wipe out previously saved relations" do
141
132
  @library.book_ids = [@book.pid, @book2.pid]
142
133
  @library.book_ids = [@book2.pid]
143
- expect(@library.books).to eq([@book2])
144
-
134
+ @library.books.should == [@book2]
135
+
145
136
  end
146
137
 
147
- it 'saving the parent should save the relationships on the children' do
138
+ it "saving the parent should save the relationships on the children" do
148
139
  @library.save
149
140
  @library.books = [@book, @book2]
150
141
  @library.save
151
142
  @library = Library.find(@library.pid)
152
- expect(@library.books).to eq([@book, @book2])
143
+ @library.books.should == [@book, @book2]
153
144
  end
154
145
 
155
146
 
156
- it 'should let you lookup an array of objects with solr' do
147
+ it "should let you lookup an array of objects with solr" do
157
148
  @library.save
158
149
  @book.library = @library
159
150
  @book2.library = @library
@@ -161,13 +152,13 @@ describe ActiveFedora::Base do
161
152
  @book2.save
162
153
 
163
154
  @library = Library.find(@library.pid)
164
- expect(@library.books).to eq([@book, @book2])
165
-
166
- solr_resp = @library.books(:response_format => :solr)
167
- expect(solr_resp.size).to eq(2)
168
- expect(solr_resp[0]['id']).to eq(@book.pid)
169
- expect(solr_resp[1]['id']).to eq(@book2.pid)
170
-
155
+ @library.books.should == [@book, @book2]
156
+
157
+ solr_resp = @library.books(:response_format=>:solr)
158
+ solr_resp.size.should == 2
159
+ solr_resp[0]['id'].should == @book.pid
160
+ solr_resp[1]['id'].should == @book2.pid
161
+
171
162
  end
172
163
 
173
164
 
@@ -178,7 +169,7 @@ describe ActiveFedora::Base do
178
169
  end
179
170
  end
180
171
 
181
- describe 'of belongs to' do
172
+ describe "of belongs to" do
182
173
  before do
183
174
  @library = Library.new()
184
175
  @library.save
@@ -188,74 +179,22 @@ describe ActiveFedora::Base do
188
179
  it "shouldn't do anything if you set a nil id" do
189
180
  @book.library_id = nil
190
181
  end
191
- it 'should be settable from the book side' do
182
+ it "should be settable from the book side" do
192
183
  @book.library_id = @library.pid
193
- expect(@book.library).to eq(@library)
194
- expect(@book.library.pid).to eq(@library.pid)
195
- @book.attributes = {:library_id => ''}
196
- expect(@book.library_id).to be_nil
184
+ @book.library.should == @library
185
+ @book.library.pid.should == @library.pid
186
+ @book.attributes= {:library_id => ""}
187
+ @book.library_id.should be_nil
197
188
  end
198
189
  after do
199
190
  @library.delete
200
191
  @book.delete
201
192
  end
202
193
  end
203
-
204
- describe 'of has_many_and_belongs_to' do
205
- before do
206
- @topic1 = Topic.create
207
- @topic2 = Topic.create
208
- @book = Book.create
209
- @special_book = SpecialInheritedBook.create
210
- end
211
- it 'habtm should set and remove relationships bidirectionally' do
212
- @book.topics << @topic1
213
- expect(@book.topics).to eq([@topic1])
214
- expect(@topic1.books).to eq([@book])
215
- expect(@topic1.reload.books).to eq([@book])
216
-
217
- @book.topics.delete(@topic1)
218
- #@topic1.books.delete(@book)
219
- expect(@book.topics).to eq([])
220
- expect(@topic1.books).to eq([])
221
- end
222
- it 'Should allow for more than 10 items' do
223
-
224
- (0..11).each do
225
- @book.topics << Topic.create
226
- end
227
- @book.save
228
- expect(@book.topics.count).to eq(12)
229
- book2 = Book.find(@book.pid)
230
- expect(book2.topics.count).to eq(12)
231
- end
232
-
233
- it 'Should find inherited objects along with base objects' do
234
- @book.topics << @topic1
235
- @special_book.topics << @topic1
236
- expect(@topic1.books).to eq([@book, @special_book])
237
- expect(@topic1.reload.books).to eq([@book, @special_book])
238
- end
239
-
240
- it 'Should cast found books to the correct cmodel' do
241
- @topic1.books[0].class == Book
242
- @topic1.books[1].class == SpecialInheritedBook
243
- end
244
-
245
- after do
246
- @topic1.delete
247
- @topic2.delete
248
- @book.delete
249
- @special_book.delete
250
- end
251
- end
252
194
  end
253
195
 
254
-
255
-
256
-
257
- describe 'a saved instance' do
258
- describe 'of belongs_to' do
196
+ describe "a saved instance" do
197
+ describe "of belongs_to" do
259
198
  before do
260
199
  @library = Library.new()
261
200
  @library.save()
@@ -266,86 +205,61 @@ describe ActiveFedora::Base do
266
205
  @publisher = Publisher.new
267
206
  @publisher.save
268
207
  end
269
- it 'should have many books once it has been saved' do
208
+ it "should have many books once it has been saved" do
270
209
  @library.books << @book
271
210
 
272
- expect(@book.library.pid).to eq(@library.pid)
211
+ @book.library.pid.should == @library.pid
273
212
  @library.books.reload
274
- expect(@library.books).to eq([@book])
213
+ @library.books.should == [@book]
275
214
 
276
215
  @library2 = Library.find(@library.pid)
277
- expect(@library2.books).to eq([@book])
216
+ @library2.books.should == [@book]
278
217
  end
279
218
 
280
- it 'should have a count once it has been saved' do
281
- @library.books << @book << Book.create
219
+ it "should have a count once it has been saved" do
220
+ @library.books << @book << Book.create
282
221
  @library.save
283
222
 
284
- # @book.library.pid.should == @library.pid
285
- # @library.books.reload
286
- # @library.books.should == [@book]
287
-
288
223
  @library2 = Library.find(@library.pid)
289
- expect(@library2.books.size).to eq(2)
224
+ @library2.books.size.should == 2
290
225
  end
291
226
 
292
- it 'should respect the :class_name parameter' do
227
+ it "should respect the :class_name parameter" do
293
228
  @book.author = @person
294
229
  @book.save
295
- expect(Book.find(@book.id).author_id).to eq(@person.pid)
296
- expect(Book.find(@book.id).author.send(:find_target)).to be_kind_of Person
230
+ Book.find(@book.id).author_id.should == @person.pid
231
+ Book.find(@book.id).author.should be_kind_of Person
297
232
  end
298
233
 
299
- it 'should respect multiple associations that share the same :property and respect associated class' do
234
+ it "should respect multiple associations that share the same :property and respect associated class" do
300
235
  @book.author = @person
301
236
  @book.publisher = @publisher
302
237
  @book.save
238
+
239
+ Book.find(@book.id).publisher_id.should == @publisher.pid
240
+ Book.find(@book.id).publisher.should be_kind_of Publisher
303
241
 
304
- expect(Book.find(@book.id).publisher_id).to eq(@publisher.pid)
305
- expect(Book.find(@book.id).publisher.send(:find_target)).to be_kind_of Publisher
306
-
307
- expect(Book.find(@book.id).author_id).to eq(@person.pid)
308
- expect(Book.find(@book.id).author.send(:find_target)).to be_kind_of Person
242
+ Book.find(@book.id).author_id.should == @person.pid
243
+ Book.find(@book.id).author.should be_kind_of Person
309
244
  end
310
245
 
311
- describe 'when changing the belonger' do
246
+ describe "when changing the belonger" do
312
247
  before do
313
248
  @book.library = @library
314
249
  @book.save
315
250
  @library2 = Library.create
316
251
  end
317
- it 'should replace an existing instance' do
318
- expect(@book.library_id).to eq(@library.id)
252
+ it "should replace an existing instance" do
253
+ @book.library_id.should == @library.id
319
254
  @book.library = @library2
320
255
  @book.save
321
- expect(Book.find(@book.id).library_id).to eq(@library2.id)
256
+ Book.find(@book.id).library_id.should == @library2.id
322
257
  end
323
258
  after do
324
259
  @library2.delete
325
260
  end
326
261
  end
327
262
 
328
- describe 'when dealing with inherited objects' do
329
- before do
330
- @library2 = Library.create
331
- @special_book = SpecialInheritedBook.create
332
-
333
- @book.library = @library2
334
- @book.save
335
- @special_book.library = @library2
336
- @special_book.save
337
- end
338
-
339
- it 'should cast to the most specific class for the association' do
340
- @library2.books[0].class == Book
341
- @library2.books[1].class == SpecialInheritedBook
342
- end
343
-
344
- after do
345
- @library2.delete
346
- @special_book.delete
347
- end
348
- end
349
263
 
350
264
  after do
351
265
  @library.delete
@@ -354,65 +268,9 @@ describe ActiveFedora::Base do
354
268
  @publisher.delete
355
269
  end
356
270
  end
357
- describe 'of has_many_and_belongs_to' do
358
- before do
359
- @book = Book.create
360
- end
361
- after do
362
- @book.delete
363
- end
364
- describe 'when invese is specified' do
365
- before do
366
- @topic1 = Topic.create
367
- @topic2 = Topic.create
368
- end
369
- it 'should set relationships bidirectionally' do
370
- @book.topics << @topic1
371
- expect(@book.topics).to eq([@topic1])
372
- expect(@book.relationships(:has_topic)).to eq([@topic1.internal_uri])
373
- expect(@topic1.relationships(:has_topic)).to eq([])
374
- expect(@topic1.relationships(:is_topic_of)).to eq([@book.internal_uri])
375
- expect(Topic.find(@topic1.pid).books).to eq([@book]) #Can't have saved it because @book isn't saved yet.
376
- end
377
- it 'should save new child objects' do
378
- @book.topics << Topic.new
379
- expect(@book.topics.first.pid).not_to be_nil
380
- end
381
- it 'should clear out the old associtions' do
382
- @book.topics = [@topic1]
383
- @book.topics = [@topic2]
384
- expect(@book.topic_ids).to eq([@topic2.pid])
385
- end
386
- after do
387
- @topic1.delete
388
- @topic2.delete
389
- end
390
- end
391
- describe 'when invese is not specified' do
392
- before do
393
- @c = Collection.create
394
- @book.collections << @c
395
- @book.save
396
- end
397
- after do
398
- @c.delete
399
- end
400
- it 'should have a collection' do
401
- expect(@book.relationships(:is_member_of_collection)).to eq([@c.internal_uri])
402
- expect(@book.collections).to eq([@c])
403
- end
404
- it 'habtm should not set foreign relationships if :inverse_of is not specified' do
405
- expect(@c.relationships(:is_member_of_collection)).to eq([])
406
- end
407
- it 'should load the collections' do
408
- reloaded = Book.find(@book.pid)
409
- expect(reloaded.collections).to eq([@c])
410
- end
411
- end
412
- end
413
271
  end
414
272
 
415
- describe 'setting belongs_to' do
273
+ describe "setting belongs_to" do
416
274
  before do
417
275
  @library = Library.new()
418
276
  @library.save()
@@ -422,51 +280,51 @@ describe ActiveFedora::Base do
422
280
  @publisher = Publisher.new
423
281
  @publisher.save
424
282
  end
425
- it 'should set the association' do
283
+ it "should set the association" do
426
284
  @book.library = @library
427
- expect(@book.library.pid).to eq(@library.pid)
285
+ @book.library.pid.should == @library.pid
428
286
  @book.save
429
287
 
430
288
 
431
- expect(Book.find(@book.pid).library.pid).to eq(@library.pid)
432
-
289
+ Book.find(@book.pid).library.pid.should == @library.pid
290
+
433
291
  end
434
- it 'should clear the association' do
292
+ it "should clear the association" do
435
293
  @book.library = @library
436
294
  @book.library = nil
437
295
  @book.save
438
296
 
439
- expect(Book.find(@book.pid).library).to be_nil
440
-
297
+ Book.find(@book.pid).library.should be_nil
298
+
441
299
  end
442
300
 
443
- it 'should replace the association' do
301
+ it "should replace the association" do
444
302
  @library2 = Library.new
445
303
  @library2.save
446
304
  @book.library = @library
447
305
  @book.save
448
306
  @book.library = @library2
449
307
  @book.save
450
- expect(Book.find(@book.pid).library.pid).to eq(@library2.pid)
308
+ Book.find(@book.pid).library.pid.should == @library2.pid
451
309
 
452
310
  end
453
311
 
454
- it 'should only replace the matching class association' do
312
+ it "should only replace the matching class association" do
455
313
  @publisher2 = Publisher.new
456
314
  @publisher2.save
457
315
 
458
316
  @book.publisher = @publisher
459
- @book.author = @author
460
- @book.save
317
+ @book.author = @author
318
+ @book.save
461
319
 
462
320
  @book.publisher = @publisher2
463
321
  @book.save
464
322
 
465
- expect(Book.find(@book.pid).publisher.pid).to eq(@publisher2.pid)
466
- expect(Book.find(@book.pid).author.pid).to eq(@author.pid)
323
+ Book.find(@book.pid).publisher.pid.should == @publisher2.pid
324
+ Book.find(@book.pid).author.pid.should == @author.pid
467
325
  end
468
326
 
469
- it 'should only clear the matching class association' do
327
+ it "should only clear the matching class association" do
470
328
  @book.publisher = @publisher
471
329
  @book.author = @author
472
330
  @book.save
@@ -474,16 +332,16 @@ describe ActiveFedora::Base do
474
332
  @book.author = nil
475
333
  @book.save
476
334
 
477
- expect(Book.find(@book.pid).author).to be_nil
478
- expect(Book.find(@book.pid).publisher.pid).to eq(@publisher.pid)
335
+ Book.find(@book.pid).author.should be_nil
336
+ Book.find(@book.pid).publisher.pid.should == @publisher.pid
479
337
  end
480
338
 
481
- it 'should be able to be set by id' do
339
+ it "should be able to be set by id" do
482
340
  @book.library_id = @library.pid
483
- expect(@book.library_id).to eq(@library.pid)
484
- expect(@book.library.pid).to eq(@library.pid)
341
+ @book.library_id.should == @library.pid
342
+ @book.library.pid.should == @library.pid
485
343
  @book.save
486
- expect(Book.find(@book.pid).library_id).to eq(@library.pid)
344
+ Book.find(@book.pid).library_id.should == @library.pid
487
345
  end
488
346
 
489
347
  after do
@@ -497,48 +355,22 @@ describe ActiveFedora::Base do
497
355
  end
498
356
  end
499
357
 
500
- describe 'belongs_to when class_name is ActiveFedora::Base' do
501
- before :all do
502
- class Textbook < ActiveFedora::Base
503
- belongs_to :container, :property => :is_part_of, :class_name => 'ActiveFedora::Base'
504
- end
505
- class Shelf < ActiveFedora::Base; end
506
- end
507
-
508
- after :all do
509
- Object.send(:remove_const, :Textbook)
510
- Object.send(:remove_const, :Shelf)
511
- end
512
-
513
- after do
514
- shelf.destroy
515
- end
516
-
517
- let(:shelf) { Shelf.create}
518
- subject { Textbook.new }
519
-
520
- it 'Should not raise a deprecation message' do
521
- expect(Deprecation).not_to receive(:warn) # a deprecation in 6.6.0 that's going away in 7.0.0
522
- subject.container_id = shelf.id
523
- end
524
- end
525
-
526
- describe 'single direction habtm' do
358
+ describe "single direction habtm" do
527
359
  before :all do
528
360
  class Course < ActiveFedora::Base
529
- has_and_belongs_to_many :textbooks, :property => :is_part_of
361
+ has_and_belongs_to_many :textbooks, :property=>:is_part_of
530
362
  end
531
363
  class Textbook < ActiveFedora::Base
532
- has_many :courses, :property => :is_part_of
364
+ has_many :courses, :property=>:is_part_of
533
365
  end
534
-
366
+
535
367
  end
536
368
  after :all do
537
369
  Object.send(:remove_const, :Course)
538
370
  Object.send(:remove_const, :Textbook)
539
371
  end
540
372
 
541
- describe 'with a parent that has two children' do
373
+ describe "with a parent that has two children" do
542
374
  before do
543
375
  @course = Course.create
544
376
  @t1 = Textbook.create()
@@ -547,46 +379,46 @@ describe ActiveFedora::Base do
547
379
  @course.save
548
380
  end
549
381
 
550
- it 'should load the association stored in the parent' do
382
+ it "should load the association stored in the parent" do
551
383
  @reloaded_course = Course.find(@course.pid)
552
- expect(@reloaded_course.textbooks).to eq([@t1, @t2])
384
+ @reloaded_course.textbooks.should == [@t1, @t2]
553
385
  end
554
386
 
555
- it 'should allow a parent to be deleted from the has_many association' do
387
+ it "should allow a parent to be deleted from the has_many association" do
556
388
  @reloaded_course = Course.find(@course.pid)
557
389
  @t1.courses.delete(@reloaded_course)
558
390
  @reloaded_course.save
559
391
 
560
392
  @reloaded_course = Course.find(@course.pid)
561
- expect(@reloaded_course.textbooks).to eq([@t2])
393
+ @reloaded_course.textbooks.should == [@t2]
562
394
  end
563
395
 
564
- it 'should allow replacing the children' do
396
+ it "should allow replacing the children" do
565
397
  @t3 = Textbook.create()
566
398
  @t4 = Textbook.create()
567
399
  @course.textbooks = [@t3, @t4]
568
400
  @course.save
569
401
 
570
- expect(@course.reload.textbooks).to eq([@t3, @t4])
402
+ @course.reload.textbooks.should == [@t3, @t4]
571
403
  end
572
404
 
573
- it 'should allow a child to be deleted from the has_and_belongs_to_many association' do
405
+ it "should allow a child to be deleted from the has_and_belongs_to_many association" do
574
406
  @reloaded_course = Course.find(@course.pid)
575
407
  @reloaded_course.textbooks.delete(@t1)
576
408
  @reloaded_course.save
577
409
  @t1.save
578
410
 
579
411
  @reloaded_course = Course.find(@course.pid)
580
- expect(@reloaded_course.textbooks).to eq([@t2])
412
+ @reloaded_course.textbooks.should == [@t2]
581
413
  end
582
414
  end
583
415
  end
584
416
 
585
- describe 'association hooks' do
586
- describe 'for habtm' do
417
+ describe "association hooks" do
418
+ describe "for habtm" do
587
419
  before :all do
588
420
  class LibraryBook < ActiveFedora::Base
589
- has_and_belongs_to_many :pages, :property => :is_part_of, after_remove: :after_hook, before_remove: :before_hook
421
+ has_and_belongs_to_many :pages, :property=>:is_part_of, after_remove: :after_hook, before_remove: :before_hook
590
422
 
591
423
  def before_hook(m)
592
424
  say_hi(m)
@@ -601,16 +433,16 @@ describe ActiveFedora::Base do
601
433
 
602
434
  end
603
435
  class Page < ActiveFedora::Base
604
- has_many :library_books, :property => :is_part_of
436
+ has_many :library_books, :property=>:is_part_of
605
437
  end
606
-
438
+
607
439
  end
608
440
  after :all do
609
441
  Object.send(:remove_const, :LibraryBook)
610
442
  Object.send(:remove_const, :Page)
611
443
  end
612
444
 
613
- describe 'removing association' do
445
+ describe "removing association" do
614
446
  subject {LibraryBook.create}
615
447
  before do
616
448
  @p1 = Page.create
@@ -618,74 +450,43 @@ describe ActiveFedora::Base do
618
450
  subject.pages << @p1 << @p2
619
451
  subject.save!
620
452
  end
621
- it 'should save between the before and after hooks' do
622
- expect(subject).to receive(:say_hi).with(@p2).twice
453
+ it "should save between the before and after hooks" do
454
+ subject.should_receive(:say_hi).with(@p2).twice
623
455
  subject.pages.delete(@p2)
624
456
  end
625
457
  end
626
458
  end
627
- describe 'for has_many' do
459
+ describe "for has_many" do
628
460
  before :all do
629
461
  class LibraryBook < ActiveFedora::Base
630
- has_many :pages, :property => :is_part_of, after_remove: :say_hi
462
+ has_many :pages, :property=>:is_part_of, after_remove: :say_hi
631
463
 
632
464
  end
633
465
  class Page < ActiveFedora::Base
634
- belongs_to :library_book, :property => :is_part_of
466
+ belongs_to :library_book, :property=>:is_part_of
635
467
  end
636
-
468
+
637
469
  end
638
470
  after :all do
639
471
  Object.send(:remove_const, :LibraryBook)
640
472
  Object.send(:remove_const, :Page)
641
473
  end
642
474
 
643
- describe 'removing association' do
475
+ describe "removing association" do
644
476
  subject {LibraryBook.new}
645
477
  before do
646
478
  @p1 = subject.pages.build
647
479
  @p2 = subject.pages.build
648
480
  end
649
- it 'should run the hooks' do
650
- expect(subject).to receive(:say_hi).with(@p2)
481
+ it "should run the hooks" do
482
+ subject.should_receive(:say_hi).with(@p2)
651
483
  subject.pages.delete(@p2)
652
484
  end
653
485
  end
654
486
  end
655
487
  end
656
488
 
657
-
658
- describe 'when a object is deleted' do
659
- before (:all) do
660
- class MasterFile < ActiveFedora::Base
661
- belongs_to :media_object, :property => :is_part_of
662
- end
663
- class MediaObject < ActiveFedora::Base
664
- has_many :parts, :class_name => 'MasterFile', :property => :is_part_of
665
- end
666
- end
667
-
668
- before :each do
669
- @master = MasterFile.create
670
- @media = MediaObject.create
671
- @master.media_object = @media
672
- @master.save
673
- @master.reload
674
- end
675
-
676
- after :all do
677
- Object.send(:remove_const, :MasterFile)
678
- Object.send(:remove_const, :MediaObject)
679
- end
680
-
681
- it 'should also remove the relationships that point at that object' do
682
- @media.delete
683
- @master = MasterFile.find(@master.pid)
684
- expect(@master.relationships(:is_part_of)).to eq([])
685
- end
686
- end
687
-
688
- describe 'has_many' do
489
+ describe "has_many" do
689
490
  describe "when an object doesn't have a property, and the class_name is predictable" do
690
491
  before (:all) do
691
492
  class Bauble < ActiveFedora::Base
@@ -700,8 +501,8 @@ describe ActiveFedora::Base do
700
501
  Object.send(:remove_const, :MediaObject)
701
502
  end
702
503
 
703
- it 'it should find the predicate' do
704
- expect(MediaObject.new.baubles.send(:find_predicate)).to eq(:is_part_of)
504
+ it "it should find the predicate" do
505
+ MediaObject.new.association(:baubles).send(:find_predicate).should == :is_part_of
705
506
  end
706
507
  end
707
508
 
@@ -711,7 +512,7 @@ describe ActiveFedora::Base do
711
512
  belongs_to :media_object, property: :is_part_of
712
513
  end
713
514
  class MediaObject < ActiveFedora::Base
714
- has_many :parts, :class_name => 'MasterFile'
515
+ has_many :parts, :class_name=>'MasterFile'
715
516
  end
716
517
  end
717
518
  after :all do
@@ -719,12 +520,12 @@ describe ActiveFedora::Base do
719
520
  Object.send(:remove_const, :MediaObject)
720
521
  end
721
522
 
722
- it 'it should find the predicate' do
723
- expect(MediaObject.new.parts.send(:find_predicate)).to eq(:is_part_of)
523
+ it "it should find the predicate" do
524
+ MediaObject.new.association(:parts).send(:find_predicate).should == :is_part_of
724
525
  end
725
526
  end
726
527
 
727
- describe 'an object has an explicity property' do
528
+ describe "an object has an explicity property" do
728
529
  before (:all) do
729
530
  class Bauble < ActiveFedora::Base
730
531
  belongs_to :media_object, property: :is_part_of
@@ -738,8 +539,8 @@ describe ActiveFedora::Base do
738
539
  Object.send(:remove_const, :MediaObject)
739
540
  end
740
541
 
741
- it 'it should find the predicate' do
742
- expect(MediaObject.new.baubles.send(:find_predicate)).to eq(:has_baubles)
542
+ it "it should find the predicate" do
543
+ MediaObject.new.association(:baubles).send(:find_predicate).should == :has_baubles
743
544
  end
744
545
  end
745
546
  describe "an object doesn't have a property" do
@@ -756,14 +557,14 @@ describe ActiveFedora::Base do
756
557
  Object.send(:remove_const, :MediaObject)
757
558
  end
758
559
 
759
- it 'it should find the predicate' do
760
- expect { MediaObject.new.shoes.send(:find_predicate) }.to raise_error RuntimeError, 'No :property attribute was set or could be inferred for has_many :shoes on MediaObject'
560
+ it "it should find the predicate" do
561
+ expect { MediaObject.new.shoes.send(:find_predicate) }.to raise_error RuntimeError, "No :property attribute was set or could be inferred for has_many :shoes on MediaObject"
761
562
  end
762
563
  end
763
564
  end
764
565
 
765
- describe 'casting when the class name is ActiveFedora::Base' do
766
- describe 'for habtm' do
566
+ describe "casting when the class name is ActiveFedora::Base" do
567
+ describe "for habtm" do
767
568
  before :all do
768
569
  class Novel < ActiveFedora::Base
769
570
  has_and_belongs_to_many :contents, property: :is_part_of, class_name: 'ActiveFedora::Base'
@@ -777,7 +578,7 @@ describe ActiveFedora::Base do
777
578
  class Image < ActiveFedora::Base
778
579
  has_many :books, property: :is_part_of, class_name: 'ActiveFedora::Base'
779
580
  end
780
-
581
+
781
582
  end
782
583
  after :all do
783
584
  Object.send(:remove_const, :Novel)
@@ -786,7 +587,7 @@ describe ActiveFedora::Base do
786
587
  Object.send(:remove_const, :Image)
787
588
  end
788
589
 
789
- describe 'saving between the before and after hooks' do
590
+ describe "saving between the before and after hooks" do
790
591
  let(:text1) { Text.create}
791
592
  let(:image1) { Image.create}
792
593
  let(:text2) { Text.create}
@@ -794,114 +595,26 @@ describe ActiveFedora::Base do
794
595
  let(:book1) { TextBook.create}
795
596
  let(:book2) { Novel.create}
796
597
 
797
- it 'should work when added via the has_and_belongs_to_many' do
598
+ it "should work when added via the has_and_belongs_to_many" do
798
599
  book1.contents = [text1, image1]
799
600
  book1.save!
800
601
  book2.contents = [text2, image2]
801
602
  book2.save!
802
603
 
803
- expect(book1.reload.contents).to include(text1, image1)
804
- expect(text1.reload.books).to eq([book1])
805
- expect(image1.reload.books).to eq([book1])
604
+ book1.reload.contents.should include(text1, image1)
605
+ text1.reload.books.should == [book1]
606
+ image1.reload.books.should == [book1]
806
607
 
807
- expect(book2.reload.contents).to include(text2, image2)
808
- expect(text2.reload.books).to eq([book2])
809
- expect(image2.reload.books).to eq([book2])
608
+ book2.reload.contents.should include(text2, image2)
609
+ text2.reload.books.should == [book2]
610
+ image2.reload.books.should == [book2]
810
611
  end
811
612
 
812
- it 'should work when added via the has_many' do
613
+ it "should work when added via the has_many" do
813
614
  text2.books << book2
814
615
  book2.save
815
- expect(book2.reload.contents).to eq([text2])
816
- expect(text2.reload.books).to eq([book2])
817
- end
818
- end
819
- end
820
- end
821
-
822
- describe 'casting inheritance additional test cases' do
823
- describe 'for habtm' do
824
- before :all do
825
- class SimpleObject < ActiveFedora::Base
826
- belongs_to :simple_collection, property: :is_part_of, class_name: 'SimpleCollection'
827
- belongs_to :complex_collection, property: :is_part_of, class_name: 'ComplexCollection'
828
- end
829
-
830
- class ComplexObject < SimpleObject
831
- end
832
-
833
- class SimpleCollection < ActiveFedora::Base
834
- has_many :objects, property: :is_part_of, class_name: 'SimpleObject'
835
- has_many :complex_objects, property: :is_part_of, class_name: 'ComplexObject'
836
- end
837
-
838
- class ComplexCollection < SimpleCollection
839
- end
840
-
841
- end
842
- after :all do
843
- Object.send(:remove_const, :SimpleObject)
844
- Object.send(:remove_const, :ComplexObject)
845
- Object.send(:remove_const, :SimpleCollection)
846
- Object.send(:remove_const, :ComplexCollection)
847
- end
848
-
849
- describe 'saving between the before and after hooks' do
850
- before do
851
- @simple_collection = SimpleCollection.create
852
- @complex_collection = ComplexCollection.create
853
-
854
- @simple_object = SimpleObject.create
855
- @simple_object_second = SimpleObject.create
856
- @complex_object = ComplexObject.create
857
-
858
- #Need to add the simpler cmodel here as currently inheritance support is read-only.
859
- #See ActiveFedora pull request 207 on how to do this programmatically.
860
- @complex_object.add_relationship(:has_model, @complex_object.class.superclass.to_class_uri)
861
-
862
- @simple_collection.objects = [@simple_object, @simple_object_second, @complex_object]
863
- @simple_collection.save!
864
- @complex_collection.objects = [@simple_object, @complex_object]
865
- @complex_collection.save!
866
- @complex_object.save!
867
- @simple_object.save!
868
- @simple_object_second.save!
869
- end
870
-
871
-
872
- it 'casted association methods should work and return the most complex class' do
873
- expect(@complex_object.simple_collection).to be_instance_of SimpleCollection
874
- expect(@complex_object.complex_collection).to be_instance_of ComplexCollection
875
-
876
- expect(@simple_object.simple_collection).to be_instance_of SimpleCollection
877
- expect(@simple_object.complex_collection).to be_instance_of ComplexCollection
878
- expect(@simple_object_second.simple_collection).to be_instance_of SimpleCollection
879
- expect(@simple_object_second.complex_collection).to be_nil
880
-
881
- expect(@complex_collection.objects[0]).to be_instance_of SimpleObject
882
- expect(@complex_collection.objects[1]).to be_instance_of ComplexObject
883
-
884
- expect(@simple_collection.objects[0]).to be_instance_of SimpleObject
885
- expect(@simple_collection.objects[1]).to be_instance_of SimpleObject
886
- expect(@simple_collection.objects[2]).to be_instance_of ComplexObject
887
-
888
- end
889
-
890
- it 'specified ending relationships should ignore classes not specified' do
891
- expect(@complex_collection.complex_objects.length).to eq(1)
892
- expect(@complex_collection.complex_objects[0]).to be_instance_of ComplexObject
893
- expect(@complex_collection.complex_objects[1]).to be_nil
894
-
895
- expect(@simple_collection.complex_objects.length).to eq(1)
896
- expect(@simple_collection.complex_objects[0]).to be_instance_of ComplexObject
897
- expect(@simple_collection.complex_objects[1]).to be_nil
898
-
899
- end
900
-
901
- after do
902
- @simple_object.delete
903
- @simple_object_second.delete
904
- @complex_object.delete
616
+ book2.reload.contents.should == [text2]
617
+ text2.reload.books.should == [book2]
905
618
  end
906
619
  end
907
620
  end