require File.dirname(__FILE__) + '/spec_helper' describe Baurets::Optionsful::Server do include Rack::Test::Methods describe "as a Rack middleware" do it "is a Ruby object that responds to call;" do assert ::Baurets::Optionsful::Server.new(app).respond_to? :call end it "takes exactly one argument, (the environment) and returns an Array;" do response = ::Baurets::Optionsful::Server.new(app).call(mock_env({"REQUEST_METHOD" => "OPTIONS", "PATH_INFO" => "/posts"})) assert response.kind_of?(Array) end it "the returned Array must have exactly three values: the status, the headers and the body;" do response = ::Baurets::Optionsful::Server.new(app).call(mock_env({"REQUEST_METHOD" => "OPTIONS", "PATH_INFO" => "/posts"})) assert response.size.should == 3 assert response[0].kind_of? Fixnum assert response[1].kind_of? Hash assert response[2].kind_of? String end before do ActionController::Routing::Routes.draw do |map| map.resources :posts, :has_many => :comments end end it "must be nice, acting somewhere on a Rack middleware stack." do response = fake_opts_app.call(mock_env({"REQUEST_METHOD" => "OPTIONS", "PATH_INFO" => "/posts"})) assert response.size.should == 3 assert response[0].kind_of? Fixnum assert response[0].should == 204 assert response[1].kind_of? Hash assert response[1]["Allow"] end it "must let the request go through the stack, if it has nothing to it" do response = fake_opts_app.call(mock_env({"REQUEST_METHOD" => "GET", "PATH_INFO" => "/lobster"})) assert response.size.should == 3 assert response[0].kind_of? Fixnum assert response[0].should == 200 assert response[1].kind_of? Hash end end describe "is intended to provide HTTP OPTIONS calls for Rails RESTful resources" do describe "to collect the allowed HTTP methods, it overrides Rails routing recognition, so it must understand" do describe "the default Rails resource routing: " do before(:all) do ActionController::Routing::Routes.draw do |map| map.resources :posts, :has_many => :comments end end it "the index action displays a list of all posts in response of a GET request;" do response = http_options_request("/posts") assert response.kind_of?(Array) assert allows?(response[1], "GET") end it "the new action return from a GET request an HTML form for creating a new post;" do response = http_options_request("/posts/new") assert response.kind_of?(Array) assert allows?(response[1], "GET") end it "the create action uses POST to create a new post instance;" do response = http_options_request("/posts") assert response.kind_of?(Array) assert allows?(response[1], "POST") end it "the show action display a specific post in response of a GET request;" do response = http_options_request("/posts/1") assert response.kind_of?(Array) assert allows?(response[1], "GET") end it "the edit action return an HTML form for editing a post in response of a GET request;" do response = http_options_request("/posts/1/edit") assert response.kind_of?(Array) assert allows?(response[1], "GET") end it "the update action uses PUT to update a specific post;" do response = http_options_request("/posts/1") assert response.kind_of?(Array) assert allows?(response[1], "PUT") end it "the destroy action uses DELETE to delete a specific post." do response = http_options_request("/posts/1") assert response.kind_of?(Array) assert allows?(response[1], "DELETE") end it "not found a path" do response = http_options_request("/sblingers/sblongers") assert response.kind_of?(Array) assert response[0].should == 404 end # Note that extension relation types are REQUIRED to be absolute URIs # in Link headers, and MUST be quoted if they contain a semicolon (";") # or comma (",") (as these characters are used as delimiters in the # header itself). it "the Link header MUST be quoted if it contains a semicolon or comma" do response = http_options_request("/posts") assert response.kind_of?(Array) link = response[1]["Link"] assert link.should =~ /\A"{1}.+"\z/ end it "not finding a path, pretend you're dead and.. let it goes through" do pending end end describe "must understand Rails named routes" do before(:each) do ActionController::Routing::Routes.draw do |map| map.login 'login', :controller => 'accounts', :action => 'login' end end it "must understand" do pending end end describe "Rails custom route" do end describe "Rails route globbing" do end describe "Pretty URLs" do end describe "Regular Expressions and parameters" do end end end end