active-fedora 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/.hg/00changelog.i +0 -0
  4. data/.hg/branch +1 -0
  5. data/.hg/branch.cache +2 -0
  6. data/.hg/dirstate +0 -0
  7. data/.hg/hgrc +2 -0
  8. data/.hg/requires +2 -0
  9. data/.hg/store/00changelog.i +0 -0
  10. data/.hg/store/00manifest.i +0 -0
  11. data/.hg/store/data/.hgignore.i +0 -0
  12. data/.hg/store/data/.hgtags.i +0 -0
  13. data/.hg/store/data/_c_o_p_y_i_n_g.txt.i +0 -0
  14. data/.hg/store/data/_c_o_y_i_n_g._l_e_s_s_e_r.txt.i +0 -0
  15. data/.hg/store/data/_history.txt.i +0 -0
  16. data/.hg/store/data/_license.txt.i +0 -0
  17. data/.hg/store/data/_manifest.txt.i +0 -0
  18. data/.hg/store/data/_post_install.txt.i +0 -0
  19. data/.hg/store/data/_r_e_a_d_m_e.rdoc.i +0 -0
  20. data/.hg/store/data/_r_e_a_d_m_e.txt.i +0 -0
  21. data/.hg/store/data/_rakefile.i +0 -0
  22. data/.hg/store/data/_v_e_r_s_i_o_n.i +0 -0
  23. data/.hg/store/data/active-fedora.gemspec.i +0 -0
  24. data/.hg/store/data/active__fedora/_history.txt.i +0 -0
  25. data/.hg/store/data/active__fedora/_manifest.txt.i +0 -0
  26. data/.hg/store/data/active__fedora/_post_install.txt.i +0 -0
  27. data/.hg/store/data/active__fedora/_r_e_a_d_m_e.rdoc.i +0 -0
  28. data/.hg/store/data/active__fedora/_rakefile.i +0 -0
  29. data/.hg/store/data/active__fedora/lib/active__fedora.rb.i +0 -0
  30. data/.hg/store/data/active__fedora/script/console.i +0 -0
  31. data/.hg/store/data/active__fedora/script/destroy.i +0 -0
  32. data/.hg/store/data/active__fedora/script/generate.i +0 -0
  33. data/.hg/store/data/active__fedora/spec/active__fedora__spec.rb.i +0 -0
  34. data/.hg/store/data/active__fedora/spec/spec__helper.rb.i +0 -0
  35. data/.hg/store/data/config/fedora.yml.i +0 -0
  36. data/.hg/store/data/config/solr__mappings.yml.i +0 -0
  37. data/.hg/store/data/config/solr__mappings__af__0.1.yml.i +0 -0
  38. data/.hg/store/data/config/solr__mappings__bl__2.4.yml.i +0 -0
  39. data/.hg/store/data/lib/active-fedora.rb.i +0 -0
  40. data/.hg/store/data/lib/active__fedora.rb.i +0 -0
  41. data/.hg/store/data/lib/active__fedora/base.rb.i +0 -0
  42. data/.hg/store/data/lib/active__fedora/content__model.rb.i +0 -0
  43. data/.hg/store/data/lib/active__fedora/datastream.rb.i +0 -0
  44. data/.hg/store/data/lib/active__fedora/fedora__object.rb.i +0 -0
  45. data/.hg/store/data/lib/active__fedora/metadata__datastream.rb.i +0 -0
  46. data/.hg/store/data/lib/active__fedora/model.rb.i +0 -0
  47. data/.hg/store/data/lib/active__fedora/property.rb.i +0 -0
  48. data/.hg/store/data/lib/active__fedora/qualified__dublin__core__datastream.rb.i +0 -0
  49. data/.hg/store/data/lib/active__fedora/relationship.rb.i +0 -0
  50. data/.hg/store/data/lib/active__fedora/rels__ext__datastream.rb.i +0 -0
  51. data/.hg/store/data/lib/active__fedora/semantic__node.rb.i +0 -0
  52. data/.hg/store/data/lib/active__fedora/solr__mapper.rb.i +0 -0
  53. data/.hg/store/data/lib/active__fedora/solr__service.rb.i +0 -0
  54. data/.hg/store/data/lib/fedora/base.rb.i +0 -0
  55. data/.hg/store/data/lib/fedora/connection.rb.i +0 -0
  56. data/.hg/store/data/lib/fedora/datastream.rb.i +0 -0
  57. data/.hg/store/data/lib/fedora/fedora__object.rb.i +0 -0
  58. data/.hg/store/data/lib/fedora/formats.rb.i +0 -0
  59. data/.hg/store/data/lib/fedora/generic__search.rb.i +0 -0
  60. data/.hg/store/data/lib/fedora/repository.rb.i +0 -0
  61. data/.hg/store/data/lib/ruby-fedora.rb.i +0 -0
  62. data/.hg/store/data/lib/util/class__level__inheritable__attributes.rb.i +0 -0
  63. data/.hg/store/data/script/console.i +0 -0
  64. data/.hg/store/data/script/destroy.i +0 -0
  65. data/.hg/store/data/script/generate.i +0 -0
  66. data/.hg/store/data/solr/config/schema-1.5.xml.i +0 -0
  67. data/.hg/store/data/solr/config/schema.xml.i +0 -0
  68. data/.hg/store/data/solr/config/solrconfig-1.5.xml.i +0 -0
  69. data/.hg/store/data/spec/fixtures/changeme155.xml.i +0 -0
  70. data/.hg/store/data/spec/fixtures/dino.jpg.i +0 -0
  71. data/.hg/store/data/spec/fixtures/minivan.jpg.d +0 -0
  72. data/.hg/store/data/spec/fixtures/minivan.jpg.i +0 -0
  73. data/.hg/store/data/spec/fixtures/test__12.foxml.xml.i +0 -0
  74. data/.hg/store/data/spec/integration/active__fedora/base__spec.rb.i +0 -0
  75. data/.hg/store/data/spec/integration/active__fedora/datastream__spec.rb.i +0 -0
  76. data/.hg/store/data/spec/integration/active__fedora/fedora__object__spec.rb.i +0 -0
  77. data/.hg/store/data/spec/integration/active__fedora/full__featured__model__spec.rb.i +0 -0
  78. data/.hg/store/data/spec/integration/active__fedora/model__spec.rb.i +0 -0
  79. data/.hg/store/data/spec/integration/active__fedora/rels__ext__datastream__spec.rb.i +0 -0
  80. data/.hg/store/data/spec/integration/active__fedora/semantic__node__spec.rb.i +0 -0
  81. data/.hg/store/data/spec/integration/base__file__management__spec.rb.i +0 -0
  82. data/.hg/store/data/spec/integration/base__spec.rb.i +0 -0
  83. data/.hg/store/data/spec/integration/bug__spec.rb.i +0 -0
  84. data/.hg/store/data/spec/integration/datastream__spec.rb.i +0 -0
  85. data/.hg/store/data/spec/integration/datastreams__crud__spec.rb.i +0 -0
  86. data/.hg/store/data/spec/integration/fedora__object__spec.rb.i +0 -0
  87. data/.hg/store/data/spec/integration/full__featured__model__spec.rb.i +0 -0
  88. data/.hg/store/data/spec/integration/model__spec.rb.i +0 -0
  89. data/.hg/store/data/spec/integration/rels__ext__datastream__spec.rb.i +0 -0
  90. data/.hg/store/data/spec/integration/repository__spec.rb.i +0 -0
  91. data/.hg/store/data/spec/integration/rf__fedora__object__spec.rb.i +0 -0
  92. data/.hg/store/data/spec/integration/semantic__node__spec.rb.i +0 -0
  93. data/.hg/store/data/spec/integration/solr__service__spec.rb.i +0 -0
  94. data/.hg/store/data/spec/samples/models/audio__record.rb.i +0 -0
  95. data/.hg/store/data/spec/samples/models/image.rb.i +0 -0
  96. data/.hg/store/data/spec/samples/models/oral__history.rb.i +0 -0
  97. data/.hg/store/data/spec/samples/models/seminar.rb.i +0 -0
  98. data/.hg/store/data/spec/samples/models/seminar__audio__file.rb.i +0 -0
  99. data/.hg/store/data/spec/samples/oh__qdc.xml.i +0 -0
  100. data/.hg/store/data/spec/samples/oral__history.rb.i +0 -0
  101. data/.hg/store/data/spec/samples/oral__history__sample.xml.i +0 -0
  102. data/.hg/store/data/spec/samples/oral__history__sample__model.rb.i +0 -0
  103. data/.hg/store/data/spec/samples/oral__history__xml.xml.i +0 -0
  104. data/.hg/store/data/spec/spec.opts.i +0 -0
  105. data/.hg/store/data/spec/spec__helper.rb.i +0 -0
  106. data/.hg/store/data/spec/unit/active__fedora/base__cma__spec.rb.i +0 -0
  107. data/.hg/store/data/spec/unit/active__fedora/base__extra__spec.rb.i +0 -0
  108. data/.hg/store/data/spec/unit/active__fedora/base__spec.rb.i +0 -0
  109. data/.hg/store/data/spec/unit/active__fedora/content__model__spec.rb.i +0 -0
  110. data/.hg/store/data/spec/unit/active__fedora/datastream__spec.rb.i +0 -0
  111. data/.hg/store/data/spec/unit/active__fedora/inheritance__spec.rb.i +0 -0
  112. data/.hg/store/data/spec/unit/active__fedora/metadata__datastream__spec.rb.i +0 -0
  113. data/.hg/store/data/spec/unit/active__fedora/model__spec.rb.i +0 -0
  114. data/.hg/store/data/spec/unit/active__fedora/property__spec.rb.i +0 -0
  115. data/.hg/store/data/spec/unit/active__fedora/qualified__dublin__core__datastream__spec.rb.i +0 -0
  116. data/.hg/store/data/spec/unit/active__fedora/relationship__spec.rb.i +0 -0
  117. data/.hg/store/data/spec/unit/active__fedora/rels__ext__datastream__spec.rb.i +0 -0
  118. data/.hg/store/data/spec/unit/active__fedora/semantic__node__spec.rb.i +0 -0
  119. data/.hg/store/data/spec/unit/active__fedora/solr__service__spec.rb.i +0 -0
  120. data/.hg/store/data/spec/unit/active__fedora__spec.rb.i +0 -0
  121. data/.hg/store/data/spec/unit/base__cma__spec.rb.i +0 -0
  122. data/.hg/store/data/spec/unit/base__datastream__management__spec.rb.i +0 -0
  123. data/.hg/store/data/spec/unit/base__extra__spec.rb.i +0 -0
  124. data/.hg/store/data/spec/unit/base__file__management__spec.rb.i +0 -0
  125. data/.hg/store/data/spec/unit/base__loader__spec.rb.i +0 -0
  126. data/.hg/store/data/spec/unit/base__spec.rb.i +0 -0
  127. data/.hg/store/data/spec/unit/connection__spec.rb.i +0 -0
  128. data/.hg/store/data/spec/unit/content__model__spec.rb.i +0 -0
  129. data/.hg/store/data/spec/unit/datastream__concurrency__spec.rb.i +0 -0
  130. data/.hg/store/data/spec/unit/datastream__spec.rb.i +0 -0
  131. data/.hg/store/data/spec/unit/fedora__object__spec.rb.i +0 -0
  132. data/.hg/store/data/spec/unit/inheritance__spec.rb.i +0 -0
  133. data/.hg/store/data/spec/unit/metadata__datastream__spec.rb.i +0 -0
  134. data/.hg/store/data/spec/unit/model__spec.rb.i +0 -0
  135. data/.hg/store/data/spec/unit/property__spec.rb.i +0 -0
  136. data/.hg/store/data/spec/unit/qualified__dublin__core__datastream__spec.rb.i +0 -0
  137. data/.hg/store/data/spec/unit/relationship__spec.rb.i +0 -0
  138. data/.hg/store/data/spec/unit/rels__ext__datastream__spec.rb.i +0 -0
  139. data/.hg/store/data/spec/unit/repository__spec.rb.i +0 -0
  140. data/.hg/store/data/spec/unit/rf__datastream__spec.rb.i +0 -0
  141. data/.hg/store/data/spec/unit/semantic__node__spec.rb.i +0 -0
  142. data/.hg/store/data/spec/unit/solr__config__options__spec.rb.i +0 -0
  143. data/.hg/store/data/spec/unit/solr__mapper__spec.rb.i +0 -0
  144. data/.hg/store/data/spec/unit/solr__service__spec.rb.i +0 -0
  145. data/.hg/store/data/tasks/rspec.rake.i +0 -0
  146. data/.hg/store/undo +0 -0
  147. data/.hg/undo.branch +1 -0
  148. data/.hg/undo.dirstate +0 -0
  149. data/.hgignore +7 -0
  150. data/.hgtags +14 -0
  151. data/COPYING.txt +674 -0
  152. data/COYING.LESSER.txt +165 -0
  153. data/History.txt +34 -0
  154. data/LICENSE +20 -0
  155. data/License.txt +58 -0
  156. data/Manifest.txt +1 -1
  157. data/README.rdoc +13 -54
  158. data/README.txt +59 -0
  159. data/Rakefile +35 -0
  160. data/VERSION +1 -0
  161. data/active-fedora.gemspec +359 -0
  162. data/config/fedora.yml +16 -0
  163. data/config/solr_mappings.yml +14 -0
  164. data/config/solr_mappings_af_0.1.yml +16 -0
  165. data/config/solr_mappings_bl_2.4.yml +14 -0
  166. data/lib/active_fedora.rb +66 -6
  167. data/lib/active_fedora/base.rb +59 -23
  168. data/lib/active_fedora/datastream.rb +1 -1
  169. data/lib/active_fedora/metadata_datastream.rb +14 -7
  170. data/lib/active_fedora/model.rb +4 -4
  171. data/lib/active_fedora/rels_ext_datastream.rb +1 -1
  172. data/lib/active_fedora/semantic_node.rb +4 -3
  173. data/lib/active_fedora/solr_mapper.rb +17 -0
  174. data/lib/active_fedora/solr_service.rb +44 -2
  175. data/lib/fedora/base.rb +38 -0
  176. data/lib/fedora/connection.rb +210 -0
  177. data/lib/fedora/datastream.rb +56 -0
  178. data/lib/fedora/fedora_object.rb +161 -0
  179. data/lib/fedora/formats.rb +30 -0
  180. data/lib/fedora/generic_search.rb +71 -0
  181. data/lib/fedora/repository.rb +287 -0
  182. data/lib/ruby-fedora.rb +20 -0
  183. data/lib/util/class_level_inheritable_attributes.rb +23 -0
  184. data/script/console +15 -0
  185. data/script/destroy +14 -0
  186. data/script/generate +14 -0
  187. data/solr/config/schema-1.5.xml +468 -0
  188. data/solr/config/schema.xml +174 -212
  189. data/solr/config/solrconfig-1.5.xml +1069 -0
  190. data/spec/active_fedora_spec.rb +7 -0
  191. data/spec/fixtures/changeme155.xml +255 -0
  192. data/spec/fixtures/dino.jpg +0 -0
  193. data/spec/fixtures/minivan.jpg +0 -0
  194. data/spec/fixtures/test_12.foxml.xml +121 -0
  195. data/spec/integration/base_file_management_spec.rb +20 -0
  196. data/spec/integration/base_spec.rb +196 -0
  197. data/spec/integration/bug_spec.rb +57 -0
  198. data/spec/integration/datastream_spec.rb +60 -0
  199. data/spec/integration/datastreams_crud_spec.rb +208 -0
  200. data/spec/integration/fedora_object_spec.rb +77 -0
  201. data/spec/integration/full_featured_model_spec.rb +207 -0
  202. data/spec/integration/model_spec.rb +54 -0
  203. data/spec/integration/rels_ext_datastream_spec.rb +67 -0
  204. data/spec/integration/repository_spec.rb +297 -0
  205. data/spec/integration/rf_fedora_object_spec.rb +95 -0
  206. data/spec/integration/semantic_node_spec.rb +95 -0
  207. data/spec/integration/solr_service_spec.rb +33 -0
  208. data/spec/samples/models/audio_record.rb +29 -0
  209. data/spec/samples/models/image.rb +5 -0
  210. data/spec/samples/models/oral_history.rb +50 -0
  211. data/spec/samples/models/seminar.rb +29 -0
  212. data/spec/samples/models/seminar_audio_file.rb +34 -0
  213. data/spec/samples/oh_qdc.xml +32 -0
  214. data/spec/samples/oral_history_sample.xml +38 -0
  215. data/spec/samples/oral_history_sample_model.rb +39 -0
  216. data/spec/samples/oral_history_xml.xml +35 -0
  217. data/spec/spec.opts +5 -0
  218. data/spec/spec_helper.rb +41 -0
  219. data/spec/unit/active_fedora_spec.rb +15 -0
  220. data/spec/unit/base_cma_spec.rb +25 -0
  221. data/spec/unit/base_datastream_management_spec.rb +119 -0
  222. data/spec/unit/base_extra_spec.rb +108 -0
  223. data/spec/unit/base_file_management_spec.rb +90 -0
  224. data/spec/unit/base_loader_spec.rb +43 -0
  225. data/spec/unit/base_spec.rb +584 -0
  226. data/spec/unit/connection_spec.rb +25 -0
  227. data/spec/unit/content_model_spec.rb +51 -0
  228. data/spec/unit/datastream_concurrency_spec.rb +59 -0
  229. data/spec/unit/datastream_spec.rb +85 -0
  230. data/spec/unit/fedora_object_spec.rb +66 -0
  231. data/spec/unit/inheritance_spec.rb +46 -0
  232. data/spec/unit/metadata_datastream_spec.rb +290 -0
  233. data/spec/unit/model_spec.rb +186 -0
  234. data/spec/unit/property_spec.rb +50 -0
  235. data/spec/unit/qualified_dublin_core_datastream_spec.rb +177 -0
  236. data/spec/unit/relationship_spec.rb +77 -0
  237. data/spec/unit/rels_ext_datastream_spec.rb +99 -0
  238. data/spec/unit/repository_spec.rb +136 -0
  239. data/spec/unit/rf_datastream_spec.rb +49 -0
  240. data/spec/unit/semantic_node_spec.rb +354 -0
  241. data/spec/unit/solr_config_options_spec.rb +98 -0
  242. data/spec/unit/solr_mapper_spec.rb +31 -0
  243. data/spec/unit/solr_service_spec.rb +83 -0
  244. data/tasks/hoe.rake +0 -0
  245. data/tasks/rspec.rake +29 -0
  246. metadata +373 -55
