yaks 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +158 -56
  3. data/Rakefile +1 -3
  4. data/ataru_setup.rb +72 -0
  5. data/find_missing_tests.rb +34 -0
  6. data/lib/yaks.rb +8 -10
  7. data/lib/yaks/breaking_changes.rb +4 -6
  8. data/lib/yaks/builder.rb +1 -1
  9. data/lib/yaks/changelog.rb +1 -1
  10. data/lib/yaks/collection_mapper.rb +8 -5
  11. data/lib/yaks/collection_resource.rb +0 -1
  12. data/lib/yaks/config.rb +17 -7
  13. data/lib/yaks/configurable.rb +20 -14
  14. data/lib/yaks/default_policy.rb +82 -33
  15. data/lib/yaks/format.rb +7 -3
  16. data/lib/yaks/format/collection_json.rb +4 -4
  17. data/lib/yaks/format/hal.rb +1 -2
  18. data/lib/yaks/format/halo.rb +2 -4
  19. data/lib/yaks/format/json_api.rb +46 -27
  20. data/lib/yaks/html5_forms.rb +0 -2
  21. data/lib/yaks/mapper.rb +5 -5
  22. data/lib/yaks/mapper/association.rb +7 -7
  23. data/lib/yaks/mapper/association_mapper.rb +2 -0
  24. data/lib/yaks/mapper/attribute.rb +10 -4
  25. data/lib/yaks/mapper/config.rb +2 -2
  26. data/lib/yaks/mapper/form.rb +4 -10
  27. data/lib/yaks/mapper/form/config.rb +16 -17
  28. data/lib/yaks/mapper/form/dynamic_field.rb +1 -1
  29. data/lib/yaks/mapper/form/field.rb +16 -7
  30. data/lib/yaks/mapper/form/field/option.rb +5 -4
  31. data/lib/yaks/mapper/form/fieldset.rb +1 -1
  32. data/lib/yaks/mapper/form/legend.rb +18 -0
  33. data/lib/yaks/mapper/has_many.rb +1 -0
  34. data/lib/yaks/mapper/link.rb +7 -4
  35. data/lib/yaks/null_resource.rb +4 -5
  36. data/lib/yaks/pipeline.rb +2 -2
  37. data/lib/yaks/primitivize.rb +3 -2
  38. data/lib/yaks/reader/hal.rb +12 -13
  39. data/lib/yaks/reader/json_api.rb +50 -33
  40. data/lib/yaks/resource.rb +6 -7
  41. data/lib/yaks/resource/form.rb +2 -12
  42. data/lib/yaks/resource/form/field.rb +4 -3
  43. data/lib/yaks/resource/form/field/option.rb +1 -1
  44. data/lib/yaks/resource/form/fieldset.rb +1 -1
  45. data/lib/yaks/resource/form/legend.rb +18 -0
  46. data/lib/yaks/resource/has_fields.rb +13 -7
  47. data/lib/yaks/resource/link.rb +1 -1
  48. data/lib/yaks/runner.rb +5 -2
  49. data/lib/yaks/serializer.rb +2 -3
  50. data/lib/yaks/util.rb +7 -8
  51. data/lib/yaks/version.rb +1 -1
  52. data/spec/acceptance/acceptance_spec.rb +53 -38
  53. data/spec/acceptance/json_shared_examples.rb +45 -12
  54. data/spec/acceptance/models.rb +1 -1
  55. data/spec/integration/dynamic_form_fields_spec.rb +0 -1
  56. data/spec/integration/fieldset_spec.rb +18 -20
  57. data/spec/integration/map_to_resource_spec.rb +6 -6
  58. data/spec/json/{confucius.collection.json → confucius.collection_json.json} +0 -0
  59. data/spec/json/confucius.json_api.json +43 -27
  60. data/spec/json/list_of_quotes.collection_json.json +43 -0
  61. data/spec/json/list_of_quotes.hal.json +18 -0
  62. data/spec/json/list_of_quotes.json_api.json +25 -0
  63. data/spec/json/youtypeitwepostit.collection_json.json +45 -0
  64. data/spec/spec_helper.rb +4 -3
  65. data/spec/support/classes_for_policy_testing.rb +38 -14
  66. data/spec/support/deep_eql.rb +21 -18
  67. data/spec/support/pet_mapper.rb +2 -0
  68. data/spec/support/shared_contexts.rb +9 -9
  69. data/spec/unit/yaks/builder_spec.rb +41 -18
  70. data/spec/unit/yaks/collection_mapper_spec.rb +22 -19
  71. data/spec/unit/yaks/collection_resource_spec.rb +16 -8
  72. data/spec/unit/yaks/config_spec.rb +215 -19
  73. data/spec/unit/yaks/configurable_spec.rb +66 -7
  74. data/spec/unit/yaks/default_policy/derive_mapper_from_collection_spec.rb +47 -0
  75. data/spec/unit/yaks/default_policy/derive_mapper_from_item_spec.rb +114 -0
  76. data/spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb +29 -71
  77. data/spec/unit/yaks/default_policy_spec.rb +4 -5
  78. data/spec/unit/yaks/format/collection_json_spec.rb +35 -36
  79. data/spec/unit/yaks/format/hal_spec.rb +3 -3
  80. data/spec/unit/yaks/format/json_api_spec.rb +109 -68
  81. data/spec/unit/yaks/format_spec.rb +34 -0
  82. data/spec/unit/yaks/fp/callable_spec.rb +5 -3
  83. data/spec/unit/yaks/mapper/association_mapper_spec.rb +22 -4
  84. data/spec/unit/yaks/mapper/association_spec.rb +23 -11
  85. data/spec/unit/yaks/mapper/attribute_spec.rb +46 -7
  86. data/spec/unit/yaks/mapper/config_spec.rb +2 -3
  87. data/spec/unit/yaks/mapper/form/config_spec.rb +95 -0
  88. data/spec/unit/yaks/mapper/form/dynamic_field_spec.rb +30 -0
  89. data/spec/unit/yaks/mapper/form/field/option_spec.rb +48 -4
  90. data/spec/unit/yaks/mapper/form/field_spec.rb +43 -2
  91. data/spec/unit/yaks/mapper/form/fieldset_spec.rb +67 -8
  92. data/spec/unit/yaks/mapper/form/legend_spec.rb +52 -0
  93. data/spec/unit/yaks/mapper/form_spec.rb +84 -23
  94. data/spec/unit/yaks/mapper/has_many_spec.rb +39 -36
  95. data/spec/unit/yaks/mapper/has_one_spec.rb +28 -20
  96. data/spec/unit/yaks/mapper/link_spec.rb +68 -16
  97. data/spec/unit/yaks/mapper_spec.rb +118 -30
  98. data/spec/unit/yaks/null_resource_spec.rb +83 -52
  99. data/spec/unit/yaks/pipeline_spec.rb +101 -74
  100. data/spec/unit/yaks/primitivize_spec.rb +25 -6
  101. data/spec/unit/yaks/resource/form/field_spec.rb +5 -5
  102. data/spec/unit/yaks/resource/form/fieldset_spec.rb +7 -0
  103. data/spec/unit/yaks/resource/form/legend_spec.rb +8 -0
  104. data/spec/unit/yaks/resource/form_spec.rb +17 -37
  105. data/spec/unit/yaks/resource/has_fields_spec.rb +44 -3
  106. data/spec/unit/yaks/resource/link_spec.rb +11 -6
  107. data/spec/unit/yaks/resource_spec.rb +87 -98
  108. data/spec/unit/yaks/runner_spec.rb +112 -28
  109. data/spec/unit/yaks/serializer_spec.rb +1 -1
  110. data/spec/unit/yaks/util_spec.rb +30 -10
  111. data/spec/yaml/list_of_quotes.yaml +13 -0
  112. data/yaks.gemspec +21 -13
  113. metadata +129 -41
  114. data/lib/yaks/attributes.rb +0 -86
  115. data/lib/yaks/fp.rb +0 -26
  116. data/lib/yaks/identifier/link_relation.rb +0 -17
  117. data/resources/iana-link-relations.csv +0 -152
  118. data/spec/json/youtypeitwepostit.collection.json +0 -45
  119. data/spec/unit/yaks/attributes_spec.rb +0 -178
  120. data/spec/unit/yaks/fp_spec.rb +0 -29
