diff --git a/Gemfile b/Gemfile index f62a7e9..39bdd55 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,8 @@ source :gemcutter gem "rspec" gem "rack" gem "actionpack", "3.0.0.beta2", :require => "action_controller" +gem "railties", "3.0.0.beta2", :require => "rails" gem "ParseTree" gem "ruby2ruby" -gem "rake" \ No newline at end of file +gem "rake" +gem "rack-test", :require => "rack/test" \ No newline at end of file diff --git a/spec/controllers/action_args_controller.rb b/spec/controllers/action_args_controller.rb index 6f39149..57b3681 100644 --- a/spec/controllers/action_args_controller.rb +++ b/spec/controllers/action_args_controller.rb @@ -3,10 +3,6 @@ class ApplicationController < ActionController::Base end module ExtraActions - # def self.included(base) - # base.show_action(:funky_inherited_method) - # end - def funky_inherited_method(foo, bar) render :text => "#{foo} #{bar}" end @@ -57,3 +53,14 @@ def with_default_array(foo, bar = []) end +class MyApp < Rails::Application + config.session_store :disabled + + routes.draw do + match "/awesome/index" => "Awesome::ActionArgs#index" + + controller :action_args do + match "/action_args/:action" + end + end +end diff --git a/spec/rails_action_args_spec.rb b/spec/rails_action_args_spec.rb index 1bb3db5..142bfb7 100644 --- a/spec/rails_action_args_spec.rb +++ b/spec/rails_action_args_spec.rb @@ -1,57 +1,63 @@ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe "RailsActionArgs" do + def app + MyApp + end + it "should be able to handle a nested class" do - Awesome::ActionArgsController.action(:index).call(Rack::MockRequest.env_for("/?foo=bar"))[2].body.should == "bar" + request("/awesome/index?foo=bar").body.should == "bar" end it "should be able to handle no arguments" do - ActionArgsController.action(:nada).call(Rack::MockRequest.env_for("/"))[2].body.should == "NADA" + request("/action_args/nada").body.should == "NADA" end it "should be able to accept Action Arguments" do - ActionArgsController.action(:index).call(Rack::MockRequest.env_for("/?foo=bar"))[2].body.should == "bar" + request("/action_args/index?foo=bar").body.should == "bar" end it "should be able to accept multiple Action Arguments" do - ActionArgsController.action(:multi).call(Rack::MockRequest.env_for("/?foo=bar&bar=baz"))[2].body.should == "bar baz" + request("/action_args/multi?foo=bar&bar=baz").body.should == "bar baz" end it "should be able to handle defaults in Action Arguments" do - ActionArgsController.action(:defaults).call(Rack::MockRequest.env_for("/?foo=bar"))[2].body.should == "bar bar" + request("/action_args/defaults?foo=bar").body.should == "bar bar" end it "should be able to handle out of order defaults" do - ActionArgsController.action(:defaults_mixed).call(Rack::MockRequest.env_for("/?foo=bar&baz=bar"))[2].body.should == "bar bar bar" + request("/action_args/defaults_mixed?foo=bar&baz=bar").body.should == "bar bar bar" end - it "should throw a BadRequest if the arguments are not provided" do - lambda { ActionArgsController.action(:index).call(Rack::MockRequest.env_for("/")) }.should raise_error(AbstractController::BadRequest) + it "should throw a 400 Bad Request if the arguments are not provided" do + request("/action_args/index").status.should == 400 end it "should treat define_method actions as equal" do - ActionArgsController.action(:dynamic_define_method).call(Rack::MockRequest.env_for("/"))[2].body.should == "mos def" + request("/action_args/dynamic_define_method").body.should == "mos def" end it "should be able to inherit actions for use with Action Arguments" do - ActionArgsController.action(:funky_inherited_method).call(Rack::MockRequest.env_for("/?foo=bar&bar=baz"))[2].body.should == "bar baz" + request("/action_args/funky_inherited_method?foo=bar&bar=baz").body.should == "bar baz" end it "should be able to handle nil defaults" do - ActionArgsController.action(:with_default_nil).call(Rack::MockRequest.env_for("/?foo=bar"))[2].body.should == "bar " + request("/action_args/with_default_nil?foo=bar").body.should == "bar " end it "should be able to handle [] defaults" do - ActionArgsController.action(:with_default_array).call(Rack::MockRequest.env_for("/?foo=bar"))[2].body.should == "bar []" + request("/action_args/with_default_array?foo=bar").body.should == "bar []" end it "should print out the missing parameters if all are required" do - lambda { ActionArgsController.action(:multi).call(Rack::MockRequest.env_for("/")) }.should raise_error( - AbstractController::BadRequest, /were missing foo, bar/) + response = request("/action_args/multi") + response.status.should == 400 + response.body.should include("were missing foo, bar") end - + it "should only print out missing parameters" do - lambda { ActionArgsController.action(:multi).call(Rack::MockRequest.env_for("/?foo=Hello")) }.should raise_error( - AbstractController::BadRequest, /were missing bar/) + response = request("/action_args/multi?foo=Hello") + response.status.should == 400 + response.body.should include("were missing bar") end end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f1760a3..ed7c5eb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,4 +8,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), "controllers", "action_args_controller")) Spec::Runner.configure do |config| + config.include(Rack::Test::Methods) end