noodall-form-builder 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/Gemfile +12 -11
  2. data/README.rdoc +23 -2
  3. data/app/assets/javascripts/admin/formbuilder.js +1 -1
  4. data/app/controllers/noodall/admin/form_responses_controller.rb +6 -6
  5. data/app/helpers/forms_helper.rb +3 -7
  6. data/app/models/noodall/date_field.rb +5 -0
  7. data/app/models/noodall/field.rb +3 -2
  8. data/app/models/noodall/form.rb +9 -1
  9. data/app/models/noodall/form_response.rb +19 -39
  10. data/app/views/form_mailer/_form_response_fields.html.erb +1 -1
  11. data/app/views/noodall/admin/fields/_date_field.html.erb +14 -0
  12. data/app/views/noodall/admin/fields/_field.html.erb +0 -0
  13. data/app/views/noodall/admin/form_responses/index.html.erb +1 -1
  14. data/app/views/noodall/admin/forms/_field_select.html.erb +1 -0
  15. data/app/views/noodall/admin/forms/show.html.erb +3 -0
  16. data/app/views/noodall/form_responses/_form.html.erb +1 -0
  17. data/app/views/noodall/form_responses/fields/_datefield.html.erb +6 -0
  18. data/features/form_builder.feature +6 -5
  19. data/features/form_module.feature +1 -0
  20. data/features/step_definitions/cms_node_steps.rb +6 -6
  21. data/features/step_definitions/component_steps.rb +4 -4
  22. data/features/step_definitions/form_builder_steps.rb +17 -15
  23. data/features/step_definitions/web_steps.rb +6 -6
  24. data/features/support/env.rb +3 -2
  25. data/features/support/mm_factory_steps.rb +11 -9
  26. data/lib/noodall/form_builder/version.rb +1 -1
  27. data/script/cucumber +10 -0
  28. data/script/rails +6 -0
  29. data/spec/factories/field.rb +2 -0
  30. data/spec/factories/form.rb +9 -4
  31. data/spec/models/form_spec.rb +34 -0
  32. data/spec/spec_helper.rb +7 -2
  33. metadata +14 -8
  34. data/spec/noodall_form_builder_spec.rb +0 -7
data/Gemfile CHANGED
@@ -1,24 +1,25 @@
1
1
  source :rubygems
2
-
2
+ source "http://gems.github.com"
3
3
  gemspec
4
4
 
5
- gem 'mm-versionable', '0.2.5'
6
5
  gem 'rails', '3.1.3'
7
6
  gem 'noodall-ui'
8
- gem 'capybara', '>= 0.3.9'
9
- gem 'rspec-rails', '>= 2.0.0.beta'
10
- gem 'database_cleaner'
11
- gem 'cucumber-rails'
12
- gem 'launchy' # So you can do Then show me the page
13
- gem 'rmagick', :require => 'RMagick'
14
7
  gem 'dragonfly', '~> 0.7.6'
15
- gem 'factory_girl', '~> 1.3.2'
16
- gem 'faker', '~> 0.3.1'
17
8
  gem 'defensio'
18
- gem 'email_spec'
19
9
  gem 'fastercsv'
20
10
  gem 'bson_ext'
21
11
 
12
+ group :test do
13
+ gem 'email_spec'
14
+ gem 'cucumber-rails'
15
+ gem 'rspec-rails', '>= 2.0.0.beta'
16
+ gem 'factory_girl_rails'
17
+ gem 'faker', '~> 0.3.1'
18
+ gem 'capybara', '>= 0.3.9'
19
+ gem 'database_cleaner'
20
+ gem 'launchy' # So you can do Then show me the page
21
+ end
22
+
22
23
  if RUBY_VERSION < '1.9'
23
24
  gem 'system_timer'
24
25
  gem "ruby-debug", ">= 0.10.3"
data/README.rdoc CHANGED
@@ -1,3 +1,24 @@
1
- = Noodall-form-builder
1
+ = Noodall Form Builder
2
2
 
