acts_as_multipart_form 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.0.3
2
+
3
+ * Moved capybara and sqlite to development gems
4
+
1
5
  == 0.0.2
2
6
 
3
7
  * Updating the readme
data/Gemfile CHANGED
@@ -4,13 +4,15 @@ source "http://rubygems.org"
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
 
6
6
  gem "rails", "3.0.7"
7
- gem "capybara", ">= 0.4.0"
8
- gem "sqlite3"
9
7
 
10
8
 
11
9
  # Add dependencies to develop your gem here.
12
10
  # Include everything needed to run rake, tests, features, etc.
13
11
  group :development do
12
+
13
+ gem "capybara", ">= 0.4.0"
14
+ gem "sqlite3"
15
+
14
16
  gem 'ruby-debug19'
15
17
  gem "rspec", "~> 2.6.0"
16
18
  gem "rspec-rails", "~>2.6.1"
@@ -1,6 +1,6 @@
1
1
  = acts_as_multipart_form
2
2
 
3
- Create multipart forms in rails without using multiple routes. A controler mixin handles loading and saving data based on partials on a single route.
3
+ Create multipart forms in rails without using multiple routes. A controller mixin handles loading and saving data based on partials on a single route.
4
4
 
5
5
  = How to use
6
6
 
@@ -22,7 +22,7 @@ Each form has a polymorphic relationship with a single record. This relationshi
22
22
 
23
23
  Two routes can be specified for the form system. The form route corresponds to the route to the form itself. It's default value is model_name_form_name. In the example, the specified value would be the default value. The show route, specified with the tag :show_route is redirected to after the last part of the multipart form is submitted and passes validations. It defauls to model_name to correspond with the model's view page.
24
24
 
25
- == Add the mixing to your model
25
+ == Add the mixin to your model
26
26
 
27
27
  multipart_formable :forms => [:hire_form]
28
28
 
@@ -30,12 +30,17 @@ This is currently only used for validations. If this is set, you can use a vali
30
30
 
31
31
  validates_presence_of :name, :if => :hire_form_personal_info?
32
32
 
33
- == Adding a breadcrumb to the form page
33
+ == Setting up your form
34
34
 
35
35
  <%= render "multipart_form/breadcrumb" %>
36
36
 
37
- This adds links to each form page and next/previous links to the page. It must be on a multipart form view to work. The configuration options in the initializer can be used to change the output of the partial.
37
+ <%= form_for @form_subject, :url => person_hire_form_path(:id => @form_subject.id, :multipart_form_part => @next_multipart_form_part), :html => {:method => :post} do |f| %>
38
+ <%= render "multipart_form/all_errors" %>
39
+ <%= render @multipart_form_part, :locals => {:form => f} %>
40
+ <%= f.submit "Submit" %>
41
+ <% end %>
38
42
 
43
+ The breadcrumb adds links to the other multipart for parts. The all_errors partial is a substitute for putting error handling on each individual partial. The url and @form_subject instance variable are necessary to make the form submit and redirect correctly.
39
44
  == Adding form part links to the index page
40
45
 
41
46
  === On the controller
@@ -43,7 +48,7 @@ This adds links to each form page and next/previous links to the page. It must
43
48
  @people = Person.all
44
49
  load_multipart_form_index_links(:hire_form, @people)
45
50
 
46
- === On the view
51
+ === On the index view
47
52
 
48
53
  <%= render "multipart_form/index_links", :locals => {:form_subject => person } %>
49
54
 
@@ -56,6 +61,8 @@ Creates links to each form part for the given form subject. The load_multipart_
56
61
  * Improve the behavior of the previous and next links in the breadcrumb
57
62
  * Add A controller and views generator to generate the files in the rails project so they can be edited for project specific needs
58
63
  * Improve code quality of the mixin where it makes variables available to views
