Skip to content

Commit

Permalink
make sure full URLs are always used for redirects. ignore :base_uri
Browse files Browse the repository at this point in the history
… from Integrity.config

also make Webrat::SinatraSession set HTTP_HOST on requests
  • Loading branch information
mislav committed Jan 15, 2009
1 parent cbae1a2 commit 715bd54
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app.rb
Expand Up @@ -58,7 +58,7 @@ def params
get "/login" do
login_required
session[:user] = current_user
redirect "/"
redirect root_url
end

get "/new" do
Expand All @@ -74,7 +74,7 @@ def params
@project = Project.new(params['project_data'])
if @project.save
@project.enable_notifiers(params["enabled_notifiers[]"], params["notifiers"])
redirect project_path(@project)
redirect project_url(@project)
else
show :new, :title => ["projects", "new project"]
end
Expand Down Expand Up @@ -106,7 +106,7 @@ def params
login_required

current_project.destroy
redirect "/"
redirect root_url
end

get "/:project/edit" do
Expand Down
26 changes: 21 additions & 5 deletions lib/integrity/helpers.rb
Expand Up @@ -68,28 +68,44 @@ def cycle(*values)
values[next_value]
end

def integrity_domain
Addressable::URI.parse(Integrity.config[:base_uri]).to_s
# def integrity_domain
# Addressable::URI.parse(Integrity.config[:base_uri]).to_s
# end

def url(path)
url = "#{request.scheme}://#{request.host}"

if request.scheme == "https" && request.port != 443 ||
request.scheme == "http" && request.port != 80
url << ":#{request.port}"
end

url << "/" unless path.index("/").zero?
url << path
end

def root_url
url("/")
end

def project_path(project, *path)
"/" << [project.permalink, *path].join("/")
end

def project_url(project, *path)
"#{integrity_domain}#{project_path(project, *path)}"
url project_path(project, *path)
end

def push_url_for(project)
"#{project_url(project)}/push"
project_url(project, "push")
end

def build_path(build)
"/#{build.project.permalink}/builds/#{build.commit_identifier}"
end

def build_url(build)
"#{integrity_domain}#{build_path(build)}"
url build_path(build)
end

def errors_on(object, field)
Expand Down
3 changes: 1 addition & 2 deletions test/helpers/acceptance.rb
Expand Up @@ -23,6 +23,7 @@ def #{verb}(path, data, headers = {})
data[key] = Rack::Utils.unescape(value)
data
end
headers['HTTP_HOST'] = DEFAULT_DOMAIN
@sinatra_test.#{verb}(path, params, headers)
end
METHOD
Expand Down Expand Up @@ -55,8 +56,6 @@ def response_location_host
require Integrity.root / "app"
require File.dirname(__FILE__) / "acceptance/git_helper"

Integrity.config[:base_uri] = "http://#{Webrat::SinatraSession::DEFAULT_DOMAIN}"

module AcceptanceHelper
include FileUtils

Expand Down

0 comments on commit 715bd54

Please sign in to comment.