Skip to content

Commit

Permalink
Merge branch 'sinatra-0.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
foca committed Jan 25, 2009
2 parents 674bee8 + e0c6c5c commit a3b7784
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 95 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

4 changes: 2 additions & 2 deletions Rakefile
Expand Up @@ -51,7 +51,7 @@ namespace :test do

desc "Install all gems on which the tests depend on"
task :install_dependencies do
system 'gem install redgreen rr mocha ruby-debug dm-sweatshop'
system 'gem install redgreen rr mocha ruby-debug dm-sweatshop webrat'
system 'gem install -s http://gems.github.com jeremymcanally-context jeremymcanally-matchy jeremymcanally-pending foca-storyteller'
end
end
Expand Down Expand Up @@ -89,7 +89,7 @@ begin
s.executables = ['integrity']
s.post_install_message = 'Run `integrity help` for information on how to setup Integrity.'

s.add_dependency 'sinatra', ['>= 0.3.2']
s.add_dependency 'sinatra', ['>= 0.9.0.3']
s.add_dependency 'haml' # ah, you evil monkey you
s.add_dependency 'dm-core', ['>= 0.9.5']
s.add_dependency 'dm-validations', ['>= 0.9.5']
Expand Down
13 changes: 6 additions & 7 deletions app.rb
@@ -1,7 +1,6 @@
require File.dirname(__FILE__) + "/lib/integrity"
require "sinatra"
require "helpers"
require "hacks"

set :root, Integrity.root
set :public, Integrity.root / "public"
Expand Down Expand Up @@ -46,7 +45,7 @@
get "/login" do
login_required
session[:user] = current_user
redirect "/"
redirect root_url
end

get "/new" do
Expand All @@ -62,7 +61,7 @@
@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 All @@ -75,15 +74,15 @@

get "/:project.atom" do
login_required unless current_project.public?
header "Content-Type" => "application/atom+xml; charset=utf-8"
response["Content-Type"] = "application/rss+xml; charset=utf-8"
builder :project
end

put "/:project" do
login_required

if current_project.update_attributes(params[:project_data])
current_project.enable_notifiers(params["enabled_notifiers[]"], params["notifiers"])
current_project.enable_notifiers(params["enabled_notifiers"], params["notifiers"])
redirect project_url(current_project)
else
show :new, :title => ["projects", current_project.permalink, "edit"]
Expand All @@ -94,7 +93,7 @@
login_required

current_project.destroy
redirect "/"
redirect root_url
end

get "/:project/edit" do
Expand Down Expand Up @@ -129,7 +128,7 @@
end

get "/integrity.css" do
header "Content-Type" => "text/css; charset=utf-8"
response["Content-Type"] = "text/css; charset=utf-8"
sass :integrity
end

Expand Down
2 changes: 1 addition & 1 deletion lib/integrity/helpers/authorization.rb
Expand Up @@ -25,7 +25,7 @@ def authorize(user, password)
end

def unauthorized!(realm=authorization_realm)
header "WWW-Authenticate" => %(Basic realm="#{realm}")
response["WWW-Authenticate"] = %(Basic realm="#{realm}")
throw :halt, [401, show(:unauthorized, :title => "incorrect credentials")]
end
end
Expand Down
24 changes: 18 additions & 6 deletions lib/integrity/helpers/urls.rb
@@ -1,23 +1,35 @@
module Integrity
module Helpers
module Urls
def integrity_domain
Addressable::URI.parse(Integrity.config[:base_uri]).to_s
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)
Addressable::URI.parse("#{project_url(project)}/push").tap do |url|
Addressable::URI.parse(project_url(project, "push")).tap do |url|
if Integrity.config[:use_basic_auth]
url.user = Integrity.config[:admin_username]
url.password = Integrity.config[:hash_admin_password] ?
url.password = Integrity.config[:hash_admin_password] ?
"<password>" : Integrity.config[:admin_password]
end
end.to_s
Expand All @@ -28,7 +40,7 @@ def build_path(build)
end

def build_url(build)
"#{integrity_domain}#{build_path(build)}"
url build_path(build)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/api_test.rb
Expand Up @@ -33,7 +33,7 @@ class ApiTest < Test::Unit::AcceptanceTestCase
end
end

Project.gen(:my_test_project, :uri => repo.path)
Project.gen(:my_test_project, :uri => repo.path, :command => "echo successful")

lambda do
basic_auth "admin", "test"
Expand Down Expand Up @@ -71,7 +71,7 @@ class ApiTest < Test::Unit::AcceptanceTestCase
Project.gen(:my_test_project, :uri => git_repo(:my_test_project).path)
head = git_repo(:my_test_project).head
post "/my-test-project/push", :payload => payload(head, "master")

response_code.should == 401
end

Expand Down
14 changes: 5 additions & 9 deletions test/acceptance/build_notifications_test.rb
Expand Up @@ -7,27 +7,23 @@ class BuildNotificationsTest < Test::Unit::AcceptanceTestCase
I want to setup notifiers on my projects
So that I get alerts with every build
EOS

