noodall-form-builder 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,7 +26,7 @@ module Noodall
26
26
  end
27
27
  end
28
28
 
29
- flash[:notice] = 'Thank you for getting in contact.'
29
+ flash[:notice] = @form.thank_you_message
30
30
  format.html
31
31
  format.xml { render :xml => @form, :status => :created, :location => @form }
32
32
  else
@@ -3,11 +3,13 @@ module Noodall
3
3
  include MongoMapper::Document
4
4
  plugin MongoMapper::Plugins::MultiParameterAttributes
5
5
  plugin Noodall::GlobalUpdateTime
6
-
6
+
7
7
  key :title, String, :required => true
8
8
  key :description, String
9
9
  key :email, String, :format => /.+\@.+\..+/
10
-
10
+ key :thank_you_message, :default => 'Thank you for getting in contact.'
11
+ key :thank_you_email, :default => 'Thank you for getting in contact.'
12
+
11
13
  MANDATORY_FIELDS = ['Name','Email']
12
14
  many :fields, :class => Noodall::Field
13
15
  many :responses, :class => Noodall::FormResponse do
@@ -18,21 +20,21 @@ module Noodall
18
20
  self.select {|r| r.spaminess >= (self.class.defensio_config['spam_threshold'] || 0.75)}
19
21
  end
20
22
  end
21
-
23
+
22
24
  before_save :create_mandatory_fields!
23
-
25
+
24
26
  timestamps!
25
-
27
+
26
28
  validates_associated :fields, :message => "have not had a name completed"
27
-
29
+
28
30
  def boolean_fields
29
31
  self.fields.select{|f| f.class == Noodall::CheckBox }
30
32
  end
31
-
33
+
32
34
  def required_fields
33
35
  self.fields.select{|f| f.required }
34
36
  end
35
-
37
+
36
38
  def create_mandatory_fields!
37
39
  MANDATORY_FIELDS.each do |mf|
38
40
  if fields.blank? or fields.select{|f| f.name == mf }.empty?
@@ -40,6 +42,6 @@ module Noodall
40
42
  end
41
43
  end
42
44
  end
43
-
45
+
44
46
  end
45
- end
47
+ end
@@ -40,12 +40,11 @@ module Noodall
40
40
  def check_for_spam
41
41
  if self.defensio_signature.blank?
42
42
  status, response = self.class.defensio.post_document(self.defensio_attributes)
43
- Rails.logger.debug "Defensio said: #{response.inspect}"
44
43
  return unless status == 200
45
44
 
46
45
  self.defensio_signature = response['signature']
47
- self.spaminess = response['spaminess']
48
- self.approved = (response['spaminess'] < (self.class.defensio_config['spam_threshold'] || 0.75))
46
+ self.spaminess = response['spaminess'] || 0
47
+ self.approved = (spaminess < (self.class.defensio_config['spam_threshold'] || 0.75))
49
48
  end
50
49
  end
51
50
 
@@ -6,9 +6,7 @@
6
6
  <body>
7
7
  <p>Dear <%= "#{@response.name}" %>,</p>
8
8
 
9
- <p>Thank you for getting in contact.</p>
10
-
11
- <p>We will be in touch shortly.</p>
9
+ <%= simple_format(@form.thank_you_email) %>
12
10
 
13
11
  <p>Regards<br />
14
12
  <%= Noodall::UI.app_name %>
@@ -32,4 +30,4 @@ Subject: <%= "#{Noodall::UI.app_name}: Response to the #{@form.title} form." %><
32
30
  </tbody>
33
31
  </table>
34
32
  </body>
35
- </html>
33
+ </html>
@@ -20,7 +20,7 @@
20
20
  <% @responses.sort_by(&:created_at).reverse.each do |response| %>
21
21
  <tr id="form-<%= response.id %>" class="<%=cycle('odd', 'even')%>">
22
22
  <td class="edit"><%= mail_to response.email, h(response.name) %></td>
23
- <td><%= @form.fields.collect{|f| "<strong>#{f.name}:</strong> #{response.send(f.underscored_name)}" }.join(",&nbsp;").html_safe %></td>
23
+ <td><%= @form.fields.collect{|f| "<strong>#{f.name}:</strong> #{response.respond_to?(f.underscored_name) ? response.send(f.underscored_name) : ''}" }.join(",&nbsp;").html_safe %></td>
24
24
  <td><%= h response.created_at.to_formatted_s(:long_dot) %></td>
