noodall-form-builder 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +24 -0
- data/Gemfile.lock +202 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +39 -0
- data/app/controllers/noodall/admin/fields_controller.rb +21 -0
- data/app/controllers/noodall/admin/form_responses_controller.rb +75 -0
- data/app/controllers/noodall/admin/forms_controller.rb +97 -0
- data/app/controllers/noodall/form_responses_controller.rb +39 -0
- data/app/helpers/admin/forms_helper.rb +2 -0
- data/app/helpers/forms_helper.rb +11 -0
- data/app/mailers/form_mailer.rb +21 -0
- data/app/models/contact_form.rb +16 -0
- data/app/models/noodall/check_box.rb +5 -0
- data/app/models/noodall/field.rb +25 -0
- data/app/models/noodall/form.rb +38 -0
- data/app/models/noodall/form_response.rb +88 -0
- data/app/models/noodall/radio.rb +4 -0
- data/app/models/noodall/select.rb +5 -0
- data/app/models/noodall/text_field.rb +12 -0
- data/app/views/admin/components/_contact_form.html.erb +11 -0
- data/app/views/components/_contact_form.html.erb +8 -0
- data/app/views/form_mailer/_form_response_fields.html.erb +3 -0
- data/app/views/form_mailer/form_response.html.erb +5 -0
- data/app/views/form_mailer/form_response_thankyou.html.erb +19 -0
- data/app/views/noodall/admin/fields/_check_box.html.erb +14 -0
- data/app/views/noodall/admin/fields/_radio.html.erb +14 -0
- data/app/views/noodall/admin/fields/_select.html.erb +14 -0
- data/app/views/noodall/admin/fields/_text_field.html.erb +26 -0
- data/app/views/noodall/admin/form_responses/index.csv.csvbuilder +12 -0
- data/app/views/noodall/admin/form_responses/index.html.erb +41 -0
- data/app/views/noodall/admin/forms/_field_select.html.erb +11 -0
- data/app/views/noodall/admin/forms/index.html.erb +41 -0
- data/app/views/noodall/admin/forms/show.html.erb +138 -0
- data/app/views/noodall/form_responses/_form.html.erb +45 -0
- data/app/views/noodall/form_responses/create.html.erb +5 -0
- data/app/views/noodall/form_responses/new.html.erb +5 -0
- data/app/views/noodall/forms/edit.html.erb +12 -0
- data/app/views/noodall/forms/index.html.erb +18 -0
- data/app/views/noodall/forms/new.html.erb +11 -0
- data/app/views/noodall/forms/show.html.erb +3 -0
- data/cucumber.yml +8 -0
- data/features/form_builder.feature +54 -0
- data/features/form_module.feature +40 -0
- data/features/step_definitions/cms_node_steps.rb +126 -0
- data/features/step_definitions/component_steps.rb +138 -0
- data/features/step_definitions/email_steps.rb +182 -0
- data/features/step_definitions/form_builder_steps.rb +247 -0
- data/features/step_definitions/sign_in_steps.rb +48 -0
- data/features/step_definitions/web_steps.rb +219 -0
- data/features/support/defensio_mock.rb +6 -0
- data/features/support/env.rb +52 -0
- data/features/support/paths.rb +60 -0
- data/lib/noodall/form_builder/engine.rb +13 -0
- data/lib/noodall/form_builder/routes.rb +35 -0
- data/lib/noodall/form_builder/version.rb +5 -0
- data/lib/noodall-form-builder.rb +1 -0
- data/noodall-form-builder.gemspec +23 -0
- data/public/images/admin/spam.png +0 -0
- data/public/javascripts/admin/formbuilder.js +52 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +22 -0
- data/spec/dummy/app/helpers/application_helper.rb +8 -0
- data/spec/dummy/app/models/page_a.rb +8 -0
- data/spec/dummy/app/models/user.rb +14 -0
- data/spec/dummy/app/views/admin/nodes/_page_a.html.erb +47 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/nodes/page_a.html.erb +14 -0
- data/spec/dummy/config/application.rb +46 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +12 -0
- data/spec/dummy/config/defensio.yml +16 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/dragonfly.rb +1 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/mongo_mapper.rb +13 -0
- data/spec/dummy/config/initializers/noodall.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/asset.rb +6 -0
- data/spec/factories/contact_form.rb +3 -0
- data/spec/factories/field.rb +15 -0
- data/spec/factories/form.rb +13 -0
- data/spec/factories/node.rb +5 -0
- data/spec/factories/response.rb +7 -0
- data/spec/factories/user.rb +15 -0
- data/spec/files/beef.png +0 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/noodall_form_builder_spec.rb +7 -0
- data/spec/spec_helper.rb +30 -0
- metadata +204 -0
@@ -0,0 +1,247 @@
|
|
1
|
+
When /^I visit the form builder admin page$/ do
|
2
|
+
visit noodall_admin_forms_path
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^I should see a form with at least the following fields:$/ do |table|
|
6
|
+
table.rows.each do |row|
|
7
|
+
page.should have_selector("input[value='#{row[0]}']")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
When /^I fill the following fields:$/ do |table|
|
12
|
+
table.rows.each do |row|
|
13
|
+
@new_form_name = row[1] if @new_form_name.nil?
|
14
|
+
fill_in row[0], :with => row[1]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
When /^I add the fields I want on the form$/ do
|
19
|
+
# Some selenium dodads here
|
20
|
+
|
21
|
+
# 5.times do |i|
|
22
|
+
# #get index of new fieldset
|
23
|
+
# index = 1
|
24
|
+
# response.should have_selector('#form-fields fieldset') do |fieldset|
|
25
|
+
# index += 1
|
26
|
+
# end
|
27
|
+
# click_link_within 'div#main-form', 'Add'
|
28
|
+
# save_and_open_page
|
29
|
+
#
|
30
|
+
# within "fieldset#field-#{index}" do |fieldset|
|
31
|
+
# fieldset.fill_in 'Name', :with => "Field #{i}"
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
end
|
35
|
+
|
36
|
+
Then /^I should see the new form in the Form List$/ do
|
37
|
+
page.should have_content(@new_form_name)
|
38
|
+
end
|
39
|
+
|
40
|
+
Given /^I am creating a form$/ do
|
41
|
+
visit new_noodall_admin_form_path
|
42
|
+
end
|
43
|
+
|
44
|
+
Then /^I should see a new field with the options "([^\"]*)"$/ do |arg1|
|
45
|
+
#get index of new fieldset
|
46
|
+
index = 0
|
47
|
+
page.should have_selector('#form-fields fieldset') do |fieldset|
|
48
|
+
index += 1
|
49
|
+
end
|
50
|
+
|
51
|
+
page.should have_selector("fieldset#field-#{index}")
|
52
|
+
end
|
53
|
+
|
54
|
+
Given /^a form exists that has had many responses$/ do
|
55
|
+
form = Factory(:form)
|
56
|
+
|
57
|
+
responses = []
|
58
|
+
9.times do |i|
|
59
|
+
responses << Factory(:response)
|
60
|
+
end
|
61
|
+
form.responses = responses
|
62
|
+
form.save!
|
63
|
+
end
|
64
|
+
|
65
|
+
When /^I click "([^\"]*)" on the forms row in the Form List$/ do |arg1|
|
66
|
+
within('#content-table table tbody tr:first-child') do
|
67
|
+
click_link arg1
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
Then /^I should receive a CSV file containing all the responses to that form$/ do
|
72
|
+
CSV.parse(page.body).should have(10).things # 9 rows plus header
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
Given /^forms have been created with the form builder$/ do
|
77
|
+
5.times do
|
78
|
+
Factory(:form)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
Then /^I should see a form select element containing the exisitng forms$/ do
|
83
|
+
Noodall::Form.all.each do |form|
|
84
|
+
page.should have_selector("select#node_wide_slot_0_form_id option:contains('#{form.title}')")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
When /^I select a form$/ do
|
89
|
+
@_form = Noodall::Form.first
|
90
|
+
select @_form.title, :from => 'Form'
|
91
|
+
end
|
92
|
+
|
93
|
+
Then /^I should see the form I selected$/ do
|
94
|
+
@_form.fields.each do |field|
|
95
|
+
page.should have_selector("label[for=form_response_#{field.underscored_name}]")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
Given /^a form exists$/ do
|
100
|
+
Factory(:form)
|
101
|
+
end
|
102
|
+
|
103
|
+
Given /^content exists with a form added via the contact module$/ do
|
104
|
+
@_node = Factory(:page_a)
|
105
|
+
@_form = Factory(:form)
|
106
|
+
@_node.wide_slot_0 = Factory(:contact_form, :form_id => @_form.id)
|
107
|
+
@_node.save
|
108
|
+
end
|
109
|
+
|
110
|
+
When /^a website visitor visits the content$/ do
|
111
|
+
visit node_path(@_node)
|
112
|
+
end
|
113
|
+
|
114
|
+
Then /^they should see the form$/ do
|
115
|
+
Then %{I should see the form I selected}
|
116
|
+
end
|
117
|
+
|
118
|
+
When /^they fill in and submit the form$/ do
|
119
|
+
@_form = Noodall::Form.find(@_node.wide_slot_0.form_id)
|
120
|
+
@_form.fields.each do |field|
|
121
|
+
if field.name == 'Email'
|
122
|
+
fill_in "form_response[#{field.underscored_name}]", :with => 'hello@example.com'
|
123
|
+
else
|
124
|
+
fill_in "form_response[#{field.underscored_name}]", :with => 'Weopunggggggggst'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
When %{they submit the form}
|
129
|
+
end
|
130
|
+
|
131
|
+
Then /^the email address of the form should receive an email detailing the information submitted$/ do
|
132
|
+
Then %{"#{@_form.email}" should receive an email}
|
133
|
+
@_form.fields do |field|
|
134
|
+
Then %{they should see "#{field.name}:" in the email body}
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
Then /^they should receive an email confirming the request has been sent$/ do
|
139
|
+
Then %{"hello@example.com" should receive an email}
|
140
|
+
@_form.fields do |field|
|
141
|
+
Then %{they should see "#{field.name}:" in the email body}
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
Then /^the response should be stored in the database along with the time submitted, IP address, and page it was submitted from$/ do
|
146
|
+
@_form.reload
|
147
|
+
@response = @_form.responses.last
|
148
|
+
|
149
|
+
@response.created_at.should_not be nil
|
150
|
+
@response.ip.should == '127.0.0.1'
|
151
|
+
@response.referrer.should == node_url(@_node)
|
152
|
+
end
|
153
|
+
|
154
|
+
Then /^it should be checked by a spam filter$/ do
|
155
|
+
#err
|
156
|
+
end
|
157
|
+
|
158
|
+
Then /^it should be rejected if the spam filter deems the response to be spam$/ do
|
159
|
+
within('form #errorExplanation') do
|
160
|
+
page.should have_content('spam')
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
Then /^the website visitor should see an spam message$/ do
|
165
|
+
Then %{it should be rejected if the spam filter deems the response to be spam}
|
166
|
+
end
|
167
|
+
|
168
|
+
Then /^it should be checked against the validation speficied in the form builder$/ do
|
169
|
+
@_form.required_fields.each do |field|
|
170
|
+
within('#errorExplanation') do
|
171
|
+
page.should have_content(field.name)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
Then /^it should be rejected if the the response does not meet the validation$/ do
|
177
|
+
Then %{it should be checked against the validation speficied in the form builder}
|
178
|
+
end
|
179
|
+
|
180
|
+
Then /^the website visitor should see an error message$/ do
|
181
|
+
page.should have_selector('form #errorExplanation')
|
182
|
+
end
|
183
|
+
|
184
|
+
When /^a website visitor fills in and submits a form$/ do
|
185
|
+
When %{they fill in and submit the form}
|
186
|
+
end
|
187
|
+
|
188
|
+
When /^they submit the form$/ do
|
189
|
+
click_button 'Send'
|
190
|
+
end
|
191
|
+
|
192
|
+
When /^a form response is deemed to be spam$/ do
|
193
|
+
When %{a website visitor visits the content}
|
194
|
+
defensio_dummy = double("defensio dummy")
|
195
|
+
defensio_dummy.stub(:post_document){ [200, {:spaminess => 1}] }
|
196
|
+
|
197
|
+
Noodall::FormResponse.stub(:defensio).and_return(defensio_dummy)
|
198
|
+
When %{they fill in and submit the form}
|
199
|
+
end
|
200
|
+
|
201
|
+
Then /^it should marked as spam$/ do
|
202
|
+
Noodall::Form.last.responses.last.approved.should == false
|
203
|
+
end
|
204
|
+
|
205
|
+
When /^I click "([^"]*)"$/ do |arg1|
|
206
|
+
click_link(arg1)
|
207
|
+
end
|
208
|
+
|
209
|
+
Given /^a form exists with the following fields:$/ do |table|
|
210
|
+
fields = table.rows_hash.map do |name, type|
|
211
|
+
factory, opts = type.split(': ')
|
212
|
+
if opts.blank?
|
213
|
+
Factory(factory.parameterize('_'), :name => name)
|
214
|
+
else
|
215
|
+
Factory(factory.parameterize('_'), :name => name, :options => opts)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
@_form = Factory(:form, :fields => fields)
|
219
|
+
end
|
220
|
+
|
221
|
+
When /^I am editing the form$/ do
|
222
|
+
visit noodall_admin_form_path(@_form)
|
223
|
+
end
|
224
|
+
|
225
|
+
When /^I click the "([^"]*)" arrow next to "([^"]*)" twice$/ do |arg1, arg2|
|
226
|
+
pending # express the regexp above with the code you wish you had
|
227
|
+
end
|
228
|
+
|
229
|
+
Then /^the "([^"]*)" field should be at position (\d+)$/ do |arg1, arg2|
|
230
|
+
pending # express the regexp above with the code you wish you had
|
231
|
+
end
|
232
|
+
|
233
|
+
When /^I click the "([^"]*)" arrow next to "([^"]*)" once$/ do |arg1, arg2|
|
234
|
+
pending # express the regexp above with the code you wish you had
|
235
|
+
end
|
236
|
+
|
237
|
+
When /^I view the form on the website$/ do
|
238
|
+
@_node = Factory(:page_a)
|
239
|
+
@_node.wide_slot_0 = Factory(:contact_form, :form_id => @_form.id)
|
240
|
+
@_node.save
|
241
|
+
When %{a website visitor visits the content}
|
242
|
+
end
|
243
|
+
|
244
|
+
Then /^I should see the fields in the order I set$/ do
|
245
|
+
pending # express the regexp above with the code you wish you had
|
246
|
+
end
|
247
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
Given /^I am signed in(?: as an? (.*))?$/ do |role|
|
2
|
+
role ||= 'user'
|
3
|
+
role = role.strip.gsub(/\W/,'_')
|
4
|
+
|
5
|
+
user = Factory(role)
|
6
|
+
Given %{I sign in as "#{user.email}/#{user.password}"}
|
7
|
+
end
|
8
|
+
|
9
|
+
Then /^I should see a list of users$/ do
|
10
|
+
page.should have_css('tbody tr', :count => 20)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Database
|
14
|
+
|
15
|
+
Given /^a user exists with the attrubutes:$/ do |fields|
|
16
|
+
user = Factory :user, fields.rows_hash
|
17
|
+
end
|
18
|
+
|
19
|
+
Given /^I sign in as a (.+)$/ do |role|
|
20
|
+
user = create_model(role).first
|
21
|
+
user.confirm_email!
|
22
|
+
Given %{I sign in as "#{user.email}\/#{user.password}"}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Actions
|
26
|
+
|
27
|
+
When /^I sign in as "(.*)\/(.*)"$/ do |email, password|
|
28
|
+
When %{I go to the sign in page}
|
29
|
+
And %{I fill in "user_email" with "#{email}"}
|
30
|
+
And %{I fill in "user_password" with "#{password}"}
|
31
|
+
And %{I press "Sign in"}
|
32
|
+
end
|
33
|
+
|
34
|
+
When /^I sign out$/ do
|
35
|
+
visit destroy_user_session_path
|
36
|
+
end
|
37
|
+
|
38
|
+
Then /^the user should (not )?be able to sign in as "(.*)\/(.*)"$/ do |yes_no, email, password|
|
39
|
+
Given %{I sign out}
|
40
|
+
And %{I sign in as "#{email}/#{password}"}
|
41
|
+
if yes_no.blank?
|
42
|
+
Then %{I should see "Signed in successfully"}
|
43
|
+
else
|
44
|
+
Then %{I should see "Invalid email or password."}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
@@ -0,0 +1,219 @@
|
|
1
|
+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
2
|
+
# It is recommended to regenerate this file in the future when you upgrade to a
|
3
|
+
# newer version of cucumber-rails. Consider adding your own code to a new file
|
4
|
+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
5
|
+
# files.
|
6
|
+
|
7
|
+
|
8
|
+
require 'uri'
|
9
|
+
require 'cgi'
|
10
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
11
|
+
|
12
|
+
module WithinHelpers
|
13
|
+
def with_scope(locator)
|
14
|
+
locator ? within(locator) { yield } : yield
|
15
|
+
end
|
16
|
+
end
|
17
|
+
World(WithinHelpers)
|
18
|
+
|
19
|
+
Given /^(?:|I )am on (.+)$/ do |page_name|
|
20
|
+
visit path_to(page_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
When /^(?:|I )go to (.+)$/ do |page_name|
|
24
|
+
visit path_to(page_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
|
28
|
+
with_scope(selector) do
|
29
|
+
click_button(button)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
|
34
|
+
with_scope(selector) do
|
35
|
+
click_link(link)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
|
40
|
+
with_scope(selector) do
|
41
|
+
fill_in(field, :with => value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
|
46
|
+
with_scope(selector) do
|
47
|
+
fill_in(field, :with => value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Use this to fill in an entire form with data from a table. Example:
|
52
|
+
#
|
53
|
+
# When I fill in the following:
|
54
|
+
# | Account Number | 5002 |
|
55
|
+
# | Expiry date | 2009-11-01 |
|
56
|
+
# | Note | Nice guy |
|
57
|
+
# | Wants Email? | |
|
58
|
+
#
|
59
|
+
# TODO: Add support for checkbox, select og option
|
60
|
+
# based on naming conventions.
|
61
|
+
#
|
62
|
+
When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
|
63
|
+
with_scope(selector) do
|
64
|
+
fields.rows_hash.each do |name, value|
|
65
|
+
When %{I fill in "#{name}" with "#{value}"}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
|
71
|
+
with_scope(selector) do
|
72
|
+
select(value, :from => field)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
|
77
|
+
with_scope(selector) do
|
78
|
+
check(field)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
|
83
|
+
with_scope(selector) do
|
84
|
+
uncheck(field)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
|
89
|
+
with_scope(selector) do
|
90
|
+
choose(field)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
|
95
|
+
with_scope(selector) do
|
96
|
+
attach_file(field, path)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
Then /^(?:|I )should see JSON:$/ do |expected_json|
|
101
|
+
require 'json'
|
102
|
+
expected = JSON.pretty_generate(JSON.parse(expected_json))
|
103
|
+
actual = JSON.pretty_generate(JSON.parse(response.body))
|
104
|
+
expected.should == actual
|
105
|
+
end
|
106
|
+
|
107
|
+
Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
|
108
|
+
with_scope(selector) do
|
109
|
+
if page.respond_to? :should
|
110
|
+
page.should have_content(text)
|
111
|
+
else
|
112
|
+
assert page.has_content?(text)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
|
118
|
+
regexp = Regexp.new(regexp)
|
119
|
+
with_scope(selector) do
|
120
|
+
if page.respond_to? :should
|
121
|
+
page.should have_xpath('//*', :text => regexp)
|
122
|
+
else
|
123
|
+
assert page.has_xpath?('//*', :text => regexp)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
|
129
|
+
with_scope(selector) do
|
130
|
+
if page.respond_to? :should
|
131
|
+
page.should have_no_content(text)
|
132
|
+
else
|
133
|
+
assert page.has_no_content?(text)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
|
139
|
+
regexp = Regexp.new(regexp)
|
140
|
+
with_scope(selector) do
|
141
|
+
if page.respond_to? :should
|
142
|
+
page.should have_no_xpath('//*', :text => regexp)
|
143
|
+
else
|
144
|
+
assert page.has_no_xpath?('//*', :text => regexp)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
|
150
|
+
with_scope(selector) do
|
151
|
+
field = find_field(field)
|
152
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
153
|
+
if field_value.respond_to? :should
|
154
|
+
field_value.should =~ /#{value}/
|
155
|
+
else
|
156
|
+
assert_match(/#{value}/, field_value)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
|
162
|
+
with_scope(selector) do
|
163
|
+
field = find_field(field)
|
164
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
165
|
+
if field_value.respond_to? :should_not
|
166
|
+
field_value.should_not =~ /#{value}/
|
167
|
+
else
|
168
|
+
assert_no_match(/#{value}/, field_value)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
|
174
|
+
with_scope(selector) do
|
175
|
+
field_checked = find_field(label)['checked']
|
176
|
+
if field_checked.respond_to? :should
|
177
|
+
field_checked.should be_true
|
178
|
+
else
|
179
|
+
assert field_checked
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
|
185
|
+
with_scope(selector) do
|
186
|
+
field_checked = find_field(label)['checked']
|
187
|
+
if field_checked.respond_to? :should
|
188
|
+
field_checked.should be_false
|
189
|
+
else
|
190
|
+
assert !field_checked
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
196
|
+
current_path = URI.parse(current_url).path
|
197
|
+
if current_path.respond_to? :should
|
198
|
+
current_path.should == path_to(page_name)
|
199
|
+
else
|
200
|
+
assert_equal path_to(page_name), current_path
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
205
|
+
query = URI.parse(current_url).query
|
206
|
+
actual_params = query ? CGI.parse(query) : {}
|
207
|
+
expected_params = {}
|
208
|
+
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
|
209
|
+
|
210
|
+
if actual_params.respond_to? :should
|
211
|
+
actual_params.should == expected_params
|
212
|
+
else
|
213
|
+
assert_equal expected_params, actual_params
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
Then /^show me the page$/ do
|
218
|
+
save_and_open_page
|
219
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
2
|
+
# It is recommended to regenerate this file in the future when you upgrade to a
|
3
|
+
# newer version of cucumber-rails. Consider adding your own code to a new file
|
4
|
+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
5
|
+
# files.
|
6
|
+
|
7
|
+
ENV["RAILS_ENV"] ||= "test"
|
8
|
+
require File.expand_path("../../../spec/dummy/config/environment.rb", __FILE__)
|
9
|
+
|
10
|
+
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
|
11
|
+
require 'cucumber/rails/rspec'
|
12
|
+
require 'cucumber/rails/world'
|
13
|
+
require 'email_spec/cucumber'
|
14
|
+
require 'cucumber/web/tableish'
|
15
|
+
require 'cucumber/rspec/doubles'
|
16
|
+
|
17
|
+
require 'capybara/rails'
|
18
|
+
require 'capybara/cucumber'
|
19
|
+
require 'capybara/session'
|
20
|
+
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
|
21
|
+
# order to ease the transition to Capybara we set the default here. If you'd
|
22
|
+
# prefer to use XPath just remove this line and adjust any selectors in your
|
23
|
+
# steps to use the XPath syntax.
|
24
|
+
Capybara.default_selector = :css
|
25
|
+
|
26
|
+
# If you set this to false, any error raised from within your app will bubble
|
27
|
+
# up to your step definition and out to cucumber unless you catch it somewhere
|
28
|
+
# on the way. You can make Rails rescue errors and render error pages on a
|
29
|
+
# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
|
30
|
+
#
|
31
|
+
# If you set this to true, Rails will rescue all errors and render error
|
32
|
+
# pages, more or less in the same way your application would behave in the
|
33
|
+
# default production environment. It's not recommended to do this for all
|
34
|
+
# of your scenarios, as this makes it hard to discover errors in your application.
|
35
|
+
ActionController::Base.allow_rescue = false
|
36
|
+
|
37
|
+
# How to clean your database when transactions are turned off. See
|
38
|
+
# http://github.com/bmabey/database_cleaner for more info.
|
39
|
+
require 'database_cleaner'
|
40
|
+
require 'database_cleaner/cucumber'
|
41
|
+
DatabaseCleaner.strategy = :truncation
|
42
|
+
|
43
|
+
require 'factory_girl'
|
44
|
+
|
45
|
+
Factory.definition_file_paths = [
|
46
|
+
File.expand_path("../../../spec/factories", __FILE__)
|
47
|
+
]
|
48
|
+
Factory.find_definitions
|
49
|
+
|
50
|
+
require 'factory_girl/step_definitions'
|
51
|
+
require 'csv' #for checking CSV content
|
52
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'noodall/permalinks'
|
2
|
+
|
3
|
+
module NavigationHelpers
|
4
|
+
# Maps a name to a path. Used by the
|
5
|
+
#
|
6
|
+
# When /^I go to (.+)$/ do |page_name|
|
7
|
+
#
|
8
|
+
# step definition in web_steps.rb
|
9
|
+
#
|
10
|
+
def path_to(page_name)
|
11
|
+
case page_name
|
12
|
+
|
13
|
+
when /the (home\s?page|website)/i
|
14
|
+
root_path
|
15
|
+
when /the CMS/
|
16
|
+
'/admin'
|
17
|
+
when /the sign in page/
|
18
|
+
new_user_session_path
|
19
|
+
when /^the (?:root )?content titled "([^\"]*)" page$/i
|
20
|
+
node = Node.find_by_title($1)
|
21
|
+
node_path(node)
|
22
|
+
when /^the content admin page$/
|
23
|
+
noodall_admin_nodes_path
|
24
|
+
when /^the site ?map page$/
|
25
|
+
noodall_sitemap_path
|
26
|
+
when /^a page that's content is in the "([^\"]*)" template$/
|
27
|
+
node = Node.first(:_type => $1.gsub(' ',''), :order => 'created_at DESC')
|
28
|
+
node_path(node)
|
29
|
+
when /^a page that's content is in the "([^\"]*)" template that does not have published children$/
|
30
|
+
node = Factory($1.gsub(' ','_').tableize.singularize, :publish => true)
|
31
|
+
node.children.each{|c| c.destroy }
|
32
|
+
node_path(node)
|
33
|
+
when /^a page that's content is in the "([^\"]*)" template that has published children$/
|
34
|
+
node = Factory($1.gsub(' ','_').tableize.singularize, :publish => true)
|
35
|
+
3.times do
|
36
|
+
Factory(:page_a, :publish => true, :parent => node)
|
37
|
+
end
|
38
|
+
node_path(node)
|
39
|
+
when /^that page$/
|
40
|
+
node_path(@_content)
|
41
|
+
|
42
|
+
when /^the article list page$/
|
43
|
+
node_path(@_content)
|
44
|
+
when /content titled "([^\"]*)"$/
|
45
|
+
node_path(Node.find_by_title($1))
|
46
|
+
else
|
47
|
+
begin
|
48
|
+
page_name =~ /the (.*) page/
|
49
|
+
path_components = $1.split(/\s+/)
|
50
|
+
self.send(path_components.push('path').join('_').to_sym)
|
51
|
+
rescue Object => e
|
52
|
+
raise "Can't find a mapping from \"#{page_name}\" to a path.\n" +
|
53
|
+
"Please add one to #{__FILE__}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
World(NavigationHelpers)
|
60
|
+
World(Noodall::Permalinks)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Noodall
|
2
|
+
module FormBuilder
|
3
|
+
class Engine < Rails::Engine
|
4
|
+
initializer "set menu" do |app|
|
5
|
+
Noodall::UI.menu_items['Forms'] = :noodall_admin_forms_path
|
6
|
+
end
|
7
|
+
|
8
|
+
initializer "static assets" do |app|
|
9
|
+
app.middleware.use ::ActionDispatch::Static, "#{root}/public"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Noodall
|
2
|
+
module FormBuilder
|
3
|
+
class Routes
|
4
|
+
class << self
|
5
|
+
def draw(app)
|
6
|
+
app.routes.draw do
|
7
|
+
|
8
|
+
namespace 'noodall', :as => 'noodall', :path => '' do
|
9
|
+
resources :forms do
|
10
|
+
resources :form_responses
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
namespace 'noodall/admin', :as => 'noodall_admin', :path => 'admin' do
|
15
|
+
resources :forms do
|
16
|
+
resources :form_responses do
|
17
|
+
member do
|
18
|
+
get :mark_as_spam
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
resources :fields do
|
24
|
+
collection do
|
25
|
+
get :form
|
26
|
+
end
|
27
|
+
end
|
28
|
+
match 'components/form/:type' => 'components#form'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'noodall/form_builder/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|