hungryform 0.0.9 → 0.0.10

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: faa4b7aec875ea1a2be57ee1e8f35119367832b8
4
- data.tar.gz: 20bd1356c0cf47c5e651d69c9c44b1f6afb1c0c6
3
+ metadata.gz: c55e397d5568ee783aa7a4c10579676ed50314bf
4
+ data.tar.gz: 23e0adea07adeaa6b2d3d613a48b32a79402bf7c
5
5
  SHA512:
6
- metadata.gz: 82a39eb9740d20619524296f1d246ffad7646f12885136c262a744bb457003bd50cc25644a049e20b436c7148463c008d852cd224e67ddceed52c4789bd60355
7
- data.tar.gz: ee1663f3b3e8f5854d4d50bfc9ec2302268209829f1ad1c29584d0ef47a60f880ee2c459684c4a8056939600b4aea1c9369dbfc65a1c1fa68a5f1ab38c0a6fe1
6
+ metadata.gz: 883d982d48448c144de2d9e6dcbbe97db6f49e59b4e97372031cbacaa8a19e16bfea8e20b2f9276e61d9496ac49a7939087bdfb2b1d79e34c07ce92b394c9366
7
+ data.tar.gz: aafb593254ac8fd69158b9990bd2d2bac90a2afc5dbf56714a0fda95fa8d4dd746bb124564600b94cd14db3fe21b3e1c74f6b45404a7f8d758b0e3c749639c4d
@@ -11,7 +11,7 @@ module HungryForm
11
11
  hashable :visible, :dependency, :name, :label
12
12
 
13
13
  def initialize(name, parent, resolver, attributes = {})
14
- @attributes = HungryForm.configuration.send(self.class.name.demodulize.underscore).dup
14
+ @attributes = configuration.dup
15
15
  @attributes.merge!(attributes)
16
16
 
17
17
  @placeholders ||= {}
@@ -42,6 +42,11 @@ module HungryForm
42
42
  def dependency_json
43
43
  JSON.generate(dependency) if dependency
44
44
  end
45
+
46
+ # Configuration params specific to the element
47
+ def configuration
48
+ HungryForm.configuration.send(self.class.name.demodulize.underscore)
49
+ end
45
50
  end
46
51
  end
47
52
  end
@@ -52,7 +52,7 @@ module HungryForm
52
52
  @current_page ||= pages.first
53
53
  end
54
54
 
55
- # Create a form page
55
+ # Create a new page
56
56
  def page(name, attributes = {}, &block)
57
57
  page = Elements::Page.new(name, nil, @resolver, attributes, &block)
58
58
  pages << page if page.visible?
@@ -60,7 +60,7 @@ module HungryForm
60
60
 
61
61
  # Entire form validation. Loops through the form pages and
62
62
  # validates each page individually.
63
- def valid?
63
+ def validate
64
64
  is_valid = true
65
65
 
66
66
  pages.each do |page|
@@ -71,8 +71,12 @@ module HungryForm
71
71
  is_valid
72
72
  end
73
73
 
74
+ def valid?
75
+ validate
76
+ end
77
+
74
78
  def invalid?
75
- !valid?
79
+ !validate
76
80
  end
77
81
 
78
82
  # Get all the elements the form consists of
@@ -101,12 +105,14 @@ module HungryForm
101
105
  end
102
106
  end
103
107
 
108
+ # Get the next page of the form
104
109
  def next_page
105
110
  pages.each_cons(2) do |page, next_page|
106
111
  return next_page if page == current_page
107
112
  end
108
113
  end
109
114
 
115
+ # Get the previous page of the form
110
116
  def prev_page
111
117
  pages.each_cons(2) do |prev_page, page|
112
118
  return prev_page if page == current_page
@@ -1,3 +1,3 @@
1
1
  module HungryForm
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -86,6 +86,17 @@ describe HungryForm do
86
86
  end
87
87
  end
88
88
 
89
+ describe "#validate" 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
+
89
100
  describe "#valid?" do
90
101
  it "should be valid" do
91
102
  expect(subject.valid?).to eq true
@@ -97,6 +108,17 @@ describe HungryForm do
97
108
  end
98
109
  end
99
110
 
111
+ describe "#invalid?" do
112
+ it "should not be invalid" do
113
+ expect(subject.invalid?).to eq false
114
+ end
115
+
116
+ it "should be invalid" do
117
+ options[:params]["first_first_name"] = ''
118
+ expect(subject.invalid?).to eq true
119
+ end
120
+ end
121
+
100
122
  describe "#next_page" do
101
123
  it "should return the next page" do
102
124
  options[:params][:page] = "first"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hungryform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Bazhutkin