Commit 15829a14bbcbda0869d7dbdbc959be009a0905ac

Authored by Daniela Feitosa
Committed by Joenio Costa
1 parent 5ca65170

Fixed redirections of noosfero

After creation/edition of an article, the user is redirected to the article
Used back_to to store the page to return

(ActionItem1424)
app/controllers/my_profile/cms_controller.rb
... ... @@ -81,14 +81,11 @@ class CmsController < MyProfileController
81 81 @type = params[:type] || @article.class.to_s
82 82  
83 83 refuse_blocks
84   - if !@article.nil? && @article.blog? || !@type.nil? && @type == 'Blog'
85   - @back_url = url_for(:controller => 'profile_editor', :profile => profile.identifier)
86   - end
87   - record_coming_from_public_view
  84 + record_coming
88 85 if request.post?
89 86 @article.last_changed_by = user
90 87 if @article.update_attributes(params[:article])
91   - redirect_back
  88 + redirect_to @article.view_url
92 89 return
93 90 end
94 91 end
... ... @@ -99,6 +96,7 @@ class CmsController < MyProfileController
99 96  
100 97 # user must choose an article type first
101 98  
  99 + record_coming
102 100 @type = params[:type]
103 101 if @type.blank?
104 102 @article_types = []
... ... @@ -110,12 +108,9 @@ class CmsController < MyProfileController
110 108 })
111 109 end
112 110 @parent_id = params[:parent_id]
113   - render :action => 'select_article_type', :layout => false
  111 + render :action => 'select_article_type', :layout => false, :back_to => @back_to
114 112 return
115 113 else
116   - if @type == 'Blog'
117   - @back_url = url_for(:controller => 'profile_editor', :profile => profile.identifier)
118   - end
119 114 refuse_blocks
120 115 end
121 116  
... ... @@ -131,13 +126,11 @@ class CmsController < MyProfileController
131 126 @parent_id = parent.id
132 127 end
133 128  
134   - record_creating_from_public_view
135   -
136 129 @article.profile = profile
137 130 @article.last_changed_by = user
138 131 if request.post?
139 132 if @article.save
140   - redirect_back
  133 + redirect_to @article.view_url
141 134 return
142 135 end
143 136 end
... ... @@ -159,29 +152,36 @@ class CmsController < MyProfileController
159 152 @article = @parent = check_parent(params[:parent_id])
160 153 @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier
161 154 @folders = Folder.find(:all, :conditions => { :profile_id => profile })
162   - record_coming_from_public_view if @article
  155 + @media_listing = params[:media_listing]
  156 + if @article && !@media_listing
  157 + record_coming
  158 + end
163 159 if request.post? && params[:uploaded_files]
164 160 params[:uploaded_files].each do |file|
165 161 @uploaded_files << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => @parent) unless file == ''
166 162 end
167 163 @errors = @uploaded_files.select { |f| f.errors.any? }
168   - @back_to = params[:back_to]
169 164 if @errors.any?
170   - if @back_to && @back_to == 'media_listing'
  165 + if @media_listing
171 166 flash[:notice] = _('Could not upload all files')
172   - redirect_back
  167 + redirect_to :action => 'media_listing'
173 168 else
174 169 render :action => 'upload_files', :parent_id => @parent_id
175 170 end
176 171 else
177   - if params[:back_to]
178   - redirect_back
  172 + if @media_listing
  173 + flash[:notice] = _('All files were uploaded successfully')
  174 + redirect_to :action => 'media_listing'
179 175 else
180   - redirect_to( if @parent
181   - {:action => 'view', :id => @parent.id}
  176 + if @back_to
  177 + redirect_to @back_to
182 178 else
183   - {:action => 'index'}
184   - end)
  179 + redirect_to( if @parent
  180 + {:action => 'view', :id => @parent.id}
  181 + else
  182 + {:action => 'index'}
  183 + end)
  184 + end
185 185 end
186 186 end
187 187 end
... ... @@ -212,7 +212,7 @@ class CmsController &lt; MyProfileController
212 212  
213 213 def publish
214 214 @article = profile.articles.find(params[:id])
215   - record_coming_from_public_view
  215 + record_coming
216 216 @groups = profile.memberships - [profile]
217 217 @marked_groups = []
218 218 groups_ids = profile.memberships.map{|m|m.id.to_s}
... ... @@ -233,7 +233,11 @@ class CmsController &lt; MyProfileController
233 233 end
234 234 if @failed.blank?
235 235 flash[:notice] = _("Your publish request was sent successfully")
236   - redirect_back
  236 + if @back_to
  237 + redirect_to @back_to
  238 + else
  239 + redirect_to @article.view_url
  240 + end
