OpenProject is the leading open source project management software.
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.
openproject/spec_legacy/unit/watcher_spec.rb

118 lines
3.5 KiB

#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See docs/COPYRIGHT.rdoc for more details.
#++
require 'legacy_spec_helper'
describe Watcher do
before do
@user = FactoryBot.create :user
@issue = FactoryBot.create :work_package
@role = FactoryBot.create :role, permissions: [:view_work_packages]
@issue.project.add_member! @user, @role
end
it 'should add_watcher' do
@issue.add_watcher(@user)
assert_contains @issue.watchers.map(&:user), @user
end
it 'should add_watcher_will_not_add_same_user_twice' do
assert @issue.add_watcher(@user)
refute @issue.add_watcher(@user)
end
it 'should watched_by' do
@issue.add_watcher(@user)
assert @issue.watched_by?(@user)
assert_contains WorkPackage.watched_by(@user), @issue
end
it 'watcher_users contains correct_classes' do
@issue.add_watcher(@user)
expect(@issue.watcher_users).to all be_kind_of(User)
end
it 'should watcher_users_should_not_validate_user' do
skip 'Is a known issue in 5.0.0 has_many: https://github.com/rails/rails/issues/25718'
Convert specs to RSpec 3.2.0 syntax with Transpec This conversion is done by Transpec 3.1.0 with the following command: transpec -f -c "bundle exec rspec -Itest" test/functional/account_controller_test.rb test/functional/activities_controller_test.rb test/functional/admin_controller_test.rb test/functional/application_controller_test.rb test/functional/attachments_controller_test.rb test/functional/boards_controller_test.rb test/functional/custom_fields_controller_test.rb test/functional/enumerations_controller_test.rb test/functional/groups_controller_test.rb test/functional/help_controller_test.rb test/functional/journals_controller_test.rb test/functional/mail_handler_controller_test.rb test/functional/messages_controller_test.rb test/functional/my_controller_test.rb test/functional/project_enumerations_controller_test.rb test/functional/projects_controller_test.rb test/functional/repositories_controller_test.rb test/functional/repositories_filesystem_controller_test.rb test/functional/repositories_git_controller_test.rb test/functional/repositories_subversion_controller_test.rb test/functional/roles_controller_test.rb test/functional/search_controller_test.rb test/functional/settings_controller_test.rb test/functional/sys_controller_test.rb test/functional/time_entries/reports_controller_test.rb test/functional/timelog_controller_test.rb test/functional/types_controller_test.rb test/functional/user_mailer_test.rb test/functional/users_controller_test.rb test/functional/watchers_controller_test.rb test/functional/welcome_controller_test.rb test/functional/wiki_controller_test.rb test/functional/wikis_controller_test.rb test/functional/workflows_controller_test.rb test/integration/api_test/disabled_rest_api_test.rb test/integration/api_test/http_accept_auth_test.rb test/integration/api_test/http_basic_login_test.rb test/integration/api_test/http_basic_login_with_api_token_test.rb test/integration/api_test/token_authentication_test.rb test/integration/application_test.rb test/integration/layout_test.rb test/integration/lib/redmine/menu_manager_test.rb test/integration/lib/redmine/themes_test.rb test/integration/routing_test.rb test/unit/activity_test.rb test/unit/attachment_test.rb test/unit/board_test.rb test/unit/category_test.rb test/unit/changeset_test.rb test/unit/comment_test.rb test/unit/custom_field_test.rb test/unit/custom_field_user_format_test.rb test/unit/custom_value_test.rb test/unit/default_data_test.rb test/unit/enabled_module_test.rb test/unit/enumeration_test.rb test/unit/group_test.rb test/unit/helpers/application_helper_test.rb test/unit/helpers/custom_fields_helper_test.rb test/unit/helpers/sort_helper_test.rb test/unit/helpers/timelog_helper_test.rb test/unit/issue_nested_set_test.rb test/unit/issue_priority_test.rb test/unit/journal_observer_test.rb test/unit/journal_test.rb test/unit/ldap_auth_source_test.rb test/unit/lib/open_project/database_test.rb test/unit/lib/redmine/access_control_test.rb test/unit/lib/redmine/ciphering_test.rb test/unit/lib/redmine/codeset_util_test.rb test/unit/lib/redmine/helpers/calendar_test.rb test/unit/lib/redmine/hook_test.rb test/unit/lib/redmine/i18n_test.rb test/unit/lib/redmine/menu_manager/mapper_test.rb test/unit/lib/redmine/menu_manager/menu_helper_test.rb test/unit/lib/redmine/menu_manager/menu_item_test.rb test/unit/lib/redmine/menu_manager_test.rb test/unit/lib/redmine/mime_type_test.rb test/unit/lib/redmine/notifiable_test.rb test/unit/lib/redmine/plugin_test.rb test/unit/lib/redmine/safe_attributes_test.rb test/unit/lib/redmine/scm/adapters/filesystem_adapter_test.rb test/unit/lib/redmine/scm/adapters/git_adapter_test.rb test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb test/unit/lib/redmine/unified_diff_test.rb test/unit/lib/redmine/wiki_formatting/macros_test.rb test/unit/lib/redmine/wiki_formatting/null_formatter_test.rb test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb test/unit/lib/redmine/wiki_formatting_test.rb test/unit/lib/redmine_test.rb test/unit/mail_handler_test.rb test/unit/member_test.rb test/unit/message_test.rb test/unit/principal_test.rb test/unit/project_nested_set_test.rb test/unit/project_test.rb test/unit/query_test.rb test/unit/relation_test.rb test/unit/repository_filesystem_test.rb test/unit/repository_git_test.rb test/unit/repository_subversion_test.rb test/unit/repository_test.rb test/unit/role_test.rb test/unit/search_test.rb test/unit/status_test.rb test/unit/time_entry_activity_test.rb test/unit/time_entry_test.rb test/unit/token_test.rb test/unit/type_test.rb test/unit/user_preference_test.rb test/unit/user_test.rb test/unit/version_test.rb test/unit/watcher_test.rb test/unit/wiki_content_test.rb test/unit/wiki_page_test.rb test/unit/wiki_redirect_test.rb test/unit/wiki_test.rb * 180 conversions from: it { should ... } to: it { is_expected.to ... } * 12 conversions from: obj.stub(:message) to: allow(obj).to receive(:message) * 4 conversions from: Klass.any_instance.should_receive(:message) to: expect_any_instance_of(Klass).to receive(:message) * 4 conversions from: obj.should_receive(:message) to: expect(obj).to receive(:message) * 2 conversions from: Klass.any_instance.stub(:message) to: allow_any_instance_of(Klass).to receive(:message) For more details: https://github.com/yujinakayama/transpec#supported-conversions
10 years ago
allow(@user).to receive(:valid?).and_return(false)
@issue.watcher_users << @user
assert @issue.watched_by?(@user)
end
it 'should watcher_user_ids' do
@issue.add_watcher(@user)
assert_contains @issue.watcher_user_ids, @user.id
end
it 'should watcher_user_ids' do
@issue.watcher_user_ids = [@user.id]
assert @issue.watched_by?(@user)
end
it 'should watcher_user_ids_should_make_ids_uniq' do
@issue.watcher_user_ids = [@user.id, @user.id]
assert @issue.valid?
assert_equal 1, @issue.watchers.count
end
it 'should recipients' do
@user.update_attribute :mail_notification, 'all'
assert @issue.watcher_recipients.empty?
assert @issue.add_watcher(@user)
assert_contains @issue.watcher_recipients, @user
@user.update_attribute :mail_notification, 'none'
assert_does_not_contain @issue.watcher_recipients, @user
end
it 'should unwatch' do
assert @issue.add_watcher(@user)
@issue.save
assert_equal 1, @issue.remove_watcher(@user)
@issue.save
@issue.reload
refute @issue.watched_by?(@user)
end
it 'should prune_removes_watchers_that_dont_have_permission' do
@issue.add_watcher(@user)
assert_no_difference 'Watcher.count' do
Watcher.prune(user: @user)
end
assert @issue.watched_by?(@user)
Member.destroy_all
@issue.reload
refute @issue.watched_by?(@user)
end
end