Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix some test on redirect controller and fix some error if no current…

…_user
  • Loading branch information...
commit 582e70a686f1c76ae59c4485800713af505f9884 1 parent c4a4257
@shingara shingara authored
View
2  app/controllers/comments_controller.rb
@@ -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
View
1  app/models/article.rb
@@ -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
View
35 spec/controllers/redirect_controller_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.