Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / radiant_specs / test / unit / .svn / text-base / page_context_test.rb.svn-base
blob42b631ec4c2ad67852be1518cb0d66a13db72042
1 require File.dirname(__FILE__) + '/../test_helper'
3 class PageContextTest < Test::Unit::TestCase
4   fixtures :pages, :page_parts, :layouts, :snippets, :users
5   test_helper :pages
6   
7   def setup
8     @page = pages(:radius)
9     @context = PageContext.new(@page)
10     @parser = Radius::Parser.new(@context, :tag_prefix => 'r')
11   end
12     
13   def test_initialize
14     assert_equal(@page, @context.page)
15   end
16   
17   def test_tag_missing
18     assert_raises(StandardTags::TagError) { @parser.parse '<r:missing />' }
19     def @context.testing?() false end
20     assert_parse_output_match "undefined tag `missing'", '<r:missing />'
21   end
22   
23   def test_request_is_passed_around
24     @context.define_tag "if_request" do |tag|
25       tag.expand if tag.locals.page.request
26     end
27     assert_parse_output_match /^$/, '<r:if_request>tada!</r:if_request>'
28     
29     @page.request = ActionController::TestRequest.new
30     assert_parse_output_match "tada!", '<r:if_request>tada!</r:if_request>'
31     assert_parse_output_match "tada!", '<r:find url="/another/"><r:if_request>tada!</r:if_request></r:find>'
32   end
33   
34   def test_response_is_passed_around
35     @context.define_tag "if_response" do |tag|
36       tag.expand if tag.locals.page.response
37     end
38     assert_parse_output_match /^$/, '<r:if_response>tada!</r:if_response>'
39     
40     @page.response = ActionController::TestResponse.new
41     assert_parse_output_match "tada!", '<r:if_response>tada!</r:if_response>'
42     assert_parse_output_match "tada!", '<r:find url="/another/"><r:if_response>tada!</r:if_response></r:find>'
43   end
45   def test_exception_pops_stack
46     assert_equal '', @context.current_nesting
47     @context.define_tag("error") {|tag| raise "Broken!"}
48     def @context.testing?(); false; end
49     assert_parse_output_match /Broken\!/, "<r:error/>"
50     assert_equal '', @context.current_nesting
51   end
53   private
54     
55     def assert_parse_output_match(regexp, input)
56       output = @parser.parse(input)
57       assert_match regexp, output
58     end
59     
60 end