Skip to content

Commit

Permalink
Merged my latest code with github's 0.3.6, bumped to 0.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Bauerpauer committed Mar 13, 2009
2 parents 3374e5b + cec2bd0 commit d728fd1
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 11 deletions.
Binary file removed .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
coverage
pkg
pkg
.DS_Store
15 changes: 11 additions & 4 deletions Rakefile
@@ -1,15 +1,22 @@
require "rubygems"
require "pathname"
require "rake"
require "rake/testtask"
require "spec/rake/spectask"

# Specs
task :default => :spec
task :default => [:spec, :test]
Spec::Rake::SpecTask.new("spec") do |t|
t.spec_opts << "--colour" << "--loadby" << "random"
t.spec_files = Dir["spec/**/*_spec.rb"]
end

Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList["test/**/*_test.rb"]
t.verbose = true
end

# rcov
Spec::Rake::SpecTask.new("rcov") do |t|
t.spec_opts << "--colour" << "--loadby" << "random"
Expand All @@ -32,7 +39,7 @@ require "rake/gempackagetask"

NAME = "wheels"
SUMMARY = "Wheels Framework"
GEM_VERSION = "0.3.2"
GEM_VERSION = "0.3.7"

spec = Gem::Specification.new do |s|
s.name = NAME
Expand Down Expand Up @@ -63,7 +70,7 @@ task :publish do
`git push --tags &> /dev/null`

commands = [
"if [ ! -d '#{NAME}' ]; then git clone /home/git/#{NAME}; fi",
"if [ ! -d '#{NAME}' ]; then git clone git://github.com/wiecklabs/wheels.git; fi",
"cd #{NAME}",
"git pull &> /dev/null",
"rake repackage &> /dev/null",
Expand All @@ -74,4 +81,4 @@ task :publish do

`ssh gems@able.wieck.com "#{commands.join(" && ")}"`
STDOUT.puts "done"
end
end
18 changes: 16 additions & 2 deletions lib/wheels/mailer.rb
Expand Up @@ -8,6 +8,14 @@
module Wheels
class Mailer < MailFactory

def self.layout=(layout)
@@layout = layout
end

def self.layout
@@layout rescue nil
end

attr_accessor :mail_server

##
Expand Down Expand Up @@ -71,7 +79,13 @@ def headers_to_s
if value.is_a?(Wheels::View)
value.context.merge(:mailer => self)
end
super

if layout = self.class.layout.dup
layout.sub!(/(\.html\.erb$)|$/, ".txt.erb") if method == "text="
value = Wheels::View.new(layout, :content => value)
end

super(value)
end
end

Expand All @@ -88,7 +102,7 @@ def tokenize_urls!(mail_server_url)

[:@html, :@text].each do |ivar|
if content = instance_variable_get(ivar)
new_content = content.to_s.gsub(/(http(s)?:\/\/.+?)(?=[" ]|$)/) do |url|
new_content = content.to_s.gsub(/(http(s)?:\/\/.+?(?=[" <]|$))/) do |url|
"#{mail_server_url}/m/#{envelope_id}?r=#{CGI.escape([url].pack("m"))}"
end
instance_variable_set(ivar, new_content)
Expand Down
4 changes: 2 additions & 2 deletions lib/wheels/request.rb
Expand Up @@ -22,7 +22,7 @@ def layout
end

def request_method
@env['REQUEST_METHOD'] = params['_method'].upcase if request_method_in_params?
@env['REQUEST_METHOD'] = self.POST['_method'].upcase if request_method_in_params?
@env['REQUEST_METHOD']
end

Expand All @@ -32,7 +32,7 @@ def environment

private
def request_method_in_params?
@env["REQUEST_METHOD"] == "POST" && %w(PUT DELETE).include?((params['_method'] || "").upcase)
@env["REQUEST_METHOD"] == "POST" && self.POST && %w(PUT DELETE).include?((self.POST['_method'] || "").upcase)
end
end
end
1 change: 1 addition & 0 deletions lib/wheels/view.rb
Expand Up @@ -111,6 +111,7 @@ def _erb_buffer( the_binding ) # :nodoc:
end

class View

def self.path
@path ||= []
end
Expand Down
5 changes: 3 additions & 2 deletions spec/router_spec.rb
Expand Up @@ -131,7 +131,7 @@

it "should match a put request (with _method)" do
@request.env["REQUEST_METHOD"] = "POST"
@request.params.update("_method" => "put")
@request.env["rack.request.form_hash"] = { "_method" => "put" }
@router.match(@request).call.should == "Index"
end

Expand All @@ -155,7 +155,8 @@

it "should match a delete request (with _method)" do
@request.env["REQUEST_METHOD"] = "POST"
@request.params.update("_method" => "delete")
@request.env["rack.request.form_hash"] = { "_method" => "delete" }

@router.match(@request).call.should == "Index"
end

Expand Down
1 change: 1 addition & 0 deletions test/helper.rb
@@ -1,4 +1,5 @@
require "rubygems"
require "pathname"
require "test/unit"
require Pathname(__FILE__).dirname.parent + "lib/wheels"
require "wheels/xml_view"
Expand Down
13 changes: 13 additions & 0 deletions test/mailer_test.rb
Expand Up @@ -30,4 +30,17 @@ def test_tokenize_urls_with_https
assert_equal("http://m.wieck.com/m/#{mailer.envelope_id}?r=#{CGI.escape([url].pack("m"))}", mailer.text)
end

##
# Fixing an issue reported by Drew where links would be blown away.
#
def test_tokenize_urls_with_link_as_name
mailer = Wheels::Mailer.new
url = "http://test.com"
mailer.rawhtml = "<a href=\"#{url}\">#{url}</a>"
mailer.tokenize_urls!("http://m.wieck.com")

url = "http://m.wieck.com/m/#{mailer.envelope_id}?r=#{CGI.escape([url].pack("m"))}"
assert_equal("<a href=\"#{url}\">#{url}</a>", mailer.html)
end

end
28 changes: 28 additions & 0 deletions test/request_test.rb
@@ -0,0 +1,28 @@
require "helper"

class RequestTest < Test::Unit::TestCase
def test_no_method_override_for_get
assert_equal("GET", get("/").request_method)
assert_equal("GET", get("/?_method=DELETE").request_method)
end

def test_method_override_for_post
assert_equal("POST", post("/").request_method)
assert_equal("POST", post("/?_request=delete").request_method)
assert_equal("PUT", post("/", :input => "_method=put").request_method)
assert_equal("DELETE", post("/", :input => "_method=delete").request_method)
end

def get(path, options = {})
request(path, "GET", options)
end

def post(path, options = {})
request(path, "POST", options)
end

def request(path, method, options)
Wheels::Request.new(Class.new, Rack::MockRequest.env_for(path, options.merge(:method => method)))
end

end

0 comments on commit d728fd1

Please sign in to comment.