hydramata-works 0.0.1.prerelease

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.hound.yml +818 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +20 -0
  6. data/CONTRIBUTING.md +220 -0
  7. data/Gemfile +36 -0
  8. data/Guardfile +36 -0
  9. data/LICENSE +15 -0
  10. data/README.md +36 -0
  11. data/Rakefile +47 -0
  12. data/TODO.md +74 -0
  13. data/VISION.md +19 -0
  14. data/app/forms/hydramata/works/entity_form.rb +92 -0
  15. data/app/forms/hydramata/works/validation_service.rb +78 -0
  16. data/app/models/hydramata/works/data_definition.rb +57 -0
  17. data/app/models/hydramata/works/entities.rb +11 -0
  18. data/app/models/hydramata/works/entity.rb +75 -0
  19. data/app/models/hydramata/works/predicate.rb +35 -0
  20. data/app/models/hydramata/works/predicate_presentation_sequences/storage.rb +29 -0
  21. data/app/models/hydramata/works/predicate_set.rb +44 -0
  22. data/app/models/hydramata/works/predicate_sets/storage.rb +45 -0
  23. data/app/models/hydramata/works/predicates.rb +14 -0
  24. data/app/models/hydramata/works/predicates/storage.rb +33 -0
  25. data/app/models/hydramata/works/presentation_structure.rb +29 -0
  26. data/app/models/hydramata/works/property.rb +72 -0
  27. data/app/models/hydramata/works/property_set.rb +89 -0
  28. data/app/models/hydramata/works/validations.rb +6 -0
  29. data/app/models/hydramata/works/value.rb +34 -0
  30. data/app/models/hydramata/works/work_type.rb +49 -0
  31. data/app/models/hydramata/works/work_types.rb +14 -0
  32. data/app/models/hydramata/works/work_types/storage.rb +42 -0
  33. data/app/parsers/hydramata/works/datastream_parser.rb +36 -0
  34. data/app/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser.rb +60 -0
  35. data/app/parsers/hydramata/works/datastream_parsers/simple_xml_parser.rb +27 -0
  36. data/app/parsers/hydramata/works/predicate_parser.rb +31 -0
  37. data/app/parsers/hydramata/works/predicate_parsers/simple_parser.rb +13 -0
  38. data/app/parsers/hydramata/works/validations_parser.rb +22 -0
  39. data/app/parsers/hydramata/works/value_parser.rb +26 -0
  40. data/app/parsers/hydramata/works/value_parsers.rb +27 -0
  41. data/app/parsers/hydramata/works/value_parsers/date_parser.rb +13 -0
  42. data/app/parsers/hydramata/works/value_parsers/interrogation_parser.rb +18 -0
  43. data/app/parsers/hydramata/works/value_parsers/simple_parser.rb +14 -0
  44. data/app/presenters/hydramata/works/base_presenter.rb +146 -0
  45. data/app/presenters/hydramata/works/dom_attributes_builder.rb +24 -0
  46. data/app/presenters/hydramata/works/entity_presenter.rb +67 -0
  47. data/app/presenters/hydramata/works/fieldset_presenter.rb +54 -0
  48. data/app/presenters/hydramata/works/property_presenter.rb +51 -0
  49. data/app/presenters/hydramata/works/value_presenter.rb +60 -0
  50. data/app/renderers/hydramata/works/entity_renderer.rb +45 -0
  51. data/app/views/hydramata/works/fieldsets/_edit.html.erb +4 -0
  52. data/app/views/hydramata/works/fieldsets/_show.html.erb +8 -0
  53. data/app/views/hydramata/works/fieldsets/_show.json.jbuilder +8 -0
  54. data/app/views/hydramata/works/properties/_edit.html.erb +12 -0
  55. data/app/views/hydramata/works/properties/_show.html.erb +3 -0
  56. data/app/views/hydramata/works/properties/_show.json.jbuilder +1 -0
  57. data/app/views/hydramata/works/works/_edit.html.erb +8 -0
  58. data/app/views/hydramata/works/works/_new.html.erb +8 -0
  59. data/app/views/hydramata/works/works/_show.html.erb +3 -0
  60. data/app/views/hydramata/works/works/_show.json.jbuilder +13 -0
  61. data/app/wranglers/hydramata/works/fedora_wrangler.rb +66 -0
  62. data/bin/rails +12 -0
  63. data/db/migrate/20140606132349_create_hydramata_work_predicates.rb +13 -0
  64. data/db/migrate/20140606132350_create_hydramata_work_types.rb +9 -0
  65. data/db/migrate/20140606132351_create_hydramata_work_predicate_sets.rb +13 -0
  66. data/db/migrate/20140606132352_create_hydramata_work_predicate_presentation_sequences.rb +12 -0
  67. data/db/migrate/20140623200635_add_validations_to_predicates.rb +5 -0
  68. data/db/migrate/20140627134133_adding_item_type_schema_dot_org_to_work_type.rb +5 -0
  69. data/db/migrate/20140627140840_adding_item_prop_schema_dot_org_to_predicate.rb +5 -0
  70. data/db/seeds.rb +36 -0
  71. data/documents/administrative-set-strawperson.md +45 -0
  72. data/documents/diagrams/hydramata-refactor-tasks.dot +88 -0
  73. data/documents/diagrams/hydramata-sip-dip-aip.dot +88 -0
  74. data/documents/diagrams/hydramata-work-architecture.dot +129 -0
  75. data/documents/diagrams/hydramata-work-subcomponents.dot +36 -0
  76. data/documents/diagrams/map-from-database-to-work-object.dot +44 -0
  77. data/documents/diagrams/map-from-fedora-to-work-object.dot +51 -0
  78. data/documents/diagrams/map-from-input-to-work-object.dot +37 -0
  79. data/documents/diagrams/map-from-work-object-to-database.dot +31 -0
  80. data/documents/diagrams/work-rendering.dot +53 -0
  81. data/documents/diagrams/work-structure.dot +32 -0
  82. data/documents/handling-work.md +224 -0
  83. data/documents/high-level-stories.md +105 -0
  84. data/documents/hydramata-components.md +82 -0
  85. data/documents/interface-between-work-and-permissions.md +131 -0
  86. data/documents/interface-between-work-and-workflow.md +6 -0
  87. data/documents/timeline.md +75 -0
  88. data/fs +3 -0
  89. data/gemfiles/rails4.1.gemfile +12 -0
  90. data/gemfiles/rails4.gemfile +13 -0
  91. data/hydramata-works.gemspec +43 -0
  92. data/lib/hydramata-works.rb +23 -0
  93. data/lib/hydramata/works/conversions.rb +21 -0
  94. data/lib/hydramata/works/conversions/exceptions.rb +18 -0
  95. data/lib/hydramata/works/conversions/predicate.rb +22 -0
  96. data/lib/hydramata/works/conversions/predicate_set.rb +28 -0
  97. data/lib/hydramata/works/conversions/presented_fieldsets.rb +28 -0
  98. data/lib/hydramata/works/conversions/presenter.rb +13 -0
  99. data/lib/hydramata/works/conversions/property.rb +31 -0
  100. data/lib/hydramata/works/conversions/property_set.rb +23 -0
  101. data/lib/hydramata/works/conversions/translation_key_fragment.rb +20 -0
  102. data/lib/hydramata/works/conversions/value.rb +20 -0
  103. data/lib/hydramata/works/conversions/work_type.rb +26 -0
  104. data/lib/hydramata/works/engine.rb +31 -0
  105. data/lib/hydramata/works/linters.rb +99 -0
  106. data/lib/hydramata/works/linters/implement_data_definition_interface_matcher.rb +17 -0
  107. data/lib/hydramata/works/linters/implement_entity_interface_matcher.rb +16 -0
  108. data/lib/hydramata/works/linters/implement_predicate_interface_matcher.rb +17 -0
  109. data/lib/hydramata/works/linters/implement_predicate_set_interface_matcher.rb +8 -0
  110. data/lib/hydramata/works/linters/implement_property_set_interface_matcher.rb +8 -0
  111. data/lib/hydramata/works/linters/implement_value_interface_matcher.rb +8 -0
  112. data/lib/hydramata/works/linters/implement_work_type_interface_matcher.rb +13 -0
  113. data/lib/hydramata/works/linters/interface_matcher_builder.rb +36 -0
  114. data/lib/hydramata/works/translator.rb +67 -0
  115. data/lib/hydramata/works/version.rb +5 -0
  116. data/lib/hydramata_works.rb +2 -0
  117. data/lib/tasks/hydramata_work_tasks.rake +4 -0
  118. data/run_each_spec_in_isolation +16 -0
  119. data/run_each_spec_in_isolation.txt +110 -0
  120. data/script/analyzer.rb +124 -0
  121. data/script/fast_specs +22 -0
  122. data/spec/features/fedora_to_in_memory_spec.rb +60 -0
  123. data/spec/features/format_and_view_path_overrides_spec.rb +72 -0
  124. data/spec/features/in_memory_to_output_buffer_spec.rb +109 -0
  125. data/spec/features/instantiate_entity_from_persisted_work_type_spec.rb +26 -0
  126. data/spec/features/new_user_input_to_in_memory_spec.rb +75 -0
  127. data/spec/features/translation_services_spec.rb +107 -0
  128. data/spec/features/validate_entity_based_on_work_type_structure_spec.rb +19 -0
  129. data/spec/fixtures/cassettes/fedora-object.yml +299 -0
  130. data/spec/fixtures/translations.yml +20 -0
  131. data/spec/forms/hydramata/works/entity_form_spec.rb +83 -0
  132. data/spec/forms/hydramata/works/validation_service_spec.rb +32 -0
  133. data/spec/lib/hydramata-work_spec.rb +14 -0
  134. data/spec/lib/hydramata/works/conversions/predicate_set_spec.rb +50 -0
  135. data/spec/lib/hydramata/works/conversions/predicate_spec.rb +43 -0
  136. data/spec/lib/hydramata/works/conversions/presented_fieldsets_spec.rb +52 -0
  137. data/spec/lib/hydramata/works/conversions/presenter_spec.rb +22 -0
  138. data/spec/lib/hydramata/works/conversions/property_set_spec.rb +42 -0
  139. data/spec/lib/hydramata/works/conversions/property_spec.rb +68 -0
  140. data/spec/lib/hydramata/works/conversions/translation_key_fragment_spec.rb +45 -0
  141. data/spec/lib/hydramata/works/conversions/value_spec.rb +36 -0
  142. data/spec/lib/hydramata/works/conversions/work_type_spec.rb +55 -0
  143. data/spec/lib/hydramata/works/translator_spec.rb +81 -0
  144. data/spec/models/hydramata/works/data_definition_spec.rb +53 -0
  145. data/spec/models/hydramata/works/entity_spec.rb +50 -0
  146. data/spec/models/hydramata/works/predicate_presentation_sequences/storage_spec.rb +15 -0
  147. data/spec/models/hydramata/works/predicate_set_spec.rb +63 -0
  148. data/spec/models/hydramata/works/predicate_sets/storage_spec.rb +37 -0
  149. data/spec/models/hydramata/works/predicate_spec.rb +16 -0
  150. data/spec/models/hydramata/works/predicates/storage_spec.rb +78 -0
  151. data/spec/models/hydramata/works/predicates_spec.rb +18 -0
  152. data/spec/models/hydramata/works/presentation_structure_spec.rb +27 -0
  153. data/spec/models/hydramata/works/property_set_spec.rb +135 -0
  154. data/spec/models/hydramata/works/property_spec.rb +74 -0
  155. data/spec/models/hydramata/works/value_spec.rb +61 -0
  156. data/spec/models/hydramata/works/work_type_spec.rb +45 -0
  157. data/spec/models/hydramata/works/work_types/storage_spec.rb +74 -0
  158. data/spec/models/hydramata/works/work_types_spec.rb +16 -0
  159. data/spec/parsers/hydramata/works/datastream_parser_spec.rb +29 -0
  160. data/spec/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser_spec.rb +65 -0
  161. data/spec/parsers/hydramata/works/datastream_parsers/simple_xml_parser_spec.rb +37 -0
  162. data/spec/parsers/hydramata/works/predicate_parser_spec.rb +30 -0
  163. data/spec/parsers/hydramata/works/predicate_parsers/simple_parser_spec.rb +20 -0
  164. data/spec/parsers/hydramata/works/validations_parser_spec.rb +31 -0
  165. data/spec/parsers/hydramata/works/value_parser_spec.rb +22 -0
  166. data/spec/parsers/hydramata/works/value_parsers/simple_parser_spec.rb +20 -0
  167. data/spec/parsers/hydramata/works/value_parsers_spec.rb +36 -0
  168. data/spec/presenters/hydramata/works/base_presenter_spec.rb +111 -0
  169. data/spec/presenters/hydramata/works/dom_attributes_builder_spec.rb +26 -0
  170. data/spec/presenters/hydramata/works/entity_presenter_spec.rb +51 -0
  171. data/spec/presenters/hydramata/works/fieldset_presenter_spec.rb +58 -0
  172. data/spec/presenters/hydramata/works/property_presenter_spec.rb +42 -0
  173. data/spec/presenters/hydramata/works/value_presenter_spec.rb +49 -0
  174. data/spec/renderers/hydramata/works/entity_renderer_spec.rb +25 -0
  175. data/spec/spec_active_record_helper.rb +30 -0
  176. data/spec/spec_fast_helper.rb +12 -0
  177. data/spec/spec_slow_helper.rb +56 -0
  178. data/spec/spec_view_helper.rb +14 -0
  179. data/spec/test_app_templates/lib/generators/test_app_generator.rb +21 -0
  180. data/spec/views/hydramata/works/fieldsets/_edit.html.erb_spec.rb +29 -0
  181. data/spec/views/hydramata/works/fieldsets/_show.html.erb_spec.rb +25 -0
  182. data/spec/views/hydramata/works/properties/_edit.html.erb_spec.rb +22 -0
  183. data/spec/views/hydramata/works/properties/_show.html.erb_spec.rb +22 -0
  184. data/spec/views/hydramata/works/works/_edit.html.erb_spec.rb +23 -0
  185. data/spec/views/hydramata/works/works/_new.html.erb_spec.rb +23 -0
  186. data/spec/views/hydramata/works/works/_show.html.erb_spec.rb +24 -0
  187. data/spec/wranglers/hydramata/works/fedora_wrangler_spec.rb +26 -0
  188. metadata +466 -0
