active-fedora 2.3.8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/.rvmrc +1 -1
  2. data/Gemfile.lock +16 -10
  3. data/History.txt +4 -5
  4. data/README.textile +1 -1
  5. data/active-fedora.gemspec +2 -2
  6. data/lib/active_fedora.rb +36 -19
  7. data/lib/active_fedora/associations.rb +157 -0
  8. data/lib/active_fedora/associations/association_collection.rb +180 -0
  9. data/lib/active_fedora/associations/association_proxy.rb +177 -0
  10. data/lib/active_fedora/associations/belongs_to_association.rb +36 -0
  11. data/lib/active_fedora/associations/has_many_association.rb +52 -0
  12. data/lib/active_fedora/attribute_methods.rb +8 -0
  13. data/lib/active_fedora/base.rb +76 -80
  14. data/lib/active_fedora/datastream.rb +0 -1
  15. data/lib/active_fedora/delegating.rb +53 -0
  16. data/lib/active_fedora/model.rb +4 -2
  17. data/lib/active_fedora/nested_attributes.rb +153 -0
  18. data/lib/active_fedora/nokogiri_datastream.rb +17 -18
  19. data/lib/active_fedora/reflection.rb +140 -0
  20. data/lib/active_fedora/relationships_helper.rb +10 -5
  21. data/lib/active_fedora/semantic_node.rb +146 -57
  22. data/lib/active_fedora/solr_service.rb +0 -7
  23. data/lib/active_fedora/version.rb +1 -1
  24. data/lib/fedora/connection.rb +75 -111
  25. data/lib/fedora/repository.rb +14 -28
  26. data/lib/ruby-fedora.rb +1 -1
  27. data/spec/integration/associations_spec.rb +139 -0
  28. data/spec/integration/nested_attribute_spec.rb +40 -0
  29. data/spec/integration/repository_spec.rb +9 -14
  30. data/spec/integration/semantic_node_spec.rb +2 -0
  31. data/spec/spec_helper.rb +1 -3
  32. data/spec/unit/active_fedora_spec.rb +2 -1
  33. data/spec/unit/association_proxy_spec.rb +13 -0
  34. data/spec/unit/base_active_model_spec.rb +61 -0
  35. data/spec/unit/base_delegate_spec.rb +59 -0
  36. data/spec/unit/base_spec.rb +45 -58
  37. data/spec/unit/connection_spec.rb +21 -21
  38. data/spec/unit/datastream_spec.rb +0 -11
  39. data/spec/unit/has_many_collection_spec.rb +27 -0
  40. data/spec/unit/model_spec.rb +1 -1
  41. data/spec/unit/nokogiri_datastream_spec.rb +3 -29
  42. data/spec/unit/repository_spec.rb +2 -2
  43. data/spec/unit/semantic_node_spec.rb +2 -0
  44. data/spec/unit/solr_service_spec.rb +0 -7
  45. metadata +36 -15
  46. data/lib/active_fedora/active_fedora_configuration_exception.rb +0 -2
  47. data/lib/util/class_level_inheritable_attributes.rb +0 -23
@@ -2,24 +2,24 @@ require File.join( File.dirname(__FILE__), "../spec_helper" )
2
2
 
3
3
  require 'active_resource'
4
4
  require 'fedora/repository'