3
- This project rocks and uses MIT-LICENSE.
3
+ Form building for Noodall
4
+
5
+ == Getting Started
6
+
7
+ Add to Gemfile
8
+
9
+ gem 'noodall-form-builder'
10
+
11
+ Install the gem
12
+
13
+ bundle install
14
+
15
+ Add the Form Builder routes to config/routes.rb
16
+
17
+ require 'noodall/form_builder/routes'
18
+ Noodall::FormBuilder::Routes.draw <AppNameConstantGoesHere>::Application
19
+
20
+ Add ContactForm to required slots in config/initializers/noodall.rb
21
+
22
+ Noodall::Node.slot :large, ContactForm
23
+
24
+ This project rocks and uses MIT-LICENSE.
@@ -1,5 +1,5 @@
1
1
  function new_form_field(type) {
2
- if ($.inArray(type, ['text_field', 'select', 'multiselect', 'radio', 'check_box']) == -1) {
2
+ if ($.inArray(type, ['text_field', 'select', 'multiselect', 'date_field', 'radio', 'check_box']) == -1) {
3
3
  alert('Unknown field type.');
4
4
  } else {
5
5
  // find an index for the new form field (largest index plus one)
@@ -41,7 +41,7 @@ module Noodall
41
41
  nil
42
42
  end
43
43
  end
44
- response_row += [response.created_at.to_formatted_s(:long_dot), response.ip, response.referrer]
44
+ response_row += [response.created_at.to_formatted_s(:long), response.ip, response.referrer]
45
45
  csv << response_row
46
46
  end
47
47
  end
@@ -67,17 +67,17 @@ module Noodall
67
67
 
68
68
  def mark_as_spam
69
69
  @response = @form.responses.find(params[:id])
70
- @response.mark_as_spam!
70
+ @response.mark_as_spam!
71
71
  redirect_to(noodall_admin_form_form_responses_url(@form))
72
72
  end
73
-
73
+
74
74
  def mark_as_not_spam
75
75
  @response = @form.responses.find(params[:id])
76
- @response.approve!
77
-
76
+ @response.approve!
77
+
78
78
  FormMailer.form_response(@form, @response).deliver unless @form.email.blank?
79
79
  FormMailer.form_response_thankyou(@form, @response).deliver
80
-
80
+
81
81
  redirect_to(noodall_admin_form_form_responses_url(@form))
82
82
  end
83
83
 
@@ -1,20 +1,16 @@
1
1
  module FormsHelper
2
2
 
3
3
  def response_setup(form)
4
- # collect the default values together
5
- defaults = {}
6
- form.fields.collect{|f| defaults[f.underscored_name.to_sym] = f.default } unless form.nil? || form.fields.nil?
7
-
8
- Noodall::FormResponse.new(defaults)
4
+ form.responses.build
9
5
  end
10
6
 
11
7
  def field_type(field)
12
8
  field_type = field._type.gsub(/^.*::/, '').downcase
13
-
9
+
14
10
  if field_type == "textfield" && field.rows > 1
15
11
  field_type = "textarea"
16
12
  end
17
-
13
+
18
14
  return field_type
19
15
  end
20
16
 
@@ -0,0 +1,5 @@
1
+ module Noodall
2
+ class DateField < Noodall::Field
3
+ key :default, Date
4
+ end
5
+ end
@@ -1,6 +1,7 @@
1
1
  module Noodall
2
2
  class Field
3
3
  include MongoMapper::EmbeddedDocument
4
+ plugin MongoMapper::Plugins::MultiParameterAttributes
4
5
 
5
6
  key :_type, String, :required => true
6
7
  key :name, String, :required => true
@@ -14,11 +15,11 @@ module Noodall
14
15
  def default_label
15
16
  self.label = self.name if self.label.blank?
16
17
  end
17
-
18
+
18
19
  def underscored_name
19
20
  name.parameterize.gsub('-','_').to_s
20
21
  end
21
-
22
+
22
23
  def default_class(response)
23
24
  'default-value' if response.send(underscored_name.to_sym) == default
24
25
  end
@@ -1,7 +1,6 @@
1
1
  module Noodall
2
2
  class Form
3
3
  include MongoMapper::Document
4
- plugin MongoMapper::Plugins::MultiParameterAttributes
5
4
  plugin Noodall::GlobalUpdateTime
6
5
 
7
6
  key :title, String, :required => true
@@ -19,6 +18,15 @@ module Noodall
19
18
  def spam
20
19
  self.select {|r| r.spaminess >= (self.class.defensio_config['spam_threshold'] || 0.75)}
21
20
  end
21
+ def build(attrs={})
22
+ doc = klass.new
23
+ apply_scope(doc)
24
+ doc.set_up_keys!
25
+ doc.attributes = attrs
26
+ @target ||= [] unless loaded?
27
+ @target << doc
28
+ doc
29
+ end
22
30
  end
23
31
 
24
32
  before_save :create_mandatory_fields!
@@ -2,7 +2,7 @@ module Noodall
2
2
  class FormResponse
3
3
  include MongoMapper::Document
4
4
 
5
- key :name, String
5
+ key :name, String, :required => true
6
6
  key :email, String, :format => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
7
7
  key :ip, String, :required => true
8
8
  key :referrer, String, :required => true
@@ -15,19 +15,16 @@ module Noodall
15
15
 
16
16
  attr_protected :approved
17
17
 
18
+
18
19
  timestamps!
19
20
 
20
21
  belongs_to :form, :class => Noodall::Form, :foreign_key => 'noodall_form_id'
21
22
 
22
- def required_fields
23
- self.form.fields.select{ |f| f.required? }
24
- end
25
-
26
- def correct_fields?
27
- self.form.fields.each do |f|
28
- return false unless self.respond_to?(f.name.downcase.parameterize("_").to_sym)
23
+ # Overiden to set up keys after find
24
+ def initialize_from_database(attrs={})
25
+ super.tap do
26
+ set_up_keys!
29
27
  end
30
- return true
31
28
  end
32
29
 
33
30
  def approve!
@@ -46,18 +43,22 @@ module Noodall
46
43
  self.approved == false
47
44
  end
48
45
 
49
- def string_value(name)
50
- return '' unless self.respond_to?(name)
51
- value = self.send(name)
46
+ # Create appropriate MongoMapper keys for current instance
47
+ # based on the fields of the form it belongs to
48
+ def set_up_keys!
49
+ form.fields.each do |f|
50
+ class_eval do
51
+ key f.underscored_name, f.keys['default'].type, :required => f.required, :default => f.default
52
+ end
53
+ end if form
54
+ end
52
55
 
53
- if value.is_a?(Array)
54
- value.join(', ')
55
- else
56
- value.to_s
57
- end
56
+ # Merge meta keys with real keys
57
+ def keys
58
+ super.merge( class_eval( 'keys' ) )
58
59
  end
59
60
 
60
- protected
61
+ protected
61
62
  def defensio_configuired?
62
63
  defined?(Defensio) && !self.class.defensio_config.blank?
63
64
  end
@@ -103,26 +104,5 @@ module Noodall
103
104
  }
104
105
  end
105
106
 
106
-
107
- private
108
- validate :custom_validation
109
-
110
- def custom_validation
111
- return true if required_fields.nil? || !self.new_record?
112
- required_fields.each do |field|
113
- self.errors.add(field.underscored_name.to_sym, "can't be empty") if self.send(field.underscored_name).blank?
114
- end
115
- return true if self.errors.empty?
116
- end
117
-
118
- def method_missing(method)
119
- # If the form doesn't have a field that matches this method, act normally. Otherwise, return nil to show the field is empty.
120
- if form.fields.select{|f| f.underscored_name.to_sym == method}.empty?
121
- super
122
- else
123
- return nil
124
- end
125
- end
126
-
127
107
  end
128
108
  end
@@ -1,6 +1,6 @@
1
1
  <% for field in @form.fields %>
2
2
  <tr>
3
3
  <td><%= field.name %></td>
4
- <td><%= @response.string_value(field.underscored_name) %></td>
4
+ <td><%= @response.send(field.underscored_name) %></td>
5
5
  </tr>
6
6
  <% end %>
@@ -0,0 +1,14 @@
1
+ <%= fields_for "form[fields][#{index}]", field do |f| %>
2
+ <tr>
3
+ <td><%= f.hidden_field :_type %><%= f.label :name, 'Name *' %><%= f.text_field :name %></td>
4
+ <td>Date Select</td>
5
+ <td><%= f.label :label, 'Label' %><%= f.text_field :label %></td>
6
+ <td><%= f.label :default, 'Default Option' %><%= f.text_field :default %></td>
7
+ <td class="center">-</td>
8
+ <td>-</td>
9
+ <td><%= f.label :required, 'Required?' %><%= f.check_box :required %></td>
10
+ <td width="25" class="up"><a class="page_up" title="Move this field up">up</a></td>
11
+ <td width="30" class="down"><a class="page_down" title="Move this field down">down</a></td>
12
+ <td><%= link_to_function 'Delete', 'return delete_form_field(this);', :class => 'delete' %></td>
13
+ </tr>
14
+ <% end %>
File without changes
@@ -21,7 +21,7 @@
21
21
  <% @responses.sort_by(&:created_at).reverse.each do |response| %>
22
22
  <tr id="form-<%= response.id %>" class="<%=cycle('odd', 'even')%>">
23
23
  <td class="edit"><%= mail_to response.email, h(response.name) %></td>
24
- <td><%= @form.fields.collect{|f| "<strong>#{f.name}:</strong> #{response.string_value(f.underscored_name)}" }.join(",&nbsp;").html_safe %></td>
24
+ <td><%= @form.fields.collect{|f| "<strong>#{f.name}:</strong> #{response.send(f.underscored_name)}" }.join(",&nbsp;").html_safe %></td>
25
25
  <td><%= h response.created_at.to_formatted_s(:long_dot) %></td>
26
26
  <td class="spam <%= 'flagged' unless response.approved %>">
27
27
  <% if response.approved %>
@@ -5,6 +5,7 @@
5
5
  <option value="text_field">Text</option>
6
6
  <option value="select">Select Box</option>
7
7
  <option value="multiselect">Multi-Select Box</option>
8
+ <option value="date_field">Date</option>
8
9
  <option value="radio">Radio Buttons</option>
9
10
  <option value="check_box">Check Box</option>
10
11
  </select>
@@ -50,6 +50,9 @@
50
50
  <p id="multiselect" class="field-help">
51
51
  Similar to Select. <strong>Examples:</strong> Acceptable Contact Methods, Phone, Phone AND Email, Phone AND Text AND Mail
52
52
  </p>
53
+ <p id="date_select" class="field-help">
54
+ Similar to Select but allows you to select the day, month and year.
55
+ </p>
53
56
  <p id="radio" class="field-help">
54
57
  <strong>Examples:</strong> Yes or No Questions, Multiple Choice<br/><br/>
55
58
  The radio button only allows one option to be chosen.
@@ -14,3 +14,4 @@
14
14
  <%= f.submit "Reset Form", :name => 'reset', :type => 'reset', :id => "form-reset" %>
15
15
  </p>
16
16
  <% end %>
17
+ sdfsdf
@@ -0,0 +1,6 @@
1
+ <%= (f.label field.underscored_name, field.label) %>
2
+ <%= (field.required ? content_tag('span', ' *', :class => 'required') : '') %>
3
+
4
+ <%= f.text_field field.underscored_name, :class => 'date-field' %>
5
+ <hr />
6
+
@@ -27,11 +27,12 @@ Feature: Form builder
27
27
  Then I should see a new field with the options "<Options>"
28
28
 
29
29
  Examples:
30
- | Field Type | Options |
31
- | Text | Name, Label, Default, Rows, Required |
32
- | Select | Name, Label, Default Option, Options, Required |
33
- | Radio | Name, Label, Default Option, Options, Required |
34
- | Check Box | Name, Label, Default state, Required |
30
+ | Field Type | Options |
31
+ | Text | Name, Label, Default, Rows, Required |
32
+ | Select | Name, Label, Default Option, Options, Required |
33
+ | Radio | Name, Label, Default Option, Options, Required |
34
+ | Check Box | Name, Label, Default state, Required |
35
+ | Date | Name, Label, Default, Required |
35
36
 
36
37
  @javascript
37
38
  Scenario: Reorder fields
@@ -72,6 +72,7 @@ Feature: Form Module
72
72
  And I fill in the following:
73
73
  | Name | Dave |
74
74
  | Email | spoon@buttonmooon.com |
75
+ | Date | 30/03/1976 |
75
76
  And I press "Send"
76
77
  Then I should see "Thanks for that"
77
78
  And "spoon@buttonmooon.com" should receive an email
@@ -8,7 +8,7 @@ When /^I click on a root$/ do
8
8
  within("tbody tr:last") { click_link "Children" }
9
9
  end
10
10
 
11
- Then /^I should see a list the of the roots children$/ do
11
+ Then /^I should see a list the of the root's children$/ do
12
12
  @_page.children.each do |child|
13
13
  page.should have_content(child.title)
14
14
  end
@@ -19,7 +19,7 @@ When /^I click on a child$/ do
19
19
  within(:css, "tbody tr:first") { click_link "Children" }
20
20
  end
21
21
 
22
- Then /^I should see a list of the childs children$/ do
22
+ Then /^I should see a list of the child's children$/ do
23
23
  @_child.children.each do |gchild|
24
24
  page.should have_content(gchild.title)
25
25
  end
@@ -50,7 +50,7 @@ Then /^I should be able to create a new child$/ do
50
50
  page.should have_content(' was successfully created.')
51
51
  end
52
52
 
53
- Then /^I should see the child listed within the roots children$/ do
53
+ Then /^I should see the child listed within the root's children$/ do
54
54
  visit noodall_admin_node_nodes_path(@_page)
55
55
  page.should have_content('New Child')
56
56
  end
@@ -63,7 +63,7 @@ Then /^I should be able to delete content$/ do
63
63
  page.should have_content("deleted")
64
64
  end
65
65
 
66
- Then /^the content and all of its sub content will be removed from the website$/ do
66
+ Then /^the content and all of it's sub content will be removed from the website$/ do
67
67
 
68
68
  lambda { visit node_path(@_deleted_node) }.should raise_error(MongoMapper::DocumentNotFound)
69
69
 
@@ -83,14 +83,14 @@ Then /^I should be able to move a child content to another parent$/ do
83
83
  click_button 'Draft'
84
84
  end
85
85
 
86
- Then /^I should see the child listed within the other parents children$/ do
86
+ Then /^I should see the child listed within the other parent's children$/ do
87
87
  visit noodall_admin_node_nodes_path(@_new_parent)
88
88
  within('tbody') do
89
89
  page.should have_content(@_child.title)
90
90
  end
91
91
  end
92
92
 
93
- Then /^I should be able change the order of the roots children$/ do
93
+ Then /^I should be able change the order of the root's children$/ do
94
94
  table = table(tableish("table tr", 'td, th'))
95
95
  title = table.hashes[2]['Title'] # 2 as zero index
96
96
  within(:css, 'table tbody tr:nth(3)') { click_link "up" }
@@ -11,13 +11,13 @@ When /^(?:|I )click a "([^"]*)" component slot$/ do |slot_name|
11
11
  end