@@ -0,0 +1,29 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/datastream_parser'
3
+ require 'hydramata/works/linters'
4
+
5
+ module Hydramata
6
+ module Works
7
+ describe DatastreamParser do
8
+ context '.parser_for' do
9
+ let(:a_parser) { double('A Parser') }
10
+ let(:parser_finder) { double('Parser Finder', call: a_parser) }
11
+ let(:datastream) { double('Datastream') }
12
+ let(:options) { { parser_finder: parser_finder, datastream: datastream } }
13
+ it 'should find the appropriate parser based on input options' do
14
+ expect(described_class.parser_for(options)).to eq(a_parser)
15
+ expect(parser_finder).to have_received(:call).with(options)
16
+ end
17
+ end
18
+
19
+ context '.call' do
20
+ let(:content) { '<fields>\n <depositor>Username-1</depositor>\n</fields>' }
21
+ let(:datastream) { double('Datastream', content: content, mimeType: 'text/xml') }
22
+ let(:options) { { datastream: datastream } }
23
+ it 'should find the appropriate parser based on input options' do
24
+ expect { |b| described_class.call(options, &b) }.to yield_with_args(predicate: 'depositor', value: 'Username-1')
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/datastream_parsers/rdf_ntriples_parser'
3
+ require 'hydramata/works/linters'
4
+ require 'rdf'
5
+
6
+ module Hydramata
7
+ module Works
8
+ module DatastreamParsers
9
+ describe RdfNtriplesParser do
10
+ it_behaves_like 'a datastream parser'
11
+
12
+ let(:rdf_subject) { 'info:fedora/und:f4752f8687n' }
13
+ let(:rdf_predicate) { 'http://purl.org/dc/terms/dateSubmitted' }
14
+ let(:rdf_object) { "\"#{rdf_object_value}\"^^<http://www.w3.org/2001/XMLSchema#date>" }
15
+ let(:rdf_object_value) { '2014-06-02Z' }
16
+ let(:data) { "<#{rdf_subject}> <#{rdf_predicate}> #{rdf_object} ." }
17
+
18
+ subject { described_class }
19
+
20
+ context '.match?' do
21
+ let(:ntriples_datastream) { double(content: data, mimeType: 'text/plain') }
22
+ let(:not_ntriples_datastream) { double(content: '', mimeType: 'application/xml') }
23
+ it 'should not match when no datastream is provided' do
24
+ expect(described_class.match?).to be_falsey
25
+ end
26
+
27
+ it 'should match when an RDF ntriples datastream is provided' do
28
+ expect(described_class.match?(datastream: ntriples_datastream)).to eq(described_class)
29
+ end
30
+
31
+ it 'should not match when the data stream does not appear to be RDF ntriples' do
32
+ expect(described_class.match?(datastream: not_ntriples_datastream)).to be_falsey
33
+ end
34
+ end
35
+
36
+ context 'with single value encountered' do
37
+ it 'should yield each encountered property' do
38
+ expect { |b| subject.call(data, &b) }.to yield_with_args(predicate: rdf_predicate, value: instance_of(RDF::Literal::Date))
39
+ end
40
+ end
41
+
42
+ context 'with multiple values encountered' do
43
+ let(:rdf_object_1) { "\"#{rdf_object_value_1}\"^^<http://www.w3.org/2001/XMLSchema#date>" }
44
+ let(:rdf_object_2) { "\"#{rdf_object_value_2}\"^^<http://www.w3.org/2001/XMLSchema#date>" }
45
+ let(:rdf_object_value_1) { '2014-06-02Z' }
46
+ let(:rdf_object_value_2) { '2013-05-03Z' }
47
+ let(:data) do
48
+ [
49
+ "<#{rdf_subject}> <#{rdf_predicate}> #{rdf_object_1} .",
50
+ "<#{rdf_subject}> <#{rdf_predicate}> #{rdf_object_2} ."
51
+ ].join("\n")
52
+ end
53
+
54
+ it 'should yield each encountered property' do
55
+ expect { |b| subject.call(data, &b) }.
56
+ to yield_successive_args(
57
+ { predicate: rdf_predicate, value: instance_of(RDF::Literal::Date) },
58
+ { predicate: rdf_predicate, value: instance_of(RDF::Literal::Date) }
59
+ )
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/datastream_parsers/simple_xml_parser'
3
+ require 'hydramata/works/linters'
4
+
5
+ module Hydramata
6
+ module Works
7
+ module DatastreamParsers
8
+ describe SimpleXmlParser do
9
+ it_behaves_like 'a datastream parser'
10
+
11
+ context '.call' do
12
+ let(:content) { '<fields>\n <depositor>Username-1</depositor>\n</fields>' }
13
+ it 'should find the appropriate parser based on input options' do
14
+ expect { |b| described_class.call(content, &b) }.to yield_with_args(predicate: 'depositor', value: 'Username-1')
15
+ end
16
+ end
17
+
18
+ context '.match?' do
19
+ let(:xml_datastream) { double(content: '<xml>', mimeType: 'application/xml') }
20
+ let(:non_xml_datastream) { double(content: '', mimeType: 'text/plain') }
21
+ it 'should not match when no datastream is provided' do
22
+ expect(described_class.match?).to be_falsey
23
+ end
24
+
25
+ it 'should match when an RDF ntriples datastream is provided' do
26
+ expect(described_class.match?(datastream: xml_datastream)).to eq(described_class)
27
+ end
28
+
29
+ it 'should not match when the data stream does not appear to be RDF ntriples' do
30
+ expect(described_class.match?(datastream: non_xml_datastream)).to be_falsey
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/predicate_parser'
3
+
4
+ module Hydramata
5
+ module Works
6
+ describe PredicateParser do
7
+
8
+ let(:predicate) { double('Predicate') }
9
+ let(:value) { double('Value') }
10
+
11
+ context '.parser_for' do
12
+ let(:a_parser) { double('A Parser', call: true) }
13
+ let(:parser_finder) { double('Parser Finder', call: a_parser) }
14
+ let(:options) { { predicate: predicate, work_type: 'article', parser_finder: parser_finder, value: value } }
15
+ it 'should find the appropriate parser based on the predicate and work_type' do
16
+ expect(described_class.parser_for(options)).to eq(a_parser)
17
+ expect(parser_finder).to have_received(:call).with(options)
18
+ end
19
+ end
20
+
21
+ context '.call' do
22
+ let(:options) { { predicate: predicate, work_type: 'article', value: value } }
23
+ it 'coordinates with the parser_finder and calls the found parser' do
24
+ expect { |b| described_class.call(options, &b) }.to yield_with_args(value: value)
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/predicate_parsers/simple_parser'
3
+ require 'hydramata/works/linters'
4
+
5
+ module Hydramata
6
+ module Works
7
+ module PredicateParsers
8
+ describe SimpleParser do
9
+ it_behaves_like 'a predicate parser'
10
+
11
+ context '.call' do
12
+ let(:object) { double('Object') }
13
+ it 'makes no effort to to convert the object' do
14
+ expect { |b| described_class.call(object, &b) }.to yield_with_args(value: object)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/validations_parser'
3
+
4
+ module Hydramata
5
+ module Works
6
+ describe ValidationsParser do
7
+ context '.call' do
8
+ it 'parses simple JSON' do
9
+ expect(described_class.call('{"presence": true}')).to eq({ 'presence' => true })
10
+ end
11
+
12
+ it 'returns an empty hash when input is nil' do
13
+ expect(described_class.call(nil)).to eq({})
14
+ end
15
+
16
+ it 'returns an empty hash when input is an empty string' do
17
+ expect(described_class.call('')).to eq({})
18
+ end
19
+
20
+ it 'returns the same Hash if one is given' do
21
+ object = {a: 1}
22
+ expect(described_class.call(object).object_id).to eq(object.object_id)
23
+ end
24
+
25
+ it 'raises an error on unexpected input' do
26
+ expect{ described_class.call(Object.new) }.to raise_error
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/value_parser'
3
+
4
+ module Hydramata
5
+ module Works
6
+ describe ValueParser do
7
+ let(:predicate) { double('Predicate') }
8
+ let(:value) { double('Value') }
9
+ let(:a_parser) { double('A Parser', call: true) }
10
+ let(:parser_finder) { double('Parser Finder', call: a_parser) }
11
+
12
+ context '.call' do
13
+ let(:options) { { predicate: predicate, work_type: 'article', parser_finder: parser_finder, value: value } }
14
+ it 'coordinate with the parser_finder and calls the found parser' do
15
+ parsed_value = '1234'
16
+ expect(a_parser).to receive(:call).with(value).and_yield(value: parsed_value)
17
+ expect { |b| described_class.call(options, &b) }.to yield_with_args(value: parsed_value)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/value_parsers/simple_parser'
3
+ require 'hydramata/works/linters'
4
+
5
+ module Hydramata
6
+ module Works
7
+ module ValueParsers
8
+ describe SimpleParser do
9
+ it_behaves_like 'a value parser'
10
+
11
+ context '.call' do
12
+ let(:object) { double('Object') }
13
+ it 'makes no effort to to convert the object' do
14
+ expect { |b| described_class.call(object, &b) }.to yield_with_args(value: object, raw_object: object)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/value_parsers'
3
+ require 'hydramata/works/predicate'
4
+
5
+ module Hydramata
6
+ module Works
7
+ module ValueParsers
8
+ class MockParser
9
+ end
10
+ end
11
+ describe ValueParsers do
12
+ let(:predicate) { Predicate.new(value_parser_name: parser_class_name) }
13
+
14
+ context 'existing parser in ValueParsers namespace' do
15
+ let(:parser_class_name) { 'MockParser' }
16
+ it 'should use that' do
17
+ expect(described_class.find(predicate: predicate)).to eq ValueParsers::MockParser
18
+ end
19
+ end
20
+
21
+ context 'an escaped namespace class' do
22
+ let(:parser_class_name) { '::Object' }
23
+ it 'will fallback to the simple parser' do
24
+ expect(described_class.find(predicate: predicate)).to eq ValueParsers::SimpleParser
25
+ end
26
+ end
27
+
28
+ context 'a constant not in the namespace' do
29
+ let(:parser_class_name) { 'MissingParser' }
30
+ it 'will fallback to the simple parser' do
31
+ expect(described_class.find(predicate: predicate)).to eq ValueParsers::SimpleParser
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/base_presenter'
3
+
4
+ module Hydramata
5
+ module Works
6
+ class MockPresentable
7
+ attr_accessor :name
8
+ def initialize
9
+ yield(self) if block_given?
10
+ end
11
+ end
12
+ describe BasePresenter do
13
+ let(:name) { 'hello world' }
14
+ let(:object) { MockPresentable.new { |b| b.name = name } }
15
+ let(:translator) { double('Translator', t: true) }
16
+ subject { described_class.new(object, translator: translator) }
17
+
18
+ it 'should have #presenter_dom_class' do
19
+ expect(subject.presenter_dom_class).to eq('base')
20
+ end
21
+
22
+ it 'should return self for #to_presenter' do
23
+ expect(subject.to_presenter.object_id).to eq(subject.object_id)
24
+ end
25
+
26
+ it 'should have a friendly inspect message, because tracking it down could be a pain' do
27
+ expect(subject.inspect).to include("#{described_class}")
28
+ expect(subject.inspect).to include(object.inspect)
29
+ end
30
+
31
+ it 'should be an instance of the presented object\'s class' do
32
+ expect(subject.instance_of?(object.class)).to be_truthy
33
+ end
34
+
35
+ it 'should also be an instance of the presenter class' do
36
+ expect(subject.instance_of?(described_class)).to be_truthy
37
+ end
38
+
39
+ it 'should translate attribute keys' do
40
+ subject.translate(:name)
41
+ expect(translator).to have_received(:t).with(:name, scopes: [], default: instance_of(Proc))
42
+ end
43
+
44
+ context '#dom_class' do
45
+ it 'extrapolates based on the named object' do
46
+ expect(subject.dom_class).to eq('hello-world')
47
+ end
48
+
49
+ it 'allows a prefix' do
50
+ expect(subject.dom_class(prefix: 'edit')).to eq('edit-hello-world')
51
+ end
52
+
53
+ it 'allows a suffix' do
54
+ expect(subject.dom_class(suffix: '1')).to eq('hello-world-1')
55
+ end
56
+
57
+ it 'allows a prefix and a suffix' do
58
+ expect(subject.dom_class(prefix: 'edit', suffix: '1')).to eq('edit-hello-world-1')
59
+ end
60
+ end
61
+
62
+ context '#render' do
63
+ let(:template) { double('Template', render: true)}
64
+
65
+ it 'should delegate render to the template' do
66
+ subject.render(template: template)
67
+ expect(template).to have_received(:render).with(partial: 'hydramata/works/base/show', object: subject)
68
+ end
69
+
70
+ it 'should handle a partial_prefixes rendering in less and less specificity' do
71
+ subject = described_class.new(object, translator: translator, partial_prefixes: ['article/required', 'article'], presentation_context: 'show', template_missing_exception: [RuntimeError, NoMethodError])
72
+ expect(template).to receive(:render).
73
+ with(partial: 'hydramata/works/base/article/required/show', object: subject).
74
+ ordered.
75
+ and_raise(NoMethodError)
76
+ expect(template).to receive(:render).
77
+ with(partial: 'hydramata/works/base/article/show', object: subject).
78
+ ordered.
79
+ and_raise(RuntimeError)
80
+ expect(template).to receive(:render).
81
+ with(partial: 'hydramata/works/base/show', object: subject).
82
+ ordered
83
+ subject.render(template: template)
84
+ end
85
+
86
+ it 'should stop rendering chain once we sucessfully render a template' do
87
+ subject = described_class.new(object, translator: translator, partial_prefixes: ['article/required', 'article'], presentation_context: 'show', template_missing_exception: [RuntimeError, NoMethodError])
88
+ expect(template).to receive(:render).
89
+ with(partial: 'hydramata/works/base/article/required/show', object: subject).
90
+ ordered.
91
+ and_raise(NoMethodError)
92
+ expect(template).to receive(:render).
93
+ with(partial: 'hydramata/works/base/article/show', object: subject).
94
+ ordered
95
+ expect(template).to_not receive(:render).
96
+ with(partial: 'hydramata/works/base/show', object: subject)
97
+ subject.render(template: template)
98
+ end
99
+
100
+ it 'should raise exception if we are rendering as general as possible' do
101
+ subject = described_class.new(object, translator: translator, presentation_context: 'show')
102
+ expect(template).to receive(:render).
103
+ with(partial: 'hydramata/works/base/show', object: subject).
104
+ and_raise(RuntimeError)
105
+ expect { subject.render(template: template) }.
106
+ to raise_error(RuntimeError)
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/dom_attributes_builder'
3
+
4
+ module Hydramata
5
+ module Works
6
+ describe DomAttributesBuilder do
7
+ let(:context) { double }
8
+
9
+ it 'should append attributes' do
10
+ response = described_class.call(context, { class: ['hello'] }, { class: ['world'] } )
11
+ expect(response).to eq({ class: ['hello', 'world'] })
12
+ end
13
+
14
+ it 'should handle mixed array and string' do
15
+ response = described_class.call(context, { class: 'hello' }, { class: ['world'] } )
16
+ expect(response).to eq({ class: ['hello', 'world'] })
17
+ end
18
+
19
+ it 'should add new keys to returned value' do
20
+ response = described_class.call(context, { data_attribute: ['hello'] }, { class: ['world'] } )
21
+ expect(response).to eq({ data_attribute: ['hello'], class: ['world'] })
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/entity_presenter'
3
+ require 'hydramata/works/entity'
4
+ require 'hydramata/works/linters'
5
+
6
+ module Hydramata
7
+ module Works
8
+ describe EntityPresenter do
9
+ it_behaves_like 'a presented entity'
10
+
11
+ let(:presentation_structure) { double('PresentationStructure') }
12
+ let(:entity) { Entity.new(work_type: 'My Work Type') }
13
+ let(:presented_fieldset_builder) { double('Builder', call: true) }
14
+ let(:template) { double('Template', render: true) }
15
+ subject do
16
+ described_class.new(
17
+ entity: entity,
18
+ presentation_structure: presentation_structure,
19
+ presented_fieldset_builder: presented_fieldset_builder,
20
+ template_missing_exception: [RuntimeError]
21
+ )
22
+ end
23
+
24
+ it 'should have #container_content_tag_attributes' do
25
+ expect(subject.container_content_tag_attributes.keys).to eq([:class, :itemscope, :itemtype])
26
+ end
27
+
28
+ it 'should have #fieldsets that are extracted from the #entity and #presentation_structure' do
29
+ subject.fieldsets
30
+ expect(presented_fieldset_builder).to have_received(:call).with(entity: subject, presentation_structure: presentation_structure)
31
+ end
32
+
33
+ it 'should have a default partial prefixes' do
34
+ expect(subject.partial_prefixes).to eq([['my_work_type']])
35
+ end
36
+
37
+ it 'should render as per the template' do
38
+ expect(template).to receive(:render).
39
+ with(partial: 'hydramata/works/works/my_work_type/show', object: subject).
40
+ ordered.
41
+ and_raise(RuntimeError)
42
+ expect(template).to receive(:render).
43
+ with(partial: 'hydramata/works/works/show', object: subject).
44
+ ordered.
45
+ and_return('YES')
46
+ expect(subject.render(template: template)).to eq('YES')
47
+ end
48
+
49
+ end
50
+ end
51
+ end