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,36 @@
|
|
1
|
+
require 'spec_fast_helper'
|
2
|
+
require 'hydramata/works/conversions/value'
|
3
|
+
require 'hydramata/works/linters/implement_value_interface_matcher'
|
4
|
+
|
5
|
+
module Hydramata
|
6
|
+
module Works
|
7
|
+
describe Conversions do
|
8
|
+
include Conversions
|
9
|
+
|
10
|
+
context '#Value' do
|
11
|
+
it 'should convert a Hash to a Value object' do
|
12
|
+
expect(Value(value: 'hello')).to implement_value_interface
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should convert an object that implements #to_value' do
|
16
|
+
object = double(to_value: Value.new(value: 'Value'))
|
17
|
+
expect(Value(object)).to eq(object.to_value)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should convert a String to a Value object' do
|
21
|
+
expect(Value('hello')).to implement_value_interface
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should return the same Value if a Value is given' do
|
25
|
+
value = Value('hello')
|
26
|
+
expect(Value(value).object_id).to eq(value.object_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should raise an error object is unexpected' do
|
30
|
+
expect { Value([]) }.to raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_fast_helper'
|
2
|
+
require 'hydramata/works/conversions/work_type'
|
3
|
+
require 'hydramata/works/linters/implement_work_type_interface_matcher'
|
4
|
+
|
5
|
+
module Hydramata
|
6
|
+
module Works
|
7
|
+
describe Conversions do
|
8
|
+
include Conversions
|
9
|
+
|
10
|
+
context '#WorkType' do
|
11
|
+
it 'should not convert something that is not empty' do
|
12
|
+
expect{ WorkType(double(:empty? => false)) }.to raise_error
|
13
|
+
end
|
14
|
+
it 'should convert an empty value to a WorkType null object' do
|
15
|
+
expect(WorkType()).to implement_work_type_interface.with(:identity, 'unknown')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should convert an Array to a WorkType null object' do
|
19
|
+
expect(WorkType([])).to implement_work_type_interface.with(:identity, 'unknown')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should convert Nil to a WorkType null object' do
|
23
|
+
expect(WorkType(nil)).to implement_work_type_interface.with(:identity, 'unknown')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should convert a String to a WorkType object' do
|
27
|
+
expect(WorkType('hello')).to implement_work_type_interface
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should convert a Symbol to a WorkType object' do
|
31
|
+
expect(WorkType(:hello)).to implement_work_type_interface
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return the same work_type if a WorkType is given' do
|
35
|
+
work_type = WorkType(:hello)
|
36
|
+
expect(WorkType(work_type).object_id).to eq(work_type.object_id)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should convert a "well-formed" Hash to a WorkType object' do
|
40
|
+
expect(WorkType(identity: 'hello')).to implement_work_type_interface
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should convert a "#to_work_type" to a WorkType object' do
|
44
|
+
stored_object = double('Object', to_work_type: WorkType.new)
|
45
|
+
expect(WorkType(stored_object)).to implement_work_type_interface
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should raise an error if the Hash is not "well-formed"' do
|
49
|
+
expect { WorkType(other: 'hello') }.to raise_error
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_fast_helper'
|
2
|
+
require 'hydramata/works/translator'
|
3
|
+
|
4
|
+
module Hydramata
|
5
|
+
module Works
|
6
|
+
describe Translator do
|
7
|
+
subject do
|
8
|
+
described_class.new(
|
9
|
+
base_scope: base_scope,
|
10
|
+
translation_service: translation_service,
|
11
|
+
translation_service_error: translation_service_error
|
12
|
+
)
|
13
|
+
end
|
14
|
+
let(:base_scope) { ['hydramata', 'work'] }
|
15
|
+
let(:scopes) { [['grandparent', 'parent'], ['grandparent']] }
|
16
|
+
let(:translation_service) { double('TranslationService', translate: true) }
|
17
|
+
let(:translation_service_error) { ArgumentError }
|
18
|
+
|
19
|
+
context '#translate' do
|
20
|
+
it 'passes options to the default rendering' do
|
21
|
+
expect(translation_service).to receive(:translate).
|
22
|
+
with('child', scope: base_scope, default: 'default').
|
23
|
+
ordered.
|
24
|
+
and_return('With Default')
|
25
|
+
|
26
|
+
expect(subject.translate('child', default: 'default')).to eq('With Default')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'attempts to translate through each scope then finally via the base scope' do
|
30
|
+
expect(translation_service).to receive(:translate).
|
31
|
+
with('child', scope: (base_scope + scopes[0]), raise: true).
|
32
|
+
ordered.
|
33
|
+
and_raise(translation_service_error)
|
34
|
+
expect(translation_service).to receive(:translate).
|
35
|
+
with('child', scope: (base_scope + scopes[1]), raise: true).
|
36
|
+
ordered.
|
37
|
+
and_raise(translation_service_error)
|
38
|
+
expect(translation_service).to receive(:translate).
|
39
|
+
with('child', scope: base_scope, scopes: scopes).
|
40
|
+
ordered.
|
41
|
+
and_return('My Work Type')
|
42
|
+
|
43
|
+
expect(subject.translate('child', scopes: scopes)).to eq('My Work Type')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'translates through each scope until it finds a match then returns without processing more generic case' do
|
47
|
+
expect(translation_service).to receive(:translate).
|
48
|
+
with('child', scope: (base_scope + scopes[0]), raise: true).
|
49
|
+
ordered.
|
50
|
+
and_raise(translation_service_error)
|
51
|
+
expect(translation_service).to receive(:translate).
|
52
|
+
with('child', scope: (base_scope + scopes[1]), raise: true).
|
53
|
+
ordered.
|
54
|
+
and_return('Found Grandparent')
|
55
|
+
expect(translation_service).to_not receive(:translate).
|
56
|
+
with('child', scope: base_scope)
|
57
|
+
|
58
|
+
expect(subject.translate('child', scopes: scopes)).to eq('Found Grandparent')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'translates through each scope until it finds a match then returns without processing more generic case' do
|
62
|
+
expect(translation_service).to receive(:translate).
|
63
|
+
with('child', scope: (base_scope + scopes[0]), raise: true).
|
64
|
+
ordered.
|
65
|
+
and_raise(translation_service_error)
|
66
|
+
expect(translation_service).to receive(:translate).
|
67
|
+
with('child', scope: (base_scope + scopes[1]), raise: true).
|
68
|
+
ordered.
|
69
|
+
and_raise(translation_service_error)
|
70
|
+
expect(translation_service).to_not receive(:translate).
|
71
|
+
with('child', scope: base_scope, scopes: scopes).
|
72
|
+
ordered.
|
73
|
+
and_raise(translation_service_error)
|
74
|
+
|
75
|
+
expect { subject.translate('child', scopes: scopes) }.to raise_error
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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/data_definition'
|
5
|
+
require 'hydramata/works/linters/implement_data_definition_interface_matcher'
|
6
|
+
|
7
|
+
module Hydramata
|
8
|
+
module Works
|
9
|
+
describe DataDefinition do
|
10
|
+
subject { described_class.new(identity: 'My Identity') }
|
11
|
+
it { should implement_data_definition_interface }
|
12
|
+
|
13
|
+
it 'should initialize via attributes' do
|
14
|
+
expect(subject.identity).to eq('My Identity')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have a meaningful #to_s' do
|
18
|
+
expect(subject.to_s).to eq('My Identity')
|
19
|
+
end
|
20
|
+
|
21
|
+
context '#==' do
|
22
|
+
subject { described_class.new(identity: 'My Identity') }
|
23
|
+
|
24
|
+
it 'be true if class and identity is equal' do
|
25
|
+
other = described_class.new(identity: subject.identity)
|
26
|
+
expect(subject == other).to be_truthy
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'be false if identity is equal but not class' do
|
30
|
+
other = double(identity: subject.identity)
|
31
|
+
expect(subject == other).to be_falsey
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'be false if class is equal but not identity' do
|
35
|
+
other = subject.class.new(identity: "#{subject.identity}1")
|
36
|
+
expect(subject == other).to be_falsey
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context '#to_translation_key_fragment' do
|
41
|
+
it 'should default to identity if no name is given for application usage' do
|
42
|
+
expect(subject.to_translation_key_fragment).to eq subject.identity
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should default to identity if no name is given for application usage' do
|
46
|
+
subject = described_class.new(identity: 'My Identity', name_for_application_usage: 'Twonky')
|
47
|
+
expect(subject.to_translation_key_fragment).to eq 'Twonky'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_fast_helper'
|
2
|
+
require 'hydramata/works/entity'
|
3
|
+
require 'hydramata/works/linters/implement_entity_interface_matcher'
|
4
|
+
|
5
|
+
module Hydramata
|
6
|
+
module Works
|
7
|
+
describe Entity do
|
8
|
+
subject { described_class.new }
|
9
|
+
it { should implement_entity_interface }
|
10
|
+
|
11
|
+
let(:predicate) { :title }
|
12
|
+
let(:value) { 'Hello' }
|
13
|
+
let(:property) { Property.new(predicate: predicate, value: value) }
|
14
|
+
|
15
|
+
|
16
|
+
context '#to_presenter' do
|
17
|
+
let(:presenter_builder) { double('Presenter Builder', call: :built) }
|
18
|
+
subject { described_class.new(presenter_builder: presenter_builder) }
|
19
|
+
it 'should call the presenter_builder' do
|
20
|
+
expect(subject.to_presenter).to eq(:built)
|
21
|
+
expect(presenter_builder).to have_received(:call).with(subject)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context '#has_property?' do
|
26
|
+
it 'changes from false to true when the property is added' do
|
27
|
+
expect { subject.properties << property }.
|
28
|
+
to change { subject.has_property?(predicate) }.
|
29
|
+
from(false).
|
30
|
+
to(true)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context '#properties' do
|
35
|
+
it 'can be appended' do
|
36
|
+
expect { subject.properties << property }.
|
37
|
+
to change { subject.properties.count }.
|
38
|
+
by(1)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context '#property' do
|
43
|
+
it 'returns matching predicates' do
|
44
|
+
subject.properties << property
|
45
|
+
expect(subject.properties[predicate]).to eq(property)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,15 @@
|
|
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/predicate_presentation_sequences/storage'
|
5
|
+
|
6
|
+
module Hydramata
|
7
|
+
module Works
|
8
|
+
module PredicatePresentationSequences
|
9
|
+
|
10
|
+
describe Storage do
|
11
|
+
subject { described_class.new }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_fast_helper'
|
2
|
+
require 'hydramata/works/predicate_set'
|
3
|
+
require 'hydramata/works/linters/implement_predicate_set_interface_matcher'
|
4
|
+
|
5
|
+
module Hydramata
|
6
|
+
module Works
|
7
|
+
describe PredicateSet do
|
8
|
+
subject { described_class.new(identity: 'My Identity') }
|
9
|
+
it { should implement_predicate_set_interface }
|
10
|
+
|
11
|
+
it 'should initialize via attributes' do
|
12
|
+
expect(subject.identity).to eq('My Identity')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should initialize via attributes' do
|
16
|
+
expect(subject.identity).to eq('My Identity')
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'comparability' do
|
20
|
+
let(:work_type) { 'Work Type' }
|
21
|
+
let(:identity) { 'Identity' }
|
22
|
+
subject { described_class.new(identity: 'Identity', work_type: work_type) }
|
23
|
+
|
24
|
+
it 'is != if they are different base classes' do
|
25
|
+
other = double(work_type: work_type, identity: identity)
|
26
|
+
expect(subject == other).to be_falsey
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'is == if they are the same object' do
|
30
|
+
expect(subject == subject).to be_truthy
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'is == if work type and identity are the same' do
|
34
|
+
other = described_class.new(identity: identity, work_type: work_type)
|
35
|
+
expect(subject == other).to be_truthy
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'is != if work type is the same but not identity' do
|
39
|
+
other = described_class.new(identity: identity + 'not', work_type: work_type)
|
40
|
+
expect(subject == other).to be_falsey
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'is != if identity is the same but not work type' do
|
44
|
+
other = described_class.new(identity: identity, work_type: work_type + 'not')
|
45
|
+
expect(subject == other).to be_falsey
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'is "nil" when we are comparing against other objects' do
|
49
|
+
other = double("Other")
|
50
|
+
expect(subject <=> other).to be_nil
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'is based on the array underlying array' do
|
54
|
+
other = described_class.new(identity: 'Z' + identity, work_type: 'A' + work_type)
|
55
|
+
# The other one is greater than this one
|
56
|
+
expect(subject <=> other).to eq(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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_type'
|
5
|
+
require 'hydramata/works/predicate_sets/storage'
|
6
|
+
require 'hydramata/works/linters/implement_predicate_set_interface_matcher'
|
7
|
+
|
8
|
+
module Hydramata
|
9
|
+
module Works
|
10
|
+
module PredicateSets
|
11
|
+
|
12
|
+
describe Storage do
|
13
|
+
it { should implement_predicate_set_interface }
|
14
|
+
|
15
|
+
let(:identity) { 'a predicate' }
|
16
|
+
let(:work_type) { WorkTypes::Storage.create(identity: 'a_work_type') }
|
17
|
+
subject do
|
18
|
+
described_class.create(
|
19
|
+
work_type: work_type,
|
20
|
+
identity: identity,
|
21
|
+
presentation_sequence: 1,
|
22
|
+
name_for_application_usage: 'predicate_set_name'
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'belongs to a work_type' do
|
27
|
+
expect(subject.work_type).to eq(work_type)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'has #to_predicate_set' do
|
31
|
+
expect(described_class.new.to_predicate_set).to implement_predicate_set_interface
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,16 @@
|
|
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/predicate'
|
5
|
+
require 'hydramata/works/linters/implement_predicate_interface_matcher'
|
6
|
+
require 'hydramata/works/linters/implement_data_definition_interface_matcher'
|
7
|
+
|
8
|
+
module Hydramata
|
9
|
+
module Works
|
10
|
+
describe Predicate do
|
11
|
+
subject { described_class.new }
|
12
|
+
it { should implement_predicate_interface }
|
13
|
+
it { should implement_data_definition_interface }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,78 @@
|
|
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/predicates/storage'
|
5
|
+
require 'hydramata/works/linters/implement_predicate_interface_matcher'
|
6
|
+
|
7
|
+
module Hydramata
|
8
|
+
module Works
|
9
|
+
module Predicates
|
10
|
+
|
11
|
+
describe Storage do
|
12
|
+
subject { described_class.new }
|
13
|
+
|
14
|
+
let(:identity) { 'http://hello.com/world' }
|
15
|
+
let(:predicate) do
|
16
|
+
described_class.create(
|
17
|
+
identity: identity,
|
18
|
+
name_for_application_usage: 'hello-world',
|
19
|
+
datastream_name: 'descMetadata',
|
20
|
+
value_coercer_name: 'SimpleParser',
|
21
|
+
value_parser_name: 'SimpleParser',
|
22
|
+
indexing_strategy: 'dsti',
|
23
|
+
validations: '{ "presence": { "on": "create" } }'
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
it { should implement_predicate_interface }
|
28
|
+
|
29
|
+
context '#to_predicate' do
|
30
|
+
it 'coerces itself to a predicate' do
|
31
|
+
expect(described_class.new.to_predicate).to implement_predicate_interface
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context '.find_by_identity' do
|
36
|
+
|
37
|
+
it 'returns a Predicate object when identity exists' do
|
38
|
+
predicate # creating the object
|
39
|
+
expect(described_class.find_by_identity!(identity)).to implement_predicate_interface
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns nil when identity is missing' do
|
43
|
+
# @TODO - Should this be a NullPredicate?
|
44
|
+
expect { described_class.find_by_identity!(identity) }.to raise_error
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context '.existing_attributes_for' do
|
49
|
+
it 'should return the existing predicate attributes' do
|
50
|
+
predicate
|
51
|
+
keys = [
|
52
|
+
:id,
|
53
|
+
:identity,
|
54
|
+
:name_for_application_usage,
|
55
|
+
:datastream_name,
|
56
|
+
:value_coercer_name,
|
57
|
+
:value_parser_name,
|
58
|
+
:indexing_strategy
|
59
|
+
]
|
60
|
+
actual_values = described_class.existing_attributes_for(identity).values_at(keys)
|
61
|
+
# Because date comparisons are a bit wonky
|
62
|
+
expect(actual_values).to eq(predicate.attributes.values_at(keys))
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should return the identity if a matching predicate was not found' do
|
66
|
+
expect(described_class.existing_attributes_for(identity)).to eq(identity: identity)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should handle connection failed' do
|
70
|
+
expect(described_class).to receive(:find_by_identity!).and_raise(ActiveRecord::ConnectionNotEstablished)
|
71
|
+
expect(described_class.existing_attributes_for(identity)).to eq(identity: identity)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|