5
- ### Removed by Justin 2011-9-23
6
- # describe Fedora::Connection do
7
- # it "should be creatable w/ a surrogate id" do
8
- # c = Fedora::Connection.new('http://127.0.0.1/fedora', 'fubar', 'bob')
9
- # c.site.to_s.should == "http://127.0.0.1/fedora"
10
- # c.format.should == 'fubar'
11
- # c.surrogate.should == 'bob'
12
- # end
13
- # it "should set a from header if surrogate defined." do
14
- # c = Fedora::Connection.new('http://127.0.0.1/fedora', ActiveResource::Formats[:xml], 'bob')
15
- # h = Hash.new
16
- # r= c.send(:build_request_headers,h)
17
- # r['From'].should == 'bob'
18
- # end
19
- # it "should not set a from header if surrogate undefined." do
20
- # c = Fedora::Connection.new('http://127.0.0.1/fedora' )
21
- # h = Hash.new
22
- # r= c.send(:build_request_headers,h)
23
- # r['From'].should be_nil
24
- # end
25
- # end
5
+
6
+ describe Fedora::Connection do
7
+ it "should be creatable w/ a surrogate id" do
8
+ c = Fedora::Connection.new('http://127.0.0.1/fedora', 'fubar', 'bob')
9
+ c.site.to_s.should == "http://127.0.0.1/fedora"
10
+ c.format.should == 'fubar'
11
+ c.surrogate.should == 'bob'
12
+ end
13
+ it "should set a from header if surrogate defined." do
14
+ c = Fedora::Connection.new('http://127.0.0.1/fedora', ActiveResource::Formats[:xml], 'bob')
15
+ h = Hash.new
16
+ r= c.send(:build_request_headers,h)
17
+ r['From'].should == 'bob'
18
+ end
19
+ it "should not set a from header if surrogate undefined." do
20
+ c = Fedora::Connection.new('http://127.0.0.1/fedora' )
21
+ h = Hash.new
22
+ r= c.send(:build_request_headers,h)
23
+ r['From'].should be_nil
24
+ end
25
+ end
@@ -60,17 +60,6 @@ describe ActiveFedora::Datastream do
60
60
  end
61
61
  end
62
62
 
63
- describe '.content=' do
64
- it "should update the content and ng_xml, marking the datastream as dirty" do
65
- sample_xml = "<foo><xmlelement/></foo>"
66
- @test_datastream.should_not be_dirty
67
- @test_datastream.blob.should_not be_equivalent_to(sample_xml)
68
- @test_datastream.content = sample_xml
69
- @test_datastream.should be_dirty
70
- @test_datastream.blob.should be_equivalent_to(sample_xml)
71
- end
72
- end
73
-
74
63
  describe ".dirty?" do
75
64
  it "should return the value of the @dirty attribute" do
76
65
  @test_datastream.dirty.should equal(@test_datastream.dirty?)
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Associations::HasManyAssociation do
4
+ it "should be able to replace the collection" do
5
+ @owner = stub(:new_record? => false)
6
+ @reflection = stub(:klass => Mocha::Mock, :options=>{:property=>'predicate'})
7
+ #ac = ActiveFedora::Associations::AssociationCollection.new(@owner, @reflection)
8
+ ac = ActiveFedora::Associations::HasManyAssociation.new(@owner, @reflection)
9
+ @target = [stub(:new_record? => false, :remove_relationship=>true), stub(:new_record? => false, :remove_relationship=>true), stub(:new_record? => false, :remove_relationship=>true)]
10
+ ac.target = @target
11
+
12
+ @expected1 = stub(:new_record? => false, :add_relationship=>true, :save=>true)
13
+ @expected2 = stub(:new_record? => false, :add_relationship=>true, :save=>true)
14
+ ac.replace([@expected1, @expected2])
15
+ ac.target.should == [@expected1, @expected2]
16
+
17
+ end
18
+
19
+ it "should build" do
20
+ class Foo; end
21
+ @owner = stub(:new_record? => false)
22
+ @assoc = ActiveFedora::Associations::HasManyAssociation.new(@owner, @reflection)
23
+ @assoc.should respond_to :build
24
+
25
+ end
26
+
27
+ end
@@ -103,7 +103,7 @@ describe ActiveFedora::Model do
103
103
  mock_solr = mock("SolrConnection")
104
104
  mock_result = mock("MockResult")
105
105
  mock_result.expects(:hits).returns([{"id" => "changeme:30"}, {"id" => "changeme:22"}])