12
12
 
13
13
  When /^(?:|I )select the "([^\"]+)" component$/ do |component_name|
14
- within "#fancybox-inner" do
14
+ within "#fancybox-content" do
15
15
  select component_name, :from => 'Select the type of component'
16
16
  end
17
17
  end
18
18
 
19
19
  When /^(?:|I )fill in the following within the component:$/ do |fields|
20
- within "#fancybox-inner" do
20
+ within "#fancybox-content" do
21
21
  fields.rows_hash.each do |name, value|
22
22
  When %{I fill in "#{name}" with "#{value}"}
23
23
  end
@@ -25,7 +25,7 @@ When /^(?:|I )fill in the following within the component:$/ do |fields|
25
25
  end
26
26
 
27
27
  When /^(?:|I )press "([^"]*)" within the component$/ do |button|
28
- within "#fancybox-inner" do
28
+ within "#fancybox-content" do
29
29
  click_button(button)
30
30
  sleep 3
31
31
  end
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  When /^(?:|I )select an image from the asset library$/ do
35
35
  asset = Factory(:asset, :title => "My Image")
36
- within "#fancybox-inner" do
36
+ within "#fancybox-content" do
37
37
  pending
38
38
  end
39
39
  end
@@ -111,7 +111,7 @@ When /^a website visitor visits the content$/ do
111
111
  end