25
25
  <td><%= link_to 'Delete', noodall_admin_form_form_response_path(@form, response), :confirm => 'Are you sure?', :method => :delete, :class => 'delete', :title => 'Delete this response' %>
26
26
  <%= link_to 'Mark as Spam', mark_as_spam_noodall_admin_form_form_response_path(@form, response), :class => 'spam', :title => 'Mark this response as spam and delete' %></td>
@@ -24,6 +24,18 @@
24
24
  <span class="input-wrap"><%= f.text_field :email %></span>
25
25
  </p>
26
26
 
27
+ <p>
28
+ <span class="tooltip" title="Enter an message that will displayed once thet have submitted the form">&nbsp;</span>
29
+ <%= f.label :thank_you_message %><br/>
30
+ <span class="input-wrap"><%= f.text_area :thank_you_message, :rows => 3 %></span>
31
+ </p>
32
+
33
+ <p>
34
+ <span class="tooltip" title="Enter a message they will see in the thank you email">&nbsp;</span>
35
+ <%= f.label :thank_you_email %><br/>
36
+ <span class="input-wrap"><%= f.text_area :thank_you_email, :rows => 3 %></span>
37
+ </p>
38
+
27
39
  <div id="form-fields">
28
40
  <fieldset>
29
41
  <div id="content-table">
@@ -1,5 +1,5 @@
1
1
  <div id="main-content" class="no-nav">
2
- <h1><%=h @form.title %>: Thank you for your response</h1>
2
+ <h1>Thank you</h1>
3
3
 
4
- <p>We will be in touch soon.</p>
4
+ <%= simple_format(@form.thank_you_message) %>
5
5
  </div>
@@ -9,15 +9,17 @@ Feature: Form builder
9
9
  | Name |
10
10
  | Email |
11
11
  When I fill the following fields:
12
- | Field | Value |
13
- | Title | A Contact Form |
14
- | Description | So people can get in touch |
15
- | Email | hello@weaarebeef.co.uk |
12
+ | Field | Value |
13
+ | Title | A Contact Form |
14
+ | Description | So people can get in touch |
15
+ | Email | hello@weaarebeef.co.uk |
16
+ | Thank you message | Cheers then! |
17
+ | Thank you email | Thaanks for that |
16
18
  And I add the fields I want on the form
17
19
  And I press "Create"
18
20
  Then I should see the new form in the Form List
19
21
 
20
- @javscript @wip
22
+ @javascript
21
23
  Scenario Outline: Add fields
22
24
  Given I am creating a form
23
25
  When I select "<Field Type>" from "Add a new field"
@@ -31,7 +33,7 @@ Feature: Form builder
31
33
  | Radio | Name, Label, Default Option, Options, Required |
32
34
  | Check Box | Name, Label, Default state, Required |
33
35
 
34
- @javscript @wip
36
+ @javascript
35
37
  Scenario: Reorder fields
36
38
  Given a form exists with the following fields:
37
39
  | Name | Text Field |
@@ -43,7 +45,7 @@ Feature: Form builder
43
45
  Then the "Title" field should be at position 1
44
46
  When I click the "down" arrow next to "Email" once
45
47
  Then the "Email" field should be at position 4
46
- When I press "Save"
48
+ When I press "Update"
47
49
  And I view the form on the website
48
50
  Then I should see the fields in the order I set
49
51
 
@@ -53,7 +55,6 @@ Feature: Form builder
53
55
  And I click "Download Responses" on the forms row in the Form List
54
56
  Then I should receive a CSV file containing all the responses to that form
55
57
 
56
- @javscript @wip
57
58
  Scenario: Update an existing form with responses
58
59
  Given a form exists that has had many responses
59
60
  When I am editing the last form
@@ -38,3 +38,17 @@ Feature: Form Module
38
38
  Then it should be checked against the validation speficied in the form builder
39
39
  And it should be rejected if the the response does not meet the validation
40
40
  And the website visitor should see an error message
