require File.dirname(__FILE__) + '/spec_helper.rb' require "rack" require "rack/test" require_fixtures 'application_spec_applications' describe Trellis::Page, " when sending an event to a page" do include Rack::Test::Methods def app TestApp::MyApp.new end it "should redirect to the receiving page if the event handler returns self" do get "/home/events/event1" redirect = last_response.headers['Location'] redirect.should eql('/home') end it "should return a response as a string if the event handler returns a String" do get "/home/events/event2" last_response.body.should == "just some text" end it "should redirect to the injected page as a response if the event handler returns an injected page" do get "/home/events/event3" redirect = last_response.headers['Location'] redirect.should eql('/other') end it "should be able to pass a value as the last element or the URL" do get "/home/events/event4/quo%20vadis" last_response.body.should == "the value is quo vadis" end end describe Trellis::Page, " when calling inject_dependent_pages on an instance of Page" do it "should contain instances of the injected pages" do homepage = TestApp::Home.new homepage.inject_dependent_pages injected_page = homepage.instance_eval { @other } injected_page.should be_an_instance_of(TestApp::Other) end end describe Trellis::Page, " when created with a custom route" do it "should contain an instance of Router" do router = TestApp::RoutedDifferently.router router.should_not be_nil router.should be_an_instance_of(Trellis::Router) end end describe Trellis::Page, " when provided with a #get method" do include Rack::Test::Methods def app TestApp::MyApp.new end it "should redirect to the page returned" do get "/page_with_get_redirect" redirect = last_response.headers['Location'] redirect.should eql('/other') end it "should return a response as a string if the ==get== methood returns a String" do get "/page_with_get_plain_text" last_response.body.should == "some content" end it "should render the result of the ==get== method if it is the same page" do get "/page_with_get_same" last_response.body.should include("

Vera, what has become of you?

") end end describe Trellis::Page, " when given a template" do include Rack::Test::Methods def app TestApp::MyApp.new end it "should rendered it correctly if it is in HAML format" do get "/haml_page" last_response.body.should include(%[\n This is a HAML page\n \n \n \n

\n Page Title\n

\n

\n HAML rocks!\n

]) end it "should rendered it correctly if it is in Textile format" do get "/textile_page" last_response.body.should == "\n

A simple example.

\n" end it "should rendered it correctly if it is in Markdown format" do get "/mark_down_page" last_response.body.should include(%[body>

This is the Title

\n\n

This is the SubTitle

\n\n

This is some text]) end it "should rendered it correctly if it is in ERuby format" do get "/e_ruby_page" last_response.body.should include("

  • Hey
  • ") last_response.body.should include("
  • bud
  • ") last_response.body.should include("
  • let's
  • ") last_response.body.should include("
  • party!
  • ") end it "should rendered it correctly if it is in HTML format" do get "/html_page" last_response.body.should include("

    This is just HTML

    ") end end describe Trellis::Page do include Rack::Test::Methods before do @application = TestApp::MyApp.new end def app @application end it "should have access to application constants in ERuby format" do get "/constant_access_page" last_response.body.should include("

    it's just us, chickens!

    ") end it "should have access to application methods in ERuby format" do get "/method_access_page" last_response.body.should include("

    helloooo, la la la

    ") end it "should invoke the before_load method if provided by the page" do get "/before_load" last_response.body.should include("8675309") end it "should invoke the after_load method if provided by the page" do get "/after_load" last_response.body.should include("chunky bacon!") end it "should invoke the before_render method if provided by the page" do get "/before_render" last_response.body.should include("8675309") end it "should invoke the after_render method if provided by the page" do env = Hash.new env["rack.session"] = Hash.new get "/after_render", {}, env env["rack.session"][:my_field].should include("changed in after_render method") end it "should redirect if giving an explicit redirect" do get '/explicit_redirect' redirect = last_response.headers['Location'] redirect.should eql('/hello/Ford%20Prefect') get redirect last_response.body.should include("

    Hello

    \n \n Ford%20Prefect") end end