require "#{File.expand_path(File.dirname(__FILE__))}/helper" describe "HttpController" do with_environment :test with_http before :all do @dir = "#{File.expand_path(File.dirname(__FILE__))}/http_controller_spec" $LOAD_PATH << @dir HttpController = Crystal::HttpController crystal.after :environment do crystal.conveyors.web do |web| web.use Crystal::Processors::HttpWriter, :content web.use Crystal::Processors::ControllerCaller, :content end end end after :all do $LOAD_PATH.delete @dir remove_constants %w( HttpController ContentTypeSpec StatusSpec LocationSpec ForbidGetSpec ) end describe 'render' do it "should take :content_type option" do class ::ContentTypeSpec inherit HttpController def action render :inline => "some content", :content_type => Mime['js'] end end wcall(ContentTypeSpec, :action) response.content_type.should == "application/javascript" end it "should take :status option" do class ::StatusSpec inherit HttpController def action render :inline => "some content", :status => 220 end end wcall(StatusSpec, :action) response.status.should == 220 end it "should take :location option" do class ::LocationSpec inherit HttpController def action render :location => "/", :status => 220 end end wcall(LocationSpec, :action) response.location.should == "/" response.status.should == 220 end end it "should be able to protect methods from GET request" do class ::ForbidGetSpec inherit HttpController allow_get_for :get_action def get_action; end def post_action; end end workspace = {:env => {'REQUEST_METHOD' => 'GET'}} wcall(ForbidGetSpec, :get_action, workspace, {}) lambda{ wcall(ForbidGetSpec, :post_action, workspace, {}) }.should raise_error(/not allowed/) end end