before(:each) do
Integrity.config[:base_uri] = "http://integrity.example.org"
end

scenario "an admin sets up a notifier for a project that didn't have any" do
git_repo(:my_test_project).add_successful_commit
Project.gen(:my_test_project, :notifiers => [], :uri => git_repo(:my_test_project).path)
rm_f "/tmp/textfile_notifications.txt"

login_as "admin", "test"

visit "/my-test-project"

click_link "Edit Project"
check "enabled_notifiers_textfile"
fill_in "File", :with => "/tmp/textfile_notifications.txt"
click_button "Update Project"

click_button "manual build"

notification = File.read("/tmp/textfile_notifications.txt")
notification.should =~ /=== Build #{git_repo(:my_test_project).short_head} was successful ===/
notification.should =~ /Build #{git_repo(:my_test_project).head} was successful/
Expand All @@ -37,4 +33,4 @@ class BuildNotificationsTest < Test::Unit::AcceptanceTestCase
notification.should =~ /Commit Message: This commit will work/
notification.should =~ /Build Output:\n\nRunning tests...\n/
end
end
end
80 changes: 66 additions & 14 deletions test/helpers/acceptance.rb
@@ -1,9 +1,61 @@
require "webrat/sinatra"
require 'webrat/rack'
require 'sinatra'
require 'sinatra/test'

disable :run
disable :reload

Webrat.configuration.instance_variable_set("@mode", :sinatra)

module Webrat
class SinatraSession < Session
DEFAULT_DOMAIN = "integrity.example.org"

def initialize(context = nil)
super(context)
@sinatra_test = Sinatra::TestHarness.new
end

%w(get head post put delete).each do |verb|
class_eval <<-METHOD
def #{verb}(path, data, headers = {})
params = data.inject({}) do |data, (key,value)|
data[key] = Rack::Utils.unescape(value)
data
end
headers['HTTP_HOST'] = DEFAULT_DOMAIN
@sinatra_test.#{verb}(path, params, headers)
end
METHOD
end

def response_body
@sinatra_test.body
end

def response_code
@sinatra_test.status
end

private

def response
@sinatra_test.response
end

def current_host
URI.parse(current_url).host || DEFAULT_DOMAIN
end

def response_location_host
URI.parse(response_location).host || DEFAULT_DOMAIN
end
end
end

require Integrity.root / "app"
require File.dirname(__FILE__) / "acceptance/git_helper"

Webrat.configuration.mode = :sinatra

module AcceptanceHelper
include FileUtils

Expand All @@ -17,14 +69,14 @@ def enable_auth!
Integrity.config[:admin_password] = "test"
Integrity.config[:hash_admin_password] = false
end

def login_as(user, password)
def AcceptanceHelper.logged_in; true; end
basic_auth user, password
visit "/login"
Sinatra.application.before { login_required if AcceptanceHelper.logged_in }
Sinatra::Application.before { login_required if AcceptanceHelper.logged_in }
end

def log_out
def AcceptanceHelper.logged_in; false; end
@_webrat_session = Webrat::SinatraSession.new(self)
Expand All @@ -47,17 +99,17 @@ def setup_log!
end
end

module WebratHelpers
include Webrat::Methods
Webrat::Methods.delegate_to_session :response_code, :response_body
end

class Test::Unit::AcceptanceTestCase < Test::Unit::TestCase
include AcceptanceHelper
include Test::Storyteller
include WebratHelpers
include GitHelper

include Webrat::Methods
Webrat::Methods.delegate_to_session :response_code

before(:all) do
Integrity.config[:base_uri] = "http://#{Webrat::SinatraSession::DEFAULT_DOMAIN}"
end

before(:each) do
# ensure each scenario is run in a clean sandbox
setup_and_reset_database!
Expand All @@ -66,7 +118,7 @@ class Test::Unit::AcceptanceTestCase < Test::Unit::TestCase
set_and_create_export_directory!
log_out
end

after(:each) do
destroy_all_git_repos
rm_r export_directory if File.directory?(export_directory)
Expand Down
3 changes: 2 additions & 1 deletion test/unit/helpers_test.rb
Expand Up @@ -28,7 +28,8 @@ class BrowsePublicProjectsTest < Test::Unit::TestCase
@project = Project.gen(:integrity)
Integrity.config[:admin_username] = "admin"
Integrity.config[:admin_password] = "test"
Integrity.config[:base_uri] = "http://integrity.example.org:1234"

stub(self).request { OpenStruct.new(:scheme => "http", :port => "1234", :host => "integrity.example.org") }
end

test "with auth disabled" do
Expand Down
49 changes: 0 additions & 49 deletions vendor/sinatra-hacks/lib/hacks.rb

This file was deleted.

2 changes: 1 addition & 1 deletion vendor/webrat
Submodule webrat updated from 78b8f3 to 0272e8

0 comments on commit a3b7784

Please sign in to comment.