Initial Redmine tooling and local plugin forks
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
# 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 AutoCompletesControllerTest < ActionController::TestCase
|
||||
fixtures :projects, :issues, :issue_statuses,
|
||||
:enumerations, :users, :issue_categories,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:roles,
|
||||
:member_roles,
|
||||
:members,
|
||||
:enabled_modules,
|
||||
:workflows,
|
||||
:journals, :journal_details
|
||||
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
|
||||
@request.session[:user_id] = 1
|
||||
end
|
||||
|
||||
def test_contacts_should_not_be_case_sensitive
|
||||
compatible_request :get, :contacts, :project_id => 'ecookbook', :q => 'ma'
|
||||
assert_response :success
|
||||
assert response.body.match /Marat/
|
||||
end
|
||||
|
||||
def test_contacts_should_accept_term_param
|
||||
compatible_request :get, :contacts, :project_id => 'ecookbook', :term => 'ma'
|
||||
assert_response :success
|
||||
assert response.body.match /Marat/
|
||||
end
|
||||
|
||||
def test_companies_should_not_be_case_sensitive
|
||||
compatible_request :get, :companies, :project_id => 'ecookbook', :q => 'domo'
|
||||
assert_response :success
|
||||
assert response.body.match /Domoway/
|
||||
end
|
||||
|
||||
def test_companies_witth_spaces_should_be_found
|
||||
compatible_request :get, :companies, :project_id => 'ecookbook', :q => 'my c'
|
||||
assert_response :success
|
||||
assert response.body.match /My company/
|
||||
end
|
||||
|
||||
def test_contacts_should_return_json
|
||||
compatible_request :get, :contacts, :project_id => 'ecookbook', :q => 'marat'
|
||||
assert_response :success
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_kind_of Array, json
|
||||
contact = json.last
|
||||
assert_kind_of Hash, contact
|
||||
assert_equal 2, contact['id']
|
||||
assert_equal 2, contact['value']
|
||||
assert_equal 'Marat Aminov', contact['name']
|
||||
end
|
||||
|
||||
def test_companies_should_return_json
|
||||
compatible_request :get, :companies, :project_id => 'ecookbook', :q => 'domo'
|
||||
assert_response :success
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_kind_of Array, json
|
||||
contact = json.first
|
||||
assert_kind_of Hash, contact
|
||||
assert_equal 3, contact['id']
|
||||
assert_equal 'Domoway', contact['value']
|
||||
assert_equal 'Domoway', contact['label']
|
||||
end
|
||||
|
||||
def test_contact_tags_should_return_json
|
||||
compatible_request :get, :contact_tags, :q => 'ma'
|
||||
assert_response :success
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_kind_of Array, json
|
||||
tag = json.last
|
||||
assert_match 'main', tag
|
||||
end
|
||||
|
||||
def test_taggable_tags_should_return_json
|
||||
compatible_request :get, :taggable_tags, :q => 'ma', :taggable_type => 'contact'
|
||||
assert_response :success
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_kind_of Array, json
|
||||
tag = json.last
|
||||
assert_match 'main', tag
|
||||
end
|
||||
def test_deals_should_return_json
|
||||
compatible_request :get, :deals, :q => 'redmine'
|
||||
assert_response :success
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_kind_of Array, json
|
||||
deal = json.last
|
||||
assert_kind_of Hash, deal
|
||||
assert_equal 3, deal['id']
|
||||
assert_equal 3, deal['value']
|
||||
assert_match 'Delevelop redmine plugin', deal['label']
|
||||
end
|
||||
|
||||
def test_deals_should_fiend_by_contact_details
|
||||
check_by_contact_details('', 5, 2, 'Second deal with contacts') # Search string is empty
|
||||
check_by_contact_details('Ivanov', 1, 1, 'First deal with contacts') # Contact last name is Ivanov
|
||||
check_by_contact_details('jsmith@somenet.foo', 0) # Contact email is jsmith@somenet.foo
|
||||
check_by_contact_details('Domoway', 4, 2) # Contact first name is Domoway
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_by_contact_details(search_string, expected_number, deal_id = 0, deal_label = '')
|
||||
compatible_request :get, :deals, :q => search_string
|
||||
assert_response :success
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_equal expected_number, json.length
|
||||
|
||||
return if expected_number == 0
|
||||
deal = json.last
|
||||
%w(id value).each { |field| assert_equal deal_id, deal[field] }
|
||||
%w(label text).each { |field| assert_match deal_label, deal[field] }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,158 @@
|
||||
# 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 ContactImportsControllerTest < ActionController::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,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
User.current = nil
|
||||
@csv_file = Rack::Test::UploadedFile.new(redmine_contacts_fixture_files_path + 'contacts_cf.csv', 'text/csv')
|
||||
end
|
||||
|
||||
test 'should open contact import form' do
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :new, :project_id => 1
|
||||
assert_response :success
|
||||
if Redmine::VERSION.to_s >= '3.2'
|
||||
assert_select 'form input#file'
|
||||
else
|
||||
assert_select 'form.new_contact_import'
|
||||
end
|
||||
end
|
||||
|
||||
test 'should create new import object' do
|
||||
if Redmine::VERSION.to_s >= '3.2'
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :create, :project_id => 1, :file => @csv_file
|
||||
assert_response :redirect
|
||||
assert_equal Import.last.class, ContactKernelImport
|
||||
assert_equal Import.last.user, User.find(1)
|
||||
assert_equal Import.last.project, 1
|
||||
assert_equal Import.last.settings, { 'project' => 1,
|
||||
'separator' => Rails.version >= '5.1' ? ';' : ',',
|
||||
'wrapper' => "\"",
|
||||
'encoding' => 'ISO-8859-1',
|
||||
'date_format' => '%m/%d/%Y' }
|
||||
end
|
||||
end
|
||||
|
||||
test 'should open settings page' do
|
||||
if Redmine::VERSION.to_s >= '3.2'
|
||||
@request.session[:user_id] = 1
|
||||
import = ContactKernelImport.new
|
||||
import.user = User.find(1)
|
||||
import.project = Project.find(1)
|
||||
import.file = @csv_file
|
||||
import.save!
|
||||
compatible_request :get, :settings, :id => import.filename, :project_id => 1
|
||||
assert_response :success
|
||||
assert_select 'form#import-form'
|
||||
end
|
||||
end
|
||||
|
||||
test 'should show mapping page' do
|
||||
if Redmine::VERSION.to_s >= '3.2'
|
||||
@request.session[:user_id] = 1
|
||||
import = ContactKernelImport.new
|
||||
import.user = User.find(1)
|
||||
import.project = Project.find(1)
|
||||
import.file = @csv_file
|
||||
import.save!
|
||||
compatible_request :get, :mapping, :id => import.filename, :project_id => 1
|
||||
assert_response :success
|
||||
assert_select "select[name='import_settings[mapping][is_company]']"
|
||||
assert_select 'select[name="import_settings[mapping][first_name]"]'
|
||||
assert_select 'table.sample-data tr'
|
||||
assert_select 'table.sample-data tr td', 'Monica'
|
||||
assert_select 'table.sample-data tr td', 'ivan@mail.com'
|
||||
end
|
||||
end
|
||||
|
||||
test 'should successfully import from CSV with new import' do
|
||||
if Redmine::VERSION.to_s >= '3.2'
|
||||
cf = ContactCustomField.create!(:name => 'LIST_FIELD', :field_format => 'list', :multiple => true, :possible_values => %w(1 2 3))
|
||||
@request.session[:user_id] = 1
|
||||
import = ContactKernelImport.new
|
||||
import.user = User.find(1)
|
||||
import.project = Project.find(1)
|
||||
import.file = @csv_file
|
||||
import.save!
|
||||
compatible_request :post, :mapping, :id => import.filename, :project_id => 1,
|
||||
:import_settings => { :mapping => { :first_name => 2, :email => 8, "cf_#{cf.id}" => 21 } }
|
||||
assert_response :redirect
|
||||
compatible_request :post, :run, :id => import.filename, :project_id => 1, :format => :js
|
||||
assert_equal Contact.last.first_name, 'Monica'
|
||||
assert_equal Contact.last.email, 'ivan@mail.com'
|
||||
assert_equal Contact.last.custom_field_value(cf).sort, ['1', '3']
|
||||
end
|
||||
end
|
||||
|
||||
test 'should successfully import from CSV' do
|
||||
if Redmine::VERSION.to_s < '3.2'
|
||||
@request.session[:user_id] = 1
|
||||
assert_difference('Contact.count', 4, 'Should add 4 contacts to the database') do
|
||||
compatible_request :post, :create, {
|
||||
:project_id => 1,
|
||||
:contact_import => {
|
||||
:file => Rack::Test::UploadedFile.new(redmine_contacts_fixture_files_path + 'correct.csv', 'text/comma-separated-values'),
|
||||
:quotes_type => '"'
|
||||
}
|
||||
}
|
||||
assert_redirected_to project_contacts_path(:project_id => 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,753 @@
|
||||
# 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 ContactsControllerTest < ActionController::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,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries,
|
||||
:addresses])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_get_index
|
||||
@request.session[:user_id] = 1
|
||||
assert_not_nil Contact.find(1)
|
||||
compatible_request :get, :index
|
||||
assert_response :success
|
||||
assert_not_nil contacts_in_list
|
||||
assert_select 'a', :html => /Domoway/
|
||||
assert_select 'a', :html => /Marat/
|
||||
assert_select 'h3', :html => /Tags/
|
||||
assert_select 'h3', :html => /Recently viewed/
|
||||
assert_select 'div#tags span#single_tags span.tag-label-color a', 'test'
|
||||
assert_select 'div#tags span#single_tags span.tag-label-color a', 'main'
|
||||
end
|
||||
|
||||
test 'should get index in project' do
|
||||
@request.session[:user_id] = 1
|
||||
Setting.default_language = 'en'
|
||||
|
||||
compatible_request :get, :index, :project_id => 1
|
||||
assert_response :success
|
||||
assert_not_nil contacts_in_list
|
||||
assert_select 'a', :html => /Domoway/
|
||||
assert_select 'a', :html => /Marat/
|
||||
assert_select 'h3', :html => /Tags/
|
||||
assert_select 'h3', :html => /Recently viewed/
|
||||
end
|
||||
test 'should get index with filters and sorting' do
|
||||
field = ContactCustomField.create!(:name => 'Test custom field', :is_filter => true, :field_format => 'string')
|
||||
contact = Contact.find(1)
|
||||
contact.custom_field_values = { field.id => "This is custom значение" }
|
||||
contact.save
|
||||
|
||||
@request.session[:user_id] = 1
|
||||
Setting.default_language = 'en'
|
||||
|
||||
compatible_request :get, :index, :sort => 'assigned_to,cf_1,last_name,first_name',
|
||||
:v => { 'first_name' => ['Ivan'] },
|
||||
:f => ['first_name', ''],
|
||||
:op => { 'first_name' => '~' }
|
||||
assert_response :success
|
||||
assert_not_nil contacts_in_list
|
||||
|
||||
assert_select 'div#content div#contact_list table.contacts td.name h1', 'Ivan Ivanov'
|
||||
end
|
||||
|
||||
def test_get_index_with_all_fields
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get,
|
||||
:index,
|
||||
:set_filter => 1,
|
||||
:project_id => 1,
|
||||
:c => ContactQuery.available_columns.map(&:name),
|
||||
:contacts_list_style => 'list'
|
||||
assert_response :success
|
||||
assert_select 'tr#contact-1 td.id a[href=?]', '/contacts/1'
|
||||
assert_select 'tr#contact-1 td.tags', 'main'
|
||||
end
|
||||
|
||||
def test_index_with_short_filters
|
||||
@request.session[:user_id] = 1
|
||||
to_test = {
|
||||
'tags' => {
|
||||
'main|test' => { :op => '=', :values => ['main', 'test'] },
|
||||
'=main' => { :op => '=', :values => ['main'] },
|
||||
'!test' => { :op => '!', :values => ['test'] } },
|
||||
'country' => {
|
||||
'*' => { :op => '*', :values => [''] },
|
||||
'!*' => { :op => '!*', :values => [''] },
|
||||
'US|RU' => { :op => '=', :values => ['US', 'RU'] } },
|
||||
'first_name' => {
|
||||
'Marat' => { :op => '=', :values => ['Marat'] },
|
||||
'~Mara' => { :op => '~', :values => ['Mara'] },
|
||||
'!~Mara' => { :op => '!~', :values => ['Mara'] } },
|
||||
'created_on' => {
|
||||
'>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
|
||||
'<t-2' => { :op => '<t-', :values => ['2'] },
|
||||
'>t-2' => { :op => '>t-', :values => ['2'] },
|
||||
't-2' => { :op => 't-', :values => ['2'] } },
|
||||
'last_note' => {
|
||||
'>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
|
||||
'<t-2' => { :op => '<t-', :values => ['2'] },
|
||||
'>t-2' => { :op => '>t-', :values => ['2'] },
|
||||
't-2' => { :op => 't-', :values => ['2'] } },
|
||||
'has_deals' => {
|
||||
'c' => { :op => '=', :values => ['c'] },
|
||||
'!c' => { :op => '!', :values => ['c'] } },
|
||||
'has_open_issues' => {
|
||||
'=4' => { :op => '=', :values => ['4'] },
|
||||
'!*' => { :op => '!*', :values => [''] },
|
||||
'*' => { :op => '*', :values => [''] } }
|
||||
}
|
||||
|
||||
default_filter = { 'status_id' => { :operator => 'o', :values => [''] } }
|
||||
|
||||
to_test.each do |field, expression_and_expected|
|
||||
expression_and_expected.each do |filter_expression, expected|
|
||||
compatible_request :get, :index, :set_filter => 1, field => filter_expression
|
||||
|
||||
assert_response :success
|
||||
assert_not_nil contacts_in_list
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_filter_by_ids_equal
|
||||
@request.session[:user_id] = 1
|
||||
ids = [1, 2]
|
||||
compatible_request :get, :index, :project_id => 1, :set_filter => 1, 'f' => ['ids', ''], 'op' => { 'ids' => '=' }, 'v' => { 'ids' => [ids.join(',')] }
|
||||
assert_response :success
|
||||
assert_equal ids.sort, contacts_in_list.map(&:id).sort
|
||||
end if Redmine::VERSION.to_s >= '3.3'
|
||||
|
||||
def test_filter_by_ids_any
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :project_id => 1, :set_filter => 1, 'f' => ['ids', ''], 'op' => { 'ids' => '*' }
|
||||
assert_response :success
|
||||
assert_equal Project.find(1).contacts.map(&:id).sort, contacts_in_list.map(&:id).sort
|
||||
end if Redmine::VERSION.to_s >= '3.3'
|
||||
|
||||
def test_filter_by_ids_more_than
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :project_id => 1, :set_filter => 1, 'f' => ['ids', ''], 'op' => { 'ids' => '>=' }, 'v' => { 'ids' => [3] }
|
||||
assert_response :success
|
||||
assert_equal [3, 4, 5], contacts_in_list.map(&:id).sort
|
||||
end if Redmine::VERSION.to_s >= '3.3'
|
||||
|
||||
def test_filter_by_ids_less_than
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :project_id => 1, :set_filter => 1, 'f' => ['ids', ''], 'op' => { 'ids' => '<=' }, 'v' => { 'ids' => [2] }
|
||||
assert_response :success
|
||||
assert_equal [1, 2], contacts_in_list.map(&:id).sort
|
||||
end if Redmine::VERSION.to_s >= '3.3'
|
||||
|
||||
def test_filter_by_ids_between
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :project_id => 1, :set_filter => 1, 'f' => ['ids', ''], 'op' => { 'ids' => '><' }, 'v' => { 'ids' => ['1', '3'] }
|
||||
assert_response :success
|
||||
assert_equal [1, 2, 3], contacts_in_list.map(&:id).sort
|
||||
end if Redmine::VERSION.to_s >= '3.3'
|
||||
|
||||
def test_index_sort_by_custom_field
|
||||
@request.session[:user_id] = 1
|
||||
cf = ContactCustomField.create!(:name => 'Contact test cf', :is_for_all => true, :field_format => 'string')
|
||||
CustomValue.create!(:custom_field => cf, :customized => Contact.find(1), :value => 'test_1')
|
||||
CustomValue.create!(:custom_field => cf, :customized => Contact.find(2), :value => 'test_2')
|
||||
CustomValue.create!(:custom_field => cf, :customized => Contact.find(3), :value => 'test_3')
|
||||
|
||||
compatible_request :get, :index, :set_filter => 1, :sort => "cf_#{cf.id},id"
|
||||
assert_response :success
|
||||
|
||||
assert_equal [1, 2, 3], contacts_in_list.select { |contact| contact.custom_field_value(cf).present? }.map(&:id).sort
|
||||
end
|
||||
|
||||
def test_should_not_absolute_links
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :get, :index
|
||||
assert_response :success
|
||||
assert_no_match %r{localhost}, @response.body
|
||||
end
|
||||
|
||||
def test_should_get_index_deny_user_in_project
|
||||
@request.session[:user_id] = 5
|
||||
|
||||
compatible_request :get, :index, :project_id => 1
|
||||
assert_response :redirect
|
||||
end
|
||||
|
||||
def test_should_get_index_with_filters
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :is_company => ActiveRecord::Base.connection.quoted_true.gsub(/'/, '')
|
||||
assert_response :success
|
||||
assert_select 'div#content div#contact_list table.contacts td.name h1 a', 'Domoway'
|
||||
end
|
||||
def test_should_get_index_as_csv
|
||||
field = ContactCustomField.create!(:name => 'Test custom field', :is_filter => true, :field_format => 'string')
|
||||
contact = Contact.find(1)
|
||||
contact.custom_field_values = { field.id => "This is custom значение" }
|
||||
contact.save
|
||||
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :format => 'csv'
|
||||
assert_response :success
|
||||
assert_not_nil contacts_in_list
|
||||
assert_equal 'text/csv; header=present', @response.content_type
|
||||
assert_match /Domoway/, @response.body
|
||||
end
|
||||
|
||||
def test_should_get_index_as_VCF
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :format => 'vcf'
|
||||
assert_response :success
|
||||
assert_not_nil contacts_in_list
|
||||
assert_equal 'text/x-vcard', @response.content_type
|
||||
assert @response.body.starts_with?('BEGIN:VCARD')
|
||||
assert_match /^N:;Domoway/, @response.body
|
||||
end
|
||||
|
||||
def test_should_get_contacts_notes_as_csv
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :contacts_notes, :format => 'csv'
|
||||
assert_response :success
|
||||
assert_equal 'text/csv; header=present', @response.content_type
|
||||
assert @response.body.starts_with?('#,')
|
||||
end
|
||||
|
||||
def test_get_show
|
||||
@request.session[:user_id] = 2
|
||||
Setting.default_language = 'en'
|
||||
|
||||
compatible_request :get, :show, :id => 3, :project_id => 1
|
||||
assert_response :success
|
||||
|
||||
assert_not_nil contacts_in_list
|
||||
assert_select 'h1', :html => /Domoway/
|
||||
assert_select 'div#tags_data span.tag-label-color a', 'main'
|
||||
assert_select 'div#tags_data span.tag-label-color a', 'test'
|
||||
assert_select 'div#tab-placeholder-contacts'
|
||||
assert_select 'div#comments div#notes table.note_data td.name h4', 4
|
||||
assert_select 'h3', 'Recently viewed'
|
||||
end
|
||||
|
||||
def test_get_show_with_long_note
|
||||
long_note = 'A' * 1500
|
||||
Contact.find(3).notes.create(:content => long_note, :author_id => 1)
|
||||
@request.session[:user_id] = 2
|
||||
Setting.default_language = 'en'
|
||||
|
||||
compatible_request :get, :show, :id => 3, :project_id => 1
|
||||
assert_response :success
|
||||
assert_select '.note a', '(read more)'
|
||||
end
|
||||
def test_get_show_tab_deals
|
||||
@request.session[:user_id] = 2
|
||||
Setting.default_language = 'en'
|
||||
|
||||
compatible_request :get, :show, :id => 3, :project_id => 1, :tab => 'deals'
|
||||
assert_response :success
|
||||
assert_not_nil contacts_in_list
|
||||
assert_select 'h1', :html => /Domoway/
|
||||
assert_select 'div#deals a', 'Delevelop redmine plugin'
|
||||
assert_select 'div#deals a', 'Second deal with contacts'
|
||||
end
|
||||
|
||||
def test_get_show_without_deals
|
||||
@request.session[:user_id] = 4
|
||||
Setting.default_language = 'en'
|
||||
|
||||
compatible_request :get, :show, :id => 3, :project_id => 1, :tab => 'deals'
|
||||
assert_response :success
|
||||
assert_not_nil contacts_in_list
|
||||
|
||||
assert_select 'div#deals a', { :count => 0, :text => /Delevelop redmine plugin/ }
|
||||
assert_select 'div#deals a', { :count => 0, :text => /Second deal with contacts/ }
|
||||
end
|
||||
|
||||
def test_get_new
|
||||
@request.session[:user_id] = 2
|
||||
compatible_request :get, :new, :project_id => 1
|
||||
assert_response :success
|
||||
assert_select 'input#contact_first_name'
|
||||
end
|
||||
|
||||
def test_get_new_without_permission
|
||||
@request.session[:user_id] = 4
|
||||
compatible_request :get, :new, :project_id => 1
|
||||
assert_response :forbidden
|
||||
end
|
||||
|
||||
def test_post_create
|
||||
@request.session[:user_id] = 1
|
||||
assert_difference 'Contact.count' do
|
||||
compatible_request :post, :create, :project_id => 1, :contact => { :company => 'OOO "GKR"',
|
||||
:is_company => 0,
|
||||
:job_title => 'CFO',
|
||||
:assigned_to_id => 3,
|
||||
:tag_list => 'test,new',
|
||||
:last_name => 'New',
|
||||
:middle_name => 'Ivanovich',
|
||||
:first_name => 'Created' }
|
||||
end
|
||||
|
||||
assert_redirected_to :controller => 'contacts', :action => 'show', :id => Contact.last.id, :project_id => Contact.last.project
|
||||
|
||||
contact = Contact.where(:first_name => 'Created', :last_name => 'New', :middle_name => 'Ivanovich').first
|
||||
assert_not_nil contact
|
||||
assert_equal 'CFO', contact.job_title
|
||||
assert_equal ['new', 'test'], contact.tag_list.sort
|
||||
assert_equal 3, contact.assigned_to_id
|
||||
end
|
||||
def test_post_create_with_custom_fields
|
||||
field = ContactCustomField.create!(:name => 'Test', :is_filter => true, :field_format => 'string')
|
||||
@request.session[:user_id] = 1
|
||||
assert_difference 'Contact.count' do
|
||||
compatible_request :post, :create, :project_id => 1, :contact => { :company => 'OOO "GKR"',
|
||||
:is_company => 0,
|
||||
:job_title => 'CFO',
|
||||
:assigned_to_id => 3,
|
||||
:tag_list => 'test,new',
|
||||
:last_name => 'New',
|
||||
:middle_name => 'Ivanovich',
|
||||
:first_name => 'Created',
|
||||
:custom_field_values => { "#{field.id}" => 'contact one' } }
|
||||
end
|
||||
assert_redirected_to :controller => 'contacts', :action => 'show', :id => Contact.last.id, :project_id => Contact.last.project
|
||||
|
||||
contact = Contact.where(:first_name => 'Created', :last_name => 'New', :middle_name => 'Ivanovich').first
|
||||
assert_equal 'contact one', contact.custom_field_values.last.value
|
||||
end
|
||||
|
||||
def test_post_create_without_permission
|
||||
@request.session[:user_id] = 4
|
||||
compatible_request :post, :create, :project_id => 1, :contact => { :company => 'OOO "GKR"',
|
||||
:is_company => 0,
|
||||
:job_title => 'CFO',
|
||||
:assigned_to_id => 3,
|
||||
:tag_list => 'test,new',
|
||||
:last_name => 'New',
|
||||
:middle_name => 'Ivanovich',
|
||||
:first_name => 'Created' }
|
||||
assert_response :forbidden
|
||||
end
|
||||
|
||||
def test_get_edit
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :edit, :id => 1
|
||||
assert_response :success
|
||||
assert_select 'h2', /Editing Contact Information/
|
||||
end
|
||||
|
||||
def test_get_edit_with_duplicates
|
||||
contact = Contact.find(3)
|
||||
contact_clone = contact.dup
|
||||
contact_clone.project = contact.project
|
||||
contact_clone.save!
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
Setting.default_language = 'en'
|
||||
|
||||
compatible_request :get, :edit, :id => 3
|
||||
assert_response :success
|
||||
assert_select 'div#duplicates', 1
|
||||
assert_select 'div#duplicates h3', /Possible duplicates/
|
||||
ensure
|
||||
contact_clone.delete
|
||||
end
|
||||
|
||||
def test_put_update
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
contact = Contact.find(1)
|
||||
new_firstname = 'Fist name modified by ContactsControllerTest#test_put_update'
|
||||
|
||||
compatible_request :put, :update, :id => 1, :project_id => 1, :contact => { :first_name => new_firstname }
|
||||
assert_redirected_to :action => 'show', :id => '1', :project_id => 1
|
||||
contact.reload
|
||||
assert_equal new_firstname, contact.first_name
|
||||
end
|
||||
|
||||
def test_post_destroy
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :post, :destroy, :id => 1, :project_id => 'ecookbook'
|
||||
assert_redirected_to :action => 'index', :project_id => 'ecookbook'
|
||||
assert_equal 0, Contact.where(:id => [1]).count
|
||||
end
|
||||
|
||||
def test_post_bulk_destroy
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :post, :bulk_destroy, :ids => [1, 2, 3]
|
||||
assert_redirected_to :controller => 'contacts', :action => 'index'
|
||||
|
||||
assert_equal 0, Contact.where(:id => [1, 2, 3]).count
|
||||
end
|
||||
|
||||
def test_post_bulk_destroy_without_permission
|
||||
@request.session[:user_id] = 4
|
||||
assert_raises ActiveRecord::RecordNotFound do
|
||||
compatible_request :post, :bulk_destroy, :ids => [1, 2]
|
||||
end
|
||||
end
|
||||
def test_bulk_edit_mails
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :post, :edit_mails, :ids => [1, 2]
|
||||
assert_response :success
|
||||
assert_not_nil contacts_in_list
|
||||
end
|
||||
|
||||
def test_bulk_edit_mails_by_deny_user
|
||||
@request.session[:user_id] = 4
|
||||
compatible_request :post, :edit_mails, :ids => [1, 2]
|
||||
assert_response 403
|
||||
end
|
||||
|
||||
def test_bulk_send_mails_by_deny_user
|
||||
@request.session[:user_id] = 4
|
||||
compatible_request :post, :send_mails, :ids => [1, 2], :message => 'test message', :subject => 'test subject'
|
||||
assert_response 403
|
||||
end
|
||||
|
||||
def test_bulk_send_mails
|
||||
ActionMailer::Base.deliveries.clear
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :post, :send_mails, :ids => [2], :from => 'test@mail.from', :bcc => 'test@mail.bcc', :"message-content" => "Hello %%NAME%%\ntest message", :subject => 'test subject'
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert_not_nil mail
|
||||
assert_match /Hello Marat/, mail.text_part.body.to_s
|
||||
assert_equal 'test subject', mail.subject
|
||||
assert_equal 'test@mail.from', mail.from.first
|
||||
assert_equal 'test@mail.bcc', mail.bcc.first
|
||||
note = Note.last
|
||||
assert_equal 'test subject', note.subject
|
||||
assert_equal note.type_id, Note.note_types[:email]
|
||||
assert_equal "Hello Marat\ntest message", note.content
|
||||
end
|
||||
|
||||
def test_post_bulk_edit
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :post, :bulk_edit, :ids => [1, 2]
|
||||
assert_response :success
|
||||
assert_not_nil contacts_in_list
|
||||
end
|
||||
|
||||
def test_post_bulk_edit_without_permission
|
||||
@request.session[:user_id] = 4
|
||||
assert_raises ActiveRecord::RecordNotFound do
|
||||
compatible_request :post, :bulk_edit, :ids => [1, 2]
|
||||
end
|
||||
end
|
||||
|
||||
def test_put_bulk_update
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :put, :bulk_update, :ids => [1, 2],
|
||||
:add_tag_list => 'bulk, edit, tags',
|
||||
:delete_tag_list => 'main',
|
||||
:add_projects_list => ['1', '2', '3'],
|
||||
:delete_projects_list => ['3', '4', '5'],
|
||||
:note => { :content => 'Bulk note content' },
|
||||
:contact => { :company => 'Bulk company', :job_title => '' }
|
||||
|
||||
assert_redirected_to :controller => 'contacts', :action => 'index', :project_id => nil
|
||||
contacts = Contact.find([1, 2])
|
||||
contacts.each do |contact|
|
||||
assert_equal 'Bulk company', contact.company
|
||||
tag_list = contact.tag_list # Need for 4 rails
|
||||
assert tag_list.include?('bulk')
|
||||
assert tag_list.include?('edit')
|
||||
assert tag_list.include?('tags')
|
||||
assert !tag_list.include?('main')
|
||||
assert contact.project_ids.include?(1) && contact.project_ids.include?(2)
|
||||
|
||||
assert_equal 'Bulk note content', contact.notes.find_by_content('Bulk note content').content
|
||||
end
|
||||
end
|
||||
|
||||
def test_put_bulk_update_without_permission
|
||||
@request.session[:user_id] = 4
|
||||
|
||||
compatible_request :put, :bulk_update, :ids => [1, 2],
|
||||
:add_tag_list => 'bulk, edit, tags',
|
||||
:delete_tag_list => 'main',
|
||||
:note => { :content => 'Bulk note content' },
|
||||
:contact => { :company => 'Bulk company', :job_title => '' }
|
||||
assert_response 403
|
||||
end
|
||||
|
||||
def test_get_contacts_notes
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
compatible_request :get, :contacts_notes
|
||||
assert_response :success
|
||||
assert_select 'h2', /All notes/
|
||||
assert_select 'div#contacts_notes table.note_data div.note.content.preview', /Note 1/
|
||||
end
|
||||
|
||||
def test_get_context_menu
|
||||
@request.session[:user_id] = 1
|
||||
compatible_xhr_request :get, :context_menu, :back_url => '/projects/contacts-plugin/contacts', :project_id => 'ecookbook', :ids => ['1', '2']
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_post_index_with_search
|
||||
@request.session[:user_id] = 1
|
||||
compatible_xhr_request :post, :index, :search => 'Domoway'
|
||||
assert_response :success
|
||||
assert_match 'contacts?search=Domoway', response.body
|
||||
assert_select 'a', :html => /Domoway/
|
||||
end
|
||||
|
||||
def test_post_index_with_search_in_project
|
||||
@request.session[:user_id] = 1
|
||||
compatible_xhr_request :post, :index, :search => 'Domoway', :project_id => 'ecookbook'
|
||||
assert_response :success
|
||||
assert_match 'contacts?search=Domoway', response.body
|
||||
assert_select 'a', :html => /Domoway/
|
||||
end
|
||||
|
||||
def test_post_contacts_notes_with_search
|
||||
@request.session[:user_id] = 1
|
||||
compatible_xhr_request :post, :contacts_notes, :search_note => 'Note 1'
|
||||
assert_response :success
|
||||
assert_match 'note_data', response.body
|
||||
assert_select 'table.note_data div.note.content.preview', /Note 1/
|
||||
assert_select 'table.note_data div.note.content.preview', { :count => 0, :text => /Note 2/ }
|
||||
end
|
||||
|
||||
def test_post_contacts_notes_with_search_in_project
|
||||
@request.session[:user_id] = 1
|
||||
compatible_xhr_request :post, :contacts_notes, :search_note => 'Note 2', :project_id => 'ecookbook'
|
||||
assert_response :success
|
||||
assert_match 'note_data', response.body
|
||||
assert_select 'table.note_data div.note.content.preview', /Note 2/
|
||||
end
|
||||
def test_should_have_import_csv_link_if_authorized_to
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :project_id => 1
|
||||
assert_response :success
|
||||
assert_select 'a#import_from_csv'
|
||||
end
|
||||
|
||||
def test_should_not_have_import_csv_link_if_unauthorized
|
||||
@request.session[:user_id] = 4
|
||||
compatible_request :get, :index, :project_id => 1
|
||||
assert_response :success
|
||||
assert_select 'a#import_from_csv', false, 'Should not see CSV import link'
|
||||
end
|
||||
|
||||
def test_index_should_omit_page_param_in_csv_export_link
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :page => 2
|
||||
assert_response :success
|
||||
assert_select 'a.csv[href=?]', '/contacts.csv'
|
||||
assert_select 'form#csv-export-form[action=?]', '/contacts.csv'
|
||||
end
|
||||
|
||||
def test_index_should_include_query_params_in_csv_export_form
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get,
|
||||
:index,
|
||||
{:project_id => 1,
|
||||
:set_filter => 1,
|
||||
:has_deals => 1,
|
||||
:c => ['name', 'job_title'],
|
||||
:sort => 'name'}
|
||||
|
||||
assert_select '#csv-export-form[action=?]', '/projects/ecookbook/contacts.csv'
|
||||
assert_select '#csv-export-form[method=?]', 'get'
|
||||
|
||||
assert_select '#csv-export-form' do
|
||||
assert_select 'input[name=?][value=?]', 'set_filter', '1'
|
||||
|
||||
assert_select 'input[name=?][value=?]', 'f[]', 'has_deals'
|
||||
assert_select 'input[name=?][value=?]', 'op[has_deals]', '='
|
||||
assert_select 'input[name=?][value=?]', 'v[has_deals][]', '1'
|
||||
|
||||
assert_select 'input[name=?][value=?]', 'c[]', 'name'
|
||||
assert_select 'input[name=?][value=?]', 'c[]', 'job_title'
|
||||
|
||||
assert_select 'input[name=?][value=?]', 'sort', 'name'
|
||||
end
|
||||
end if Redmine::VERSION::STRING > '3.2.1'
|
||||
|
||||
def test_index_csv_without_filters
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get,
|
||||
:index,
|
||||
{:format => 'csv',
|
||||
:set_filter => 1,
|
||||
:f => ['']}
|
||||
assert_response :success
|
||||
# -1 for headers
|
||||
lines = @response.body.chomp.lines.count - 1
|
||||
assert_equal Contact.count, lines
|
||||
end if Redmine::VERSION::STRING > '3.3'
|
||||
|
||||
def test_index_csv_with_some_filters
|
||||
@request.session[:user_id] = 1
|
||||
filter = {:job_title => 'CEO'}
|
||||
params = {:format => 'csv', :set_filter => 1}.merge(filter)
|
||||
|
||||
compatible_request :get, :index, params
|
||||
assert_response :success
|
||||
# -1 for headers
|
||||
lines = @response.body.chomp.lines.count - 1
|
||||
assert_equal Contact.where(filter).count, lines
|
||||
end if Redmine::VERSION::STRING > '3.3'
|
||||
|
||||
def test_index_csv_with_few_columns
|
||||
@request.session[:user_id] = 1
|
||||
columns = ['id', 'name', 'company', 'job_title']
|
||||
compatible_request :get,
|
||||
:index,
|
||||
:format => 'csv',
|
||||
:c => columns
|
||||
assert_response :success
|
||||
assert_equal 'text/csv; header=present', @response.content_type
|
||||
assert response.body.starts_with?("#,")
|
||||
|
||||
actual_columns = response.body.chomp.lines.first.split(',').count
|
||||
assert_equal columns.count, actual_columns
|
||||
end
|
||||
|
||||
def test_index_csv_with_all_available_columns
|
||||
@request.session[:user_id] = 1
|
||||
all_columns = if Redmine::VERSION::STRING < '3.2'
|
||||
{:columns => 'all'}
|
||||
elsif Redmine::VERSION::STRING < '3.4'
|
||||
{:csv => {:columns => 'all'}}
|
||||
else
|
||||
{:c => ['all_inline']}
|
||||
end
|
||||
params = {:format => 'csv'}.merge(all_columns)
|
||||
|
||||
compatible_request :get, :index, params
|
||||
assert_response :success
|
||||
assert_equal 'text/csv; header=present', @response.content_type
|
||||
assert response.body.starts_with?("#,")
|
||||
|
||||
available_columns = ContactQuery.new.available_columns.count
|
||||
actual_columns = response.body.chomp.lines.first.split(',').count
|
||||
assert_equal available_columns, actual_columns
|
||||
end
|
||||
|
||||
def test_index_with_contacts_as_cards_exports_all_columns
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :contacts_list_style => 'list_cards'
|
||||
assert_response :success
|
||||
assert_select 'a[href^="/contacts.csv"][onclick^=?]', 'showModal', false
|
||||
end
|
||||
|
||||
def test_index_with_contacts_as_list_allows_to_choose_columns
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :contacts_list_style => 'list'
|
||||
assert_response :success
|
||||
assert_select 'a[href^="/contacts.csv"][onclick^=?]', 'showModal'
|
||||
end
|
||||
|
||||
def test_index_properly_exports_tags_as_text_in_csv
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
contact = Contact.find(1)
|
||||
contact.tags = [RedmineCrm::Tag.new(:name => 'foo')]
|
||||
contact.save
|
||||
|
||||
compatible_request :get,
|
||||
:index,
|
||||
:format => 'csv',
|
||||
:c => ['tags']
|
||||
assert_response :success
|
||||
assert_include "foo\n", @response.body.chomp.lines
|
||||
end
|
||||
|
||||
def test_render_tab_partial_on_load_tab
|
||||
@request.session[:user_id] = 4
|
||||
compatible_xhr_request :get, :load_tab, :id => 3, :tab_name => 'notes', :partial => 'notes', :format => :js
|
||||
assert_response :success
|
||||
assert_match 'note_data', response.body
|
||||
end
|
||||
|
||||
def test_post_create_with_avatar
|
||||
image = Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/files/image.jpg'
|
||||
attach = Attachment.create!(:file => Rack::Test::UploadedFile.new(image, 'image/jpeg'), :author => User.find(1))
|
||||
|
||||
@request.session[:user_id] = 1
|
||||
assert_difference 'Contact.count' do
|
||||
compatible_request :post, :create, :project_id => 1,
|
||||
:attachments => { '0' => { 'filename' => 'image.jpg', 'description' => 'avatar', 'token' => attach.token } },
|
||||
:contact => { :last_name => 'Testov',
|
||||
:middle_name => 'Test',
|
||||
:first_name => 'Testovich' }
|
||||
end
|
||||
|
||||
assert_redirected_to :controller => 'contacts', :action => 'show', :id => Contact.last.id, :project_id => Contact.last.project
|
||||
assert_equal 'Contact', Attachment.last.container_type
|
||||
assert_equal Contact.last.id, Attachment.last.container_id
|
||||
|
||||
assert_equal 'image.jpg', Attachment.last.diskfile[/image\.jpg/]
|
||||
end
|
||||
|
||||
def test_last_notes_for_contact
|
||||
contact = Contact.find(1)
|
||||
note = contact.notes.create(:content => 'note for contact', :author_id => 1)
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index
|
||||
assert_response :success
|
||||
assert_select '.note.content', :text => note.content
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,103 @@
|
||||
# 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__)
|
||||
# require 'contacts_duplicates_controller'
|
||||
|
||||
class ContactsDuplicatesControllerTest < ActionController::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,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_get_index_duplicates
|
||||
contact = Contact.find(3)
|
||||
contact_clone = contact.dup
|
||||
contact_clone.project = contact.project
|
||||
contact_clone.save!
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
Setting.default_language = 'en'
|
||||
|
||||
compatible_request :get, :index, :project_id => contact.project, :contact_id => 3
|
||||
assert_response :success
|
||||
assert_select 'ul#contact_duplicates li', 1
|
||||
assert_select 'ul#contact_duplicates li a', contact.name
|
||||
ensure
|
||||
contact_clone.delete
|
||||
end
|
||||
|
||||
def test_get_merge_duplicates
|
||||
@request.session[:user_id] = 1
|
||||
Setting.default_language = 'en'
|
||||
|
||||
compatible_request :get, :merge, :project_id => 1, :contact_id => 1, :duplicate_id => 2
|
||||
assert_redirected_to :controller => 'contacts', :action => 'show', :id => 2, :project_id => 'ecookbook'
|
||||
|
||||
contact = Contact.find(2)
|
||||
assert_equal contact.emails, ['marat@mail.ru', 'marat@mail.com', 'ivan@mail.com']
|
||||
end
|
||||
|
||||
def test_xhr_get_duplicates
|
||||
@request.session[:user_id] = 1
|
||||
compatible_xhr_request :get, :duplicates, :project_id => 'ecookbook', :contact => { :first_name => 'marat' }
|
||||
assert_match /Marat Aminov/, @response.body
|
||||
end
|
||||
|
||||
def test_xhr_get_search
|
||||
@request.session[:user_id] = 1
|
||||
compatible_xhr_request :get, :search, :project_id => 'ecookbook', :contact_id => 2, :q => 'iva'
|
||||
assert_match /Ivan Ivanov/, @response.body
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,138 @@
|
||||
# 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 ContactsIssuesControllerTest < ActionController::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,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_create_issue
|
||||
@request.session[:user_id] = 1
|
||||
@request.env['HTTP_REFERER'] = '/contacts/1'
|
||||
parameters = { :issue => { :subject => 'Test subject', :assigned_to_id => '1', :due_date => Date.today.to_s, :description => 'Test descripiton', :tracker_id => '1' } }
|
||||
assert_difference('Issue.count') do
|
||||
assert_difference('ContactsIssue.count') do
|
||||
compatible_request :post, :create_issue, { :project_id => 1, :id => 1 }.merge!(parameters)
|
||||
end
|
||||
end
|
||||
assert_response 302
|
||||
end
|
||||
|
||||
def test_delete
|
||||
@request.session[:user_id] = 1
|
||||
ContactsIssue.create(:contact_id => 1, :issue_id => 1)
|
||||
assert_difference('ContactsIssue.count', -1) do
|
||||
compatible_xhr_request :delete, :delete, :project_id => 1, :id => 1, :issue_id => 1
|
||||
end
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_close
|
||||
@request.session[:user_id] = 1
|
||||
assert_not_nil Issue.find(1)
|
||||
compatible_xhr_request :post, :close, :issue_id => 1
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_autocomplete_for_contact
|
||||
@request.session[:user_id] = 1
|
||||
compatible_xhr_request :get, :autocomplete_for_contact, :q => 'domo', :issue_id => '1', :project_id => 'ecookbook', :cross_project_contacts => '1'
|
||||
assert_response :success
|
||||
assert_select 'input', :count => 1
|
||||
if ActiveRecord::VERSION::MAJOR >= 4
|
||||
assert_select "input[name='contacts_issue[contact_ids][]'][value='3']"
|
||||
else
|
||||
assert_select 'input[name=?][value=3]', 'contacts_issue[contact_ids][]'
|
||||
end
|
||||
end
|
||||
|
||||
def test_autocomplete_for_contact_cross_contacts
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
compatible_xhr_request :get, :autocomplete_for_contact, :q => 'a', :issue_id => '4', :project_id => 'onlinestore', :cross_project_contacts => '0'
|
||||
assert_response :success
|
||||
assert_select 'span.contact', :count => 1
|
||||
assert_select 'span.contact', /Ivan Ivanov/
|
||||
|
||||
compatible_xhr_request :get, :autocomplete_for_contact, :q => 'a', :issue_id => '4', :project_id => 'onlinestore', :cross_project_contacts => '1'
|
||||
assert_response :success
|
||||
assert_select 'span.contact', :count => 4
|
||||
assert_select 'span.contact', /Domoway/
|
||||
assert_select 'span.contact', /Ivan Ivanov/
|
||||
assert_select 'span.contact', /Marat Aminov/
|
||||
assert_select 'span.contact', /My company/
|
||||
end
|
||||
|
||||
def test_new
|
||||
@request.session[:user_id] = 1
|
||||
compatible_xhr_request :get, :new, :issue_id => '1'
|
||||
assert_response :success
|
||||
assert_match /ajax-modal/, response.body
|
||||
end
|
||||
|
||||
def test_create_multiple
|
||||
@request.session[:user_id] = 1
|
||||
assert_difference('ContactsIssue.count', 2) do
|
||||
compatible_xhr_request :post, :create, :issue_id => '2', :contacts_issue => {:contact_ids => ['3', '4']}
|
||||
assert_response :success
|
||||
assert_match /contacts/, response.body
|
||||
assert_match /ajax-modal/, response.body
|
||||
end
|
||||
assert Issue.find(2).contact_ids.include?(3)
|
||||
assert Issue.find(2).contact_ids.include?(4)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,75 @@
|
||||
# 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 ContactsMailerControllerTest < ActionController::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
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_should_create_issue
|
||||
# Enable API and set a key
|
||||
Setting.mail_handler_api_enabled = 1
|
||||
Setting.mail_handler_api_key = 'secret'
|
||||
|
||||
compatible_request :post, :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'fwd_new_note_plain.eml'))
|
||||
assert_response 201
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,94 @@
|
||||
# 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 ContactsProjectsControllerTest < ActionController::TestCase
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:time_entries
|
||||
|
||||
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
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_delete_destroy
|
||||
@request.session[:user_id] = 1
|
||||
contact = Contact.find(1)
|
||||
assert_equal 2, contact.projects.size
|
||||
compatible_xhr_request :delete, :destroy, :project_id => 1, :id => 2, :contact_id => 1
|
||||
assert_response :success
|
||||
assert_include 'contact_projects', response.body
|
||||
|
||||
contact.reload
|
||||
assert_equal [1], contact.project_ids
|
||||
end
|
||||
|
||||
def test_delete_destroy_last_project
|
||||
@request.session[:user_id] = 1
|
||||
contact = Contact.find(1)
|
||||
assert RedmineContacts::TestCase.is_arrays_equal(contact.project_ids, [1, 2])
|
||||
compatible_xhr_request :delete, :destroy, :project_id => 1, :id => 2, :contact_id => 1
|
||||
assert_response :success
|
||||
compatible_xhr_request :delete, :destroy, :project_id => 1, :id => 1, :contact_id => 1
|
||||
assert_response 403
|
||||
|
||||
contact.reload
|
||||
assert_equal [1], contact.project_ids
|
||||
end
|
||||
|
||||
def test_post_new
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_xhr_request :post, :new, :project_id => 'ecookbook', :id => 2, :contact_id => 2
|
||||
assert_response :success
|
||||
assert_include 'contact_projects', response.body
|
||||
contact = Contact.find(2)
|
||||
assert RedmineContacts::TestCase.is_arrays_equal(contact.project_ids, [1, 2])
|
||||
end
|
||||
|
||||
def test_post_create_without_permissions
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_xhr_request :post, :create, :project_id => 'project6', :id => 2, :contact_id => 2
|
||||
assert_response 403
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,60 @@
|
||||
# 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 ContactsSettingsControllerTest < ActionController::TestCase
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:time_entries
|
||||
|
||||
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
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_should_save_setting
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :post, :save, :project_id => 1, :contacts_settings => { :setting1 => 1, :setting2 => 'Hello' }, :tab => 'contacts'
|
||||
assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'contacts', :id => 'ecookbook'
|
||||
assert_equal '1', ContactsSetting[:setting1, 1]
|
||||
assert_equal 'Hello', ContactsSetting[:setting2, 1]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,112 @@
|
||||
# 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 ContactsTagsControllerTest < ActionController::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,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
User.current = nil
|
||||
@request.env['HTTP_REFERER'] = '/'
|
||||
end
|
||||
|
||||
def test_should_get_edit
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :edit, :id => 1
|
||||
assert_response :success
|
||||
assigned_tag = css_select('#tag_name').map { |tag| tag['value'] }.join
|
||||
assert_not_nil assigned_tag
|
||||
assert_equal RedmineCrm::Tag.find(1).name, assigned_tag
|
||||
end
|
||||
|
||||
def test_should_put_update
|
||||
@request.session[:user_id] = 1
|
||||
tag1 = RedmineCrm::Tag.find(1)
|
||||
new_name = 'updated main'
|
||||
compatible_request :put, :update, :id => 1, :tag => { :name => new_name, :color_name => '#000000' }
|
||||
assert_redirected_to :controller => 'settings', :action => 'plugin', :id => 'redmine_contacts', :tab => 'tags'
|
||||
tag1.reload
|
||||
assert_equal new_name, tag1.name
|
||||
end
|
||||
|
||||
def test_should_delete_destroy
|
||||
@request.session[:user_id] = 1
|
||||
assert_difference 'RedmineCrm::Tag.count', -1 do
|
||||
compatible_request :post, :destroy, :id => 1
|
||||
assert_response 302
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_get_merge
|
||||
@request.session[:user_id] = 1
|
||||
tag1 = RedmineCrm::Tag.find(1)
|
||||
tag2 = RedmineCrm::Tag.find(2)
|
||||
compatible_request :get, :merge, :ids => [tag1.id, tag2.id]
|
||||
assert_response :success
|
||||
merged_tags = css_select('.tag_list a').map { |tag| tag.to_s.to_s[/.*>(.+?)<\/a>/, 1] }
|
||||
assert_equal 2, merged_tags.size
|
||||
end
|
||||
|
||||
def test_should_post_merge
|
||||
@request.session[:user_id] = 1
|
||||
tag1 = RedmineCrm::Tag.find(1)
|
||||
tag2 = RedmineCrm::Tag.find(2)
|
||||
assert_difference 'RedmineCrm::Tag.count', -1 do
|
||||
compatible_request :post, :merge, :ids => [tag1.id, tag2.id], :tag => { :name => 'main' }
|
||||
assert_redirected_to :controller => 'settings', :action => 'plugin', :id => 'redmine_contacts', :tab => 'tags'
|
||||
end
|
||||
assert_equal 0, Contact.tagged_with('test').count
|
||||
assert_equal 4, Contact.tagged_with('main').count # added one more tagging for tag2
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,107 @@
|
||||
# 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 ContactsVcfControllerTest < ActionController::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,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
end
|
||||
|
||||
def test_load_from_vcard
|
||||
@request.session[:user_id] = 1
|
||||
Setting.default_language = 'en'
|
||||
|
||||
compatible_request :post, :load, {
|
||||
:project_id => 1,
|
||||
:contact_vcf => Rack::Test::UploadedFile.new(redmine_contacts_fixture_files_path + 'kirill_bezrukov.vcf', 'text/x-vcard')
|
||||
}
|
||||
|
||||
assert_redirected_to new_project_contact_path(:project_id => 'ecookbook', :contact => {
|
||||
'background' => 'Текстовое описание на Русском',
|
||||
'birthday' => '1981-05-12',
|
||||
'email' => 'kirill@gmail.com',
|
||||
'first_name' => 'Кирилл',
|
||||
'job_title' => '',
|
||||
'address_attributes' => { 'city' => 'Москва', 'postcode' => '', 'region' => '', 'street1' => 'Миклухи Маклая, 9 к 2, корпус Б' },
|
||||
'last_name' => 'Безруков',
|
||||
'middle_name' => '',
|
||||
'phone' => '+1 (234) 234-11-33'
|
||||
})
|
||||
end
|
||||
|
||||
def test_load_from_vcard_with_umlauts
|
||||
@request.session[:user_id] = 1
|
||||
Setting.default_language = 'en'
|
||||
|
||||
compatible_request :post, :load, {
|
||||
:project_id => 1,
|
||||
:contact_vcf => Rack::Test::UploadedFile.new(redmine_contacts_fixture_files_path + 'umlaut_card.vcf', 'text/x-vcard')
|
||||
}
|
||||
|
||||
assert_redirected_to new_project_contact_path(:project_id => 'ecookbook', :contact => {
|
||||
'address_attributes' => { 'city' => 'Düsseldorf', 'postcode' => '11111 ', 'region' => 'Nordrhein-Westfalen', 'street1' => 'Bleichstraße' },
|
||||
'background' => 'Test note',
|
||||
'birthday' => '1980-12-01',
|
||||
'company' => 'Geschäftszweig',
|
||||
'email' => 't.test@test.com',
|
||||
'first_name' => 'Test',
|
||||
'job_title' => 'Tester',
|
||||
'last_name' => 'Testovish',
|
||||
'middle_name' => '',
|
||||
'phone' => '+11-111-111111-11111'
|
||||
})
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,138 @@
|
||||
# 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 CrmQueriesControllerTest < ActionController::TestCase
|
||||
fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :enumerations, :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
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 1
|
||||
end
|
||||
|
||||
def test_get_new_project_query
|
||||
compatible_request :get, :new, :project_id => 1, :object_type => 'contact'
|
||||
assert_response :success
|
||||
att = { :type => 'checkbox',
|
||||
:name => 'query_is_for_all',
|
||||
:checked => nil,
|
||||
:disabled => nil }
|
||||
assert_select 'input', :attributes => att
|
||||
end
|
||||
|
||||
def test_get_new_global_query
|
||||
compatible_request :get, :new, :object_type => 'contact'
|
||||
assert_response :success
|
||||
att = { :type => 'checkbox',
|
||||
:name => 'query_is_for_all',
|
||||
:checked => 'checked',
|
||||
:disabled => nil }
|
||||
assert_select 'input', :attributes => att
|
||||
end
|
||||
|
||||
def test_post_create_project_public_query
|
||||
if Redmine::VERSION.to_s < '2.4'
|
||||
query_params = { 'name' => 'test_new_project_public_contacts_query', 'is_public' => '1' }
|
||||
else
|
||||
query_params = { 'name' => 'test_new_project_public_contacts_query', 'visibility' => '2' }
|
||||
end
|
||||
|
||||
compatible_request :post, :create,
|
||||
:project_id => 'ecookbook',
|
||||
:object_type => 'contact',
|
||||
:default_columns => '1',
|
||||
:f => ['first_name', 'last_name'],
|
||||
:op => { 'first_name' => '=', 'last_name' => '=' },
|
||||
:v => { 'first_name' => ['Ivan'], 'last_name' => ['Ivanov'] },
|
||||
:query => query_params
|
||||
|
||||
q = ContactQuery.find_by_name('test_new_project_public_contacts_query')
|
||||
assert_redirected_to :controller => 'contacts', :action => 'index', :project_id => 'ecookbook', :query_id => q
|
||||
assert q.is_public?
|
||||
assert q.has_default_columns?
|
||||
assert q.valid?
|
||||
end
|
||||
|
||||
def test_post_create_project_private_query
|
||||
|
||||
if Redmine::VERSION.to_s < '2.4'
|
||||
query_params = { 'name' => 'test_new_project_public_contacts_query', 'is_public' => '0' }
|
||||
else
|
||||
query_params = { 'name' => 'test_new_project_public_contacts_query', 'visibility' => '0' }
|
||||
end
|
||||
|
||||
compatible_request :post, :create,
|
||||
:project_id => 'ecookbook',
|
||||
:object_type => 'contact',
|
||||
:default_columns => '1',
|
||||
:f => ['first_name', 'last_name'],
|
||||
:op => { 'first_name' => '=', 'last_name' => '=' },
|
||||
:v => { 'first_name' => ['Ivan'], 'last_name' => ['Ivanov'] },
|
||||
:query => query_params
|
||||
|
||||
q = ContactQuery.find_by_name('test_new_project_public_contacts_query')
|
||||
assert_redirected_to :controller => 'contacts', :action => 'index', :project_id => 'ecookbook', :query_id => q
|
||||
assert !q.is_public?
|
||||
assert q.has_default_columns?
|
||||
assert q.valid?
|
||||
end
|
||||
|
||||
def test_put_update_global_public_query
|
||||
|
||||
if Redmine::VERSION.to_s < '2.4'
|
||||
query_params = { 'name' => 'test_edit_global_public_query', 'is_public' => '1' }
|
||||
else
|
||||
query_params = { 'name' => 'test_edit_global_public_query', 'visibility' => '2' }
|
||||
end
|
||||
|
||||
compatible_request :put, :update,
|
||||
:id => 2,
|
||||
:object_type => 'contact',
|
||||
:default_columns => '1',
|
||||
:fields => ['first_name', 'last_name'],
|
||||
:operators => { 'first_name' => '=', 'last_name' => '=' },
|
||||
:values => { 'first_name' => ['Ivan'], 'last_name' => ['Ivanov'] },
|
||||
:query => query_params
|
||||
|
||||
assert_redirected_to :controller => 'contacts', :action => 'index', :project_id => 'ecookbook', :query_id => 2
|
||||
q = ContactQuery.find_by_name('test_edit_global_public_query')
|
||||
assert q.is_public?
|
||||
assert q.has_default_columns?
|
||||
assert q.valid?
|
||||
end
|
||||
|
||||
def test_delete_destroy
|
||||
compatible_request :delete, :destroy, :id => 2, :object_type => 'contact'
|
||||
assert_redirected_to :controller => 'contacts', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil
|
||||
assert_nil Query.find_by_id(2)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,120 @@
|
||||
# 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 DealCategoriesControllerTest < ActionController::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,
|
||||
:deal_categories,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 1
|
||||
end
|
||||
|
||||
def test_get_new
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :new, :project_id => 1
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_get_edit
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :edit, :id => 1
|
||||
assert_response :success
|
||||
category_name = css_select('#category_name').map { |tag| tag['value'] }.join
|
||||
assert_not_nil category_name
|
||||
assert_equal DealCategory.find(1).name, category_name
|
||||
end
|
||||
|
||||
def test_put_update
|
||||
@request.session[:user_id] = 1
|
||||
category1 = DealCategory.find(1)
|
||||
new_name = 'updated main'
|
||||
compatible_request :put, :update, :id => 1, :category => { :name => new_name }
|
||||
assert_redirected_to '/projects/ecookbook/settings/deals'
|
||||
category1.reload
|
||||
assert_equal new_name, category1.name
|
||||
end
|
||||
|
||||
def test_destroy_category_not_in_use
|
||||
compatible_request :delete, :destroy, :id => 2
|
||||
assert_redirected_to '/projects/ecookbook/settings/deals'
|
||||
assert_nil DealCategory.find_by_id(2)
|
||||
end
|
||||
|
||||
def test_destroy_category_in_use
|
||||
compatible_request :delete, :destroy, :id => 1
|
||||
assert_response :success
|
||||
assert_not_nil DealCategory.find_by_id(1)
|
||||
end
|
||||
|
||||
def test_destroy_category_in_use_with_reassignment
|
||||
deal = Deal.where(:category_id => 1).first
|
||||
compatible_request :delete, :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
|
||||
assert_redirected_to '/projects/ecookbook/settings/deals'
|
||||
assert_nil DealCategory.find_by_id(1)
|
||||
# check that the issue was reassign
|
||||
assert_equal 2, deal.reload.category_id
|
||||
end
|
||||
|
||||
def test_destroy_category_in_use_without_reassignment
|
||||
deal = Deal.where(:category_id => 1).first
|
||||
compatible_request :delete, :destroy, :id => 1, :todo => 'nullify'
|
||||
assert_redirected_to '/projects/ecookbook/settings/deals'
|
||||
assert_nil DealCategory.find_by_id(1)
|
||||
# check that the issue category was nullified
|
||||
assert_nil deal.reload.category_id
|
||||
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/>.
|
||||
|
||||
# encoding: utf-8
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class DealImportsControllerTest < ActionController::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])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
@controller = DealImportsController.new
|
||||
User.current = nil
|
||||
@csv_file = Rack::Test::UploadedFile.new(redmine_contacts_fixture_files_path + 'deals_correct.csv', 'text/csv')
|
||||
end
|
||||
|
||||
test 'should open contact import form' do
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :new, :project_id => 1
|
||||
assert_response :success
|
||||
if Redmine::VERSION.to_s >= '3.2'
|
||||
assert_select 'form input#file'
|
||||
else
|
||||
assert_select 'form.new_deal_import'
|
||||
end
|
||||
end
|
||||
|
||||
test 'should create new import object' do
|
||||
if Redmine::VERSION.to_s >= '3.2'
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :create, :project_id => 1, :file => @csv_file
|
||||
assert_response :redirect
|
||||
assert_equal Import.last.class, DealKernelImport
|
||||
assert_equal Import.last.user, User.find(1)
|
||||
assert_equal Import.last.project, 1
|
||||
assert_equal Import.last.settings, { 'project' => 1,
|
||||
'separator' => ';',
|
||||
'wrapper' => "\"",
|
||||
'encoding' => 'ISO-8859-1',
|
||||
'date_format' => '%m/%d/%Y' }
|
||||
end
|
||||
end
|
||||
|
||||
test 'should open settings page' do
|
||||
if Redmine::VERSION.to_s >= '3.2'
|
||||
@request.session[:user_id] = 1
|
||||
import = DealKernelImport.new
|
||||
import.user = User.find(1)
|
||||
import.project = Project.find(1)
|
||||
import.file = @csv_file
|
||||
import.save!
|
||||
compatible_request :get, :settings, :id => import.filename, :project_id => 1
|
||||
assert_response :success
|
||||
assert_select 'form#import-form'
|
||||
end
|
||||
end
|
||||
|
||||
test 'should show mapping page' do
|
||||
if Redmine::VERSION.to_s >= '3.2'
|
||||
@request.session[:user_id] = 1
|
||||
import = DealKernelImport.new
|
||||
import.user = User.find(1)
|
||||
import.settings = { 'project' => 1,
|
||||
'separator' => ';',
|
||||
'wrapper' => "\"",
|
||||
'encoding' => 'UTF-8',
|
||||
'date_format' => '%m/%d/%Y' }
|
||||
import.file = @csv_file
|
||||
import.save!
|
||||
compatible_request :get, :mapping, :id => import.filename, :project_id => 1
|
||||
assert_response :success
|
||||
assert_select "select[name='import_settings[mapping][name]']"
|
||||
assert_select 'select[name="import_settings[mapping][currency]"]'
|
||||
assert_select 'table.sample-data tr'
|
||||
assert_select 'table.sample-data tr td', 'Сделка века'
|
||||
assert_select 'table.sample-data tr td', 'Кемска волость'
|
||||
end
|
||||
end
|
||||
|
||||
test 'should successfully import from CSV with new import' do
|
||||
if Redmine::VERSION.to_s >= '3.2'
|
||||
cf = DealCustomField.create!(:name => 'LIST_FIELD', :field_format => 'list', :multiple => true, :possible_values => %w(1 2 3))
|
||||
@request.session[:user_id] = 1
|
||||
import = DealKernelImport.new
|
||||
import.user = User.find(1)
|
||||
import.settings = { 'project' => 1,
|
||||
'separator' => ';',
|
||||
'wrapper' => "\"",
|
||||
'encoding' => 'UTF-8',
|
||||
'date_format' => '%m/%d/%Y' }
|
||||
import.file = @csv_file
|
||||
import.save!
|
||||
compatible_request :post, :mapping, :id => import.filename, :project_id => 1, :import_settings => { :mapping => { :name => 1, :background => 2, "cf_#{cf.id}" => 12 } }
|
||||
assert_response :redirect
|
||||
compatible_request :post, :run, :id => import.filename, :project_id => 1, :format => :js
|
||||
assert_equal Deal.last.name, 'Сделка века'
|
||||
assert_equal Deal.last.background, 'Кемска волость'
|
||||
assert_equal Deal.last.custom_field_value(cf).sort, ['1', '3']
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,122 @@
|
||||
# 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 DealStatusesControllerTest < ActionController::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])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
@controller = DealStatusesController.new
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_index_by_anonymous_should_redirect_to_login_form
|
||||
@request.session[:user_id] = nil
|
||||
compatible_request :get, :index
|
||||
assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fdeal_statuses'
|
||||
end
|
||||
|
||||
def test_should_get_new
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :new
|
||||
assert_response :success
|
||||
assert_select 'h2', %r{New}
|
||||
end
|
||||
|
||||
def test_should_get_edit
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :edit, :id => 1
|
||||
assert_response :success
|
||||
assert_select 'h2', %r{#{DealStatus.find(1).name}}
|
||||
end
|
||||
|
||||
def test_should_post_update
|
||||
@request.session[:user_id] = 1
|
||||
status1 = DealStatus.find(1)
|
||||
new_name = 'updated main'
|
||||
compatible_request :put, :update, :id => 1, :deal_status => { :name => new_name, :color_name => '#000000' }
|
||||
assert_redirected_to :controller => 'settings', :action => 'plugin', :id => 'redmine_contacts', :tab => 'deal_statuses'
|
||||
status1.reload
|
||||
assert_equal new_name, status1.name
|
||||
end
|
||||
|
||||
def test_assing_to_project
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :put, :assing_to_project, :deal_statuses => ['1', '2'], :project_id => 'ecookbook'
|
||||
assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'deals', :id => 'ecookbook'
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
@request.session[:user_id] = 1
|
||||
Deal.where('status_id = 1').delete_all
|
||||
|
||||
assert_difference 'DealStatus.count', -1 do
|
||||
compatible_request :delete, :destroy, :id => '1'
|
||||
end
|
||||
assert_redirected_to :controller => 'settings', :action => 'plugin', :id => 'redmine_contacts', :tab => 'deal_statuses'
|
||||
assert_nil DealStatus.find_by_id(1)
|
||||
end
|
||||
|
||||
def test_destroy_should_block_if_status_in_use
|
||||
@request.session[:user_id] = 1
|
||||
assert_not_nil Deal.find_by_status_id(1)
|
||||
|
||||
assert_no_difference 'DealStatus.count' do
|
||||
compatible_request :delete, :destroy, :id => '1'
|
||||
end
|
||||
assert_redirected_to :controller => 'settings', :action => 'plugin', :id => "redmine_contacts", :tab => "deal_statuses"
|
||||
assert_not_nil DealStatus.find_by_id(1)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,506 @@
|
||||
# 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__)
|
||||
include RedmineContacts::TestHelper
|
||||
|
||||
class DealsControllerTest < ActionController::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,
|
||||
:deals,
|
||||
:deal_statuses,
|
||||
:deal_statuses_projects,
|
||||
:notes])
|
||||
if RedmineContacts.products_plugin_installed?
|
||||
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_products).directory + '/test/fixtures/', [:product_categories,
|
||||
:products,
|
||||
:order_statuses,
|
||||
:orders,
|
||||
:product_lines])
|
||||
end
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_get_index
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :get, :index
|
||||
assert_response :success
|
||||
assert_not_nil deals_in_list
|
||||
assert_select 'a', /First deal with contacts/
|
||||
end
|
||||
|
||||
def test_get_index_list
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :get, :index, :deals_list_style => 'list'
|
||||
assert_response :success
|
||||
assert_select 'table.list.deals'
|
||||
assert_not_nil deals_in_list
|
||||
assert_select 'a', /First deal with contacts/
|
||||
end
|
||||
|
||||
def test_get_index_board
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :get, :index, :deals_list_style => 'list_board'
|
||||
assert_response :success
|
||||
assert_select 'table.list.deal-board'
|
||||
assert_not_nil deals_in_list
|
||||
assert_select 'a', /First deal with contacts/
|
||||
end
|
||||
|
||||
def test_get_index_pipeline
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :get, :index, :deals_list_style => 'list_pipeline'
|
||||
assert_response :success
|
||||
assert_select 'table.list.sales-funnel'
|
||||
assert_not_nil deals_in_list
|
||||
assert_select 'tr.deal_status_type-0 span', /Pending/
|
||||
end
|
||||
|
||||
def test_get_index_calendar
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :get, :index, :deals_list_style => 'crm_calendars/crm_calendar'
|
||||
assert_response :success
|
||||
assert_select 'table.cal'
|
||||
assert_not_nil deals_in_list
|
||||
assert_select 'td.even div.deal a', /First deal with contacts/
|
||||
end
|
||||
|
||||
def test_get_index_board_with_sorting
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :get, :index, :deals_list_style => 'list_board', :sort => 'due_date'
|
||||
assert_response :success
|
||||
assert_select 'table.list.deal-board'
|
||||
assert_not_nil deals_in_list
|
||||
assert_select 'a', /First deal with contacts/
|
||||
end
|
||||
|
||||
def test_get_index_with_closed
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :get, :index
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Deals'
|
||||
assert_select 'a', /First deal with contacts/
|
||||
assert_select 'table.contacts.index h1.deal_name a', { :count => 0, :text => /Closed deal/ }
|
||||
end
|
||||
|
||||
def test_get_closed_index_with_pages
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :get, :index, :f => ['']
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Deals'
|
||||
assert_select 'table.contacts.index h1.deal_name a', /Closed deal/
|
||||
end
|
||||
|
||||
def test_get_index_with_filters
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :get, :index, :f => ['status_id', ''], :op => { 'status_id' => '=' }, :v => { 'status_id' => ['3'] }
|
||||
assert_equal 1, deals_in_list.count
|
||||
assert_select 'table.contacts.index h1.deal_name a', /Second deal with contacts/
|
||||
assert_select 'table.contacts.index h1.deal_name a', { :count => 0, :text => 'Deal without contact' }
|
||||
end
|
||||
|
||||
def test_get_index_with_project
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :get, :index, :project_id => 1
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Deals'
|
||||
assert_not_nil deals_in_list
|
||||
assert_select 'a', :html => /First deal with contacts/
|
||||
assert_select 'Second deal with contacts', false
|
||||
assert_select 'h3', :html => /Recently viewed/
|
||||
end
|
||||
|
||||
def test_filter_by_ids
|
||||
@request.session[:user_id] = 1
|
||||
ids = [3, 2]
|
||||
compatible_request :get, :index, :project_id => 2, :set_filter => 1, 'f' => ['ids', ''], 'op' => { 'ids' => '=' }, 'v' => { 'ids' => [ids.join(',')] }
|
||||
assert_response :success
|
||||
assert_equal ids.sort, deals_in_list.map(&:id).sort
|
||||
end if Redmine::VERSION.to_s >= '3.3'
|
||||
|
||||
def test_filter_by_ids_any
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :project_id => 1, :set_filter => 1, 'f' => ['ids', ''], 'op' => { 'ids' => '*' }
|
||||
assert_response :success
|
||||
assert_equal Project.find(1).deals.map(&:id).sort, deals_in_list.map(&:id).sort
|
||||
end if Redmine::VERSION.to_s >= '3.3'
|
||||
|
||||
def test_filter_by_ids_more_than
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :project_id => 2, :set_filter => 1, 'f' => ['ids', ''], 'op' => { 'ids' => '>=' }, 'v' => { 'ids' => [3] }
|
||||
assert_response :success
|
||||
assert_equal [3, 4, 5], deals_in_list.map(&:id).sort
|
||||
end if Redmine::VERSION.to_s >= '3.3'
|
||||
|
||||
def test_get_index_without_statuses
|
||||
project = Project.find_by_identifier('onlinestore')
|
||||
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :project_id => 'onlinestore'
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Deals'
|
||||
assert_equal 1, deals_in_list.count
|
||||
|
||||
assert_select 'table.deals_statistics'
|
||||
assert_select'a', :html => /Deal without contact/
|
||||
assert_select'span.tag-label-color a', :text => 'Pending(1)'
|
||||
|
||||
project.deal_statuses.delete_all
|
||||
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :project_id => 'onlinestore'
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Deals'
|
||||
assert_equal 1, deals_in_list.count
|
||||
|
||||
assert_select 'table.deals_statistics', { :count => 0 }
|
||||
assert_select 'a', :html => /Deal without contact/
|
||||
end
|
||||
|
||||
def test_post_create
|
||||
@request.session[:user_id] = 1
|
||||
assert_difference 'Deal.count' do
|
||||
compatible_request :post, :create, :project_id => 1,
|
||||
:deal => { :price => 5500,
|
||||
:name => 'New created deal 1',
|
||||
:background => 'Background of new created deal',
|
||||
:contact_id => 2,
|
||||
:assigned_to_id => 3,
|
||||
:category_id => 1,
|
||||
:probability => 30,
|
||||
:currency => 'RUB' }
|
||||
end
|
||||
assert_redirected_to :controller => 'deals', :action => 'show', :id => Deal.last.id
|
||||
|
||||
deal = Deal.find_by_name('New created deal 1')
|
||||
assert_not_nil deal
|
||||
assert_equal 1, deal.category_id
|
||||
assert_equal 2, deal.contact_id
|
||||
assert_equal 3, deal.assigned_to_id
|
||||
assert_equal 30, deal.probability
|
||||
assert_equal 'RUB', deal.currency
|
||||
end
|
||||
|
||||
def test_post_create_with_formatted_price
|
||||
with_contacts_settings('thousands_delimiter' => '.', 'decimal_separator' => ',') do
|
||||
@request.session[:user_id] = 1
|
||||
assert_difference 'Deal.count' do
|
||||
compatible_request :post, :create, :project_id => 1,
|
||||
:deal => { :price => '1.234,56',
|
||||
:name => 'New created deal 2',
|
||||
:background => 'Background of new created deal',
|
||||
:contact_id => 2,
|
||||
:assigned_to_id => 3,
|
||||
:category_id => 1,
|
||||
:probability => 30,
|
||||
:currency => 'RUB' }
|
||||
end
|
||||
assert_redirected_to :controller => 'deals', :action => 'show', :id => Deal.last.id
|
||||
|
||||
deal = Deal.find_by_name('New created deal 2')
|
||||
assert_not_nil deal
|
||||
assert_equal 1234.56, deal.price
|
||||
end
|
||||
end
|
||||
|
||||
def test_get_show
|
||||
@request.session[:user_id] = 1
|
||||
deal = Deal.find(1)
|
||||
compatible_request :get, :show, :id => deal.id
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Deal #1'
|
||||
assert_select 'table.subject_header td.name h1', %r{#{deal.name}}
|
||||
end
|
||||
|
||||
def test_get_show_with_custom_field
|
||||
NoteCustomField.create!(:name => 'TestCustomField', :default_value => 'test text', :field_format => 'string')
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :show, :id => 1
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Deal #1'
|
||||
assert_match 'TestCustomField', @response.body
|
||||
assert_match 'test text', @response.body
|
||||
end
|
||||
|
||||
def test_get_show_with_statuses
|
||||
project = Project.find(1)
|
||||
project.deal_statuses.delete_all
|
||||
project.deal_statuses << DealStatus.find(1)
|
||||
project.deal_statuses << DealStatus.find(2)
|
||||
project.save
|
||||
|
||||
assert_equal ['Intermediate 1', 'Intermediate 2', 'Lost', 'Pending', 'Won'].sort, DealStatus.all.map(&:name).sort
|
||||
assert_equal ['Pending', 'Won'].sort, project.deal_statuses.map(&:name).sort
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :show, :id => 1
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Deal #1'
|
||||
assert_select '#deal_status_id', /Pending/
|
||||
assert_select '#deal_status_id', /Won/
|
||||
assert_select '#deal_status_id', { :count => 0, :text => /Lost/ }
|
||||
end
|
||||
|
||||
def test_get_new
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
project = Project.find(1)
|
||||
project.deal_statuses << DealStatus.default
|
||||
project.save
|
||||
|
||||
compatible_request :get, :new, :project_id => 1
|
||||
assert_response :success
|
||||
assert_equal DealStatus.default, Deal.new.status
|
||||
assert_equal ContactsSetting.default_currency, Deal.new.currency
|
||||
end
|
||||
|
||||
def test_index_should_not_contatin_add_deal_link
|
||||
EnabledModule.where(:name => 'deals').delete_all
|
||||
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index
|
||||
assert_response :success
|
||||
assert_select '[href="/deals/new"]', { :count => 0 }
|
||||
end
|
||||
|
||||
def test_get_edit
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :edit, :id => 1
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Edit deal information'
|
||||
assert_equal Deal.find(1).name, css_select('input#deal_name').map { |tag| tag['value'] }.join
|
||||
end
|
||||
|
||||
def test_put_update
|
||||
@request.session[:user_id] = 1
|
||||
Setting.plugin_redmine_contacts['thousands_delimiter'] = ','
|
||||
Setting.plugin_redmine_contacts['decimal_separator'] = '.'
|
||||
|
||||
deal = Deal.find(3)
|
||||
new_name = 'Name modified by DealControllerTest#test_put_update'
|
||||
|
||||
compatible_request :put, :update, :id => 3, :deal => { :name => new_name, :currency => 'GBP', :price => 23000 }
|
||||
assert_redirected_to :action => 'show', :id => '3'
|
||||
deal.reload
|
||||
assert_equal 23000, deal.price
|
||||
|
||||
compatible_request :get, :show, :id => 3
|
||||
assert_response :success
|
||||
assert_select 'td.subject_info', /23\,000\.0/
|
||||
assert_equal new_name, deal.name
|
||||
end
|
||||
|
||||
def test_should_bulk_edit_deals
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :post, :bulk_edit, :ids => [1, 2, 4]
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Edit all selected deals'
|
||||
assert_not_nil deals_in_list
|
||||
end
|
||||
|
||||
def test_should_not_bulk_edit_deals_by_deny_user
|
||||
@request.session[:user_id] = 4
|
||||
compatible_request :post, :bulk_edit, :ids => [1, 2, 4]
|
||||
assert_response 403
|
||||
end
|
||||
|
||||
def test_should_put_bulk_update
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_request :put, :bulk_update, :ids => [1, 2, 4],
|
||||
:deal => { :assigned_to_id => 2,
|
||||
:category_id => 2,
|
||||
:currency => 'GBP' },
|
||||
:note => { :content => 'Bulk deals edit note content' }
|
||||
|
||||
assert_redirected_to :controller => 'deals', :action => 'index', :project_id => nil
|
||||
|
||||
deals = Deal.find(1, 2, 4)
|
||||
|
||||
assert_equal [2], deals.collect(&:assigned_to_id).uniq
|
||||
assert_equal [2], deals.collect(&:category_id).uniq
|
||||
assert_equal ['GBP'], deals.collect(&:currency).uniq
|
||||
|
||||
assert_equal 3, Note.where(:content => 'Bulk deals edit note content').count
|
||||
end
|
||||
|
||||
def test_should_delete_bulk_destroy
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :delete, :bulk_destroy, :ids => [1, 2, 4]
|
||||
assert_redirected_to :controller => 'deals', :action => 'index'
|
||||
end
|
||||
|
||||
def test_post_index_live_search
|
||||
@request.session[:user_id] = 1
|
||||
compatible_xhr_request :post, :index, :search => 'First'
|
||||
assert_response :success
|
||||
assert_select 'table.deals.index'
|
||||
assert_select 'a', :html => /First deal with contacts/
|
||||
end
|
||||
|
||||
def test_should_post_index_live_search_in_project
|
||||
@request.session[:user_id] = 1
|
||||
compatible_xhr_request :post, :index, :search => 'First', :project_id => 'ecookbook'
|
||||
assert_response :success
|
||||
assert_select 'table.deals.index'
|
||||
assert_select 'a', :content => /First deal with contacts/
|
||||
end
|
||||
|
||||
def test_should_get_index_as_csv
|
||||
field = DealCustomField.create!(:name => 'Test custom field', :is_filter => true, :field_format => 'string')
|
||||
deal = Deal.find(1)
|
||||
deal.custom_field_values = { field.id => "This is custom значение" }
|
||||
deal.save
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :format => 'csv'
|
||||
assert_response :success
|
||||
assert_not_nil deals_in_list
|
||||
assert_equal 'text/csv; header=present', @response.content_type
|
||||
assert_match 'Test custom field', @response.body
|
||||
assert_match 'This is custom значение', @response.body
|
||||
end
|
||||
|
||||
def test_put_update_recalc_count_in_status
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
project = Project.find 1
|
||||
deal = project.deals.first
|
||||
old_status = deal.status.id
|
||||
new_status_id = old_status + 1
|
||||
new_status = DealStatus.find(new_status_id)
|
||||
next_status_count = Deal.where(:status_id => new_status_id, :project_id => project.id).count
|
||||
compatible_request :put, :update, :id => 1, :deal => { :status_id => new_status_id }, :status_id => '*', :format => 'js', :project_id => 1
|
||||
deal.reload
|
||||
assert_equal new_status, deal.status
|
||||
assert_match "#{new_status.name} (#{next_status_count + 1})", @response.body
|
||||
end
|
||||
|
||||
def test_delete_links_for_watchers
|
||||
deal = Deal.find(1)
|
||||
user = User.find(2)
|
||||
Watcher.create!(:watchable_type => 'Deal', :watchable => deal, :user => user)
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :show, :id => 1
|
||||
assert_response :success
|
||||
assert_select "ul.watchers li.user-#{user.id} a.delete"
|
||||
end
|
||||
def test_create_with_related_product
|
||||
@request.session[:user_id] = 1
|
||||
product = Product.find(1)
|
||||
compatible_request :post, :create, :project_id => 1,
|
||||
:deal => { :price => 5500,
|
||||
:name => 'New deal with product',
|
||||
:background =>'Background of new created deal',
|
||||
:contact_id => 2,
|
||||
:assigned_to_id => 3,
|
||||
:category_id => 1,
|
||||
:probability => 30,
|
||||
:currency => 'RUB',
|
||||
:lines_attributes => { '0' => { :product_id => product.id,
|
||||
:description => '',
|
||||
:quantity => '2',
|
||||
:price => '223.0',
|
||||
:tax => '5.0',
|
||||
:discount => '10',
|
||||
:_destroy => 'false',
|
||||
:position => '' } } }
|
||||
assert_redirected_to :controller => 'deals', :action => 'show', :id => Deal.last.id
|
||||
|
||||
deal = Deal.find_by_name('New deal with product')
|
||||
assert_not_nil deal
|
||||
assert_equal 1, deal.category_id
|
||||
assert_equal 2, deal.contact_id
|
||||
assert_equal 3, deal.assigned_to_id
|
||||
assert_equal 30, deal.probability
|
||||
assert_equal 'RUB', deal.currency
|
||||
assert_equal 1, deal.lines.count
|
||||
assert_equal product, deal.lines.last.product
|
||||
end if RedmineContacts.products_plugin_installed?
|
||||
|
||||
def test_get_show_with_related_product
|
||||
@request.session[:user_id] = 1
|
||||
deal = Deal.find(1)
|
||||
compatible_request :get, :show, :id => deal.id
|
||||
|
||||
assert_response :success
|
||||
assert_select 'table.product-lines tr.line-data', 1
|
||||
end if RedmineContacts.products_plugin_installed?
|
||||
|
||||
def test_get_edit_with_related_product
|
||||
@request.session[:user_id] = 1
|
||||
deal = Deal.find(1)
|
||||
compatible_request :get, :edit, :id => deal.id
|
||||
|
||||
assert_response :success
|
||||
assert_select 'table.product-lines tr.sortable-line', 1
|
||||
end if RedmineContacts.products_plugin_installed?
|
||||
|
||||
def test_get_index_with_product_filter
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :set_filter => '1', :f => ['products', ''], :op => { 'products' => '*' }
|
||||
assert_equal 5, deals_in_list.count
|
||||
assert_select 'table.deals.index h1.deal_name a', /First deal with contacts/
|
||||
end if RedmineContacts.products_plugin_installed?
|
||||
|
||||
def test_get_index_with_product_category_filter
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index, :set_filter => '1', :f => ['product_category_id', ''], :op => { 'product_category_id' => '=' }, :v => { :product_category_id => ['1'] }
|
||||
assert_equal 1, deals_in_list.count
|
||||
assert_select 'table.deals.index h1.deal_name a', /First deal with contacts/
|
||||
end if RedmineContacts.products_plugin_installed?
|
||||
end
|
||||
@@ -0,0 +1,149 @@
|
||||
# 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 IssuesControllerTest < ActionController::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_issues,
|
||||
:deals,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 1
|
||||
end
|
||||
|
||||
def test_get_show_issue_with_deal_and_contacts
|
||||
compatible_request :get, :show, :id => 1
|
||||
assert_response :success
|
||||
assert_select '#issue_contacts span.contact a', /Marat Aminov/
|
||||
if Redmine::VERSION.to_s >= '3.2'
|
||||
assert_select 'div.value a', /Ivan Ivanov: First deal with contacts/
|
||||
else
|
||||
assert_select 'td a', /Ivan Ivanov: First deal with contacts/
|
||||
end
|
||||
end
|
||||
def test_get_index_with_contacts_and_deals
|
||||
compatible_request :get, :index, :f => ['status_id', 'companies', 'deal', ''],
|
||||
:op => { :status_id => 'o', :companies => '=', :deal => '=' },
|
||||
:v => { :companies => ['3'], :deal => ['2'] },
|
||||
:c => ['subject', 'contacts', 'deal'],
|
||||
:project_id => 'ecookbook'
|
||||
assert_response :success
|
||||
assert_select 'table.list.issues td.contacts span.contact a', /Marat Aminov/
|
||||
assert_select 'table.list.issues td.deal a', /Second deal with contacts/
|
||||
end
|
||||
|
||||
def test_get_issues_without_contacts
|
||||
compatible_request :get, :index, :f => ['status_id', 'contacts', ''],
|
||||
:op => { :status_id => '*', :contacts => '!*' },
|
||||
:c => ['subject', 'contacts'],
|
||||
:project_id => 'ecookbook'
|
||||
assert_response :success
|
||||
assert_select 'table.list.issues td.contacts', ''
|
||||
end
|
||||
|
||||
def test_get_issues_only_with_contacts
|
||||
compatible_request :get, :index, :f => ['status_id', 'contacts', ''],
|
||||
:op => { :status_id => '*', :contacts => '*' },
|
||||
:c => ['subject', 'contacts'],
|
||||
:project_id => 'ecookbook'
|
||||
assert_response :success
|
||||
assert_select 'table.list.issues td.contacts'
|
||||
end
|
||||
|
||||
def test_get_new_with_deal
|
||||
compatible_request :get, :new, :project_id => 'ecookbook', :deal_id => 1
|
||||
assert_response :success
|
||||
assert_select 'select#issue_deals_issue_attributes_deal_id', /First deal with contacts/
|
||||
if ActiveRecord::VERSION::MAJOR >= 4
|
||||
assert_select "#issue_deals_issue_attributes_deal_id option[value='1']"
|
||||
else
|
||||
assert_select '#issue_deals_issue_attributes_deal_id option[value=?]', 1
|
||||
end
|
||||
end
|
||||
|
||||
def test_post_create_with_deal
|
||||
assert_difference 'DealsIssue.count' do
|
||||
compatible_request :post, :create, :issue => { :tracker_id => 3, :subject => 'test', :status_id => 2, :priority_id => 5,
|
||||
:deals_issue_attributes => { :deal_id => 1 } },
|
||||
:project_id => 'ecookbook'
|
||||
end
|
||||
|
||||
issue = Issue.order('id ASC').last
|
||||
assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
|
||||
assert_not_nil issue.deal
|
||||
end
|
||||
|
||||
def test_post_create_with_invalid_deal_id
|
||||
assert_no_difference 'Issue.count' do
|
||||
compatible_request :post, :create, :issue => { :tracker_id => 3, :subject => 'test', :status_id => 2, :priority_id => 5,
|
||||
:deals_issue_attributes => { :deal_id => 'abc' } },
|
||||
:project_id => 'ecookbook'
|
||||
end
|
||||
end
|
||||
|
||||
def test_put_update_form
|
||||
issue = Issue.find(1)
|
||||
if ActiveRecord::VERSION::MAJOR < 4
|
||||
compatible_xhr_request :put, :update_form, :issue => { :tracker_id => 2,
|
||||
:deals_issue_attributes => { :deal_id => 2 } },
|
||||
:project_id => issue.project
|
||||
assert_response :success
|
||||
assert_equal 'text/javascript', response.content_type
|
||||
|
||||
issue = assigns(:issue)
|
||||
assert_kind_of Issue, issue
|
||||
assert_equal 2, issue.deals_issue.deal_id
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,91 @@
|
||||
# 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 NotesControllerTest < ActionController::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,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
User.current = nil
|
||||
@request.env['HTTP_REFERER'] = '/'
|
||||
end
|
||||
|
||||
def test_should_post_add_note_to_contact
|
||||
@request.session[:user_id] = 1
|
||||
assert_difference 'Note.count' do
|
||||
compatible_request :post, :create, :project_id => 1,
|
||||
:note => { :subject => 'Note subject',
|
||||
:content => 'Note *content*' },
|
||||
:source_type => Contact.to_s,
|
||||
:source_id => 1
|
||||
end
|
||||
|
||||
note = Note.where(:subject => 'Note subject', :content => 'Note *content*').first
|
||||
assert_not_nil note
|
||||
assert_equal 1, note.source_id
|
||||
assert_equal Contact, note.source.class
|
||||
end
|
||||
|
||||
def test_should_put_update
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
note = Note.find(1)
|
||||
new_content = 'New note content'
|
||||
|
||||
compatible_request :put, :update, :id => 1, :project_id => 1, :note => { :content => new_content }
|
||||
assert_redirected_to :action => 'show', :project_id => note.source.project, :id => note.id
|
||||
note.reload
|
||||
assert_equal new_content, note.content
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,45 @@
|
||||
# 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 QueriesControllerTest < ActionController::TestCase
|
||||
fixtures :projects, :enabled_modules,
|
||||
:users, :email_addresses,
|
||||
:members, :member_roles, :roles,
|
||||
:trackers, :issue_statuses, :issue_categories, :enumerations, :versions,
|
||||
:issues, :custom_fields, :custom_values,
|
||||
:queries
|
||||
|
||||
def setup
|
||||
User.current = nil
|
||||
end
|
||||
def test_filter_for_contact_custom_field
|
||||
contact_cf = ContactCustomField.create!(:name => 'contact_cf', :is_filter => true, :field_format => 'company')
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :filter, :params => { :type => 'ContactQuery', :name => contact_cf.name }
|
||||
|
||||
assert_response :success
|
||||
assert_equal 'application/json', response.content_type
|
||||
ensure
|
||||
contact_cf.destroy
|
||||
end if Redmine::VERSION.to_s >= '3.4' || RedmineContacts.unstable_branch?
|
||||
end
|
||||
@@ -0,0 +1,86 @@
|
||||
# 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 SearchControllerTest < ActionController::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,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
def test_search_for_contacts
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Search'
|
||||
|
||||
compatible_request :get, :index, :q => 'ivan'
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Search'
|
||||
assert_match Contact.find(1).first_name, response.body
|
||||
end
|
||||
|
||||
def test_search_for_contacts_by_email
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :index
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Search'
|
||||
|
||||
compatible_request :get, :index, :q => 'marat@mail.ru'
|
||||
assert_response :success
|
||||
assert_select 'h2', 'Search'
|
||||
assert_match Contact.find(2).first_name, response.body
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,89 @@
|
||||
# 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 TimelogControllerTest < ActionController::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_issues,
|
||||
:deals,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
end
|
||||
def test_get_report_with_deal
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :report, :columns => 'month', :criteria => ['deal', 'deal_contact'], :project_id => 'ecookbook'
|
||||
assert_response :success
|
||||
assert_select 'table#time-report td', /Domoway/
|
||||
assert_select 'table#time-report td', /First deal with contacts/
|
||||
assert_select 'table#time-report td', /Second deal with contacts/
|
||||
end
|
||||
|
||||
def test_get_index_with_company_cf
|
||||
@request.session[:user_id] = 1
|
||||
project = Project.find(1)
|
||||
company = Contact.find(3)
|
||||
@cfield = IssueCustomField.create!(:name => 'COMPANY', :field_format => 'company', :is_filter => true)
|
||||
@cfield.projects << project
|
||||
compatible_request :get, :index, :set_filter => 1,
|
||||
:f => ["issue.cf_#{@cfield.id}", ''],
|
||||
:op => { "issue.cf_#{@cfield.id}" => '=' },
|
||||
:v => { "issue.cf_#{@cfield.id}" => [company.id] },
|
||||
:c => ['spent_on', 'user', 'issue'],
|
||||
:project_id => project.identifier
|
||||
assert_response :success
|
||||
assert_match "values\":[[\"#{company.name}\",\"#{company.id}\"]]", response.body
|
||||
assert_match "\"field_format\":\"company\"", response.body
|
||||
ensure
|
||||
@cfield.destroy
|
||||
end if Redmine::VERSION.to_s > '2.5'
|
||||
end
|
||||
@@ -0,0 +1,67 @@
|
||||
# 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 UsersControllerTest < ActionController::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,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
end
|
||||
def test_get_new_from_contact
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :new_from_contact, :contact_id => 1, :id => 'current'
|
||||
assert_response :success
|
||||
assert_select 'input#user_firstname[value=?]', 'Ivan'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,112 @@
|
||||
# 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 WikiControllerTest < ActionController::TestCase
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:roles,
|
||||
:enabled_modules,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:wikis,
|
||||
: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,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
RedmineContacts::TestCase.prepare
|
||||
EnabledModule.create(:project_id => 1, :name => 'wiki')
|
||||
@project = Project.find(1)
|
||||
@wiki = @project.wiki
|
||||
@page_name = 'contact_macro_test'
|
||||
@page = @wiki.find_or_new_page(@page_name)
|
||||
@page.content = WikiContent.new
|
||||
@page.content.text = 'test'
|
||||
@page.content.author = User.find(1)
|
||||
@page.save!
|
||||
end
|
||||
|
||||
def test_show_with_contact_macro
|
||||
@request.session[:user_id] = 1
|
||||
@page.content.text = '{{contact(1)}}'
|
||||
@page.content.save!
|
||||
compatible_request :get, :show, :project_id => 1, :id => @page_name
|
||||
assert_response :success
|
||||
assert_select 'h3', 'Wiki'
|
||||
assert_select 'div.wiki p', /Ivan Ivanov/
|
||||
end
|
||||
|
||||
def test_show_with_contact_avatar_macro
|
||||
@request.session[:user_id] = 1
|
||||
@page.content.text = '{{contact_avatar(1)}}'
|
||||
@page.content.save!
|
||||
compatible_request :get, :show, :project_id => 1, :id => @page_name
|
||||
assert_response :success
|
||||
assert_select 'h3', 'Wiki'
|
||||
assert_select 'div.wiki p img'
|
||||
end
|
||||
|
||||
def test_show_with_note_macro
|
||||
@request.session[:user_id] = 1
|
||||
@page.content.text = '{{contact_note(1)}}'
|
||||
@page.content.save!
|
||||
compatible_request :get, :show, :project_id => 1, :id => @page_name
|
||||
assert_response :success
|
||||
assert_select 'h3', 'Wiki'
|
||||
assert_select 'div.wiki p', /Note 1 content with wiki syntax/
|
||||
end
|
||||
def test_show_with_deal_macro
|
||||
@request.session[:user_id] = 1
|
||||
@page.content.text = '{{deal(1)}}'
|
||||
@page.content.save!
|
||||
compatible_request :get, :show, :project_id => 1, :id => @page_name
|
||||
assert_response :success
|
||||
assert_select 'h3', 'Wiki'
|
||||
assert_select 'div.wiki p', /Ivan Ivanov: First deal with contacts/
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user