237 241 end
238 242 end
239 243 end
... ... @@ -258,7 +262,7 @@ class CmsController &lt; MyProfileController
258 262 @image_folders = @folders.select {|f| f.children.any? {|c| c.image?} }
259 263 @document_folders = @folders.select {|f| f.children.any? {|c| !c.image? && c.kind_of?(UploadedFile) } }
260 264  
261   - @back_to = 'media_listing'
  265 + @media_listing = true
262 266  
263 267 respond_to do |format|
264 268 format.html { render :layout => false}
... ... @@ -273,42 +277,11 @@ class CmsController &lt; MyProfileController
273 277  
274 278 protected
275 279  
276   - def redirect_back
277   - if params[:back_to] == 'control_panel'
278   - redirect_to :controller => 'profile_editor', :profile => @profile.identifier
279   - elsif params[:back_to] == 'public_view'
280   - redirect_to @article.view_url.merge(Noosfero.url_options)
281   - elsif params[:back_to] == 'media_listing'
282   - redirect_to :action => 'media_listing'
283   - elsif @article.parent
284   - redirect_to :action => 'view', :id => @article.parent
285   - elsif @article.folder? && !@article.blog? && @article.parent
286   - redirect_to :action => 'index'
  280 + def record_coming
  281 + if request.post?
  282 + @back_to = params[:back_to]
287 283 else
288   - redirect_back_or_default :action => 'index'
289   - end
290   - end
291   -
292   - def record_coming_from_public_view
293   - referer = request.referer
294   - referer.gsub!(/\?.*/, '') unless referer.nil?
295   - if (maybe_ssl(url_for(@article.url)).include?(referer)) || (@article == profile.home_page && maybe_ssl(url_for(profile.url)).include?(referer))
296   - @back_to = 'public_view'
297   - @back_url = @article.view_url
298   - end
299   - if !request.post? and @article.blog?
300   - store_location(request.referer)
301   - end
302   - end
303   -
304   - def record_creating_from_public_view
305   - referer = request.referer
306   - if (referer =~ Regexp.new("^#{(url_for(profile.url).sub('https:', 'https?:'))}")) || params[:back_to] == 'public_view'
307   - @back_to = 'public_view'
308   - @back_url = referer
309   - end
310   - if !request.post? and @article.blog?
311   - store_location(request.referer)
  284 + @back_to = params[:back_to] || request.referer
312 285 end
313 286 end
314 287  
... ...
app/controllers/public/content_viewer_controller.rb
... ... @@ -67,9 +67,6 @@ class ContentViewerController &lt; ApplicationController
67 67 return
68 68 end
69 69  
70   - # store location if the page is not a download
71   - store_location
72   -
73 70 @form_div = params[:form]
74 71  
75 72 if request.post? && params[:comment] && params[self.icaptcha_field].blank? && params[:confirm] == 'true' && @page.accept_comments?
... ...
app/controllers/public/invite_controller.rb
... ... @@ -23,7 +23,11 @@ class InviteController &lt; PublicController
23 23 elsif !contacts_to_invite.empty?
24 24 Invitation.invite(current_user.person, contacts_to_invite, params[:mail_template], profile)
25 25 flash[:notice] = _('Your invitations have been sent.')
26   - redirect_back_or_default :controller => 'profile'
  26 + if profile.person?
  27 + redirect_to :controller => 'friends'
  28 + else
  29 + redirect_to :controller => 'profile_members'
  30 + end
27 31 else
28 32 flash.now[:notice] = _('Please enter a valid email address.')
29 33 end
... ... @@ -31,8 +35,6 @@ class InviteController &lt; PublicController
31 35 @manual_import_addresses = manual_import_addresses || ""
32 36 @webmail_import_addresses = webmail_import_addresses || []
33 37 end
34   - else
35   - store_location(request.referer)
36 38 end
37 39 @import_from = params[:import_from] || "manual"
38 40 @mail_template = params[:mail_template] || environment.invitation_mail_template(profile)
... ...
app/controllers/public/profile_controller.rb
... ... @@ -83,10 +83,9 @@ class ProfileController &lt; PublicController
83 83 redirect_to_before_join
84 84 end
85 85 else
86   - store_location(request.referer)
87 86 if current_user.person.memberships.include?(profile)
88 87 flash[:notice] = _('You are already a member of "%s"') % profile.name
89   - redirect_back_or_default profile.url
  88 + redirect_to profile.url
90 89 return
91 90 end
92 91 if request.xhr?
... ... @@ -97,15 +96,16 @@ class ProfileController &lt; PublicController
97 96  
98 97 def leave
99 98 @wizard = params[:wizard]
  99 + @back_to = params[:back_to] || request.referer
100 100 if request.post? && params[:confirmation]
101 101 profile.remove_member(current_user.person)
102 102 if @wizard
103 103 redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true
104 104 else
105   - redirect_back_or_default profile.url
  105 + back = @back_to || profile.url
  106 + redirect_to back