106
- mock_solr.expects(:query).with('active_fedora_model_s:SpecModel\:\:Basic', :rows=>1001).returns(mock_result)
106
+ mock_solr.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel\:\:Basic', :rows=>1001).returns(mock_result)
107
107
  ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
108
108
  Fedora::Repository.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("Fake Object1")
109
109
  Fedora::Repository.instance.expects(:find_model).with("changeme:22", SpecModel::Basic).returns("Fake Object2")
@@ -10,7 +10,7 @@ describe ActiveFedora::NokogiriDatastream do
10
10
  :empty_field => {:values => {}}
11
11
  }
12
12
  @sample_xml = XmlSimple.xml_in("<fields><coverage>coverage1</coverage><coverage>coverage2</coverage><creation_date>fake-date</creation_date><mydate>fake-date</mydate><publisher>publisher1</publisher></fields>")
13
- @sample_raw_xml = "<foo><xmlelement/></foo>"
13
+
14
14
  @solr_doc = {"id"=>"hydrange_article1","name_role_roleTerm_t"=>["creator","submitter","teacher"],"name_0_role_t"=>"\r\ncreator\r\nsubmitter\r\n","name_1_role_t"=>"\r\n teacher \r\n","name_0_role_0_roleTerm_t"=>"creator","name_0_role_1_roleTerm_t"=>"submitter","name_1_role_0_roleTerm_t"=>["teacher"]}
15
15
  end
16
16
 
@@ -35,8 +35,8 @@ describe ActiveFedora::NokogiriDatastream do
35
35
  test_ds1.ng_xml.to_xml.should == "<?xml version=\"1.0\"?>\n<xml>\n <foo/>\n</xml>\n"
36
36
  end
37
37
  it "should initialize from #xml_template if no xml is provided" do
38
- ActiveFedora::NokogiriDatastream.expects(:xml_template).returns("<fake template/>")
39
- ActiveFedora::NokogiriDatastream.new.ng_xml.should be_equivalent_to("<fake template/>")
38
+ ActiveFedora::NokogiriDatastream.expects(:xml_template).returns("fake template")
39
+ ActiveFedora::NokogiriDatastream.new.ng_xml.should == "fake template"
40
40
  end
41
41
  end
42
42
 
@@ -234,32 +234,6 @@ describe ActiveFedora::NokogiriDatastream do
234
234
  end
235
235
  end
236
236
 
237
- describe '.content=' do
238
- it "should update the content and ng_xml, marking the datastream as dirty" do
239
- @test_ds.should_not be_dirty
240
- @test_ds.blob.should_not be_equivalent_to(@sample_raw_xml)
241
- @test_ds.ng_xml.to_xml.should_not be_equivalent_to(@sample_raw_xml)
242
- @test_ds.content = @sample_raw_xml
243
- @test_ds.should be_dirty
244
- @test_ds.blob.should be_equivalent_to(@sample_raw_xml)
245
- @test_ds.ng_xml.to_xml.should be_equivalent_to(@sample_raw_xml)
246
- end
247
- end
248
-
249
- describe 'ng_xml=' do
250
- it "should parse raw xml for you" do
251
- @test_ds.ng_xml.to_xml.should_not be_equivalent_to(@sample_raw_xml)
252
- @test_ds.ng_xml = @sample_raw_xml
253
- @test_ds.ng_xml.class.should == Nokogiri::XML::Document
254
- @test_ds.ng_xml.to_xml.should be_equivalent_to(@sample_raw_xml)
255
- end
256
- it "should mark the datastream as dirty" do
257
- @test_ds.should_not be_dirty
258
- @test_ds.ng_xml = @sample_raw_xml
259
- @test_ds.should be_dirty
260
- end
261
- end
262
-
263
237
  describe '.to_xml' do
264
238
  it "should provide .to_xml" do
265
239
  @test_ds.should respond_to(:to_xml)
@@ -99,14 +99,14 @@ describe Fedora::Repository do
99
99
  it "should post the provided xml or file to fedora" do
