diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb
index 849fdbe..206486e 100644
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -81,14 +81,11 @@ class CmsController < MyProfileController
@type = params[:type] || @article.class.to_s
refuse_blocks
- if !@article.nil? && @article.blog? || !@type.nil? && @type == 'Blog'
- @back_url = url_for(:controller => 'profile_editor', :profile => profile.identifier)
- end
- record_coming_from_public_view
+ record_coming
if request.post?
@article.last_changed_by = user
if @article.update_attributes(params[:article])
- redirect_back
+ redirect_to @article.view_url
return
end
end
@@ -99,6 +96,7 @@ class CmsController < MyProfileController
# user must choose an article type first
+ record_coming
@type = params[:type]
if @type.blank?
@article_types = []
@@ -110,12 +108,9 @@ class CmsController < MyProfileController
})
end
@parent_id = params[:parent_id]
- render :action => 'select_article_type', :layout => false
+ render :action => 'select_article_type', :layout => false, :back_to => @back_to
return
else
- if @type == 'Blog'
- @back_url = url_for(:controller => 'profile_editor', :profile => profile.identifier)
- end
refuse_blocks
end
@@ -131,13 +126,11 @@ class CmsController < MyProfileController
@parent_id = parent.id
end
- record_creating_from_public_view
-
@article.profile = profile
@article.last_changed_by = user
if request.post?
if @article.save
- redirect_back
+ redirect_to @article.view_url
return
end
end
@@ -159,29 +152,36 @@ class CmsController < MyProfileController
@article = @parent = check_parent(params[:parent_id])
@target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier
@folders = Folder.find(:all, :conditions => { :profile_id => profile })
- record_coming_from_public_view if @article
+ @media_listing = params[:media_listing]
+ if @article && !@media_listing
+ record_coming
+ end
if request.post? && params[:uploaded_files]
params[:uploaded_files].each do |file|
@uploaded_files << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => @parent) unless file == ''
end
@errors = @uploaded_files.select { |f| f.errors.any? }
- @back_to = params[:back_to]
if @errors.any?
- if @back_to && @back_to == 'media_listing'
+ if @media_listing
flash[:notice] = _('Could not upload all files')
- redirect_back
+ redirect_to :action => 'media_listing'
else
render :action => 'upload_files', :parent_id => @parent_id
end
else
- if params[:back_to]
- redirect_back
+ if @media_listing
+ flash[:notice] = _('All files were uploaded successfully')
+ redirect_to :action => 'media_listing'
else
- redirect_to( if @parent
- {:action => 'view', :id => @parent.id}
+ if @back_to
+ redirect_to @back_to
else
- {:action => 'index'}
- end)
+ redirect_to( if @parent
+ {:action => 'view', :id => @parent.id}
+ else
+ {:action => 'index'}
+ end)
+ end
end
end
end
@@ -212,7 +212,7 @@ class CmsController < MyProfileController
def publish
@article = profile.articles.find(params[:id])
- record_coming_from_public_view
+ record_coming
@groups = profile.memberships - [profile]
@marked_groups = []
groups_ids = profile.memberships.map{|m|m.id.to_s}
@@ -233,7 +233,11 @@ class CmsController < MyProfileController
end
if @failed.blank?
flash[:notice] = _("Your publish request was sent successfully")
- redirect_back
+ if @back_to
+ redirect_to @back_to
+ else
+ redirect_to @article.view_url
+ end
end
end
end
@@ -258,7 +262,7 @@ class CmsController < MyProfileController
@image_folders = @folders.select {|f| f.children.any? {|c| c.image?} }
@document_folders = @folders.select {|f| f.children.any? {|c| !c.image? && c.kind_of?(UploadedFile) } }
- @back_to = 'media_listing'
+ @media_listing = true
respond_to do |format|
format.html { render :layout => false}
@@ -273,42 +277,11 @@ class CmsController < MyProfileController
protected
- def redirect_back
- if params[:back_to] == 'control_panel'
- redirect_to :controller => 'profile_editor', :profile => @profile.identifier
- elsif params[:back_to] == 'public_view'
- redirect_to @article.view_url.merge(Noosfero.url_options)
- elsif params[:back_to] == 'media_listing'
- redirect_to :action => 'media_listing'
- elsif @article.parent
- redirect_to :action => 'view', :id => @article.parent
- elsif @article.folder? && !@article.blog? && @article.parent
- redirect_to :action => 'index'
+ def record_coming
+ if request.post?
+ @back_to = params[:back_to]
else
- redirect_back_or_default :action => 'index'
- end
- end
-
- def record_coming_from_public_view
- referer = request.referer
- referer.gsub!(/\?.*/, '') unless referer.nil?
- if (maybe_ssl(url_for(@article.url)).include?(referer)) || (@article == profile.home_page && maybe_ssl(url_for(profile.url)).include?(referer))
- @back_to = 'public_view'
- @back_url = @article.view_url
- end
- if !request.post? and @article.blog?
- store_location(request.referer)
- end
- end
-
- def record_creating_from_public_view
- referer = request.referer
- if (referer =~ Regexp.new("^#{(url_for(profile.url).sub('https:', 'https?:'))}")) || params[:back_to] == 'public_view'
- @back_to = 'public_view'
- @back_url = referer
- end
- if !request.post? and @article.blog?
- store_location(request.referer)
+ @back_to = params[:back_to] || request.referer
end
end
diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb
index abcc58e..0c1ab29 100644
--- a/app/controllers/public/content_viewer_controller.rb
+++ b/app/controllers/public/content_viewer_controller.rb
@@ -67,9 +67,6 @@ class ContentViewerController < ApplicationController
return
end
- # store location if the page is not a download
- store_location
-
@form_div = params[:form]
if request.post? && params[:comment] && params[self.icaptcha_field].blank? && params[:confirm] == 'true' && @page.accept_comments?
diff --git a/app/controllers/public/invite_controller.rb b/app/controllers/public/invite_controller.rb
index 8e94e8f..450d13e 100644
--- a/app/controllers/public/invite_controller.rb
+++ b/app/controllers/public/invite_controller.rb
@@ -23,7 +23,11 @@ class InviteController < PublicController
elsif !contacts_to_invite.empty?
Invitation.invite(current_user.person, contacts_to_invite, params[:mail_template], profile)
flash[:notice] = _('Your invitations have been sent.')
- redirect_back_or_default :controller => 'profile'
+ if profile.person?
+ redirect_to :controller => 'friends'
+ else
+ redirect_to :controller => 'profile_members'
+ end
else
flash.now[:notice] = _('Please enter a valid email address.')
end
@@ -31,8 +35,6 @@ class InviteController < PublicController
@manual_import_addresses = manual_import_addresses || ""
@webmail_import_addresses = webmail_import_addresses || []
end
- else
- store_location(request.referer)
end
@import_from = params[:import_from] || "manual"
@mail_template = params[:mail_template] || environment.invitation_mail_template(profile)
diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb
index 316be4c..2540a57 100644
--- a/app/controllers/public/profile_controller.rb
+++ b/app/controllers/public/profile_controller.rb
@@ -83,10 +83,9 @@ class ProfileController < PublicController
redirect_to_before_join
end
else
- store_location(request.referer)
if current_user.person.memberships.include?(profile)
flash[:notice] = _('You are already a member of "%s"') % profile.name
- redirect_back_or_default profile.url
+ redirect_to profile.url
return
end
if request.xhr?
@@ -97,15 +96,16 @@ class ProfileController < PublicController
def leave
@wizard = params[:wizard]
+ @back_to = params[:back_to] || request.referer
if request.post? && params[:confirmation]
profile.remove_member(current_user.person)
if @wizard
redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true
else
- redirect_back_or_default profile.url
+ back = @back_to || profile.url
+ redirect_to back
end
else
- store_location(request.referer)
if request.xhr?
render :layout => false
end
@@ -146,7 +146,9 @@ class ProfileController < PublicController
end
def store_before_join
- session[:before_join] = request.referer unless logged_in?
+ if session[:before_join].nil?
+ session[:before_join] = request.referer
+ end
end
def redirect_to_before_join
@@ -155,7 +157,7 @@ class ProfileController < PublicController
session[:before_join] = nil
redirect_to back
else
- redirect_back_or_default profile.url
+ redirect_to profile.url
end
end
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 2e22541..b7b39b7 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -383,7 +383,7 @@ class Profile < ActiveRecord::Base
def url_options
options = { :host => default_hostname, :profile => (own_hostname ? nil : self.identifier) }
- options.merge(Noosfero.url_options.merge(options))
+ options.merge(Noosfero.url_options)
end
private :generate_url, :url_options
diff --git a/app/views/cms/_upload_file_form.rhtml b/app/views/cms/_upload_file_form.rhtml
index dcf7141..2e3b0f8 100644
--- a/app/views/cms/_upload_file_form.rhtml
+++ b/app/views/cms/_upload_file_form.rhtml
@@ -15,10 +15,10 @@
<% button_bar do %>
<%= add_upload_file_field(_('More files'), {:size => size}) %>
- <% if @back_to == 'media_listing' %>
+ <% if @media_listing %>
<%= submit_button :save, _('Upload') %>
- <% elsif @back_url %>
- <%= submit_button :save, _('Upload'), :cancel => @back_url %>
+ <% elsif @back_to %>
+ <%= submit_button :save, _('Upload'), :cancel => @back_to %>
<% else %>
<%= submit_button :save, _('Upload'), :cancel => {:action => (@parent ? 'view' : 'index'), :id => @parent } %>
<% end %>
diff --git a/app/views/cms/edit.rhtml b/app/views/cms/edit.rhtml
index aee8956..3bebf61 100644
--- a/app/views/cms/edit.rhtml
+++ b/app/views/cms/edit.rhtml
@@ -37,10 +37,8 @@
<% button_bar do %>
<%= submit_button :save, _('Save') %>
- <% if @return_to %>
- <%= button :cancel, _('Cancel'), @return_to %>
- <% elsif @back_url %>
- <%= button :cancel, _('Cancel'), @back_url %>
+ <% if @back_to %>
+ <%= button :cancel, _('Cancel'), @back_to %>
<% elsif @parent_id || @article.parent %>
<%= button :cancel, _('Cancel'), :action => 'view', :id => @parent_id || @article.parent %>
<% else %>
diff --git a/app/views/cms/media_listing.rhtml b/app/views/cms/media_listing.rhtml
index ae510f8..331f375 100644
--- a/app/views/cms/media_listing.rhtml
+++ b/app/views/cms/media_listing.rhtml
@@ -39,7 +39,7 @@
<% form_for('uploaded_file', :url => {:action => 'upload_files'}, :html => {:multipart => true}) do |f| %>
- <%= hidden_field_tag('back_to', @back_to) %>
+ <%= hidden_field_tag('media_listing', @media_listing) %>
<%= render :partial => 'upload_file_form', :locals => { :size => '30' } %>
<% end %>
diff --git a/app/views/cms/publish.rhtml b/app/views/cms/publish.rhtml
index ef429f3..fd06f54 100644
--- a/app/views/cms/publish.rhtml
+++ b/app/views/cms/publish.rhtml
@@ -26,7 +26,7 @@
<% end %>
<% button_bar do %>
- <%= submit_button 'spread', _('Publish') %>
+ <%= submit_button 'spread', _('Publish'), :cancel => @back_to %>
<% end %>
<% end %>
<% else %>
diff --git a/app/views/cms/select_article_type.rhtml b/app/views/cms/select_article_type.rhtml
index 6121063..2534d13 100644
--- a/app/views/cms/select_article_type.rhtml
+++ b/app/views/cms/select_article_type.rhtml
@@ -3,7 +3,7 @@
<% for type in @article_types %>
-
- <%= link_to type[:short_description], :action => 'new', :type => type[:name], :parent_id => @parent_id %>
+ <%= link_to type[:short_description], :action => 'new', :type => type[:name], :parent_id => @parent_id, :back_to => @back_to %>
<%= type[:description] %>
<% end %>
diff --git a/app/views/profile/join.rhtml b/app/views/profile/join.rhtml
index 35a5e8b..1ad934d 100644
--- a/app/views/profile/join.rhtml
+++ b/app/views/profile/join.rhtml
@@ -5,6 +5,7 @@
<% form_tag do %>
+ <%= hidden_field_tag('back_to', @back_to) %>
<%= hidden_field_tag(:confirmation, 1) %>
<%= submit_button(:ok, _("Yes, I want to join.") % profile.name) %>
<% if logged_in? && request.xhr? %>
diff --git a/app/views/profile/leave.rhtml b/app/views/profile/leave.rhtml
index bd3937c..45ffc59 100644
--- a/app/views/profile/leave.rhtml
+++ b/app/views/profile/leave.rhtml
@@ -6,6 +6,7 @@
<% form_tag do %>
<%= hidden_field_tag(:confirmation, 1) %>
+ <%= hidden_field_tag(:back_to, @back_to) %>
<%= submit_button(:ok, _("Yes, I want to leave.") % profile.name) %>
<% if logged_in? && request.xhr? %>
<%= lightbox_close_button(_("No, I don't want")) %>
diff --git a/features/blog.feature b/features/blog.feature
index 4848b0d..f7a680b 100644
--- a/features/blog.feature
+++ b/features/blog.feature
@@ -15,25 +15,24 @@ Feature: blog
Then I should see "My Blog"
When I fill in "Title" with "My Blog"
And I press "Save"
- And I follow "Control panel"
+ And I go to Joao Silva's control panel
Then I should see "Configure blog"
- Scenario: redirect to control panel after create blog
+ Scenario: redirect to blog after create blog from control panel
Given I follow "Control panel"
And I follow "Create blog"
Then I should see "My Blog"
When I fill in "Title" with "My Blog"
And I press "Save"
- Then I should be on /myprofile/joaosilva
+ Then I should be on /joaosilva/my-blog
- Scenario: redirect to cms after create blog
+ Scenario: redirect to blog after create blog from cms
Given I follow "Control panel"
And I follow "Manage Content"
When I follow "New Blog"
- Then I should see "My Blog"
- When I fill in "Title" with "My Blog"
+ And I fill in "Title" with "Blog from cms"
And I press "Save"
- Then I should be on /myprofile/joaosilva/cms
+ Then I should be on /joaosilva/blog-from-cms
Scenario: create multiple blogs
Given I follow "Control panel"
@@ -41,11 +40,13 @@ Feature: blog
And I follow "New Blog"
And I fill in "Title" with "Blog One"
And I press "Save"
+ Then I follow "Control panel"
+ And I follow "Manage Content"
And I follow "New Blog"
And I fill in "Title" with "Blog Two"
And I press "Save"
Then I should not see "error"
- And I should be on /myprofile/joaosilva/cms
+ And I should be on /joaosilva/blog-two
Scenario: cancel button back to cms
Given I follow "Control panel"
diff --git a/features/create_article.feature b/features/create_article.feature
deleted file mode 100644
index 68d478f..0000000
--- a/features/create_article.feature
+++ /dev/null
@@ -1,61 +0,0 @@
-Feature: create article
- As a noosfero user
- I want to create new articles
-
- Background:
- Given I am on the homepage
- And the following users
- | login | name |
- | joaosilva | Joao Silva |
- And I am logged in as "joaosilva"
-
- Scenario: create a folder
- Given I am on Joao Silva's control panel
- And I follow "Manage Content"
- When I follow "New Folder"
- And I fill in "Title" with "My Folder"
- And I press "Save"
- And I go to Joao Silva's control panel
- Then I should see "My Folder"
-
- Scenario: redirect to the created folder
- Given I am on Joao Silva's control panel
- And I follow "Manage Content"
- When I follow "New Folder"
- And I fill in "Title" with "My Folder"
- And I press "Save"
- Then I should see "Content management"
- And I should be on Joao Silva's cms
-
- Scenario: cancel button back to cms
- Given I follow "Control panel"
- And I follow "Manage Content"
- And I follow "New Folder"
- When I follow "Cancel"
- Then I should be on Joao Silva's cms
-
- Scenario: display tag list field when creating event
- Given I follow "Control panel"
- And I follow "Manage Content"
- And I follow "New article"
- When I follow "Event"
- Then I should see "Tag list"
-
- Scenario: display tag list field when creating folder
- Given I follow "Control panel"
- And I follow "Manage Content"
- When I follow "New folder"
- Then I should see "Tag list"
-
- Scenario: create new article with tags
- Given I follow "Control panel"
- And I follow "Manage Content"
- And I follow "New article"
- When I follow "Text article with Textile markup language"
- Then I should see "Tag list"
- When I fill in "Title" with "Article with tags"
- And I fill in "Tag list" with "aurium, bug"
- And I press "Save"
- And I go to /joaosilva/article-with-tags
- Then I should see "aurium" within "#article-tags a:first"
- And I should see "bug" within "#article-tags a:last"
diff --git a/features/edit_article.feature b/features/edit_article.feature
new file mode 100644
index 0000000..b60bd33
--- /dev/null
+++ b/features/edit_article.feature
@@ -0,0 +1,116 @@
+Feature: edit article
+ As a noosfero user
+ I want to create and edit articles
+
+ Background:
+ Given I am on the homepage
+ And the following users
+ | login | name |
+ | joaosilva | Joao Silva |
+ And the following articles
+ | owner | name | body |
+ | joaosilva | Save the whales | ... |
+ And I am logged in as "joaosilva"
+
+ Scenario: create a folder
+ Given I am on Joao Silva's control panel
+ And I follow "Manage Content"
+ When I follow "New Folder"
+ And I fill in "Title" with "My Folder"
+ And I press "Save"
+ And I go to Joao Silva's control panel
+ Then I should see "My Folder"
+
+ Scenario: redirect to the created folder
+ Given I am on Joao Silva's control panel
+ And I follow "Manage Content"
+ When I follow "New Folder"
+ And I fill in "Title" with "My Folder"
+ And I press "Save"
+ Then I should see "My Folder"
+ And I should be on /joaosilva/my-folder
+
+ Scenario: cancel button back to cms
+ Given I follow "Control panel"
+ And I follow "Manage Content"
+ And I follow "New Folder"
+ When I follow "Cancel"
+ Then I should be on Joao Silva's cms
+
+ Scenario: display tag list field when creating event
+ Given I follow "Control panel"
+ And I follow "Manage Content"
+ And I follow "New article"
+ When I follow "Event"
+ Then I should see "Tag list"
+
+ Scenario: display tag list field when creating folder
+ Given I follow "Control panel"
+ And I follow "Manage Content"
+ When I follow "New folder"
+ Then I should see "Tag list"
+
+ Scenario: create new article with tags
+ Given I follow "Control panel"
+ And I follow "Manage Content"
+ And I follow "New article"
+ When I follow "Text article with Textile markup language"
+ Then I should see "Tag list"
+ When I fill in "Title" with "Article with tags"
+ And I fill in "Tag list" with "aurium, bug"
+ And I press "Save"
+ And I go to /joaosilva/article-with-tags
+ Then I should see "aurium" within "#article-tags a:first"
+ And I should see "bug" within "#article-tags a:last"
+
+ Scenario: redirect to the created article
+ Given I am on Joao Silva's control panel
+ And I follow "Manage Content"
+ When I follow "New article"
+ When I follow "Text article with visual editor"
+ And I fill in "Title" with "My Article"
+ And I press "Save"
+ Then I should see "My Article"
+ And I should be on /joaosilva/my-article
+
+ Scenario: edit an article
+ Given I am on Joao Silva's sitemap
+ And I follow "Save the whales"
+ And I follow "Edit"
+ And I fill in "Title" with "My Article edited"
+ When I press "Save"
+ Then I should be on /joaosilva/my-article-edited
+
+ Scenario: cancel button back to article when edit
+ Given I am on Joao Silva's sitemap
+ And I follow "Save the whales"
+ And I follow "Edit"
+ When I follow "Cancel"
+ Then I should be on /joaosilva/save-the-whales
+
+ Scenario: create an article inside a folder
+ Given I am on Joao Silva's control panel
+ And I follow "Manage Content"
+ And I follow "New Folder"
+ And I fill in "Title" with "My Folder"
+ And I press "Save"
+ Then I should be on /joaosilva/my-folder
+ When I follow "New article"
+ And I follow "Text article with visual editor"
+ And I fill in "Title" with "My Article"
+ And I press "Save"
+ Then I should see "My Article"
+ And I should be on /joaosilva/my-folder/my-article
+
+ Scenario: cancel button back to folder after giving up creating
+ Given I am on Joao Silva's control panel
+ And I follow "Manage Content"
+ And I follow "New Folder"
+ And I fill in "Title" with "My Folder"
+ And I press "Save"
+ Then I should be on /joaosilva/my-folder
+ When I follow "New article"
+ And I follow "Text article with visual editor"
+ When I follow "Cancel"
+ And I should be on /joaosilva/my-folder
+
diff --git a/lib/noosfero.rb b/lib/noosfero.rb
index 1cd2d49..89024e6 100644
--- a/lib/noosfero.rb
+++ b/lib/noosfero.rb
@@ -55,6 +55,8 @@ module Noosfero
def self.url_options
if ENV['RAILS_ENV'] == 'development'
development_url_options
+ elsif ENV['RAILS_ENV'] == 'cucumber'
+ {:host => ''}
else
{}
end
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb
index fb6068b..4ea2aa4 100644
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -478,29 +478,31 @@ class CmsControllerTest < Test::Unit::TestCase
assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/new?parent_id=#{f.id}&type=Folder" }
end
- should 'redirect back to index after creating top-level article' do
- post :new, :profile => profile.identifier, :type => 'TextileArticle', :article => { :name => 'test' }
- assert_redirected_to :action => 'index'
+ should 'redirect to article after creating top-level article' do
+ post :new, :profile => profile.identifier, :type => 'TextileArticle', :article => { :name => 'top-level-article' }
+
+ assert_redirected_to @profile.articles.find_by_name('top-level-article').url
end
- should 'redirect back to folder after creating article inside it' do
+ should 'redirect to article after creating article inside a folder' do
f = Folder.new(:name => 'f'); profile.articles << f; f.save!
- post :new, :profile => profile.identifier, :type => 'TextileArticle', :parent_id => f.id, :article => { :name => 'test' }
- assert_redirected_to :action => 'view', :id => f.id
+ post :new, :profile => profile.identifier, :type => 'TextileArticle', :parent_id => f.id, :article => { :name => 'article-inside-folder' }
+
+ assert_redirected_to @profile.articles.find_by_name('article-inside-folder').url
end
- should 'redirect back to index after editing top-level article' do
- f = Folder.new(:name => 'f'); profile.articles << f; f.save!
+ should 'redirect back to article after editing top-level article' do
+ f = Folder.new(:name => 'top-level-article'); profile.articles << f; f.save!
post :edit, :profile => profile.identifier, :id => f.id
- assert_redirected_to :action => 'index'
+ assert_redirected_to @profile.articles.find_by_name('top-level-article').url
end
- should 'redirect back to folder after editing article inside it' do
+ should 'redirect back to article after editing article inside a folder' do
f = Folder.new(:name => 'f'); profile.articles << f; f.save!
- a = TextileArticle.create!(:parent => f, :name => 'test', :profile_id => profile.id)
+ a = TextileArticle.create!(:parent => f, :name => 'article-inside-folder', :profile_id => profile.id)
post :edit, :profile => profile.identifier, :id => a.id
- assert_redirected_to :action => 'view', :id => f.id
+ assert_redirected_to @profile.articles.find_by_name('article-inside-folder').url
end
should 'point back to index when cancelling creation of top-level article' do
@@ -604,15 +606,15 @@ class CmsControllerTest < Test::Unit::TestCase
@request.expects(:referer).returns('http://colivre.net/testinguser/myarticle').at_least_once
get :edit, :profile => 'testinguser', :id => article.id
- assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
+ assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/testinguser\/myarticle/ }
end
should 'detect when comming from home page' do
@request.expects(:referer).returns('http://colivre.net/testinguser').at_least_once
get :edit, :profile => 'testinguser', :id => @profile.home_page.id
- assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
- assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/testinguser\/#{@profile.home_page.slug}$/ }
+ assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
+ assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => @request.referer }
end
should 'go back to public view when saving coming from there' do
@@ -625,7 +627,7 @@ class CmsControllerTest < Test::Unit::TestCase
should 'record as coming from public view when creating article' do
@request.expects(:referer).returns('http://colivre.net/testinguser/testingusers-home-page').at_least_once
get :new, :profile => 'testinguser', :type => 'TextileArticle'
- assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
+ assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => 'http://colivre.net/testinguser/testingusers-home-page' }
end
@@ -835,17 +837,18 @@ class CmsControllerTest < Test::Unit::TestCase
assert :tag => 'input', :attributes => {:name => 'article[notify_comments]', :value => 1}
end
- should 'back to control panel after create blog' do
+ should 'go to blog after create it' do
assert_difference Blog, :count do
post :new, :type => Blog.name, :profile => profile.identifier, :article => { :name => 'my-blog' }, :back_to => 'control_panel'
- assert_redirected_to :controller => 'profile_editor', :profile => profile.identifier
end
+ assert_redirected_to @profile.articles.find_by_name('my-blog').view_url
end
- should 'back to control panel after config blog' do
+ should 'back to blog after config blog' do
profile.articles << Blog.new(:name => 'my-blog', :profile => profile)
- post :edit, :profile => profile.identifier, :id => profile.blog.id, :back_to => 'control_panel'
- assert_redirected_to :controller => 'profile_editor', :profile => profile.identifier
+ post :edit, :profile => profile.identifier, :id => profile.blog.id
+
+ assert_redirected_to @profile.articles.find_by_name('my-blog').view_url
end
should 'back to control panel if cancel create blog' do
@@ -885,27 +888,26 @@ class CmsControllerTest < Test::Unit::TestCase
@request.expects(:referer).returns("http://colivre.net/#{profile.identifier}/#{folder.slug}").at_least_once
get :upload_files, :profile => profile.identifier, :parent_id => folder.id
- assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
+ assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/#{profile.identifier}\/#{folder.slug}/ }
end
should 'detect when comming from home page to upload files' do
folder = Folder.create!(:name => 'testfolder', :profile => profile)
- profile.expects(:home_page).returns(folder).at_least_once
-
@request.expects(:referer).returns("http://colivre.net/#{profile.identifier}").at_least_once
@controller.stubs(:profile).returns(profile)
get :upload_files, :profile => profile.identifier, :parent_id => folder.id
- assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
- assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/#{profile.identifier}\/#{profile.home_page.slug}$/ }
+ assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
+ assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => @request.referer }
end
should 'go back to public view when upload files coming from there' do
folder = Folder.create!(:name => 'test_folder', :profile => profile)
+ @request.expects(:referer).returns(folder.view_url).at_least_once
- post :upload_files, :profile => profile.identifier, :parent_id => folder.id, :back_to => 'public_view', :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
+ post :upload_files, :profile => profile.identifier, :parent_id => folder.id, :back_to => @request.referer, :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
assert_template nil
- assert_redirected_to folder.url
+ assert_redirected_to folder.view_url
end
should 'record when coming from public view on edit files with view true' do
@@ -914,26 +916,25 @@ class CmsControllerTest < Test::Unit::TestCase
@request.expects(:referer).returns("http://colivre.net/#{profile.identifier}/#{file.slug}?view=true").at_least_once
get :edit, :profile => profile.identifier, :id => file.id
- assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
+ assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/#{profile.identifier}\/#{file.slug}?.*view=true/ }
end
should 'detect when comming from home page to edit files with view true' do
file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
- profile.expects(:home_page).returns(file).at_least_once
@request.expects(:referer).returns("http://colivre.net/#{profile.identifier}?view=true").at_least_once
@controller.stubs(:profile).returns(profile)
get :edit, :profile => profile.identifier, :id => file.id
- assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
- assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/#{profile.identifier}\/#{profile.home_page.slug}?.*view=true$/ }
+ assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
+ assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => @request.referer }
end
should 'go back to public view when edit files coming from there with view true' do
file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
@request.expects(:referer).returns("http://colivre.net/#{profile.identifier}/#{file.slug}?view=true").at_least_once
- post :edit, :profile => profile.identifier, :id => file.id, :back_to => 'public_view', :article => {:abstract => 'some description'}
+ post :edit, :profile => profile.identifier, :id => file.id, :back_to => @request.referer, :article => {:abstract => 'some description'}
assert_template nil
assert_redirected_to file.url.merge(:view => true)
end
@@ -1107,7 +1108,7 @@ class CmsControllerTest < Test::Unit::TestCase
should 'redirect to media listing when upload files from there' do
- post :upload_files, :profile => profile.identifier, :back_to => 'media_listing', :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
+ post :upload_files, :profile => profile.identifier, :media_listing => true, :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
assert_template nil
assert_redirected_to :action => 'media_listing'
end
@@ -1115,7 +1116,7 @@ class CmsControllerTest < Test::Unit::TestCase
should 'redirect to media listing when occur errors when upload files from there' do
file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('files/rails.png', 'image/png'))
- post :upload_files, :profile => profile.identifier, :back_to => 'media_listing', :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
+ post :upload_files, :profile => profile.identifier, :media_listing => true, :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
assert_template nil
assert_redirected_to :action => 'media_listing'
end
diff --git a/test/functional/invite_controller_test.rb b/test/functional/invite_controller_test.rb
index dc99e7f..8597e50 100644
--- a/test/functional/invite_controller_test.rb
+++ b/test/functional/invite_controller_test.rb
@@ -13,7 +13,7 @@ class InviteControllerTest < ActionController::TestCase
should 'actually invite manually added address with friend object' do
assert_difference InviteFriend, :count, 1 do
post :friends, :profile => profile.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: ", :step => 2
- assert_redirected_to :controller => 'profile'
+ assert_redirected_to :controller => 'friends'
end
end
@@ -83,4 +83,15 @@ class InviteControllerTest < ActionController::TestCase
assert_response 403 # forbidden
end
+ should 'redirect to friends after invitation if profile is a person' do
+ post :friends, :profile => profile.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: ", :step => 2
+ assert_redirected_to :controller => 'friends'
+ end
+
+ should 'redirect to friends after invitation if profile is not a person' do
+ community.add_admin(profile)
+ post :friends, :profile => community.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: ", :step => 2
+ assert_redirected_to :controller => 'profile_members'
+ end
+
end
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index edf4eab..7c33326 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -574,10 +574,10 @@ class ProfileControllerTest < Test::Unit::TestCase
community = Community.create!(:name => 'my test community')
community.add_member(profile)
- @request.session[:return_to] = "/profile/#{community.identifier}/to_go"
+ @request.expects(:referer).returns("/profile/#{community.identifier}/to_go").at_least_once
login_as(profile.identifier)
- post :leave, :profile => community.identifier, :confirmation => '1'
+ post :leave, :profile => community.identifier, :confirmation => '1', :back_to => @request.referer
assert_redirected_to "/profile/#{community.identifier}/to_go"
end
@@ -586,30 +586,28 @@ class ProfileControllerTest < Test::Unit::TestCase
community = Community.create!(:name => 'my test community')
login_as(profile.identifier)
- assert_nil @request.session[:return_to]
- @request.expects(:referer).returns("/profile/redirect_to")
+ @request.expects(:referer).returns("/profile/redirect_to").at_least_once
get :leave, :profile => community.identifier
- assert_equal '/profile/redirect_to', @request.session[:return_to]
+ assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer }
end
should 'store referer location when request join via get' do
community = Community.create!(:name => 'my test community')
login_as(profile.identifier)
- assert_nil @request.session[:return_to]
- @request.expects(:referer).returns("/profile/redirect_to").at_least_once
+ @request.session[:before_join] = "/profile/redirect_to"
get :join, :profile => community.identifier
- assert_equal '/profile/redirect_to', @request.session[:return_to]
+ assert_equal '/profile/redirect_to', @request.session[:before_join]
end
should 'redirect to stored location after join community' do
community = Community.create!(:name => 'my test community')
- @request.session[:return_to] = "/profile/#{community.identifier}/to_go"
+ @request.expects(:referer).returns("/profile/#{community.identifier}/to_go")
login_as(profile.identifier)
post :join, :profile => community.identifier, :confirmation => '1'
@@ -630,7 +628,7 @@ class ProfileControllerTest < Test::Unit::TestCase
should 'redirect to location before login after join community' do
community = Community.create!(:name => 'my test community')
- @request.session[:return_to] = "/profile/#{community.identifier}/to_go"
+ @request.expects(:referer).returns("/profile/#{community.identifier}/to_go")
login_as(profile.identifier)
post :join, :profile => community.identifier, :confirmation => '1'
diff --git a/test/integration/manage_documents_test.rb b/test/integration/manage_documents_test.rb
index 77587dd..6fb3007 100644
--- a/test/integration/manage_documents_test.rb
+++ b/test/integration/manage_documents_test.rb
@@ -29,7 +29,7 @@ class ManageDocumentsTest < ActionController::IntegrationTest
assert_response :redirect
follow_redirect!
a = Article.find_by_path('my-article')
- assert_equal "/myprofile/myuser/cms", path
+ assert_equal "/myuser/#{a.slug}", path
end
def test_update_of_an_existing_article
@@ -62,7 +62,7 @@ class ManageDocumentsTest < ActionController::IntegrationTest
assert_response :redirect
follow_redirect!
a = Article.find_by_path('my-article')
- assert_equal "/myprofile/myuser/cms", path
+ assert_equal "/myuser/#{a.slug}", path
end
def test_removing_an_article
--
libgit2 0.21.2