106 107 end
107 108 else
108   - store_location(request.referer)
109 109 if request.xhr?
110 110 render :layout => false
111 111 end
... ... @@ -146,7 +146,9 @@ class ProfileController &lt; PublicController
146 146 end
147 147  
148 148 def store_before_join
149   - session[:before_join] = request.referer unless logged_in?
  149 + if session[:before_join].nil?
  150 + session[:before_join] = request.referer
  151 + end
150 152 end
151 153  
152 154 def redirect_to_before_join
... ... @@ -155,7 +157,7 @@ class ProfileController &lt; PublicController
155 157 session[:before_join] = nil
156 158 redirect_to back
157 159 else
158   - redirect_back_or_default profile.url
  160 + redirect_to profile.url
159 161 end
160 162 end
161 163  
... ...
app/models/profile.rb
... ... @@ -383,7 +383,7 @@ class Profile &lt; ActiveRecord::Base
383 383  
384 384 def url_options
385 385 options = { :host => default_hostname, :profile => (own_hostname ? nil : self.identifier) }
386   - options.merge(Noosfero.url_options.merge(options))
  386 + options.merge(Noosfero.url_options)
387 387 end
388 388  
389 389 private :generate_url, :url_options
... ...
app/views/cms/_upload_file_form.rhtml
... ... @@ -15,10 +15,10 @@
15 15  
16 16 <% button_bar do %>
17 17 <%= add_upload_file_field(_('More files'), {:size => size}) %>
18   - <% if @back_to == 'media_listing' %>
  18 + <% if @media_listing %>
19 19 <%= submit_button :save, _('Upload') %>
20   - <% elsif @back_url %>
21   - <%= submit_button :save, _('Upload'), :cancel => @back_url %>
  20 + <% elsif @back_to %>
  21 + <%= submit_button :save, _('Upload'), :cancel => @back_to %>
22 22 <% else %>
23 23 <%= submit_button :save, _('Upload'), :cancel => {:action => (@parent ? 'view' : 'index'), :id => @parent } %>
24 24 <% end %>
... ...
app/views/cms/edit.rhtml
... ... @@ -37,10 +37,8 @@
37 37  
38 38 <% button_bar do %>
39 39 <%= submit_button :save, _('Save') %>
40   - <% if @return_to %>
41   - <%= button :cancel, _('Cancel'), @return_to %>
42   - <% elsif @back_url %>
43   - <%= button :cancel, _('Cancel'), @back_url %>
  40 + <% if @back_to %>
  41 + <%= button :cancel, _('Cancel'), @back_to %>
44 42 <% elsif @parent_id || @article.parent %>
45 43 <%= button :cancel, _('Cancel'), :action => 'view', :id => @parent_id || @article.parent %>
46 44 <% else %>
... ...
app/views/cms/media_listing.rhtml
... ... @@ -39,7 +39,7 @@
39 39 </div>
40 40  
41 41 <% form_for('uploaded_file', :url => {:action => 'upload_files'}, :html => {:multipart => true}) do |f| %>
42   - <%= hidden_field_tag('back_to', @back_to) %>
  42 + <%= hidden_field_tag('media_listing', @media_listing) %>
43 43 <%= render :partial => 'upload_file_form', :locals => { :size => '30' } %>
44 44 <% end %>
45 45 </div><!-- id='media-listing-upload' -->
... ...
app/views/cms/publish.rhtml
... ... @@ -26,7 +26,7 @@
26 26 <% end %>
27 27  
28 28 <% button_bar do %>
29   - <%= submit_button 'spread', _('Publish') %>
  29 + <%= submit_button 'spread', _('Publish'), :cancel => @back_to %>
30 30 <% end %>
31 31 <% end %>
32 32 <% else %>
... ...
app/views/cms/select_article_type.rhtml
... ... @@ -3,7 +3,7 @@
3 3 <ul id="article_types">
4 4 <% for type in @article_types %>
5 5 <li>
6   - <%= link_to type[:short_description], :action => 'new', :type => type[:name], :parent_id => @parent_id %>
  6 + <%= link_to type[:short_description], :action => 'new', :type => type[:name], :parent_id => @parent_id, :back_to => @back_to %>
7 7 <br/> <%= type[:description] %>
8 8 </li>
9 9 <% end %>
... ...
app/views/profile/join.rhtml
... ... @@ -5,6 +5,7 @@
5 5 </p>
6 6  
7 7 <% form_tag do %>
  8 + <%= hidden_field_tag('back_to', @back_to) %>
8 9 <%= hidden_field_tag(:confirmation, 1) %>
9 10 <%= submit_button(:ok, _("Yes, I want to join.") % profile.name) %>
10 11 <% if logged_in? && request.xhr? %>
... ...
app/views/profile/leave.rhtml
... ... @@ -6,6 +6,7 @@
6 6  
7 7 <% form_tag do %>
8 8 <%= hidden_field_tag(:confirmation, 1) %>
  9 + <%= hidden_field_tag(:back_to, @back_to) %>
