acts_as_multipart_form 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --profile
data/CHANGELOG CHANGED
@@ -1,5 +1,10 @@
1
1
  == unreleased changes
2
2
 
3
+ == 0.0.7
4
+
5
+ * Updated future work in readme
6
+ * Updated the behavior of the previous and next links to skip update pages
7
+
3
8
  == 0.0.6
4
9
 
5
10
  * Added indices to the migration
@@ -60,10 +60,7 @@ Creates links to each form part for the given form subject. The load_multipart_
60
60
  == Future work
61
61
 
62
62
  * Fix the index links loading so that the user does not have to explicitly call a method when they are needed
63
- * Improve the behavior of the previous and next links in the breadcrumb
64
- * Add A controller and views generator to generate the files in the rails project so they can be edited for project specific needs
65
63
  * Improve code quality of the mixin where it makes variables available to views
66
- * Move the logic in the multipart_form partials to heleprs
67
64
  * 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.
68
65
 
69
66
  == Contributing to acts_as_multipart_form
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "acts_as_multipart_form"
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremiah Hemphill", "Ethan Pemble"]
12
- s.date = "2012-02-29"
12
+ s.date = "2012-03-14"
13
13
  s.description = "Multipart forms using custom routes"
14
14
  s.email = "jeremiah@cloudspace.com"
