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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +7 -0
  3. data/README.md +161 -35
  4. data/gather_content-api.gemspec +1 -1
  5. data/lib/gather_content.rb +2 -0
  6. data/lib/gather_content/api.rb +16 -15
  7. data/lib/gather_content/config.rb +9 -0
  8. data/lib/gather_content/config/builder.rb +20 -0
  9. data/lib/gather_content/config/elements.rb +15 -0
  10. data/lib/gather_content/config/elements/base.rb +32 -0
  11. data/lib/gather_content/config/elements/choice_checkbox.rb +32 -0
  12. data/lib/gather_content/config/elements/choice_radio.rb +62 -0
  13. data/lib/gather_content/config/elements/files.rb +17 -0
  14. data/lib/gather_content/config/elements/option.rb +30 -0
  15. data/lib/gather_content/config/elements/other_option.rb +26 -0
  16. data/lib/gather_content/config/elements/section.rb +31 -0
  17. data/lib/gather_content/config/elements/text.rb +32 -0
  18. data/lib/gather_content/config/tab.rb +30 -0
  19. data/lib/gather_content/config/tabs.rb +13 -0
  20. data/lib/gather_content/dsl.rb +15 -0
  21. data/lib/gather_content/dsl/base.rb +28 -0
  22. data/lib/gather_content/dsl/choice_checkbox.rb +19 -0
  23. data/lib/gather_content/dsl/choice_radio.rb +25 -0
  24. data/lib/gather_content/dsl/config.rb +16 -0
  25. data/lib/gather_content/dsl/files.rb +12 -0
  26. data/lib/gather_content/dsl/option.rb +29 -0
  27. data/lib/gather_content/dsl/other_option.rb +18 -0
  28. data/lib/gather_content/dsl/section.rb +24 -0
  29. data/lib/gather_content/dsl/tab.rb +54 -0
  30. data/lib/gather_content/dsl/text.rb +29 -0
  31. data/lib/gather_content/error.rb +1 -1
  32. data/lib/gather_content/version.rb +1 -1
  33. data/spec/gather_content/config/builder_spec.rb +42 -0
  34. data/spec/gather_content/config/elements/choice_checkbox_spec.rb +78 -0
  35. data/spec/gather_content/config/elements/choice_radio_spec.rb +175 -0
  36. data/spec/gather_content/config/elements/files_spec.rb +23 -0
  37. data/spec/gather_content/config/elements/option_spec.rb +88 -0
  38. data/spec/gather_content/config/elements/other_option_spec.rb +124 -0
  39. data/spec/gather_content/config/elements/section_spec.rb +80 -0
  40. data/spec/gather_content/config/elements/text_spec.rb +163 -0
  41. data/spec/gather_content/config/tab_spec.rb +120 -0
  42. data/spec/gather_content/dsl/choice_checkbox_spec.rb +25 -0
  43. data/spec/gather_content/dsl/choice_radio_spec.rb +47 -0
  44. data/spec/gather_content/dsl/files_spec.rb +12 -0
  45. data/spec/gather_content/dsl/section_spec.rb +37 -0
  46. data/spec/gather_content/dsl/tab_spec.rb +107 -0
  47. data/spec/gather_content/dsl/text_spec.rb +48 -0
  48. data/spec/spec_helper.rb +1 -1
  49. data/spec/support/shared_examples/dsl.rb +63 -0
  50. data/spec/support/shared_examples/element.rb +77 -0
  51. metadata +63 -4
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+ require 'gather_content/config/elements/other_option'
3
+
4
+ RSpec.describe GatherContent::Config::Element::OtherOption do
5
+ let(:name) { "file" }
6
+ let(:label) { "Files" }
7
+ let(:selected) { false }
8
+ let(:value) { "other option" }
9
+
10
+ let(:option) { GatherContent::Config::Element::OtherOption.new }
11
+
12
+ before(:each) do
13
+ option.name = name
14
+ option.label = label
15
+ option.selected = selected
16
+ option.value = value
17
+ end
18
+
19
+ context "when converting to JSON" do
20
+ subject { option.serialize }
21
+
22
+ context "a valid section instance" do
23
+ it "has a name" do
24
+ expect(subject[:name]).to eq(name)
25
+ end
26
+
27
+ it "has a label" do
28
+ expect(subject[:label]).to eq(label)
29
+ end
30
+
31
+ it "has a selected flag" do
32
+ expect(subject[:selected]).to eq(selected)
33
+ end
34
+ end
35
+
36
+ context "with an empty name" do
37
+ let(:name) { "" }
38
+
39
+ it "raises a ArgumentError" do
40
+ expect {
41
+ subject
42
+ }.to raise_error(ArgumentError)
43
+ end
44
+ end
45
+
46
+ context "with an empty label" do
47
+ let(:label) { "" }
48
+
49
+ it "raises a ArgumentError" do
50
+ expect {
51
+ subject
52
+ }.to raise_error(ArgumentError)
53
+ end
54
+ end
55
+
56
+ context "selected" do
57
+ context "is true" do
58
+ let(:selected) { true }
59
+
60
+ it "compiles to true" do
61
+ expect(subject[:selected]).to eq(true)
62
+ end
63
+ end
64
+
65
+ context "is false" do
66
+ let(:selected) { false }
67
+
68
+ it "compiles to false" do
69
+ expect(subject[:selected]).to eq(false)
70
+ end
71
+ end
72
+
73
+ context "is truthy" do
74
+ let(:selected) { "I'm a string!" }
75
+
76
+ it "compiles to true" do
77
+ expect(subject[:selected]).to eq(true)
78
+ end
79
+ end
80
+
81
+ context "is falsey" do
82
+ let(:selected) { nil }
83
+
84
+ it "compiles to false" do
85
+ expect(subject[:selected]).to eq(false)
86
+ end
87
+ end
88
+ end
89
+
90
+ context "value" do
91
+ context "select is true" do
92
+ let(:selected) { true }
93
+
94
+ it "compiles to the supplied value" do
95
+ expect(subject[:value]).to eq(value)
96
+ end
97
+ end
98
+
99
+ context "select is false" do
100
+ let(:selected) { false }
101
+
102
+ it "compiles to empty string" do
103
+ expect(subject[:value]).to eq("")
104
+ end
105
+ end
106
+
107
+ context "select is truthy" do
108
+ let(:selected) { "I'm a string!" }
109
+
110
+ it "compiles to the supplied value" do
111
+ expect(subject[:value]).to eq(value)
112
+ end
113
+ end
114
+
115
+ context "select is falsey" do
116
+ let(:selected) { nil }
117
+
118
+ it "compiles to empty string" do
119
+ expect(subject[:value]).to eq("")
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+ require 'gather_content/config/elements/section'
3
+
4
+ RSpec.describe GatherContent::Config::Element::Section do
5
+ let(:name) { "section" }
6
+ let(:title) { "Section Title" }
7
+ let(:subtitle) { "Section Subtitle" }
8
+
9
+ let(:section) { GatherContent::Config::Element::Section.new }
10
+
11
+ context "defaults" do
12
+ subject { section }
13
+
14
+ context "name" do
15
+ it "is an empty string" do
16
+ expect(subject.name).to eq("")
17
+ end
18
+ end
19
+
20
+ context "title" do
21
+ it "is an empty string" do
22
+ expect(subject.title).to eq("")
23
+ end
24
+ end
25
+
26
+ context "subtitle" do
27
+ it "is an empty string" do
28
+ expect(subject.subtitle).to eq("")
29
+ end
30
+ end
31
+ end
32
+
33
+ context "when converting to JSON" do
34
+ before(:each) do
35
+ section.name = name
36
+ section.title = title
37
+ section.subtitle = subtitle
38
+ end
39
+
40
+ subject { section.serialize }
41
+
42
+ it "has the correct type" do
43
+ expect(subject[:type]).to eq("section")
44
+ end
45
+
46
+ context "a valid section instance" do
47
+ it "has a name" do
48
+ expect(subject[:name]).to eq(name)
49
+ end
50
+
51
+ it "has a title" do
52
+ expect(subject[:title]).to eq(title)
53
+ end
54
+
55
+ it "has a subtitle" do
56
+ expect(subject[:subtitle]).to eq(subtitle)
57
+ end
58
+ end
59
+
60
+ context "with an empty name" do
61
+ let(:name) { "" }
62
+
63
+ it "raises a ArgumentError" do
64
+ expect {
65
+ subject
66
+ }.to raise_error(ArgumentError)
67
+ end
68
+ end
69
+
70
+ context "with an empty title" do
71
+ let(:title) { "" }
72
+
73
+ it "raises a ArgumentError" do
74
+ expect {
75
+ subject
76
+ }.to raise_error(ArgumentError)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,163 @@
1
+ require 'spec_helper'
2
+ require 'gather_content/config/elements/text'
3
+
4
+ RSpec.describe GatherContent::Config::Element::Text do
5
+ let(:name) { "text" }
6
+ let(:required) { false }
7
+ let(:label) { "Text" }
8
+ let(:microcopy) { "Write some text" }
9
+ let(:value) { "Placeholder text" }
10
+ let(:limit_type) { :words }
11
+ let(:limit) { 1000 }
12
+ let(:plain_text) { false }
13
+
14
+ let(:text) { GatherContent::Config::Element::Text.new }
15
+
16
+ context "defaults" do
17
+ subject { text }
18
+
19
+ include_examples "Gather Content Defaults", "text"
20
+
21
+ context "value" do
22
+ it "is a blank string" do
23
+ expect(subject.value).to eq("")
24
+ end
25
+ end
26
+
27
+ context "limit_type" do
28
+ it "is chars" do
29
+ expect(subject.limit_type).to eq(:chars)
30
+ end
31
+ end
32
+
33
+ context "limit" do
34
+ it "is 0" do
35
+ expect(subject.limit).to eq(0)
36
+ end
37
+ end
38
+
39
+ context "plain_text" do
40
+ it "is false" do
41
+ expect(subject.plain_text).to eq(true)
42
+ end
43
+ end
44
+ end
45
+
46
+ context "when converting to JSON" do
47
+ before(:each) do
48
+ text.name = name
49
+ text.required = required
50
+ text.label = label
51
+ text.microcopy = microcopy
52
+ text.value = value
53
+ text.limit_type = limit_type
54
+ text.limit = limit
55
+ text.plain_text = plain_text
56
+ end
57
+
58
+ subject { text.serialize }
59
+ it_behaves_like "a Gather Content Element", "text"
60
+
61
+ context "limit_type" do
62
+ context "is :words" do
63
+ let(:limit_type) { :words }
64
+
65
+ it "is ok" do
66
+ expect {
67
+ subject
68
+ }.to_not raise_error
69
+ end
70
+
71
+ it "converts to string" do
72
+ expect(subject[:limit_type]).to eq("words")
73
+ end
74
+ end
75
+
76
+ context "is :chars" do
77
+ let(:limit_type) { :chars }
78
+
79
+ it "is ok" do
80
+ expect {
81
+ subject
82
+ }.to_not raise_error
83
+ end
84
+
85
+ it "converts to string" do
86
+ expect(subject[:limit_type]).to eq("chars")
87
+ end
88
+ end
89
+
90
+ context "with invalid limit_type" do
91
+ let(:limit_type) { :not_valid }
92
+
93
+ it "raises a ArgumentError" do
94
+ expect {
95
+ subject
96
+ }.to raise_error(ArgumentError)
97
+ end
98
+ end
99
+ end
100
+
101
+ context "limit" do
102
+ context "is a positive number" do
103
+ let(:limit) { 1000 }
104
+
105
+ it "raises no exception" do
106
+ expect(subject[:limit]).to eq(limit)
107
+ end
108
+ end
109
+
110
+ context "is a negative number" do
111
+ let(:limit) { -1000 }
112
+
113
+ it "raises a ArgumentError" do
114
+ expect {
115
+ subject
116
+ }.to raise_error(ArgumentError)
117
+ end
118
+ end
119
+
120
+ context "is not a number" do
121
+ let(:limit) { "Hello" }
122
+
123
+ it "probably casts to 0" do
124
+ expect(subject[:limit]).to eq(0)
125
+ end
126
+ end
127
+ end
128
+
129
+ context "plain_text" do
130
+ context "is true" do
131
+ let(:plain_text) { true }
132
+
133
+ it "compiles to true" do
134
+ expect(subject[:plain_text]).to eq(true)
135
+ end
136
+ end
137
+
138
+ context "is false" do
139
+ let(:plain_text) { false }
140
+
141
+ it "compiles to false" do
142
+ expect(subject[:plain_text]).to eq(false)
143
+ end
144
+ end
145
+
146
+ context "is truthy" do
147
+ let(:plain_text) { "I'm a string!" }
148
+
149
+ it "compiles to true" do
150
+ expect(subject[:plain_text]).to eq(true)
151
+ end
152
+ end
153
+
154
+ context "is falsey" do
155
+ let(:plain_text) { nil }
156
+
157
+ it "compiles to false" do
158
+ expect(subject[:plain_text]).to eq(false)
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,120 @@
1
+ require 'spec_helper'
2
+ require 'gather_content/config/tab'
3
+
4
+ RSpec.describe GatherContent::Config::Tab do
5
+ let(:name) { "tab" }
6
+ let(:label) { "Tab" }
7
+ let(:hidden) { false }
8
+ let(:elements) { [] }
9
+
10
+ let(:tab) { GatherContent::Config::Tab.new }
11
+
12
+ context "defaults" do
13
+ subject { tab }
14
+
15
+ context "name" do
16
+ it "is an empty string" do
17
+ expect(subject.name).to eq("")
18
+ end
19
+ end
20
+
21
+ context "label" do
22
+ it "is an empty string" do
23
+ expect(subject.label).to eq("")
24
+ end
25
+ end
26
+
27
+ context "hidden" do
28
+ it "is false" do
29
+ expect(subject.hidden).to eq(false)
30
+ end
31
+ end
32
+
33
+ context "elements" do
34
+ it "is an empty array" do
35
+ expect(subject.elements).to eq([])
36
+ end
37
+ end
38
+ end
39
+
40
+ context "when converting to JSON" do
41
+ before(:each) do
42
+ tab.name = name
43
+ tab.label = label
44
+ tab.hidden = hidden
45
+ tab.elements = elements
46
+ end
47
+
48
+ subject { tab.serialize }
49
+
50
+ it "has a name" do
51
+ expect(subject[:name]).to eq(name)
52
+ end
53
+
54
+ it "has a hidden flag" do
55
+ expect(subject[:hidden]).to eq(hidden)
56
+ end
57
+
58
+ it "has a label" do
59
+ expect(subject[:label]).to eq(label)
60
+ end
61
+
62
+ it "has elements" do
63
+ expect(subject[:elements]).to eq(elements)
64
+ end
65
+
66
+ context "with an empty name" do
67
+ let(:name) { "" }
68
+
69
+ it "raises a ArgumentError" do
70
+ expect {
71
+ subject
72
+ }.to raise_error(ArgumentError)
73
+ end
74
+ end
75
+
76
+ context "with an empty label" do
77
+ let(:label) { "" }
78
+
79
+ it "raises a ArgumentError" do
80
+ expect {
81
+ subject
82
+ }.to raise_error(ArgumentError)
83
+ end
84
+ end
85
+
86
+ context "hidden" do
87
+ context "is true" do
88
+ let(:hidden) { true }
89
+
90
+ it "compiles to true" do
91
+ expect(subject[:hidden]).to eq(true)
92
+ end
93
+ end
94
+
95
+ context "is false" do
96
+ let(:hidden) { false }
97
+
98
+ it "compiles to false" do
99
+ expect(subject[:hidden]).to eq(false)
100
+ end
101
+ end
102
+
103
+ context "is truthy" do
104
+ let(:hidden) { "I'm a string!" }
105
+
106
+ it "compiles to true" do
107
+ expect(subject[:hidden]).to eq(true)
108
+ end
109
+ end
110
+
111
+ context "is falsey" do
112
+ let(:hidden) { nil }
113
+
114
+ it "compiles to false" do
115
+ expect(subject[:hidden]).to eq(false)
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end