9 10 <%= submit_button(:ok, _("Yes, I want to leave.") % profile.name) %>
10 11 <% if logged_in? && request.xhr? %>
11 12 <%= lightbox_close_button(_("No, I don't want")) %>
... ...
features/blog.feature
... ... @@ -15,25 +15,24 @@ Feature: blog
15 15 Then I should see "My Blog"
16 16 When I fill in "Title" with "My Blog"
17 17 And I press "Save"
18   - And I follow "Control panel"
  18 + And I go to Joao Silva's control panel
19 19 Then I should see "Configure blog"
20 20  
21   - Scenario: redirect to control panel after create blog
  21 + Scenario: redirect to blog after create blog from control panel
22 22 Given I follow "Control panel"
23 23 And I follow "Create blog"
24 24 Then I should see "My Blog"
25 25 When I fill in "Title" with "My Blog"
26 26 And I press "Save"
27   - Then I should be on /myprofile/joaosilva
  27 + Then I should be on /joaosilva/my-blog
28 28  
29   - Scenario: redirect to cms after create blog
  29 + Scenario: redirect to blog after create blog from cms
30 30 Given I follow "Control panel"
31 31 And I follow "Manage Content"
32 32 When I follow "New Blog"
33   - Then I should see "My Blog"
34   - When I fill in "Title" with "My Blog"
  33 + And I fill in "Title" with "Blog from cms"
35 34 And I press "Save"
36   - Then I should be on /myprofile/joaosilva/cms
  35 + Then I should be on /joaosilva/blog-from-cms
37 36  
38 37 Scenario: create multiple blogs
39 38 Given I follow "Control panel"
... ... @@ -41,11 +40,13 @@ Feature: blog
41 40 And I follow "New Blog"
42 41 And I fill in "Title" with "Blog One"
43 42 And I press "Save"
  43 + Then I follow "Control panel"
  44 + And I follow "Manage Content"
44 45 And I follow "New Blog"
45 46 And I fill in "Title" with "Blog Two"
46 47 And I press "Save"
47 48 Then I should not see "error"
48   - And I should be on /myprofile/joaosilva/cms
  49 + And I should be on /joaosilva/blog-two
