radiant-forms-extension 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. data/.gitignore +3 -0
  2. data/README.md +117 -0
  3. data/Rakefile +137 -0
  4. data/VERSION +1 -0
  5. data/app/controllers/admin/forms_controller.rb +10 -0
  6. data/app/controllers/forms_controller.rb +35 -0
  7. data/app/models/form.rb +5 -0
  8. data/app/models/form_page.rb +7 -0
  9. data/app/models/response.rb +11 -0
  10. data/app/views/admin/forms/_fields.html.haml +56 -0
  11. data/app/views/admin/forms/_filters.html.haml +7 -0
  12. data/app/views/admin/forms/_form.html.haml +6 -0
  13. data/app/views/admin/forms/_header.html.haml +3 -0
  14. data/app/views/admin/forms/edit.html.haml +15 -0
  15. data/app/views/admin/forms/index.html.haml +20 -0
  16. data/app/views/admin/forms/new.html.haml +15 -0
  17. data/app/views/admin/forms/remove.html.haml +20 -0
  18. data/config/locales/en.yml +3 -0
  19. data/config/routes.rb +9 -0
  20. data/cucumber.yml +1 -0
  21. data/db/migrate/001_create_forms.rb +16 -0
  22. data/db/migrate/002_create_user_observer.rb +15 -0
  23. data/db/migrate/003_rename_output_to_content.rb +9 -0
  24. data/db/migrate/004_create_responses.rb +13 -0
  25. data/forms_extension.rb +24 -0
  26. data/lib/forms/admin_ui.rb +23 -0
  27. data/lib/forms/application_controller_extensions.rb +20 -0
  28. data/lib/forms/extension_methods.rb +14 -0
  29. data/lib/forms/page_extensions.rb +6 -0
  30. data/lib/forms/site_controller_extensions.rb +19 -0
  31. data/lib/forms/tags.rb +277 -0
  32. data/lib/tasks/forms_extension_tasks.rake +55 -0
  33. data/public/images/admin/extensions/form/form.png +0 -0
  34. data/radiant-forms-extension.gemspec +87 -0
  35. data/spec/controllers/forms_controller_spec.rb +150 -0
  36. data/spec/datasets/forms.rb +30 -0
  37. data/spec/lib/forms/extension_methods_spec.rb +41 -0
  38. data/spec/lib/forms/tags_spec.rb +122 -0
  39. data/spec/models/form_spec.rb +40 -0
  40. data/spec/models/response_spec.rb +31 -0
  41. data/spec/spec.opts +7 -0
  42. data/spec/spec_helper.rb +18 -0
  43. metadata +102 -0