@@ -1,18 +1,57 @@
1
1
  RSpec.describe Yaks::Mapper::Attribute do
2
2
  include_context 'yaks context'
3
3
 
4
- subject(:attribute) { described_class.new(:the_name) }
5
- fake(:mapper)
4
+ let(:attribute_with_block) { described_class.create(:the_name) { "Alice" } }
6
5
 
7
- its(:name) { should be :the_name }
6
+ subject(:attribute) { described_class.create(:the_name) }
7
+ fake(:mapper)
8
8
 
9
9
  before do
10
10
  stub(mapper).load_attribute(:the_name) { 123 }
11
+ stub(mapper).object { fake(name: "Bob") }
12
+ end
13
+
14
+ describe ".create" do
15
+ its(:name) { should be :the_name }
16
+ its(:block) { should be_nil }
17
+
18
+ it "should accept two parameter" do
19
+ expect{described_class.create(:the_name, {})}.not_to raise_error()
20
+ end
21
+
22
+ context "with block" do
23
+ subject(:attribute) { attribute_with_block }
24
+
25
+ its(:block) { should_not be_nil }
26
+
27
+ it "should store the given block" do
28
+ expect(subject.block.call).to eq("Alice")
29
+ end
30
+ end
11
31
  end
12
32
 
13
- it 'should add itself to a resource based on a lookup' do
14
- expect(attribute.add_to_resource(Yaks::Resource.new, mapper , yaks_context)).to eql(
15
- Yaks::Resource.new(attributes: { :the_name => 123 })
16
- )
33
+ describe "#add_to_resource" do
34
+ it "should add itself to a resource based on a lookup" do
35
+ expect(attribute.add_to_resource(Yaks::Resource.new, mapper, yaks_context))
36
+ .to eql(Yaks::Resource.new(attributes: {the_name: 123}))
37
+ end
38
+
39
+ context "when the attribute has a block" do
40
+ subject(:attribute) { attribute_with_block }
41
+
42
+ it "should add itself to a resource with the block value" do
43
+ expect(attribute.add_to_resource(Yaks::Resource.new, mapper, yaks_context))
44
+ .to eql(Yaks::Resource.new(attributes: {the_name: "Alice"}))
45
+ end
46
+
47
+ context "using the mapper context" do
48
+ let(:attribute) { described_class.create(:the_name) { object.name } }
49
+
50
+ it "should add itself to a resource with the block value" do
51
+ expect(attribute.add_to_resource(Yaks::Resource.new, mapper, yaks_context))
52
+ .to eql(Yaks::Resource.new(attributes: {the_name: "Bob"}))
53
+ end
54
+ end
55
+ end
17
56
  end
