yaks 0.8.0.alpha → 0.8.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae9407b2b6c0f2f15c86276063e02ea2d7f9a4f7
4
- data.tar.gz: 776d6202349cbf8854506a3d89f06134f2bee12f
3
+ metadata.gz: ad5b36d2206adbc6ccc3a79eb484d70eb6a56f62
4
+ data.tar.gz: e902f2b6b88e269d4dc788e3e19969f881ec107c
5
5
  SHA512:
6
- metadata.gz: 23ec9ff975f4a4da763720f8ce5d11d8346c1e23f592070e9517dc340605d5221adad9e9a9c64db38158fc88af4b03d21717fc478137dbf4a2f85836a99dd417
7
- data.tar.gz: 64f8c4e3078416d4ccffdd572c8eadd0606d5e11c950085f16d5fede07aea162e3338c038284d92c2bbc1974c0a32e98fda97aa4a8d17d1a0d40755c17ba49ad
6
+ metadata.gz: 38efaa84bb8b2ae036fd7bc04aae45da7d9ecd8cb386f7dfbe95ee0470c52ffdf1bbf62c81893f599fa030a9859fe1496c764bc744a3d44ddaceecc36f1de619
7
+ data.tar.gz: 93e074f082306f8a8bbd6f36a0564a3d30c3b056c2b29061506155ffaec1725268170d427f751fda58959ece321fa625fc00f712877d5040a9727cb88bf01b0e
data/README.md CHANGED
@@ -394,11 +394,29 @@ end
394
394
 
395
395
  ### Collection+JSON
396
396
 
397
+ Collection+JSON has support for write templates. To use them, the `:template`
398
+ option can be used. It will map the specified form to a CJ template. Please
399
+ notice that CJ only allows one template per representation.
400
+
397
401
  ```ruby
398
402
  default_format :collection_json
403
+
404
+ collection_json = Yaks.new do
405
+ format_options :collection_json, template: :my_template_form
406
+ end
407
+
408
+ class PostMapper < Yaks::Mapper
409
+ form :my_template_form do
410
+ # This will be used for template
411
+ end
412
+
413
+ form :not_my_template do
414
+ # This won't be used for template
415
+ end
416
+ end
399
417
  ```
400
418
 
401
- Subresources aren't mapped because Collection+JSON doesn't really have that concept, and the other way around templates and queries don't exist (yet) in Yaks.
419
+ Subresources aren't mapped because Collection+JSON doesn't really have that concept.
402
420
 
403
421
  ## Hooks
404
422
 
data/Rakefile CHANGED
@@ -36,31 +36,65 @@ task :mutant_chunked do
36
36
  # Yaks::Runner,
37
37
 