49 50  
50 51 Scenario: cancel button back to cms
51 52 Given I follow "Control panel"
... ...
features/create_article.feature
... ... @@ -1,61 +0,0 @@
1   -Feature: create article
2   - As a noosfero user
3   - I want to create new articles
4   -
5   - Background:
6   - Given I am on the homepage
7   - And the following users
8   - | login | name |
9   - | joaosilva | Joao Silva |
10   - And I am logged in as "joaosilva"
11   -
12   - Scenario: create a folder
13   - Given I am on Joao Silva's control panel
14   - And I follow "Manage Content"
15   - When I follow "New Folder"
16   - And I fill in "Title" with "My Folder"
17   - And I press "Save"
18   - And I go to Joao Silva's control panel
19   - Then I should see "My Folder"
20   -
21   - Scenario: redirect to the created folder
22   - Given I am on Joao Silva's control panel
23   - And I follow "Manage Content"
24   - When I follow "New Folder"
25   - And I fill in "Title" with "My Folder"
26   - And I press "Save"
27   - Then I should see "Content management"
28   - And I should be on Joao Silva's cms
29   -
30   - Scenario: cancel button back to cms
31   - Given I follow "Control panel"
32   - And I follow "Manage Content"
33   - And I follow "New Folder"
34   - When I follow "Cancel"
35   - Then I should be on Joao Silva's cms
36   -
37   - Scenario: display tag list field when creating event
38   - Given I follow "Control panel"
39   - And I follow "Manage Content"
40   - And I follow "New article"
41   - When I follow "Event"
42   - Then I should see "Tag list"
43   -
44   - Scenario: display tag list field when creating folder
45   - Given I follow "Control panel"
46   - And I follow "Manage Content"
47   - When I follow "New folder"
48   - Then I should see "Tag list"
49   -
50   - Scenario: create new article with tags
51   - Given I follow "Control panel"
52   - And I follow "Manage Content"
53   - And I follow "New article"
54   - When I follow "Text article with Textile markup language"
55   - Then I should see "Tag list"
56   - When I fill in "Title" with "Article with tags"
57   - And I fill in "Tag list" with "aurium, bug"
58   - And I press "Save"
59   - And I go to /joaosilva/article-with-tags
60   - Then I should see "aurium" within "#article-tags a:first"
61   - And I should see "bug" within "#article-tags a:last"
features/edit_article.feature 0 → 100644
... ... @@ -0,0 +1,116 @@
  1 +Feature: edit article
  2 + As a noosfero user
  3 + I want to create and edit articles
  4 +
  5 + Background:
  6 + Given I am on the homepage
  7 + And the following users
  8 + | login | name |
  9 + | joaosilva | Joao Silva |
  10 + And the following articles
  11 + | owner | name | body |
  12 + | joaosilva | Save the whales | ... |
  13 + And I am logged in as "joaosilva"
  14 +
  15 + Scenario: create a folder
  16 + Given I am on Joao Silva's control panel
  17 + And I follow "Manage Content"
  18 + When I follow "New Folder"
  19 + And I fill in "Title" with "My Folder"
  20 + And I press "Save"
  21 + And I go to Joao Silva's control panel
  22 + Then I should see "My Folder"
  23 +
  24 + Scenario: redirect to the created folder
  25 + Given I am on Joao Silva's control panel
  26 + And I follow "Manage Content"
  27 + When I follow "New Folder"
  28 + And I fill in "Title" with "My Folder"
  29 + And I press "Save"
  30 + Then I should see "My Folder"
  31 + And I should be on /joaosilva/my-folder
  32 +
  33 + Scenario: cancel button back to cms
  34 + Given I follow "Control panel"
  35 + And I follow "Manage Content"
  36 + And I follow "New Folder"
  37 + When I follow "Cancel"
  38 + Then I should be on Joao Silva's cms
  39 +
  40 + Scenario: display tag list field when creating event
  41 + Given I follow "Control panel"
  42 + And I follow "Manage Content"
  43 + And I follow "New article"
  44 + When I follow "Event"
  45 + Then I should see "Tag list"
  46 +
  47 + Scenario: display tag list field when creating folder
  48 + Given I follow "Control panel"
  49 + And I follow "Manage Content"
  50 + When I follow "New folder"
  51 + Then I should see "Tag list"
  52 +
  53 + Scenario: create new article with tags
  54 + Given I follow "Control panel"
  55 + And I follow "Manage Content"
  56 + And I follow "New article"
  57 + When I follow "Text article with Textile markup language"
  58 + Then I should see "Tag list"
  59 + When I fill in "Title" with "Article with tags"
  60 + And I fill in "Tag list" with "aurium, bug"
  61 + And I press "Save"
  62 + And I go to /joaosilva/article-with-tags
  63 + Then I should see "aurium" within "#article-tags a:first"
  64 + And I should see "bug" within "#article-tags a:last"
  65 +
  66 + Scenario: redirect to the created article
  67 + Given I am on Joao Silva's control panel
  68 + And I follow "Manage Content"
  69 + When I follow "New article"
  70 + When I follow "Text article with visual editor"
  71 + And I fill in "Title" with "My Article"
  72 + And I press "Save"
  73 + Then I should see "My Article"
  74 + And I should be on /joaosilva/my-article
  75 +
  76 + Scenario: edit an article
  77 + Given I am on Joao Silva's sitemap
  78 + And I follow "Save the whales"
  79 + And I follow "Edit"
  80 + And I fill in "Title" with "My Article edited"
  81 + When I press "Save"
  82 + Then I should be on /joaosilva/my-article-edited
  83 +
  84 + Scenario: cancel button back to article when edit
  85 + Given I am on Joao Silva's sitemap
  86 + And I follow "Save the whales"
  87 + And I follow "Edit"
  88 + When I follow "Cancel"
  89 + Then I should be on /joaosilva/save-the-whales
  90 +
  91 + Scenario: create an article inside a folder
  92 + Given I am on Joao Silva's control panel
  93 + And I follow "Manage Content"
  94 + And I follow "New Folder"
  95 + And I fill in "Title" with "My Folder"
  96 + And I press "Save"
  97 + Then I should be on /joaosilva/my-folder
  98 + When I follow "New article"
  99 + And I follow "Text article with visual editor"
  100 + And I fill in "Title" with "My Article"
  101 + And I press "Save"
  102 + Then I should see "My Article"
  103 + And I should be on /joaosilva/my-folder/my-article
  104 +
  105 + Scenario: cancel button back to folder after giving up creating
  106 + Given I am on Joao Silva's control panel
  107 + And I follow "Manage Content"
  108 + And I follow "New Folder"
  109 + And I fill in "Title" with "My Folder"
  110 + And I press "Save"
  111 + Then I should be on /joaosilva/my-folder
  112 + When I follow "New article"
  113 + And I follow "Text article with visual editor"
  114 + When I follow "Cancel"
  115 + And I should be on /joaosilva/my-folder
  116 +
... ...
lib/noosfero.rb
... ... @@ -55,6 +55,8 @@ module Noosfero
55 55 def self.url_options
56 56 if ENV['RAILS_ENV'] == 'development'
57 57 development_url_options
  58 + elsif ENV['RAILS_ENV'] == 'cucumber'
  59 + {:host => ''}
