hungryform 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -1
  3. data/.rspec +0 -1
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +5 -0
  6. data/README.md +72 -43
  7. data/Rakefile +3 -4
  8. data/hungryform.gemspec +4 -4
  9. data/lib/hungryform/configuration.rb +31 -0
  10. data/lib/hungryform/elements/base/active_element.rb +44 -36
  11. data/lib/hungryform/elements/base/element.rb +40 -49
  12. data/lib/hungryform/elements/base/group.rb +74 -71
  13. data/lib/hungryform/elements/base/hashable.rb +32 -30
  14. data/lib/hungryform/elements/base/options_element.rb +28 -24
  15. data/lib/hungryform/elements/html.rb +1 -1
  16. data/lib/hungryform/elements/page.rb +4 -0
  17. data/lib/hungryform/elements/radio_group.rb +1 -1
  18. data/lib/hungryform/elements/select_field.rb +14 -18
  19. data/lib/hungryform/elements/{text_area_field.rb → text_area.rb} +1 -1
  20. data/lib/hungryform/elements.rb +9 -1
  21. data/lib/hungryform/exceptions.rb +3 -0
  22. data/lib/hungryform/form.rb +32 -2
  23. data/lib/hungryform/resolver.rb +14 -16
  24. data/lib/hungryform/version.rb +1 -1
  25. data/lib/hungryform.rb +22 -5
  26. data/spec/elements/group_spec.rb +10 -1
  27. data/spec/elements/html_spec.rb +11 -9
  28. data/spec/elements/page_spec.rb +10 -7
  29. data/spec/elements/radio_group_spec.rb +9 -15
  30. data/spec/elements/select_field_spec.rb +19 -33
  31. data/spec/elements/shared_examples/active_element.rb +52 -0
  32. data/spec/elements/shared_examples/element.rb +42 -0
  33. data/spec/elements/shared_examples/group.rb +31 -0
  34. data/spec/elements/shared_examples/options_element.rb +24 -0
  35. data/spec/elements/text_area_spec.rb +14 -0
  36. data/spec/elements/text_field_spec.rb +10 -3
  37. data/spec/form_spec.rb +68 -1
  38. data/spec/resolver_spec.rb +7 -7
  39. data/spec/spec_helper.rb +4 -2
  40. metadata +29 -40
  41. data/Gemfile.lock +0 -52
  42. data/spec/elements/text_area_field_spec.rb +0 -7
  43. data/spec/support/shared_active_element.rb +0 -65
  44. data/spec/support/shared_element.rb +0 -62
  45. data/spec/support/shared_group.rb +0 -42
  46. data/spec/support/shared_options_element.rb +0 -36
