yaks 0.7.7 → 0.8.0.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/Rakefile +1 -1
  4. data/lib/yaks/attributes.rb +17 -11
  5. data/lib/yaks/builder.rb +43 -0
  6. data/lib/yaks/changelog.rb +2 -2
  7. data/lib/yaks/collection_mapper.rb +0 -2
  8. data/lib/yaks/config.rb +52 -32
  9. data/lib/yaks/configurable.rb +43 -14
  10. data/lib/yaks/errors.rb +1 -0
  11. data/lib/yaks/format/collection_json.rb +37 -5
  12. data/lib/yaks/format/hal.rb +8 -2
  13. data/lib/yaks/format/halo.rb +16 -9
  14. data/lib/yaks/format/json_api.rb +21 -2
  15. data/lib/yaks/format.rb +21 -15
  16. data/lib/yaks/html5_forms.rb +3 -2
  17. data/lib/yaks/identifier/link_relation.rb +17 -0
  18. data/lib/yaks/mapper/attribute.rb +2 -2
  19. data/lib/yaks/mapper/config.rb +1 -15
  20. data/lib/yaks/mapper/form/config.rb +21 -0
  21. data/lib/yaks/mapper/form/field/option.rb +20 -0
  22. data/lib/yaks/mapper/form/field.rb +13 -26
  23. data/lib/yaks/mapper/form/fieldset.rb +43 -0
  24. data/lib/yaks/mapper/form.rb +41 -16
  25. data/lib/yaks/mapper/link.rb +9 -7
  26. data/lib/yaks/mapper.rb +15 -7
  27. data/lib/yaks/null_resource.rb +2 -1
  28. data/lib/yaks/pipeline.rb +42 -0
  29. data/lib/yaks/primitivize.rb +0 -1
  30. data/lib/yaks/reader/hal.rb +63 -0
  31. data/lib/yaks/resource/form/field.rb +19 -0
  32. data/lib/yaks/resource/form/fieldset.rb +13 -0
  33. data/lib/yaks/resource/form.rb +6 -10
  34. data/lib/yaks/resource.rb +19 -2
  35. data/lib/yaks/runner.rb +13 -38
  36. data/lib/yaks/serializer.rb +34 -1
  37. data/lib/yaks/util.rb +8 -2
  38. data/lib/yaks/version.rb +1 -1
  39. data/lib/yaks.rb +37 -10
  40. data/resources/iana-link-relations.csv +152 -0
  41. data/spec/acceptance/acceptance_spec.rb +4 -3
  42. data/spec/acceptance/json_shared_examples.rb +11 -0
  43. data/spec/acceptance/models.rb +1 -1
  44. data/spec/integration/dynamic_form_fields_spec.rb +36 -0
  45. data/spec/integration/fieldset_spec.rb +62 -0
  46. data/spec/integration/map_to_resource_spec.rb +0 -2
  47. data/spec/json/confucius.halo.json +0 -1
  48. data/spec/sanity_spec.rb +0 -2
  49. data/spec/spec_helper.rb +3 -3
  50. data/spec/unit/yaks/attributes_spec.rb +3 -5
  51. data/spec/unit/yaks/{stateful_builder_spec.rb → builder_spec.rb} +8 -10
  52. data/spec/unit/yaks/collection_mapper_spec.rb +0 -2
  53. data/spec/unit/yaks/collection_resource_spec.rb +0 -2
  54. data/spec/unit/yaks/config_spec.rb +9 -15
  55. data/spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb +0 -2
  56. data/spec/unit/yaks/default_policy_spec.rb +0 -2
  57. data/spec/unit/yaks/format/collection_json_spec.rb +195 -3
  58. data/spec/unit/yaks/format/hal_spec.rb +0 -2
  59. data/spec/unit/yaks/format/halo_spec.rb +0 -1
  60. data/spec/unit/yaks/format/html_spec.rb +0 -2
  61. data/spec/unit/yaks/format/json_api_spec.rb +0 -2
  62. data/spec/unit/yaks/format_spec.rb +4 -6
  63. data/spec/unit/yaks/fp/callable_spec.rb +0 -2
  64. data/spec/unit/yaks/fp_spec.rb +0 -2
  65. data/spec/unit/yaks/mapper/association_mapper_spec.rb +0 -2
  66. data/spec/unit/yaks/mapper/association_spec.rb +0 -2
  67. data/spec/unit/yaks/mapper/attribute_spec.rb +0 -2
  68. data/spec/unit/yaks/mapper/config_spec.rb +6 -167
  69. data/spec/unit/yaks/mapper/form/field_spec.rb +0 -2
  70. data/spec/unit/yaks/mapper/form_spec.rb +2 -26
  71. data/spec/unit/yaks/mapper/has_many_spec.rb +0 -2
  72. data/spec/unit/yaks/mapper/has_one_spec.rb +0 -2
  73. data/spec/unit/yaks/mapper/link_spec.rb +13 -2
  74. data/spec/unit/yaks/mapper_spec.rb +2 -10
  75. data/spec/unit/yaks/null_resource_spec.rb +2 -4
  76. data/spec/unit/yaks/pipeline_spec.rb +140 -0
  77. data/spec/unit/yaks/primitivize_spec.rb +0 -2
  78. data/spec/unit/yaks/resource/link_spec.rb +0 -2
  79. data/spec/unit/yaks/resource_spec.rb +2 -4
  80. data/spec/unit/yaks/runner_spec.rb +52 -92
  81. data/spec/unit/yaks/serializer_spec.rb +0 -2
  82. data/spec/unit/yaks/util_spec.rb +12 -2
  83. metadata +58 -23
  84. data/lib/yaks/config/dsl.rb +0 -174
  85. data/lib/yaks/mapper/class_methods.rb +0 -47
  86. data/lib/yaks/stateful_builder.rb +0 -63
  87. data/spec/unit/yaks/config/dsl_spec.rb +0 -92
  88. data/spec/unit/yaks/configurable_spec.rb +0 -55
  89. data/spec/unit/yaks/mapper/class_methods_spec.rb +0 -83
