active-fedora 3.2.0.pre3 → 3.2.0.pre4

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.
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Base do
4
+ before :all do
5
+ class CallbackStub < ActiveFedora::Base
6
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"someData" do |m|
7
+ m.field "fubar", :string
8
+ m.field "swank", :text
9
+ end
10
+ delegate :fubar, :to=>'someData'
11
+ delegate :swank, :to=>'someData'
12
+
13
+ after_initialize :a_init
14
+ before_save :b_save
15
+ after_save :a_save
16
+ before_create :b_create
17
+ after_create :a_create
18
+ before_update :b_update
19
+ after_update :a_update
20
+ after_find :a_find
21
+
22
+ end
23
+ end
24
+ after :all do
25
+ Object.send(:remove_const, :CallbackStub)
26
+ end
27
+
28
+ it "Should have after_initialize, before_save,after_save, before_create, after_create, after_update, before_update" do
29
+ CallbackStub.any_instance.expects(:a_init).twice
30
+ CallbackStub.any_instance.expects :b_create
31
+ CallbackStub.any_instance.expects :a_create
32
+ CallbackStub.any_instance.expects(:b_save).twice
33
+ CallbackStub.any_instance.expects(:a_save).twice
34
+ CallbackStub.any_instance.expects(:a_find)
35
+ CallbackStub.any_instance.expects(:b_update)
36
+ CallbackStub.any_instance.expects(:a_update)
37
+ cb = CallbackStub.new
38
+ cb.save
39
+
40
+ cb2 = CallbackStub.find(cb.pid)
41
+ cb2.save
42
+ end
43
+
44
+ end
@@ -3,11 +3,12 @@ require 'spec_helper'
3
3
  describe ActiveFedora::RelationshipGraph do
4
4
  before do
5
5
  @graph = ActiveFedora::RelationshipGraph.new
6
+ @n1 = ActiveFedora::Base.new()
7
+ @n1.stubs(:pid => 'foo:777')
6
8
  end
7
9
 
8
10
 
9
11
  it "should add relationships" do
10
- @n1 = ActiveFedora::Base.new
11
12
  @n2 = ActiveFedora::Base.new
12
13
  @graph.add(:has_part, @n1)
13
14
  @graph.relationships[:has_part].should == [@n1]
@@ -23,7 +24,6 @@ describe ActiveFedora::RelationshipGraph do
23
24
  graph.should be_kind_of RDF::Graph
24
25
  graph.statements.to_a.should == []
25
26
 
26
- @n1 = ActiveFedora::Base.new(:pid=>'foo:777')
27
27
  @graph.add(:has_part, @n1)
28
28
  graph = @graph.to_graph('info:fedora/foo:1')
29
29
  stmts = graph.statements.to_a
@@ -36,7 +36,6 @@ describe ActiveFedora::RelationshipGraph do
36
36
  end
37
37
 
38
38
  it "should have array accessor" do
39
- @n1 = ActiveFedora::Base.new(:pid=>'foo:777')
40
39
  @graph.add(:has_part, @n1)
41
40
  @graph[:has_part].should == [@n1]
42
41
  end
@@ -44,7 +43,6 @@ describe ActiveFedora::RelationshipGraph do
44
43
 
45
44
  describe "delete" do
46
45
  it "should delete an object when an object is passed" do
47
- @n1 = ActiveFedora::Base.new(:pid=>'foo:777')
48
46
  @graph.add(:has_part, @n1)
49
47
  @graph[:has_part].should == [@n1]
50
48
  @graph.delete(:has_part, @n1)
@@ -52,7 +50,6 @@ describe ActiveFedora::RelationshipGraph do
52
50
  end
53
51
  it "should delete an pid when an object is passed" do
54
52
  #a reloaded rels-ext is just a list of uris, not inflated.
55
- @n1 = ActiveFedora::Base.new(:pid=>'foo:777')
56
53
  @graph.add(:has_part, 'info:fedora/foo:777')
57
54
  @graph[:has_part].should == ['info:fedora/foo:777']
58
55
  @graph.delete(:has_part, @n1)
@@ -60,7 +57,6 @@ describe ActiveFedora::RelationshipGraph do
60
57
  end
61
58
  it "should delete an pid when a string is passed" do
62
59
  #a reloaded rels-ext is just a list of uris, not inflated.
63
- @n1 = ActiveFedora::Base.new(:pid=>'foo:777')
64
60
  @graph.add(:has_part, 'info:fedora/foo:777')