@@ -0,0 +1,42 @@
1
+ RSpec.shared_examples "an element" do
2
+ describe "#visible?" do
3
+ it "should be visible" do
4
+ expect(subject.visible?).to eq true
5
+ end
6
+
7
+ it "should not be visible" do
8
+ options[:visible] = false
9
+ expect(subject.visible?).to eq false
10
+ end
11
+
12
+ context "when dependency is present" do
13
+ it "should not be visible" do
14
+ options[:dependency] = { eq: [0, 1] }
15
+ expect(subject.visible?).to eq false
16
+ end
17
+
18
+ it "should be visible" do
19
+ options[:dependency] = { eq: [1, 1] }
20
+ expect(subject.visible?).to eq true
21
+ end
22
+ end
23
+ end
24
+
25
+ describe "#label" do
26
+ it "should have a humanized label based on element's name" do
27
+ expect(subject.label).to eq "Element name"
28
+ end
29
+
30
+ it "should have a label defined in options" do
31
+ options[:label] = "Special Label"
32
+ expect(subject.label).to eq "Special Label"
33
+ end
34
+ end
35
+
36
+ describe "#to_hash" do
37
+ it "should include visible, dependency, name and label" do
38
+ options.merge!(dependency: { eq: [1, 1] }, name: 'name')
39
+ expect(subject.to_hash).to include(:visible, :dependency, :name, :label)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,31 @@
1
+ RSpec.shared_examples "a group" do
2
+ describe "#group" do
3
+ it "creates a nested group" do
4
+ subject.group(:nested, {}) {}
5
+ expect(subject.elements.first.class).to eq HungryForm::Elements::Group
6
+ end
7
+
8
+ it "concatenates nested element's name with the parent's one" do
9
+ subject.group(:nested, {}) {}
10
+ expect(subject.elements.first.name).to end_with "element_name_nested"
11
+ end
12
+ end
13
+
14
+ describe "#to_hash" do
15
+ it "should include group elements" do
16
+ expect(subject.to_hash).to include(:elements)
17
+ end
18
+ end
19
+
20
+ describe ".method_missing" do
21
+ it "creates a nested element" do
22
+ subject.html(:name)
23
+ expect(subject.elements.first.class).to eq HungryForm::Elements::Html
24
+ end
25
+
26
+ it "concatenates nested element's name with the parent's one" do
27
+ subject.html(:html)
28
+ expect(subject.elements.first.name).to end_with "element_name_html"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ RSpec.shared_examples "an element with options" do
2
+ describe ".new" do
3
+ it "should raise an exception if there is no options provided" do
4
+ options.delete(:options)
5
+ expect { described_class.new(:element_name, group, resolver, options) }.to raise_error(HungryForm::HungryFormException)
6
+ end
7
+
8
+ it "should have options" do
9
+ options[:options] = {"1" => "First", "2" => "Last"}
10
+ expect(subject.options).to eq({"1" => "First", "2" => "Last"})
11
+ end
12
+
13
+ it "should convert options to hash" do
14
+ options[:options] = ->(el) {{"1" => "First", "2" => "Last"}}
15
+ expect(subject.options).to eq({"1" => "First", "2" => "Last"})
16
+ end
17
+ end
18
+
19
+ describe "#to_hash" do
20
+ it "should include options" do
21
+ expect(subject.to_hash).to include(:options)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe HungryForm::Elements::TextArea do
4
+ let(:resolver_options) { {} }
5
+ let(:resolver) { HungryForm::Resolver.new(resolver_options) }
6
+ let(:group_options) { {} }
7
+ let(:group) { HungryForm::Elements::Group.new(:group, nil, resolver, group_options) {} }
8
+ let(:options) { {} }
9
+
10
+ subject { HungryForm::Elements::TextArea.new(:element_name, group, resolver, options) {} }
11
+
12
+ it_behaves_like 'an element'
13
+ it_behaves_like 'an active element'
14
+ end
@@ -1,7 +1,14 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe HungryForm::Elements::TextField do
4
- it_behaves_like "an active element" do
5
- let(:active_element_options) { {} }
6
- end
4
+ let(:resolver_options) { {} }
5
+ let(:resolver) { HungryForm::Resolver.new(resolver_options) }
6
+ let(:group_options) { {} }
7
+ let(:group) { HungryForm::Elements::Group.new(:group, nil, resolver, group_options) {} }
8
+ let(:options) { {} }
9
+
10
+ subject { HungryForm::Elements::TextField.new(:element_name, group, resolver, options) {} }
11
+
12
+ it_behaves_like 'an element'
13
+ it_behaves_like 'an active element'
7
14
  end
data/spec/form_spec.rb CHANGED
@@ -15,7 +15,7 @@ describe HungryForm do
15
15
  subject do
16
16
  HungryForm::Form.new(options) do
17
17
  page :first do
18
- text_field :first_name
18
+ text_field :first_name, required: true
19
19
  text_field :last_name
20
20
  end
21
21
  page :second, visible: false do
@@ -37,6 +37,28 @@ describe HungryForm do
37
37
  end
38
38
  end
39
39
 
40
+ describe ".configure" do
41
+ it "sets a new views prefix" do
42
+ HungryForm.configure do |config|
43
+ config.views_prefix = '/new/prefix'
44
+ end
45
+
46
+ expect(HungryForm.configuration.views_prefix).to eq '/new/prefix'
47
+ end
48
+
49
+ it "configures default element options" do
50
+ HungryForm.configure do |config|
51
+ config.text_field my_attr: 100
52
+ end
53
+
54
+ expect(HungryForm.configuration.text_field[:my_attr]).to eq 100
55
+ end
56
+
57
+ after do
58
+ HungryForm.reset_config
59
+ end
60
+ end
61
+
40
62
  describe "#page" do