18
57
  end
@@ -1,11 +1,10 @@
1
1
  RSpec.describe Yaks::Mapper::Config do
2
-
3
2
  describe '#add_attributes' do
4
3
  it 'should add attributes' do
5
4
  expect(subject.add_attributes(:bar).add_attributes(:baz)).to eql described_class.new(
6
5
  attributes: [
7
- Yaks::Mapper::Attribute.new(:bar),
8
- Yaks::Mapper::Attribute.new(:baz),
6
+ Yaks::Mapper::Attribute.create(:bar),
7
+ Yaks::Mapper::Attribute.create(:baz)
9
8
  ]
10
9
  )
11
10
  end
@@ -0,0 +1,95 @@
1
+ RSpec.describe Yaks::Mapper::Form::Config do
2
+ let(:config) { described_class.new }
3
+
4
+ describe ".create" do
5
+ let(:config) {
6
+ described_class.create name: :bar, method: "POST"
7
+ }
8
+
9
+ it "should take an attribute hash" do
10
+ expect(config)
11
+ .to eql Yaks::Mapper::Form::Config.new(
12
+ name: :bar,
13
+ method: "POST"
14
+ )
15
+ end
16
+ end
17
+
18
+ describe ".build" do
19
+ context "with no arguments" do
20
+ it "should create a default Form::Config" do
21
+ expect(described_class.build).to eql described_class.new
22
+ end
23
+ end
24
+
25
+ context "with a block" do
26
+ let(:config) {
27
+ described_class.build name: :bar do
28
+ method "DELETE"
29
+ password :secret
30
+ end
31
+ }
32
+
33
+ it "should evaluate as Form DSL" do
34
+ expect(config)
35
+ .to eql Yaks::Mapper::Form::Config.new(
36
+ name: :bar,
37
+ method: "DELETE",
38
+ fields: [
39
+ Yaks::Mapper::Form::Field.new(name: :secret, type: :password)
40
+ ]
41
+ )
42
+ end
43
+ end
44
+ end
45
+
46
+ describe ".build_with_object" do
47
+ let(:config) {
48
+ described_class.build_with_object "the_object" do |obj|
49
+ title obj
50
+ end
51
+ }
52
+
53
+ it "should pass the object to the config block" do
54
+ expect(config)
55
+ .to eql Yaks::Mapper::Form::Config.new(
56
+ title: "the_object"
57
+ )
58
+ end
59
+ end
60
+
61
+ describe "#condition" do
62
+ it "should work with a lambda" do
63
+ expect(config.condition(->{ :okay }).if.call).to equal :okay
64
+ end
65
+
66
+ it "should work with a block" do
67
+ expect(config.condition { :okay }.if.call).to equal :okay
68
+ end
69
+ end
70
+
71
+ describe "#to_resource_fields" do
72
+ include_context 'yaks context'
73
+ let(:mapper) { Yaks::Mapper.new(yaks_context) }
74
+ let(:config) {
75
+ described_class.build do
76
+ fieldset do
77
+ text :first_name
78
+ text :last_name
79
+ end
80
+ end
81
+ }
82
+
83
+ it "should map to resource fields" do
84
+ expect(config.to_resource_fields(mapper))
85
+ .to eql [
86
+ Yaks::Resource::Form::Fieldset.new(
87
+ fields: [
88
+ Yaks::Resource::Form::Field.new(name: :first_name, type: :text),
89
+ Yaks::Resource::Form::Field.new(name: :last_name, type: :text)
90
+ ]
91
+ )
92
+ ]
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,30 @@
1
+ RSpec.describe Yaks::Mapper::Form::DynamicField do
2
+ describe ".create" do
3
+ it "take a block" do
4
+ expect(described_class.create { :foo }.block.call).to equal :foo
5
+ end
6
+
7
+ it "should ignore any options hash given" do
8
+ expect { described_class.create(foo: :bar) }.to_not raise_error
9
+ end
10
+ end
11
+
12
+ describe "#to_resource_fields" do
13
+ include_context "yaks context"
14
+ let(:mapper) { Yaks::Mapper.new(yaks_context) }
15
+ let(:field) {
16
+ described_class.create do |obj|
17
+ text :first_name, value: obj
18
+ text :last_name
19
+ end
20
+ }
21
+
22
+ it "should return an array of fields" do
23
+ mapper.call("Arne")
24
+ expect(field.to_resource_fields(mapper)).to eql [
25
+ Yaks::Resource::Form::Field.new(name: :first_name, type: :text, value: "Arne"),
26
+ Yaks::Resource::Form::Field.new(name: :last_name, type: :text)
27
+ ]
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,5 @@
1
1
  RSpec.describe Yaks::Mapper::Form::Field::Option do
