hydramata-works 0.0.1.prerelease
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.hound.yml +818 -0
- data/.rspec +2 -0
- data/.travis.yml +20 -0
- data/CONTRIBUTING.md +220 -0
- data/Gemfile +36 -0
- data/Guardfile +36 -0
- data/LICENSE +15 -0
- data/README.md +36 -0
- data/Rakefile +47 -0
- data/TODO.md +74 -0
- data/VISION.md +19 -0
- data/app/forms/hydramata/works/entity_form.rb +92 -0
- data/app/forms/hydramata/works/validation_service.rb +78 -0
- data/app/models/hydramata/works/data_definition.rb +57 -0
- data/app/models/hydramata/works/entities.rb +11 -0
- data/app/models/hydramata/works/entity.rb +75 -0
- data/app/models/hydramata/works/predicate.rb +35 -0
- data/app/models/hydramata/works/predicate_presentation_sequences/storage.rb +29 -0
- data/app/models/hydramata/works/predicate_set.rb +44 -0
- data/app/models/hydramata/works/predicate_sets/storage.rb +45 -0
- data/app/models/hydramata/works/predicates.rb +14 -0
- data/app/models/hydramata/works/predicates/storage.rb +33 -0
- data/app/models/hydramata/works/presentation_structure.rb +29 -0
- data/app/models/hydramata/works/property.rb +72 -0
- data/app/models/hydramata/works/property_set.rb +89 -0
- data/app/models/hydramata/works/validations.rb +6 -0
- data/app/models/hydramata/works/value.rb +34 -0
- data/app/models/hydramata/works/work_type.rb +49 -0
- data/app/models/hydramata/works/work_types.rb +14 -0
- data/app/models/hydramata/works/work_types/storage.rb +42 -0
- data/app/parsers/hydramata/works/datastream_parser.rb +36 -0
- data/app/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser.rb +60 -0
- data/app/parsers/hydramata/works/datastream_parsers/simple_xml_parser.rb +27 -0
- data/app/parsers/hydramata/works/predicate_parser.rb +31 -0
- data/app/parsers/hydramata/works/predicate_parsers/simple_parser.rb +13 -0
- data/app/parsers/hydramata/works/validations_parser.rb +22 -0
- data/app/parsers/hydramata/works/value_parser.rb +26 -0
- data/app/parsers/hydramata/works/value_parsers.rb +27 -0
- data/app/parsers/hydramata/works/value_parsers/date_parser.rb +13 -0
- data/app/parsers/hydramata/works/value_parsers/interrogation_parser.rb +18 -0
- data/app/parsers/hydramata/works/value_parsers/simple_parser.rb +14 -0
- data/app/presenters/hydramata/works/base_presenter.rb +146 -0
- data/app/presenters/hydramata/works/dom_attributes_builder.rb +24 -0
- data/app/presenters/hydramata/works/entity_presenter.rb +67 -0
- data/app/presenters/hydramata/works/fieldset_presenter.rb +54 -0
- data/app/presenters/hydramata/works/property_presenter.rb +51 -0
- data/app/presenters/hydramata/works/value_presenter.rb +60 -0
- data/app/renderers/hydramata/works/entity_renderer.rb +45 -0
- data/app/views/hydramata/works/fieldsets/_edit.html.erb +4 -0
- data/app/views/hydramata/works/fieldsets/_show.html.erb +8 -0
- data/app/views/hydramata/works/fieldsets/_show.json.jbuilder +8 -0
- data/app/views/hydramata/works/properties/_edit.html.erb +12 -0
- data/app/views/hydramata/works/properties/_show.html.erb +3 -0
- data/app/views/hydramata/works/properties/_show.json.jbuilder +1 -0
- data/app/views/hydramata/works/works/_edit.html.erb +8 -0
- data/app/views/hydramata/works/works/_new.html.erb +8 -0
- data/app/views/hydramata/works/works/_show.html.erb +3 -0
- data/app/views/hydramata/works/works/_show.json.jbuilder +13 -0
- data/app/wranglers/hydramata/works/fedora_wrangler.rb +66 -0
- data/bin/rails +12 -0
- data/db/migrate/20140606132349_create_hydramata_work_predicates.rb +13 -0
- data/db/migrate/20140606132350_create_hydramata_work_types.rb +9 -0
- data/db/migrate/20140606132351_create_hydramata_work_predicate_sets.rb +13 -0
- data/db/migrate/20140606132352_create_hydramata_work_predicate_presentation_sequences.rb +12 -0
- data/db/migrate/20140623200635_add_validations_to_predicates.rb +5 -0
- data/db/migrate/20140627134133_adding_item_type_schema_dot_org_to_work_type.rb +5 -0
- data/db/migrate/20140627140840_adding_item_prop_schema_dot_org_to_predicate.rb +5 -0
- data/db/seeds.rb +36 -0
- data/documents/administrative-set-strawperson.md +45 -0
- data/documents/diagrams/hydramata-refactor-tasks.dot +88 -0
- data/documents/diagrams/hydramata-sip-dip-aip.dot +88 -0
- data/documents/diagrams/hydramata-work-architecture.dot +129 -0
- data/documents/diagrams/hydramata-work-subcomponents.dot +36 -0
- data/documents/diagrams/map-from-database-to-work-object.dot +44 -0
- data/documents/diagrams/map-from-fedora-to-work-object.dot +51 -0
- data/documents/diagrams/map-from-input-to-work-object.dot +37 -0
- data/documents/diagrams/map-from-work-object-to-database.dot +31 -0
- data/documents/diagrams/work-rendering.dot +53 -0
- data/documents/diagrams/work-structure.dot +32 -0
- data/documents/handling-work.md +224 -0
- data/documents/high-level-stories.md +105 -0
- data/documents/hydramata-components.md +82 -0
- data/documents/interface-between-work-and-permissions.md +131 -0
- data/documents/interface-between-work-and-workflow.md +6 -0
- data/documents/timeline.md +75 -0
- data/fs +3 -0
- data/gemfiles/rails4.1.gemfile +12 -0
- data/gemfiles/rails4.gemfile +13 -0
- data/hydramata-works.gemspec +43 -0
- data/lib/hydramata-works.rb +23 -0
- data/lib/hydramata/works/conversions.rb +21 -0
- data/lib/hydramata/works/conversions/exceptions.rb +18 -0
- data/lib/hydramata/works/conversions/predicate.rb +22 -0
- data/lib/hydramata/works/conversions/predicate_set.rb +28 -0
- data/lib/hydramata/works/conversions/presented_fieldsets.rb +28 -0
- data/lib/hydramata/works/conversions/presenter.rb +13 -0
- data/lib/hydramata/works/conversions/property.rb +31 -0
- data/lib/hydramata/works/conversions/property_set.rb +23 -0
- data/lib/hydramata/works/conversions/translation_key_fragment.rb +20 -0
- data/lib/hydramata/works/conversions/value.rb +20 -0
- data/lib/hydramata/works/conversions/work_type.rb +26 -0
- data/lib/hydramata/works/engine.rb +31 -0
- data/lib/hydramata/works/linters.rb +99 -0
- data/lib/hydramata/works/linters/implement_data_definition_interface_matcher.rb +17 -0
- data/lib/hydramata/works/linters/implement_entity_interface_matcher.rb +16 -0
- data/lib/hydramata/works/linters/implement_predicate_interface_matcher.rb +17 -0
- data/lib/hydramata/works/linters/implement_predicate_set_interface_matcher.rb +8 -0
- data/lib/hydramata/works/linters/implement_property_set_interface_matcher.rb +8 -0
- data/lib/hydramata/works/linters/implement_value_interface_matcher.rb +8 -0
- data/lib/hydramata/works/linters/implement_work_type_interface_matcher.rb +13 -0
- data/lib/hydramata/works/linters/interface_matcher_builder.rb +36 -0
- data/lib/hydramata/works/translator.rb +67 -0
- data/lib/hydramata/works/version.rb +5 -0
- data/lib/hydramata_works.rb +2 -0
- data/lib/tasks/hydramata_work_tasks.rake +4 -0
- data/run_each_spec_in_isolation +16 -0
- data/run_each_spec_in_isolation.txt +110 -0
- data/script/analyzer.rb +124 -0
- data/script/fast_specs +22 -0
- data/spec/features/fedora_to_in_memory_spec.rb +60 -0
- data/spec/features/format_and_view_path_overrides_spec.rb +72 -0
- data/spec/features/in_memory_to_output_buffer_spec.rb +109 -0
- data/spec/features/instantiate_entity_from_persisted_work_type_spec.rb +26 -0
- data/spec/features/new_user_input_to_in_memory_spec.rb +75 -0
- data/spec/features/translation_services_spec.rb +107 -0
- data/spec/features/validate_entity_based_on_work_type_structure_spec.rb +19 -0
- data/spec/fixtures/cassettes/fedora-object.yml +299 -0
- data/spec/fixtures/translations.yml +20 -0
- data/spec/forms/hydramata/works/entity_form_spec.rb +83 -0
- data/spec/forms/hydramata/works/validation_service_spec.rb +32 -0
- data/spec/lib/hydramata-work_spec.rb +14 -0
- data/spec/lib/hydramata/works/conversions/predicate_set_spec.rb +50 -0
- data/spec/lib/hydramata/works/conversions/predicate_spec.rb +43 -0
- data/spec/lib/hydramata/works/conversions/presented_fieldsets_spec.rb +52 -0
- data/spec/lib/hydramata/works/conversions/presenter_spec.rb +22 -0
- data/spec/lib/hydramata/works/conversions/property_set_spec.rb +42 -0
- data/spec/lib/hydramata/works/conversions/property_spec.rb +68 -0
- data/spec/lib/hydramata/works/conversions/translation_key_fragment_spec.rb +45 -0
- data/spec/lib/hydramata/works/conversions/value_spec.rb +36 -0
- data/spec/lib/hydramata/works/conversions/work_type_spec.rb +55 -0
- data/spec/lib/hydramata/works/translator_spec.rb +81 -0
- data/spec/models/hydramata/works/data_definition_spec.rb +53 -0
- data/spec/models/hydramata/works/entity_spec.rb +50 -0
- data/spec/models/hydramata/works/predicate_presentation_sequences/storage_spec.rb +15 -0
- data/spec/models/hydramata/works/predicate_set_spec.rb +63 -0
- data/spec/models/hydramata/works/predicate_sets/storage_spec.rb +37 -0
- data/spec/models/hydramata/works/predicate_spec.rb +16 -0
- data/spec/models/hydramata/works/predicates/storage_spec.rb +78 -0
- data/spec/models/hydramata/works/predicates_spec.rb +18 -0
- data/spec/models/hydramata/works/presentation_structure_spec.rb +27 -0
- data/spec/models/hydramata/works/property_set_spec.rb +135 -0
- data/spec/models/hydramata/works/property_spec.rb +74 -0
- data/spec/models/hydramata/works/value_spec.rb +61 -0
- data/spec/models/hydramata/works/work_type_spec.rb +45 -0
- data/spec/models/hydramata/works/work_types/storage_spec.rb +74 -0
- data/spec/models/hydramata/works/work_types_spec.rb +16 -0
- data/spec/parsers/hydramata/works/datastream_parser_spec.rb +29 -0
- data/spec/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser_spec.rb +65 -0
- data/spec/parsers/hydramata/works/datastream_parsers/simple_xml_parser_spec.rb +37 -0
- data/spec/parsers/hydramata/works/predicate_parser_spec.rb +30 -0
- data/spec/parsers/hydramata/works/predicate_parsers/simple_parser_spec.rb +20 -0
- data/spec/parsers/hydramata/works/validations_parser_spec.rb +31 -0
- data/spec/parsers/hydramata/works/value_parser_spec.rb +22 -0
- data/spec/parsers/hydramata/works/value_parsers/simple_parser_spec.rb +20 -0
- data/spec/parsers/hydramata/works/value_parsers_spec.rb +36 -0
- data/spec/presenters/hydramata/works/base_presenter_spec.rb +111 -0
- data/spec/presenters/hydramata/works/dom_attributes_builder_spec.rb +26 -0
- data/spec/presenters/hydramata/works/entity_presenter_spec.rb +51 -0
- data/spec/presenters/hydramata/works/fieldset_presenter_spec.rb +58 -0
- data/spec/presenters/hydramata/works/property_presenter_spec.rb +42 -0
- data/spec/presenters/hydramata/works/value_presenter_spec.rb +49 -0
- data/spec/renderers/hydramata/works/entity_renderer_spec.rb +25 -0
- data/spec/spec_active_record_helper.rb +30 -0
- data/spec/spec_fast_helper.rb +12 -0
- data/spec/spec_slow_helper.rb +56 -0
- data/spec/spec_view_helper.rb +14 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +21 -0
- data/spec/views/hydramata/works/fieldsets/_edit.html.erb_spec.rb +29 -0
- data/spec/views/hydramata/works/fieldsets/_show.html.erb_spec.rb +25 -0
- data/spec/views/hydramata/works/properties/_edit.html.erb_spec.rb +22 -0
- data/spec/views/hydramata/works/properties/_show.html.erb_spec.rb +22 -0
- data/spec/views/hydramata/works/works/_edit.html.erb_spec.rb +23 -0
- data/spec/views/hydramata/works/works/_new.html.erb_spec.rb +23 -0
- data/spec/views/hydramata/works/works/_show.html.erb_spec.rb +24 -0
- data/spec/wranglers/hydramata/works/fedora_wrangler_spec.rb +26 -0
- metadata +466 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_fast_helper'
|
2
|
+
require 'hydramata/works/predicates'
|
3
|
+
require 'hydramata/works/linters/implement_predicate_interface_matcher'
|
4
|
+
|
5
|
+
|
6
|
+
module Hydramata
|
7
|
+
module Works
|
8
|
+
describe Predicates do
|
9
|
+
|
10
|
+
context '.find' do
|
11
|
+
it 'uses the identity to construct the appropriate predicate' do
|
12
|
+
expect(described_class.find('name', { something: 'george' })).to implement_predicate_interface
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_fast_helper'
|
2
|
+
require 'hydramata/works/presentation_structure'
|
3
|
+
|
4
|
+
module Hydramata
|
5
|
+
module Works
|
6
|
+
describe PresentationStructure do
|
7
|
+
subject { described_class.new }
|
8
|
+
let(:fieldset) { [:required, [:title]] }
|
9
|
+
|
10
|
+
context '.build' do
|
11
|
+
let(:object) { double('Object with predicate sets', predicate_sets: ['predicate_1', 'predicate_2']) }
|
12
|
+
it 'should transform an entities predicate_sets to fieldsets' do
|
13
|
+
structure = described_class.build_from(object)
|
14
|
+
expect(structure.fieldsets).to eq(object.predicate_sets)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context '#fieldsets' do
|
19
|
+
it 'can be appended' do
|
20
|
+
expect { subject.fieldsets << fieldset }.
|
21
|
+
to change { subject.fieldsets.count }.
|
22
|
+
by(1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_fast_helper'
|
2
|
+
require 'hydramata/works/property_set'
|
3
|
+
|
4
|
+
module Hydramata
|
5
|
+
module Works
|
6
|
+
describe PropertySet do
|
7
|
+
subject { PropertySet.new }
|
8
|
+
let(:property) { Property.new(predicate: :title, value: 'value one') }
|
9
|
+
|
10
|
+
context 'predicate order' do
|
11
|
+
it 'the first predicate pushed will return as the first' do
|
12
|
+
subject << (first = Property.new(predicate: :one, value: 1))
|
13
|
+
subject << (second = Property.new(predicate: :two, value: 2))
|
14
|
+
subject << (third = Property.new(predicate: :three, value: 3))
|
15
|
+
|
16
|
+
# Note: I am pushing a Property with the same predicate as the first
|
17
|
+
# object pushed. This will modify
|
18
|
+
subject << Property.new(predicate: :one, value: 4)
|
19
|
+
|
20
|
+
expect { |b| subject.each(&b) }.to yield_successive_args(first, second, third)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'exposes #properties' do
|
25
|
+
subject << property
|
26
|
+
expect(subject.properties).to eq([property])
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'allows properties to be pushed onto it' do
|
30
|
+
expect { subject << property }.
|
31
|
+
to change { subject.count }.
|
32
|
+
by(1)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'amends an existing property if a common predicate is found' do
|
36
|
+
property = Property.new(predicate: :title, value: 'value one')
|
37
|
+
property_with_same_predicate = Property.new(predicate: :title, value: 'another')
|
38
|
+
subject << property
|
39
|
+
expect do
|
40
|
+
expect { subject << property_with_same_predicate }.
|
41
|
+
to_not change { subject.count }
|
42
|
+
end.to change { property.values }.
|
43
|
+
from(['value one']).
|
44
|
+
to(['value one', 'another'])
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'data retrieval methods' do
|
48
|
+
before { subject << property }
|
49
|
+
|
50
|
+
context '#predicates' do
|
51
|
+
it 'should be the predicate names' do
|
52
|
+
expect(subject.predicates).to eq [property.predicate.to_s]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context '#fetch' do
|
57
|
+
it 'should raise an error if the predicate is not found' do
|
58
|
+
expect { subject.fetch(:missing) }.to raise_error(KeyError)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should return the values if the predicate exists' do
|
62
|
+
expect(subject.fetch(property.predicate)).to eq(property)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context '#key?' do
|
67
|
+
it 'should be false if predicate does not exist' do
|
68
|
+
expect(subject.key?(:missing)).to be_falsey
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should return the values if the predicate exists' do
|
72
|
+
expect(subject.key?(property.predicate)).to be_truthy
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context '#[]' do
|
77
|
+
it 'should return nil if the predicate is not found' do
|
78
|
+
expect(subject[:missing]).to eq(Property.new(predicate: :missing))
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should return the values if the predicate exists' do
|
82
|
+
expect(subject[property.predicate]).to eq(property)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context '#each' do
|
87
|
+
it 'should yield the predicate and normalized values' do
|
88
|
+
expect { |b| subject.each(&b) }.to yield_with_args(property)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context '#==' do
|
93
|
+
it 'should return true if underlying properties are identical' do
|
94
|
+
property_set = described_class.new
|
95
|
+
other = described_class.new
|
96
|
+
|
97
|
+
expect(property_set == other).to be_truthy
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should return false if different classes' do
|
101
|
+
property_set = described_class.new
|
102
|
+
other = 'abc'
|
103
|
+
|
104
|
+
expect(property_set == other).to be_falsey
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should return false if underlyng properties are different' do
|
108
|
+
property_set = described_class.new
|
109
|
+
other = described_class.new
|
110
|
+
property_set << property
|
111
|
+
|
112
|
+
expect(property_set == other).to be_falsey
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should return true if empty property set and hash are compared' do
|
116
|
+
property_set = described_class.new
|
117
|
+
other = {}
|
118
|
+
|
119
|
+
expect(property_set == other).to be_truthy
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context '#subset' do
|
124
|
+
let(:a_second_property) { { predicate: :another_predicate, value: 'another value' } }
|
125
|
+
it 'should return a property set that only has the specified keys' do
|
126
|
+
subject << a_second_property
|
127
|
+
subset = described_class.new
|
128
|
+
subset << property
|
129
|
+
expect(subject.subset(property.predicate)).to eq(subset)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_fast_helper'
|
2
|
+
require 'hydramata/works/property'
|
3
|
+
|
4
|
+
module Hydramata
|
5
|
+
module Works
|
6
|
+
describe Property do
|
7
|
+
let(:predicate) { 'Predicate' }
|
8
|
+
let(:value) { double('Value') }
|
9
|
+
subject { described_class.new(predicate: predicate) }
|
10
|
+
|
11
|
+
it { should respond_to :values }
|
12
|
+
it { should respond_to :name }
|
13
|
+
|
14
|
+
it 'should delegate #each to #values' do
|
15
|
+
subject << value
|
16
|
+
expect { |b| subject.each(&b) }.to yield_with_args(value)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'can append to values' do
|
20
|
+
expect { subject << value }.
|
21
|
+
to change { subject.values }.
|
22
|
+
from([]).
|
23
|
+
to([value])
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should have a #to_translation_key_fragment' do
|
27
|
+
expect(subject.to_translation_key_fragment).to eq(subject.predicate.to_translation_key_fragment)
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'case equality' do
|
31
|
+
it 'should delegate to the compared object' do
|
32
|
+
object = double('Double')
|
33
|
+
expect(object).
|
34
|
+
to receive(:instance_of?).
|
35
|
+
with(Property).
|
36
|
+
and_return(true)
|
37
|
+
expect(Property === object).to eq(true)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'equality' do
|
42
|
+
it 'is not equal if the predicates are different' do
|
43
|
+
property = described_class.new(predicate: :hello)
|
44
|
+
other = described_class.new(predicate: :goodbye)
|
45
|
+
expect(property == other).to eq(false)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'is equal if the predicates and values are the same' do
|
49
|
+
property = described_class.new(predicate: :hello, values: [123])
|
50
|
+
other = described_class.new(predicate: :hello, values: [123])
|
51
|
+
expect(property == other).to eq(true)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'is not equal if the predicates are the same but values are the different' do
|
55
|
+
property = described_class.new(predicate: :hello, values: [123])
|
56
|
+
other = described_class.new(predicate: :hello, values: [123, 345])
|
57
|
+
expect(property == other).to eq(false)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'is not equal if the predicates are different but the values are the same' do
|
61
|
+
property = described_class.new(predicate: :goodbye, values: [123])
|
62
|
+
other = described_class.new(predicate: :hello, values: [123])
|
63
|
+
expect(property == other).to eq(false)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'is not equal if of different classes' do
|
67
|
+
property = described_class.new(predicate: :goodbye, values: [123])
|
68
|
+
other = Struct.new(:predicate, :values).new(:goodbye, [123])
|
69
|
+
expect(property == other).to eq(false)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_fast_helper'
|
2
|
+
require 'date'
|
3
|
+
require 'hydramata/works/value'
|
4
|
+
require 'hydramata/works/linters/implement_value_interface_matcher'
|
5
|
+
|
6
|
+
module Hydramata
|
7
|
+
module Works
|
8
|
+
describe Value do
|
9
|
+
let(:raw_object) { double('Raw Object') }
|
10
|
+
let(:value) { 123456789 }
|
11
|
+
subject { described_class.new(value: value, raw_object: raw_object) }
|
12
|
+
|
13
|
+
it { should implement_value_interface }
|
14
|
+
|
15
|
+
it 'should have a #raw_object' do
|
16
|
+
expect(subject.raw_object).to eq(raw_object)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should have a friendly inspect message, because tracking it down could be a pain' do
|
20
|
+
expect(subject.inspect).to include("#{described_class}")
|
21
|
+
expect(subject.inspect).to include(raw_object.inspect)
|
22
|
+
expect(subject.inspect).to include(value.inspect)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should be an instance of the presented object\'s class' do
|
26
|
+
expect(subject.instance_of?(value.class)).to be_truthy
|
27
|
+
end
|
28
|
+
|
29
|
+
context '#==' do
|
30
|
+
context 'for two value objects' do
|
31
|
+
it 'should not be true if underlying objects do not match' do
|
32
|
+
expect(described_class.new(value: 123) == described_class.new(value: 1234)).to be_falsey
|
33
|
+
end
|
34
|
+
it 'should be true if underlying objects match' do
|
35
|
+
expect(described_class.new(value: Date.new(2013,1,3)) == described_class.new(value: Date.new(2013,1,3))).to be_truthy
|
36
|
+
end
|
37
|
+
end
|
38
|
+
context 'for integers' do
|
39
|
+
let(:value) { 123456789 }
|
40
|
+
it 'should be equal when base value is the same' do
|
41
|
+
expect(subject == value).to be_truthy
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'for strings' do
|
46
|
+
let(:value) { 'Hello World' }
|
47
|
+
it 'should be equal when base value is the same' do
|
48
|
+
expect(subject == value).to be_truthy
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'for dates' do
|
53
|
+
let(:value) { Date.new(2013,1,3) }
|
54
|
+
it 'should be equal when base value is the same' do
|
55
|
+
expect(subject == Date.new(2013,1,3)).to be_truthy
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Instead of using spec_helper, I'm using the twice as fast custom helper
|
2
|
+
# for active record objects.
|
3
|
+
require 'spec_fast_helper'
|
4
|
+
require 'hydramata/works/work_type'
|
5
|
+
require 'hydramata/works/linters/implement_work_type_interface_matcher'
|
6
|
+
require 'hydramata/works/linters/implement_data_definition_interface_matcher'
|
7
|
+
|
8
|
+
module Hydramata
|
9
|
+
module Works
|
10
|
+
describe WorkType do
|
11
|
+
subject { described_class.new(identity: 'My Identity') }
|
12
|
+
it { should implement_work_type_interface }
|
13
|
+
it { should implement_data_definition_interface }
|
14
|
+
|
15
|
+
context '#predicate_sets=' do
|
16
|
+
it 'handles predicate set conversion' do
|
17
|
+
subject = described_class.new(identity: 'My Identity', predicate_sets: ['one predicate', 'two predicate'])
|
18
|
+
expect(subject.predicate_sets).to eq([PredicateSet.new(identity: 'one predicate'), PredicateSet.new(identity: 'two predicate')])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should have #fieldsets that is an alias of #predicate_sets' do
|
23
|
+
subject = described_class.new(identity: 'My Identity', predicate_sets: ['one predicate', 'two predicate'])
|
24
|
+
expect(subject.fieldsets).to eq(subject.predicate_sets)
|
25
|
+
end
|
26
|
+
|
27
|
+
context '#itemtype_schema_dot_org' do
|
28
|
+
it 'should utilize the default' do
|
29
|
+
subject = described_class.new(identity: 'My Identity')
|
30
|
+
expect(subject.itemtype_schema_dot_org).to match(/\Ahttps?:\/\/schema.org/)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should prepend http://schema.org if is missing' do
|
34
|
+
subject = described_class.new(identity: 'My Identity', itemtype_schema_dot_org: 'Thing')
|
35
|
+
expect(subject.itemtype_schema_dot_org).to eq('http://schema.org/Thing')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should accept http directly' do
|
39
|
+
subject = described_class.new(identity: 'My Identity', itemtype_schema_dot_org: 'http://schema.org/CreativeWork')
|
40
|
+
expect(subject.itemtype_schema_dot_org).to eq('http://schema.org/CreativeWork')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Instead of using spec_helper, I'm using the twice as fast custom helper
|
2
|
+
# for active record objects.
|
3
|
+
require 'spec_active_record_helper'
|
4
|
+
require 'hydramata/works/work_types/storage'
|
5
|
+
require 'hydramata/works/linters/implement_work_type_interface_matcher'
|
6
|
+
|
7
|
+
module Hydramata
|
8
|
+
module Works
|
9
|
+
module WorkTypes
|
10
|
+
|
11
|
+
describe Storage do
|
12
|
+
subject { described_class.new }
|
13
|
+
it { should implement_work_type_interface }
|
14
|
+
|
15
|
+
let(:identity) { 'http://hello.com/world' }
|
16
|
+
subject { described_class.create(identity: identity, name_for_application_usage: 'hello_world') }
|
17
|
+
|
18
|
+
context '#to_work_type' do
|
19
|
+
it 'returns a WorkType object' do
|
20
|
+
work_type = described_class.new do |work_type|
|
21
|
+
work_type.predicate_sets.build(identity: 'hello')
|
22
|
+
end.to_work_type
|
23
|
+
|
24
|
+
expect(work_type).to implement_work_type_interface
|
25
|
+
expect(work_type.predicate_sets.size).to eq(1)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context '.find_by_identity' do
|
30
|
+
|
31
|
+
it 'returns a WorkType object when identity exists' do
|
32
|
+
subject # creating the object
|
33
|
+
expect(described_class.find_by_identity!(identity)).to implement_work_type_interface
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns nil when identity is missing' do
|
37
|
+
# @TODO - Should this be a NullPredicate?
|
38
|
+
expect { described_class.find_by_identity!(identity) }.to raise_error
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context '.existing_attributes_for' do
|
43
|
+
it 'should return the existing work_type attributes' do
|
44
|
+
subject
|
45
|
+
keys = [
|
46
|
+
:id,
|
47
|
+
:identity,
|
48
|
+
:name_for_application_usage
|
49
|
+
]
|
50
|
+
actual_values = described_class.existing_attributes_for(identity).values_at(keys)
|
51
|
+
# Because date comparisons are a bit wonky
|
52
|
+
expect(actual_values).to eq(subject.attributes.values_at(keys))
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should return the identity if a matching work_type was not found' do
|
56
|
+
expect(described_class.existing_attributes_for(identity)).to eq(identity: identity)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should handle connection failed' do
|
60
|
+
expect(described_class).to receive(:find_by_identity!).and_raise(ActiveRecord::ConnectionNotEstablished)
|
61
|
+
expect(described_class.existing_attributes_for(identity)).to eq(identity: identity)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should have many :predicate_sets' do
|
66
|
+
expect { subject.predicate_sets.create(identity: 'required', presentation_sequence: 1) }.
|
67
|
+
to change { subject.predicate_sets.count }.
|
68
|
+
by(1)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_fast_helper'
|
2
|
+
require 'hydramata/works/work_types'
|
3
|
+
require 'hydramata/works/linters/implement_work_type_interface_matcher'
|
4
|
+
|
5
|
+
|
6
|
+
module Hydramata
|
7
|
+
module Works
|
8
|
+
describe WorkTypes do
|
9
|
+
context '.find' do
|
10
|
+
it 'uses the identity to construct the appropriate work_type' do
|
11
|
+
expect(described_class.find('name', { something: 'george' })).to implement_work_type_interface
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|