Permalink
Browse files

Merge changes from 'reist/master'

* `verification` was released as a gem
* New test was added against _method override
  • Loading branch information...
2 parents 55f45e2 + e87ce19 commit fe9d6f2543e02a90e4a9e13828ccc8c11d8afb45 @sikachu committed Sep 11, 2012
Showing with 50 additions and 6 deletions.
  1. +3 −0 .gitignore
  2. +1 −5 Gemfile
  3. +1 −0 lib/verification.rb
  4. +19 −1 test/verification_test.rb
  5. +26 −0 verification.gemspec
View
@@ -1 +1,4 @@
Gemfile.lock
+pkg/*
+*.gem
+.bundle
View
@@ -1,7 +1,3 @@
source "https://rubygems.org"
-gem 'rake'
-gem 'test-unit'
-gem 'activesupport'
-gem 'actionpack'
-gem 'mocha'
+gemspec
View
@@ -0,0 +1 @@
+require 'action_controller/verification'
@@ -1,6 +1,8 @@
require 'test_helper'
class VerificationTestController < ActionController::Base
+ use Rack::MethodOverride
+
verify :only => :guarded_one, :params => "one",
:add_flash => { :error => 'unguarded' },
:redirect_to => { :action => "unguarded" }
@@ -33,6 +35,8 @@ class VerificationTestController < ActionController::Base
verify :only => :must_be_post, :method => :post, :render => { :status => 405, :text => "Must be post" }, :add_headers => { "Allow" => "POST" }
+ verify :only => :must_be_put, :method => :put, :render => { :status => 405, :text => "Must be put" }, :add_headers => { "Allow" => "PUT" }
+
verify :only => :guarded_one_for_named_route_test, :params => "one",
:redirect_to => :foo_url
@@ -93,6 +97,10 @@ def must_be_post
render :text => "Was a post!"
end
+ def must_be_put
+ render :text => "Was a put!"
+ end
+
def guarded_with_back
render :text => "#{params[:one]}"
end
@@ -252,6 +260,16 @@ def test_guarded_post_and_calls_render_succeeds
assert_equal "Was a post!", @response.body
end
+ def test_guarded_put_and_calls_render_succeeds
+ put :must_be_put
+ assert_equal "Was a put!", @response.body
+ end
+
+ def test_guarded_post_with_put_params_and_calls_render_succeeds
+ post :must_be_put, '_method' => 'put'
+ assert_equal "Was a put!", @response.body
+ end
+
def test_default_failure_should_be_a_bad_request
post :no_default_action
assert_response :bad_request
@@ -267,7 +285,7 @@ def test_guarded_post_and_calls_render_fails_and_sets_allow_header
def test_second_redirect
assert_nothing_raised { get :two_redirects }
end
-
+
def test_guarded_http_method_respects_overwritten_request_method
# Overwrite http method on application level like Rails supports via sending a _method parameter
@request.stubs(:request_method).returns('POST')
View
@@ -0,0 +1,26 @@
+$:.push File.expand_path("../lib", __FILE__)
+
+Gem::Specification.new do |s|
+ s.name = "verification"
+ s.version = "1.0.3"
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["David Heinemeier Hansson"]
+ s.email = ["david@loudthinking.com"]
+ s.homepage = "https://rubygems.org/gems/verification"
+ s.summary = %q{Verify preconditions for Rails actions}
+ s.description = %q{Verify preconditions for Rails actions}
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_dependency('activesupport', '>= 3.0.0', '< 3.3.0')
+ s.add_dependency('actionpack', '>= 3.0.0', '< 3.3.0')
+
+ s.add_development_dependency('rake')
+ s.add_development_dependency('test-unit')
+ s.add_development_dependency('activesupport')
+ s.add_development_dependency('actionpack')
+ s.add_development_dependency('mocha')
+end

0 comments on commit fe9d6f2

Please sign in to comment.