15
15
  s.extra_rdoc_files = [
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
+ ".rspec",
20
21
  "CHANGELOG",
21
22
  "Gemfile",
22
23
  "Gemfile.lock",
@@ -1,7 +1,7 @@
1
1
  <div class='multipart_form_breadcrumb'>
2
2
  <% if ActsAsMultipartForm.config.show_previous_next_links %>
3
3
  <div class='multipart_form_breadcrumb_previous'>
4
- <%= link_to "Previous", send(@multipart_form_path, :id => @form_subject.id, :multipart_form_part => @previous_multipart_form_part ) %>
4
+ <%= link_to "Previous", send(@multipart_form_path, :id => @form_subject.id, :multipart_form_part => @breadcrumb_links[:previous] ) %>
5
5
  </div>
6
6
  <% end %>
7
7
  <div class='multipart_form_breadcrumb_parts'>
@@ -15,7 +15,7 @@
15
15
  </div>
16
16
  <% if ActsAsMultipartForm.config.show_previous_next_links %>
17
17
  <div class='multipart_form_breadcrumb_next'>
18
- <%= link_to "Next", send(@multipart_form_path, :id => @form_subject.id, :multipart_form_part => @next_multipart_form_part ) %>
18
+ <%= link_to "Next", send(@multipart_form_path, :id => @form_subject.id, :multipart_form_part => @breadcrumb_links[:next] ) %>
19
19
  </div>
20
20
  <% end %>
21
21
  </div>
@@ -1,6 +1,5 @@
1
1
  <div class='multipart_form_index_links'>
2
2
  <div class='multipart_form_index_links_links'>
3
- <% debugger %>
4
3
  <% @multipart_form_index_parts[form_subject.id][:parts].each do |part| %>
5
4
  <% if ActsAsMultipartForm.config.use_numbered_parts_on_index %>
6
5
  <%= link_to part[:number].to_s, send(@multipart_form_path, :id => form_subject.id, :multipart_form_part => part[:name]) %>
@@ -137,12 +137,17 @@ module ActsAsMultipartForm
137
137
  part = get_previous_multipart_form_part(form_name, part)
138
138
  end
139
139
  end
140
- # get two previous parts so the previous link works
141
- previous_part = get_previous_multipart_form_part(form_name, part)
142
- @previous_multipart_form_part = get_previous_multipart_form_part(form_name, previous_part).to_s
140
+
141
+ # move forward or backwards 2 parts for the previous and next links on the bredcrumb
142
+ skip_update_part = true
143
+ @breadcrumb_links= {
144
+ :previous => get_previous_multipart_form_part(form_name, part, skip_update_part).to_s,
145
+ :next => get_next_multipart_form_part(form_name, part, skip_update_part).to_s,
146
+ }
147
+
143
148
  # needs to be a string so that the view can read it
144
- @multipart_form_part = part.to_s
145
149
  @next_multipart_form_part = get_next_multipart_form_part(form_name, part).to_s
150
+ @multipart_form_part = part.to_s
146
151
  @form_subject = form_subject
147
152
  @available_multipart_form_parts = get_available_multipart_form_parts(form_name, in_progress_form.last_completed_step)
148
153
  @multipart_form_path = (self.multipart_forms[form_name][:form_route] + "_path").to_sym
@@ -158,29 +163,45 @@ module ActsAsMultipartForm
158
163
  self.multipart_forms.keys.include?(sym)
159
164
  end
160
165
 
161
- # Gets the next multipart form part for the form or returns the current part if it is first
166
+ # Gets the previous multipart form part for the form or returns the current part if it is first
162
167
  #
163
168
  # @param [Symbol] form The name of the multipart form
164
169
  # @param [Symbol] part The name of the current part
170
+ # @param [Boolean] skip_update_part If set to true, moves back two parts instead of one
165
171
  # @returns [Symbol] The name of the next part
166
- def get_previous_multipart_form_part(form, part)
172
+ def get_previous_multipart_form_part(form, part, skip_update_part = false)
167
173
  part_index = self.multipart_forms[form][:parts].index(part)
168
- if part_index > 0
169
- return self.multipart_forms[form][:parts][part_index - 1]
174
+
175
+ if skip_update_part
176
+ prev_part_distance = 2
170
177
  else
171
- return part
178
+ prev_part_distance = 1
179
+ end
180
+
181
+ if part_index - prev_part_distance >= 0
182
+ return self.multipart_forms[form][:parts][part_index - prev_part_distance]
183
+ else
184
+ return self.multipart_forms[form][:parts].first
172
185
  end
173
186
  end
174
187
 
175
- # Gets the previous multipart form part for the form or returns the current part if it is first
188
+ # Gets the next multipart form part for the form or returns the current part if it is first
176
189
  #
177
190
  # @param [Symbol] form The name of the multipart form
178
191
  # @param [Symbol] part The name of the current part
192
+ # @param [Boolean] skip_update_part If set to true, moves forward two parts instead of one
179
193
  # @returns [Symbol] The name of the previous part
180
- def get_next_multipart_form_part(form, part)
194
+ def get_next_multipart_form_part(form, part, skip_update_part = false)
181
195
  part_index = self.multipart_forms[form][:parts].index(part)
182
- if part_index < self.multipart_forms[form][:parts].length - 1
183
- return self.multipart_forms[form][:parts][part_index + 1]
196
+
197
+ if skip_update_part
198
+ next_part_distance = 2
199
+ else
200
+ next_part_distance = 1
201
+ end
202
+
203
+ if part_index < self.multipart_forms[form][:parts].length - next_part_distance
204
+ return self.multipart_forms[form][:parts][part_index + next_part_distance]
184
205
  else
185
206
  return part
186
207
  end
@@ -34,7 +34,7 @@ describe ActsAsMultipartForm::MultipartFormInController do
34
34
  describe "get_next_multipart_form_part method" do
35
35
  before(:each) do
36
36
  @controller = PeopleController.new
37
- @controller.multipart_forms[:hire_form][:parts] = [:person_info, :job_info]
37
+ @controller.multipart_forms[:hire_form][:parts] = [:person_info, :person_info_update, :job_info, :job_info_update]
38
38
  end
39
39
 
40
40
  it "should respond to get_next_multipart_form_part" do
@@ -42,18 +42,27 @@ describe ActsAsMultipartForm::MultipartFormInController do
42
42
  end
43
43
 
44
44
  it "should return the next part" do
45
- @controller.get_next_multipart_form_part(:hire_form, :person_info).should == :job_info
45
+ @controller.get_next_multipart_form_part(:hire_form, :person_info).should == :person_info_update
46
46
  end
47
47
 
48
48
  it "should return the current part if on the last part" do
49
- @controller.get_next_multipart_form_part(:hire_form, :job_info).should == :job_info
49
+ @controller.get_next_multipart_form_part(:hire_form, :job_info_update).should == :job_info_update
50
+ end
51
+
52
+ it "should return the second next part if skip_update_part is set to true" do
53
+ @controller.get_next_multipart_form_part(:hire_form, :person_info, true).should == :job_info
54
+ end
55
+
56
+ it "should return the current part if skip update part is set and on the last or second to last part" do
57
+ @controller.get_next_multipart_form_part(:hire_form, :job_info_update, true).should == :job_info_update
58
+ @controller.get_next_multipart_form_part(:hire_form, :job_info, true).should == :job_info
50
59
  end
51
60
  end
52
61
 
53
62
  describe "get_previous_multipart_form_part method" do
54
63
  before(:each) do
55
64
  @controller = PeopleController.new
56
- @controller.multipart_forms[:hire_form][:parts] = [:person_info, :job_info]
65
+ @controller.multipart_forms[:hire_form][:parts] = [:person_info, :person_info_update, :job_info, :job_info_update]
57
66
  end
58
67
 
59
68
  it "should respond to get_previous_multipart_form_part" do
@@ -61,12 +70,21 @@ describe ActsAsMultipartForm::MultipartFormInController do
61
70
  end
62
71
 
63
72
  it "should return the previous part" do
64
- @controller.get_previous_multipart_form_part(:hire_form, :job_info).should == :person_info
73
+ @controller.get_previous_multipart_form_part(:hire_form, :job_info).should == :person_info_update
65
74
  end
66
75
 
67
76
  it "Should return the current part if on the first part" do
68
77
  @controller.get_previous_multipart_form_part(:hire_form, :person_info).should == :person_info
69
78
  end
79
+
80
+ it "should return the second previous part if skip_update_part is set to true" do
81
+ @controller.get_previous_multipart_form_part(:hire_form, :job_info, true).should == :person_info
82
+ end
83
+
84
+ it "should return the first part if skip update part is set to true and on the first or second part" do
85
+ @controller.get_previous_multipart_form_part(:hire_form, :person_info, true).should == :person_info
86
+ @controller.get_previous_multipart_form_part(:hire_form, :person_info_update, true).should == :person_info
87
+ end
70
88
  end
71
89
 
72
90
  describe "last_multipart_form_part? method" 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.6
5
+ version: 0.0.7
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: 2012-02-29 00:00:00 Z
14
+ date: 2012-03-14 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -155,6 +155,7 @@ extra_rdoc_files:
155
155
  - LICENSE.txt
156
156
  - README.rdoc
157
157
  files:
158
+ - .rspec
158
159
  - CHANGELOG
159
160
  - Gemfile
160
161
  - Gemfile.lock
@@ -257,7 +258,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
257
258
  requirements:
258
259
  - - ">="
259
260
  - !ruby/object:Gem::Version
260
- hash: 3542899139585014364
261
+ hash: 3192784938124864737
261
262
  segments:
262
263
  - 0
263
264
  version: "0"