@@ -0,0 +1,186 @@
1
+ require File.join( File.dirname(__FILE__), "../spec_helper" )
2
+
3
+ require 'active_fedora'
4
+ require 'active_fedora/model'
5
+ require "rexml/document"
6
+ require 'ftools'
7
+ require 'mocha'
8
+
9
+
10
+ describe ActiveFedora::Model do
11
+
12
+ before(:all) do
13
+ module SpecModel
14
+ class Basic
15
+ include ActiveFedora::Model
16
+ end
17
+ end
18
+ @test_property = ActiveFedora::Property.new("foo_model","test_property", :text)
19
+ end
20
+
21
+ before(:each) do
22
+ Fedora::Repository.instance.stubs(:nextid).returns('_nextid_')
23
+ @test_instance = SpecModel::Basic.new
24
+ @property = stub("myproperty", :name => "mock_prop", :instance_variable_name => "@mock_prop")
25
+ SpecModel::Basic.extend(ActiveFedora::Model)
26
+ SpecModel::Basic.create_property_getter(@property)
27
+ @obj = SpecModel::Basic.new
28
+ end
29
+
30
+ after(:all) do
31
+ #Object.send(:remove_const, :SpecModel)
32
+ end
33
+
34
+ it 'should provide #attribute_set and #attribute_get' do
35
+ SpecModel::Basic.should respond_to(:attribute_set)
36
+ SpecModel::Basic.should respond_to(:attribute_get)
37
+ end
38
+
39
+ describe "#attribute_set" do
40
+ it "should look up the property's ivar name from properties hash" do
41
+ pending
42
+ SpecModel::Basic.expects(:properties).with(@test_property.name)
43
+ SpecModel::Basic.expects(:set_instance_variable).with(@test_property.instance_variable_name, "new value")
44
+ SpecModel::Basic.attribute_set(@test_property.name, "new value")
45
+ end
46
+ end
47
+
48
+ describe "#attribute_get" do
49
+ it "should look up the property's ivar name from properties hash" do
50
+ pending
51
+ SpecModel::Basic.expects(:properties).with(@test_property.name)
52
+ SpecModel::Basic.expects(:get_instance_variable).with(@test_property.instance_variable_name)
53
+ SpecModel::Basic.attribute_get(@test_property.name, "new value")
54
+ end
55
+ end
56
+
57
+ it 'should provide #create_property_getter' do
58
+ SpecModel::Basic.should respond_to(:create_property_getter)
59
+ end
60
+
61
+ describe '#create_property_getter' do
62
+ it 'should add getter to the model' do
63
+ @obj.should respond_to(@property.name)
64
+ end
65
+
66
+ it 'should use attribute_get in custom getter method' do
67
+ @obj.expects(:attribute_get).with(@property.name)
68
+ @obj.send @property.name
69
+ end
70
+
71
+ end
72
+
73
+ it 'should provide #create_property_setter' do
74
+ SpecModel::Basic.should respond_to(:create_property_setter)
75
+ end
76
+
77
+ describe '#create_property_setter' do
78
+
79
+ before(:each) do
80
+ @property = stub("myproperty", :name => "mock_prop", :instance_variable_name => "@mock_prop")
81
+ SpecModel::Basic.create_property_setter(@property)
82
+ @obj = SpecModel::Basic.new
83
+ end
84
+
85
+ it 'should add setter to the model' do
86
+ @obj.should respond_to("#{@property.name}=")
87
+ end
88
+
89
+ it 'should use attribute_set in custom setter method' do
90
+ @obj.expects(:attribute_set).with(@property.name, "sample value")
91
+ @obj.send "#{@property.name}=", "sample value"
92
+ end
93
+
94
+ end
95
+
96
+ it 'should provide #find' do
97
+ SpecModel::Basic.should respond_to(:find)
98
+ end
99
+
100
+ describe '#find' do
101
+
102
+ it "(:all) should query solr for all objects with :active_fedora_model_s of self.class" do
103
+ mock_solr = mock("SolrConnection")
104
+ mock_result = mock("MockResult")
105
+ mock_result.expects(:hits).returns([{"id" => "changeme:30"}, {"id" => "changeme:22"}])
106
+ mock_solr.expects(:query).with('active_fedora_model_s:SpecModel\:\:Basic').returns(mock_result)
107
+ ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
108
+ Fedora::Repository.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("Fake Object")
109
+ Fedora::Repository.instance.expects(:find_model).with("changeme:22", SpecModel::Basic).returns("Fake Object")
110
+ SpecModel::Basic.find(:all)
111
+ end
112
+
113
+ it "(String) should query solr for an object with the given id and return that object" do
114
+ mock_solr = mock("SolrConnection")
115
+ mock_result = mock("MockResult")
116
+ mock_result.expects(:hits).returns([{"id" => "changeme:30"}])
117
+ mock_solr.expects(:query).with('id:changeme\:30').returns(mock_result)
118
+ ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
119
+ Fedora::Repository.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("Fake Object")
120
+
121
+ SpecModel::Basic.find("changeme:30").should == "Fake Object"
122
+ end
123
+
124
+ it 'should not call #new' do
125
+ mock_solr = mock("SolrConnection")
126
+ mock_result = mock("MockResult")
127
+ mock_result.expects(:hits).returns([{"id" => "changeme:30"}])
128
+ mock_solr.expects(:query).with('id:changeme\:30').returns(mock_result)
129
+ Fedora::Repository.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("fake object")
130
+
131
+ ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
132
+
133
+ res = SpecModel::Basic.find("changeme:30")
134
+ end
135
+
136
+ describe"(:pid => xxx)" do
137
+ it "should pull the inner object from fedora if it already exists in fedora" do
138
+ pending
139
+ Fedora::Repository.instance.expects(:save).never
140
+ mock_obj = mock("Fedora Object")
141
+ Fedora::Repository.instance.expects(:find_objects).returns([mock_obj])
142
+ ActiveFedora::Base.new(:pid=>"test:1").inner_object.should equal(mock_obj)
143
+ end
144
+ it "should save the inner_object to fedora if it does not already exist" do
145
+ pending
146
+ Fedora::Repository.instance.expects(:save)
147
+ Fedora::Repository.instance.expects(:find_objects).returns([])
148
+ ActiveFedora::Base.new(:pid=>"test:1")
149
+ end
150
+ end
151
+
152
+ end
153
+
154
+
155
+ it 'should provide #find_by_solr' do
156
+ SpecModel::Basic.should respond_to(:find)
157
+ end
158
+
159
+ describe '#find_by_solr' do
160
+ it "(:all) should query solr for all objects with :active_fedora_model_s of self.class and return a Solr result" do
161
+ mock_solr = mock("SolrConnection")
162
+ mock_response = mock("SolrResponse")
163
+ mock_solr.expects(:query).with('active_fedora_model_s:SpecModel\:\:Basic', {}).returns(mock_response)
164
+ ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
165
+
166
+ SpecModel::Basic.find_by_solr(:all).should equal(mock_response)
167
+ end
168
+ it "(String) should query solr for an object with the given id and return the Solr Result" do
169
+ mock_solr = mock("SolrConnection")
170
+ mock_response = mock("SolrResponse")
171
+ mock_solr.expects(:query).with('id:changeme\:30', {}).returns(mock_response)
172
+ ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
173
+
174
+ SpecModel::Basic.find_by_solr("changeme:30").should equal(mock_response)
175
+ end
176
+ end
177
+
178
+ describe "load_instance" do
179
+ it "should use Repository.find_model to instantiate an object" do
180
+ mock_repo = mock("repo")
181
+ mock_repo.expects(:find_model).with("_PID_", SpecModel::Basic)
182
+ Fedora::Repository.expects(:instance).returns(mock_repo)
183
+ SpecModel::Basic.load_instance("_PID_")
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,50 @@
1
+ require File.join( File.dirname(__FILE__), "../spec_helper" )
2
+
3
+ require 'active_fedora'
4
+ require 'active_fedora/model'
5
+ require 'mocha'
6
+ include Mocha::Standalone
7
+
8
+ describe ActiveFedora::Property do
9
+
10
+ before(:all) do
11
+ @test_property = ActiveFedora::Property.new(stub("model_stub"),"file_name", :string)
12
+ end
13
+
14
+ it 'should provide .new' do
15
+ ActiveFedora::Property.should respond_to(:new)
16
+ end
17
+
18
+ describe '.new' do
19
+
20
+ it 'should use assertions to check types of incoming args'
21
+
22
+ # This could rely on property_set and in turn serialize to a 'properties' metadata datastream...
23
+ it 'should add corresponding field to the properties datastream'
24
+
25
+ it 'should add field to repository indexer (ie. solr)'
26
+ end
27
+
28
+ it 'should provide .name' do
29
+ ActiveFedora::Property.should respond_to(:name)
30
+ end
31
+
32
+ describe '.name' do
33
+ it 'should return the value of the name attribute' do
34
+
35
+ end
36
+ end
37
+
38
+ it 'should provide .instance_variable_name' do
39
+ #ActiveFedora::Property.should respond_to(:instance_variable_name)
40
+
41
+ @test_property.should respond_to(:instance_variable_name)
42
+ end
43
+
44
+ describe '.instance_variable_name' do
45
+ it 'should return the value of the name attribute with an @ appended' do
46
+ @test_property.instance_variable_name.should eql("@#{@test_property.name}")
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,177 @@
1
+ require File.join( File.dirname(__FILE__), "../spec_helper" )
2
+
3
+ require 'active_fedora'
4
+ require 'xmlsimple'
5
+
6
+ describe ActiveFedora::QualifiedDublinCoreDatastream do
7
+
8
+ before(:all) do
9
+ # Load Sample OralHistory Model
10
+ require File.join( File.dirname(__FILE__), "..", "samples","oral_history_sample_model" )
11
+ @dc_elements = [:contributor, :coverage, :creator, :date, :description, :format, :identifier, :language, :publisher, :relation, :rights, :source]
12
+ @dc_terms = []
13
+ end
14
+
15
+ before(:each) do
16
+ Fedora::Repository.instance.stubs(:nextid).returns("_nextid_")
17
+ @test_ds = ActiveFedora::QualifiedDublinCoreDatastream.new
18
+ end
19
+ it "from_xml should parse everything correctly" do
20
+ #originally just tested that lcsh encoding and stuff worked, but the other stuff is worth testing
21
+ mockr= mock('repo')
22
+ mockr.expects(:nextid).returns("meh:leh")
23
+ Fedora::Repository.stubs(:instance).returns(mockr)
24
+ tmpl = OralHistorySampleModel.new.datastreams['dublin_core']
25
+
26
+ tmpl.expects(:subject_append).with('sh1')
27
+ tmpl.expects(:subject_append).with('sh2')
28
+ tmpl.expects(:subject_append).with('kw2')
29
+ tmpl.expects(:subject_append).with('kw1')
30
+ tmpl.expects(:spatial_append).with('sp1')
31
+ tmpl.expects(:spatial_append).with('sp2')
32
+ tmpl.expects(:language_append).with('English')
33
+ tmpl.expects(:alternative_append).with('alt')
34
+ tmpl.expects(:title_append).with('title')
35
+ tmpl.expects(:temporal_append).with('tmp')
36
+ tmpl.expects(:extent_append).with('extent')
37
+ tmpl.expects(:medium_append).with('medium')
38
+ tmpl.expects(:format_append).with('audio/x-wav')
39
+ tmpl.expects(:subject_heading_append).with('sh1')
40
+ tmpl.expects(:subject_heading_append).with('sh2')
41
+ tmpl.expects(:creator_append).with('creator')
42
+ tmpl.expects(:type_append).with('sound')
43
+ tmpl.expects(:rights_append).with('rights')
44
+ tmpl.expects(:publisher_append).with('jwa')
45
+ tmpl.expects(:description_append).with('desc')
46
+
47
+ sample = File.join(File.dirname(__FILE__), '../samples/oh_qdc.xml')
48
+ z = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(tmpl, REXML::Document.new(File.open(sample)).root.elements.first)
49
+ z.should === tmpl
50
+ end
51
+
52
+ it "should create the right number of fields" do
53
+ ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS.size.should == 65
54
+ end
55
+
56
+ it "should have unmodifiable constants" do
57
+ proc {ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS<<:foo}.should raise_error(TypeError, 'can\'t modify frozen array')
58
+
59
+ end
60
+
61
+ it "should have identity in and out" do
62
+ sample = File.join(File.dirname(__FILE__), '../samples/oh_qdc.xml')
63
+ tmpl = OralHistorySampleModel.new.datastreams['dublin_core']
64
+ z = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(tmpl, REXML::Document.new(File.open(sample)).root.elements.first)
65
+ y = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(tmpl, REXML::Document.new(z.to_dc_xml))
66
+ y.to_dc_xml.should == z.to_dc_xml
67
+ end
68
+
69
+ it "should handle arbitrary attribs" do
70
+ tmpl = OralHistorySampleModel.new.datastreams['dublin_core']
71
+ tmpl.field :mycomplicated, :string, :xml_node=>'alt', :element_attrs=>{:foo=>'bar'}
72
+ tmpl.mycomplicated_values='fubar'
73
+ tmpl.to_dc_xml.should == '<dc xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:dcterms=\'http://purl.org/dc/terms/\'><dcterms:alt foo=\'bar\'>fubar</dcterms:alt></dc>'
74
+
75
+ end
76
+
77
+
78
+
79
+ it "should parse dcterms and dcelements from xml" do
80
+ doc = REXML::Document.new(File.open(File.dirname(__FILE__)+'/../fixtures/changeme155.xml'), :force_array=>true)
81
+ stream = doc.elements['//foxml:datastream[@ID=\'dublin_core\']']
82
+ n = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(ActiveFedora::QualifiedDublinCoreDatastream.new, stream)
83
+ n.spatial_values.should == ["Boston [7013445]", "Dorchester [7013575]", "Roxbury [7015002]"]
84
+ n.title_values.should == ["Oral history with Frances Addelson, 1997 November 14"]
85
+ n.dirty?.should == false
86
+
87
+ end
88
+
89
+
90
+ it "should default dc elements to :multiple=>true" do
91
+ @test_ds.fields.values.each do |s|
92
+ s.has_key?(:multiple).should == true
93
+ end
94
+ end
95
+
96
+ after(:each) do
97
+ end
98
+
99
+ describe '#new' do
100
+ it 'should provide #new' do
101
+ ActiveFedora::QualifiedDublinCoreDatastream.should respond_to(:new)
102
+ end
103
+
104
+ it 'should initialize an object with fields for all DC elements' do
105
+ @dc_elements.each do |el|
106
+ @test_ds.fields.should_not be_nil
107
+ @test_ds.fields.should have_key("#{el.to_s}".to_sym)
108
+ end
109
+ end
110
+
111
+ it 'should respond to getters and setters for all DC elements' do
112
+ @dc_elements.each do |el|
113
+ @test_ds.should respond_to("#{el.to_s}_values")
114
+ @test_ds.should respond_to("#{el.to_s}_values=")
115
+ eval("@test_ds.#{el.to_s}_values").class.should == Array
116
+ eval("@test_ds.#{el.to_s}_values = ['test_value']").should == ['test_value']
117
+ end
118
+ end
119
+
120
+ end
121
+
122
+ describe '.set_blob_for_save' do
123
+ it "should call .blob= with to_dc_xml" do
124
+ @test_ds.expects(:blob=).with(@test_ds.to_dc_xml)
125
+ @test_ds.set_blob_for_save
126
+ end
127
+ end
128
+
129
+ describe '.to_dc_xml' do
130
+
131
+ it 'should respond to .to_dc_xml' do
132
+ @test_ds.should respond_to(:to_dc_xml)
133
+ end
134
+
135
+
136
+ #
137
+ # I think the fields should just be tracked as a REXML::Document internally. Too much BS otherwise.
138
+ #
139
+
140
+
141
+ it 'should output the fields hash as Qualified Dublin Core XML' do
142
+ sample_xml = "<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><dcterms:title>title1</dcterms:title><dcterms:publisher>publisher1</dcterms:publisher><dcterms:creator>creator1</dcterms:creator><dcterms:creator>creator2</dcterms:creator></dc>"
143
+ #@test_ds.expects(:fields).returns({:publisher => ["publisher1"], :creator => ["creator1", "creator2"], :title => ["title1"]})
144
+ @test_ds.publisher_values = ["publisher1"]
145
+ @test_ds.creator_values = ["creator1", "creator2"]
146
+ @test_ds.title_values = ["title1"]
147
+
148
+ dc_xml = XmlSimple.xml_in(@test_ds.to_dc_xml)
149
+ dc_xml.should == XmlSimple.xml_in(sample_xml)
150
+ end
151
+
152
+ it 'should not include :type information' do
153
+ @test_ds.publisher_values = ["publisher1"]
154
+ dc_xml = XmlSimple.xml_in(@test_ds.to_dc_xml)
155
+ @test_ds.fields[:publisher].should have_key(:type)
156
+ dc_xml["publisher"].should_not include("type")
157
+ end
158
+
159
+ it "should use specified :xml_node if it is available in the field Hash" do
160
+ @test_ds.stubs(:fields).returns({:myfieldname => {:values => ["sample spatial coverage"], :xml_node => "nodename" }})
161
+ REXML::Document.new(@test_ds.to_dc_xml).elements['./dc/dcterms:nodename'].text.should == 'sample spatial coverage'
162
+ end
163
+
164
+ it "should use specified :xml_node if it was specified when .field was called" do
165
+ sample_xml = "<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><dcterms:nodename>sample spatial coverage</dcterms:nodename></dc>"
166
+ @test_ds.field :myfieldname, :string, :xml_node => "nodename"
167
+ @test_ds.myfieldname_values = "sample spatial coverage"
168
+ dc_xml = XmlSimple.xml_in(@test_ds.to_dc_xml)
169
+ dc_xml.should == XmlSimple.xml_in(sample_xml)
170
+ end
171
+
172
+ it "should only apply encoding info and other qualifiers to the nodes that explicitly declare it" do
173
+ end
174
+ end
175
+
176
+
177
+ end
@@ -0,0 +1,77 @@
1
+ require File.join( File.dirname(__FILE__), "../spec_helper" )
2
+
3
+ require 'active_fedora'
4
+ require "rexml/document"
5
+ require 'mocha'
6
+
7
+ include Mocha::Standalone
8
+
9
+ describe ActiveFedora::Relationship do
10
+
11
+ %/
12
+ module ModelSpec
13
+ class AudioRecord
14
+ include ActiveFedora::Model
15
+
16
+ relationship "parents", :is_part_of, [nil, :oral_history]
17
+ end
18
+
19
+ class OralHistory
20
+ include ActiveFedora::Model
21
+
22
+ relationship "parts", :is_part_of, [:audio_record], :inbound => true
23
+ end
24
+ /%
25
+ before(:each) do
26
+ @test_relationship = ActiveFedora::Relationship.new
27
+ end
28
+
29
+ it "should provide #new" do
30
+ ActiveFedora::Relationship.should respond_to(:new)
31
+ end
32
+
33
+ describe "#new" do
34
+ test_relationship = ActiveFedora::Relationship.new(:subject => "demo:5", :predicate => "isMemberOf", :object => "demo:10")
35
+
36
+ test_relationship.subject.should == "info:fedora/demo:5"
37
+ test_relationship.predicate.should == "isMemberOf"
38
+ test_relationship.object.should == "info:fedora/demo:10"
39
+ end
40
+
41
+ describe "#subject=" do
42
+ it "should turn strings into fedora URIs" do
43
+ @test_relationship.subject = "demo:6"
44
+ @test_relationship.subject.should == "info:fedora/demo:6"
45
+ @test_relationship.subject = "info:fedora/demo:7"
46
+ @test_relationship.subject.should == "info:fedora/demo:7"
47
+ end
48
+ it "should use the pid of the passed object if it responds to #pid" do
49
+ mock_fedora_object = stub("mock_fedora_object", :pid => "demo:stub_pid")
50
+ @test_relationship.subject = mock_fedora_object
51
+ @test_relationship.subject.should == "info:fedora/#{mock_fedora_object.pid}"
52
+ end
53
+ end
54
+
55
+ describe "#object=" do
56
+ it "should turn strings into Fedora URIs" do
57
+ @test_relationship.object = "demo:11"
58
+ @test_relationship.object.should == "info:fedora/demo:11"
59
+ end
60
+ it "should use the pid of the passed object if it responds to #pid" do
61
+ mock_fedora_object = stub("mock_fedora_object", :pid => "demo:stub_pid")
62
+ @test_relationship.object = mock_fedora_object
63
+ @test_relationship.object.should == "info:fedora/#{mock_fedora_object.pid}"
64
+ end end
65
+
66
+ describe "#predicate=" do
67
+ it "should default to setting the argument itself as the new subject" do
68
+ @test_relationship.predicate = "isComponentOf"
69
+ @test_relationship.predicate.should == "isComponentOf"
70
+ end
71
+ end
72
+
73
+ describe "#to_hash" do
74
+ it "should return a hash of structure {subject => {predicate => [object]}}"
75
+ end
76
+
77
+ end