41
63
  subject(:form) { HungryForm::Form.new() {} }
42
64
 
@@ -53,4 +75,49 @@ describe HungryForm do
53
75
  expect(hash["pages"].first["elements"].size).to eq 2
54
76
  end
55
77
  end
78
+
79
+ describe "#values" do
80
+ it "should generate an array of name => value hashes" do
81
+ expect(subject.values).to include(
82
+ first_first_name: "John",
83
+ first_last_name: "Doe",
84
+ third_occupation: "programmer"
85
+ )
86
+ end
87
+ end
88
+
89
+ describe "#valid?" do
90
+ it "should be valid" do
91
+ expect(subject.valid?).to eq true
92
+ end
93
+
94
+ it "should be invalid" do
95
+ options[:params]["first_first_name"] = ''
96
+ expect(subject.valid?).to eq false
97
+ end
98
+ end
99
+
100
+ describe "#next_page" do
101
+ it "should return the next page" do
102
+ options[:params][:page] = "first"
103
+ expect(subject.next_page).to eq subject.pages[1]
104
+ end
105
+
106
+ it "should return nil if there is no next page" do
107
+ options[:params][:page] = "third"
108
+ expect(subject.next_page).to be_nil
109
+ end
110
+ end
111
+
112
+ describe "#prev_page" do
113
+ it "should return the previous page" do
114
+ options[:params][:page] = "third"
115
+ expect(subject.prev_page).to eq subject.pages.first
116
+ end
117
+
118
+ it "should return nil if there is no previous page" do
119
+ options[:params][:page] = "first"
120
+ expect(subject.prev_page).to be_nil
121
+ end
122
+ end
56
123
  end
@@ -40,37 +40,37 @@ describe HungryForm::Resolver do
40
40
 
41
41
  describe "#resolve_dependency" do
42
42
  it "should resolve EQ dependency" do
43
- dependency = { "EQ" => ["Text", "Text"] }
43
+ dependency = { eq: ["Text", "Text"] }
44
44
  expect(subject.resolve_dependency(dependency)).to eq true
45
45
  end
46
46
 
47
47
  it "should resolve LT dependency" do
48
- dependency = { "LT" => ["0", "1"] }
48
+ dependency = { lt: ["0", "1"] }
49
49
  expect(subject.resolve_dependency(dependency)).to eq true
50
50
  end
51
51
 
52
52
  it "should resolve GT dependency" do
53
- dependency = { "GT" => ["1", "0"] }
53
+ dependency = { gt: ["1", "0"] }
54
54
  expect(subject.resolve_dependency(dependency)).to eq true
55
55
  end
56
56
 
57
57
  it "should resolve SET dependency" do
58
- dependency = { "SET" => "1" }
58
+ dependency = { set: "1" }
59
59
  expect(subject.resolve_dependency(dependency)).to eq true
60
60
  end
61
61
 
62
62
  it "should resolve AND dependency" do
63
- dependency = { "AND" => [{"SET" => "1"}, {"SET" => "1"}] }
63
+ dependency = { and: [{set: "1"}, {set: "1"}] }
64
64
  expect(subject.resolve_dependency(dependency)).to eq true
65
65
  end
66
66
 
67
67
  it "should resolve OR dependency" do
68
- dependency = { "OR" => [{"SET" => ""}, {"SET" => "1"}] }
68
+ dependency = { or: [{set: ""}, {set: "1"}] }
69
69
  expect(subject.resolve_dependency(dependency)).to eq true
70
70
  end
71
71
 
72
72
  it "should resolve NOT dependency" do
73
- dependency = { "NOT" => {"SET" => ""} }
73
+ dependency = { not: {set: ""} }
74
74
  expect(subject.resolve_dependency(dependency)).to eq true
