Skip to content

Commit

Permalink
Sinatra 0.9 compatibility
Browse files Browse the repository at this point in the history
* switch vendore/webrat to brynary's master and monkey-patch SinatraSession
  TODO: send fixes upstream
* no need for sinatra-hacks anymore! (nested params is now built in sinatra)
* use #response[]= instead of deprecated #header
* update sinatra dependency to >= 0.9.0.3
  • Loading branch information
mislav authored and sr committed Jan 22, 2009
1 parent 0a40868 commit c772b6c
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "vendor/webrat"]
path = vendor/webrat
url = git://github.com/foca/webrat.git
url = git://github.com/brynary/webrat.git
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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.headers["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.headers["Content-Type"] = "text/css; charset=utf-8"
sass :integrity
end

Expand Down
28 changes: 22 additions & 6 deletions lib/integrity/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def authorize(user, password)
end

def unauthorized!(realm=authorization_realm)
header "WWW-Authenticate" => %(Basic realm="#{realm}")
response.headers["WWW-Authenticate"] = %(Basic realm="#{realm}")
throw :halt, [401, show(:unauthorized, :title => "incorrect credentials")]
end

Expand Down 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
14 changes: 5 additions & 9 deletions test/acceptance/build_notifications_test.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
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 52 files
+2 −1 .gitignore
+60 −19 History.txt
+4 −4 Rakefile
+1 −1 lib/webrat.rb
+52 −23 lib/webrat/core/configuration.rb
+10 −1 lib/webrat/core/elements/field.rb
+1 −1 lib/webrat/core/elements/label.rb
+8 −2 lib/webrat/core/locators/field_labeled_locator.rb
+14 −0 lib/webrat/core/matchers/have_content.rb
+15 −0 lib/webrat/core/matchers/have_selector.rb
+14 −0 lib/webrat/core/matchers/have_tag.rb
+10 −0 lib/webrat/core/matchers/have_xpath.rb
+1 −0 lib/webrat/core/methods.rb
+30 −10 lib/webrat/core/scope.rb
+34 −7 lib/webrat/core/session.rb
+3 −3 lib/webrat/core/xml/nokogiri.rb
+6 −62 lib/webrat/merb.rb
+65 −0 lib/webrat/merb_session.rb
+25 −6 lib/webrat/rails.rb
+16 −15 lib/webrat/selenium.rb
+38 −0 lib/webrat/selenium/matchers.rb
+52 −46 lib/webrat/selenium/selenium_session.rb
+13 −5 lib/webrat/sinatra.rb
+5 −1 spec/integration/merb/app/controllers/testing.rb
+5 −0 spec/integration/merb/app/views/testing/show_form.html.erb
+2 −1 spec/integration/merb/config/router.rb
+13 −2 spec/integration/merb/spec/webrat_spec.rb
+24 −3 spec/integration/rails/app/controllers/webrat_controller.rb
+7 −0 spec/integration/rails/app/views/webrat/before_redirect_form.html.erb
+11 −0 spec/integration/rails/app/views/webrat/form.html.erb
+8 −3 spec/integration/rails/config/routes.rb
+17 −0 spec/integration/rails/test/integration/webrat_rails_test.rb
+30 −2 spec/integration/rails/test/integration/webrat_test.rb
+22 −11 spec/integration/sinatra/app.rb
+18 −3 spec/integration/sinatra/test/webrat_test.rb
+61 −21 spec/private/core/configuration_spec.rb
+68 −2 spec/private/core/session_spec.rb
+27 −5 spec/private/rails/rails_session_spec.rb
+44 −0 spec/private/selenium/selenium_session_spec.rb
+52 −0 spec/private/selenium/selenium_spec.rb
+1 −14 spec/private/sinatra/helper.rb
+28 −0 spec/private/sinatra/sinatra_session_spec.rb
+0 −28 spec/private/sinatra/sinatra_spec.rb
+15 −0 spec/public/locators/field_labeled_spec.rb
+144 −5 spec/public/matchers_spec.rb
+1 −1 spec/public/reload_spec.rb
+0 −1 spec/public/set_hidden_field_spec.rb
+0 −1 spec/public/submit_form_spec.rb
+10 −2 spec/public/visit_spec.rb
+95 −18 spec/public/within_spec.rb
+1 −0 spec/spec_helper.rb
+3 −3 webrat.gemspec

0 comments on commit c772b6c

Please sign in to comment.