58 60 else
59 61 {}
60 62 end
... ...
test/functional/cms_controller_test.rb
... ... @@ -478,29 +478,31 @@ class CmsControllerTest &lt; Test::Unit::TestCase
478 478 assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/new?parent_id=#{f.id}&amp;type=Folder" }
479 479 end
480 480  
481   - should 'redirect back to index after creating top-level article' do
482   - post :new, :profile => profile.identifier, :type => 'TextileArticle', :article => { :name => 'test' }
483   - assert_redirected_to :action => 'index'
  481 + should 'redirect to article after creating top-level article' do
  482 + post :new, :profile => profile.identifier, :type => 'TextileArticle', :article => { :name => 'top-level-article' }
  483 +
  484 + assert_redirected_to @profile.articles.find_by_name('top-level-article').url
484 485 end
485 486  
486   - should 'redirect back to folder after creating article inside it' do
  487 + should 'redirect to article after creating article inside a folder' do
487 488 f = Folder.new(:name => 'f'); profile.articles << f; f.save!
488   - post :new, :profile => profile.identifier, :type => 'TextileArticle', :parent_id => f.id, :article => { :name => 'test' }
489   - assert_redirected_to :action => 'view', :id => f.id
  489 + post :new, :profile => profile.identifier, :type => 'TextileArticle', :parent_id => f.id, :article => { :name => 'article-inside-folder' }
  490 +
  491 + assert_redirected_to @profile.articles.find_by_name('article-inside-folder').url
490 492 end
491 493  
492   - should 'redirect back to index after editing top-level article' do
493   - f = Folder.new(:name => 'f'); profile.articles << f; f.save!
  494 + should 'redirect back to article after editing top-level article' do
  495 + f = Folder.new(:name => 'top-level-article'); profile.articles << f; f.save!
494 496 post :edit, :profile => profile.identifier, :id => f.id
495   - assert_redirected_to :action => 'index'
  497 + assert_redirected_to @profile.articles.find_by_name('top-level-article').url
496 498 end
497 499  
498   - should 'redirect back to folder after editing article inside it' do
  500 + should 'redirect back to article after editing article inside a folder' do
499 501 f = Folder.new(:name => 'f'); profile.articles << f; f.save!
500   - a = TextileArticle.create!(:parent => f, :name => 'test', :profile_id => profile.id)
  502 + a = TextileArticle.create!(:parent => f, :name => 'article-inside-folder', :profile_id => profile.id)
501 503  
502 504 post :edit, :profile => profile.identifier, :id => a.id
503   - assert_redirected_to :action => 'view', :id => f.id
  505 + assert_redirected_to @profile.articles.find_by_name('article-inside-folder').url
504 506 end
505 507  
506 508 should 'point back to index when cancelling creation of top-level article' do
... ... @@ -604,15 +606,15 @@ class CmsControllerTest &lt; Test::Unit::TestCase
604 606 @request.expects(:referer).returns('http://colivre.net/testinguser/myarticle').at_least_once
605 607  
606 608 get :edit, :profile => 'testinguser', :id => article.id
607   - assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
  609 + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
608 610 assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/testinguser\/myarticle/ }
609 611 end
610 612  
611 613 should 'detect when comming from home page' do
612 614 @request.expects(:referer).returns('http://colivre.net/testinguser').at_least_once
613 615 get :edit, :profile => 'testinguser', :id => @profile.home_page.id
614   - assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
615   - assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/testinguser\/#{@profile.home_page.slug}$/ }
  616 + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
  617 + assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => @request.referer }
616 618 end
617 619  
618 620 should 'go back to public view when saving coming from there' do
... ... @@ -625,7 +627,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
625 627 should 'record as coming from public view when creating article' do
626 628 @request.expects(:referer).returns('http://colivre.net/testinguser/testingusers-home-page').at_least_once
627 629 get :new, :profile => 'testinguser', :type => 'TextileArticle'
628   - assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
  630 + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
629 631 assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => 'http://colivre.net/testinguser/testingusers-home-page' }
630 632 end
631 633  
... ... @@ -835,17 +837,18 @@ class CmsControllerTest &lt; Test::Unit::TestCase
835 837 assert :tag => 'input', :attributes => {:name => 'article[notify_comments]', :value => 1}
836 838 end
837 839  
838   - should 'back to control panel after create blog' do
  840 + should 'go to blog after create it' do
839 841 assert_difference Blog, :count do
840 842 post :new, :type => Blog.name, :profile => profile.identifier, :article => { :name => 'my-blog' }, :back_to => 'control_panel'
841   - assert_redirected_to :controller => 'profile_editor', :profile => profile.identifier
842 843 end
  844 + assert_redirected_to @profile.articles.find_by_name('my-blog').view_url
843 845 end
844 846  
845   - should 'back to control panel after config blog' do
  847 + should 'back to blog after config blog' do
