Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / radiant_specs / test / functional / admin / .svn / text-base / abstract_model_controller_test.rb.svn-base
blob14ac2daab0bf46fb30d3d1c635c90cefc19564ca
1 require File.dirname(__FILE__) + '/../../test_helper'
4 # This test exercises the AbstractModelController by excercising the Layout
5 # model and the LayoutController views.
7 class Admin::AbstractModelControllerTest < Test::Unit::TestCase
8   
9   class TestModelController < Admin::AbstractModelController
10     model_class Layout
11     
12     def rescue_action(e) raise e end
13     
14     def default_template_name(default_action_name = action_name)
15       "#{Admin::LayoutController.controller_path}/#{default_action_name}"
16     end
17   end
18   
19   fixtures :users, :layouts
20   test_helper :layouts, :caching, :routing, :login
21   
22   def setup
23     @controller = TestModelController.new
24     @request    = ActionController::TestRequest.new
25     @response   = ActionController::TestResponse.new
26     login_as(:existing)
27     @cache = @controller.cache = FakeResponseCache.new
28     
29     @layout_name = "Test Layout"
30     
31     destroy_test_layout
32     setup_custom_routes
33   end
34   
35   def teardown
36     teardown_custom_routes
37   end
38   
39   def test_initialize
40     @controller = TestModelController.new
41     assert_kind_of ResponseCache, @controller.cache
42   end
43   
44   def test_index
45     get :index
46     assert_response :success
47     layouts = assigns(:layouts)
48     assert_kind_of Array, layouts
49     assert_kind_of Layout, layouts.first
50   end
51   
52   def test_new
53     get :new, :layout => layout_params
54     assert_response :success
55     assert_template 'admin/layout/edit'
56     
57     @layout = assigns(:layout)
58     assert_kind_of Layout, @layout
59     assert_nil @layout.name
60   end
61   def test_new__post
62     post :new, :layout => layout_params
63     assert_redirected_to layout_index_url
64     assert_match /saved/, flash[:notice]
65     assert_kind_of Layout, get_test_layout
66   end
67   def test_new__post_with_invalid_layout
68     post :new, :layout => layout_params(:name => nil)
69     assert_response :success
70     assert_match /error/, flash[:error]
71     assert_nil get_test_layout
72   end
73   def test_new__save_and_continue_editing
74     post :new, :layout => layout_params, :continue => 'Save and Continue Editing'
75     @layout = get_test_layout
76     assert_redirected_to layout_edit_url(:id => @layout.id)
77   end
78   
79   def test_edit
80     get :edit, :id => '1', :layout => layout_params
81     assert_response :success
82     
83     @layout = assigns(:layout)
84     assert_kind_of Layout, @layout
85     assert_equal 'Home Page', @layout.name
86   end  
87   def test_edit__post
88     @layout = create_test_layout
89     post :edit, :id => @layout.id, :layout => layout_params(:content => 'edited')
90     assert_response :redirect
91     assert_equal 'edited', get_test_layout.content
92     
93     # TODO: Test what happens when an invalid page is submitted 
94   end
95   
96   def test_remove
97     @layout = create_test_layout
98     get :remove, :id => @layout.id 
99     assert_response :success
100     assert_equal @layout, assigns(:layout)
101     assert_not_nil get_test_layout
102   end
103   def test_remove__post
104     @layout = create_test_layout
105     post :remove, :id => @layout.id
106     assert_nil get_test_layout
107     assert_redirected_to layout_index_url
108     assert_match /deleted/, flash[:notice]
109   end
110   
111   def test_clears_cache_on_save
112     @layout = layouts(:main)
113     post :edit, :id => @layout.id, :layout => layout_params(:content => 'edited')
114     assert_redirected_to layout_index_url
115     assert_equal true, @cache.cleared?
116   end
117   
118   def test_not_cleared_when_invalid
119     @layout = layouts(:main)
120     post :edit, :id => @layout.id, :layout => layout_params(:name => 'x' * 1000)
121     assert_response :success
122     assert_equal false, @cache.cleared?
123   end
124