Skip to content

Commit

Permalink
fix some test on redirect controller and fix some error if no current…
Browse files Browse the repository at this point in the history
…_user
  • Loading branch information
shingara committed Feb 25, 2009
1 parent c4a4257 commit 582e70a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def create
art.add_comment(params[:comment].symbolize_keys)
end

unless current_user.id.nil? or session[:user_id].nil?
unless current_user.nil? or session[:user_id].nil?
# maybe useless, but who knows ?
if current_user.id == session[:user_id]
@comment.user_id = current_user.id
Expand Down
1 change: 1 addition & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def self.find_by_permalink(params)
if date_range
req_params[:published_at] = date_range
end
return nil if req_params.empty? # no search if no params send

find_published(:first, :conditions => req_params) or raise ActiveRecord::RecordNotFound
end
Expand Down
35 changes: 18 additions & 17 deletions spec/controllers/redirect_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,36 @@ def test_no_redirect
end

def test_redirect_articles
get :redirect, :from => ["articles", "foo", "bar", "baz"]
get :redirect, :from => ["articles", "2004", "04", "01", "second-blog-article"]
assert_response 301
assert_redirected_to "http://test.host/foo/bar/baz"
end

def test_redirect_articles_with_articles_in_path
get :redirect, :from => ["articles", "foo", "articles", "baz"]
assert_response 301
assert_redirected_to "http://test.host/foo/articles/baz"
assert_redirected_to "http://myblog.net/2004/04/01/second-blog-article"
end

def test_url_root_redirect_articles
ActionController::Base.relative_url_root = "/blog"
get :redirect, :from => ["articles", "foo", "bar", "baz"]
b = blogs(:default)
b.base_url = "http://test.host/blog"
b.save
get :redirect, :from => ["articles", "2004", "04", "01", "second-blog-article"]
assert_response 301
assert_redirected_to "http://test.host/blog/foo/bar/baz"
assert_redirected_to "http://test.host/blog/2004/04/01/second-blog-article"
end

def test_url_root_redirect_articles_when_url_root_is_articles
ActionController::Base.relative_url_root = "/articles"
get :redirect, :from => ["articles", "foo", "bar", "baz"]
b = blogs(:default)
b.base_url = "http://test.host/articles"
b.save
get :redirect, :from => ["articles", "2004", "04", "01", "second-blog-article"]
assert_response 301
assert_redirected_to "http://test.host/articles/foo/bar/baz"
assert_redirected_to "http://test.host/articles/2004/04/01/second-blog-article"
end

def test_url_root_redirect_articles_with_articles_in_url_root
ActionController::Base.relative_url_root = "/aaa/articles/bbb"
get :redirect, :from => ["articles", "foo", "bar", "baz"]
b = blogs(:default)
b.base_url = "http://test.host/aaa/articles/bbb"
b.save

get :redirect, :from => ["articles", "2004", "04", "01", "second-blog-article"]
assert_response 301
assert_redirected_to "http://test.host/aaa/articles/bbb/foo/bar/baz"
assert_redirected_to "http://test.host/aaa/articles/bbb/2004/04/01/second-blog-article"
end
end

0 comments on commit 582e70a

Please sign in to comment.