112
112
 
113
113
  Then /^they should see the form$/ do
114
- Then %{I should see the form I selected}
114
+ step %{I should see the form I selected}
115
115
  end
116
116
 
117
117
  When /^they fill in and submit the form$/ do
@@ -122,24 +122,26 @@ When /^they fill in and submit the form$/ do
122
122
  else
123
123
  if field.class == Noodall::TextField
124
124
  fill_in "form_response[#{field.underscored_name}]", :with => 'Weopunggggggggst'
125
+ elsif field.class == Noodall::DateField
126
+ fill_in "form_response[#{field.underscored_name}]", :with => '30/03/1976'
125
127
  end
126
128
  end
127
129
  end
128
130
 
129
- When %{they submit the form}
131
+ step %{they submit the form}
130
132
  end
131
133
 
132
134
  Then /^the email address of the form should receive an email detailing the information submitted$/ do
133
- Then %{"#{@_form.email}" should receive an email}
135
+ step %{"#{@_form.email}" should receive an email}
134
136
  @_form.fields do |field|
135
- Then %{they should see "#{field.name}:" in the email body}
137
+ step %{they should see "#{field.name}:" in the email body}
136
138
  end
137
139
  end
138
140
 
139
141
  Then /^they should receive an email confirming the request has been sent$/ do
