Initial Redmine tooling and local plugin forks

This commit is contained in:
Jason Thistlethwaite
2026-04-24 22:01:18 +00:00
commit 9f682af0eb
683 changed files with 56878 additions and 0 deletions
@@ -0,0 +1,137 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
# encoding: utf-8
require File.expand_path('../../test_helper', __FILE__)
class AddressTest < ActiveSupport::TestCase
def setup
Setting.plugin_redmine_contacts['post_address_format'] = nil
end
def test_should_generate_full_address
address = Address.new
address.street1 = '300 Boylston Ave E'
address.street2 = 'Piso2 Dto.4'
address.city = 'Seattle'
address.region = 'WA'
address.postcode = '98102'
address.country_code = 'US'
address.save
address.reload
assert_equal '300 Boylston Ave E, Piso2 Dto.4, Seattle, 98102, WA, United States', address.full_address
end
def test_should_generate_to_s
address = Address.new
address.street1 = '300 Boylston Ave E'
address.street2 = 'Piso2 Dto.4'
address.city = 'Seattle'
address.region = 'WA'
address.postcode = '98102'
address.country_code = 'US'
assert_equal '300 Boylston Ave E, Piso2 Dto.4, Seattle, 98102, WA, United States', address.to_s
end
def test_should_generate_particular_full_address
address = Address.new
address.street1 = '300 Boylston Ave E'
address.city = 'Seattle'
address.postcode = '98102'
address.region = ''
address.country_code = 'US'
address.save
address.reload
assert_equal '300 Boylston Ave E, Seattle, 98102, United States', address.full_address
end
def test_should_generate_us_post_address
address = Address.new
address.street1 = '300 Boylston Ave E'
address.city = 'Seattle'
address.postcode = '98102'
address.region = 'WA'
address.country_code = 'US'
assert_equal "300 Boylston Ave E\nSeattle, 98102\nWA\nUnited States", address.post_address
end
def test_should_generate_us_post_address_with_double_spaces
Setting.plugin_redmine_contacts['post_address_format'] = "%street1%\n%street2%\n%city% %region% %postcode%\n%country%"
address = Address.new
address.street1 = '300 Boylston Ave E'
address.city = 'Seattle'
address.postcode = '98102'
address.region = 'WA'
address.country_code = 'US'
assert_equal "300 Boylston Ave E\nSeattle WA 98102\nUnited States", address.post_address
end
def test_should_generate_ru_post_address
address = Address.new
address.street1 = "ул. Маршала Жукова, 6"
address.city = "г. Арзамас"
address.postcode = '611137'
address.region = "Нижегородская область"
address.country_code = 'RU'
assert_equal "ул. Маршала Жукова, 6\nг. Арзамас, 611137\nНижегородская область\nRussia", address.post_address
end
def test_should_generate_ru_post_address_with_empty_region
address = Address.new
address.street1 = "ул. Новая Басманная, 14"
address.city = "г. Москва"
address.postcode = '145013'
address.country_code = 'RU'
assert_equal "ул. Новая Басманная, 14\nг. Москва, 145013\nRussia", address.post_address
end
def test_should_strip_empty_lines_and_punctuation
Setting.plugin_redmine_contacts['post_address_format'] = "%street1%,\n,%street2%,,,\n%city%, %postcode%\n%region%\n%country%"
address = Address.new
address.city = 'Seattle'
address.region = 'WA'
address.country_code = 'US'
assert_equal "Seattle\nWA\nUnited States", address.post_address
end
def test_should_create_new_address
address = Address.new
address.street1 = 'ул. Новая Басманная, 14'
address.city = 'г. Москва'
address.postcode = '145013'
address.country_code = 'RU'
address.address_type = 'business'
address.addressable = Contact.first
address.save!
assert_equal false, address.new_record?
assert_equal 'ул. Новая Басманная, 14, г. Москва, 145013, Russia', address.full_address
end
end
@@ -0,0 +1,66 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../test_helper', __FILE__)
class ContactImportTest < ActiveSupport::TestCase
fixtures :projects, :users
def test_open_correct_csv
contact_import = ContactImport.new(
:file => Rack::Test::UploadedFile.new(redmine_contacts_fixture_files_path + 'correct.csv', 'text/comma-separated-values'),
:project => Project.first,
:quotes_type => '"'
)
puts contact_import.errors.full_messages unless contact_import.valid?
assert_equal 4, contact_import.imported_instances.count, 'Should find 4 contacts in file'
assert contact_import.save, 'Should save successfully'
end
def test_should_report_error_line
contact_import = ContactImport.new(
:file => Rack::Test::UploadedFile.new(redmine_contacts_fixture_files_path + 'with_data_malformed.csv', 'text/comma-separated-values'),
:project => Project.first,
:quotes_type => '"'
)
assert !contact_import.save, 'Should not save with malformed date'
assert_equal 1, contact_import.errors.count, 'Should have 1 error'
assert contact_import.errors.first.last.include?("Error on line 1"), 'Should mention string number in error message'
end
def test_open_csv_with_custom_fields
cf1 = ContactCustomField.create!(:name => 'License', :field_format => 'string')
cf2 = ContactCustomField.create!(:name => 'Purchase date', :field_format => 'date')
contact_import = ContactImport.new(
:file => Rack::Test::UploadedFile.new(redmine_contacts_fixture_files_path + 'contacts_cf.csv', 'text/comma-separated-values'),
:project => Project.first,
:quotes_type => '"'
)
assert_equal 1, contact_import.imported_instances.count, 'Should find 1 contact in file'
assert contact_import.save, 'Should save successfully'
contact = Contact.find_by_first_name('Monica')
assert_equal '12345', contact.custom_field_value(cf1.id)
assert_equal 'rhill', contact.assigned_to.login
assert_equal '123456', contact.postcode
assert_equal 'Moscow', contact.city
assert_equal 'Russia', contact.country
end
end
@@ -0,0 +1,256 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../test_helper', __FILE__)
class ContactTest < ActiveSupport::TestCase
fixtures :projects,
:users,
:roles,
:members,
:member_roles,
:issues,
:issue_statuses,
:versions,
:trackers,
:projects_trackers,
:issue_categories,
:enabled_modules,
:enumerations,
:attachments,
:workflows,
:custom_fields,
:custom_values,
:custom_fields_projects,
:custom_fields_trackers,
:time_entries,
:journals,
:journal_details,
:queries
fixtures :email_addresses if ActiveRecord::VERSION::MAJOR >= 4
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
:contacts_projects,
:contacts_issues,
:deals,
:notes,
:tags,
:taggings,
:queries])
def setup
RedmineContacts::TestCase.prepare
end
def test_find_by_emails_first_email
emails = ['marat@mail.ru', 'domoway@mail.ru']
assert_equal 2, Contact.find_by_emails(emails).count
end
def test_find_by_emails_second_email
emails = ['marat@mail.com']
assert_equal 1, Contact.find_by_emails(emails).count
end
def test_scope_live_search
assert_equal 4, Contact.live_search('john').first.try(:id)
end
def test_visible_public_contacts
project = Project.find(1)
contact = Contact.find(1)
user = User.find(1) # John Smith
contact.visibility = Contact::VISIBILITY_PUBLIC
contact.save!
assert contact.visible?(user)
end
def test_visible_scope_for_non_member_without_view_contacts_permissions
# Non member user should not see issues without permission
Role.non_member.remove_permission!(:view_contacts)
user = User.find(9)
assert user.projects.empty?
contacts = Contact.visible(user).all
assert contacts.empty?
assert_visibility_match user, contacts
end
def test_visible_scope_for_member
user = User.find(2)
# User should see issues of projects for which he has view_issues permissions only
role = Role.create!(:name => 'CRM', :permissions => [:view_contacts])
Role.non_member.remove_permission!(:view_contacts)
project = Project.find(2)
Contact.delete_all
Member.where(:user_id => user).delete_all
member = Member.create!(:principal => user, :project_id => project.id, :role_ids => [role.id])
contact = Contact.create!(:project => project, :first_name => 'UnitTest', :visibility => Contact::VISIBILITY_PUBLIC)
contacts = Contact.visible(user).all
assert contacts.any?
assert_nil contacts.detect { |c| c.project.id != project.id }
# assert_nil contacts.detect {|c| c.is_private?}
assert_visibility_match user, contacts
contact.visibility = Contact::VISIBILITY_PRIVATE
contact.save!
contacts = Contact.visible(user).all
assert contacts.blank?, 'Private contacts are visible'
assert user.allowed_to?(:view_contacts, project)
contact.visibility = Contact::VISIBILITY_PROJECT
contact.save!
contacts = Contact.visible(user).all
assert contacts.any?, "Project contacts doesn't visible with permissions"
role.remove_permission!(:view_contacts)
user.reload
contact.visibility = Contact::VISIBILITY_PROJECT
contact.save!
contacts = project.contacts.visible(user).all
assert contacts.blank?, 'Contacts visible for user without view_contacts permissions'
role.add_permission!(:view_private_contacts)
user.reload
contact.visibility = Contact::VISIBILITY_PRIVATE
contact.save!
contacts = Contact.visible(user).all
assert contacts.any?, 'Contacts note visible for user with view_private_contacts permissions'
end
def test_create_should_send_email_notification
ActionMailer::Base.deliveries.clear
contact = Contact.new(:first_name => 'New contact', :project => Project.find(1))
with_settings :notified_events => %w(crm_contact_added) do
assert contact.save
end
assert_equal 1, ActionMailer::Base.deliveries.size
end
def assert_visibility_match(user, contacts)
assert_equal contacts.collect(&:id).sort, Contact.all.select { |contact| contact.visible?(user) }.collect(&:id).sort
end
def test_that_contact_with_email_containing_plus_is_valid
contact = Contact.find(1)
contact.email = 'foo+bar-baz@email.example'
assert contact.valid?
end
def test_if_email_with_local_domain_is_allowed
contact = Contact.find(1)
contact.email = 'email@mydomain'
assert contact.valid?
end
def test_special_characters_in_email_local_part
contact = Contact.find(1)
contact.email = "#!$%&'{}@email.example"
assert contact.valid?
end
def test_email_containing_unicode_characters
contact = Contact.find(1)
contact.email = 'денис@пример.рф'
assert contact.valid?
end
def test_that_email_can_include_ip_address
contact = Contact.find(1)
contact.email = 'foo@[IPv6:2001:db8::1]'
assert contact.valid?
end
def test_contact_with_multiple_email_addresses
contact = Contact.find(1)
contact.email = 'foo@email.example,bar@email.example'
assert contact.valid?
end
def test_if_email_without_at_sign_is_invalid
contact = Contact.find(1)
contact.email = 'hello'
assert contact.invalid?
end
def test_email_transformation_on_create
assert_equal 'test@test.com', Contact.create!(:project => Project.find(1), :first_name => 'Test', :email => ' test@test.com ').email
assert_equal 'test@test.com,foo@bar.com', Contact.create!(:project => Project.find(1), :first_name => 'Test', :email => ' test@test.com , foo@bar.com ').email
end
def test_duplicates_no_middle_name
project = Project.find(1)
User.current = User.find(1)
contact1 = Contact.create!(:project => project, :first_name => 'Kristiyan', :middle_name => 'Stoyanov')
contact2 = Contact.create!(:project => project, :first_name => 'Kristiyan', :middle_name => '')
assert contact2.duplicates.include?(contact1)
assert contact1.duplicates.include?(contact2)
end
def test_duplicates_by_just_email
project = Project.find(1)
User.current = User.find(1)
contact1 = Contact.create!(:project => project, :first_name => 'Kristiyan', :email => 'test@test.com')
contact2 = Contact.create!(:project => project, :first_name => 'Peter', :email => 'test@test.com')
assert contact2.duplicates.include?(contact1)
assert contact1.duplicates.include?(contact2)
end
def test_duplicates_no_middle_name_with_last_name
project = Project.find(1)
User.current = User.find(1)
contact1 = Contact.create!(:project => project, :first_name => 'Kristiyan', :middle_name => '', :last_name => 'Stoyanov')
contact2 = Contact.create!(:project => project, :first_name => 'Kristiyan', :middle_name => 'Petrov', :last_name => 'Stoyanov')
assert contact1.duplicates.include?(contact2)
assert contact2.duplicates.include?(contact1)
end
def test_duplicates_no_middle_name_with_last_name_and_email
project = Project.find(1)
User.current = User.find(1)
contact1 = Contact.create!(:project => project, :first_name => 'Kristiyan', :last_name => 'Stoyanov', :email => 'test@test.com')
contact2 = Contact.create!(:project => project, :first_name => 'Kristiyan', :middle_name => 'Petrov', :last_name => 'Stoyanov', :email => 'test@test.com')
assert contact1.duplicates.include?(contact2)
assert contact2.duplicates.include?(contact1)
end
def test_multiple_duplicates_different_criteria
project = Project.find(1)
User.current = User.find(1)
contact1 = Contact.create!(:project => project, :first_name => 'Kristiyan', :middle_name => '', :email => 'test@test.com')
contact2 = Contact.create!(:project => project, :first_name => 'Kristiyan', :middle_name => '', :last_name => 'Stoyanov', :email => 'test@test.com')
contact3 = Contact.create!(:project => project, :first_name => 'Kristiyan', :middle_name => 'Petrov', :last_name => 'Stoyanov')
contact4 = Contact.create!(:project => project, :first_name => 'Mr.Nobody', :middle_name => '', :last_name => 'Test', :email => 'test@test.com')
assert contact1.duplicates.include?(contact2)
assert contact1.duplicates.include?(contact3)
assert contact1.duplicates.include?(contact4)
end
end
@@ -0,0 +1,31 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../test_helper', __FILE__)
class ContactsIssuesTest < ActiveSupport::TestCase
fixtures :contacts_issues
# Replace this with your real tests.
def test_truth
assert true
end
end
@@ -0,0 +1,151 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../test_helper', __FILE__)
class ContactsMailerTest < ActiveSupport::TestCase
fixtures :projects,
:users,
:roles,
:members,
:member_roles,
:issues,
:issue_statuses,
:versions,
:trackers,
:projects_trackers,
:issue_categories,
:enabled_modules,
:enumerations,
:attachments,
:workflows,
:custom_fields,
:custom_values,
:custom_fields_projects,
:custom_fields_trackers,
:time_entries,
:journals,
:journal_details,
:queries
fixtures :email_addresses if ActiveRecord::VERSION::MAJOR >= 4
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
:contacts_projects,
:contacts_issues,
:deals,
:notes,
:tags,
:taggings,
:queries])
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/contacts_mailer'
def setup
RedmineContacts::TestCase.prepare
ActionMailer::Base.deliveries.clear
Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
end
test 'Should add contact note from to' do
# This email contains: 'Project: onlinestore'
note = submit_email('new_note.eml').first
assert_instance_of ContactNote, note
assert !note.new_record?
note.reload
assert_equal Contact, note.source.class
assert_equal 'New note from email', note.subject
assert_equal User.find_by_login('admin'), note.author
assert_equal Contact.find(1).id, note.source_id
end
test 'Should add contact note from ID in to' do
# This email contains: 'Project: onlinestore'
note = submit_email('new_note_by_id.eml').first
assert_instance_of ContactNote, note
assert !note.new_record?
note.reload
assert_equal Contact, note.source.class
assert_equal 'New note from email', note.subject
assert_equal User.find_by_login('admin'), note.author
assert_equal Contact.find(1).id, note.source_id
end
test 'Should add contact note from ID in cc' do
# This email contains: 'Project: onlinestore'
note = submit_email('new_note_with_cc.eml').first
assert_instance_of ContactNote, note
assert !note.new_record?
note.reload
assert_equal Contact, note.source.class
assert_equal 'New note from email by id in cc', note.subject
assert_equal User.find_by_login('admin'), note.author
assert_equal Contact.find(1).id, note.source_id
end
test 'Should add deal note from ID in to' do
# This email contains: 'Project: onlinestore'
note = submit_email('new_deal_note_by_id.eml').first
assert_instance_of DealNote, note
assert !note.new_record?
note.reload
assert_equal Deal, note.source.class
assert_equal 'New note from email', note.subject
assert_equal User.find_by_login('admin'), note.author
assert_equal Deal.find(1).id, note.source_id
end
test 'Should add contact note from forwarded' do
note = submit_email('fwd_new_note_plain.eml').first
assert_instance_of ContactNote, note
assert !note.new_record?
note.reload
assert_equal Contact, note.source.class
assert_equal 'New note from forwarded email', note.subject
assert_match 'From: "Marat Aminov" marat@mail.ru', note.content
assert_equal User.find_by_login('admin'), note.author
assert_equal Contact.find(2).id, note.source_id
end
test 'Should add contact note from forwarded html' do
note = submit_email('fwd_new_note_html.eml').first
assert_instance_of ContactNote, note
assert !note.new_record?
note.reload
assert_equal Contact, note.source.class
assert_equal 'New note from forwarded html email', note.subject
assert_match 'From: Marat Aminov <marat@mail.com>', note.content
assert_equal User.find_by_login('admin'), note.author
assert_equal Contact.find(2).id, note.source_id
end
test 'Should not add contact note from deny user to' do
assert !submit_email('new_deny_note.eml')
end
private
def submit_email(filename, options = {})
raw = IO.read(File.join(FIXTURES_PATH, filename))
ContactsMailer.receive(raw, options)
end
end
@@ -0,0 +1,78 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../test_helper', __FILE__)
include RedmineContacts::TestHelper
if Redmine::VERSION.to_s > '2.5'
class CustomFieldCompanyFormatTest < ActiveSupport::TestCase
fixtures :custom_fields, :projects, :members, :users, :member_roles, :trackers, :issues
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
:contacts_projects,
:contacts_issues,
:deals,
:notes,
:tags,
:taggings,
:queries])
def setup
RedmineContacts::TestCase.prepare
@field = IssueCustomField.create!(:name => 'Tester', :field_format => 'company')
@controller = DealStatusesController.new
Role.anonymous.remove_permission!(:view_contacts)
User.current = nil
end
def test_possible_values_options_with_no_arguments
with_contacts_settings('cross_project_contacts' => 0) do
User.current = nil
assert_equal [], @field.possible_values_options
assert_equal [], @field.possible_values_options(nil)
end
end
def test_possible_values_options_with_project_resource
with_contacts_settings('cross_project_contacts' => 1) do
User.current = User.find(1)
project = Project.find(1)
possible_values_options = @field.possible_values_options(project.issues.first)
assert possible_values_options.empty?
end
end
def test_cast_blank_value
assert_nil @field.cast_value(nil)
assert_nil @field.cast_value('')
end
def test_cast_valid_value
contact = @field.cast_value('2')
assert_kind_of Contact, contact
assert_equal Contact.find(2), contact
end
def test_cast_invalid_value
assert_nil @field.cast_value('187')
end
end
end
@@ -0,0 +1,53 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../test_helper', __FILE__)
class DealImportTest < ActiveSupport::TestCase
fixtures :projects, :users
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
:contacts_projects,
:deals,
:deal_statuses,
:deal_categories])
def fixture_files_path
"#{File.expand_path('../..', __FILE__)}/fixtures/files/"
end
def test_open_correct_csv
deal_import = DealImport.new(
:file => Rack::Test::UploadedFile.new(fixture_files_path + 'deals_correct.csv', 'text/comma-separated-values'),
:project => Project.first,
:quotes_type => '"'
)
assert_difference('Deal.count', 1, 'Should have 1 deal in the database') do
assert_equal 1, deal_import.imported_instances.count, 'Should find 1 deal in file'
assert deal_import.save, 'Should save successfully'
end
deal = Deal.last
assert_equal 2, deal.status_id, "Status doesn't mach"
assert_equal 1, deal.category_id, 'Category should be Design'
assert_equal 'rhill', deal.assigned_to.login, 'Assignee should be rhill'
end
end
@@ -0,0 +1,77 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../test_helper', __FILE__)
class ContactTest < ActiveSupport::TestCase
fixtures :projects,
:users,
:roles,
:members,
:member_roles,
:issues,
:issue_statuses,
:versions,
:trackers,
:projects_trackers,
:issue_categories,
:enabled_modules,
:enumerations,
:attachments,
:workflows,
:custom_fields,
:custom_values,
:custom_fields_projects,
:custom_fields_trackers,
:time_entries,
:journals,
:journal_details,
:queries
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
:contacts_projects,
:contacts_issues,
:deals,
:deal_statuses,
:notes,
:tags,
:taggings,
:queries])
# Replace this with your real tests.
def test_destroy
new_status = DealStatus.create(:name => 'New status', :is_default => false, :status_type => DealStatus::OPEN_STATUS)
assert_difference 'DealStatus.count', -1 do
assert new_status.destroy
end
end
def test_destroy_status_in_use
status = Deal.find(1).status
assert_no_difference 'DealStatus.count' do
assert_raise(RuntimeError, "Can't delete status") do
status.destroy
end
end
end
end
@@ -0,0 +1,56 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../test_helper', __FILE__)
class DealTest < ActiveSupport::TestCase
fixtures :projects, :users
RedmineContacts::TestCase.create_fixtures(
Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts, :contacts_projects,
:deals, :deal_statuses]
)
def test_price_to_s_with_custome_settings
Setting.plugin_redmine_contacts['decimal_separator'] = '.'
Setting.plugin_redmine_contacts['thousands_delimiter'] = ' '
assert_equal '$3 000.00', Deal.find(1).price_to_s
end
def test_count_for_status_scope
project = Project.find(2)
assert_equal 1, project.deals.with_status(1).count
assert_equal 2, project.deals.with_status(2).count
assert_equal 1, project.deals.with_status(3).count
end
def test_price_with_big_value
Setting.plugin_redmine_contacts['decimal_separator'] = '.'
Setting.plugin_redmine_contacts['thousands_delimiter'] = ' '
deal = Deal.find(5)
price = deal.price
deal.update_attributes(:price => 9999999999999)
assert_equal '9 999 999 999 999.00 RUB', Deal.find(5).price_to_s
ensure
deal.update_attributes(:price => price)
end
end
@@ -0,0 +1,96 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../test_helper', __FILE__)
class DealsPipelineProcessorTest < ActiveSupport::TestCase
fixtures :projects, :users
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
:contacts_projects,
:deals,
:deal_statuses,
:deal_categories])
def setup
Deal.destroy_all
@deal_status_new = DealStatus.find(1)
@deal_status_won = DealStatus.find(2)
@deal_status_lost = DealStatus.find(3)
@deal_status_intermediate1 = DealStatus.find(4)
@deal_status_intermediate2 = DealStatus.find(5)
end
def test_constructor
assert_not_nil DealsPipelineProcessor.new(Deal)
end
def test_closed_deal_counts_in_last_unclosed_status
@deal = Deal.create!(:status => @deal_status_new, :name => 'New deal', :project => Project.last)
@deal.init_deal_process(User.first)
@deal.update_attribute(:status, @deal_status_won)
assert_equal(1, DealProcess.count)
processor = DealsPipelineProcessor.new(Deal)
assert_equal(1, processor.deals_for_status(@deal_status_new).count)
end
def test_open_deal_counts_in_last_unclosed_status
@deal = Deal.create!(:status => @deal_status_new, :name => 'New deal', :project => Project.last)
@deal.init_deal_process(User.first)
@deal.update_attribute(:status, @deal_status_intermediate1)
assert_equal(1, DealProcess.count)
processor = DealsPipelineProcessor.new(Deal)
assert_equal(1, processor.deals_for_status(@deal_status_new).count)
end
def test_if_asked_in_status_returns_simple_case
@deal = Deal.create!(:status => @deal_status_new, :name => 'New deal', :project => Project.last)
@deal.init_deal_process(User.first)
@deal.update_attribute(:status, @deal_status_won)
@deal = Deal.create!(:status => @deal_status_new, :name => 'New deal 2', :project => Project.last)
@deal.init_deal_process(User.first)
@deal.update_attribute(:status, @deal_status_intermediate1)
assert_equal(2, DealProcess.count)
processor = DealsPipelineProcessor.new(Deal)
assert_equal(1, processor.deals_for_status(@deal_status_won).count)
end
def test_if_deal_jumped_over_status
@deal = Deal.create!(:status => @deal_status_new, :name => 'New deal', :project => Project.last)
@deal.init_deal_process(User.first)
@deal.update_attribute(:status, @deal_status_intermediate2)
processor = DealsPipelineProcessor.new(Deal)
assert_equal(1, processor.deals_for_status(@deal_status_intermediate1).count)
end
def test_if_deal_returned_from_lost
@deal = Deal.create!(:status => @deal_status_new, :name => 'New deal', :project => Project.last)
@deal.init_deal_process(User.first)
@deal.update_attribute(:status, @deal_status_lost)
@deal.update_attribute(:status, @deal_status_intermediate2)
processor = DealsPipelineProcessor.new(Deal)
assert_equal(1, processor.deals_for_status(@deal_status_intermediate1).count)
end
end
@@ -0,0 +1,87 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../../test_helper', __FILE__)
class ContactsHelperTest < ActionView::TestCase
include ApplicationHelper
include ContactsHelper
include CustomFieldsHelper
include Redmine::I18n
include ERB::Util
fixtures :projects, :trackers, :issue_statuses, :issues,
:enumerations, :users, :issue_categories,
:versions,
:projects_trackers,
:member_roles,
:members,
:groups_users,
:enabled_modules
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
:contacts_projects,
:contacts_issues,
:deals,
:notes,
:tags,
:taggings,
:queries])
def setup
super
set_language_if_valid('en')
User.current = nil
end
def test_contacts_to_xls
User.current = User.find(1)
xls_result = contacts_to_xls(Contact.all)
assert_match /First Name/, xls_result
assert_match /Domoway/, xls_result
end
def test_contacts_to_xls_with_multivalue_custom_field
User.current = User.find(1)
field = ContactCustomField.create!(:name => 'filter', :field_format => 'list',
:is_filter => true, :is_for_all => true,
:possible_values => ['value1', 'value2', 'value3'],
:multiple => true)
contact = Contact.find(1)
contact.custom_field_values = { field.id => ['value1', 'value2', 'value3'] }
contact.save!
xls_result = contacts_to_xls([contact])
assert_match /First Name/, xls_result
assert_match /Domoway/, xls_result
assert_match /value1, value2, value3/, xls_result
end
def test_mail_macro
field = ContactCustomField.create!(:name => 'Custom field', :field_format => 'string')
contact = Contact.find(1)
contact.custom_field_values = {field.id => 'test value'}
contact.save!
message = "Hello %%NAME%%, %%FULL_NAME%% %%COMPANY%% %%LAST_NAME%% %%MIDDLE_NAME%% %%DATE%% %%Custom field%%"
result_msg = mail_macro(contact, message)
assert_equal "Hello Ivan, Ivan Ivanov Domoway Ivanov Ivanovich #{format_date(Date.today)} test value", result_msg
end
end
@@ -0,0 +1,76 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../../test_helper', __FILE__)
class DealsHelperTest < ActionView::TestCase
include ApplicationHelper
include DealsHelper
include CustomFieldsHelper
include Redmine::I18n
include ERB::Util
fixtures :projects, :trackers, :issue_statuses, :issues,
:enumerations, :users, :issue_categories,
:versions,
:projects_trackers,
:member_roles,
:members,
:groups_users,
:enabled_modules
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
:contacts_projects,
:contacts_issues,
:deals,
:notes,
:tags,
:taggings,
:queries])
def setup
super
set_language_if_valid('en')
User.current = nil
end
def test_deals_to_csv
User.current = User.find(1)
csv_result = deals_to_csv(Deal.all)
assert_match /Name/, csv_result
assert_match /First deal with contacts/, csv_result
end
def test_deals_to_csv_with_multivalue_custom_field
User.current = User.find(1)
field = DealCustomField.create!(:name => 'filter', :field_format => 'list',
:is_filter => true, :is_for_all => true,
:possible_values => ['value1', 'value2', 'value3'],
:multiple => true)
deal = Deal.find(1)
deal.custom_field_values = { field.id => ['value1', 'value2', 'value3'] }
deal.save!
csv_result = deals_to_csv([deal])
assert_match /Name/, csv_result
assert_match /First deal with contacts/, csv_result
assert_match /value1, value2, value3/, csv_result
end
end
@@ -0,0 +1,78 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../../test_helper', __FILE__)
class NotesHelperTest < ActionView::TestCase
include ApplicationHelper
include NotesHelper
include Redmine::I18n
include ERB::Util
fixtures :projects, :trackers, :issue_statuses, :issues,
:enumerations, :users, :issue_categories,
:versions,
:projects_trackers,
:member_roles,
:members,
:groups_users,
:enabled_modules
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
:contacts_projects,
:contacts_issues,
:deals,
:notes,
:tags,
:taggings,
:queries])
def setup
super
set_language_if_valid('en')
User.current = nil
end
def test_authoring_note_without_time
RedmineContacts.settings[:note_authoring_time] = false
assert_nothing_raised { authoring_note('2012-12-12 10:00'.to_time, User.find(1)) }
end
def test_authoring_note_with_time
RedmineContacts.settings[:note_authoring_time] = true
assert_nothing_raised { authoring_note('2012-12-12 10:00'.to_time, User.find(1)) }
end
def test_authoring_note_without_time_with_empty_time
RedmineContacts.settings[:note_authoring_time] = true
assert_nothing_raised { authoring_note(nil, User.find(1)) }
end
def test_authoring_note_without_time_with_empty_time
RedmineContacts.settings[:note_authoring_time] = false
assert_nothing_raised { authoring_note(nil, User.find(1)) }
end
def test_authoring_note_without_time_with_empty_user
RedmineContacts.settings[:note_authoring_time] = true
assert_nothing_raised { authoring_note('2012-12-12 10:00'.to_time, nil) }
end
end
@@ -0,0 +1,82 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
# encoding: utf-8
require File.expand_path('../../../test_helper', __FILE__)
class ContactsProjectSettingTest < ActiveSupport::TestCase
fixtures :projects,
:users,
:roles,
:members,
:member_roles,
:issues,
:issue_statuses,
:versions,
:trackers,
:projects_trackers,
:issue_categories,
:enabled_modules,
:enumerations,
:attachments,
:workflows,
:custom_fields,
:custom_values,
:custom_fields_projects,
:custom_fields_trackers,
:time_entries,
:journals,
:journal_details,
:queries
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
:contacts_projects,
:contacts_issues,
:contacts_settings,
:deals,
:notes,
:tags,
:taggings,
:queries])
def setup
Setting.plugin_redmine_contacts['post_address_format'] = nil
@project_settings = ContactsProjectSetting.new(Project.find(1), 'redmine_contacts')
end
def test_read_values
assert_equal 'String value', @project_settings.string_setting
assert_equal true, @project_settings.boolean_setting?
end
def test_read_global_values
Setting['plugin_redmine_contacts']['global_value'] = 'Global'
assert_equal 'Global', @project_settings.global_value
end
def test_read_default_values
assert_equal ['USD', 'EUR', 'GBP', 'RUB', 'CHF'].sort, @project_settings.major_currencies.sort
end
def test_read_default_values_post_address_format
assert_equal "%street1%\n%street2%\n%city%, %postcode%\n%region%\n%country%", @project_settings.post_address_format
end
end
@@ -0,0 +1,124 @@
# encoding: utf-8
#
# This file is a part of Redmine CRM (redmine_contacts) plugin,
# customer relationship management plugin for Redmine
#
# Copyright (C) 2010-2018 RedmineUP
# http://www.redmineup.com/
#
# redmine_contacts 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 3 of the License, or
# (at your option) any later version.
#
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path('../../test_helper', __FILE__)
class MailerPatchTest < ActiveSupport::TestCase
fixtures :projects,
:users,
:roles,
:members,
:member_roles,
:issues,
:issue_statuses,
:versions,
:trackers,
:projects_trackers,
:issue_categories,
:enabled_modules,
:enumerations,
:attachments,
:workflows,
:custom_fields,
:custom_values,
:custom_fields_projects,
:custom_fields_trackers,
:time_entries,
:journals,
:journal_details,
:queries
fixtures :email_addresses if ActiveRecord::VERSION::MAJOR >= 4
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
:contacts_projects,
:contacts_issues,
:deal_processes,
:deals,
:notes,
:tags,
:taggings,
:queries])
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/contacts_mailer'
def setup
RedmineContacts::TestCase.prepare
Setting.host_name = 'mydomain.foo'
Setting.protocol = 'http'
Setting.plain_text_mail = '0'
ActionMailer::Base.deliveries.clear
Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
end
def test_crm_note_add
note = Note.find(1)
assert Mailer.crm_note_add(note).deliver
assert_match 'Note 1', last_email.text_part.to_s
end
def test_crm_note_add_to_company
note = Note.find(4)
assert Mailer.crm_note_add(note).deliver
assert_match 'Note 4', last_email.text_part.to_s
end
def test_crm_contact_add
contact = Contact.find(1)
assert Mailer.crm_contact_add(contact).deliver
assert_match 'Contact #1: Ivan Ivanov', last_email.text_part.to_s
end
def test_crm_note_add_to_deal
note = Note.find(5)
assert Mailer.crm_note_add(note).deliver
assert_match 'Note 5', last_email.text_part.to_s
end
def test_crm_deal_add
deal = Deal.find(1)
assert Mailer.crm_deal_add(deal).deliver
assert_match 'Deal #1', last_email.text_part.to_s
end
def test_crm_deal_updated
deal_process = DealProcess.last
deal_process.author = User.find(2)
deal_process.save
assert Mailer.crm_deal_updated(deal_process).deliver
assert_match 'John Smith', last_email.text_part.to_s
end
private
def last_email
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
mail
end
def text_part
last_email.parts.detect { |part| part.content_type.include?('text/plain') }
end
def html_part
last_email.parts.detect { |part| part.content_type.include?('text/html') }
end
end