38
38
  [
39
- # Yaks::Resource::Form, # no explicit coverage
40
- # Yaks::Resource::Form::Field, # no explicit coverage
41
- # Yaks::Mapper::Form::Field::Option, # no explicit coverage
42
- # Yaks::Format::HTML, # no explicit coverage
43
- Yaks::Resource, # 35/206 # 83.01%
44
- Yaks::StatefulBuilder, # 25/192 # 86.98%
45
- Yaks::Format::Halo, # 24/232 # 89.66%
46
- Yaks::Mapper, # 15/482 # 96.89%
47
- Yaks::Resource::Link, # 13/43 # 69.77%
48
- Yaks::Mapper::Form::Field, # 11/155 # 92.90%
49
- Yaks::Mapper::Link, # 10/357 # 97.20%
50
- Yaks::CollectionMapper, # 7/217 # 96.77%
51
- Yaks::Primitivize, # 3/239 # 98.74%
52
- Yaks::Mapper::Form, # 3/179 # 98.32%
53
- Yaks::CollectionResource, # 3/9 # 66.67%
54
- Yaks::Format::JsonAPI, # 3/435 # 99.31%
55
- Yaks::Format, # 2/29 # 93.10%
56
- Yaks::Attributes, # 1/239 # 99.57%
57
- Yaks::StatefulBuilder::StatefulMethods, # 1/66 # 98.49%
58
- Yaks::Mapper::Association, # 1/222 # 99.55%
59
- Yaks::Serializer, # 1/74 # 98.65%
60
- Yaks::Format::Hal, # 1/328 # 99.70%
61
- # Yaks::Format::Transit, # no explicit coverage
62
- # Yaks::Format::Transit::WriteHandler, # no explicit coverage
63
- # Yaks::Format::Transit::ReadHandler, # no explicit coverage
39
+ # >> Yaks::Attributes
40
+ # >> Yaks::Attributes::InstanceMethods
41
+ # >> Yaks::Builder
42
+ # >> Yaks::CollectionMapper
43
+ # >> Yaks::CollectionResource
44
+ # >> Yaks::Config
45
+ # >> Yaks::Configurable
46
+ # >> Yaks::DefaultPolicy
47
+ # >> Yaks::Error
48
+ # >> Yaks::FP
49
+ # >> Yaks::FP::Callable
50
+ # >> Yaks::Format
51
+ # >> Yaks::Format::CollectionJson
52
+ # >> Yaks::Format::HTML
53
+ # >> Yaks::Format::Hal
54
+ # >> Yaks::Format::Halo
55
+ # >> Yaks::Format::JsonAPI
56
+ # >> Yaks::Format::Reader
57
+ # >> Yaks::Format::Transit
58
+ # >> Yaks::Format::Transit::ReadHandler
59
+ # >> Yaks::Format::Transit::WriteHandler
60
+ # >> Yaks::HTML5Forms
61
+ # >> Yaks::Identifier
62
+ # >> Yaks::Identifier::LinkRelation
63
+ # >> Yaks::IllegalStateError
64
+ # >> Yaks::Mapper
65
+ # >> Yaks::Mapper::Association
66
+ # >> Yaks::Mapper::AssociationMapper
67
+ # >> Yaks::Mapper::Attribute
68
+ # >> Yaks::Mapper::Config
69
+ # >> Yaks::Mapper::Form
70
+ # >> Yaks::Mapper::Form::Config
71
+ # >> Yaks::Mapper::Form::Field
72
+ # >> Yaks::Mapper::Form::Field::Option
73
+ # >> Yaks::Mapper::Form::Fieldset
74
+ # >> Yaks::Mapper::HasMany
75
+ # >> Yaks::Mapper::HasOne
76
+ # >> Yaks::Mapper::Link
77
+ # >> Yaks::NullResource
78
+ # >> Yaks::Pipeline
79
+ # >> Yaks::Primitivize
80
+ # >> Yaks::PrimitivizeError
81
+ # >> Yaks::Reader
82
+ # >> Yaks::Reader::Hal
83
+ # Yaks::Resource,
84
+ # Yaks::Resource::Form,
85
+ Yaks::Resource::Form::Field,
86
+ Yaks::Resource::Form::Field::Option,
87
+ Yaks::Resource::Form::Fieldset,
88
+ Yaks::Resource::Link,
89
+ # >> Yaks::Runner
90
+ # >> Yaks::RuntimeError
91
+ # >> Yaks::Serializer
92
+ # >> Yaks::Serializer::JSONReader
93
+ # >> Yaks::Serializer::JSONWriter
94
+ # >> Yaks::Undefined
95
+ # >> Yaks::UnsupportedOperationError
96
+ # >> Yaks::Util
97
+ # >> Yaks::Util::Deprecated
64
98
  ].each do |space|
65
99
  puts space
66
100
  ENV['PATTERN'] = "#{space}"
@@ -13,8 +13,9 @@ module Yaks
13
13
  items: serialize_items(resource)
14
14
  }
15
15
  result[:href] = resource.self_link.uri if resource.self_link