140
- Then %{"hello@example.com" should receive an email}
142
+ step %{"hello@example.com" should receive an email}
141
143
  @_form.fields do |field|
142
- Then %{they should see "#{field.name}:" in the email body}
144
+ step %{they should see "#{field.name}:" in the email body}
143
145
  end
144
146
  end
145
147
 
@@ -163,7 +165,7 @@ Then /^it should be rejected if the spam filter deems the response to be spam$/
163
165
  end
164
166
 
165
167
  Then /^the website visitor should see an spam message$/ do
166
- Then %{it should be rejected if the spam filter deems the response to be spam}
168
+ step %{it should be rejected if the spam filter deems the response to be spam}
167
169
  end
168
170
 
169
171
  Then /^it should be checked against the validation speficied in the form builder$/ do
@@ -175,7 +177,7 @@ Then /^it should be checked against the validation speficied in the form builder
175
177
  end
176
178
 
177
179
  Then /^it should be rejected if the the response does not meet the validation$/ do
178
- Then %{it should be checked against the validation speficied in the form builder}
180
+ step %{it should be checked against the validation speficied in the form builder}
179
181
  end
180
182
 
181
183
  Then /^the website visitor should see an error message$/ do
@@ -183,7 +185,7 @@ Then /^the website visitor should see an error message$/ do
183
185
  end