846 848 profile.articles << Blog.new(:name => 'my-blog', :profile => profile)
847   - post :edit, :profile => profile.identifier, :id => profile.blog.id, :back_to => 'control_panel'
848   - assert_redirected_to :controller => 'profile_editor', :profile => profile.identifier
  849 + post :edit, :profile => profile.identifier, :id => profile.blog.id
  850 +
  851 + assert_redirected_to @profile.articles.find_by_name('my-blog').view_url
849 852 end
850 853  
851 854 should 'back to control panel if cancel create blog' do
... ... @@ -885,27 +888,26 @@ class CmsControllerTest &lt; Test::Unit::TestCase
885 888 @request.expects(:referer).returns("http://colivre.net/#{profile.identifier}/#{folder.slug}").at_least_once
886 889  
887 890 get :upload_files, :profile => profile.identifier, :parent_id => folder.id
888   - assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
  891 + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
889 892 assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/#{profile.identifier}\/#{folder.slug}/ }
890 893 end
891 894  
892 895 should 'detect when comming from home page to upload files' do
893 896 folder = Folder.create!(:name => 'testfolder', :profile => profile)
894   - profile.expects(:home_page).returns(folder).at_least_once
895   -
896 897 @request.expects(:referer).returns("http://colivre.net/#{profile.identifier}").at_least_once
897 898 @controller.stubs(:profile).returns(profile)
898 899 get :upload_files, :profile => profile.identifier, :parent_id => folder.id
899   - assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
900   - assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/#{profile.identifier}\/#{profile.home_page.slug}$/ }
  900 + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
  901 + assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => @request.referer }
901 902 end
902 903  
903 904 should 'go back to public view when upload files coming from there' do
904 905 folder = Folder.create!(:name => 'test_folder', :profile => profile)
  906 + @request.expects(:referer).returns(folder.view_url).at_least_once
905 907  
906   - post :upload_files, :profile => profile.identifier, :parent_id => folder.id, :back_to => 'public_view', :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
  908 + post :upload_files, :profile => profile.identifier, :parent_id => folder.id, :back_to => @request.referer, :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
907 909 assert_template nil
908   - assert_redirected_to folder.url
  910 + assert_redirected_to folder.view_url
909 911 end
910 912  
911 913 should 'record when coming from public view on edit files with view true' do
... ... @@ -914,26 +916,25 @@ class CmsControllerTest &lt; Test::Unit::TestCase
914 916 @request.expects(:referer).returns("http://colivre.net/#{profile.identifier}/#{file.slug}?view=true").at_least_once
915 917  
916 918 get :edit, :profile => profile.identifier, :id => file.id
917   - assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
  919 + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
918 920 assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/#{profile.identifier}\/#{file.slug}?.*view=true/ }
919 921 end
920 922  
921 923 should 'detect when comming from home page to edit files with view true' do
922 924 file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
923   - profile.expects(:home_page).returns(file).at_least_once
924 925  
925 926 @request.expects(:referer).returns("http://colivre.net/#{profile.identifier}?view=true").at_least_once
926 927 @controller.stubs(:profile).returns(profile)
927 928 get :edit, :profile => profile.identifier, :id => file.id
928   - assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
929   - assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/#{profile.identifier}\/#{profile.home_page.slug}?.*view=true$/ }
  929 + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
  930 + assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => @request.referer }
930 931 end
931 932  
932 933 should 'go back to public view when edit files coming from there with view true' do
933 934 file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
934 935 @request.expects(:referer).returns("http://colivre.net/#{profile.identifier}/#{file.slug}?view=true").at_least_once
935 936  
936   - post :edit, :profile => profile.identifier, :id => file.id, :back_to => 'public_view', :article => {:abstract => 'some description'}
  937 + post :edit, :profile => profile.identifier, :id => file.id, :back_to => @request.referer, :article => {:abstract => 'some description'}
937 938 assert_template nil
938 939 assert_redirected_to file.url.merge(:view => true)
939 940 end
... ... @@ -1107,7 +1108,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
1107 1108  
1108 1109  
1109 1110 should 'redirect to media listing when upload files from there' do
1110   - post :upload_files, :profile => profile.identifier, :back_to => 'media_listing', :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
  1111 + post :upload_files, :profile => profile.identifier, :media_listing => true, :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
1111 1112 assert_template nil
1112 1113 assert_redirected_to :action => 'media_listing'
1113 1114 end
... ... @@ -1115,7 +1116,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
1115 1116 should 'redirect to media listing when occur errors when upload files from there' do
1116 1117 file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('files/rails.png', 'image/png'))
1117 1118  
1118   - post :upload_files, :profile => profile.identifier, :back_to => 'media_listing', :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
  1119 + post :upload_files, :profile => profile.identifier, :media_listing => true, :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