2
- include_context 'yaks context'
2
+ include_context "yaks context"
3
3
 
4
4
  let(:mapper_class) do
5
5
  Class.new(Yaks::Mapper) do
@@ -10,10 +10,54 @@ RSpec.describe Yaks::Mapper::Form::Field::Option do
10
10
  end
11
11
 
12
12
  let(:mapper) { mapper_class.new(yaks_context) }
13
+ let(:args) {
14
+ {
15
+ value: ->{ color },
16
+ label: ->{ :color },
17
+ selected: ->{ true },
18
+ disabled: ->{ true }
19
+ }
20
+ }
13
21
 
14
- let(:option) { described_class.new(value: ->{color}, label: :color) }
22
+ let(:option) { described_class.new(args) }
15
23
 
16
- it 'should expand procs in the context of the mapper' do
17
- expect(option.to_resource_field_option(mapper)).to eql Yaks::Resource::Form::Field::Option.new(value: :yellow, label: :color, selected: false)
24
+ describe ".create" do
25
+ it "should take the first argument as 'value'" do
26
+ expect(described_class.create(0, label: 'zero'))
27
+ .to eql Yaks::Mapper::Form::Field::Option.new(
28
+ value: 0,
29
+ label: 'zero'
30
+ )
31
+ end
32
+ end
33
+
34
+ describe "#to_resource_field_option" do
35
+ let(:resource_field_option) { option.to_resource_field_option(mapper) }
36
+
37
+ it "should expand procs in the context of the mapper" do
38
+ expect(resource_field_option)
39
+ .to eql Yaks::Resource::Form::Field::Option.new(
40
+ value: :yellow,
41
+ label: :color,
42
+ selected: true,
43
+ disabled: true
44
+ )
45
+ end
46
+
47
+ context "with a truthy condition" do
48
+ let(:args) { super().merge(if: ->{ true }) }
49
+
50
+ it "should return an Option instance" do
51
+ expect(resource_field_option).to be_a Yaks::Resource::Form::Field::Option
52
+ end
53
+ end
54
+
55
+ context "with a falsey condition" do
56
+ let(:args) { super().merge(if: ->{ false }) }
57
+
58
+ it "should return nil" do
59
+ expect(resource_field_option).to be_nil
60
+ end
61
+ end
18
62
  end