16
- result[:links] = serialize_links(resource) if links? resource
17
- result[:queries] = serialize_queries(resource) if queries? resource
16
+ result[:links] = serialize_links(resource) if links?(resource)
17
+ result[:queries] = serialize_queries(resource) if queries?(resource)
18
+ result[:template] = serialize_template(resource) if template?(resource)
18
19
  {collection: result}
19
20
  end
20
21
 
@@ -69,6 +70,10 @@ module Yaks
69
70
  resource.collection? && resource.links.any?
70
71
  end
71
72
 
73
+ def template?(resource)
74
+ options.key?(:template) && template_form_exists?(resource)
75
+ end
76
+
72
77
  protected
73
78
 
74
79
  def form_is_query?(form)
@@ -76,7 +81,21 @@ module Yaks
76
81
  end
77
82
 
78
83
  def method_is_get?(method)
79
- method.downcase.to_sym === :get
84
+ !method.nil? && method.downcase.to_sym === :get
85
+ end
86
+
87
+ def template_form_exists?(resource)
88
+ !resource.find_form(options.fetch(:template)).nil?
89
+ end
90
+
91
+ def serialize_template(resource)
92
+ fields = resource.find_form(options.fetch(:template)).fields
93
+ result = {data: []}
94
+ fields.each do |field|
95
+ result[:data] << {name: field.name, value: nil.to_s}
96
+ result[:data].last[:prompt] = field.label if field.label
97
+ end
98
+ result
80
99
  end
81
100
  end
82
101
  end
@@ -36,7 +36,7 @@ module Yaks
36
36
  field.to_h_compact.each_with_object({}) do |(attr,value), hsh|
37
37
  if attr == :options # <option>s of a <select>
38
38
  if !value.empty?
39
- hsh[:options] = value.map(&:to_h)
39
+ hsh[:options] = value.map(&:to_h_compact)
40
40
  end
41
41
  else
42
42
  hsh[attr] = value
@@ -50,7 +50,8 @@ module Yaks
50
50
  step: nil,
51
51
  list: nil,
52
52
  placeholder: nil,
53
- checked: false
53
+ checked: false,
54
+ disabled: false
54
55
  }
55
56
 
56
57
  end
@@ -11,7 +11,7 @@ module Yaks
11
11
  end
12
12
 
13
13
  def to_resource
14
- to_h #placeholder
14
+ Resource::Form::Field::Option.new(to_h)
15
15
  end
16
16
  end
17
17
  end
@@ -0,0 +1,11 @@
1
+ module Yaks
2
+ class Resource
3
+ class Form
4
+ class Field
5
+ class Option
6
+ include Yaks::Mapper::Form::Field::Option.attributes
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -4,13 +4,12 @@ module Yaks
4
4
  class Field
5
5
  include Yaks::Mapper::Form::Field.attributes.add(:error => nil)
6
6
 
7
- def value(arg = Undefined)
8
- return @value if arg.eql?(Undefined)
9
- if type == :select
7
+ def value
8
+ if type.equal? :select
10
9
  selected = options.find { |option| option.selected }
11
10
  selected.value if selected
12
11
  else
13
- with(value: arg)
12
+ @value
14
13
  end
15
14
  end
16
15
  end
@@ -4,18 +4,18 @@ module Yaks
4
4
  include Yaks::Mapper::Form::Config.attributes.remove(:dynamic_blocks)
5
5
 
6
6
  def [](name)
7
- fields.find {|field| field.name == name}.value
7
+ fields.find {|field| field.name.equal? name}.value
8
8
  end
9
9
 
10
10
  def values
11
- fields.each_with_object({}) do |field, values|
11
+ fields_flat.each_with_object({}) do |field, values|
12
12
  values[field.name] = field.value
13
13
  end
14
14
  end
15
15
 
16
16
  def fields_flat(fields = fields)
17
17
  fields.each_with_object([]) do |field, acc|