184
186
 
185
187
  When /^a website visitor fills in and submits a form$/ do
186
- When %{they fill in and submit the form}
188
+ step %{they fill in and submit the form}
187
189
  end
188
190
 
189
191
  When /^they submit the form$/ do
@@ -191,13 +193,13 @@ When /^they submit the form$/ do
191
193
  end
192
194
 
193
195
  When /^a form response is deemed to be spam$/ do
194
- When %{a website visitor visits the content}
196
+ step %{a website visitor visits the content}
195
197
  defensio_dummy = double("defensio dummy")
196
198
  defensio_dummy.stub(:post_document){ [200, {'spaminess' => 1, "allow" => false}] }
197
199
  defensio_dummy.stub(:put_document){ [200, {"allow" => false}] }
198
200
 
199
201
  Noodall::FormResponse.stub(:defensio).and_return(defensio_dummy)
200
- When %{they fill in and submit the form}
202
+ step %{they fill in and submit the form}
201
203
  end
202
204
 
203
205
  Then /^it should marked as spam$/ do
@@ -225,8 +227,8 @@ When /^I am editing the form$/ do
225
227
  end
226
228
 
227
229
  When /^I click the "([^\"]*)" arrow next to "([^\"]*)" twice$/ do |arrow, field|
228
- When %{I click the "#{arrow}" arrow next to "#{field}" once}
229
- When %{I click the "#{arrow}" arrow next to "#{field}" once}
230
+ step %{I click the "#{arrow}" arrow next to "#{field}" once}
231
+ step %{I click the "#{arrow}" arrow next to "#{field}" once}
230
232
  end
231
233
 
232
234
  Then /^the "([^"]*)" field should be at position (\d+)$/ do |field, position|
@@ -249,7 +251,7 @@ When /^I view the form on the website$/ do
249
251
  @_node = Factory(:page_a)
250
252
  @_node.wide_slot_0 = Factory(:contact_form, :form_id => @_form.id)
251
253
  @_node.save
252
- When %{a website visitor visits the content}
254
+ step %{a website visitor visits the content}
253
255
  end
254
256
 
255
257
  Then /^I should see the fields in the order I set$/ do
@@ -271,7 +273,7 @@ Given /^I am viewing the form's responses$/ do
271
273
  end
272
274
 
273
275
  Given /^I mark the response as not spam$/ do
274
- When %{I follow "Not Spam?"} # This is tied to the current page, could be abstracted a little more
276
+ step %{I follow "Not Spam?"} # This is tied to the current page, could be abstracted a little more
275
277
  end
276
278
 
277
279
 
@@ -1,6 +1,6 @@
1
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
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
4
  # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
5
  # files.
6
6
 
@@ -62,7 +62,7 @@ end
62
62
  When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
63
63
  with_scope(selector) do
64
64
  fields.rows_hash.each do |name, value|
65
- When %{I fill in "#{name}" with "#{value}"}
65
+ step %{I fill in "#{name}" with "#{value}"}
66
66
  end
67
67
  end
68
68
  end
@@ -191,7 +191,7 @@ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |
191
191
  end
192
192
  end
193
193
  end
194
-
194
+
195
195
  Then /^(?:|I )should be on (.+)$/ do |page_name|
196
196
  current_path = URI.parse(current_url).path
197
197
  if current_path.respond_to? :should
@@ -205,8 +205,8 @@ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
205
205
  query = URI.parse(current_url).query
206
206
  actual_params = query ? CGI.parse(query) : {}
207
207
  expected_params = {}
208
- expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
209
-
208
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
209
+
210
210
  if actual_params.respond_to? :should
211
211
  actual_params.should == expected_params
212
212
  else