100
100
  foxml = fixture("test_12.foxml.xml").read
101
101
  connection = Fedora::Repository.instance.send(:connection)
102
- connection.expects(:post).with("/fedora/objects/new",:body=>foxml)
102
+ connection.expects(:post).with("/fedora/objects/new",foxml)
103
103
  Fedora::Repository.instance.ingest(foxml)
104
104
  end
105
105
  it "should accept a file as its input" do
106
106
  foxml_file = fixture("test_12.foxml.xml")
107
107
  foxml = fixture("test_12.foxml.xml").read
108
108
  connection = Fedora::Repository.instance.send(:connection)
109
- connection.expects(:post).with("/fedora/objects/new",:body=>foxml)
109
+ connection.expects(:post).with("/fedora/objects/new",foxml)
110
110
  Fedora::Repository.instance.ingest(foxml_file)
111
111
  end
112
112
  end
@@ -10,6 +10,7 @@ require 'xmlsimple'
10
10
  @@last_pid = 0
11
11
 
12
12
  class SpecNode2
13
+ include ActiveFedora::RelationshipsHelper
13
14
  include ActiveFedora::SemanticNode
14
15
 
15
16
  attr_accessor :pid
@@ -31,6 +32,7 @@ describe ActiveFedora::SemanticNode do
31
32
 
32
33
  before(:each) do
33
34
  class SpecNode
35
+ include ActiveFedora::RelationshipsHelper
34
36
  include ActiveFedora::SemanticNode
35
37
 
36
38
  attr_accessor :pid
@@ -84,11 +84,4 @@ describe ActiveFedora::SolrService do
84
84
  end
85
85
  end
86
86
 
87
- describe "escape_characters_for_query" do
88
- it "should escape the Solr special characters" do
89
- test_val = '# + - || ! ( ) { } [ ] ^ " ~ * ? : \\'
90
- expected_result = '\\# \\+ \\- \\|\\| \\! \\( \\) \\{ \\} \\[ \\] \\^ \\" \\~ \\* \\? \\: \\\\'
91
- ActiveFedora::SolrService.escape_characters_for_query(test_val).should == expected_result
92
- end
93
- end
94
87
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
- - 2
8
7
  - 3
9
- - 8
10
- version: 2.3.8
8
+ - 0
9
+ - 0
10
+ version: 3.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Zumwalt
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-09-23 00:00:00 -05:00
19
+ date: 2011-09-02 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -133,7 +133,7 @@ dependencies:
133
133
  requirement: &id008 !ruby/object:Gem::Requirement
134
134
  none: false
135
135
  requirements:
136
- - - <
136
+ - - ~>
137
137
  - !ruby/object:Gem::Version
138
138
  hash: 7
139
139
  segments:
@@ -144,21 +144,23 @@ dependencies:
144
144
  type: :runtime
145
145
  version_requirements: *id008
146
146
  - !ruby/object:Gem::Dependency
147
- name: mediashelf-loggable
147
+ name: activesupport
148
148
  prerelease: false
149
149
  requirement: &id009 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
- - - ">="
152
+ - - ~>
153
153
  - !ruby/object:Gem::Version
154
- hash: 3
154
+ hash: 7
155
155
  segments:
156
+ - 3
156
157
  - 0
157
- version: "0"
158
+ - 0
159
+ version: 3.0.0
158
160
  type: :runtime
159
161
  version_requirements: *id009
160
162
  - !ruby/object:Gem::Dependency
161
- name: equivalent-xml
163
+ name: mediashelf-loggable
162
164
  prerelease: false
163
165
  requirement: &id010 !ruby/object:Gem::Requirement
164
166
  none: false
@@ -172,7 +174,7 @@ dependencies:
172
174
  type: :runtime
173
175
  version_requirements: *id010
174
176
  - !ruby/object:Gem::Dependency
175
- name: facets
177
+ name: equivalent-xml
176
178
  prerelease: false