64
+ * Move the logic in the multipart_form partials to heleprs
65
+ * Find a fix for having to explicitly create the form subject in the code. The current system pushes us towards models that only hold the form subject id. The problem is that it is possible to use a multipart form without a specific form model. This leads to orphaned or blank records.
59
66
 
60
67
  == Contributing to acts_as_multipart_form
61
68
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_multipart_form}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Jeremiah Hemphill}, %q{Ethan Pemble}]
12
- s.date = %q{2011-07-28}
12
+ s.date = %q{2011-08-01}
13
13
  s.description = %q{Multipart forms using custom routes}
14
14
  s.email = %q{jeremiah@cloudspace.com}
15
15
  s.extra_rdoc_files = [
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "acts_as_multipart_form.gemspec",
29
29
  "app/controllers/multipart_form/in_progress_forms_controller.rb",
30
30
  "app/models/multipart_form/in_progress_form.rb",
31
+ "app/views/multipart_form/_all_errors.html.erb",
31
32
  "app/views/multipart_form/_breadcrumb.html.erb",
32
33
  "app/views/multipart_form/_index_links.html.erb",
33
34
  "app/views/multipart_form/in_progress_form/index.html.erb",
@@ -74,6 +75,7 @@ Gem::Specification.new do |s|
74
75
  "spec/dummy/db/migrate/20110715180834_create_people.rb",
75
76
  "spec/dummy/db/migrate/20110722130249_create_multipart_form_tables.rb",
76
77
  "spec/dummy/db/schema.rb",
78
+ "spec/dummy/features/all_errors_partial.feature",
77
79
  "spec/dummy/features/form_breadcrumb.feature",
78
80
  "spec/dummy/features/form_submission.feature",
79
81
  "spec/dummy/features/index_links.feature",
@@ -114,8 +116,8 @@ Gem::Specification.new do |s|
114
116
 
115
117
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
116
118
  s.add_runtime_dependency(%q<rails>, ["= 3.0.7"])
117
- s.add_runtime_dependency(%q<capybara>, [">= 0.4.0"])
118
- s.add_runtime_dependency(%q<sqlite3>, [">= 0"])
119
+ s.add_development_dependency(%q<capybara>, [">= 0.4.0"])
120
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
119
121
  s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
120
122
  s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
121
123
  s.add_development_dependency(%q<rspec-rails>, ["~> 2.6.1"])
@@ -0,0 +1,15 @@
1
+ <div id="error_explanation">
2
+
3
+ <% vars = controller.instance_variable_names.select { |var| eval(var).is_a?(ActiveRecord::Base) && eval(var).errors.is_a?(ActiveModel::Errors)} %>
4
+ <% if vars.sum { |v| eval(v).errors.count } > 0 %>
5
+ <h2><%=pluralize(vars.sum { |v| eval(v).errors.count }, "error") %> prohibited this form from being saved:</h2>
6
+ <ul>
7
+ <% vars.each do |var| %>
8
+ <% eval(var).errors.full_messages.each do |msg| %>
9
+ <li><%= eval(var).class.name + ": " + msg %></li>
10
+ <% end %>
11
+ <% end %>
12
+ </ul>
13
+ <% end %>
14
+ </div>
15
+
@@ -33,19 +33,21 @@ module ActsAsMultipartForm
33
33
  # def person_info_update
34
34
  # @person = Person.find(params[:id])
35
35
  # @person = Person.new if @person.nil?
36
+ # @person.multipart_form_controller_action = "person_info_update"
36
37
  #
37
38
  # valid = @person.update_attributes(params[:person])
38
- # return {:valid => valid, :errors => @person.errors}
39
+ # return {:valid => valid}
39
40
  # end
40
41
  #
41
42
  # def job_info
42
43
  # @job_position = JobPosition.new
43
44
  # @job_position.person = Person.find(load_multipart_form_data(form_instance_id, :person))
45
+ # @job_position.multipart_form_controller_action = "job_info_update"
44
46
  # end
45
47
  #
46
48
  # def job_info_update
47
49
  # valid = @job_position.update_attributes(params[:job_position])
48
- # return {:valid => valid, :errors => @job_position.errors}
50
+ # return {:valid => valid}
49
51
  # end
50
52
  #
51
53
  # @param [Array] args An array of hashes that determines the data for a multipart form
@@ -205,7 +207,9 @@ module ActsAsMultipartForm
205
207
 
206
208
  # Given a form name and a form subject id, it creates the form subject
207
209
  # The form subject is defined by the id and the multipart form's model attribute
208
- # The subject is created with values and saved without validations (this might change in the future)
210
+ #
211
+ # The subject is created with no values and saved without validations (this might change in the future)
212
+ # This is not a good situation but I don't know how to ensure the form subject gets saved otherwise
209
213
  #
210
214
  # @param [Symbol] form_name The name of the multipart form
211
215
  # @param [Integer] form_dubject_id The id of the form subject (could be nil)
@@ -7,11 +7,14 @@ class PeopleController < ApplicationController
7
7
 
8
8
  def person_info_update
9
9
  @person = Person.find(params[:id])
10
- if @person.update_attributes(params[:person])
11
- return {:valid => true}
10
+ @person.multipart_form_controller_action = "person_info_update"
11
+ if params[:person] and params[:person][:person]
12
+ @person.update_attributes(params[:person][:person])
13
+ return { :valid => @person.valid? }
12
14
  else
13
- return {:valid => false}
15
+ return { :valid => false }
14
16
  end
17
+
15
18
  end
16
19
 
17
20
  def job_info
@@ -20,16 +23,17 @@ class PeopleController < ApplicationController
20
23
 
21
24
  def job_info_update
22
25
  @person = Person.find(params[:id])
26
+ @person.multipart_form_controller_action = "job_info_update"
23
27
  if @person.update_attributes(params[:person])
24
28
  return {:valid => true}
25
29
  else
26
- return {:valid => false}
30
+ return {:valid => false }
27
31
  end
28
32
  end
29
33
 
30
34
  def hire_form
31
35
  #puts "stub method for the hire form"
32
- @person = Person.find(params[:id])
36
+ #@person = Person.find(params[:id])
33
37
 
34
38
  respond_to do |format|
35
39
  format.html
@@ -1,5 +1,5 @@
1
1
  class Person < ActiveRecord::Base
2
2
  multipart_formable :forms => [:hire_form]
3
3
 
4
- validates_presence_of :name, :if => :hire_form_personal_info?
4
+ validates_presence_of :name, :if => :hire_form_person_info_update?
5
5
  end
@@ -2,7 +2,7 @@
2
2
  This is the personal info multipart form partial.
3
3
  </p>
4
4
 
5
- <div class="field">
6
- <%= locals[:form].label :name %><br />
7
- <%= locals[:form].text_field :name %>
8
- </div>
5
+ <%= locals[:form].fields_for @person do |fp| %>
6
+ <%= fp.label :name %><br />
7
+ <%= fp.text_field :name %>
8
+ <% end %>
@@ -4,7 +4,8 @@
4
4
 
5
5
  <%= render "multipart_form/breadcrumb" %>
6
6
 
7
- <%= form_for @person, :url => person_hire_form_path(:id => @form_subject.id, :multipart_form_part => @next_multipart_form_part), :html => {:method => :post} do |f| %>
7
+ <%= form_for @form_subject, :url => person_hire_form_path(:id => @form_subject.id, :multipart_form_part => @next_multipart_form_part), :html => {:method => :post} do |f| %>
8
+ <%= render "multipart_form/all_errors" %>
8
9
  <%= render @multipart_form_part, :locals => {:form => f} %>
9
10
  <%= f.submit "Submit" %>
10
11
  <% end %>
@@ -0,0 +1,19 @@
1
+ Feature: I should be able to see error messages
2
+
3
+ Scenario: Errors on the person info page
4
+ Given there are no People in the system
5
+ And a person with an incomplete multipart form exists
6
+ When I go to the person hire_form page for that person
7
+ And I fill in "person_person_name" with ""
8
+ And I press "Submit"
9
+ Then I should see "1 error prohibited this form from being saved:"
10
+ And I should see "Person: Name can't be blank"
11
+
12
+ Scenario: No errors on the person info page
13
+ Given there are no People in the system
14
+ And a person with an incomplete multipart form exists
15
+ When I go to the person hire_form page for that person
16
+ And I fill in "person_person_name" with "Jeremiah"
17
+ And I press "Submit"
18
+ Then I should not see "0 errors prohibited this form from being saved:"
19
+ And I should not see "Person: Name can't be blank"
@@ -8,7 +8,7 @@ Feature: I should be able to submit data using the multipart form system
8
8
  Given there are no People in the system
9
9
  And a person with an incomplete multipart form exists
10
10
  When I go to the person hire_form page for that person
11
- And I fill in "person_name" with "Ethan"
11
+ And I fill in "person_person_name" with "Ethan"
12
12
  And I press "Submit"
13
13
  Then that person's information should have updated
14
14
  And I should be on the person hire_form page
@@ -3,15 +3,15 @@ require_relative 'spec_helper'
3
3
  describe Person do
4
4
  before(:each) do
5
5
  @person = Person.new
6
- @person.multipart_form_controller_action = "personal_info"
6
+ @person.multipart_form_controller_action = "person_info_update"
7
7
  end
8
8
 
9
- it "should respond to hire_form_personal_info" do
10
- @person.respond_to?(:hire_form_personal_info?).should be_true
9
+ it "should respond to hire_form_person_info_update" do
10
+ @person.respond_to?(:hire_form_person_info_update?).should be_true
11
11
  end
12
12
 
13
- it "should return true for hire_form_personal_info" do
14
- @person.hire_form_personal_info?.should be_true
13
+ it "should return true for hire_form_person_info_update" do
14
+ @person.hire_form_person_info_update?.should be_true
15
15
  end
16
16
 
17
17
  it "should call the name validation if the action is set" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: acts_as_multipart_form
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeremiah Hemphill
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-07-28 00:00:00 Z
14
+ date: 2011-08-01 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -32,7 +32,7 @@ dependencies:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: 0.4.0
35
- type: :runtime
35
+ type: :development
36
36
  prerelease: false
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
@@ -43,7 +43,7 @@ dependencies:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
45
  version: "0"
46
- type: :runtime
46
+ type: :development
47
47
  prerelease: false
48
48
  version_requirements: *id003
49
49
  - !ruby/object:Gem::Dependency
@@ -188,6 +188,7 @@ files:
188
188
  - acts_as_multipart_form.gemspec
189
189
  - app/controllers/multipart_form/in_progress_forms_controller.rb
190
190
  - app/models/multipart_form/in_progress_form.rb
191
+ - app/views/multipart_form/_all_errors.html.erb
191
192
  - app/views/multipart_form/_breadcrumb.html.erb
192
193
  - app/views/multipart_form/_index_links.html.erb
193
194
  - app/views/multipart_form/in_progress_form/index.html.erb
@@ -234,6 +235,7 @@ files:
234
235
  - spec/dummy/db/migrate/20110715180834_create_people.rb
235
236
  - spec/dummy/db/migrate/20110722130249_create_multipart_form_tables.rb
236
237
  - spec/dummy/db/schema.rb
238
+ - spec/dummy/features/all_errors_partial.feature
237
239
  - spec/dummy/features/form_breadcrumb.feature
238
240
  - spec/dummy/features/form_submission.feature
239
241
  - spec/dummy/features/index_links.feature
@@ -275,7 +277,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
275
277
  requirements:
276
278
  - - ">="
277
279
  - !ruby/object:Gem::Version
278
- hash: -4212957645854622535
280
+ hash: -3656101662010391779
279
281
  segments:
280
282
  - 0
281
283
  version: "0"