19
63
  end
@@ -1,7 +1,7 @@
1
1
  RSpec.describe Yaks::Mapper::Form::Field do
2
2
  include_context 'yaks context'
3
3
 
4
- let(:field) { described_class.new( full_args ) }
4
+ let(:field) { described_class.new(full_args) }
5
5
  let(:name) { :the_field }
6
6
  let(:full_args) { {name: name, options: options}.merge(args) }
7
7
  let(:options) { [] }
@@ -15,7 +15,9 @@ RSpec.describe Yaks::Mapper::Form::Field do
15
15
 
16
16
  let(:mapper) do
17
17
  Class.new(Yaks::Mapper) do
18
- def month ; 'January' ; end
18
+ def month
19
+ 'January'
20
+ end
19
21
  end.new(yaks_context)
20
22
  end
21
23
 
@@ -91,4 +93,43 @@ RSpec.describe Yaks::Mapper::Form::Field do
91
93
  end
92
94
  end
93
95
  end
96
+
97
+ describe "#resource_options" do
98
+ context "when empty" do
99
+ it "should always be the same identical object" do
100
+ opt1 = described_class.new(name: :foo).resource_options(mapper)
101
+ opt2 = described_class.new(name: :bar).resource_options(mapper)
102
+ expect(opt1).to eql []
103
+ expect(opt1).to equal opt2
104
+ end
105
+ end
106
+
107
+ context "with select options" do
108
+ let(:options) do
109
+ [
110
+ Yaks::Mapper::Form::Field::Option.new(value: 0, label: "zero"),
111
+ Yaks::Mapper::Form::Field::Option.new(value: 1, label: "one"),
112
+ Yaks::Mapper::Form::Field::Option.new(value: 2, label: "two", if: ->{ false })
113
+ ]
114
+ end
115
+
116
+ it "should map to Resource::Field::Option instances" do
117
+ expect(field.resource_options(mapper))
118
+ .to eql [
119
+ Yaks::Resource::Form::Field::Option.new(value: 0, label: "zero"),
120
+ Yaks::Resource::Form::Field::Option.new(value: 1, label: "one")
121
+ ]
122
+ end
123
+ end
124
+ end
125
+
126
+ describe "#resource_attributes" do
127
+ it "should have all the HTML form field attributes" do
128
+ expect(field.resource_attributes).to eql [
129
+ :name, :label, :type, :required, :rows, :value, :pattern,
130
+ :maxlength, :minlength, :size, :readonly, :multiple, :min,
131
+ :max, :step, :list, :placeholder, :checked, :disabled
132
+ ]
133
+ end
134
+ end
94
135
  end
@@ -2,18 +2,55 @@ RSpec.describe Yaks::Mapper::Form::Fieldset do
2
2
  include_context 'yaks context'
3
3
  let(:mapper) { Yaks::Mapper.new(yaks_context) }
4
4
 
