noodall-form-builder 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,7 +18,9 @@ module Noodall
18
18
  respond_to do |format|
19
19
  if @form_response.valid? and @form_response.save
20
20
 
21
- unless @form_response.is_spam?
21
+ if @form_response.is_spam?
22
+ logger.info "Form response was deemed to be spam: #{@form_response.inspect}"
23
+ else
22
24
  begin
23
25
  # mail the response to the form recipient
24
26
  FormMailer.form_response(@form, @form_response).deliver unless @form.email.blank?
@@ -1,6 +1,6 @@
1
1
  module Noodall
2
2
  class FormResponse
3
- include MongoMapper::EmbeddedDocument
3
+ include MongoMapper::Document
4
4
 
5
5
  key :name, String
6
6
  key :email, String, :format => /.+\@.+\..+/
@@ -11,14 +11,14 @@ module Noodall
11
11
  key :defensio_signature, String
12
12
  key :spaminess, Float, :default => 0
13
13
 
14
- def required_fields
15
- self.form.fields.select{ |f| f.required? }
16
- end
17
-
18
14
  before_save :check_for_spam
19
15
  attr_protected :approved
20
16
 
21
- embedded_in :form
17
+ belongs_to :form, :class => Noodall::Form, :foreign_key => 'noodall_form_id'
18
+
19
+ def required_fields
20
+ self.form.fields.select{ |f| f.required? }
21
+ end
22
22
 
23
23
  def approve!
24
24
  self.approved = true
@@ -41,9 +41,9 @@ module Noodall
41
41
  value = self.send(name)
42
42
 
43
43
  if value.is_a?(Array)
44
- "[#{value.join(', ')}]"
44
+ value.join(', ')
45
45
  else
46
- "Val: #{value}"
46
+ value.to_s
47
47
  end
48
48
  end
49
49
 
@@ -54,8 +54,8 @@ module Noodall
54
54
  return unless status == 200
55
55
 
56
56
  self.defensio_signature = response['signature']
57
- self.spaminess = response['spaminess'] || 0
58
- self.approved = response['allow'] || false
57
+ self.spaminess = response['spaminess']
58
+ self.approved = response['allow']
59
59
  end
60
60
  end
61
61
 
@@ -53,13 +53,9 @@ end
53
53
 
54
54
  Given /^a form exists that has had many responses$/ do
55
55
  form = Factory(:form)
56
-
57
- responses = []
58
- 9.times do |i|
59
- responses << Factory(:response)
56
+ 9.times do
57
+ Factory(:response, :form => form)
60
58
  end
61
- form.responses = responses
62
- form.save!
63
59
  end
64
60
 
65
61
  When /^I click "([^\"]*)" on the forms row in the Form List$/ do |arg1|
@@ -192,7 +188,7 @@ end
192
188
  When /^a form response is deemed to be spam$/ do
193
189
  When %{a website visitor visits the content}
194
190
  defensio_dummy = double("defensio dummy")
195
- defensio_dummy.stub(:post_document){ [200, {'spaminess' => 1}] }
191
+ defensio_dummy.stub(:post_document){ [200, {'spaminess' => 1, "allow" => false}] }
196
192
 
197
193
  Noodall::FormResponse.stub(:defensio).and_return(defensio_dummy)
198
194
  When %{they fill in and submit the form}
@@ -1,6 +1,8 @@
1
1
  Before do
2
2
  defensio_dummy = double("defensio dummy")
3
- defensio_dummy.stub(:post_document){ [200, {:spaminess => 0.2}] }
3
+ defensio_dummy.stub(:post_document) do
4
+ [200, {"spaminess" => 0.2, "allow" => true}]
5
+ end
4
6
 
5
7
  Noodall::FormResponse.stub(:defensio).and_return(defensio_dummy)
6
8
  end
@@ -49,4 +49,5 @@ Factory.find_definitions
49
49
 
50
50
  require 'factory_girl/step_definitions'
51
51
  require 'csv' #for checking CSV content
52
+ require 'ruby-debug'
52
53
 
@@ -1,5 +1,5 @@
1
1
  module Noodall
2
2
  module FormBuilder
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
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: 29
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors: []
13
13
 
@@ -15,11 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-16 00:00:00 +00:00
18
+ date: 2011-04-20 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ name: bundler
23
+ prerelease: false
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
25
  none: false
24
26
  requirements:
25
27
  - - ">="
@@ -30,12 +32,12 @@ dependencies:
30
32
  - 0
31
33
  - 0
32
34
  version: 1.0.0
33
- name: bundler
34
- prerelease: false
35
- version_requirements: *id001
36
35
  type: :development
36
+ requirement: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- requirement: &id002 !ruby/object:Gem::Requirement
38
+ name: fastercsv
39
+ prerelease: false
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
41
  none: false
40
42
  requirements:
41
43
  - - ">="
@@ -44,10 +46,8 @@ dependencies:
44
46
  segments:
45
47
  - 0
46
48
  version: "0"
47
- name: fastercsv
48
- prerelease: false
49
- version_requirements: *id002
50
49
  type: :runtime
50
+ requirement: *id002
51
51
  description: Functionality for building custom forms
52
52
  email: []
53
53