PageRenderTime 57ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/test/functional/your_data_controller_test.rb

http://rubytime.googlecode.com/
Ruby | 215 lines | 163 code | 39 blank | 13 comment | 0 complexity | a205eaf075da31d096a39bde6ddb0c1f MD5 | raw file
  1. require File.dirname(__FILE__) + '/../test_helper'
  2. require 'your_data_controller'
  3. # Re-raise errors caught by the controller.
  4. class YourDataController;
  5. def rescue_action(e) raise e end;
  6. end
  7. class YourDataControllerTest < Test::Unit::TestCase
  8. fixtures :activities, :users, :projects, :clients, :roles
  9. def setup
  10. @controller = YourDataController.new
  11. @request = ActionController::TestRequest.new
  12. @response = ActionController::TestResponse.new
  13. login_as :pm
  14. end
  15. def test_index
  16. get :index
  17. assert_response :success
  18. assert_template 'activities_calendar'
  19. end
  20. def test_activities_list
  21. get :activities_list
  22. assert_response :success
  23. assert_template 'activities_list'
  24. assert_not_nil assigns(:activities)
  25. assert_equal 7, assigns(:activities).length
  26. #chronological order
  27. assert descending?(assigns(:activities), :date), "Activities should be in descending order"
  28. end
  29. def test_activities_list_with_year_and_month
  30. #with session conditions
  31. @request.session[:year] = 2006.to_s
  32. @request.session[:month] = 8.to_s
  33. get :activities_list
  34. assert_not_nil assigns(:activities)
  35. assert_equal Activity.count(:conditions => "#{SqlFunction.get_month_equation('date', 8)} AND #{SqlFunction.get_year('date')} = '2006' " +
  36. " AND user_id = #{users(:pm).id}"), assigns(:activities).size
  37. #chronological order
  38. assert descending?(assigns(:activities), :date), "Activities should be in descending order"
  39. end
  40. def test_activities_list_with_search_params
  41. get :activities_list, :search => {:date_from => "2000-01-01", :date_to => "2004-04-04", :user_id => 1}
  42. assert_not_nil assigns(:activities)
  43. assert_equal 2, assigns(:activities).size
  44. assert descending?(assigns(:activities), :date), "Activities should be in descending order"
  45. end
  46. def test_show_activity
  47. get :show_activity, :id => 1
  48. assert_response :success
  49. assert_template 'show_activity'
  50. assert_not_nil assigns(:activity)
  51. assert assigns(:activity).valid?
  52. end
  53. def test_show_activity_doesnt_show_other_users_activities
  54. login_as :dev
  55. get :show_activity, :id => 1
  56. assert_response :success
  57. assert_template 'users/_no_permissions'
  58. end
  59. def test_new_activity
  60. get :new_activity
  61. assert_response :success
  62. assert_template 'new_activity'
  63. assert_not_nil assigns(:activity)
  64. end
  65. def test_create_activity
  66. num_activities = Activity.count
  67. post :create_activity, :activity => {:comments => "Some comment", :project_id => 1, :minutes => "1",
  68. 'date(1i)' => '2001', 'date(2i)' => '02', 'date(3i)' => '03'}
  69. assert_response :redirect
  70. assert_redirected_to :action => 'activities_list'
  71. assert_equal num_activities + 1, Activity.count
  72. end
  73. def test_create_activity_allow_duplicate_but_display_flash_warning
  74. num_activities = Activity.count
  75. post :create_activity, :activity => {:comments => "First", :project_id => 1, :minutes => '2',
  76. 'date(1i)' => '2001', 'date(2i)' => '02', 'date(3i)' => '03'}
  77. post :create_activity, :activity => {:comments => "Second", :project_id => 1, :minutes => '3',
  78. 'date(1i)' => '2001', 'date(2i)' => '02', 'date(3i)' => '03'}
  79. assert_response :redirect
  80. assert_match /already have activity/i, flash[:warning]
  81. assert_equal num_activities + 2, Activity.count
  82. end
  83. def test_edit_activity
  84. get :edit_activity, :id => 1
  85. assert_response :success
  86. assert_template 'edit_activity'
  87. assert_not_nil assigns(:activity)
  88. assert assigns(:activity).valid?
  89. end
  90. def test_update_activity
  91. post :update_activity, :id => 1, :activity => {:minutes => "8:00"}
  92. assert_response :redirect
  93. assert_redirected_to :action => 'activities_list', :id => 1
  94. post :update_activity, :id => 1, :activity => {:minutes => "0"}
  95. assert_response :success
  96. assert_template "edit_activity"
  97. assert_not_nil flash[:notice]
  98. end
  99. def test_edit_rss_feed
  100. get :edit_rss_feed
  101. assert_response :success
  102. assert_not_nil assigns(:feed)
  103. assert_equal assigns(:feed), RssFeed.find_by_owner_id_and_owner_type(users(:pm).id, "User")
  104. assert_template "edit_rss_feed"
  105. end
  106. def test_edit_rss_feed_feed_is_created_on_demand
  107. login_as :admin2
  108. get :edit_rss_feed
  109. assert_response :success
  110. assert_not_nil assigns(:feed)
  111. assert_equal assigns(:feed), RssFeed.find_by_owner_id_and_owner_type(users(:admin2).id, "User")
  112. end
  113. def test_edit_rss_feed_not_manager
  114. login_as :dev
  115. get :edit_rss_feed
  116. assert_response :success
  117. assert_template 'users/_no_permissions'
  118. end
  119. def test_update_rss_feed
  120. post :update_rss_feed, :authentication => 'key', :user_4 => 1, :user_7 => 1, :role_3 => 1, :project_3 => 1, :project_4 => 1, :project_5 => 1
  121. feed = users(:pm).rss_feed
  122. assert_equal 'key', feed.authentication
  123. assert_equal '1234512345', feed.secret_key
  124. assert_redirected_to :action => 'edit_rss_feed'
  125. assert_equal [3, 4, 5], feed.elements.projects.sort
  126. assert_equal [4, 7], feed.elements.users.sort
  127. assert_equal [3], feed.elements.roles
  128. end
  129. def test_update_rss_feed_http
  130. post :update_rss_feed, :authentication => 'http'
  131. assert_equal 'http', users(:pm).rss_feed.authentication
  132. assert_redirected_to :action => 'edit_rss_feed'
  133. end
  134. def test_update_rss_feed_regenerate_key
  135. post :update_rss_feed, :authentication => 'key', :regenerate_key => '1'
  136. assert_equal 'key', users(:pm).rss_feed.authentication
  137. assert_not_equal '1234512345', users(:pm).rss_feed.secret_key
  138. assert_redirected_to :action => 'edit_rss_feed'
  139. end
  140. def test_rss_bad_id
  141. get :rss, :format => 'html', :id => 1024
  142. assert_response :success
  143. assert_match /not found/, @response.body
  144. end
  145. def test_rss_another_user
  146. login_as :admin2
  147. get :rss, :format => :html, :id => 1
  148. assert_response :success
  149. assert_match /denied/, @response.body
  150. end
  151. def test_rss_with_no_key
  152. get :rss, :format => :rss, :id => 1
  153. assert_response :success
  154. assert_match /denied/, @response.body
  155. end
  156. def test_rss_with_wrong_key
  157. get :rss, :format => :rss, :id => 1, :key => "idontknowthekey"
  158. assert_response :success
  159. assert_match /denied/, @response.body
  160. end
  161. def test_rss_with_correct_key
  162. get :rss, :format => :rss, :id => 1, :key => "1234512345"
  163. # TODO: the assertion below doesn't work, fix something...
  164. #assert_response :success
  165. assert_not_nil assigns(:days)
  166. assert_not_nil assigns(:pub_dates)
  167. assert_equal assigns(:days).keys.sort, assigns(:pub_dates).keys.sort
  168. # TODO: test the results
  169. end
  170. # TODO: this doesn't work
  171. # def test_http_authorization
  172. # http_authorize(users(:pm).login, "admin")
  173. # get :rss, :format => :xml, :id => 2
  174. # assert_response :success
  175. # end
  176. end