@@ -0,0 +1,19 @@
1
+ module Forms
2
+ module SiteControllerExtensions
3
+ def self.included(base)
4
+ base.class_eval {
5
+ before_filter :find_response
6
+
7
+ def find_response
8
+ if request.session[:form_response]
9
+ @response = Response.find(request.session[:form_response])
10
+ else
11
+ @response = nil
12
+ end
13
+
14
+ @response
15
+ end
16
+ }
17
+ end
18
+ end
19
+ end
data/lib/forms/tags.rb ADDED
@@ -0,0 +1,277 @@
1
+ module Forms
2
+ module Tags
3
+ include Radiant::Taggable
4
+
5
+ class TagError < StandardError; end
6
+
7
+ desc %{
8
+ Render a form and its contents
9
+ <pre><code><r:form name="object[key]" [method, url] /></code></pre>
10
+
11
+ * *name* the name of the form
12
+ * *method* url submission method [ post, get, delete, put ]
13
+ * *url* address to submit the form to
14
+ }
15
+ tag 'form' do |tag|
16
+
17
+ unless tag.attr['name'].blank?
18
+ if tag.locals.form = Form.find_by_title(tag.attr['name'])
19
+ tag.attr['id'] ||= 'form_' + tag.locals.form.title
20
+ tag.attr['method'] ||= 'post'
21
+ tag.attr['action'] ||= tag.locals.form.action.nil? ? "/forms/#{tag.locals.form.id}" : tag.locals.form.action
22
+ return render_form(tag.locals.form, tag)
23
+ else
24
+ raise TagError, "Could not find '#{tag.attr['name']}' form"
25
+ end
26
+ else
27
+ tag.expand
28
+ end
29
+
30
+ end
31
+
32
+ desc %{
33
+ Render a @<label />@ tag to be used inside a form
34
+ <pre><code><r:form:label for="object[key]" /></code></pre>
35
+
36
+ **Required**
37
+ * *for* the name of the field you are relating the tag to
38
+
39
+ _A label is a piece of text which activates its related input when clicked_
40
+ }
41
+ tag 'form:label' do |tag|
42
+ raise_error_if_missing 'form:label', tag.attr, 'for'
43
+
44
+ tag.attr['for'] = tag.attr['for'].gsub('[','_').gsub(']','') unless tag.attr['for'].nil?
45
+
46
+ %(<label #{form_attrs(tag)}>#{tag.expand}</label>)
47
+ end
48
+
49
+ %w(text password reset checkbox radio hidden file button).each do |type|
50
+ desc %{
51
+ Render a @<#{type}>...</#{type}>@ tag to be used in a form
52
+ <pre><code><r:form:#{type} name="object[key]" /></code></pre>
53
+
54
+ **Required**
55
+ * *name* the name of the data to be sent
56
+
57
+ **Optional**
58
+ * *class* css class names
59
+ * *placeholder* default text, which is cleared when clicked
60
+ * *maxlength* the maximum amount of characters
61
+ }
62
+ tag "form:#{type}" do |tag|
63
+ raise_error_if_missing "form:#{type}", tag.attr, 'name'
64
+
65
+ value = tag.attr['value']
66
+ tag.attr['type'] = type
67
+
68
+ %(<input type="#{type}" value="#{value}" #{form_attrs(tag)} />)
69
+ end
70
+ end
71
+
72
+ desc %{
73
+ Renders a @<select>...</select>@ tag to be used in a form
74
+
75
+ <pre><code><r:form:select name="object[key]"><r:option value="text" /></r:form:select></code></pre>
76
+
77
+ **Required**
78
+ * *name* the name of the data to be sent
79
+
80
+ **Optional**
81
+ * *class* css class names
82
+
83
+ _@<r:option />@ tags may be nested inside the tag to automatically generate options_
84
+ }
85
+ tag 'form:select' do |tag|
86
+ raise_error_if_missing 'form:select', tag.attr, 'name'
87
+
88
+ tag.locals.parent_tag_name = tag.attr['name']
89
+ tag.locals.parent_tag_type = 'select'
90
+
91
+ %(<select #{form_attrs(tag)}>#{tag.expand}</select>)
92
+ end
93
+
94
+ desc %{
95
+ Renders a series of @<input type="radio"/>@ tags to be used in a form
96
+
97
+ <pre><code><r:form:radios name="object[value]" value="text"><r:option value="text" /></r:form:radios></code></pre>
98
+
99
+ **Required**
100
+ * *name* the name of the data to be sent
101
+
102
+ **Optional**
103
+ * *class* css class names
104
+
105
+ _@<r:option />@ tags may be nested inside the tag to automatically generate options_
106
+ }
107
+ tag 'form:radios' do |tag|
108
+ raise_error_if_missing 'form:radios', tag.attr, 'name'
109
+
110
+ tag.locals.parent_tag_name = tag.attr['name']
111
+ tag.locals.parent_tag_type = 'radios'
112
+ tag.expand
113
+ end
114
+
115
+ desc %{
116
+ Renders an @<option/>@ tag if the parent is a
117
+ @<r:form:select>...</r:form:select>@ or @<r:form:radios>...</r:form:radios>@
118
+
119
+ **Required**
120
+ * *value* the value you want to be sent if selected
121
+ }
122
+ tag 'form:option' do |tag|
123
+ value = tag.attr['value'] || tag.expand
124
+
125
+ if tag.locals.parent_tag_type == 'select'
126
+ text = tag.expand.length == 0 ? value : tag.expand
127
+ %(<option #{form_attrs(tag, { 'value' => value})}>#{text}</option>)
128
+ elsif tag.locals.parent_tag_type == 'radios'
129
+ name = tag.locals.parent_tag_type == 'radios' ? tag.locals.parent_tag_name : tag.attr['name']
130
+ id = name.gsub('[','_').gsub(']','') + '_' + value
131
+ %(<input #{form_attrs(tag, { 'id' => id, 'value' => value, 'name' => name, 'type' => 'radio' })} />)
132
+ end
133
+ end
134
+
135
+ desc %{
136
+ Renders an @<input type="submit" />@ tag for a form.
137
+
138
+ **Optional**
139
+ * *value* the text on the submit
140
+ }
141
+ tag 'form:submit' do |tag|
142
+ value = tag.attr['value'] || 'submit'
143
+
144
+ %(<input #{form_attrs(tag, { 'value' => value, 'type' => 'submit', 'class' => 'submit', 'name' => 'submit' })} />)
145
+ end
146
+
147
+ desc %{
148
+ Allows access to the response of a submitted form
149
+ @<r:form:response>...<r:get /><r:clear />...</r:form:response>@
150
+
151
+ _Will not expand if a form has not been submitted or has been cleared_
152
+ }
153
+ tag 'form:response' do |tag|
154
+ tag.locals.form_response = find_form_response(tag)
155
+
156
+ tag.expand unless tag.locals.form_response.nil? or tag.locals.form_response.response.nil?
157
+ end
158
+
159
+ desc %{
160
+ Access the attributes of a submitted form.
161
+
162
+ @<r:form:get name=object[value]
163
+ }
164
+ tag 'form:response:clear' do |tag|
165
+ clear_form_response(tag)
166
+
167
+ return nil
168
+ end
169
+
170
+ desc %{
171
+ Access the attributes of a submitted form.
172
+
173
+ @<r:form:get name="object[value]" />@ an object which was submitted with the form
174
+ @<r:form:get name="mail_ext[value]" />@ a response to an extension which hooked the submission
175
+
176
+ _Refer to the readme on extensions to find out what they return_
177
+ }
178
+ tag 'form:response:get' do |tag|
179
+ raise_error_if_missing 'form:response:get', tag.attr, 'name'
180
+
181
+ results = hash_retrieve(tag.locals.form_response.result, tag.attr['name'])
182
+ end
183
+
184
+ # accessing data when processing a form
185
+ desc %{
186
+ Query the data from a submitted form
187
+
188
+ @<r:form:read name="object[value]" />@ access the object which was submitted
189
+
190
+ _This can only be used in the content section of a form, use @<r:form:get />@ in pages_
191
+ }
192
+ tag 'form:read' do |tag|
193
+ raise_error_if_missing 'form:read', tag.attr, 'name'
194
+
195
+ data = hash_retrieve(tag.locals.page.data, tag.attr['name']).to_s
196
+ end
197
+
198
+ protected
199
+
200
+ def form_attrs(tag, extras={})
201
+ @id = tag.attr['name'] || extras['name']
202
+ @id = @id || tag.attr['for'] + '_label' if tag.attr['for']
203
+ @id = @id.gsub('[','_').gsub(']','') unless @id.nil?
204
+
205
+ attrs = {
206
+ 'id' => @id,
207
+ 'class' => tag.attr['type'],
208
+ 'name' => nil,
209
+ 'for' => nil,
210
+ 'method' => nil,
211
+ 'action' => nil,
212
+ 'placeholder' => nil,
213
+ 'value' => nil,
214
+ 'maxlength' => nil
215
+ }.merge(extras)
216
+
217
+ result = attrs.collect do |k,v|
218
+ v = (tag.attr[k] || v)
219
+ next if v.blank?
220
+ %(#{k}="#{v}")
221
+ end.reject{|e| e.blank?}
222
+
223
+ result.join(' ')
224
+ end
225
+
226
+ def prior_value(tag, tag_name=tag.attr['name'])
227
+ #TODO make work with hash_retrieve
228
+ end
229
+
230
+ def render_form(form, tag)
231
+ string = %(<form enctype="multipart/form-data" #{form_attrs(tag)}>\n)
232
+ string << %(<input type="hidden" name="page_id" value="#{tag.locals.page.id}" />\n)
233
+ string << %(<input type="hidden" name="form_id" value="#{tag.locals.form.id.to_s}" />\n)
234
+ string << "<r:form>"
235
+ string << form.body
236
+ string << "</r:form>"
237
+ string << %(</form>)
238
+
239
+ text = parse(string)
240
+ end
241
+
242
+ def raise_error_if_missing(tag_name, tag_attr, name)
243
+ raise "'#{tag_name}' tag requires a '#{name}' attribute" if tag_attr[name].blank?
244
+ end
245
+
246
+ def find_form_response(tag)
247
+ if tag.locals.form_response
248
+ tag.locals.form_response
249
+ elsif request.session[:form_response]
250
+ Response.find(request.session[:form_response])
251
+ else
252
+ nil
253
+ end
254
+ end
255
+
256
+ def clear_form_response(tag)
257
+ tag.locals.form_response.update_attribute('result', nil)
258
+ end
259
+
260
+ # takes object[key] or value
261
+ # Accesses the hash as hash[object][value]
262
+ # Accesses the value as hash[value]
263
+ def hash_retrieve(hash, array)
264
+ result = nil
265
+
266
+ unless hash.nil? or hash.empty?
267
+ data = array.gsub("[","|").gsub("]","").split("|") rescue nil
268
+
269
+ result = hash.fetch(data[0]) unless data.nil?
270
+ result = result.fetch(data[1]) unless data.nil? or data[1].nil?
271
+ end
272
+
273
+ result
274
+ end
275
+
276
+ end
277
+ end
@@ -0,0 +1,55 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :forms do
4
+
5
+ desc "Runs the migration of the Forms extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ FormsExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ Rake::Task['db:schema:dump'].invoke
11
+ else
12
+ FormsExtension.migrator.migrate
13
+ Rake::Task['db:schema:dump'].invoke
14
+ end
15
+ end
16
+
17
+ desc "Copies public assets of the Forms to the instance public/ directory."
18
+ task :update => :environment do
19
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
20
+ puts "Copying assets from FormsExtension"
21
+ Dir[FormsExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
22
+ path = file.sub(FormsExtension.root, '')
23
+ directory = File.dirname(path)
24
+ mkdir_p RAILS_ROOT + directory, :verbose => false
25
+ cp file, RAILS_ROOT + path, :verbose => false
26
+ end
27
+ unless FormsExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
28
+ puts "Copying rake tasks from FormsExtension"
29
+ local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
30
+ mkdir_p local_tasks_path, :verbose => false
31
+ Dir[File.join FormsExtension.root, %w(lib tasks *.rake)].each do |file|
32
+ cp file, local_tasks_path, :verbose => false
33
+ end
34
+ end
35
+ end
36
+
37
+ desc "Syncs all available translations for this ext to the English ext master"
38
+ task :sync => :environment do
39
+ # The main translation root, basically where English is kept
40
+ language_root = FormsExtension.root + "/config/locales"
41
+ words = TranslationSupport.get_translation_keys(language_root)
42
+
43
+ Dir["#{language_root}/*.yml"].each do |filename|
44
+ next if filename.match('_available_tags')
45
+ basename = File.basename(filename, '.yml')
46
+ puts "Syncing #{basename}"
47
+ (comments, other) = TranslationSupport.read_file(filename, basename)
48
+ words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
49
+ other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
50
+ TranslationSupport.write_file(filename, basename, comments, other)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,87 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{radiant-forms-extension}
8
+ s.version = "2.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["dirkkelly"]
12
+ s.date = %q{2010-08-02}
13
+ s.description = %q{Send data from a page to a form handler, extendable with addons}
14
+ s.email = %q{dirk.kelly@squaretalent.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.md",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "app/controllers/admin/forms_controller.rb",
24
+ "app/controllers/forms_controller.rb",
25
+ "app/models/form.rb",
26
+ "app/models/form_page.rb",
27
+ "app/models/response.rb",
28
+ "app/views/admin/forms/_fields.html.haml",
29
+ "app/views/admin/forms/_filters.html.haml",
30
+ "app/views/admin/forms/_form.html.haml",
31
+ "app/views/admin/forms/_header.html.haml",
32
+ "app/views/admin/forms/edit.html.haml",
33
+ "app/views/admin/forms/index.html.haml",
34
+ "app/views/admin/forms/new.html.haml",
35
+ "app/views/admin/forms/remove.html.haml",
36
+ "config/locales/en.yml",
37
+ "config/routes.rb",
38
+ "cucumber.yml",
39
+ "db/migrate/001_create_forms.rb",
40
+ "db/migrate/002_create_user_observer.rb",
41
+ "db/migrate/003_rename_output_to_content.rb",
42
+ "db/migrate/004_create_responses.rb",
43
+ "forms_extension.rb",
44
+ "lib/forms/admin_ui.rb",
45
+ "lib/forms/application_controller_extensions.rb",
46
+ "lib/forms/extension_methods.rb",
47
+ "lib/forms/page_extensions.rb",
48
+ "lib/forms/site_controller_extensions.rb",
49
+ "lib/forms/tags.rb",
50
+ "lib/tasks/forms_extension_tasks.rake",
51
+ "public/images/admin/extensions/form/form.png",
52
+ "radiant-forms-extension.gemspec",
53
+ "spec/controllers/forms_controller_spec.rb",
54
+ "spec/datasets/forms.rb",
55
+ "spec/lib/forms/extension_methods_spec.rb",
56
+ "spec/lib/forms/tags_spec.rb",
57
+ "spec/models/form_spec.rb",
58
+ "spec/models/response_spec.rb",
59
+ "spec/spec.opts",
60
+ "spec/spec_helper.rb"
61
+ ]
62
+ s.homepage = %q{http://github.com/squaretalent/radiant-forms-extension}
63
+ s.rdoc_options = ["--charset=UTF-8"]
64
+ s.require_paths = ["lib"]
65
+ s.rubygems_version = %q{1.3.5}
66
+ s.summary = %q{Forms Extension for Radiant CMS}
67
+ s.test_files = [
68
+ "spec/controllers/forms_controller_spec.rb",
69
+ "spec/datasets/forms.rb",
70
+ "spec/lib/forms/extension_methods_spec.rb",
71
+ "spec/lib/forms/tags_spec.rb",
72
+ "spec/models/form_spec.rb",
73
+ "spec/models/response_spec.rb",
74
+ "spec/spec_helper.rb"
75
+ ]
76
+
77
+ if s.respond_to? :specification_version then
78
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
79
+ s.specification_version = 3
80
+
81
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
82
+ else
83
+ end
84
+ else
85
+ end
86
+ end
87
+
@@ -0,0 +1,150 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe FormsController do
4
+ dataset :pages, :forms
5
+
6
+ context '#create' do
7
+
8
+ before :all do
9
+ @params = {
10
+ 'request' => 'test'
11
+ }
12
+ end
13
+
14
+ before :each do
15
+ @page = pages(:home)
16
+ @form = forms(:test)
17
+ mock(Page).find(anything) { @page }
18
+ mock(Form).find(anything) { @form }
19
+ end
20
+
21
+ context 'initialize' do
22
+
23
+ before :each do
24
+ post :create, @params
25
+ end
26
+
27
+ it 'should assign the page' do
28
+ assigns(:page).should == @page
29
+ end
30
+
31
+ it 'should assign the form' do
32
+ assigns(:form).should == @form
33
+ end
34
+
35
+ it 'should put the params into the page data' do
36
+ assigns(:page).data['request'].should == @params['request']
37
+ end
38
+
39
+ it 'should find/create a response object' do
40
+ assigns(:response).should be_an_instance_of(Response)
41
+ end
42
+
43
+ it 'should add the params to the response result' do
44
+ assigns(:response).result['request'].should == @params['request']
45
+ end
46
+
47
+ end
48
+
49
+ context 'configuration' do
50
+
51
+ before :each do
52
+ post :create, @params
53
+ end
54
+
55
+ context 'configuration exists' do
56
+
57
+ it 'should assign the configuration settings' do
58
+ assigns(:form)[:config][:test]['config'].should == 'test'
59
+ end
60
+
61
+ end
62
+
63
+ context 'configuration doesn\'t exist' do
64
+
65
+ before :each do
66
+ @form.config = nil
67
+ end
68
+
69
+ it 'should raise a form not configured exception' do
70
+ response.should raise_error
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+ context 'extensions' do
78
+
79
+ before :each do
80
+ post :create, @params
81
+ end
82
+
83
+ context 'extension configured' do
84
+
85
+ it 'should call that test extension' do
86
+ assigns(:response).result['test_ext'].should == { 'response' => 'test' }
87
+ end
88
+
89
+ it 'should not call the alt extension' do
90
+ assigns(:response).result['test_alt'].should be_nil
91
+ end
92
+
93
+ end
94
+
95
+ end
96
+
97
+ context 'response' do
98
+
99
+ context 'successfully save response' do
100
+
101
+ before :each do
102
+ stub(@response).save { true }
103
+ end
104
+
105
+ context 'form has a redirect url' do
106
+
107
+ before :each do
108
+ @form.redirect_to = '/redirect/url'
109
+ post :create, @params
110
+ end
111
+
112
+ it 'should redirect to the form redirect url' do
113
+ response.should redirect_to('/redirect/url')
114
+ end
115
+
116
+ end
117
+
118
+ context 'form does not have a redirect url' do
119
+
120
+ before :each do
121
+ @page.slug = '/page/url'
122
+ post :create, @params
123
+ end
124
+
125
+ it 'should render page url' do
126
+ response.should redirect_to(@page.url)
127
+ end
128
+
129
+ end
130
+
131
+ end
132
+
133
+ context 'cant save response' do
134
+
135
+ before :each do
136
+ stub(@response).save { false }
137
+ post :create, @params
138
+ end
139
+
140
+ it 'should raise a form not submitted exception' do
141
+ response.should raise_error
142
+ end
143
+
144
+ end
145
+
146
+ end
147
+
148
+ end
149
+
150
+ end
@@ -0,0 +1,30 @@
1
+ class FormsTestController
2
+ include Forms::ExtensionMethods
3
+ def create
4
+ result = { :response => 'test' }
5
+ end
6
+ end
7
+
8
+ class FormsAltController
9
+ include Forms::ExtensionMethods
10
+ def create
11
+ result = { :response => 'alt' }
12
+ end
13
+ end
14
+
15
+ class FormsDataset < Dataset::Base
16
+
17
+ def load
18
+ attributes = {
19
+ :title => "test_form",
20
+ :body => "<r:text name='request[test]' />",
21
+ :content => "<r:form:read name='request[test]' />",
22
+ :config => <<-CONFIG
23
+ test:
24
+ config: test
25
+ CONFIG
26
+ }
27
+ create_record :form, :test, attributes
28
+ end
29
+
30
+ end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Forms::ExtensionMethods do
4
+ dataset :forms, :pages
5
+
6
+ before :each do
7
+ @page = pages(:home)
8
+ @form = forms(:test)
9
+ end
10
+
11
+ context 'initializer' do
12
+
13
+ it 'should expect a form and page object' do
14
+ lambda { FormsTestController.new(@form, @page) }.should_not raise_error
15
+ end
16
+
17
+ end
18
+
19
+ context 'instance variables' do
20
+
21
+ before :each do
22
+ @forms_test = FormsTestController.new(@form, @page)
23
+ end
24
+
25
+ it 'should have a forms attribute' do
26
+ @forms_test.form.should be_an_instance_of(Form)
27
+ @forms_test.form.should == @form
28
+ end
29
+
30
+ it 'should have a page attribute' do
31
+ @forms_test.page.should be_an_instance_of(Page)
32
+ @forms_test.page.should == @page
33
+ end
34
+
35
+ it 'should have a data attribute' do
36
+ @forms_test.data.should == @page.data
37
+ end
38
+
39
+ end
40
+
41
+ end