18
- if field.type == :fieldset
18
+ if field.type.equal? :fieldset
19
19
  acc.concat(fields_flat field.fields)
20
20
  else
21
21
  acc << field
data/lib/yaks/resource.rb CHANGED
@@ -20,7 +20,7 @@ module Yaks
20
20
  end
21
21
 
22
22
  def find_form(name)
23
- forms.find { |form| form.name == name }
23
+ forms.find { |form| form.name.equal? name }
24
24
  end
25
25
 
26
26
  def seq
data/lib/yaks/util.rb CHANGED
@@ -21,6 +21,10 @@ module Yaks
21
21
  keys.each_with_object({}) {|k,dest| dest[k] = hash[k] if hash.key?(k) }
22
22
  end
23
23
 
24
+ def reject_keys(hash, *keys)
25
+ hash.keys.each_with_object({}) {|k,dest| dest[k] = hash[k] unless keys.include?(k) }
26
+ end
27
+
24
28
  def symbolize_keys(hash)
25
29
  hash.each_with_object({}) {|(k,v), hsh| hsh[k.to_sym] = v}
26
30
  end
data/lib/yaks/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yaks
2
- VERSION = '0.8.0.alpha'
2
+ VERSION = '0.8.0.beta1'
3
3
  end
data/lib/yaks.rb CHANGED
@@ -87,6 +87,7 @@ require 'yaks/collection_mapper'
87
87
 
88
88
  require 'yaks/resource/form'
89
89
  require 'yaks/resource/form/field'
90
+ require 'yaks/resource/form/field/option'
90
91
  require 'yaks/resource/form/fieldset'
91
92
 
92
93
  require 'yaks/format'
@@ -11,30 +11,27 @@ RSpec.describe 'Mapping domain models to Resource objects' do
11
11
  its(:links) { should eql [ Yaks::Resource::Link.new(rel: :copyright, uri: '/api/copyright/2024') ] }
12
12
 
13
13
  specify {
14
-
15
- subject.subresources == [
16
- Yaks::Resource.new(
17
- type:'pet_peeve',
18
- rels: ['rel:pet_peeve'],
19
- attributes: {id: 4, type: 'parsing with regexps'}
20
- ),
21
- Yaks::CollectionResource.new(
22
- type: 'pet',
23
- rels: ['rel:pets'],
24
- members: [
25
- Yaks::Resource.new(
26
- type: 'pet',
27
- attributes: {:id => 2, :species => 'dog', :name => 'boingboing'}
28
- ),
29
- Yaks::Resource.new(
30
- type: 'pet',
31
- attributes: {:id => 3, :species => 'cat', :name => 'wassup'}
32
- )
33
- ]
34
- )
35
- ]
36
-
37
-
14
+ subject.subresources == [
15
+ Yaks::Resource.new(
16
+ type:'pet_peeve',
17
+ rels: ['rel:pet_peeve'],
18
+ attributes: {id: 4, type: 'parsing with regexps'}
19
+ ),
20
+ Yaks::CollectionResource.new(
21
+ type: 'pet',
22
+ rels: ['rel:pets'],
23
+ members: [
24
+ Yaks::Resource.new(
25
+ type: 'pet',
26
+ attributes: {:id => 2, :species => 'dog', :name => 'boingboing'}
27
+ ),
28
+ Yaks::Resource.new(
29
+ type: 'pet',
30
+ attributes: {:id => 3, :species => 'cat', :name => 'wassup'}
31
+ )
32
+ ]
33
+ )
34
+ ]
38
35
  }
39
36
 
