spec/unit/connection_adapters/http_spec.rb in websocket-rails-0.6.2 vs spec/unit/connection_adapters/http_spec.rb in websocket-rails-0.7.0

- old
+ new

@@ -1,22 +1,43 @@ require 'spec_helper' module WebsocketRails module ConnectionAdapters describe Http do - - subject { Http.new( mock_request, double('Dispatcher').as_null_object ) } - + + subject { + mr = mock_request + mr.stub(:protocol).and_return('http://') + mr.stub(:raw_host_with_port).and_return('localhost:3000') + Http.new(mr , double('Dispatcher').as_null_object ) + } + it "should be a subclass of ConnectionAdapters::Base" do subject.class.superclass.should == ConnectionAdapters::Base end it "should set the Content-Length header to text/json" do subject.headers['Content-Type'].should == "text/json" end it "should set the Transfer-Encoding header to chunked" do subject.headers['Transfer-Encoding'].should == "chunked" + end + + it "should not set the Access-Control-Allow-Origin header" do + subject.headers['Access-Control-Allow-Origin'].should be_blank + end + + context "with IE CORS hack enabled" do + it "should set the Access-Control-Allow-Origin when passed an array as configuration" do + WebsocketRails.config.allowed_origins = ['http://localhost:3000'] + subject.headers['Access-Control-Allow-Origin'].should == 'http://localhost:3000' + end + + it "should set the Access-Control-Allow-Origin when passed a string as configuration" do + WebsocketRails.config.allowed_origins = 'http://localhost:3000' + subject.headers['Access-Control-Allow-Origin'].should == 'http://localhost:3000' + end end context "#encode_chunk" do it "should properly encode strings" do subject.__send__(:encode_chunk,"test").should == "4\r\ntest\r\n"