data/lib/yaks.rb CHANGED
@@ -1,9 +1,8 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require 'forwardable'
4
2
  require 'set'
5
3
  require 'pathname'
6
4
  require 'json'
5
+ require 'csv'
7
6
 
8
7
  require 'anima'
9
8
  require 'concord'
@@ -18,10 +17,13 @@ require 'yaks/fp'
18
17
  require 'yaks/fp/callable'
19
18
  require 'yaks/primitivize'
20
19
  require 'yaks/attributes'
21
- require 'yaks/stateful_builder'
20
+ require 'yaks/builder'
22
21
  require 'yaks/errors'
23
22
 
24
23
  require 'yaks/default_policy'
24
+ require 'yaks/serializer'
25
+ require 'yaks/config'
26
+
25
27
 
26
28
  module Yaks
27
29
  Undefined = Module.new.freeze
@@ -29,38 +31,63 @@ module Yaks
29
31
  # Set the Root constant as the gems root path
30
32
  Root = Pathname(__FILE__).join('../..')
31
33
 
34
+ DSL_METHODS = [
35
+ :format_options,
36
+ :rel_template,
37
+ :before,
38
+ :after,
39
+ :around,
40
+ :skip,
41
+ :namespace,
42
+ :mapper_namespace,
43
+ :serializer,
44
+ :json_serializer,
45
+ :map_to_primitive,
46
+ ]
47
+
48
+ ConfigBuilder = Builder.new(Yaks::Config) do
49
+ def_set *Yaks::Config.attributes.names
50
+ def_forward *DSL_METHODS
51
+ def_forward *Yaks::DefaultPolicy.public_instance_methods(false)
52
+ end
53
+
32
54
  class << self
33
55
  # @param [Proc] blk
34
56
  # @return [Yaks::Config]
57
+
35
58
  def new(&blk)
36
- Yaks::Config.new(&blk)
59
+ ConfigBuilder.create(&blk)
37
60
  end
38
61
  end
39
62
  end
40
63
 
64
+
41
65
  require 'yaks/resource'
42
66
  require 'yaks/null_resource'
43
67
  require 'yaks/resource/link'
44
68
  require 'yaks/collection_resource'
45
69
 
46
70
  require 'yaks/html5_forms'
71
+ require 'yaks/identifier/link_relation'
47
72
 
