Skip to content
Browse files

Merge pull request #390 from arr2036/app_rest_fix

App rest fix.
  • Loading branch information...
2 parents 7045f7f + 4543781 commit e930b5d07b7c7cb6c963a4ddc0ac6d0ea0400cb5 @bootstraponline bootstraponline committed Jun 26, 2012
Showing with 37 additions and 5 deletions.
  1. +13 −5 lib/gollum/frontend/app.rb
  2. +24 −0 test/test_app.rb
View
18 lib/gollum/frontend/app.rb
@@ -101,7 +101,7 @@ def supported_useragent?(user_agent)
mustache :edit
end
else
- mustache :create
+ redirect "/create/#{CGI.escape(@name)}"
end
end
@@ -124,7 +124,17 @@ def supported_useragent?(user_agent)
redirect "/#{page.escaped_url_path}"
end
-
+
+ get '/create/*' do
+ wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
+ @name = params[:splat].first
+ if wiki.page(@name)
+ redirect "/#{CGI.escape(@name)}"
+ else
+ mustache :create
+ end
+ end
+
post '/create' do
name = params[:page]
path = sanitize_empty_params(params[:path])
@@ -298,9 +308,7 @@ def show_page_or_file(fullpath)
content_type file.mime_type
file.raw_data
else
- @name = name
- @path = path
- mustache :create
+ redirect "/create/#{CGI.escape(name)}"
end
end
View
24 test/test_app.rb
@@ -124,6 +124,30 @@
assert_match /ghi/, last_response.body
end
+ test "redirects to create on non-existant page" do
+ name = "E"
+ get "/#{name}"
+ follow_redirect!
+ assert_equal "/create/#{name}", last_request.fullpath
+ assert last_response.ok?
+ end
+
+ test "edit redirects to create on non-existant page" do
+ name = "E"
+ get "/edit/#{name}"
+ follow_redirect!
+ assert_equal "/create/#{name}", last_request.fullpath
+ assert last_response.ok?
+ end
+
+ test "create redirects to page if already exists" do
+ name = "A"
+ get "/create/#{name}"
+ follow_redirect!
+ assert_equal "/#{name}", last_request.fullpath
+ assert last_response.ok?
+ end
+
test "guards against creation of existing page" do
name = "A"
post "/create", :content => 'abc', :page => name,

0 comments on commit e930b5d

Please sign in to comment.
Something went wrong with that request. Please try again.