75
75
  end
76
76
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.setup
3
3
 
4
- require "hungryform"
4
+ require 'hungryform'
5
5
 
6
- Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
6
+ Dir['./spec/support/**/*.rb'].each { |f| require f }
7
+ Dir['./spec/elements/shared_examples/**/*.rb'].each { |f| require f }
8
+ Dir['./spec/views/shared_examples/**/*.rb'].each { |f| require f }
7
9
 
8
10
  RSpec.configure do |config|
9
11
  config.order = :random
metadata CHANGED
@@ -1,37 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hungryform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Bazhutkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-17 00:00:00.000000000 Z
11
+ date: 2015-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.6'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.6'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
14
+ name: activesupport
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
19
  version: '0'
34
- type: :development
20
+ type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
@@ -39,21 +25,21 @@ dependencies:
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: rspec
28
+ name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - "~>"
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: '3.0'
33
+ version: 1.0.0
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - "~>"
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: '3.0'
40
+ version: 1.0.0
55
41
  - !ruby/object:Gem::Dependency
56
- name: pry
42
+ name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - ">="
@@ -67,19 +53,19 @@ dependencies:
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
- name: activesupport
56
+ name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - ">="
74
60
  - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
61
+ version: '3.0'
62
+ type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: '0'
68
+ version: '3.0'
83
69
  description:
84
70
  email:
85
71
  - andrey.bazhutkin@gmail.com
@@ -89,13 +75,15 @@ extra_rdoc_files: []
89
75
  files:
90
76
  - ".gitignore"
91
77
  - ".rspec"
78
+ - ".ruby-version"
79
+ - ".travis.yml"
92
80
  - Gemfile
93
- - Gemfile.lock
94
81
  - LICENSE
95
82
  - README.md
96
83
  - Rakefile
97
84
  - hungryform.gemspec
98
85
  - lib/hungryform.rb
86
+ - lib/hungryform/configuration.rb
99
87
  - lib/hungryform/elements.rb
100
88
  - lib/hungryform/elements/base/active_element.rb
101
89
  - lib/hungryform/elements/base/element.rb
@@ -107,8 +95,9 @@ files:
107
95
  - lib/hungryform/elements/page.rb
108
96
  - lib/hungryform/elements/radio_group.rb
109
97
  - lib/hungryform/elements/select_field.rb
110
- - lib/hungryform/elements/text_area_field.rb
98
+ - lib/hungryform/elements/text_area.rb
111
99
  - lib/hungryform/elements/text_field.rb
100
+ - lib/hungryform/exceptions.rb
112
101
  - lib/hungryform/form.rb
113
102
  - lib/hungryform/resolver.rb
114
103
  - lib/hungryform/validator.rb
@@ -118,15 +107,15 @@ files:
118
107
  - spec/elements/page_spec.rb
119
108
  - spec/elements/radio_group_spec.rb
120
109
  - spec/elements/select_field_spec.rb
121
- - spec/elements/text_area_field_spec.rb
110
+ - spec/elements/shared_examples/active_element.rb
111
+ - spec/elements/shared_examples/element.rb
112
+ - spec/elements/shared_examples/group.rb
113
+ - spec/elements/shared_examples/options_element.rb
114
+ - spec/elements/text_area_spec.rb
122
115
  - spec/elements/text_field_spec.rb
123
116
  - spec/form_spec.rb
124
117
  - spec/resolver_spec.rb
125
118
  - spec/spec_helper.rb
126
- - spec/support/shared_active_element.rb
127
- - spec/support/shared_element.rb
128
- - spec/support/shared_group.rb
129
- - spec/support/shared_options_element.rb
130
119
  - spec/validator_spec.rb
131
120
  homepage: https://github.com/andrba/hungryform
132
121
  licenses:
@@ -158,14 +147,14 @@ test_files:
158
147
  - spec/elements/page_spec.rb
159
148
  - spec/elements/radio_group_spec.rb
160
149
  - spec/elements/select_field_spec.rb
