PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/test/functional/groups_controller_test.rb

https://github.com/newrooky/lftwb
Ruby | 189 lines | 156 code | 31 blank | 2 comment | 0 complexity | 1413e9c25e8cd25e074936c2e877a3b2 MD5 | raw file
Possible License(s): MIT
  1. require File.dirname(__FILE__) + '/../test_helper'
  2. class GroupsControllerTest < Test::Unit::TestCase
  3. def setup
  4. @controller = GroupsController.new
  5. @request = ActionController::TestRequest.new
  6. @response = ActionController::TestResponse.new
  7. @group = groups(:africa)
  8. @africa = groups(:africa)
  9. @invisible = groups(:invisible)
  10. end
  11. should_require_login :new, :create, :edit, :update, :destroy
  12. def self.should_deny_group_admin_actions(name)
  13. context "deny access to admin actions" do
  14. setup do
  15. @group_to_test = self.instance_variable_get("@#{name.to_s}")
  16. end
  17. should "now allow edit" do
  18. get :edit, :id => @group_to_test.to_param
  19. assert_redirected_to group_url(@group_to_test)
  20. ensure_flash(PERMISSION_DENIED_MSG)
  21. end
  22. should "not allow update" do
  23. put :update, :id => @group_to_test.to_param
  24. assert_redirected_to group_url(@group_to_test)
  25. ensure_flash(PERMISSION_DENIED_MSG)
  26. end
  27. should "not allow destroy" do
  28. delete :destroy, :id => @group_to_test.to_param
  29. assert_redirected_to group_url(@group_to_test)
  30. ensure_flash(PERMISSION_DENIED_MSG)
  31. end
  32. end
  33. end
  34. context "not logged in" do
  35. context "view normal group" do
  36. setup do
  37. get :show, :id => groups(:africa).to_param
  38. end
  39. should_respond_with :success
  40. should_render_template :show
  41. end
  42. context "view invisible group" do
  43. setup do
  44. get :show, :id => groups(:invisible).to_param
  45. end
  46. should_redirect_to "groups_path"
  47. end
  48. context "view private group" do
  49. setup do
  50. get :show, :id => groups(:private).to_param
  51. end
  52. should_respond_with :success
  53. should_render_template :show
  54. should "show group information" do
  55. assert_select "#information", :count => 1
  56. end
  57. should "not show group officers" do
  58. assert_select "#group-officers", :count => 0
  59. end
  60. end
  61. context "get index page" do
  62. setup do
  63. get :index
  64. end
  65. should "not show invisible groups" do
  66. # check the page to make sure the invisible group isn't there
  67. # assert_select ".invisible", :count => 0
  68. end
  69. end
  70. end
  71. context "logged in, not a member" do
  72. setup do
  73. login_as users(:aaron)
  74. @group = groups(:invisible)
  75. end
  76. should_deny_group_admin_actions(:africa)
  77. should_deny_group_admin_actions(:invisible)
  78. context "view invisible group" do
  79. setup do
  80. get :show, :id => @group.to_param
  81. end
  82. should_redirect_to "groups_path"
  83. end
  84. end
  85. context "logged in member - not manager or admin" do
  86. setup do
  87. login_as users(:africa_member)
  88. @group = groups(:africa)
  89. end
  90. should_deny_group_admin_actions(:africa)
  91. should_deny_group_admin_actions(:invisible)
  92. context "view invisible group" do
  93. setup do
  94. login_as users(:invisible_member)
  95. get :show, :id => groups(:invisible).to_param
  96. end
  97. should_respond_with :success
  98. should_render_template :show
  99. end
  100. end
  101. context "logged in manager" do
  102. setup do
  103. @admin_user = users(:admin)
  104. login_as @admin_user
  105. end
  106. should_be_restful do |resource|
  107. resource.actions = [:index, :show, :edit, :update]
  108. resource.formats = [:html]
  109. resource.create.params = { :name => "a random new group", :description => 'this is the random group', :default_role => 'member'}
  110. resource.update.params = { :name => "Changed", :description => 'this is the changed, random group' }
  111. end
  112. context "show the group" do
  113. setup do
  114. get :show, :id => groups(:africa).to_param
  115. end
  116. should_respond_with :success
  117. should_render_template :show
  118. should "have a join link since admin isn't a member" do
  119. assert_select "div#join_group"
  120. assert_select "a", :text => "Join #{groups(:africa).name}"
  121. end
  122. end
  123. context "update group" do
  124. setup do
  125. @new_group_name = 'new group name asdf'
  126. @new_description = 'new group description'
  127. put :update, :id => @group.to_param, :group => { :name => @new_group_name, :description => @new_description }
  128. end
  129. should_redirect_to "group_path(@group)"
  130. should_set_the_flash_to(/Group was successfully updated/i)
  131. should "have new values" do
  132. @group.reload
  133. assert @group.name == @new_group_name
  134. assert @group.description == @new_description
  135. end
  136. end
  137. context "DELETE to destroy" do
  138. setup do
  139. @group = Factory(:group, :creator => @admin_user)
  140. end
  141. should "delete a group" do
  142. assert_difference "Group.count", -1 do
  143. delete :destroy, { :id => @group.to_param }
  144. assert_redirected_to groups_url
  145. end
  146. end
  147. end
  148. end
  149. end