@@ -10,8 +10,8 @@ require File.expand_path("../../../spec/dummy/config/environment.rb", __FILE__)
10
10
  require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
11
11
  require 'cucumber/rails/rspec'
12
12
  require 'cucumber/rails/world'
13
+ require 'email_spec'
13
14
  require 'email_spec/cucumber'
14
- require 'cucumber/web/tableish'
15
15
  require 'cucumber/rspec/doubles'
16
16
 
17
17
  require 'capybara/rails'
@@ -41,6 +41,7 @@ require 'database_cleaner/cucumber'
41
41
  DatabaseCleaner.strategy = :truncation
42
42
 
43
43
  require 'factory_girl'
44
+ require 'faker'
44
45
 
45
46
  Factory.definition_file_paths = [
46
47
  File.expand_path("../../../spec/factories", __FILE__)
@@ -49,5 +50,5 @@ Factory.find_definitions
49
50
 
50
51
  require 'factory_girl/step_definitions'
51
52
  require 'csv' #for checking CSV content
52
- require 'ruby-debug'
53
+ #require 'ruby-debug'
53
54
 
@@ -1,13 +1,15 @@
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
1
+ FactoryGirl.factories.each do |factory|
2
+ factory.human_names.each do |human_name|
3
+ if factory.build_class.respond_to?(:keys)
4
+ factory.build_class.keys.each_key do |key|
5
+ human_column_name = key.downcase.gsub('_', ' ')
6
+ Given /^an? #{human_name} exists with an? #{human_column_name} of "([^"]*)"$/i do |value|
7
+ Factory(factory.name, key => value)
8
+ end
8
9
 
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) }
10
+ Given /^(\d+) #{human_name.pluralize} exist with an? #{human_column_name} of "([^"]*)"$/i do |count, value|
11
+ count.to_i.times { Factory(factory.name, key => value) }
12
+ end
11
13
  end
12
14
  end
13
15
  end
@@ -1,5 +1,5 @@
1
1
  module Noodall
2
2
  module FormBuilder
3
- VERSION = "0.4.2"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
data/script/cucumber ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
4
+ if vendored_cucumber_bin
5
+ load File.expand_path(vendored_cucumber_bin)
6
+ else
7
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
8
+ require 'cucumber'
9
+ load Cucumber::BINARY
10
+ end
data/script/rails ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ #!/usr/bin/env ruby
3
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
4
+
5
+ ENGINE_PATH = File.expand_path('../..', __FILE__)
6
+ load File.expand_path('../../spec/dummy/script/rails', __FILE__)
@@ -14,3 +14,5 @@ Factory.define :radio_field, :parent => :select_field, :class => Noodall::Radio
14
14
  end
15
15
  Factory.define :check_box_field, :parent => :field, :class => Noodall::CheckBox do |field|
16
16
  end
17
+ Factory.define :date_field, :parent => :field, :class => Noodall::DateField do |field|
18
+ end
@@ -7,11 +7,16 @@ Factory.define :form, :class => Noodall::Form do |form|
7
7
  5.times do
8
8
  fields << Factory(:text_field)
9
9
  end
10
- fields << Factory(:check_box_field)
11
- fields << Factory(:select_field)
12
- fields << Factory(:check_box_field)
13
- fields << Factory(:radio_field)
10
+ fields << Factory(:check_box_field, :name => 'Check' )
11
+ fields << Factory(:select_field, :name => 'Select')
12
+ fields << Factory(:radio_field, :name => 'Radio')
13
+ fields << Factory(:date_field, :name => 'Date', :required => true)
14
14
 
15
15
  fields
16
16
  end
17
17
  end
18
+
19
+ Factory.define :blank_form, :class => Noodall::Form do |form|
20
+ form.title "A Form"
21
+ form.email "hello@wearebeef.co.uk"
22
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Noodall::FormResponse do
4
+
5
+ it "should have methods based on it's forms fields" do
6
+ form = Factory(:form)
7
+ r = form.responses.build
8
+ test_date = Time.now
9
+ r.date = test_date
10
+ r.date.should == test_date.to_date
11
+ end
12
+
13
+ it "should validate fields marked required in it's form" do
14
+ form = Factory(:form)
15
+ r = form.responses.build()
16
+ r.save
17
+ r.errors.messages.should have_key(:date)
18
+ end
19
+
20
+ it "should not persist feilds in the class" do
21
+ form = Factory(:form)
22
+ r1 = form.responses.build
23
+ r1.save
24
+ r1.errors.messages.should have_key(:date)
25
+
26
+ form = Factory(:blank_form)
27
+ r = form.responses.build
28
+ r.save
29
+ r.errors.messages.should_not have_key(:date)
30
+
31
+ r1.save
32
+ r1.errors.messages.should have_key(:date)
33
+ end
34
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,8 @@
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
4
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require 'faker'
6
+ require 'factory_girl_rails'
5
7
  require "rails/test_help"