161
- - spec/elements/text_area_field_spec.rb
150
+ - spec/elements/shared_examples/active_element.rb
151
+ - spec/elements/shared_examples/element.rb
152
+ - spec/elements/shared_examples/group.rb
153
+ - spec/elements/shared_examples/options_element.rb
154
+ - spec/elements/text_area_spec.rb
162
155
  - spec/elements/text_field_spec.rb
163
156
  - spec/form_spec.rb
164
157
  - spec/resolver_spec.rb
165
158
  - spec/spec_helper.rb
166
- - spec/support/shared_active_element.rb
167
- - spec/support/shared_element.rb
168
- - spec/support/shared_group.rb
169
- - spec/support/shared_options_element.rb
170
159
  - spec/validator_spec.rb
171
160
  has_rdoc:
data/Gemfile.lock DELETED
@@ -1,52 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- hungryform (0.0.4)
5
- activesupport
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activesupport (4.1.6)
11
- i18n (~> 0.6, >= 0.6.9)
12
- json (~> 1.7, >= 1.7.7)
13
- minitest (~> 5.1)
14
- thread_safe (~> 0.1)
15
- tzinfo (~> 1.1)
16
- coderay (1.1.0)
17
- diff-lcs (1.2.5)
18
- i18n (0.6.11)
19
- json (1.8.1)
20
- method_source (0.8.2)
21
- minitest (5.4.2)
22
- pry (0.9.12.6)
23
- coderay (~> 1.0)
24
- method_source (~> 0.8)
25
- slop (~> 3.4)
26
- rake (10.3.2)
27
- rspec (3.1.0)
28
- rspec-core (~> 3.1.0)
29
- rspec-expectations (~> 3.1.0)
30
- rspec-mocks (~> 3.1.0)
31
- rspec-core (3.1.7)
32
- rspec-support (~> 3.1.0)
33
- rspec-expectations (3.1.2)
34
- diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.1.0)
36
- rspec-mocks (3.1.3)
37
- rspec-support (~> 3.1.0)
38
- rspec-support (3.1.2)
39
- slop (3.6.0)
40
- thread_safe (0.3.4)
41
- tzinfo (1.2.2)
42
- thread_safe (~> 0.1)
43
-
44
- PLATFORMS
45
- ruby
46
-
47
- DEPENDENCIES
48
- bundler (~> 1.6)
49
- hungryform!
50
- pry
51
- rake
52
- rspec (~> 3.0)
@@ -1,7 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe HungryForm::Elements::TextAreaField do
4
- it_behaves_like "an active element" do
5
- let(:active_element_options) { {} }
6
- end
7
- end
@@ -1,65 +0,0 @@
1
- RSpec.shared_examples "an active element" do
2
- let(:resolver_options) { {} }
3
- let(:resolver) { HungryForm::Resolver.new(resolver_options) }
4
-
5
- let(:group_options) { {} }
6
- let(:group) { HungryForm::Elements::Group.new(:group, nil, resolver, group_options) {} }
7
-
8
- let(:element) { described_class.new(:element_name, group, resolver, active_element_options) {} }
9
-
10
- it_behaves_like "an element" do
11
- let(:element_options) { active_element_options }
12
- end
13
-
14
- describe ".new" do
15
- it "should have empty error" do
16
- expect(element.error).to eq ""
17
- end
18
-
19
- it "should not be required if its parent is not visible" do
20
- group_options[:visible] = false
21
- active_element_options[:required] = true
22
- expect(element.required?).to eq false
23
- end
24
-
25
- it "should have a nil value" do
26
- expect(element.value).to be nil
27
- end
28
-
29
- it "should have a value from form params" do
30
- resolver_options[:params]= {"group_element_name" => "element_value" }
31
- expect(element.value).to eq "element_value"
32
- end
33
-
34
- it "should have a value from element structure" do
35
- active_element_options[:value] = "element_value"
36
- expect(element.value).to eq "element_value"
37
- end
38
- end
39
-
40
- describe "#valid?" do
41
- describe "when required" do
42
- before(:each) do
43
- active_element_options[:required] = true
44
- end
45
-
46
- it "is valid" do
47
- element.value = "value"
48
- expect(element.valid?).to eq true
49
- end
50
-
51
- it "is invalid" do
52
- element.value = ""
53
- expect(element.valid?).to eq false
54
- end
55
- end
56
- end
57
-
58
- describe "#to_hash" do
59
- it "should include required, value and error" do
60
- active_element_options[:value] = ''
61
- active_element_options[:required] = true
62
- expect(element.to_hash).to include(:required, :value, :error)
63
- end
64
- end
65
- end
@@ -1,62 +0,0 @@
1
- RSpec.shared_examples "an element" do
2
- let(:resolver) { HungryForm::Resolver.new() }
3
-
4
- let(:group) { HungryForm::Elements::Group.new(:group, nil, resolver, {}) {} }
5
-
6
- let(:element) { described_class.new(:element_name, group, resolver, element_options) {} }
7
-
8
- describe "#visible?" do
9
- it "should be visible" do
10
- expect(element.visible?).to eq true
11
- end
12
-
13
- it "should not be visible" do
14
- element_options[:visible] = false
15
- expect(element.visible?).to eq false
16
- end
17
-
18
- context "when dependency is present" do
19
- it "should not be visible" do
20
- element_options[:dependency] = '{"EQ": ["0", "1"]}'
21
- expect(element.visible?).to eq false
22
- end
23
-
24
- it "should be visible" do
25
- element_options[:dependency] = '{"EQ": ["1", "1"]}'
26
- expect(element.visible?).to eq true
27
- end
28
- end
29
- end
30
-
31
- describe "#label" do
32
- it "should have a humanized label based on element's name" do
33
- expect(element.label).to eq "Element name"
34
- end
35
-
36
- it "should have a label defined in options" do
37
- element_options[:label] = "Special Label"
38
- expect(element.label).to eq "Special Label"
39
- end
40
- end
41
-
42
- describe "#method_missing" do
43
- it "should return existing param" do
44
- element_options[:html_param] = "param"
45
- expect(element.html_param).to eq "param"
46
- end
47
-
48
- it "should check whether param exists" do
49
- element_options[:html_param] = "param"
50
- expect(element.html_param?).to eq true
51
- expect(element.other_html_param?).to eq false
52
- end
53
- end
54
-
55
- describe "#to_hash" do
56
- it "should include visible, dependency, name and label" do
57
- element_options[:dependency] = '{"EQ": [1, 1]}'
58
- element_options[:name] = 'name'
59
- expect(element.to_hash).to include(:visible, :dependency, :name, :label)
60
- end
61
- end
62
- end
@@ -1,42 +0,0 @@
1
- RSpec.shared_examples "a group" do
2
- let(:resolver) { HungryForm::Resolver.new() }
3
-
4
- let(:page) { described_class.new(:parent_name, nil, resolver, {}) {} }
5
-
6
- let(:group_options) { {} }
7
- let(:group) { described_class.new(:name, page, resolver, group_options) {} }
8
-
9
- it_behaves_like "an element" do
10
- let(:element_options) { group_options }
11
- end
12
-
13
- describe "#group" do
14
- it "creates a nested group" do
15
- group.group(:nested, {}) {}
16
- expect(group.elements.first.class).to eq HungryForm::Elements::Group
17
- end
18
-
19
- it "concatenates nested element's name with the parent's one" do
20
- group.group(:nested, {}) {}
21
- expect(group.elements.first.name).to eq "parent_name_name_nested"
22
- end
23
- end
24
-
25
- describe "#to_hash" do
26
- it "should include group elements" do
27
- expect(group.to_hash).to include(:elements)
28
- end
29
- end
30
-
31
- describe ".method_missing" do
32
- it "creates a nested element" do
33
- group.html(:name)
34
- expect(group.elements.first.class).to eq HungryForm::Elements::Html
35
- end
36
-
37
- it "concatenates nested element's name with the parent's one" do
38
- group.html(:html)
39
- expect(group.elements.first.name).to eq "parent_name_name_html"
40
- end
41
- end
42
- end