]> git.openstreetmap.org Git - rails.git/blob - test/functional/diary_entry_controller_test.rb
cb78773365186042b1c99a8b6d3ef90cadf27a1b
[rails.git] / test / functional / diary_entry_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class DiaryEntryControllerTest < ActionController::TestCase
4   fixtures :users, :diary_entries, :diary_comments
5   def basic_authorization(user, pass)
6     @request.env["HTTP_AUTHORIZATION"] = "Basic %s" % Base64.encode64("#{user}:#{pass}")
7   end
8
9   def content(c)
10     @request.env["RAW_POST_DATA"] = c.to_s
11   end
12   
13   def test_showing_new_diary_entry
14     get :new
15     assert_response :redirect
16     assert_redirected_to :controller => :user, :action => "login", :referer => "/diary_entry/new"
17     # Now pretend to login by using the session hash, with the 
18     # id of the person we want to login as through session(:user)=user.id
19     get(:new, nil, {'user' => users(:normal_user).id})
20     assert_response :success
21     #print @response.body
22     
23     #print @response.to_yaml
24     assert_select "html:root", :count => 1 do
25       assert_select "head", :count => 1 do
26         assert_select "title", :text => /New diary entry/, :count => 1
27       end
28       assert_select "body", :count => 1 do
29         assert_select "div#content", :count => 1 do
30           assert_select "h1", "New diary entry", :count => 1
31           # We don't care about the layout, we just care about the form fields
32           # that are available
33           assert_select "form[action='/diary_entry/new']", :count => 1 do
34             assert_select "input[id=diary_entry_title][name='diary_entry[title]']", :count => 1
35             assert_select "textarea#diary_entry_body[name='diary_entry[body]']", :count => 1
36             assert_select "input#latitude[name='diary_entry[latitude]'][type=text]", :count => 1
37             assert_select "input#longitude[name='diary_entry[longitude]'][type=text]", :count => 1
38             assert_select "input[name=commit][type=submit][value=Save]", :count => 1
39           end
40         end
41       end
42     end
43         
44   end
45   
46   def test_editing_diary_entry
47     # Make sure that you are redirected to the login page when you are 
48     # not logged in, without and with the id of the entry you want to edit
49     get :edit
50     assert_response :redirect
51     assert_redirected_to :controller => :user, :action => "login", :referer => "/diary_entry/edit"
52     
53     get :edit, :id => diary_entries(:normal_user_entry_1).id
54     assert_response :redirect
55     assert_redirected_to :controller => :user, :action => "login", :referer => "/diary_entry/edit"
56     
57     # Verify that you get a not found error, when you don't pass an id
58     get(:edit, nil, {'user' => users(:normal_user).id})
59     assert_response :not_found
60     assert_select "html:root", :count => 1 do
61       assert_select "body", :count => 1 do
62         assert_select "div#content", :count => 1 do
63           assert_select "h2", :text => "No entry with the id:", :count => 1 
64         end
65       end
66     end
67     
68     # Now pass the id, and check that you can edit it
69     get(:edit, {:id => diary_entries(:normal_user_entry_1).id}, {'user' => users(:normal_user).id})
70     assert_response :success
71     assert_select "html:root", :count => 1 do
72       assert_select "head", :count => 1 do
73         assert_select "title", :text => /Edit diary entry/, :count => 1
74       end
75       assert_select "body", :count => 1 do
76         assert_select "div#content", :count => 1 do 
77           assert_select "h1", :text => /Edit diary entry/, :count => 1
78           assert_select "form[action='/diary_entry/#{diary_entries(:normal_user_entry_1).id}/edit'][method=post]", :count => 1
79         end
80       end
81     end
82         
83     #print @response.body
84   end
85   
86   def test_editing_creating_diary_comment
87     
88   end
89   
90   def test_listing_diary_entries
91     
92   end
93   
94   def test_rss
95     get :rss
96     assert :success
97     
98   end
99   
100   def test_viewing_diary_entry
101     
102   end
103 end