1119 1120 assert_template nil
1120 1121 assert_redirected_to :action => 'media_listing'
1121 1122 end
... ...
test/functional/invite_controller_test.rb
... ... @@ -13,7 +13,7 @@ class InviteControllerTest &lt; ActionController::TestCase
13 13 should 'actually invite manually added address with friend object' do
14 14 assert_difference InviteFriend, :count, 1 do
15 15 post :friends, :profile => profile.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: <url>", :step => 2
16   - assert_redirected_to :controller => 'profile'
  16 + assert_redirected_to :controller => 'friends'
17 17 end
18 18 end
19 19  
... ... @@ -83,4 +83,15 @@ class InviteControllerTest &lt; ActionController::TestCase
83 83 assert_response 403 # forbidden
84 84 end
85 85  
  86 + should 'redirect to friends after invitation if profile is a person' do
  87 + post :friends, :profile => profile.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: <url>", :step => 2
  88 + assert_redirected_to :controller => 'friends'
  89 + end
  90 +
  91 + should 'redirect to friends after invitation if profile is not a person' do
  92 + community.add_admin(profile)
  93 + post :friends, :profile => community.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: <url>", :step => 2
  94 + assert_redirected_to :controller => 'profile_members'
  95 + end
  96 +
86 97 end
... ...
test/functional/profile_controller_test.rb
... ... @@ -574,10 +574,10 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
574 574 community = Community.create!(:name => 'my test community')
575 575 community.add_member(profile)
576 576  
577   - @request.session[:return_to] = "/profile/#{community.identifier}/to_go"
  577 + @request.expects(:referer).returns("/profile/#{community.identifier}/to_go").at_least_once
578 578 login_as(profile.identifier)
579 579  
580   - post :leave, :profile => community.identifier, :confirmation => '1'
  580 + post :leave, :profile => community.identifier, :confirmation => '1', :back_to => @request.referer
581 581  
582 582 assert_redirected_to "/profile/#{community.identifier}/to_go"
583 583 end
... ... @@ -586,30 +586,28 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
586 586 community = Community.create!(:name => 'my test community')
587 587 login_as(profile.identifier)
588 588  
589   - assert_nil @request.session[:return_to]
590   - @request.expects(:referer).returns("/profile/redirect_to")
  589 + @request.expects(:referer).returns("/profile/redirect_to").at_least_once
591 590  
592 591 get :leave, :profile => community.identifier
593 592  
594   - assert_equal '/profile/redirect_to', @request.session[:return_to]
  593 + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
595 594 end
596 595  
597 596 should 'store referer location when request join via get' do
598 597 community = Community.create!(:name => 'my test community')
599 598 login_as(profile.identifier)
600 599  
601   - assert_nil @request.session[:return_to]
602   - @request.expects(:referer).returns("/profile/redirect_to").at_least_once
  600 + @request.session[:before_join] = "/profile/redirect_to"
603 601  
604 602 get :join, :profile => community.identifier
605 603  
606   - assert_equal '/profile/redirect_to', @request.session[:return_to]
  604 + assert_equal '/profile/redirect_to', @request.session[:before_join]
607 605 end
608 606  
609 607 should 'redirect to stored location after join community' do
610 608 community = Community.create!(:name => 'my test community')
611 609  
612   - @request.session[:return_to] = "/profile/#{community.identifier}/to_go"
  610 + @request.expects(:referer).returns("/profile/#{community.identifier}/to_go")
613 611 login_as(profile.identifier)
614 612  
615 613 post :join, :profile => community.identifier, :confirmation => '1'
... ... @@ -630,7 +628,7 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
630 628 should 'redirect to location before login after join community' do
631 629 community = Community.create!(:name => 'my test community')
632 630  
633   - @request.session[:return_to] = "/profile/#{community.identifier}/to_go"
  631 + @request.expects(:referer).returns("/profile/#{community.identifier}/to_go")
634 632 login_as(profile.identifier)
635 633  
636 634 post :join, :profile => community.identifier, :confirmation => '1'
... ...
test/integration/manage_documents_test.rb
... ... @@ -29,7 +29,7 @@ class ManageDocumentsTest &lt; ActionController::IntegrationTest
29 29 assert_response :redirect
30 30 follow_redirect!
31 31 a = Article.find_by_path('my-article')
32   - assert_equal "/myprofile/myuser/cms", path
  32 + assert_equal "/myuser/#{a.slug}", path
33 33 end
34 34  
35 35 def test_update_of_an_existing_article
... ... @@ -62,7 +62,7 @@ class ManageDocumentsTest &lt; ActionController::IntegrationTest
62 62 assert_response :redirect
63 63 follow_redirect!
64 64 a = Article.find_by_path('my-article')
65   - assert_equal "/myprofile/myuser/cms", path
  65 + assert_equal "/myuser/#{a.slug}", path
66 66 end
67 67  
68 68 def test_removing_an_article
... ...