You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

watchers_helper_test.rb 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../test_helper', __FILE__)
  19. class WatchersHelperTest < Redmine::HelperTest
  20. include WatchersHelper
  21. include Rails.application.routes.url_helpers
  22. fixtures :users, :issues
  23. test '#watcher_link with a non-watched object' do
  24. expected = link_to(
  25. "Watch",
  26. "/watchers/watch?object_id=1&object_type=issue",
  27. :remote => true, :method => 'post', :class => "issue-1-watcher icon icon-fav-off"
  28. )
  29. assert_equal expected, watcher_link(Issue.find(1), User.find(1))
  30. end
  31. test '#watcher_link with a single objet array' do
  32. expected = link_to(
  33. "Watch",
  34. "/watchers/watch?object_id=1&object_type=issue",
  35. :remote => true, :method => 'post', :class => "issue-1-watcher icon icon-fav-off"
  36. )
  37. assert_equal expected, watcher_link([Issue.find(1)], User.find(1))
  38. end
  39. test '#watcher_link with a multiple objets array' do
  40. expected = link_to(
  41. "Watch",
  42. "/watchers/watch?object_id%5B%5D=1&object_id%5B%5D=3&object_type=issue",
  43. :remote => true, :method => 'post', :class => "issue-bulk-watcher icon icon-fav-off"
  44. )
  45. assert_equal expected, watcher_link([Issue.find(1), Issue.find(3)], User.find(1))
  46. end
  47. def test_watcher_link_with_nil_should_return_empty_string
  48. assert_equal '', watcher_link(nil, User.find(1))
  49. end
  50. test '#watcher_link with a watched object' do
  51. Watcher.create!(:watchable => Issue.find(1), :user => User.find(1))
  52. expected = link_to(
  53. "Unwatch",
  54. "/watchers/watch?object_id=1&object_type=issue",
  55. :remote => true, :method => 'delete', :class => "issue-1-watcher icon icon-fav"
  56. )
  57. assert_equal expected, watcher_link(Issue.find(1), User.find(1))
  58. end
  59. end