48
73
  require 'yaks/mapper/association'
49
74
  require 'yaks/mapper/has_one'
50
75
  require 'yaks/mapper/has_many'
51
76
  require 'yaks/mapper/attribute'
52
77
  require 'yaks/mapper/link'
53
- require 'yaks/mapper/form'
78
+ require 'yaks/mapper/form/config'
79
+ require 'yaks/mapper/form/field/option'
54
80
  require 'yaks/mapper/form/field'
81
+ require 'yaks/mapper/form/fieldset'
82
+ require 'yaks/mapper/form'
55
83
  require 'yaks/mapper/config'
56
- require 'yaks/mapper/class_methods'
57
84
  require 'yaks/mapper'
58
85
  require 'yaks/mapper/association_mapper'
59
86
  require 'yaks/collection_mapper'
60
87
 
61
88
  require 'yaks/resource/form'
62
-
63
- require 'yaks/serializer'
89
+ require 'yaks/resource/form/field'
90
+ require 'yaks/resource/form/fieldset'
64
91
 
65
92
  require 'yaks/format'
66
93
  require 'yaks/format/hal'
@@ -68,6 +95,6 @@ require 'yaks/format/halo'
68
95
  require 'yaks/format/json_api'
69
96
  require 'yaks/format/collection_json'
70
97
 
71
- require 'yaks/config/dsl'
72
- require 'yaks/config'
98
+ require 'yaks/reader/hal'
99
+ require 'yaks/pipeline'
73
100
  require 'yaks/runner'
