|
3 | 3 | class PinnedLinksControllerTest < ActionController::TestCase |
4 | 4 | include Devise::Test::ControllerHelpers |
5 | 5 |
|
| 6 | + test ':index should correctly filter by community' do |
| 7 | + sign_in users(:global_moderator) |
| 8 | + |
| 9 | + get :index, params: { global: '1' } |
| 10 | + @links = assigns(:links) |
| 11 | + |
| 12 | + assert_response(:success) |
| 13 | + assert @links.any? |
| 14 | + assert @links.none?(&:community_id?) |
| 15 | + |
| 16 | + get :index, params: { global: '2' } |
| 17 | + @links = assigns(:links) |
| 18 | + |
| 19 | + assert_response(:success) |
| 20 | + assert @links.any? |
| 21 | + |
| 22 | + links_ids = pinned_links.map(&:id) |
| 23 | + |
| 24 | + assert(@links.all? { |link| links_ids.include?(link.id) }) |
| 25 | + end |
| 26 | + |
| 27 | + test ':index should correctly filter by activity status' do |
| 28 | + sign_in users(:moderator) |
| 29 | + |
| 30 | + get :index, params: { filter: 'all' } |
| 31 | + assert_response(:success) |
| 32 | + assert assigns(:links).any? |
| 33 | + |
| 34 | + get :index, params: { filter: 'inactive' } |
| 35 | + @links = assigns(:links) |
| 36 | + |
| 37 | + assert_response(:success) |
| 38 | + assert @links.any? |
| 39 | + assert @links.none?(&:active?) |
| 40 | + end |
| 41 | + |
| 42 | + test ':index should correctly filter by period' do |
| 43 | + sign_in users(:moderator) |
| 44 | + |
| 45 | + now = DateTime.now |
| 46 | + |
| 47 | + get :index |
| 48 | + @links = assigns(:links) |
| 49 | + assert_response(:success) |
| 50 | + assert @links.any? |
| 51 | + |
| 52 | + links_ids = pinned_links.map(&:id) |
| 53 | + assert(@links.all? { |link| links_ids.include?(link.id) }) |
| 54 | + |
| 55 | + get :index, params: { period: 'current' } |
| 56 | + @links = assigns(:links) |
| 57 | + |
| 58 | + assert_response(:success) |
| 59 | + assert @links.any? |
| 60 | + @links.each do |link| |
| 61 | + assert link.current?(now) |
| 62 | + end |
| 63 | + |
| 64 | + get :index, params: { period: 'past' } |
| 65 | + @links = assigns(:links) |
| 66 | + |
| 67 | + assert_response(:success) |
| 68 | + assert @links.any? |
| 69 | + @links.each do |link| |
| 70 | + assert link.past?(now) |
| 71 | + end |
| 72 | + |
| 73 | + get :index, params: { period: 'future' } |
| 74 | + @links = assigns(:links) |
| 75 | + |
| 76 | + assert_response(:success) |
| 77 | + assert @links.any? |
| 78 | + @links.each do |link| |
| 79 | + assert link.future?(now) |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + test ':index should treat invalid period filter as no filter' do |
| 84 | + sign_in users(:moderator) |
| 85 | + |
| 86 | + get :index, params: { period: 'invalid' } |
| 87 | + @links = assigns(:links) |
| 88 | + assert_response(:success) |
| 89 | + |
| 90 | + links_ids = pinned_links.map(&:id) |
| 91 | + assert(@links.all? { |link| links_ids.include?(link.id) }) |
| 92 | + end |
| 93 | + |
| 94 | + test 'only mods or higher should be able to see pinned links' do |
| 95 | + users.each do |user| |
| 96 | + sign_in user |
| 97 | + get :index |
| 98 | + |
| 99 | + assert_response(user.at_least_moderator? ? :success : :not_found) |
| 100 | + end |
| 101 | + end |
| 102 | + |
6 | 103 | test 'only mods or higher should be able to create pinned links' do |
7 | 104 | post = posts(:question_one) |
8 | 105 |
|
@@ -61,7 +158,7 @@ class PinnedLinksControllerTest < ActionController::TestCase |
61 | 158 | assert_equal 'updated label', assigns(:link).label |
62 | 159 | end |
63 | 160 |
|
64 | | - test 'update should correctly handle invlid pinned links' do |
| 161 | + test 'update should correctly handle invalid pinned links' do |
65 | 162 | sign_in users(:moderator) |
66 | 163 | try_update_pinned_link(pinned_links(:active_with_label), link: nil) |
67 | 164 | assert_response(:bad_request) |
|
0 commit comments