65
61
  @graph[:has_part].should == ['info:fedora/foo:777']
66
62
  @graph.delete(:has_part, 'info:fedora/foo:777')
@@ -68,7 +64,6 @@ describe ActiveFedora::RelationshipGraph do
68
64
  end
69
65
  it "should delete an object when a pid is passed" do
70
66
  #a reloaded rels-ext is just a list of uris, not inflated.
71
- @n1 = ActiveFedora::Base.new(:pid=>'foo:777')
72
67
  @graph.add(:has_part, @n1)
73
68
  @graph[:has_part].should == [@n1]
74
69
  @graph.delete(:has_part, 'info:fedora/foo:777')
@@ -13,9 +13,11 @@ describe ActiveFedora::Relationships do
13
13
  include ActiveFedora::SemanticNode
14
14
 
15
15
  attr_accessor :pid
16
- def initialize (params={})
17
- self.pid = params[:pid]
16
+ def init_with(inner_obj)
17
+ self.pid = inner_obj.pid
18
+ self
18
19
  end
20
+
19
21
  def internal_uri
20
22
  'info:fedora/' + pid.to_s
21
23
  end
@@ -25,11 +25,11 @@ describe ActiveFedora::ServiceDefinitions do
25
25
  end
26
26
  describe "method creation" do
27
27
  it "should create the system sdef methods" do
28
- obj = Test.new(:pid=>"monkey:99")
28
+ obj = Test.new()
29
29
  (obj.respond_to? :object_profile).should == true
30
30
  end
31
31
  it "should create the declared sdef methods" do
32
- obj = Test.new(:pid=>"monkey:99")
32
+ obj = Test.new()
33
33
  (obj.respond_to? :document_style_1).should == true
34
34
  end
35
35
  end
@@ -37,12 +37,14 @@ describe ActiveFedora::ServiceDefinitions do
37
37
  it "should call the appropriate rubydora rest api method" do
38
38
  Rubydora::Repository.any_instance.expects(:dissemination).with({:pid=>'monkey:99',:sdef=>'test:12', :method=>'getDocumentStyle1'})
39
39
  #@mock_client.stubs(:[]).with('objects/monkey%3A99/methods/test%3A12/getDocumentStyle1')
40
- obj = Test.new(:pid=>"monkey:99")
40
+ obj = Test.new()
41
+ obj.stubs(:pid).returns('monkey:99')
41
42
  obj.document_style_1
42
43
  end
43
44
  it "should call the appropriate rubydora rest api method with parameters" do
44
45
  Rubydora::Repository.any_instance.expects(:dissemination).with({:pid=>'monkey:99',:sdef=>'test:12', :method=>'getDocumentStyle1', :format=>'xml'})
45
- obj = Test.new(:pid=>"monkey:99")
46
+ obj = Test.new()
47
+ obj.stubs(:pid).returns('monkey:99')
46
48
  obj.document_style_1({:format=>'xml'})
47
49
  end
48
50
  it "should call the appropriate rubydora rest api method with a block" do
@@ -9,7 +9,7 @@ describe ActiveFedora do
9
9
  module SolrSpecModel
10
10
  class Basic
11
11
  include ActiveFedora::Model
12
- def initialize(opts)
12
+ def init_with(inner_obj)
13
13
  end
14
14
  end
15
15
  end
@@ -49,8 +49,9 @@ describe ActiveFedora::SolrService do
49
49
  before(:each) do
50
50
  class AudioRecord
51
51
  attr_accessor :pid
52
- def initialize (params={})
53
- self.pid = params[:pid]
52
+ def init_with(inner_obj)
53
+ self.pid = inner_obj.pid
54
+ self
54
55
  end
55
56
  end
