spec/optionsful_server_spec.rb in optionsful-0.3.2 vs spec/optionsful_server_spec.rb in optionsful-0.4.0
- old
+ new
@@ -1,8 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
include Rack::Test::Methods
-require 'fileutils'
describe "Optionsful" do
context "as a Rack middleware" do
@@ -175,11 +174,10 @@
response[1]["Allow"].should include "GET"
response[1]["Allow"].should include "POST"
end
it "the parent resource collection have an entry point for creating a new entry" do
- pending "check regexp"
response = http_options_request("/products/new")
validate_response(response)
response[0].should be 204
response[1]["Allow"].should include "GET"
response[1]["Allow"].should_not include "POST"
@@ -245,11 +243,10 @@
response[1]["Allow"].should_not include "PUT"
response[1]["Allow"].should_not include "DELETE"
end
it "the sub-resource collection have an entry point for creating a new entry" do
- pending "check regexp"
response = http_options_request("/products/123/sales/new")
validate_response(response)
response[0].should be 204
response[1]["Allow"].should include "GET"
response[1]["Allow"].should_not include "POST"
@@ -389,28 +386,26 @@
Rails.application.reload_routes!
end
end
-
-
end
- context "Link" do
+ context "the Link header" do
describe "should not be present" do
before(:each) do
rails_app.routes.draw do
resources :posts
end
+ ::Baurets::Optionsful::Config.new
end
it "if no directions were given" do
- FileUtils.mv File.join(Rails.root, 'config', 'optionsful.yml'), File.join(Rails.root, 'optionsful.yml')
+ Baurets::Optionsful::Config.new(nil, {:link => false})
response = http_options_request("/posts")
- FileUtils.mv File.join(Rails.root, 'optionsful.yml'), File.join(Rails.root, 'config', 'optionsful.yml')
validate_response(response)
response[0].should be 204
response[1]["Link"].should be nil
end
@@ -427,14 +422,51 @@
resources :posts
end
end
it "the Link header MUST be quoted if it contains a semicolon or comma" do
+ Baurets::Optionsful::Config.new(nil, {:link => true})
response = http_options_request("/posts")
validate_response(response)
response[0].should be 204
link = response[1]["Link"]
link.should match /\A\".+\"\z/
+ end
+
+ it "the Link header may use its very current host" do
+ Baurets::Optionsful::Config.new(nil, {:link => true, :host => 'auto'})
+ response = http_options_request("/posts")
+ validate_response(response)
+ response[0].should be 204
+ link = response[1]["Link"]
+ link.should match /\A\"<http:\/\/localhost.+\"\z/
+ end
+
+ it "the Link header may use a custom host value" do
+ Baurets::Optionsful::Config.new(nil, {:link => true, :host => 'www.baurets.net'})
+ response = http_options_request("/posts")
+ validate_response(response)
+ response[0].should be 204
+ link = response[1]["Link"]
+ link.should match /\A\"<http:\/\/www.baurets.net.+\"\z/
+ end
+
+ it "the Link header may use a custom base path value" do
+ Baurets::Optionsful::Config.new(nil, {:link => true, :host => 'www.baurets.net', :base_path => "/private/api/"})
+ response = http_options_request("/posts")
+ validate_response(response)
+ response[0].should be 204
+ link = response[1]["Link"]
+ link.should match /\A\"<http:\/\/www.baurets.net\/private\/api\/.+\"\z/
+ end
+
+ it "the Link header may propagate original path info" do
+ Baurets::Optionsful::Config.new(nil, {:link => true, :host => 'www.baurets.net', :base_path => "/private/api/", :propagate => true})
+ response = http_options_request("/posts")
+ validate_response(response)
+ response[0].should be 204
+ link = response[1]["Link"]
+ link.should match /\A\"<http:\/\/www.baurets.net\/private\/api\/\/posts.+\"\z/
end
after(:all) do
Rails.application.reload_routes!
end