177
179
  requirement: &id011 !ruby/object:Gem::Requirement
178
180
  none: false
@@ -186,7 +188,7 @@ dependencies:
186
188
  type: :runtime
187
189
  version_requirements: *id011
188
190
  - !ruby/object:Gem::Dependency
189
- name: net-http-persistent
191
+ name: facets
190
192
  prerelease: false
191
193
  requirement: &id012 !ruby/object:Gem::Requirement
192
194
  none: false
@@ -514,18 +516,26 @@ files:
514
516
  - config/solr_mappings_bl_2.4.yml
515
517
  - lib/active-fedora.rb
516
518
  - lib/active_fedora.rb
517
- - lib/active_fedora/active_fedora_configuration_exception.rb
519
+ - lib/active_fedora/associations.rb
520
+ - lib/active_fedora/associations/association_collection.rb
521
+ - lib/active_fedora/associations/association_proxy.rb
522
+ - lib/active_fedora/associations/belongs_to_association.rb
523
+ - lib/active_fedora/associations/has_many_association.rb
524
+ - lib/active_fedora/attribute_methods.rb
518
525
  - lib/active_fedora/base.rb
519
526
  - lib/active_fedora/content_model.rb
520
527
  - lib/active_fedora/datastream.rb
528
+ - lib/active_fedora/delegating.rb
521
529
  - lib/active_fedora/fedora_object.rb
522
530
  - lib/active_fedora/metadata_datastream.rb
523
531
  - lib/active_fedora/metadata_datastream_helper.rb
524
532
  - lib/active_fedora/model.rb
533
+ - lib/active_fedora/nested_attributes.rb
525
534
  - lib/active_fedora/nokogiri_datastream.rb
526
535
  - lib/active_fedora/property.rb
527
536
  - lib/active_fedora/qualified_dublin_core_datastream.rb
528
537
  - lib/active_fedora/railtie.rb
538
+ - lib/active_fedora/reflection.rb
529
539
  - lib/active_fedora/relationship.rb
530
540
  - lib/active_fedora/relationships_helper.rb
531
541
  - lib/active_fedora/rels_ext_datastream.rb
@@ -547,7 +557,6 @@ files:
547
557
  - lib/ruby-fedora.rb
548
558
  - lib/tasks/active_fedora.rake
549
559
  - lib/tasks/active_fedora_dev.rake
550
- - lib/util/class_level_inheritable_attributes.rb
551
560
  - script/console
552
561
  - script/destroy
553
562
  - script/generate
@@ -572,6 +581,7 @@ files:
572
581
  - spec/fixtures/rails_root/config/solr_mappings_bl_2.4.yml
573
582
  - spec/fixtures/test_12.foxml.xml
574
583
  - spec/hydrangea_fixture_mods_article1.foxml.xml
584
+ - spec/integration/associations_spec.rb
575
585
  - spec/integration/base_file_management_spec.rb
576
586
  - spec/integration/base_find_by_fields_spec.rb
577
587
  - spec/integration/base_loader_spec.rb
@@ -584,6 +594,7 @@ files:
584
594
  - spec/integration/metadata_datastream_helper_spec.rb
585
595
  - spec/integration/model_spec.rb
586
596
  - spec/integration/mods_article_integration_spec.rb
597
+ - spec/integration/nested_attribute_spec.rb
587
598
  - spec/integration/nokogiri_datastream_spec.rb
588
599
  - spec/integration/rels_ext_datastream_spec.rb
589
600
  - spec/integration/repository_spec.rb
@@ -632,8 +643,11 @@ files:
632
643
  - spec/spec.opts
633
644
  - spec/spec_helper.rb
634
645
  - spec/unit/active_fedora_spec.rb
646
+ - spec/unit/association_proxy_spec.rb
647
+ - spec/unit/base_active_model_spec.rb
635
648
  - spec/unit/base_cma_spec.rb