56
57
  @sample_solr_hits = [{"id"=>"my:_PID1_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]},
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Base do
4
+ before :all do
5
+ class ValidationStub < ActiveFedora::Base
6
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"someData" do |m|
7
+ m.field "fubar", :string
8
+ m.field "swank", :text
9
+ end
10
+ delegate :fubar, :to=>'someData'
11
+ delegate :swank, :to=>'someData'
12
+
13
+ validates_presence_of :fubar
14
+ validates_length_of :swank, :minimum=>5
15
+
16
+ end
17
+ end
18
+ after :all do
19
+ Object.send(:remove_const, :ValidationStub)
20
+ end
21
+
22
+ describe "a valid object" do
23
+ before do
24
+ @obj = ValidationStub.new(:fubar=>'here', :swank=>'long enough')
25
+ end
26
+
27
+ it "should be valid" do
28
+ @obj.should_not be_valid
29
+ end
30
+ end
31
+ describe "an invalid object" do
32
+ before do
33
+ @obj = ValidationStub.new(:swank=>'smal')
34
+ end
35
+
36
+ it "should be invalid" do
37
+ @obj.should_not be_valid
38
+ @obj.errors[:fubar].should == ["can't be blank"]
39
+ @obj.errors[:swank].should == ["is too short (minimum is 5 characters)"]
40
+ end
41
+ end
42
+
43
+ end
metadata CHANGED
@@ -1,24 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1923832047
4
+ hash: 1923832033
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 2
9
9
  - 0
10
10
  - pre
11
- - 3
12
- version: 3.2.0.pre3
11
+ - 4
12
+ version: 3.2.0.pre4
13
13
  platform: ruby
14
14
  authors:
15
15
  - Matt Zumwalt
16
16
  - McClain Looney
17
+ - Justin Coyne
17
18
  autorequire:
18
19
  bindir: bin
19
20
  cert_chain: []
20
21
 
21
- date: 2011-12-30 00:00:00 -06:00
22
+ date: 2012-01-01 00:00:00 -06:00
22
23
  default_executable:
23
24
  dependencies:
24
25
  - !ruby/object:Gem::Dependency
@@ -562,6 +563,7 @@ files:
562
563
  - lib/active_fedora/associations/has_many_association.rb
563
564
  - lib/active_fedora/attribute_methods.rb
564
565
  - lib/active_fedora/base.rb
566
+ - lib/active_fedora/callbacks.rb
565
567
  - lib/active_fedora/content_model.rb
566
568
  - lib/active_fedora/datastream.rb
567
569
  - lib/active_fedora/datastream_collections.rb
@@ -577,6 +579,7 @@ files:
577
579
  - lib/active_fedora/named_relationships.rb
578
580
  - lib/active_fedora/nested_attributes.rb
579
581
  - lib/active_fedora/nokogiri_datastream.rb
582
+ - lib/active_fedora/persistence.rb
580
583
  - lib/active_fedora/predicates.rb
581
584
  - lib/active_fedora/property.rb
582
585
  - lib/active_fedora/qualified_dublin_core_datastream.rb
@@ -595,8 +598,10 @@ files:
595
598
  - lib/active_fedora/samples/special_thing.rb
596
599
  - lib/active_fedora/semantic_node.rb
597
600
  - lib/active_fedora/service_definitions.rb
601
+ - lib/active_fedora/solr_digital_object.rb
598
602
  - lib/active_fedora/solr_service.rb
599
603
  - lib/active_fedora/unsaved_digital_object.rb
604
+ - lib/active_fedora/validations.rb
600
605
  - lib/active_fedora/version.rb
601
606
  - lib/ruby-fedora.rb
602
607
  - lib/tasks/active_fedora.rake
@@ -693,6 +698,7 @@ files:
693
698
  - spec/unit/base_extra_spec.rb
694
699
  - spec/unit/base_file_management_spec.rb
695
700
  - spec/unit/base_spec.rb
701
+ - spec/unit/callback_spec.rb
696
702
  - spec/unit/content_model_spec.rb
697
703
  - spec/unit/datastream_collections_spec.rb
698
704
  - spec/unit/datastream_concurrency_spec.rb
@@ -715,6 +721,7 @@ files:
715
721
  - spec/unit/service_definitions_spec.rb
716
722
  - spec/unit/solr_config_options_spec.rb
717
723
  - spec/unit/solr_service_spec.rb
724
+ - spec/unit/validations_spec.rb
718
725
  has_rdoc: true
719
726
  homepage: http://yourmediashelf.com/activefedora
720
727
  licenses: []
@@ -836,6 +843,7 @@ test_files:
836
843
  - spec/unit/base_extra_spec.rb
837
844
  - spec/unit/base_file_management_spec.rb
838
845
  - spec/unit/base_spec.rb
846
+ - spec/unit/callback_spec.rb
839
847
  - spec/unit/content_model_spec.rb
840
848
  - spec/unit/datastream_collections_spec.rb
841
849
  - spec/unit/datastream_concurrency_spec.rb
@@ -858,3 +866,4 @@ test_files:
858
866
  - spec/unit/service_definitions_spec.rb
859
867
  - spec/unit/solr_config_options_spec.rb
860
868
  - spec/unit/solr_service_spec.rb
869
+ - spec/unit/validations_spec.rb