6
8
  require "rspec/rails"
7
9
 
@@ -19,12 +21,15 @@ Capybara.default_selector = :css
19
21
  # Load support files
20
22
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
21
23
 
22
- Rspec.configure do |config|
24
+ RSpec.configure do |config|
23
25
  # Remove this line if you don't want Rspec's should and should_not
24
26
  # methods or matchers
25
27
  require 'rspec/expectations'
26
- config.include Rspec::Matchers
28
+ config.include RSpec::Matchers
27
29
 
28
30
  # == Mock Framework
29
31
  config.mock_with :rspec
32
+
33
+ config.backtrace_clean_patterns = [
34
+ ]
30
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noodall-form-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-01-05 00:00:00.000000000Z
14
+ date: 2012-02-03 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
18
- requirement: &16665900 !ruby/object:Gem::Requirement
18
+ requirement: &13206780 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 1.0.0
24
24
  type: :development
25
25
  prerelease: false
26
- version_requirements: *16665900
26
+ version_requirements: *13206780
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fastercsv
29
- requirement: &16665320 !ruby/object:Gem::Requirement
29
+ requirement: &13206260 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *16665320
37
+ version_requirements: *13206260
38
38
  description: Functionality for building custom forms
39
39
  email: []
40
40
  executables: []
@@ -57,6 +57,7 @@ files:
57
57
  - app/mailers/form_mailer.rb
58
58
  - app/models/contact_form.rb
59
59
  - app/models/noodall/check_box.rb
60
+ - app/models/noodall/date_field.rb
60
61
  - app/models/noodall/field.rb
61
62
  - app/models/noodall/form.rb
62
63
  - app/models/noodall/form_response.rb
@@ -70,6 +71,8 @@ files:
70
71
  - app/views/form_mailer/form_response.html.erb
71
72
  - app/views/form_mailer/form_response_thankyou.html.erb
72
73
  - app/views/noodall/admin/fields/_check_box.html.erb
74
+ - app/views/noodall/admin/fields/_date_field.html.erb
75
+ - app/views/noodall/admin/fields/_field.html.erb
73
76
  - app/views/noodall/admin/fields/_multiselect.html.erb
74
77
  - app/views/noodall/admin/fields/_radio.html.erb
75
78
  - app/views/noodall/admin/fields/_select.html.erb
@@ -82,6 +85,7 @@ files:
82
85
  - app/views/noodall/form_responses/_form.html.erb
83
86
  - app/views/noodall/form_responses/create.html.erb
84
87
  - app/views/noodall/form_responses/fields/_checkbox.html.erb
88
+ - app/views/noodall/form_responses/fields/_datefield.html.erb
85
89
  - app/views/noodall/form_responses/fields/_multiselect.html.erb
86
90
  - app/views/noodall/form_responses/fields/_radio.html.erb
87
91
  - app/views/noodall/form_responses/fields/_select.html.erb
@@ -111,6 +115,8 @@ files:
111
115
  - lib/noodall/form_builder/routes.rb
112
116
  - lib/noodall/form_builder/version.rb
113
117
  - noodall-form-builder.gemspec
118
+ - script/cucumber
119
+ - script/rails
114
120
  - spec/dummy/Rakefile
115
121
  - spec/dummy/app/controllers/application_controller.rb
116
122
  - spec/dummy/app/helpers/application_helper.rb
@@ -154,7 +160,7 @@ files:
154
160
  - spec/factories/user.rb
155
161
  - spec/files/beef.png
156
162
  - spec/integration/navigation_spec.rb
157
- - spec/noodall_form_builder_spec.rb
163
+ - spec/models/form_spec.rb
158
164
  - spec/spec_helper.rb
159
165
  homepage: http://rubygems.org/gems/noodall-form-builder
160
166
  licenses: []
@@ -170,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
176
  version: '0'
171
177
  segments:
172
178
  - 0
173
- hash: -2066216638698586933
179
+ hash: 2489411277551539261
174
180
  required_rubygems_version: !ruby/object:Gem::Requirement
175
181
  none: false
176
182
  requirements:
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Noodall::FormBuilder::Form do
4
- it "should be valid" do
5
- Noodall::FormBuilder::Form.should be_a(Module)
6
- end
7
- end