41
+
42
+ Scenario: Custom Thank You Messages
43
+ Given a form exists with the following:
44
+ | thank_you_message | Thanks for that |
45
+ | thank_you_email | Cheers then! |
46
+ When I view the form on the website
47
+ And I fill in the following:
48
+ | Name | Dave |
49
+ | Email | spoon@buttonmooon.com |
50
+ And I press "Send"
51
+ Then I should see "Thanks for that"
52
+ And "spoon@buttonmooon.com" should receive an email
53
+ When I open the email
54
+ Then I should see "Cheers then!" in the email body
@@ -192,7 +192,7 @@ end
192
192
  When /^a form response is deemed to be spam$/ do
193
193
  When %{a website visitor visits the content}
194
194
  defensio_dummy = double("defensio dummy")
195
- defensio_dummy.stub(:post_document){ [200, {:spaminess => 1}] }
195
+ defensio_dummy.stub(:post_document){ [200, {'spaminess' => 1}] }
196
196
 
197
197
  Noodall::FormResponse.stub(:defensio).and_return(defensio_dummy)
198
198
  When %{they fill in and submit the form}
@@ -229,18 +229,17 @@ end
229
229
 
230
230
  Then /^the "([^"]*)" field should be at position (\d+)$/ do |field, position|
231
231
  index = 0
232
- page.should have_selector('table.content tbody tr') do |fieldset|
232
+ all('table.content tbody tr').each do |fieldset|
233
233
  index = index+1
234
- puts fieldset.find('input[value=#{field}]').inspect
235
- return unless fieldset.find('input[value=#{field}]').nil?
234
+ break if fieldset.has_css?("input[value=#{field}]")
236
235
  end
237
-
236
+
238
237
  position.to_i.should == index
239
238
  end
240
239
 
241
240
  When /^I click the "([^\"]*)" arrow next to "([^\"]*)" once$/ do |arrow, field|
242
- page.should have_selector('table.content tbody tr') do |fieldset|
243
- click_link arrow if fieldset.find('input[value=#{field}]')
241
+ all('table.content tbody tr').each do |fieldset|
242
+ fieldset.find("a:contains('#{arrow}')").click if fieldset.has_css?("input[value=#{field}]")
244
243
  end
245
244
  end
246
245
 
@@ -252,9 +251,16 @@ When /^I view the form on the website$/ do
252
251
  end
253
252
 
254
253
  Then /^I should see the fields in the order I set$/ do
255
- pending # express the regexp above with the code you wish you had
254
+ within('div.form-wrap') do
255
+ page.should have_content("Title")
256
+ end
256
257
  end
257
258
 
258
259
  When /^I am editing the last form$/ do
259
260
  visit noodall_admin_form_path(Noodall::Form.last)
260
- end
261
+ end
262
+
263
+ Given /^a form exists with the following:$/ do |fields|
264
+ @_form = Factory(:form, fields.rows_hash)
265
+ end
266
+
@@ -0,0 +1,14 @@
1
+ Factory.factories.values.each do |factory|
2
+ if factory.build_class.respond_to?(:keys)
3
+ factory.build_class.keys.each_key do |key|
4
+ human_column_name = key.downcase.gsub('_', ' ')
5
+ Given /^an? #{factory.human_name} exists with an? #{human_column_name} of "([^"]*)"$/i do |value|
6
+ Factory(factory.factory_name, key => value)
7
+ end
8
+
9
+ Given /^(\d+) #{factory.human_name.pluralize} exist with an? #{human_column_name} of "([^"]*)"$/i do |count, value|
10
+ count.to_i.times { Factory(factory.factory_name, key => value) }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  module Noodall
2
2
  module FormBuilder
3
- VERSION = "0.0.10"
3
+ VERSION = "0.0.11"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noodall-form-builder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 10
10
- version: 0.0.10
9
+ - 11
10
+ version: 0.0.11
11
11
  platform: ruby
12
12
  authors: []
13
13
 
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-03 00:00:00 +00:00
18
+ date: 2011-02-16 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -110,6 +110,7 @@ files:
110
110
  - features/step_definitions/web_steps.rb
111
111
  - features/support/defensio_mock.rb
112
112
  - features/support/env.rb
113
+ - features/support/mm_factory_steps.rb
113
114
  - features/support/paths.rb
114
115
  - lib/noodall-form-builder.rb
115
116
  - lib/noodall/form_builder/engine.rb