5
- describe '#to_resource_fields' do
6
- context 'with dynamic elements' do
7
- let(:fieldset) do
8
- described_class.create({}) do
5
+ describe ".create" do
6
+ let(:fieldset) {
7
+ described_class.create do
8
+ text :first_name
9
+ text :last_name
10
+ end
11
+ }
12
+
13
+ it "should take a config block" do
14
+ expect(fieldset.config)
15
+ .to eql Yaks::Mapper::Form::Config.new(
16
+ fields: [
17
+ Yaks::Mapper::Form::Field.new(name: :first_name, type: :text),
18
+ Yaks::Mapper::Form::Field.new(name: :last_name, type: :text)
19
+ ]
20
+ )
21
+ end
22
+
23
+ context "with extra options" do
24
+ let(:fieldset) {
25
+ described_class.create if: true do
26
+ text :first_name
27
+ end
28
+ }
29
+
30
+ it "should take an :if option (the rest doesn't make sense for a fieldset)" do
31
+ expect(fieldset.config)
32
+ .to eql Yaks::Mapper::Form::Config.new(
33
+ fields: [
34
+ Yaks::Mapper::Form::Field.new(name: :first_name, type: :text)
35
+ ],
36
+ if: true
37
+ )
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#to_resource_fields" do
43
+ context "with dynamic elements" do
44
+ let(:fieldset) {
45
+ described_class.create do
9
46
  dynamic do |object|
10
47
  text object.name
11
48
  end
12
49
  end
13
- end
50
+ }
14
51
 
15
- it 'should render them based on the mapped object' do
16
- mapper.call(fake(name: :anthony)) # hack to set the mapper's object
52
+ it "should render them based on the mapped object" do
53
+ mapper.call(fake(name: :anthony)) # HACK: set the mapper's object
17
54
  expect(fieldset.to_resource_fields(mapper)).to eql(
18
55
  [
19
56
  Yaks::Resource::Form::Fieldset.new(
@@ -25,6 +62,28 @@ RSpec.describe Yaks::Mapper::Form::Fieldset do
25
62
  )
26
63
  end
27
64
  end
28
- end
29
65
 
66
+ context "with a truthy `:if` condition" do
67
+ let(:fieldset) {
68
+ described_class.create if: ->{ true } do
69
+ end
70
+ }
71
+
72
+ it "should return an array of fieldsets" do
73
+ expect(fieldset.to_resource_fields(mapper).first)
74
+ .to be_a Yaks::Resource::Form::Fieldset
75
+ end
76
+ end
77
+
78
+ context "with a falsey `:if` condition" do
79
+ let(:fieldset) {
80
+ described_class.create if: ->{ false } do
81
+ end
82
+ }
83
+
84
+ it "should return nil" do
85
+ expect(fieldset.to_resource_fields(mapper).first).to be_nil
86
+ end
87
+ end
88
+ end
30
89
  end
@@ -0,0 +1,52 @@
1
+ RSpec.describe Yaks::Mapper::Form::Legend do
2
+ subject(:legend) { described_class.create("a legend") }
3
+
4
+ describe ".create" do
5
+ its(:type) { should equal :legend }
6
+ its(:label) { should eql "a legend" }
7
+
8
+ context "with an `:if` option" do
9
+ subject(:legend) { described_class.create("a legend", if: ->{ true }) }
10
+
11
+ it "should set the attribute" do
12
+ expect(legend.if.call).to be true
13
+ end
14
+ end
15
+ end
16
+
17
+ describe "#to_resource_fields" do
18
+ include_context "yaks context"
19
+ let(:mapper) { Yaks::Mapper.new(yaks_context) }
20
+
21
+ it "should return an array of Resource::Form::Legend" do
22
+ expect(legend.to_resource_fields(mapper))
23
+ .to eql [Yaks::Resource::Form::Legend.new(label: "a legend", type: :legend)]
24
+ end
25
+
26
+ context "with a truthy condition" do
27
+ subject(:legend) { described_class.create("a legend", if: ->{ true }) }
28
+
29
+ it "should return an array of Resource::Form::Legend" do
30
+ expect(legend.to_resource_fields(mapper).first)
31
+ .to be_a Yaks::Resource::Form::Legend
32
+ end
33
+ end
34
+
35
+ context "with a falsey condition" do
36
+ subject(:legend) { described_class.create("a legend", if: ->{ false }) }
37
+
38
+ it "should return an empty array" do
39
+ expect(legend.to_resource_fields(mapper)).to eql []
40
+ end
41
+ end
42
+
43
+ context "with a lambda for a label" do
44
+ subject(:legend) { described_class.create(->{ self.class.to_s }) }
45
+
46
+ it "should expand the lambda in the context of the mapper" do
47
+ expect(legend.to_resource_fields(mapper))
48
+ .to eql [Yaks::Resource::Form::Legend.new(label: "Yaks::Mapper", type: :legend)]
49
+ end
50
+ end
51
+ end
52
+ end