1 require File.dirname(__FILE__) + '/../test_helper'
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}")
10 @request.env["RAW_POST_DATA"] = c.to_s
13 def test_showing_new_diary_entry
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
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
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
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
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
50 assert_response :redirect
51 assert_redirected_to :controller => :user, :action => "login", :referer => "/diary_entry/edit"
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"
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
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
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
86 def test_editing_creating_diary_comment
90 def test_listing_diary_entries
100 def test_viewing_diary_entry