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,20 @@
1
+ en:
2
+ hydramata:
3
+ work:
4
+ works:
5
+ work_type_with_translated_name:
6
+ name: I Am Translating the Name for Application Usage!
7
+ work_type_translated:
8
+ fieldsets:
9
+ property_set_translated:
10
+ name: I Am a Translated Property Set for a Translated Work Type!
11
+ properties:
12
+ property_translated:
13
+ name: I Am a Translated Property for a Translated Work Type!
14
+ name: I Am a Translated Work Type!
15
+ fieldsets:
16
+ property_set_translated:
17
+ name: I Am a Translated Property Set with a non-Translated Work Type!
18
+ properties:
19
+ property_translated:
20
+ name: I Am a Translated Property with a non-Translated Work Type!
@@ -0,0 +1,83 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/entity_form'
3
+ require 'hydramata/works/linters'
4
+ require 'hydramata/works/entity'
5
+
6
+ module Hydramata
7
+ module Works
8
+ describe EntityForm do
9
+ let(:identity) { nil }
10
+ let(:validation_service) { double(call: true) }
11
+ let(:entity) do
12
+ Entity.new(identity: identity) do |entity|
13
+ entity.properties << { predicate: :first_name, value: 'Jeremy' }
14
+ end
15
+ end
16
+ subject { described_class.new(entity, validation_service: validation_service) }
17
+
18
+ it_behaves_like 'ActiveModel'
19
+
20
+ context 'valid?' do
21
+ context 'when errors are not set' do
22
+ let(:validation_service) { double(call: true) }
23
+ it 'should be true (eg valid)' do
24
+ expect(subject.valid?).to be_truthy
25
+ expect(validation_service).to have_received(:call)
26
+ end
27
+ end
28
+ context 'when errors are encountered' do
29
+ let(:validation_service) { ->(entity) { entity.errors.add(:base, 'Found some errors!') } }
30
+ it 'should be false (eg not valid)' do
31
+ expect(subject.valid?).to be_falsey
32
+ end
33
+ end
34
+ end
35
+
36
+ it 'has a meaningful inspect' do
37
+ expect(subject.inspect).to include("EntityForm")
38
+ expect(subject.inspect).to include(entity.inspect)
39
+ end
40
+
41
+ context 'entity\'s properties' do
42
+ it 'should respond to a given predicate' do
43
+ expect(subject).to respond_to(:first_name)
44
+ end
45
+
46
+ it 'should expose the predicate name as a method' do
47
+ expect(subject.first_name).to eq(['Jeremy'])
48
+ end
49
+ end
50
+
51
+ context 'with collaborating entity without an identity' do
52
+ let(:identity) { '' }
53
+ it 'is not #persisted?' do
54
+ expect(subject.persisted?).to be_falsey
55
+ end
56
+
57
+ it 'has a nil #to_param' do
58
+ expect(subject.to_param).to be_nil
59
+ end
60
+
61
+ it 'has a nil #to_key' do
62
+ expect(subject.to_key).to be_nil
63
+ end
64
+ end
65
+
66
+ context 'with collaborating entity with an identity' do
67
+ let(:identity) { '1234' }
68
+ it 'is #persisted?' do
69
+ expect(subject.persisted?).to be_truthy
70
+ end
71
+
72
+ it 'uses the entity#identity to derive #to_param' do
73
+ expect(subject.to_param).to eq(identity)
74
+ end
75
+
76
+ it 'uses the entity#identity to derive #to_key' do
77
+ expect(subject.to_key).to eq([identity])
78
+ end
79
+
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/validation_service'
3
+ require 'hydramata/works/entity_form'
4
+ require 'hydramata/works/predicate'
5
+ require 'hydramata/works/entity'
6
+ require 'active_model/validations/presence'
7
+
8
+ module Hydramata
9
+ module Works
10
+ describe ValidationService do
11
+ let(:title) { nil }
12
+ let(:title_predicate) { Predicate.new(identity: 'title', validations: { presence: true }) }
13
+ let(:entity) do
14
+ Entity.new(work_type: 'article') do |entity|
15
+ entity.properties << { predicate: title_predicate }
16
+ end
17
+ end
18
+ let(:entity_form) { EntityForm.new(entity) }
19
+ subject { described_class }
20
+
21
+ context '#call' do
22
+ it 'runs validations attached to each predicate' do
23
+ expect { subject.call(entity_form) }.
24
+ to change { entity_form.errors.full_messages }.
25
+ from([]).
26
+ to(['title can\'t be blank'])
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata-works'
3
+
4
+ module Hydramata
5
+ describe Works do
6
+ it 'has a .table_name_prefix to conform to Rails::Engine' do
7
+ expect(described_class.table_name_prefix).to eq('hydramata_works_')
8
+ end
9
+
10
+ it 'has a .use_relative_model_naming? to conform to Rails::Engine' do
11
+ expect(described_class.use_relative_model_naming?).to eq(true)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/conversions/predicate_set'
3
+ require 'hydramata/works/linters/implement_predicate_set_interface_matcher'
4
+
5
+ module Hydramata
6
+ module Works
7
+ describe Conversions do
8
+ include Conversions
9
+
10
+ context '#PredicateSet' do
11
+ it 'should convert a "well-formed" Hash to a PredicateSet object' do
12
+ expect(PredicateSet(identity: 'hello', work_type: 'Work Type')).to implement_predicate_set_interface
13
+ end
14
+
15
+ it 'should raise an error if the Hash is not "well-formed"' do
16
+ expect { PredicateSet(other: 'hello') }.to raise_error
17
+ end
18
+
19
+ it 'should raise an error when input is unexpected' do
20
+ expect { PredicateSet(double) }.to raise_error
21
+ end
22
+
23
+ it 'should raise an error when Array is empty' do
24
+ expect { PredicateSet([]) }.to raise_error
25
+ end
26
+
27
+ it 'should handle an Array of 2 elements' do
28
+ expect(PredicateSet([:fieldset, [:predicate1, :predicate2]])).to implement_predicate_set_interface
29
+ end
30
+
31
+ it 'should handle an Array of 3 elements' do
32
+ expect(PredicateSet([:fieldset, :predicate1, :predicate2])).to implement_predicate_set_interface
33
+ end
34
+
35
+ it 'should handle an Array of 1 element' do
36
+ expect(PredicateSet([:fieldset])).to implement_predicate_set_interface
37
+ end
38
+
39
+ it 'should handle a String' do
40
+ expect(PredicateSet('An Identity')).to implement_predicate_set_interface
41
+ end
42
+
43
+ it 'should use #to_predicate_set for conversion if input responds to #to_predicate_set' do
44
+ object = double(to_predicate_set: PredicateSet.new(identity: 'hello'))
45
+ expect(PredicateSet(object)).to implement_predicate_set_interface
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/conversions/predicate'
3
+ require 'hydramata/works/linters/implement_predicate_interface_matcher'
4
+
5
+ module Hydramata
6
+ module Works
7
+ describe Conversions do
8
+ include Conversions
9
+
10
+ context '#Predicate' do
11
+ it 'should convert a String to a Predicate object' do
12
+ expect(Predicate('hello')).to implement_predicate_interface
13
+ end
14
+
15
+ it 'should convert a Symbol to a Predicate object' do
16
+ expect(Predicate(:hello)).to implement_predicate_interface
17
+ end
18
+
19
+ it 'should return the same predicate if a Predicate is given' do
20
+ predicate = Predicate(:hello)
21
+ expect(Predicate(predicate).object_id).to eq(predicate.object_id)
22
+ end
23
+
24
+ it 'should convert a "well-formed" Hash to a Predicate object' do
25
+ expect(Predicate(identity: 'hello')).to implement_predicate_interface
26
+ end
27
+
28
+ it 'should raise an error if the Hash is not "well-formed"' do
29
+ expect { Predicate(other: 'hello') }.to raise_error
30
+ end
31
+
32
+ it 'should raise an error object is unexpected' do
33
+ expect { Predicate([]) }.to raise_error
34
+ end
35
+
36
+ it 'should converate an object that responds to #to_predicate to a predicate' do
37
+ object = double(to_predicate: Predicate.new)
38
+ expect(Predicate(object)).to implement_predicate_interface
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/entity'
3
+ require 'hydramata/works/presentation_structure'
4
+ require 'hydramata/works/conversions/presented_fieldsets'
5
+
6
+ module Hydramata
7
+ module Works
8
+ describe Conversions do
9
+ include Conversions
10
+
11
+ context '#PresentedFieldsets' do
12
+ let(:entity) do
13
+ Entity.new.tap do |entity|
14
+ entity.work_type = 'Hello'
15
+ entity.properties << { predicate: :title, value: 'Hello' }
16
+ entity.properties << { predicate: :title, value: 'World' }
17
+ entity.properties << { predicate: :title, value: 'Bang!' }
18
+ entity.properties << { predicate: :abstract, value: 'Long Text' }
19
+ entity.properties << { predicate: :abstract, value: 'Longer Text' }
20
+ entity.properties << { predicate: :keyword, value: 'Programming' }
21
+ end
22
+ end
23
+
24
+ let(:presentation_structure) do
25
+ PresentationStructure.new.tap do |struct|
26
+ struct.fieldsets << [:required, [:title]]
27
+ struct.fieldsets << [:optional, [:abstract, :keyword]]
28
+ end
29
+ end
30
+
31
+ it 'should munge together the presentation structure and entity' do
32
+ presented_fieldsets = PresentedFieldsets(entity: entity, presentation_structure: presentation_structure)
33
+
34
+ expect(presented_fieldsets.count).to eq(2)
35
+
36
+ required_fieldset = presented_fieldsets[0]
37
+ expect(required_fieldset.entity).to eq(entity)
38
+ expect(required_fieldset.count).to eq(1)
39
+ expect(required_fieldset.name.to_s).to eq('required')
40
+ expect(required_fieldset[:title].values).to eq(['Hello', 'World', 'Bang!'])
41
+
42
+ optional_fieldset = presented_fieldsets[1]
43
+ expect(optional_fieldset.entity).to eq(entity)
44
+ expect(optional_fieldset.count).to eq(2)
45
+ expect(optional_fieldset.name.to_s).to eq('optional')
46
+ expect(optional_fieldset[:abstract].values).to eq(['Long Text', 'Longer Text'])
47
+ expect(optional_fieldset[:keyword].values).to eq(['Programming'])
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/conversions/presenter'
3
+
4
+ module Hydramata
5
+ module Works
6
+ describe Conversions do
7
+ include Conversions
8
+
9
+ context '#Presenter' do
10
+ it 'converts an object that implements #to_presenter' do
11
+ object = double(to_presenter: :presenter)
12
+ expect(Presenter(object)).to eq(:presenter)
13
+ end
14
+
15
+ it 'does not convert an object that does not implement a #to_presenter' do
16
+ object = double
17
+ expect(Presenter(object)).to eq(object)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/conversions/property_set'
3
+ require 'hydramata/works/conversions/predicate_set'
4
+ require 'hydramata/works/linters/implement_property_set_interface_matcher'
5
+
6
+ module Hydramata
7
+ module Works
8
+ describe Conversions do
9
+ include Conversions
10
+
11
+ context '#PropertySet' do
12
+ it 'should convert an object that implements #to_property_set' do
13
+ object = double('Object', to_property_set: PropertySet.new )
14
+ expect(PropertySet(object)).to implement_property_set_interface
15
+ end
16
+
17
+ it 'should raise an error object is unexpected' do
18
+ expect { PropertySet([]) }.to raise_error
19
+ end
20
+
21
+ it 'should convert a PredicateSet to a PropertySet' do
22
+ object = PredicateSet.new(identity: 'hello')
23
+ expect(PropertySet(object)).to implement_property_set_interface
24
+ end
25
+
26
+ it 'should preserive a PropertySet as that PropertySet' do
27
+ object = PropertySet.new(identity: 'hello')
28
+ expect(PropertySet(object).object_id).to eq(object.object_id)
29
+ end
30
+
31
+ it 'should attempt to convert the input to a PredicateSet then a PropertySet' do
32
+ object_to_convert = { identity: 'hello' }
33
+ expect(self).
34
+ to receive(:PredicateSet).
35
+ with(object_to_convert).
36
+ and_call_original
37
+ expect(PropertySet(object_to_convert)).to implement_property_set_interface
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/conversions/property'
3
+
4
+ module Hydramata
5
+ module Works
6
+ describe Conversions do
7
+ include Conversions
8
+
9
+ context '#Property' do
10
+
11
+ context 'with 0 args' do
12
+ it 'should raise an error' do
13
+ expect { Property() }.to raise_error
14
+ end
15
+ end
16
+
17
+ context 'with 1 arg' do
18
+ it 'should convert a Predicate to a Property' do
19
+ predicate = Predicate.new(identity: 'id')
20
+ expect(Property(predicate)).to be_an_instance_of(Property)
21
+ end
22
+
23
+ it 'should attempt to convert something odd to a Property via a Predicate conversion' do
24
+ object_to_convert = double
25
+ expect(self).
26
+ to receive(:Predicate).
27
+ with(object_to_convert).
28
+ and_return(Predicate.new)
29
+ expect(Property(object_to_convert)).to be_an_instance_of(Property)
30
+ end
31
+
32
+ it 'should preserve a Property' do
33
+ property = Property.new(predicate: 'a predicate')
34
+ expect(Property(property).object_id).to eq(property.object_id)
35
+ end
36
+
37
+ it 'should convert a Hash to a property' do
38
+ expect(Property(predicate: 'a predicate')).to be_an_instance_of(Property)
39
+ end
40
+
41
+ it 'should convert a Hash with values' do
42
+ expect(Property(predicate: 'a predicate', values: [1,2,3]).values).to eq([1,2,3])
43
+ end
44
+ end
45
+
46
+ context 'with 2 args' do
47
+ it 'should convert two arguements to a Property' do
48
+ expect(Property('a predicate', 'a value')).to be_an_instance_of(Property)
49
+ end
50
+
51
+ it 'should gracefully handle two arguements where last arguement is an array' do
52
+ expect(Property('a predicate', ['a value']).values).to eq([['a value']])
53
+ end
54
+
55
+ it 'should preserve the property but append the values' do
56
+ property = Property.new(predicate: 'a predicate')
57
+ expect {
58
+ Property(property, 'hello')
59
+ }.
60
+ to change { property.values }.
61
+ from([]).
62
+ to(['hello'])
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_fast_helper'
2
+ require 'hydramata/works/conversions/translation_key_fragment'
3
+
4
+ module Hydramata
5
+ module Works
6
+ describe Conversions do
7
+ include Conversions
8
+ context 'TranslationKeyFragment' do
9
+ context 'successfully converts' do
10
+ it 'a String' do
11
+ expect(TranslationKeyFragment('hello')).to eq('hello')
12
+ end
13
+
14
+ it 'to a normalized format' do
15
+ expect(TranslationKeyFragment('Hello World: Welcome')).to eq('hello_world_welcome')
16
+ end
17
+
18
+ it 'a Symbol' do
19
+ expect(TranslationKeyFragment(:hello)).to eq('hello')
20
+ end
21
+
22
+ it 'a Hash with :to_translation_key_fragment key' do
23
+ object = { to_translation_key_fragment: 'fragment' }
24
+ expect(TranslationKeyFragment(object)).to eq('fragment')
25
+ end
26
+
27
+ it 'an object that implements #to_translation_key_fragment' do
28
+ object = double(to_translation_key_fragment: 'fragment')
29
+ expect(TranslationKeyFragment(object)).to eq('fragment')
30
+ end
31
+ end
32
+
33
+ context 'will not convert' do
34
+ it 'an unexpected object' do
35
+ expect { TranslationKeyFragment(double) }.to raise_error
36
+ end
37
+
38
+ it 'nil' do
39
+ expect { TranslationKeyFragment(nil) }.to raise_error
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end