radiant-forms-extension 3.2.1 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.1
1
+ 3.2.2
@@ -176,6 +176,18 @@ module Forms
176
176
  result
177
177
  end
178
178
 
179
+ desc %{
180
+ Allows access to the response of a submitted form
181
+ @<r:response>...<r:get /><r:clear />...</r:response>@
182
+
183
+ _Will not expand if a form has not been submitted or has been cleared_
184
+ }
185
+ tag 'response' do |tag|
186
+ tag.locals.response = Forms::Tags::Responses.current(tag,request)
187
+
188
+ tag.expand if tag.locals.response.present? and tag.locals.response.result.present?
189
+ end
190
+
179
191
  desc %{
180
192
  Clears the response object
181
193
 
@@ -186,17 +198,47 @@ module Forms
186
198
 
187
199
  nil
188
200
  end
201
+
202
+ desc %{ Expand if there is a response to a specified for value }
203
+ tag 'response:if_results' do |tag|
204
+ extension = tag.attr['extension'].to_sym
205
+ tag.locals.response_extension = tag.locals.response.result[:results][extension]
206
+
207
+ tag.expand if tag.locals.response_extension.present?
208
+ end
189
209
 
190
- desc %{
191
- Allows access to the response of a submitted form
192
- @<r:response>...<r:get /><r:clear />...</r:response>@
210
+ desc %{ Expand if there is a response to a specified for value }
211
+ tag 'response:unless_results' do |tag|
212
+ extension = tag.attr['extension'].to_sym
213
+ tag.locals.response_extension = tag.locals.response.result[:results][extension]
193
214
 
194
- _Will not expand if a form has not been submitted or has been cleared_
215
+ tag.expand unless tag.locals.response_extension.present?
216
+ end
217
+
218
+ desc %{ Expand if there is a positive response to a specified for value of an extension
219
+
220
+ <pre>
221
+ <r:response:if_get extension='bogus_gateway' value='checkout'>yay</r:response:if_get>
222
+ </pre>
195
223
  }
196
- tag 'response' do |tag|
197
- tag.locals.response = Forms::Tags::Responses.current(tag,request)
224
+ tag 'response:if_get' do |tag|
225
+ query = tag.attr['name'].to_sym
226
+ result = tag.locals.response_extension[query]
198
227
 
199
- tag.expand if tag.locals.response.present? and tag.locals.response.result.present?
228
+ tag.expand if result.present? and result === true
229
+ end
230
+
231
+ desc %{ Expand if there is a negative response to a specified for value of an extension
232
+
233
+ <pre>
234
+ <r:response:unless_get extension='bogus_gateway' value='checkout'>no</r:response:unless_get>
235
+ </pre>
236
+ }
237
+ tag 'response:unless_get' do |tag|
238
+ query = tag.attr['name'].to_sym
239
+ result = tag.locals.response_extension[query]
240
+
241
+ tag.expand if !result.present? or result != true
200
242
  end
201
243
 
202
244
  desc %{
@@ -246,6 +288,7 @@ module Forms
246
288
  tag.globals.indexes[key] = 0
247
289
  nil
248
290
  end
291
+
249
292
  end
250
293
  end
251
294
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{radiant-forms-extension}
8
- s.version = "3.2.1"
8
+ s.version = "3.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["dirkkelly"]
12
- s.date = %q{2010-10-23}
12
+ s.date = %q{2010-10-25}
13
13
  s.description = %q{Send data from a page to a form handler, extendable with addons}
14
14
  s.email = %q{dirk.kelly@squaretalent.com}
15
15
  s.extra_rdoc_files = [
@@ -28,4 +28,15 @@ CONFIG
28
28
  create_record :form, :test, attributes
29
29
  end
30
30
 
31
+ helpers do
32
+ def mock_response
33
+ @response = OpenStruct.new({
34
+ :result => {
35
+ :results => {}
36
+ }
37
+ })
38
+ mock(Forms::Tags::Responses).current(anything,anything) { @response }
39
+ end
40
+ end
41
+
31
42
  end
@@ -1,8 +1,45 @@
1
1
  require 'spec/spec_helper'
2
2
 
3
3
  describe Forms::Tags::Core do
4
+
4
5
  dataset :pages, :forms
5
6
 
7
+ context 'contained tags' do
8
+
9
+ it 'should describe these tags' do
10
+ Forms::Tags::Core.tags.sort.should == [
11
+ 'form',
12
+ 'form:label',
13
+ 'form:text',
14
+ 'form:password',
15
+ 'form:reset',
16
+ 'form:checkbox',
17
+ 'form:radio',
18
+ 'form:hidden',
19
+ 'form:file',
20
+ 'form:button',
21
+ 'form:select',
22
+ 'form:radios',
23
+ 'form:option',
24
+ 'form:submit',
25
+ 'form:read',
26
+ 'form:read:each',
27
+
28
+ 'response',
29
+ 'response:clear',
30
+ 'response:get',
31
+ 'response:if_results',
32
+ 'response:unless_results',
33
+ 'response:if_get',
34
+ 'response:unless_get',
35
+
36
+ 'index',
37
+ 'reset'
38
+ ].sort
39
+ end
40
+
41
+ end
42
+
6
43
  context 'form output' do
7
44
 
8
45
  before :all do
@@ -108,4 +145,97 @@ describe Forms::Tags::Core do
108
145
 
109
146
  end
110
147
 
148
+ context 'response' do
149
+
150
+ context 'conditionals' do
151
+
152
+ before :each do
153
+ @page = pages(:home)
154
+ mock_response
155
+ end
156
+
157
+ describe 'if_results' do
158
+ context 'extension sent results' do
159
+ it 'should render' do
160
+ @response.result[:results] = { :bogus => { :payment => true } }
161
+
162
+ tag = %{<r:response:if_results extension='bogus'>success</r:response:if_results>}
163
+ exp = %{success}
164
+ @page.should render(tag).as(exp)
165
+ end
166
+ end
167
+ context 'extension did not send results' do
168
+ it 'should not render' do
169
+ tag = %{<r:response:if_results extension='bogus'>failure</r:response:if_results>}
170
+ exp = %{}
171
+ @page.should render(tag).as(exp)
172
+ end
173
+ end
174
+ end
175
+
176
+ describe 'unless_results' do
177
+ context 'extension did not send results' do
178
+ it 'should render' do
179
+ tag = %{<r:response:unless_results extension='bogus'>success</r:response:unless_results>}
180
+ exp = %{success}
181
+ @page.should render(tag).as(exp)
182
+ end
183
+ end
184
+ context 'extension sent results' do
185
+ it 'should not render' do
186
+ @response.result[:results] = { :bogus => { :payment => true } }
187
+
188
+ tag = %{<r:response:unless_results extension='bogus'>failure</r:response:unless_results>}
189
+ exp = %{}
190
+ @page.should render(tag).as(exp)
191
+ end
192
+ end
193
+ end
194
+
195
+ describe 'if_get' do
196
+ context 'extension sent positive results' do
197
+ it 'should render' do
198
+ @response.result[:results] = { :bogus => { :payment => true } }
199
+
200
+ tag = %{<r:response:if_results extension='bogus'><r:if_get name='payment'>success</r:if_get></r:response:if_results>}
201
+ exp = %{success}
202
+ @page.should render(tag).as(exp)
203
+ end
204
+ end
205
+ context 'extension sent negative results' do
206
+ it 'should not render' do
207
+ @response.result[:results] = { :bogus => { :payment => false } }
208
+
209
+ tag = %{<r:response:if_results extension='bogus'><r:if_get name='payment'>failure</r:if_get></r:response:if_results>}
210
+ exp = %{}
211
+ @page.should render(tag).as(exp)
212
+ end
213
+ end
214
+ end
215
+
216
+ describe 'unless_get' do
217
+ context 'extension sent positive results' do
218
+ it 'should render' do
219
+ @response.result[:results] = { :bogus => { :payment => false } }
220
+
221
+ tag = %{<r:response:if_results extension='bogus'><r:unless_get name='payment'>success</r:unless_get></r:response:if_results>}
222
+ exp = %{success}
223
+ @page.should render(tag).as(exp)
224
+ end
225
+ end
226
+ context 'extension sent negative results' do
227
+ it 'should not render' do
228
+ @response.result[:results] = { :bogus => { :payment => true } }
229
+
230
+ tag = %{<r:response:if_results extension='bogus'><r:unless_get name='payment'>failure</r:unless_get></r:response:if_results>}
231
+ exp = %{}
232
+ @page.should render(tag).as(exp)
233
+ end
234
+ end
235
+ end
236
+
237
+ end
238
+
239
+ end
240
+
111
241
  end
data/spec/spec.opts CHANGED
@@ -1,7 +1,4 @@
1
1
  --colour
2
- --format
3
- progress
4
- --loadby
5
- mtime
6
- --reverse
7
- --debugger
2
+ --format specdoc
3
+ --loadby mtime
4
+ --reverse
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-forms-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 3
8
8
  - 2
9
- - 1
10
- version: 3.2.1
9
+ - 2
10
+ version: 3.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - dirkkelly
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-23 00:00:00 +08:00
18
+ date: 2010-10-25 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21