Skip to content

Commit

Permalink
test: adding tests for LH#133 which tests that the return_to stays co…
Browse files Browse the repository at this point in the history
…rrect after various actions relating to images (slideshow and private image viewing). Have fixed a bug where private image viewing was rewriting the return_to.
  • Loading branch information
Kieran Pilkington committed Jan 21, 2009
1 parent 0f6d2b9 commit b009c10
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 9 deletions.
3 changes: 3 additions & 0 deletions app/controllers/application.rb
Expand Up @@ -743,6 +743,9 @@ def unlink_related
#
# We can return to this location by calling #redirect_back_or_default.
def store_location
# Because private files are served through a show action, this method gets called, but we
# don't want to set the return_to url to a private image link
return if params[:controller] == 'private_files'
# this should prevent the same page from being added to return_to
# but does not prevent case of differnt size images...
session[:return_to] = request.request_uri
Expand Down
66 changes: 59 additions & 7 deletions test/integration/account_test.rb
Expand Up @@ -5,17 +5,19 @@ class AccountTest < ActionController::IntegrationTest
context "A User" do

setup do
add_admin_as_super_user
add_paul_as_regular_user
end

should "be able to login" do
login_as('admin')
login_as('paul')
body_should_contain "Logged in successfully"
url_should_contain "/site/all/topics"
body_should_contain "Results in topics"
end

should "should have details displayed on the menu" do
login_as('admin')
body_should_contain "admin"
login_as('paul')
body_should_contain "paul"
body_should_contain "Logout"
end

Expand All @@ -25,17 +27,67 @@ class AccountTest < ActionController::IntegrationTest
end

should "be able to logout once logged in" do
login_as('admin')
login_as('paul')
body_should_contain "Logged in successfully"
logout
url_should_contain "/site/all/topics"
body_should_contain "Results in topics"
end

should "be redirected back to last tried location when logged in" do
visit "/site/baskets/choose_type"
login_as('admin', 'test', { :navigate_to_login => false })
body_should_contain "What would you like to add? Where would you like to add it?"
login_as('paul', 'test', { :navigate_to_login => false })
url_should_contain "/site/baskets/choose_type"
body_should_contain "What would you like to add?"
end

context "when homepage slideshow controls are on" do

setup do
@@site_basket.update_attribute(:index_page_image_as, 'random')
login_as('paul')
@item1 = new_still_image { attach_file "image_file_uploaded_data", "white.jpg" }
@item2 = new_still_image { attach_file "image_file_uploaded_data", "white.jpg" }
@item3 = new_still_image { attach_file "image_file_uploaded_data", "white.jpg" }
end

teardown do
@@site_basket.update_attribute(:index_page_image_as, '')
end

should "not have the slideshow overide their return_to when logging in" do
logout
visit "/"
visit "/site/account/login"
login_as('paul', 'test', { :navigate_to_login => false })
url_should_contain Regexp.new("/$")
end

end

context "when private items are enabled" do

setup do
@@site_basket.update_attribute(:show_privacy_controls, true)
login_as('paul')
@item = new_still_image({ :private_true => true, :file_private_true => true }) { attach_file "image_file_uploaded_data", "white.jpg" }
end

teardown do
@@site_basket.update_attribute(:show_privacy_controls, false)
end

should "not have the private item overide their return_to when logging in" do
logout
visit "/site/images/show/#{@item.to_param}"
body_should_contain 'No Public Version Available'
visit "#{@item.original_file.public_filename}"
body_should_contain 'Error 401: Unauthorized'
visit "/site/account/login"
login_as('paul', 'test', { :navigate_to_login => false })
url_should_contain "/site/images/show/#{@item.id}"
end

end

end
Expand Down
12 changes: 10 additions & 2 deletions test/integration/integration_test_helper.rb
Expand Up @@ -155,15 +155,23 @@ def body_should_contain_in_order(text_array, divider, options = {})
# entire request url to the console)
def url_should_contain(text, options = {})
puts request.url if options[:dump_response]
assert request.url.include?(text), "URL should contain '#{text}', but does not."
if text.is_a?(Regexp)
assert (request.url =~ text), "URL should contain '#{text}', but does not."
else
assert request.url.include?(text), "URL should contain '#{text}', but does not."
end
end

# Asserts whether the supplied text is not within the request url of the currently viewed page
# Takes required text, optional options hash which can set :dump_response option (which will output the
# entire request url to the console)
def url_should_not_contain(text, options = {})
puts request.url if options[:dump_response]
assert !request.url.include?(text), "URL should not contain '#{text}', but does."
if text.is_a?(Regexp)
assert !(request.url =~ text), "URL should not contain '#{text}', but does."
else
assert !request.url.include?(text), "URL should not contain '#{text}', but does."
end
end

# Create a new item by navigating to the item new page, filling in fields and clicking "Create". While
Expand Down

0 comments on commit b009c10

Please sign in to comment.