40
37
  its(:subresources) {
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|
@@ -93,6 +93,20 @@ RSpec.describe Yaks::Format::CollectionJson do
93
93
  expect(cj.queries?(resource)).to eq false
94
94
  end
95
95
  end
96
+
97
+ context 'and form has no method' do
98
+ let(:full_args) {
99
+ {
100
+ name: :search,
101
+ action: '/foo'
102
+ }
103
+ }
104
+
105
+ it 'should return false' do
106
+ cj = Yaks::Format::CollectionJson.new(resource)
107
+ expect(cj.queries?(resource)).to eq false
108
+ end
109
+ end
96
110
  end
97
111
 
98
112
  context 'when resource has not GET forms' do
@@ -110,6 +124,65 @@ RSpec.describe Yaks::Format::CollectionJson do
110
124
  end
111
125
  end
112
126
 
127
+ context '#template?' do
128
+ context 'when no template form has been specified' do
129
+ let(:format) {
130
+ described_class.new
131
+ }
132
+
133
+ let(:resource) {
134
+ Yaks::Resource.new(
135
+ attributes: {foo: 'fooval', bar: 'barval'},
136
+ forms: [Yaks::Resource::Form.new(name: :just_a_form)]
137
+ )
138
+ }
139
+
140
+ it 'should return false' do
141
+ expect(format.template?(resource)).to eq false
142
+ end
143
+ end
144
+
145
+ context 'when a template form has been specified' do
146
+ let(:format) {
147
+ described_class.new(:template => :template_form_name)
148
+ }
149
+
150
+ context 'and the form is not present' do
151
+ let(:resource) {
152
+ Yaks::Resource.new(
153
+ attributes: {foo: 'fooval', bar: 'barval'},
154
+ forms: [Yaks::Resource::Form.new(name: :not_the_form_name)]
155
+ )
156
+ }
157
+
158
+ subject {
159
+ Yaks::Primitivize.create.call(format.call(resource))
160
+ }
161
+
162
+ it 'should return false' do
163
+ expect(format.template?(resource)).to eq false
164
+ end
165
+ end
166
+
167
+ context 'and the form is present' do
168
+ let(:resource) {
169
+ Yaks::Resource.new(
170
+ attributes: {foo: 'fooval', bar: 'barval'},
171
+ forms: [Yaks::Resource::Form.new(name: :template_form_name)]
172
+ )
173
+ }
174
+
175
+ subject {
176
+ Yaks::Primitivize.create.call(format.call(resource))
177
+ }
178
+
179
+ it 'should return true' do
180
+ expect(format.template?(resource)).to eq true
181
+ end
182
+ end
183
+ end
184
+ end
185
+
113
186
  context 'serialize_links' do
114
187
  context 'without title' do
115
188
  let(:resource) {
@@ -262,4 +335,83 @@ RSpec.describe Yaks::Format::CollectionJson do
262
335
  end
263
336
  end
264
337
  end
338
+
339
+ context 'serialize_template' do
340
+ let(:format) {
341
+ described_class.new(:template => :form_for_new)
342
+ }
343
+
344
+ let(:resource) {
345
+ Yaks::Resource.new(
346
+ attributes: {foo: 'fooval', bar: 'barval'},
347
+ forms: [Yaks::Resource::Form.new(name: :form_for_new, fields: fields)]
348
+ )
349
+ }
350
+
351
+ subject {
352
+ Yaks::Primitivize.create.call(format.call(resource))
353
+ }
354
+
355
+ context "template uses prompts" do
356
+ let(:fields) {
357
+ [
358
+ Yaks::Resource::Form::Field.new(name: 'foo', label: 'My Foo Field'),
359
+ Yaks::Resource::Form::Field.new(name: 'bar', label: 'My Bar Field')
360
+ ]
361
+ }
362
+
363
+ it 'should render a template' do
364
+ should deep_eql(
365
+ "collection" => {
366
+ "version" => "1.0",
367
+ "items" => [
368
+ {
369
+ "data" => [
370
+ { "name"=>"foo", "value"=>"fooval" },
371
+ { "name"=>"bar", "value"=>"barval" }
372
+ ]
373
+ }
374
+ ],
375
+ "template" => {
376
+ "data" => [
377
+ { "name"=>"foo", "value"=>"", "prompt"=>"My Foo Field" },
378
+ { "name"=>"bar", "value"=>"", "prompt"=>"My Bar Field" }
379
+ ]
380
+ }
381
+ }
382
+ )
383
+ end
384
+ end
385
+
386
+ context "template does not use prompts" do
387
+ let(:fields) {
388
+ [
389
+ Yaks::Resource::Form::Field.new(name: 'foo'),
390
+ Yaks::Resource::Form::Field.new(name: 'bar')
391
+ ]
392
+ }
393
+
394
+ it 'should render a template without prompts' do
395
+ should deep_eql(
396
+ "collection" => {
397
+ "version" => "1.0",
398
+ "items" => [
399
+ {
400
+ "data" => [
401
+ { "name"=>"foo", "value"=>"fooval" },
402
+ { "name"=>"bar", "value"=>"barval" }
403
+ ]
404
+ }
405
+ ],
406
+ "template" => {
407
+ "data" => [
408
+ { "name"=>"foo", "value"=>"" },
409
+ { "name"=>"bar", "value"=>"" }
410
+ ]
411
+ }
412
+ }
413
+ )
414
+ end
415
+ end
416
+ end
265
417
  end
@@ -0,0 +1,37 @@
1
+ RSpec.describe Yaks::Resource::Form::Field do
2
+ subject do
3
+ described_class.new(value: 123)
4
+ end
5
+
6
+ describe '#value' do
7
+ its(:value) { should eql 123 }
8
+
9
+ context 'with a select box - with selection' do
10
+ subject do
11
+ described.class.new(type: :select, options: [
12
+ Yaks::Resource::Form::Field::Option.new(selected: false, value: 1),
13
+ Yaks::Resource::Form::Field::Option.new(selected: true, value: 2),
14
+ Yaks::Resource::Form::Field::Option.new(selected: false, value: 3),
15
+ ])
16
+ end
17
+
18
+ it 'should return the selected value' do
19
+ expect( subject.value ).to eql 2
20
+ end
21
+ end
22
+
23
+ context 'with a select box - no selection' do
24
+ subject do
25
+ described.class.new(type: :select, options: [
26
+ Yaks::Resource::Form::Field::Option.new(selected: false, value: 1),
27
+ Yaks::Resource::Form::Field::Option.new(selected: false, value: 2),
28
+ Yaks::Resource::Form::Field::Option.new(selected: false, value: 3),
29
+ ])
30
+ end
31
+
32
+ it 'should return nothing' do
33
+ expect( subject.value ).to be nil
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,51 @@
1
+ RSpec.describe Yaks::Resource::Form do
2
+ let(:fields) {
3
+ [
4
+ Yaks::Resource::Form::Field.new(name: :foo, value: '123', type: 'text'),
5
+ Yaks::Resource::Form::Field.new(name: :bar, value: '+32 477 123 123', type: 'tel')
6
+ ]
7
+ }
8
+
9
+ subject(:form) {
10
+ described_class.new(name: :create_foo, fields: fields)
11
+ }
12
+
13
+ describe '#[]' do
14
+ it 'should find a field value by field name' do
15
+ expect(subject[:bar])
16
+ .to eq '+32 477 123 123'
17
+ end
18
+ end
19
+
20
+ describe '#values' do
21
+ it 'should return all field values in a hash' do
22
+ expect(subject.values).to eql(foo: '123', bar: '+32 477 123 123')
23
+ end
24
+ end
25
+
26
+ describe '#fields_flat' do
27
+ let(:fields) do
28
+ [
29
+ Yaks::Resource::Form::Fieldset.new(fields: [
30
+ Yaks::Resource::Form::Field.new(name: :foo, value: '123', type: 'text'),
31
+ Yaks::Resource::Form::Field.new(name: :bar, value: '+32 477 123 123', type: 'tel')
32
+ ]),
33
+ Yaks::Resource::Form::Fieldset.new(fields: [
34
+ Yaks::Resource::Form::Fieldset.new(fields: [
35
+ Yaks::Resource::Form::Field.new(name: :qux, value: '777', type: 'text'),
36
+ ]),
37
+ Yaks::Resource::Form::Field.new(name: :quux, value: '999', type: 'tel')
38
+ ])
39
+ ]
40
+ end
41
+
42
+ it 'should flatten fieldsets' do
43
+ expect(subject.fields_flat).to eql [
44
+ Yaks::Resource::Form::Field.new(name: :foo, value: '123', type: 'text'),
45
+ Yaks::Resource::Form::Field.new(name: :bar, value: '+32 477 123 123', type: 'tel'),
46
+ Yaks::Resource::Form::Field.new(name: :qux, value: '777', type: 'text'),
47
+ Yaks::Resource::Form::Field.new(name: :quux, value: '999', type: 'tel')
48
+ ]
49
+ end
50
+ end
51
+ end
@@ -88,6 +88,26 @@ RSpec.describe Yaks::Resource do
88
88
  end
89
89
  end
90
90
 
91
+ describe '#initialize' do
92
+ it 'should verify subresources is an array' do
93
+ expect { Yaks::Resource.new(subresources: { '/rel/comments' => []}) }
94
+ .to raise_exception /comments/
95
+ end
96
+
97
+ it 'should verify subresources is an array' do
98
+ expect { Yaks::Resource.new(subresources: []) }
99
+ .to_not raise_exception
100
+ end
101
+
102
+ it 'should work without args' do
103
+ expect( Yaks::Resource.new ).to be_a Yaks::Resource
104
+ end
105
+
106
+ it 'should take defaults when no args are passed' do
107
+ expect( Yaks::Resource.new.rels ).to eq []
108
+ end
109
+ end
110
+
91
111
  describe '#self_link' do
92
112
  let(:init_opts) {
93
113
  { links:
@@ -103,10 +123,27 @@ RSpec.describe Yaks::Resource do
103
123
  end
104
124
  end
105
125
 
126
+ describe '#add_rel' do
127
+ it 'should add to the rels' do
128
+ expect(resource.add_rel(:foo).add_rel(:bar))
129
+ .to eql Yaks::Resource.new(rels: [:foo, :bar])
130
+ end
131
+ end
132
+
106
133
  describe '#add_form' do
107
134
  it 'should append to the forms' do
108
- expect(resource.add_form(:a_form))
109
- .to eq Yaks::Resource.new(forms: [:a_form])
135
+ expect(resource.add_form(Yaks::Resource::Form.new(name: :a_form)))
136
+ .to eq Yaks::Resource.new(forms: [Yaks::Resource::Form.new(name: :a_form)])
137
+ end
138
+ end
139
+
140
+ describe '#find_form' do
141
+ it 'should find a form by name' do
142
+ expect(resource
143
+ .add_form(Yaks::Resource::Form.new(name: :a_form))
144
+ .add_form(Yaks::Resource::Form.new(name: :b_form))
145
+ .find_form(:b_form))
146
+ .to eq Yaks::Resource::Form.new(name: :b_form)
110
147
  end
111
148
  end
112
149
 
@@ -118,4 +155,11 @@ RSpec.describe Yaks::Resource do
118
155
  end
119
156
  end
120
157
 
158
+ describe '#with_collection' do
159
+ it 'should be a no-op' do
160
+ expect(Yaks::Resource.new.with_collection([:foo])).to eql Yaks::Resource.new
161
+ end
162
+ end
163
+
121
164
  end
165
+ # ~> -:1:in `<main>': uninitialized constant RSpec (NameError)
data/yaks.gemspec CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require File.expand_path('../lib/yaks/version', __FILE__)
4
4
  require File.expand_path('../lib/yaks/breaking_changes', __FILE__)
5
- require File.expand_path('../lib/yaks/changelog', __FILE__)
6
5
 
7
6
  Gem::Specification.new do |gem|
8
7
  gem.name = 'yaks'
@@ -19,8 +18,6 @@ Gem::Specification.new do |gem|
19
18
  gem.test_files = gem.files.grep(/^spec/)
20
19
  gem.extra_rdoc_files = %w[README.md]
21
20
 
22
- gem.metadata = {'changelog' => Yaks::Changelog.current[0...1000]}
23
-
24
21
  if Yaks::BreakingChanges.key? Yaks::VERSION
25
22
  gem.post_install_message = Yaks::BreakingChanges[Yaks::VERSION]
26
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0.alpha
4
+ version: 0.8.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arne Brasseur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-17 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inflection
@@ -285,6 +285,7 @@ files:
285
285
  - lib/yaks/resource.rb
286
286
  - lib/yaks/resource/form.rb
287
287
  - lib/yaks/resource/form/field.rb
288
+ - lib/yaks/resource/form/field/option.rb
288
289
  - lib/yaks/resource/form/fieldset.rb
289
290
  - lib/yaks/resource/link.rb
290
291
  - lib/yaks/runner.rb
@@ -346,6 +347,8 @@ files:
346
347
  - spec/unit/yaks/null_resource_spec.rb
347
348
  - spec/unit/yaks/pipeline_spec.rb
348
349
  - spec/unit/yaks/primitivize_spec.rb
350
+ - spec/unit/yaks/resource/form/field_sepc.rb
351
+ - spec/unit/yaks/resource/form_spec.rb
349
352
  - spec/unit/yaks/resource/link_spec.rb
350
353
  - spec/unit/yaks/resource_spec.rb
351
354
  - spec/unit/yaks/runner_spec.rb
@@ -357,47 +360,7 @@ files:
357
360
  homepage: https://github.com/plexus/yaks
358
361
  licenses:
359
362
  - MIT
360
- metadata:
361
- changelog: |-
362
- Improved Collection+JSON support, dynamically generated form fields.
363
-
364
- #### Collection+JSON
365
-
366
- Carles Jove i Buxeda has done some great work to improve support for Collection+JSON, GET forms are now rendered as CJ queries.
367
-
368
- #### Dynamic Form Fields
369
-
370
- A new introduction are "dynamic" form fields. Up to now it was hard to generate forms based on the object being serialized. Now it's possible to add dynamic sections to a Form definition. These will be evaluated at map-time, they receive the object being mapped, and inside the syntax for defining form fields can be used.
371
-
372
- ```
373
- form :checkout do
374
- text :name
375
- text :lastname
376
-
377
- dynamic do |object|
378
- object.shipping_options.each do |shipping|
379
- radio shipping.type_name, title: shipping.description
380
- end
381
- end
382
- end
383
- ```
384
-
385
- #### Fieldset and Legend
386
-
387
- Support for the fieldset element type has been added, which works as you would expect
388
-
389
- ```
390
- form :foo do
391
- fieldset do
392
- legend "Hello"
393
- text :field_1
394
- end
395
- end
396
- ```
397
-
398
- #### Remove links
399
-
400
- A link de
363
+ metadata: {}
401
364
  post_install_message:
402
365
  rdoc_options: []
403
366
  require_paths:
@@ -473,6 +436,8 @@ test_files:
473
436
  - spec/unit/yaks/null_resource_spec.rb
474
437
  - spec/unit/yaks/pipeline_spec.rb
475
438
  - spec/unit/yaks/primitivize_spec.rb
439
+ - spec/unit/yaks/resource/form/field_sepc.rb
440
+ - spec/unit/yaks/resource/form_spec.rb
476
441
  - spec/unit/yaks/resource/link_spec.rb
477
442
  - spec/unit/yaks/resource_spec.rb
478
443
  - spec/unit/yaks/runner_spec.rb