636
649
  - spec/unit/base_datastream_management_spec.rb
650
+ - spec/unit/base_delegate_spec.rb
637
651
  - spec/unit/base_extra_spec.rb
638
652
  - spec/unit/base_file_management_spec.rb
639
653
  - spec/unit/base_named_datastream_spec.rb
@@ -643,6 +657,7 @@ files:
643
657
  - spec/unit/datastream_concurrency_spec.rb
644
658
  - spec/unit/datastream_spec.rb
645
659
  - spec/unit/fedora_object_spec.rb
660
+ - spec/unit/has_many_collection_spec.rb
646
661
  - spec/unit/inheritance_spec.rb
647
662
  - spec/unit/metadata_datastream_spec.rb
648
663
  - spec/unit/model_spec.rb
@@ -708,6 +723,7 @@ test_files:
708
723
  - spec/fixtures/rails_root/config/solr_mappings_bl_2.4.yml
709
724
  - spec/fixtures/test_12.foxml.xml
710
725
  - spec/hydrangea_fixture_mods_article1.foxml.xml
726
+ - spec/integration/associations_spec.rb
711
727
  - spec/integration/base_file_management_spec.rb
712
728
  - spec/integration/base_find_by_fields_spec.rb
713
729
  - spec/integration/base_loader_spec.rb
@@ -720,6 +736,7 @@ test_files:
720
736
  - spec/integration/metadata_datastream_helper_spec.rb
721
737
  - spec/integration/model_spec.rb
722
738
  - spec/integration/mods_article_integration_spec.rb
739
+ - spec/integration/nested_attribute_spec.rb
723
740
  - spec/integration/nokogiri_datastream_spec.rb
724
741
  - spec/integration/rels_ext_datastream_spec.rb
725
742
  - spec/integration/repository_spec.rb
@@ -768,8 +785,11 @@ test_files:
768
785
  - spec/spec.opts
769
786
  - spec/spec_helper.rb
770
787
  - spec/unit/active_fedora_spec.rb
788
+ - spec/unit/association_proxy_spec.rb
789
+ - spec/unit/base_active_model_spec.rb
771
790
  - spec/unit/base_cma_spec.rb
772
791
  - spec/unit/base_datastream_management_spec.rb
792
+ - spec/unit/base_delegate_spec.rb
773
793
  - spec/unit/base_extra_spec.rb
774
794
  - spec/unit/base_file_management_spec.rb
775
795
  - spec/unit/base_named_datastream_spec.rb
@@ -779,6 +799,7 @@ test_files:
779
799
  - spec/unit/datastream_concurrency_spec.rb
780
800
  - spec/unit/datastream_spec.rb
781
801
  - spec/unit/fedora_object_spec.rb
802
+ - spec/unit/has_many_collection_spec.rb
782
803
  - spec/unit/inheritance_spec.rb
783
804
  - spec/unit/metadata_datastream_spec.rb
784
805
  - spec/unit/model_spec.rb
@@ -1,2 +0,0 @@
1
- class ActiveFedoraConfigurationException < Exception
2
- end
@@ -1,23 +0,0 @@
1
- module MediaShelfClassLevelInheritableAttributes
2
- def self.included(base)
3
- base.extend(MSClassMethods)
4
- end
5
- module MSClassMethods
6
- def ms_inheritable_attributes(*args)
7
- @ms_inheritable_attributes ||=[:ms_inheritable_attributes]
8
- @ms_inheritable_attributes+=args
9
- args.each do |arg|
10
- class_eval %(
11
- class <<self;attr_accessor :#{arg} end
12
- )
13
- end
14
- @ms_inheritable_attributes
15
- end
16
- def inherited(subclass)
17
- @ms_inheritable_attributes.each do |attrib|
18
- instance_var = "@#{attrib}"
19
- subclass.instance_variable_set(instance_var, instance_variable_get(instance_var))
20
- end
21
- end
22
- end
23
- end