gather_content-api 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +7 -0
- data/README.md +161 -35
- data/gather_content-api.gemspec +1 -1
- data/lib/gather_content.rb +2 -0
- data/lib/gather_content/api.rb +16 -15
- data/lib/gather_content/config.rb +9 -0
- data/lib/gather_content/config/builder.rb +20 -0
- data/lib/gather_content/config/elements.rb +15 -0
- data/lib/gather_content/config/elements/base.rb +32 -0
- data/lib/gather_content/config/elements/choice_checkbox.rb +32 -0
- data/lib/gather_content/config/elements/choice_radio.rb +62 -0
- data/lib/gather_content/config/elements/files.rb +17 -0
- data/lib/gather_content/config/elements/option.rb +30 -0
- data/lib/gather_content/config/elements/other_option.rb +26 -0
- data/lib/gather_content/config/elements/section.rb +31 -0
- data/lib/gather_content/config/elements/text.rb +32 -0
- data/lib/gather_content/config/tab.rb +30 -0
- data/lib/gather_content/config/tabs.rb +13 -0
- data/lib/gather_content/dsl.rb +15 -0
- data/lib/gather_content/dsl/base.rb +28 -0
- data/lib/gather_content/dsl/choice_checkbox.rb +19 -0
- data/lib/gather_content/dsl/choice_radio.rb +25 -0
- data/lib/gather_content/dsl/config.rb +16 -0
- data/lib/gather_content/dsl/files.rb +12 -0
- data/lib/gather_content/dsl/option.rb +29 -0
- data/lib/gather_content/dsl/other_option.rb +18 -0
- data/lib/gather_content/dsl/section.rb +24 -0
- data/lib/gather_content/dsl/tab.rb +54 -0
- data/lib/gather_content/dsl/text.rb +29 -0
- data/lib/gather_content/error.rb +1 -1
- data/lib/gather_content/version.rb +1 -1
- data/spec/gather_content/config/builder_spec.rb +42 -0
- data/spec/gather_content/config/elements/choice_checkbox_spec.rb +78 -0
- data/spec/gather_content/config/elements/choice_radio_spec.rb +175 -0
- data/spec/gather_content/config/elements/files_spec.rb +23 -0
- data/spec/gather_content/config/elements/option_spec.rb +88 -0
- data/spec/gather_content/config/elements/other_option_spec.rb +124 -0
- data/spec/gather_content/config/elements/section_spec.rb +80 -0
- data/spec/gather_content/config/elements/text_spec.rb +163 -0
- data/spec/gather_content/config/tab_spec.rb +120 -0
- data/spec/gather_content/dsl/choice_checkbox_spec.rb +25 -0
- data/spec/gather_content/dsl/choice_radio_spec.rb +47 -0
- data/spec/gather_content/dsl/files_spec.rb +12 -0
- data/spec/gather_content/dsl/section_spec.rb +37 -0
- data/spec/gather_content/dsl/tab_spec.rb +107 -0
- data/spec/gather_content/dsl/text_spec.rb +48 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/shared_examples/dsl.rb +63 -0
- data/spec/support/shared_examples/element.rb +77 -0
- metadata +63 -4
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'gather_content/dsl/base'
|
2
|
+
require 'gather_content/config/elements/text'
|
3
|
+
|
4
|
+
module GatherContent
|
5
|
+
module DSL
|
6
|
+
class Text < Base
|
7
|
+
def initialize(tab)
|
8
|
+
@text = GatherContent::Config::Element::Text.new
|
9
|
+
super(tab, @text)
|
10
|
+
end
|
11
|
+
|
12
|
+
def value(value)
|
13
|
+
@text.value = value
|
14
|
+
end
|
15
|
+
|
16
|
+
def limit_type(limit_type)
|
17
|
+
@text.limit_type = limit_type
|
18
|
+
end
|
19
|
+
|
20
|
+
def limit(limit)
|
21
|
+
@text.limit = limit
|
22
|
+
end
|
23
|
+
|
24
|
+
def plain_text(plain_text)
|
25
|
+
@text.plain_text = plain_text
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/gather_content/error.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gather_content/config/tab'
|
3
|
+
require 'gather_content/config/builder'
|
4
|
+
|
5
|
+
RSpec.describe GatherContent::Config::Builder do
|
6
|
+
context "adding a tab element" do
|
7
|
+
it "adds the tab" do
|
8
|
+
builder = GatherContent::Config::Builder.build do
|
9
|
+
tab do
|
10
|
+
label "text_label"
|
11
|
+
name "Text Label"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
expect(builder.first).to be_instance_of(GatherContent::Config::Tab)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "to_json" do
|
20
|
+
it "returns a JSON object" do
|
21
|
+
builder = GatherContent::Config::Builder.build do
|
22
|
+
tab do
|
23
|
+
label "text_label"
|
24
|
+
name "Text Label"
|
25
|
+
|
26
|
+
text do
|
27
|
+
name "Text"
|
28
|
+
label "text"
|
29
|
+
required false
|
30
|
+
value ""
|
31
|
+
microcopy ""
|
32
|
+
limit_type :chars
|
33
|
+
limit 255
|
34
|
+
plain_text true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
expect(JSON.parse(builder.to_json)).to eq(JSON.parse([{"label": "text_label", "name": "Text Label", "hidden": false, "elements": [{"name": "Text", "required": false, "label": "text", "microcopy": "", "type": "text", "value": "", "limit_type": "chars", "limit": 255, "plain_text": true}]}].to_json))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gather_content/config/elements/choice_checkbox'
|
3
|
+
require 'gather_content/config/elements/option'
|
4
|
+
require 'gather_content/config/elements/other_option'
|
5
|
+
|
6
|
+
RSpec.describe GatherContent::Config::Element::ChoiceCheckbox do
|
7
|
+
let(:name) { "checkbox" }
|
8
|
+
let(:required) { false }
|
9
|
+
let(:label) { "Choices" }
|
10
|
+
let(:microcopy) { "Choose a thing" }
|
11
|
+
let(:options) do
|
12
|
+
o1 = GatherContent::Config::Element::Option.new("option_1", "Option 1")
|
13
|
+
o2 = GatherContent::Config::Element::Option.new("option_2", "Option 2")
|
14
|
+
|
15
|
+
[o1, o2]
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:checkbox) { GatherContent::Config::Element::ChoiceCheckbox.new }
|
19
|
+
|
20
|
+
context "defaults" do
|
21
|
+
subject { checkbox }
|
22
|
+
|
23
|
+
include_examples "Gather Content Defaults", "text"
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when converting to JSON" do
|
27
|
+
before(:each) do
|
28
|
+
checkbox.name = name
|
29
|
+
checkbox.required = required
|
30
|
+
checkbox.label = label
|
31
|
+
checkbox.microcopy = microcopy
|
32
|
+
checkbox.options = options
|
33
|
+
end
|
34
|
+
|
35
|
+
subject { checkbox.serialize }
|
36
|
+
it_behaves_like "a Gather Content Element", "choice_checkbox"
|
37
|
+
|
38
|
+
context "options" do
|
39
|
+
context "aren't supplied" do
|
40
|
+
let(:options) { [] }
|
41
|
+
|
42
|
+
it "raises a ArgumentError" do
|
43
|
+
expect {
|
44
|
+
subject
|
45
|
+
}.to raise_error(ArgumentError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "are supplied" do
|
50
|
+
let(:options) { [ GatherContent::Config::Element::Option.new("option_1", "Option 1") ] }
|
51
|
+
|
52
|
+
it "serialises the options" do
|
53
|
+
expect(subject[:options]).to eq(options.map{ |el| el.serialize })
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "are type OtherOption" do
|
58
|
+
let(:options) { [ GatherContent::Config::Element::OtherOption.new("option_1", "Option 1") ] }
|
59
|
+
|
60
|
+
it "raises a ArgumentError" do
|
61
|
+
expect {
|
62
|
+
subject
|
63
|
+
}.to raise_error(ArgumentError)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "are not an Option type" do
|
68
|
+
let(:options) { [ "Hello" ] }
|
69
|
+
|
70
|
+
it "raises a ArgumentError" do
|
71
|
+
expect {
|
72
|
+
subject
|
73
|
+
}.to raise_error(ArgumentError)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gather_content/config/elements/choice_radio'
|
3
|
+
require 'gather_content/config/elements/option'
|
4
|
+
|
5
|
+
RSpec.describe GatherContent::Config::Element::ChoiceRadio do
|
6
|
+
let(:name) { "radio" }
|
7
|
+
let(:required) { false }
|
8
|
+
let(:label) { "Choices" }
|
9
|
+
let(:microcopy) { "Choose a thing" }
|
10
|
+
let(:other_option) { false }
|
11
|
+
let(:options) do
|
12
|
+
o1 = GatherContent::Config::Element::Option.new("option_1", "Option 1")
|
13
|
+
o2 = GatherContent::Config::Element::Option.new("option_2", "Option 2")
|
14
|
+
|
15
|
+
[o1, o2]
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:radio) { GatherContent::Config::Element::ChoiceRadio.new }
|
19
|
+
|
20
|
+
context "defaults" do
|
21
|
+
subject { radio }
|
22
|
+
|
23
|
+
include_examples "Gather Content Defaults", "text"
|
24
|
+
|
25
|
+
context "other_option" do
|
26
|
+
it "is false" do
|
27
|
+
expect(subject.other_option).to eq(false)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when converting to JSON" do
|
33
|
+
before(:each) do
|
34
|
+
radio.name = name
|
35
|
+
radio.required = required
|
36
|
+
radio.label = label
|
37
|
+
radio.microcopy = microcopy
|
38
|
+
radio.options = options
|
39
|
+
radio.other_option = other_option
|
40
|
+
end
|
41
|
+
|
42
|
+
subject { radio.serialize }
|
43
|
+
it_behaves_like "a Gather Content Element", "choice_radio"
|
44
|
+
|
45
|
+
context "options" do
|
46
|
+
context "aren't supplied" do
|
47
|
+
let(:options) { [] }
|
48
|
+
|
49
|
+
it "raises a ArgumentError" do
|
50
|
+
expect {
|
51
|
+
subject
|
52
|
+
}.to raise_error(ArgumentError)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "where none are selected" do
|
57
|
+
let(:options) do
|
58
|
+
o1 = GatherContent::Config::Element::Option.new("option_1", "Option 1", false)
|
59
|
+
o2 = GatherContent::Config::Element::Option.new("option_2", "Option 2", false)
|
60
|
+
|
61
|
+
[o1, o2]
|
62
|
+
end
|
63
|
+
|
64
|
+
it "serialises the options" do
|
65
|
+
expect(subject[:options]).to eq(options.map{ |el| el.serialize })
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "where one is selected" do
|
70
|
+
let(:options) do
|
71
|
+
o1 = GatherContent::Config::Element::Option.new("option_1", "Option 1", true)
|
72
|
+
o2 = GatherContent::Config::Element::Option.new("option_2", "Option 2", false)
|
73
|
+
|
74
|
+
[o1, o2]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "serialises the options" do
|
78
|
+
expect(subject[:options]).to eq(options.map{ |el| el.serialize })
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "where more than one is selected" do
|
83
|
+
let(:options) do
|
84
|
+
o1 = GatherContent::Config::Element::Option.new("option_1", "Option 1", true)
|
85
|
+
o2 = GatherContent::Config::Element::Option.new("option_2", "Option 2", true)
|
86
|
+
|
87
|
+
[o1, o2]
|
88
|
+
end
|
89
|
+
|
90
|
+
it "raises a ArgumentError" do
|
91
|
+
expect {
|
92
|
+
subject
|
93
|
+
}.to raise_error(ArgumentError)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when other_option is false" do
|
98
|
+
context "there is only one option" do
|
99
|
+
let(:options) { [ GatherContent::Config::Element::Option.new("option_1", "Option 1") ] }
|
100
|
+
|
101
|
+
it "serialises the options" do
|
102
|
+
expect(subject[:options]).to eq(options.map{ |el| el.serialize })
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "when other_option is true" do
|
108
|
+
let(:other_option) { true }
|
109
|
+
|
110
|
+
context "there is only one option" do
|
111
|
+
let(:options) { [ GatherContent::Config::Element::Option.new("option_1", "Option 1") ] }
|
112
|
+
|
113
|
+
it "raises a ArgumentError" do
|
114
|
+
expect {
|
115
|
+
subject
|
116
|
+
}.to raise_error(ArgumentError)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "and the last option is a OptionOther" do
|
121
|
+
let(:options) do
|
122
|
+
o1 = GatherContent::Config::Element::Option.new("option_1", "Option 1")
|
123
|
+
o2 = GatherContent::Config::Element::OtherOption.new("option_2", "Option 2")
|
124
|
+
|
125
|
+
[o1, o2]
|
126
|
+
end
|
127
|
+
|
128
|
+
it "serialises the options" do
|
129
|
+
expect(subject[:options]).to eq(options.map{ |el| el.serialize })
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "and the last option is not an OtherOption" do
|
134
|
+
let(:options) do
|
135
|
+
o1 = GatherContent::Config::Element::Option.new("option_1", "Option 1")
|
136
|
+
o2 = GatherContent::Config::Element::Option.new("option_2", "Option 2")
|
137
|
+
|
138
|
+
[o1, o2]
|
139
|
+
end
|
140
|
+
|
141
|
+
it "raises a ArgumentError" do
|
142
|
+
expect {
|
143
|
+
subject
|
144
|
+
}.to raise_error(ArgumentError)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "the OtherOption is not the last option" do
|
149
|
+
let(:options) do
|
150
|
+
o1 = GatherContent::Config::Element::OtherOption.new("option_1", "Option 1")
|
151
|
+
o2 = GatherContent::Config::Element::Option.new("option_2", "Option 2")
|
152
|
+
|
153
|
+
[o1, o2]
|
154
|
+
end
|
155
|
+
|
156
|
+
it "raises a ArgumentError" do
|
157
|
+
expect {
|
158
|
+
subject
|
159
|
+
}.to raise_error(ArgumentError)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "are not an Option type" do
|
165
|
+
let(:options) { [ "Hello" ] }
|
166
|
+
|
167
|
+
it "raises a ArgumentError" do
|
168
|
+
expect {
|
169
|
+
subject
|
170
|
+
}.to raise_error(ArgumentError)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gather_content/config/elements/files'
|
3
|
+
|
4
|
+
RSpec.describe GatherContent::Config::Element::Files do
|
5
|
+
let(:name) { "file" }
|
6
|
+
let(:required) { false }
|
7
|
+
let(:label) { "Files" }
|
8
|
+
let(:microcopy) { "Upload a file" }
|
9
|
+
|
10
|
+
let(:files) { GatherContent::Config::Element::Files.new }
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
files.name = name
|
14
|
+
files.required = required
|
15
|
+
files.label = label
|
16
|
+
files.microcopy = microcopy
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when converting to JSON" do
|
20
|
+
subject { files.serialize }
|
21
|
+
it_behaves_like "a Gather Content Element", "files"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gather_content/config/elements/option'
|
3
|
+
|
4
|
+
RSpec.describe GatherContent::Config::Element::Option do
|
5
|
+
let(:name) { "file" }
|
6
|
+
let(:label) { "Files" }
|
7
|
+
let(:selected) { false }
|
8
|
+
|
9
|
+
let(:option) { GatherContent::Config::Element::Option.new }
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
option.name = name
|
13
|
+
option.label = label
|
14
|
+
option.selected = selected
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when converting to JSON" do
|
18
|
+
subject { option.serialize }
|
19
|
+
|
20
|
+
context "a valid section instance" do
|
21
|
+
it "has a name" do
|
22
|
+
expect(subject[:name]).to eq(name)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has a label" do
|
26
|
+
expect(subject[:label]).to eq(label)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has a selected flag" do
|
30
|
+
expect(subject[:selected]).to eq(selected)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with an empty name" do
|
35
|
+
let(:name) { "" }
|
36
|
+
|
37
|
+
it "raises a ArgumentError" do
|
38
|
+
expect {
|
39
|
+
subject
|
40
|
+
}.to raise_error(ArgumentError)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with an empty label" do
|
45
|
+
let(:label) { "" }
|
46
|
+
|
47
|
+
it "raises a ArgumentError" do
|
48
|
+
expect {
|
49
|
+
subject
|
50
|
+
}.to raise_error(ArgumentError)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "selected" do
|
55
|
+
context "is true" do
|
56
|
+
let(:selected) { true }
|
57
|
+
|
58
|
+
it "compiles to true" do
|
59
|
+
expect(subject[:selected]).to eq(true)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "is false" do
|
64
|
+
let(:selected) { false }
|
65
|
+
|
66
|
+
it "compiles to false" do
|
67
|
+
expect(subject[:selected]).to eq(false)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "is truthy" do
|
72
|
+
let(:selected) { "I'm a string!" }
|
73
|
+
|
74
|
+
it "compiles to true" do
|
75
|
+
expect(subject[:selected]).to eq(true)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "is falsey" do
|
80
|
+
let(:selected) { nil }
|
81
|
+
|
82
|
+
it "compiles to false" do
|
83
|
+
expect(subject[:selected]).to eq(false)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|