@@ -0,0 +1,152 @@
1
+ Relation Name,Description,Reference,Notes
2
+ about,Refers to a resource that is the subject of the link's context.,"[RFC6903], section 2",
3
+ alternate,Refers to a substitute for this context,[http://www.w3.org/TR/html5/links.html#link-type-alternate],
4
+ appendix,Refers to an appendix.,[http://www.w3.org/TR/1999/REC-html401-19991224],
5
+ archives,"Refers to a collection of records, documents, or other
6
+ materials of historical interest.",[http://www.w3.org/TR/2011/WD-html5-20110113/links.html#rel-archives],
7
+ author,Refers to the context's author.,[http://www.w3.org/TR/html5/links.html#link-type-author],
8
+ bookmark,Gives a permanent link to use for bookmarking purposes.,[http://www.w3.org/TR/html5/links.html#link-type-bookmark],
9
+ canonical,Designates the preferred version of a resource (the IRI and its contents).,[RFC6596],
10
+ chapter,Refers to a chapter in a collection of resources.,[http://www.w3.org/TR/1999/REC-html401-19991224],
11
+ collection,The target IRI points to a resource which represents the collection resource for the context IRI.,[RFC6573],
12
+ contents,Refers to a table of contents.,[http://www.w3.org/TR/1999/REC-html401-19991224],
13
+ copyright,"Refers to a copyright statement that applies to the
14
+ link's context.",[http://www.w3.org/TR/1999/REC-html401-19991224],
15
+ create-form,The target IRI points to a resource where a submission form can be obtained.,[RFC6861],
16
+ current,"Refers to a resource containing the most recent
17
+ item(s) in a collection of resources.",[RFC5005],
18
+ describedby,"Refers to a resource providing information about the
19
+ link's context.",[http://www.w3.org/TR/powder-dr/#assoc-linking],
20
+ describes,"The relationship A 'describes' B asserts that
21
+ resource A provides a description of resource B. There are no
22
+ constraints on the format or representation of either A or B,
23
+ neither are there any further constraints on either resource.",[RFC6892],"This link relation type is the inverse of the 'describedby'
24
+ relation type. While 'describedby' establishes a relation from
25
+ the described resource back to the resource that describes it,
26
+ 'describes' established a relation from the describing resource to
27
+ the resource it describes. If B is 'describedby' A, then A
28
+ 'describes' B."
29
+ disclosure,Refers to a list of patent disclosures made with respect to material for which 'disclosure' relation is specified.,[RFC6579],
30
+ duplicate,"Refers to a resource whose available representations
31
+ are byte-for-byte identical with the corresponding representations of
32
+ the context IRI.",[RFC6249],"This relation is for static resources. That is, an HTTP GET
33
+ request on any duplicate will return the same representation. It
34
+ does not make sense for dynamic or POSTable resources and should not
35
+ be used for them."
36
+ edit,"Refers to a resource that can be used to edit the
37
+ link's context.",[RFC5023],
38
+ edit-form,"The target IRI points to a resource where a submission form for
39
+ editing associated resource can be obtained.",[RFC6861],
40
+ edit-media,"Refers to a resource that can be used to edit media
41
+ associated with the link's context.",[RFC5023],
42
+ enclosure,"Identifies a related resource that is potentially
43
+ large and might require special handling.",[RFC4287],
44
+ first,"An IRI that refers to the furthest preceding resource
45
+ in a series of resources.",[RFC5988],"This relation type registration did not indicate a
46
+ reference. Originally requested by Mark Nottingham in December
47
+ 2004."
48
+ glossary,Refers to a glossary of terms.,[http://www.w3.org/TR/1999/REC-html401-19991224],
49
+ help,Refers to context-sensitive help.,[http://www.w3.org/TR/html5/links.html#link-type-help],
50
+ hosts,"Refers to a resource hosted by the server indicated by
51
+ the link context.",[RFC6690],"This relation is used in CoRE where links are retrieved as a
52
+ ""/.well-known/core"" resource representation, and is the default
53
+ relation type in the CoRE Link Format."
54
+ hub,"Refers to a hub that enables registration for
55
+ notification of updates to the context.",[http://pubsubhubbub.googlecode.com],This relation type was requested by Brett Slatkin.
56
+ icon,Refers to an icon representing the link's context.,[http://www.w3.org/TR/html5/links.html#link-type-icon],
57
+ index,Refers to an index.,[http://www.w3.org/TR/1999/REC-html401-19991224],
58
+ item,The target IRI points to a resource that is a member of the collection represented by the context IRI.,[RFC6573],
59
+ last,"An IRI that refers to the furthest following resource
60
+ in a series of resources.",[RFC5988],"This relation type registration did not indicate a
61
+ reference. Originally requested by Mark Nottingham in December
62
+ 2004."
63
+ latest-version,"Points to a resource containing the latest (e.g.,
64
+ current) version of the context.",[RFC5829],
65
+ license,Refers to a license associated with this context.,[RFC4946],"For implications of use in HTML, see:
66
+ http://www.w3.org/TR/html5/links.html#link-type-license"
67
+ lrdd,"Refers to further information about the link's context,
68
+ expressed as a LRDD (""Link-based Resource Descriptor Document"")
69
+ resource. See [RFC6415] for information about
70
+ processing this relation type in host-meta documents. When used
71
+ elsewhere, it refers to additional links and other metadata.
72
+ Multiple instances indicate additional LRDD resources. LRDD
73
+ resources MUST have an ""application/xrd+xml"" representation, and
74
+ MAY have others.",[RFC6415],
75
+ memento,"The Target IRI points to a Memento, a fixed resource that will not change state anymore.",[RFC7089],"A Memento for an Original Resource is a resource that
76
+ encapsulates a prior state of the Original Resource."
77
+ monitor,Refers to a resource that can be used to monitor changes in an HTTP resource.,[RFC5989],
78
+ monitor-group,Refers to a resource that can be used to monitor changes in a specified group of HTTP resources.,[RFC5989],
79
+ next,"Indicates that the link's context is a part of a series, and
80
+ that the next in the series is the link target.",[http://www.w3.org/TR/html5/links.html#link-type-next],
81
+ next-archive,Refers to the immediately following archive resource.,[RFC5005],
82
+ nofollow,Indicates that the context’s original author or publisher does not endorse the link target.,[http://www.w3.org/TR/html5/links.html#link-type-nofollow],
83
+ noreferrer,Indicates that no referrer information is to be leaked when following the link.,[http://www.w3.org/TR/html5/links.html#link-type-noreferrer],
84
+ original,The Target IRI points to an Original Resource.,[RFC7089],"An Original Resource is a resource that exists or used to
85
+ exist, and for which access to one of its prior states may be
86
+ required."
87
+ payment,Indicates a resource where payment is accepted.,[RFC5988],"This relation type registration did not indicate a
88
+ reference. Requested by Joshua Kinberg and Robert Sayre. It is
89
+ meant as a general way to facilitate acts of payment, and thus
90
+ this specification makes no assumptions on the type of payment or
91
+ transaction protocol. Examples may include a web page where
92
+ donations are accepted or where goods and services are available
93
+ for purchase. rel=""payment"" is not intended to initiate an
94
+ automated transaction. In Atom documents, a link element with a
95
+ rel=""payment"" attribute may exist at the feed/channel level and/or
96
+ the entry/item level. For example, a rel=""payment"" link at the
97
+ feed/channel level may point to a ""tip jar"" URI, whereas an entry/
98
+ item containing a book review may include a rel=""payment"" link
99
+ that points to the location where the book may be purchased
100
+ through an online retailer."
101
+ predecessor-version,"Points to a resource containing the predecessor
102
+ version in the version history.",[RFC5829],
103
+ prefetch,Indicates that the link target should be preemptively cached.,[http://www.w3.org/TR/html5/links.html#link-type-prefetch],
104
+ prev,"Indicates that the link's context is a part of a series, and
105
+ that the previous in the series is the link target.",[http://www.w3.org/TR/html5/links.html#link-type-prev],
106
+ preview,Refers to a resource that provides a preview of the link's context.,"[RFC6903], section 3",
107
+ previous,"Refers to the previous resource in an ordered series
108
+ of resources. Synonym for ""prev"".",[http://www.w3.org/TR/1999/REC-html401-19991224],
109
+ prev-archive,Refers to the immediately preceding archive resource.,[RFC5005],
110
+ privacy-policy,Refers to a privacy policy associated with the link's context.,"[RFC6903], section 4",
111
+ profile,"Identifying that a resource representation conforms
112
+ to a certain profile, without affecting the non-profile semantics
113
+ of the resource representation.",[RFC6906],"Profile URIs are primarily intended to be used as
114
+ identifiers, and thus clients SHOULD NOT indiscriminately access
115
+ profile URIs."
116
+ related,Identifies a related resource.,[RFC4287],
117
+ replies,"Identifies a resource that is a reply to the context
118
+ of the link.",[RFC4685],
119
+ search,"Refers to a resource that can be used to search through
120
+ the link's context and related resources.",[http://www.opensearch.org/Specifications/OpenSearch/1.1],
121
+ section,Refers to a section in a collection of resources.,[http://www.w3.org/TR/1999/REC-html401-19991224],
122
+ self,Conveys an identifier for the link's context.,[RFC4287],
123
+ service,"Indicates a URI that can be used to retrieve a
124
+ service document.",[RFC5023],"When used in an Atom document, this relation type specifies
125
+ Atom Publishing Protocol service documents by default. Requested
126
+ by James Snell."
127
+ start,"Refers to the first resource in a collection of
128
+ resources.",[http://www.w3.org/TR/1999/REC-html401-19991224],
129
+ stylesheet,Refers to a stylesheet.,[http://www.w3.org/TR/html5/links.html#link-type-stylesheet],
130
+ subsection,"Refers to a resource serving as a subsection in a
131
+ collection of resources.",[http://www.w3.org/TR/1999/REC-html401-19991224],
132
+ successor-version,"Points to a resource containing the successor version
133
+ in the version history.",[RFC5829],
134
+ tag,"Gives a tag (identified by the given address) that applies to
135
+ the current document.",[http://www.w3.org/TR/html5/links.html#link-type-tag],
136
+ terms-of-service,Refers to the terms of service associated with the link's context.,"[RFC6903], section 5",
137
+ timegate,The Target IRI points to a TimeGate for an Original Resource.,[RFC7089],"A TimeGate for an Original Resource is a resource that is
138
+ capable of datetime negotiation to support access to prior states
139
+ of the Original Resource."
140
+ timemap,The Target IRI points to a TimeMap for an Original Resource.,[RFC7089],"A TimeMap for an Original Resource is a resource from which
141
+ a list of URIs of Mementos of the Original Resource is available."
142
+ type,Refers to a resource identifying the abstract semantic type of which the link's context is considered to be an instance.,"[RFC6903], section 6",
143
+ up,"Refers to a parent document in a hierarchy of
144
+ documents.",[RFC5988],"This relation type registration did not indicate a
145
+ reference. Requested by Noah Slater."
146
+ version-history,"Points to a resource containing the version history
147
+ for the context.",[RFC5829],
148
+ via,"Identifies a resource that is the source of the
149
+ information in the link's context.",[RFC4287],
150
+ working-copy,Points to a working copy for this resource.,[RFC5829],
151
+ working-copy-of,"Points to the versioned resource from which this
152
+ working copy was obtained.",[RFC5829],
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  require 'acceptance/models'
4
2
  require 'acceptance/json_shared_examples'
5
3
 
@@ -20,6 +18,9 @@ RSpec.describe Yaks::Format::Hal do
20
18
 
21
19
  include_examples 'JSON output format', yaks_rel_template, :hal, 'confucius'
22
20
  include_examples 'JSON output format', yaks_policy_dsl, :hal, 'confucius'
21
+
22
+ include_examples 'JSON round trip', yaks_rel_template, :hal, 'confucius'
23
+ include_examples 'JSON round trip', yaks_policy_dsl, :hal, 'confucius'
23
24
  end
24
25
 
25
26
  RSpec.describe Yaks::Format::Halo do
@@ -44,7 +45,7 @@ end
44
45
  RSpec.describe Yaks::Format::CollectionJson do
45
46
  youtypeit_yaks = Yaks.new do
46
47
  default_format :collection_json
47
- namespace Youtypeitwepostit
48
+ mapper_namespace Youtypeitwepostit
48
49
  skip :serialize
49
50
  end
50
51
 
@@ -6,3 +6,14 @@ RSpec.shared_examples_for 'JSON output format' do |yaks, format, name|
6
6
 
7
7
  it { should deep_eql output }
8
8
  end
9
+
10
+ RSpec.shared_examples_for 'JSON round trip' do |yaks, format, name|
11
+ let(:json) { load_json_fixture("#{name}.#{format}") }
12
+
13
+ subject {
14
+ resource = yaks.read(json, hooks: [[:skip, :parse]])
15
+ yaks.call(resource, hooks: [[:skip, :map]], mapper: Struct.new(:context))
16
+ }
17
+
18
+ it { should deep_eql json }
19
+ end
@@ -26,7 +26,7 @@ class ScholarMapper < LiteratureBaseMapper
26
26
  has_many :works
27
27
 
28
28
  link 'http://literature.example.com/rels/quotes', 'http://literature.example.com/quotes/?author={downcased_pinyin}&q={query}', expand: [:downcased_pinyin], title: 'Search for quotes'
29
- link :self, 'http://literature.example.com/authors/{downcased_pinyin}'
29
+ link :self, 'http://literature.example.com/authors/{downcased_pinyin}', replace: true
30
30
 
31
31
  form :search do
32
32
  title 'Find a Scholar'
@@ -0,0 +1,36 @@
1
+ RSpec.describe 'dynamic form fields' do
2
+ let(:mapper) do
3
+ Class.new(Yaks::Mapper) do
4
+ type :awesome
5
+ form :foo do
6
+ text :name
7
+ dynamic do |object|
8
+ object.each do |x|
9
+ text x
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ let(:yaks) { Yaks.new }
17
+ let(:object) { [:a, :b, :c] }
18
+
19
+ it 'should create dynamic form fields' do
20
+
21
+ expect(yaks.map(object, mapper: mapper)).to eql Yaks::Resource.new(
22
+ type: :awesome,
23
+ forms: [
24
+ Yaks::Resource::Form.new(
25
+ name: :foo,
26
+ fields: [
27
+ Yaks::Resource::Form::Field.new(name: :name, type: :text),
28
+ Yaks::Resource::Form::Field.new(name: :a, type: :text),
29
+ Yaks::Resource::Form::Field.new(name: :b, type: :text),
30
+ Yaks::Resource::Form::Field.new(name: :c, type: :text)
31
+ ]
32
+ )
33
+ ]
34
+ )
35
+ end
36
+ end
@@ -0,0 +1,62 @@
1
+ RSpec.describe 'dynamic form fields' do
2
+ let(:mapper) do
3
+ Class.new(Yaks::Mapper) do
4
+ type :awesome
5
+ form :foo do
6
+ fieldset do
7
+ legend "I am legend"
8
+ text :bar
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ let(:yaks) { Yaks.new }
15
+
16
+ it 'should create fieldsets with fields' do
17
+ expect(yaks.map(:foo, mapper: mapper)).to eql Yaks::Resource.new(
18
+ type: :awesome,
19
+ forms: [
20
+ Yaks::Resource::Form.new(
21
+ name: :foo,
22
+ fields: [
23
+ Yaks::Resource::Form::Fieldset.new(
24
+ fields: [
25
+ Yaks::Resource::Form::Field.new(name: "I am legend", type: :legend),
26
+ Yaks::Resource::Form::Field.new(name: :bar, type: :text)
27
+ ]
28
+ )
29
+ ]
30
+ )
31
+ ]
32
+ )
33
+ end
34
+
35
+ it 'should convert to halo' do
36
+ expect(
37
+ yaks.with(default_format: :halo, hooks: [[:skip, :serialize]]).call(:foo, mapper: mapper)
38
+ ).to eql(
39
+ {
40
+ "_controls" => {
41
+ "foo" => {
42
+ "name" =>"foo",
43
+ "fields" => [
44
+ {
45
+ "type" => "fieldset",
46
+ "fields" => [
47
+ {
48
+ "name" => "I am legend",
49
+ "type" => "legend"
50
+ }, {
51
+ "name" => "bar",
52
+ "type" => "text"
53
+ }
54
+ ]
55
+ }
56
+ ]
57
+ }
58
+ }
59
+ }
60
+ )
61
+ end
62
+ end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe 'Mapping domain models to Resource objects' do
4
2
  include_context 'fixtures'
5
3
  include_context 'yaks context'
@@ -57,7 +57,6 @@
57
57
  "_controls": {
58
58
  "search": {
59
59
  "name": "search",
60
- "href": null,
61
60
  "title": "Find a Scholar",
62
61
  "method": "POST",
63
62
  "media_type": "application/x-www-form-urlencoded",
data/spec/sanity_spec.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe 'assorted sanity checks' do
4
2
  let(:resource_methods) { Yaks::Resource.public_instance_methods.sort }
5
3
  let(:collection_resource_methods) { Yaks::CollectionResource.public_instance_methods.sort }
data/spec/spec_helper.rb CHANGED
@@ -24,9 +24,9 @@ RSpec.configure do |rspec|
24
24
  rspec.backtrace_exclusion_patterns = [] if ENV['FULLSTACK']
25
25
  rspec.disable_monkey_patching!
26
26
  rspec.raise_errors_for_deprecations!
27
- rspec.around(:each) do |example|
28
- Timeout.timeout(1, &example)
29
- end
27
+ # rspec.around(:each) do |example|
28
+ # Timeout.timeout(1, &example)
29
+ # end
30
30
  end
31
31
 
32
32
  Bogus.configure do |bogus|
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Attributes do
4
2
  subject { Class.new { include Yaks::Attributes.new(:foo, bar: 3) } }
5
3
 
@@ -11,8 +9,8 @@ RSpec.describe Yaks::Attributes do
11
9
  expect(subject.new(foo: 3).bar).to equal 3
12
10
  end
13
11
 
14
- it 'should allow updating through attribute methods' do
15
- expect(subject.new(foo: 3).foo(4).to_h).to eql(foo: 4, bar: 3)
12
+ it 'should allow updating through with' do
13
+ expect(subject.new(foo: 3).with(foo: 4).to_h).to eql(foo: 4, bar: 3)
16
14
  end
17
15
 
18
16
  it 'should add an #append_to method' do
@@ -134,7 +132,7 @@ WidgetContainer.new(
134
132
 
135
133
  describe '#initialize' do
136
134
  it 'should take hash-based args' do
137
- expect(widget_container.new(widgets: [:bar])).to eql widget_container.new.widgets([:bar])
135
+ expect(widget_container.new(widgets: [:bar])).to eql widget_container.new.with_widgets([:bar])
138
136
  end
139
137
 
140
138
  it 'should use defaults when available' do
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Yaks::StatefulBuilder do
1
+ RSpec.describe Yaks::Builder do
4
2
  class Buildable
5
3
  include Yaks::Attributes.new(:foo, :bar)
6
4
 
@@ -9,7 +7,7 @@ RSpec.describe Yaks::StatefulBuilder do
9
7
  end
10
8
 
11
9
  def finalize
12
- update(foo: 7, bar: 8)
10
+ with(foo: 7, bar: 8)
13
11
  end
14
12
 
15
13
  def wrong_type(x, y)
@@ -18,7 +16,12 @@ RSpec.describe Yaks::StatefulBuilder do
18
16
 
19
17
  end
20
18
 
21
- subject { Yaks::StatefulBuilder.new(Buildable, [:foo, :bar, :update, :finalize, :wrong_type]) }
19
+ subject do
20
+ Yaks::Builder.new(Buildable) do
21
+ def_set :foo, :bar
22
+ def_forward :finalize, :wrong_type, :update
23
+ end
24
+ end
22
25
 
23
26
  it 'should keep state' do
24
27
  expect(
@@ -33,9 +36,4 @@ RSpec.describe Yaks::StatefulBuilder do
33
36
  expect( subject.create(3, 4) { finalize } ).to eql Buildable.new(foo: 7, bar: 8)
34
37
  end
35
38
 
36
- describe 'kind_of?' do
37
- it 'should test if the returned thing is of the right type' do
38
- expect { subject.create(3, 4) { wrong_type(1,'2') }}.to raise_exception Yaks::IllegalStateError, 'Buildable#wrong_type(1, "2") returned "foo 1 2". Expected instance of Buildable'
39
- end
40
- end
41
39
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::CollectionMapper do
4
2
  include_context 'fixtures'
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::CollectionResource do
4
2
  subject(:collection) { described_class.new(init_opts) }
5
3
  let(:init_opts) { {} }
@@ -1,26 +1,20 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::Config do
4
2
  include_context 'fixtures'
5
3
 
6
4
  def self.configure(&blk)
7
- subject(:config) { described_class.new(&blk) }
5
+ subject(:config) { Yaks::ConfigBuilder.create(&blk) }
8
6
  end
9
7
 
10
8
  describe '#initialize' do
11
9
  context 'defaults' do
12
10
  configure {}
13
11
 
14
- its(:default_format) { should equal :hal }
15
- its(:policy_class) { should < Yaks::DefaultPolicy }
16
- its(:primitivize) { should be_a Yaks::Primitivize }
17
- its(:serializers) { should eql(Yaks::Serializer.all) }
18
- its(:serializers) { should_not equal(Yaks::Serializer.all) }
19
- its(:hooks) { should eql([]) }
20
-
21
- it 'should have empty format options' do
22
- expect(config.format_options[:hal]).to eql({})
23
- end
12
+ its(:default_format) { should equal :hal }
13
+ its(:policy_class) { should <= Yaks::DefaultPolicy }
14
+ its(:primitivize) { should be_a Yaks::Primitivize }
15
+ its(:serializers) { should eql(Yaks::Serializer.all) }
16
+ its(:hooks) { should eql([]) }
17
+ its(:format_options_hash) { should eql({})}
24
18
  end
25
19
 
26
20
  context 'with a default format' do
@@ -34,7 +28,7 @@ RSpec.describe Yaks::Config do
34
28
  context 'with a custom policy class' do
35
29
  MyPolicy = Struct.new(:options)
36
30
  configure do
37
- policy MyPolicy
31
+ policy_class MyPolicy
38
32
  end
39
33
 
40
34
  its(:policy_class) { should equal MyPolicy }
@@ -55,7 +49,7 @@ RSpec.describe Yaks::Config do
55
49
  end
56
50
 
57
51
  specify do
58
- expect(config.format_options[:hal]).to eql(plural_links: [:self, :profile])
52
+ expect(config.format_options_hash[:hal]).to eql(plural_links: [:self, :profile])
59
53
  end
60
54
  end
61
55
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::DefaultPolicy, '#derive_mapper_from_object' do
4
2
  subject(:policy) { described_class.new(options) }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Yaks::DefaultPolicy do
4
2
  subject(:policy) { described_class.new( options ) }
5
3