fat_free_crm 0.20.1 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fat_free_crm might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +170 -0
- data/README.md +3 -6
- data/app/assets/config/fat_free_crm.js +3 -0
- data/app/assets/config/manifest.js +1 -0
- data/app/controllers/admin/field_groups_controller.rb +0 -2
- data/app/controllers/admin/tags_controller.rb +1 -1
- data/app/controllers/admin/users_controller.rb +1 -1
- data/app/controllers/application_controller.rb +11 -0
- data/app/controllers/comments_controller.rb +2 -0
- data/app/controllers/emails_controller.rb +2 -0
- data/app/controllers/entities/accounts_controller.rb +3 -1
- data/app/controllers/entities/campaigns_controller.rb +3 -1
- data/app/controllers/entities/contacts_controller.rb +3 -1
- data/app/controllers/entities/leads_controller.rb +4 -2
- data/app/controllers/entities/opportunities_controller.rb +3 -1
- data/app/controllers/entities_controller.rb +2 -0
- data/app/controllers/home_controller.rb +2 -0
- data/app/controllers/lists_controller.rb +2 -0
- data/app/controllers/tasks_controller.rb +3 -1
- data/app/controllers/users_controller.rb +2 -0
- data/app/helpers/accounts_helper.rb +2 -0
- data/app/helpers/application_helper.rb +22 -3
- data/app/helpers/tasks_helper.rb +1 -2
- data/app/models/entities/account.rb +1 -1
- data/app/models/entities/campaign.rb +1 -1
- data/app/models/entities/contact.rb +1 -1
- data/app/models/entities/lead.rb +1 -1
- data/app/models/entities/opportunity.rb +1 -1
- data/app/models/fields/custom_field.rb +2 -2
- data/app/models/observers/entity_observer.rb +1 -1
- data/app/models/polymorphic/avatar.rb +1 -30
- data/app/models/polymorphic/comment.rb +1 -1
- data/app/models/polymorphic/task.rb +1 -0
- data/app/models/setting.rb +4 -5
- data/app/models/users/user.rb +1 -1
- data/app/views/home/index.xls.builder +1 -0
- data/app/views/shared/_address.html.haml +1 -1
- data/bin/bundle +108 -2
- data/bin/rails +3 -3
- data/bin/rake +2 -2
- data/bin/setup +12 -15
- data/config/application.rb +22 -4
- data/config/boot.rb +3 -5
- data/config/cable.yml +10 -0
- data/config/database.yml +26 -0
- data/config/environment.rb +4 -3
- data/config/environments/development.rb +47 -11
- data/config/environments/production.rb +17 -15
- data/config/environments/test.rb +19 -9
- data/config/initializers/action_mailer.rb +1 -0
- data/config/initializers/content_security_policy.rb +21 -26
- data/config/initializers/custom_field_ransack_translations.rb +1 -0
- data/config/initializers/filter_parameter_logging.rb +6 -2
- data/config/initializers/inflections.rb +4 -4
- data/config/initializers/permissions_policy.rb +12 -0
- data/config/puma.rb +2 -2
- data/config/storage.yml +34 -0
- data/db/demo/field_groups.yml +2 -1
- data/db/migrate/20100928030617_drop_openid_tables.rb +2 -1
- data/db/migrate/20230526211831_create_active_storage_tables.active_storage.rb +51 -0
- data/db/migrate/20230526212613_convert_to_active_storage.rb +107 -0
- data/db/schema.rb +108 -76
- data/db/seeds/fields.rb +7 -21
- data/lib/development_tasks/license.rake +10 -10
- data/lib/fat_free_crm/callback.rb +2 -3
- data/lib/fat_free_crm/errors.rb +2 -10
- data/lib/fat_free_crm/exceptions.rb +1 -0
- data/lib/fat_free_crm/fields.rb +4 -5
- data/lib/fat_free_crm/gem_dependencies.rb +0 -1
- data/lib/fat_free_crm/i18n.rb +1 -1
- data/lib/fat_free_crm/mail_processor/dropbox.rb +1 -1
- data/lib/fat_free_crm/version.rb +3 -3
- data/public/avatars/User/2/large_rails.png +0 -0
- data/public/avatars/User/2/medium_rails.png +0 -0
- data/public/avatars/User/2/small_rails.png +0 -0
- data/public/avatars/User/2/thumb_rails.png +0 -0
- data/public/avatars/User/3/large_rails.png +0 -0
- data/public/avatars/User/3/medium_rails.png +0 -0
- data/public/avatars/User/3/original_rails.png +0 -0
- data/public/avatars/User/3/small_rails.png +0 -0
- data/public/avatars/User/3/thumb_rails.png +0 -0
- data/public/avatars/User/4/large_rails.png +0 -0
- data/public/avatars/User/4/medium_rails.png +0 -0
- data/public/avatars/User/4/original_rails.png +0 -0
- data/public/avatars/User/4/small_rails.png +0 -0
- data/public/avatars/User/4/thumb_rails.png +0 -0
- data/public/avatars/User/6/large_rails.png +0 -0
- data/public/avatars/User/6/medium_rails.png +0 -0
- data/public/avatars/User/6/original_rails.png +0 -0
- data/public/avatars/User/6/small_rails.png +0 -0
- data/public/avatars/User/6/thumb_rails.png +0 -0
- data/public/avatars/User/7/large_rails.png +0 -0
- data/public/avatars/User/7/medium_rails.png +0 -0
- data/public/avatars/User/7/original_rails.png +0 -0
- data/public/avatars/User/7/small_rails.png +0 -0
- data/public/avatars/User/7/thumb_rails.png +0 -0
- metadata +73 -288
- data/.docker/nginx/sites-enabled/ffcrm.conf +0 -8
- data/.github/workflows/brakeman-analysis.yml +0 -46
- data/.github/workflows/rubocop-analysis.yml +0 -40
- data/.github/workflows/ruby.yml +0 -52
- data/.gitignore +0 -39
- data/.rubocop.yml +0 -73
- data/.rubocop_todo.yml +0 -286
- data/.teatro.yml +0 -3
- data/.travis.yml +0 -60
- data/CONTRIBUTORS.md +0 -135
- data/Capfile +0 -27
- data/Dockerfile +0 -51
- data/Gemfile +0 -106
- data/Gemfile.lock +0 -529
- data/Guardfile +0 -26
- data/Procfile +0 -1
- data/SECURITY.md +0 -11
- data/Vagrantfile +0 -92
- data/config/initializers/new_framework_defaults_6_0.rb +0 -46
- data/custom_plan.rb +0 -11
- data/docker-compose.yml +0 -27
- data/fat_free_crm.gemspec +0 -62
- data/lib/tasks/.gitkeep +0 -0
- data/lib/tasks/.gitkeep~master +0 -0
- data/script/rails +0 -8
- data/spec/controllers/admin/groups_controller_spec.rb +0 -11
- data/spec/controllers/admin/users_controller_spec.rb +0 -251
- data/spec/controllers/applications_controller_spec.rb +0 -43
- data/spec/controllers/comments_controller_spec.rb +0 -195
- data/spec/controllers/emails_controller_spec.rb +0 -37
- data/spec/controllers/entities/accounts_controller_spec.rb +0 -607
- data/spec/controllers/entities/campaigns_controller_spec.rb +0 -645
- data/spec/controllers/entities/contacts_controller_spec.rb +0 -705
- data/spec/controllers/entities/leads_controller_spec.rb +0 -1009
- data/spec/controllers/entities/opportunities_controller_spec.rb +0 -904
- data/spec/controllers/entities_controller_spec.rb +0 -47
- data/spec/controllers/home_controller_spec.rb +0 -235
- data/spec/controllers/lists_controller_spec.rb +0 -11
- data/spec/controllers/tasks_controller_spec.rb +0 -517
- data/spec/controllers/users_controller_spec.rb +0 -375
- data/spec/factories/account_factories.rb +0 -40
- data/spec/factories/campaign_factories.rb +0 -30
- data/spec/factories/contact_factories.rb +0 -45
- data/spec/factories/field_factories.rb +0 -40
- data/spec/factories/lead_factories.rb +0 -36
- data/spec/factories/list_factories.rb +0 -13
- data/spec/factories/opportunity_factories.rb +0 -39
- data/spec/factories/sequences.rb +0 -32
- data/spec/factories/setting_factories.rb +0 -15
- data/spec/factories/shared_factories.rb +0 -70
- data/spec/factories/subscription_factories.rb +0 -13
- data/spec/factories/tag_factories.rb +0 -12
- data/spec/factories/task_factories.rb +0 -29
- data/spec/factories/user_factories.rb +0 -66
- data/spec/features/acceptance_helper.rb +0 -11
- data/spec/features/accounts_spec.rb +0 -126
- data/spec/features/admin/groups_spec.rb +0 -31
- data/spec/features/admin/users_spec.rb +0 -40
- data/spec/features/campaigns_spec.rb +0 -104
- data/spec/features/contacts_spec.rb +0 -134
- data/spec/features/dashboard_spec.rb +0 -67
- data/spec/features/devise/sign_in_spec.rb +0 -58
- data/spec/features/devise/sign_up_spec.rb +0 -36
- data/spec/features/leads_spec.rb +0 -138
- data/spec/features/opportunities_overview_spec.rb +0 -88
- data/spec/features/opportunities_spec.rb +0 -132
- data/spec/features/support/autocomlete_helper.rb +0 -17
- data/spec/features/support/browser.rb +0 -28
- data/spec/features/support/headless.rb +0 -19
- data/spec/features/support/paths.rb +0 -48
- data/spec/features/support/selector_helpers.rb +0 -36
- data/spec/features/tasks_spec.rb +0 -94
- data/spec/helpers/accounts_helper_spec.rb +0 -73
- data/spec/helpers/admin/field_groups_helper_spec.rb +0 -20
- data/spec/helpers/admin/plugins_helper_spec.rb +0 -11
- data/spec/helpers/admin/settings_helper_spec.rb +0 -11
- data/spec/helpers/admin/users_helper_spec.rb +0 -11
- data/spec/helpers/application_helper_spec.rb +0 -86
- data/spec/helpers/authentications_helper_spec.rb +0 -16
- data/spec/helpers/campaigns_helper_spec.rb +0 -16
- data/spec/helpers/comments_helper_spec.rb +0 -16
- data/spec/helpers/contacts_helper_spec.rb +0 -16
- data/spec/helpers/emails_helper_spec.rb +0 -11
- data/spec/helpers/fields_helper_spec.rb +0 -12
- data/spec/helpers/groups_helper_spec.rb +0 -21
- data/spec/helpers/home_helper_spec.rb +0 -16
- data/spec/helpers/leads_helper_spec.rb +0 -16
- data/spec/helpers/lists_helper_spec.rb +0 -21
- data/spec/helpers/opportunities_helper_spec.rb +0 -16
- data/spec/helpers/passwords_helper_spec.rb +0 -16
- data/spec/helpers/tasks_helper_spec.rb +0 -20
- data/spec/helpers/users_helper_spec.rb +0 -39
- data/spec/lib/comment_extensions_spec.rb +0 -42
- data/spec/lib/core_ext/string_spec.rb +0 -23
- data/spec/lib/errors_spec.rb +0 -32
- data/spec/lib/fields_spec.rb +0 -101
- data/spec/lib/mail_processor/base_spec.rb +0 -169
- data/spec/lib/mail_processor/comment_replies_spec.rb +0 -70
- data/spec/lib/mail_processor/dropbox_spec.rb +0 -306
- data/spec/lib/mail_processor/sample_emails/dropbox.rb +0 -173
- data/spec/lib/permissions_spec.rb +0 -155
- data/spec/lib/secret_token_generator_spec.rb +0 -69
- data/spec/lib/view_factory_spec.rb +0 -69
- data/spec/mailers/devise_mailer_spec.rb +0 -35
- data/spec/mailers/subscription_mailer_spec.rb +0 -48
- data/spec/mailers/user_mailer_spec.rb +0 -115
- data/spec/models/entities/account_contact_spec.rb +0 -34
- data/spec/models/entities/account_opportunity_spec.rb +0 -34
- data/spec/models/entities/account_spec.rb +0 -206
- data/spec/models/entities/campaign_spec.rb +0 -131
- data/spec/models/entities/contact_opportunity_spec.rb +0 -34
- data/spec/models/entities/contact_spec.rb +0 -314
- data/spec/models/entities/lead_spec.rb +0 -102
- data/spec/models/entities/opportunity_spec.rb +0 -299
- data/spec/models/fields/custom_field_date_pair_spec.rb +0 -92
- data/spec/models/fields/custom_field_pair_spec.rb +0 -76
- data/spec/models/fields/custom_field_spec.rb +0 -129
- data/spec/models/fields/field_group_spec.rb +0 -29
- data/spec/models/fields/field_spec.rb +0 -69
- data/spec/models/list_spec.rb +0 -19
- data/spec/models/observers/entity_observer_spec.rb +0 -74
- data/spec/models/polymorphic/address_spec.rb +0 -34
- data/spec/models/polymorphic/avatar_spec.rb +0 -46
- data/spec/models/polymorphic/comment_spec.rb +0 -45
- data/spec/models/polymorphic/email_spec.rb +0 -53
- data/spec/models/polymorphic/task_spec.rb +0 -395
- data/spec/models/polymorphic/version_spec.rb +0 -241
- data/spec/models/setting_spec.rb +0 -77
- data/spec/models/users/abilities/user_ability_spec.rb +0 -70
- data/spec/models/users/group_spec.rb +0 -11
- data/spec/models/users/permission_spec.rb +0 -58
- data/spec/models/users/preference_spec.rb +0 -71
- data/spec/models/users/user_spec.rb +0 -238
- data/spec/routing/accounts_routing_spec.rb +0 -60
- data/spec/routing/admin/users_routing_spec.rb +0 -40
- data/spec/routing/campaigns_routing_spec.rb +0 -64
- data/spec/routing/comments_routing_spec.rb +0 -32
- data/spec/routing/contacts_routing_spec.rb +0 -60
- data/spec/routing/emails_routing_spec.rb +0 -40
- data/spec/routing/leads_routing_spec.rb +0 -88
- data/spec/routing/opportunities_routing_spec.rb +0 -64
- data/spec/routing/tasks_routing_spec.rb +0 -68
- data/spec/routing/users_routing_spec.rb +0 -106
- data/spec/shared/controllers.rb +0 -99
- data/spec/shared/models.rb +0 -141
- data/spec/spec_helper.rb +0 -117
- data/spec/support/assert_select.rb +0 -167
- data/spec/support/devise_helpers.rb +0 -28
- data/spec/support/feature_helpers.rb +0 -32
- data/spec/support/macros.rb +0 -49
- data/spec/support/mail_processor_mocks.rb +0 -37
- data/spec/support/uploaded_file.rb +0 -10
- data/spec/views/accounts/_edit.haml_spec.rb +0 -43
- data/spec/views/accounts/_new.haml_spec.rb +0 -42
- data/spec/views/accounts/create.js.haml_spec.rb +0 -52
- data/spec/views/accounts/destroy.js.haml_spec.rb +0 -34
- data/spec/views/accounts/edit.js.haml_spec.rb +0 -66
- data/spec/views/accounts/index.haml_spec.rb +0 -43
- data/spec/views/accounts/index.js.haml_spec.rb +0 -34
- data/spec/views/accounts/new.js.haml_spec.rb +0 -44
- data/spec/views/accounts/show.haml_spec.rb +0 -38
- data/spec/views/accounts/update.js.haml_spec.rb +0 -93
- data/spec/views/admin/field_groups/create.js.haml_spec.rb +0 -30
- data/spec/views/admin/field_groups/destroy.js.haml_spec.rb +0 -31
- data/spec/views/admin/field_groups/edit.js.haml_spec.rb +0 -24
- data/spec/views/admin/field_groups/new.js.haml_spec.rb +0 -25
- data/spec/views/admin/field_groups/update.js.haml_spec.rb +0 -29
- data/spec/views/admin/users/_create.haml_spec.rb +0 -23
- data/spec/views/admin/users/create.js.haml_spec.rb +0 -41
- data/spec/views/admin/users/destroy.js.haml_spec.rb +0 -47
- data/spec/views/admin/users/edit.js.haml_spec.rb +0 -44
- data/spec/views/admin/users/index.haml_spec.rb +0 -22
- data/spec/views/admin/users/index.js.haml_spec.rb +0 -26
- data/spec/views/admin/users/new.js.haml_spec.rb +0 -34
- data/spec/views/admin/users/reactivate.js.haml_spec.rb +0 -22
- data/spec/views/admin/users/show.haml_spec.rb +0 -18
- data/spec/views/admin/users/suspend.js.haml_spec.rb +0 -22
- data/spec/views/admin/users/update.js.haml_spec.rb +0 -37
- data/spec/views/application/auto_complete.haml_spec.rb +0 -48
- data/spec/views/campaigns/_edit.haml_spec.rb +0 -44
- data/spec/views/campaigns/_new.haml_spec.rb +0 -41
- data/spec/views/campaigns/create.js.haml_spec.rb +0 -49
- data/spec/views/campaigns/destroy.js.haml_spec.rb +0 -31
- data/spec/views/campaigns/edit.js.haml_spec.rb +0 -66
- data/spec/views/campaigns/index.haml_spec.rb +0 -37
- data/spec/views/campaigns/index.js.haml_spec.rb +0 -34
- data/spec/views/campaigns/new.js.haml_spec.rb +0 -50
- data/spec/views/campaigns/show.haml_spec.rb +0 -38
- data/spec/views/campaigns/update.js.haml_spec.rb +0 -78
- data/spec/views/comments/edit.js.haml_spec.rb +0 -30
- data/spec/views/contacts/_edit.haml_spec.rb +0 -73
- data/spec/views/contacts/_new.haml_spec.rb +0 -52
- data/spec/views/contacts/create.js.haml_spec.rb +0 -65
- data/spec/views/contacts/destroy.js.haml_spec.rb +0 -45
- data/spec/views/contacts/edit.js.haml_spec.rb +0 -74
- data/spec/views/contacts/index.haml_spec.rb +0 -37
- data/spec/views/contacts/index.js.html_spec.rb +0 -34
- data/spec/views/contacts/new.js.haml_spec.rb +0 -47
- data/spec/views/contacts/show.haml_spec.rb +0 -35
- data/spec/views/contacts/update.js.haml_spec.rb +0 -128
- data/spec/views/home/index.haml_spec.rb +0 -36
- data/spec/views/home/index.js.haml_spec.rb +0 -33
- data/spec/views/home/options.js.haml_spec.rb +0 -53
- data/spec/views/leads/_convert.haml_spec.rb +0 -30
- data/spec/views/leads/_edit.haml_spec.rb +0 -47
- data/spec/views/leads/_new.haml_spec.rb +0 -45
- data/spec/views/leads/_sidebar_show.haml_spec.rb +0 -31
- data/spec/views/leads/convert.js.haml_spec.rb +0 -79
- data/spec/views/leads/create.js.haml_spec.rb +0 -67
- data/spec/views/leads/destroy.js.haml_spec.rb +0 -47
- data/spec/views/leads/edit.js.haml_spec.rb +0 -76
- data/spec/views/leads/index.haml_spec.rb +0 -37
- data/spec/views/leads/index.js.haml_spec.rb +0 -34
- data/spec/views/leads/new.js.haml_spec.rb +0 -47
- data/spec/views/leads/promote.js.haml_spec.rb +0 -135
- data/spec/views/leads/reject.js.haml_spec.rb +0 -45
- data/spec/views/leads/show.haml_spec.rb +0 -32
- data/spec/views/leads/update.js.haml_spec.rb +0 -118
- data/spec/views/opportunities/_edit.haml_spec.rb +0 -70
- data/spec/views/opportunities/_new.haml_spec.rb +0 -51
- data/spec/views/opportunities/create.js.haml_spec.rb +0 -86
- data/spec/views/opportunities/destroy.js.haml_spec.rb +0 -64
- data/spec/views/opportunities/edit.js.haml_spec.rb +0 -75
- data/spec/views/opportunities/index.haml_spec.rb +0 -38
- data/spec/views/opportunities/index.js.haml_spec.rb +0 -35
- data/spec/views/opportunities/new.js.haml_spec.rb +0 -54
- data/spec/views/opportunities/show.haml_spec.rb +0 -35
- data/spec/views/opportunities/update.js.haml_spec.rb +0 -143
- data/spec/views/tasks/_edit.haml_spec.rb +0 -50
- data/spec/views/tasks/complete.js.haml_spec.rb +0 -67
- data/spec/views/tasks/create.js.haml_spec.rb +0 -119
- data/spec/views/tasks/destroy.js.haml_spec.rb +0 -57
- data/spec/views/tasks/edit.js.haml_spec.rb +0 -76
- data/spec/views/tasks/index.haml_spec.rb +0 -46
- data/spec/views/tasks/new.js.haml_spec.rb +0 -49
- data/spec/views/tasks/uncomplete.js.haml_spec.rb +0 -45
- data/spec/views/tasks/update.js.haml_spec.rb +0 -140
- data/spec/views/users/avatar.js.haml_spec.rb +0 -35
- data/spec/views/users/change_password.js.haml_spec.rb +0 -51
- data/spec/views/users/edit.js.haml_spec.rb +0 -35
- data/spec/views/users/password.js.haml_spec.rb +0 -36
- data/spec/views/users/update.js.haml_spec.rb +0 -46
- data/spec/views/users/upload_avatar.js.haml_spec.rb +0 -45
- data/vendor/gems/globby-0.1.2/LICENSE.txt +0 -20
- data/vendor/gems/globby-0.1.2/README.md +0 -65
- data/vendor/gems/globby-0.1.2/Rakefile +0 -9
- data/vendor/gems/globby-0.1.2/lib/globby/glob.rb +0 -90
- data/vendor/gems/globby-0.1.2/lib/globby/globject.rb +0 -18
- data/vendor/gems/globby-0.1.2/lib/globby/result.rb +0 -20
- data/vendor/gems/globby-0.1.2/lib/globby.rb +0 -47
- data/vendor/gems/globby-0.1.2/spec/gitignore_spec.rb +0 -109
- data/vendor/gems/globby-0.1.2/spec/globby_spec.rb +0 -93
- data/zeus.json +0 -22
- /data/{spec/fixtures/rails.png → public/avatars/User/2/original_rails.png} +0 -0
@@ -1,705 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (c) 2008-2013 Michael Dvorkin and contributors.
|
4
|
-
#
|
5
|
-
# Fat Free CRM is freely distributable under the terms of MIT license.
|
6
|
-
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
7
|
-
#------------------------------------------------------------------------------
|
8
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
9
|
-
|
10
|
-
describe ContactsController do
|
11
|
-
before(:each) do
|
12
|
-
login
|
13
|
-
set_current_tab(:contacts)
|
14
|
-
end
|
15
|
-
|
16
|
-
# GET /contacts
|
17
|
-
# GET /contacts.xml
|
18
|
-
#----------------------------------------------------------------------------
|
19
|
-
describe "responding to GET index" do
|
20
|
-
it "should expose all contacts as @contacts and render [index] template" do
|
21
|
-
@contacts = [create(:contact, user: current_user)]
|
22
|
-
get :index
|
23
|
-
expect(assigns[:contacts].count).to eq(@contacts.count)
|
24
|
-
expect(assigns[:contacts]).to eq(@contacts)
|
25
|
-
expect(response).to render_template("contacts/index")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should perform lookup using query string" do
|
29
|
-
@billy_bones = create(:contact, user: current_user, first_name: "Billy", last_name: "Bones")
|
30
|
-
@captain_flint = create(:contact, user: current_user, first_name: "Captain", last_name: "Flint")
|
31
|
-
|
32
|
-
get :index, params: { query: @billy_bones.email }
|
33
|
-
expect(assigns[:contacts]).to eq([@billy_bones])
|
34
|
-
expect(assigns[:current_query]).to eq(@billy_bones.email)
|
35
|
-
expect(session[:contacts_current_query]).to eq(@billy_bones.email)
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "AJAX pagination" do
|
39
|
-
it "should pick up page number from params" do
|
40
|
-
@contacts = [create(:contact, user: current_user)]
|
41
|
-
get :index, params: { page: 42 }, xhr: true
|
42
|
-
|
43
|
-
expect(assigns[:current_page].to_i).to eq(42)
|
44
|
-
expect(assigns[:contacts]).to eq([]) # page #42 should be empty if there's only one contact ;-)
|
45
|
-
expect(session[:contacts_current_page].to_i).to eq(42)
|
46
|
-
expect(response).to render_template("contacts/index")
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should pick up saved page number from session" do
|
50
|
-
session[:contacts_current_page] = 42
|
51
|
-
@contacts = [create(:contact, user: current_user)]
|
52
|
-
get :index, xhr: true
|
53
|
-
|
54
|
-
expect(assigns[:current_page]).to eq(42)
|
55
|
-
expect(assigns[:contacts]).to eq([])
|
56
|
-
expect(response).to render_template("contacts/index")
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should reset current_page when query is altered" do
|
60
|
-
session[:contacts_current_page] = 42
|
61
|
-
session[:contacts_current_query] = "bill"
|
62
|
-
@contacts = [create(:contact, user: current_user)]
|
63
|
-
get :index, xhr: true
|
64
|
-
|
65
|
-
expect(assigns[:current_page]).to eq(1)
|
66
|
-
expect(assigns[:contacts]).to eq(@contacts)
|
67
|
-
expect(response).to render_template("contacts/index")
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "with mime type of JSON" do
|
72
|
-
it "should render all contacts as JSON" do
|
73
|
-
expect(@controller).to receive(:get_contacts).and_return(contacts = double("Array of Contacts"))
|
74
|
-
expect(contacts).to receive(:to_json).and_return("generated JSON")
|
75
|
-
|
76
|
-
request.env["HTTP_ACCEPT"] = "application/json"
|
77
|
-
get :index
|
78
|
-
expect(response.body).to eq("generated JSON")
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "with mime type of XML" do
|
83
|
-
it "should render all contacts as xml" do
|
84
|
-
expect(@controller).to receive(:get_contacts).and_return(contacts = double("Array of Contacts"))
|
85
|
-
expect(contacts).to receive(:to_xml).and_return("generated XML")
|
86
|
-
|
87
|
-
request.env["HTTP_ACCEPT"] = "application/xml"
|
88
|
-
get :index
|
89
|
-
expect(response.body).to eq("generated XML")
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
# GET /contacts/1
|
95
|
-
# GET /contacts/1.xml HTML
|
96
|
-
#----------------------------------------------------------------------------
|
97
|
-
describe "responding to GET show" do
|
98
|
-
describe "with mime type of HTML" do
|
99
|
-
before(:each) do
|
100
|
-
@contact = create(:contact, id: 42)
|
101
|
-
@stage = Setting.unroll(:opportunity_stage)
|
102
|
-
@comment = Comment.new
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should expose the requested contact as @contact" do
|
106
|
-
get :show, params: { id: 42 }
|
107
|
-
expect(assigns[:contact]).to eq(@contact)
|
108
|
-
expect(assigns[:stage]).to eq(@stage)
|
109
|
-
expect(assigns[:comment].attributes).to eq(@comment.attributes)
|
110
|
-
expect(response).to render_template("contacts/show")
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should update an activity when viewing the contact" do
|
114
|
-
get :show, params: { id: @contact.id }
|
115
|
-
expect(@contact.versions.last.event).to eq('view')
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
describe "with mime type of JSON" do
|
120
|
-
it "should render the requested contact as JSON" do
|
121
|
-
@contact = create(:contact, id: 42)
|
122
|
-
expect(Contact).to receive(:find).and_return(@contact)
|
123
|
-
expect(@contact).to receive(:to_json).and_return("generated JSON")
|
124
|
-
|
125
|
-
request.env["HTTP_ACCEPT"] = "application/json"
|
126
|
-
get :show, params: { id: 42 }
|
127
|
-
expect(response.body).to eq("generated JSON")
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "with mime type of XML" do
|
132
|
-
it "should render the requested contact as xml" do
|
133
|
-
@contact = create(:contact, id: 42)
|
134
|
-
expect(Contact).to receive(:find).and_return(@contact)
|
135
|
-
expect(@contact).to receive(:to_xml).and_return("generated XML")
|
136
|
-
|
137
|
-
request.env["HTTP_ACCEPT"] = "application/xml"
|
138
|
-
get :show, params: { id: 42 }
|
139
|
-
expect(response.body).to eq("generated XML")
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "contact got deleted or otherwise unavailable" do
|
144
|
-
it "should redirect to contact index if the contact got deleted" do
|
145
|
-
@contact = create(:contact, user: current_user)
|
146
|
-
@contact.destroy
|
147
|
-
|
148
|
-
get :show, params: { id: @contact.id }
|
149
|
-
expect(flash[:warning]).not_to eq(nil)
|
150
|
-
expect(response).to redirect_to(contacts_path)
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should redirect to contact index if the contact is protected" do
|
154
|
-
@private = create(:contact, user: create(:user), access: "Private")
|
155
|
-
|
156
|
-
get :show, params: { id: @private.id }
|
157
|
-
expect(flash[:warning]).not_to eq(nil)
|
158
|
-
expect(response).to redirect_to(contacts_path)
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should return 404 (Not Found) XML error" do
|
162
|
-
@contact = create(:contact, user: current_user)
|
163
|
-
@contact.destroy
|
164
|
-
request.env["HTTP_ACCEPT"] = "application/xml"
|
165
|
-
|
166
|
-
get :show, params: { id: @contact.id }
|
167
|
-
expect(response.code).to eq("404") # :not_found
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
# GET /contacts/new
|
173
|
-
# GET /contacts/new.xml AJAX
|
174
|
-
#----------------------------------------------------------------------------
|
175
|
-
describe "responding to GET new" do
|
176
|
-
it "should expose a new contact as @contact and render [new] template" do
|
177
|
-
@contact = Contact.new(user: current_user,
|
178
|
-
access: Setting.default_access)
|
179
|
-
@account = Account.new(user: current_user)
|
180
|
-
@accounts = [create(:account, user: current_user)]
|
181
|
-
|
182
|
-
get :new, xhr: true
|
183
|
-
expect(assigns[:contact].attributes).to eq(@contact.attributes)
|
184
|
-
expect(assigns[:account].attributes).to eq(@account.attributes)
|
185
|
-
expect(assigns[:accounts]).to eq(@accounts)
|
186
|
-
expect(assigns[:opportunity]).to eq(nil)
|
187
|
-
expect(response).to render_template("contacts/new")
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should created an instance of related object when necessary" do
|
191
|
-
@opportunity = create(:opportunity)
|
192
|
-
|
193
|
-
get :new, params: { related: "opportunity_#{@opportunity.id}" }, xhr: true
|
194
|
-
expect(assigns[:opportunity]).to eq(@opportunity)
|
195
|
-
end
|
196
|
-
|
197
|
-
describe "(when creating related contact)" do
|
198
|
-
it "should redirect to parent asset's index page with the message if parent asset got deleted" do
|
199
|
-
@account = create(:account)
|
200
|
-
@account.destroy
|
201
|
-
|
202
|
-
get :new, params: { related: "account_#{@account.id}" }, xhr: true
|
203
|
-
expect(flash[:warning]).not_to eq(nil)
|
204
|
-
expect(response.body).to eq('window.location.href = "/accounts";')
|
205
|
-
end
|
206
|
-
|
207
|
-
it "should redirect to parent asset's index page with the message if parent asset got protected" do
|
208
|
-
@account = create(:account, access: "Private")
|
209
|
-
|
210
|
-
get :new, params: { related: "account_#{@account.id}" }, xhr: true
|
211
|
-
expect(flash[:warning]).not_to eq(nil)
|
212
|
-
expect(response.body).to eq('window.location.href = "/accounts";')
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
# GET /contacts/field_group AJAX
|
218
|
-
#----------------------------------------------------------------------------
|
219
|
-
describe "responding to GET field_group" do
|
220
|
-
context "with an existing tag" do
|
221
|
-
before :each do
|
222
|
-
@tag = create(:tag)
|
223
|
-
end
|
224
|
-
|
225
|
-
it "should return with an existing tag name" do
|
226
|
-
get :field_group, params: { tag: @tag.name }, xhr: true
|
227
|
-
assigns[:tag].name == @tag.name
|
228
|
-
end
|
229
|
-
|
230
|
-
it "should have the same count of tags" do
|
231
|
-
get :field_group, params: { tag: @tag.name }, xhr: true
|
232
|
-
expect(Tag.count).to equal(1)
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
context "without an existing tag" do
|
237
|
-
it "should not find a tag" do
|
238
|
-
tag_name = "New-Tag"
|
239
|
-
get :field_group, params: { tag: tag_name }, xhr: true
|
240
|
-
expect(assigns[:tag]).to eql(nil)
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should have the same count of tags" do
|
244
|
-
tag_name = "New-Tag-1"
|
245
|
-
get :field_group, params: { tag: tag_name }, xhr: true
|
246
|
-
expect(Tag.count).to equal(0)
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
# GET /contacts/1/edit AJAX
|
252
|
-
#----------------------------------------------------------------------------
|
253
|
-
describe "responding to GET edit" do
|
254
|
-
it "should expose the requested contact as @contact and render [edit] template" do
|
255
|
-
@contact = create(:contact, id: 42, user: current_user, lead: nil)
|
256
|
-
@account = Account.new(user: current_user)
|
257
|
-
|
258
|
-
get :edit, params: { id: 42 }, xhr: true
|
259
|
-
expect(assigns[:contact]).to eq(@contact)
|
260
|
-
expect(assigns[:account].attributes).to eq(@account.attributes)
|
261
|
-
expect(assigns[:previous]).to eq(nil)
|
262
|
-
expect(response).to render_template("contacts/edit")
|
263
|
-
end
|
264
|
-
|
265
|
-
it "should expose the requested contact as @contact and linked account as @account" do
|
266
|
-
@account = create(:account, id: 99)
|
267
|
-
@contact = create(:contact, id: 42, user: current_user, lead: nil)
|
268
|
-
create(:account_contact, account: @account, contact: @contact)
|
269
|
-
|
270
|
-
get :edit, params: { id: 42 }, xhr: true
|
271
|
-
expect(assigns[:contact]).to eq(@contact)
|
272
|
-
expect(assigns[:account]).to eq(@account)
|
273
|
-
end
|
274
|
-
|
275
|
-
it "should expose previous contact as @previous when necessary" do
|
276
|
-
@contact = create(:contact, id: 42)
|
277
|
-
@previous = create(:contact, id: 1992)
|
278
|
-
|
279
|
-
get :edit, params: { id: 42, previous: 1992 }, xhr: true
|
280
|
-
expect(assigns[:previous]).to eq(@previous)
|
281
|
-
end
|
282
|
-
|
283
|
-
describe "(contact got deleted or is otherwise unavailable)" do
|
284
|
-
it "should reload current page with the flash message if the contact got deleted" do
|
285
|
-
@contact = create(:contact, user: current_user)
|
286
|
-
@contact.destroy
|
287
|
-
|
288
|
-
get :edit, params: { id: @contact.id }, xhr: true
|
289
|
-
expect(flash[:warning]).not_to eq(nil)
|
290
|
-
expect(response.body).to eq("window.location.reload();")
|
291
|
-
end
|
292
|
-
|
293
|
-
it "should reload current page with the flash message if the contact is protected" do
|
294
|
-
@private = create(:contact, user: create(:user), access: "Private")
|
295
|
-
|
296
|
-
get :edit, params: { id: @private.id }, xhr: true
|
297
|
-
expect(flash[:warning]).not_to eq(nil)
|
298
|
-
expect(response.body).to eq("window.location.reload();")
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
describe "(previous contact got deleted or is otherwise unavailable)" do
|
303
|
-
before(:each) do
|
304
|
-
@contact = create(:contact, user: current_user)
|
305
|
-
@previous = create(:contact, user: create(:user))
|
306
|
-
end
|
307
|
-
|
308
|
-
it "should notify the view if previous contact got deleted" do
|
309
|
-
@previous.destroy
|
310
|
-
|
311
|
-
get :edit, params: { id: @contact.id, previous: @previous.id }, xhr: true
|
312
|
-
expect(flash[:warning]).to eq(nil)
|
313
|
-
expect(assigns[:previous]).to eq(@previous.id)
|
314
|
-
expect(response).to render_template("contacts/edit")
|
315
|
-
end
|
316
|
-
|
317
|
-
it "should notify the view if previous contact got protected" do
|
318
|
-
@previous.update_attribute(:access, "Private")
|
319
|
-
|
320
|
-
get :edit, params: { id: @contact.id, previous: @previous.id }, xhr: true
|
321
|
-
expect(flash[:warning]).to eq(nil)
|
322
|
-
expect(assigns[:previous]).to eq(@previous.id)
|
323
|
-
expect(response).to render_template("contacts/edit")
|
324
|
-
end
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
# POST /contacts
|
329
|
-
# POST /contacts.xml AJAX
|
330
|
-
#----------------------------------------------------------------------------
|
331
|
-
describe "responding to POST create" do
|
332
|
-
describe "with valid params" do
|
333
|
-
it "should expose a newly created contact as @contact and render [create] template" do
|
334
|
-
@contact = build(:contact, first_name: "Billy", last_name: "Bones")
|
335
|
-
allow(Contact).to receive(:new).and_return(@contact)
|
336
|
-
|
337
|
-
post :create, params: { contact: { first_name: "Billy", last_name: "Bones" }, account: { id: "", name: "Hello world" } }, xhr: true
|
338
|
-
expect(assigns(:contact)).to eq(@contact)
|
339
|
-
expect(assigns(:contact).reload.account.name).to eq("Hello world")
|
340
|
-
expect(assigns(:contact).account.user).to eq(assigns(:contact).user)
|
341
|
-
expect(response).to render_template("contacts/create")
|
342
|
-
end
|
343
|
-
|
344
|
-
it "should be able to associate newly created contact with the opportunity" do
|
345
|
-
@opportunity = create(:opportunity, id: 987)
|
346
|
-
@contact = build(:contact)
|
347
|
-
allow(Contact).to receive(:new).and_return(@contact)
|
348
|
-
|
349
|
-
post :create, params: { contact: { first_name: "Billy" }, account: {}, opportunity: 987 }, xhr: true
|
350
|
-
expect(assigns(:contact).opportunities).to include(@opportunity)
|
351
|
-
expect(response).to render_template("contacts/create")
|
352
|
-
end
|
353
|
-
|
354
|
-
it "should reload contacts to update pagination if called from contacts index" do
|
355
|
-
@contact = build(:contact, user: current_user)
|
356
|
-
allow(Contact).to receive(:new).and_return(@contact)
|
357
|
-
|
358
|
-
request.env["HTTP_REFERER"] = "http://localhost/contacts"
|
359
|
-
post :create, params: { contact: { first_name: "Billy", last_name: "Bones" }, account: {} }, xhr: true
|
360
|
-
expect(assigns[:contacts]).to eq([@contact])
|
361
|
-
end
|
362
|
-
|
363
|
-
it "should add a new comment to the newly created contact when specified" do
|
364
|
-
@contact = build(:contact, user: current_user)
|
365
|
-
allow(Contact).to receive(:new).and_return(@contact)
|
366
|
-
|
367
|
-
post :create, params: { contact: { first_name: "Testy", last_name: "McTest" }, account: { name: "Hello world" }, comment_body: "Awesome comment is awesome" }, xhr: true
|
368
|
-
expect(assigns[:contact].comments.map(&:comment)).to include("Awesome comment is awesome")
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
describe "with invalid params" do
|
373
|
-
before(:each) do
|
374
|
-
@contact = build(:contact, first_name: nil, user: current_user, lead: nil)
|
375
|
-
allow(Contact).to receive(:new).and_return(@contact)
|
376
|
-
end
|
377
|
-
|
378
|
-
# Redraw [create] form with selected account.
|
379
|
-
it "should redraw [Create Contact] form with selected account" do
|
380
|
-
@account = create(:account, id: 42, user: current_user)
|
381
|
-
|
382
|
-
# This redraws [create] form with blank account.
|
383
|
-
post :create, params: { contact: {}, account: { id: 42, user_id: current_user.id } }, xhr: true
|
384
|
-
expect(assigns(:contact)).to eq(@contact)
|
385
|
-
expect(assigns(:account)).to eq(@account)
|
386
|
-
expect(assigns(:accounts)).to eq([@account])
|
387
|
-
expect(response).to render_template("contacts/create")
|
388
|
-
end
|
389
|
-
|
390
|
-
# Redraw [create] form with related account.
|
391
|
-
it "should redraw [Create Contact] form with related account" do
|
392
|
-
@account = create(:account, id: 123, user: current_user)
|
393
|
-
|
394
|
-
request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
|
395
|
-
post :create, params: { contact: { first_name: nil }, account: { name: nil, user_id: current_user.id } }, xhr: true
|
396
|
-
expect(assigns(:contact)).to eq(@contact)
|
397
|
-
expect(assigns(:account)).to eq(@account)
|
398
|
-
expect(assigns(:accounts)).to eq([@account])
|
399
|
-
expect(response).to render_template("contacts/create")
|
400
|
-
end
|
401
|
-
|
402
|
-
it "should redraw [Create Contact] form with blank account" do
|
403
|
-
@accounts = [create(:account, user: current_user)]
|
404
|
-
@account = Account.new(user: current_user)
|
405
|
-
|
406
|
-
post :create, params: { contact: { first_name: nil }, account: { name: nil, user_id: current_user.id } }, xhr: true
|
407
|
-
expect(assigns(:contact)).to eq(@contact)
|
408
|
-
expect(assigns(:account).attributes).to eq(@account.attributes)
|
409
|
-
expect(assigns(:accounts)).to eq(@accounts)
|
410
|
-
expect(response).to render_template("contacts/create")
|
411
|
-
end
|
412
|
-
|
413
|
-
it "should preserve Opportunity when called from Oppotuunity page" do
|
414
|
-
@opportunity = create(:opportunity, id: 987)
|
415
|
-
|
416
|
-
post :create, params: { contact: {}, account: {}, opportunity: 987 }, xhr: true
|
417
|
-
expect(assigns(:opportunity)).to eq(@opportunity)
|
418
|
-
expect(response).to render_template("contacts/create")
|
419
|
-
end
|
420
|
-
end
|
421
|
-
end
|
422
|
-
|
423
|
-
# PUT /contacts/1
|
424
|
-
# PUT /contacts/1.xml AJAX
|
425
|
-
#----------------------------------------------------------------------------
|
426
|
-
describe "responding to PUT update" do
|
427
|
-
describe "with valid params" do
|
428
|
-
it "should update the requested contact and render [update] template" do
|
429
|
-
@contact = create(:contact, id: 42, first_name: "Billy")
|
430
|
-
|
431
|
-
put :update, params: { id: 42, contact: { first_name: "Bones" }, account: {} }, xhr: true
|
432
|
-
expect(assigns[:contact].first_name).to eq("Bones")
|
433
|
-
expect(assigns[:contact]).to eq(@contact)
|
434
|
-
expect(response).to render_template("contacts/update")
|
435
|
-
end
|
436
|
-
|
437
|
-
it "should be able to create a new account and link it to the contact" do
|
438
|
-
@contact = create(:contact, id: 42, first_name: "Billy")
|
439
|
-
|
440
|
-
put :update, params: { id: 42, contact: { first_name: "Bones" }, account: { name: "new account" } }, xhr: true
|
441
|
-
expect(assigns[:contact].first_name).to eq("Bones")
|
442
|
-
expect(assigns[:contact].account.name).to eq("new account")
|
443
|
-
end
|
444
|
-
|
445
|
-
it "should be able to link existing account with the contact" do
|
446
|
-
@account = create(:account, id: 99, name: "Hello world")
|
447
|
-
@contact = create(:contact, id: 42, first_name: "Billy")
|
448
|
-
|
449
|
-
put :update, params: { id: 42, contact: { first_name: "Bones" }, account: { id: 99 } }, xhr: true
|
450
|
-
expect(assigns[:contact].first_name).to eq("Bones")
|
451
|
-
expect(assigns[:contact].account.id).to eq(99)
|
452
|
-
end
|
453
|
-
|
454
|
-
it "should update contact permissions when sharing with specific users" do
|
455
|
-
@contact = create(:contact, id: 42, access: "Public")
|
456
|
-
|
457
|
-
put :update, params: { id: 42, contact: { first_name: "Hello", access: "Shared", user_ids: [7, 8] }, account: {} }, xhr: true
|
458
|
-
expect(assigns[:contact].access).to eq("Shared")
|
459
|
-
expect(assigns[:contact].user_ids.sort).to eq([7, 8])
|
460
|
-
expect(assigns[:contact]).to eq(@contact)
|
461
|
-
end
|
462
|
-
|
463
|
-
describe "contact got deleted or otherwise unavailable" do
|
464
|
-
it "should reload current page is the contact got deleted" do
|
465
|
-
@contact = create(:contact, user: current_user)
|
466
|
-
@contact.destroy
|
467
|
-
|
468
|
-
put :update, params: { id: @contact.id }, xhr: true
|
469
|
-
expect(flash[:warning]).not_to eq(nil)
|
470
|
-
expect(response.body).to eq("window.location.reload();")
|
471
|
-
end
|
472
|
-
|
473
|
-
it "should reload current page with the flash message if the contact is protected" do
|
474
|
-
@private = create(:contact, user: create(:user), access: "Private")
|
475
|
-
|
476
|
-
put :update, params: { id: @private.id }, xhr: true
|
477
|
-
expect(flash[:warning]).not_to eq(nil)
|
478
|
-
expect(response.body).to eq("window.location.reload();")
|
479
|
-
end
|
480
|
-
end
|
481
|
-
end
|
482
|
-
|
483
|
-
describe "with invalid params" do
|
484
|
-
it "should not update the contact, but still expose it as @contact and render [update] template" do
|
485
|
-
@contact = create(:contact, id: 42, user: current_user, first_name: "Billy", lead: nil)
|
486
|
-
|
487
|
-
put :update, params: { id: 42, contact: { first_name: nil }, account: {} }, xhr: true
|
488
|
-
expect(assigns[:contact].reload.first_name).to eq("Billy")
|
489
|
-
expect(assigns[:contact]).to eq(@contact)
|
490
|
-
expect(response).to render_template("contacts/update")
|
491
|
-
end
|
492
|
-
|
493
|
-
it "should expose existing account as @account if selected" do
|
494
|
-
@account = create(:account, id: 99)
|
495
|
-
@contact = create(:contact, id: 42, account: @account)
|
496
|
-
|
497
|
-
put :update, params: { id: 42, contact: { first_name: nil }, account: { id: 99 } }, xhr: true
|
498
|
-
expect(assigns[:account]).to eq(@account)
|
499
|
-
end
|
500
|
-
end
|
501
|
-
end
|
502
|
-
|
503
|
-
# DELETE /contacts/1
|
504
|
-
# DELETE /contacts/1.xml AJAX
|
505
|
-
#----------------------------------------------------------------------------
|
506
|
-
describe "responding to DELETE destroy" do
|
507
|
-
before(:each) do
|
508
|
-
@contact = create(:contact, user: current_user)
|
509
|
-
end
|
510
|
-
|
511
|
-
describe "AJAX request" do
|
512
|
-
it "should destroy the requested contact and render [destroy] template" do
|
513
|
-
delete :destroy, params: { id: @contact.id }, xhr: true
|
514
|
-
|
515
|
-
expect { Contact.find(@contact.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
516
|
-
expect(response).to render_template("contacts/destroy")
|
517
|
-
end
|
518
|
-
|
519
|
-
describe "when called from Contacts index page" do
|
520
|
-
before(:each) do
|
521
|
-
request.env["HTTP_REFERER"] = "http://localhost/contacts"
|
522
|
-
end
|
523
|
-
|
524
|
-
it "should try previous page and render index action if current page has no contacts" do
|
525
|
-
session[:contacts_current_page] = 42
|
526
|
-
delete :destroy, params: { id: @contact.id }, xhr: true
|
527
|
-
|
528
|
-
expect(session[:contacts_current_page]).to eq(41)
|
529
|
-
expect(response).to render_template("contacts/index")
|
530
|
-
end
|
531
|
-
|
532
|
-
it "should render index action when deleting last contact" do
|
533
|
-
session[:contacts_current_page] = 1
|
534
|
-
delete :destroy, params: { id: @contact.id }, xhr: true
|
535
|
-
|
536
|
-
expect(session[:contacts_current_page]).to eq(1)
|
537
|
-
expect(response).to render_template("contacts/index")
|
538
|
-
end
|
539
|
-
end
|
540
|
-
|
541
|
-
describe "when called from related asset page page" do
|
542
|
-
it "should reset current page to 1" do
|
543
|
-
request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
|
544
|
-
delete :destroy, params: { id: @contact.id }, xhr: true
|
545
|
-
|
546
|
-
expect(session[:contacts_current_page]).to eq(1)
|
547
|
-
expect(response).to render_template("contacts/destroy")
|
548
|
-
end
|
549
|
-
end
|
550
|
-
|
551
|
-
describe "contact got deleted or otherwise unavailable" do
|
552
|
-
it "should reload current page is the contact got deleted" do
|
553
|
-
@contact = create(:contact, user: current_user)
|
554
|
-
@contact.destroy
|
555
|
-
|
556
|
-
delete :destroy, params: { id: @contact.id }, xhr: true
|
557
|
-
expect(flash[:warning]).not_to eq(nil)
|
558
|
-
expect(response.body).to eq("window.location.reload();")
|
559
|
-
end
|
560
|
-
|
561
|
-
it "should reload current page with the flash message if the contact is protected" do
|
562
|
-
@private = create(:contact, user: create(:user), access: "Private")
|
563
|
-
|
564
|
-
delete :destroy, params: { id: @private.id }, xhr: true
|
565
|
-
expect(flash[:warning]).not_to eq(nil)
|
566
|
-
expect(response.body).to eq("window.location.reload();")
|
567
|
-
end
|
568
|
-
end
|
569
|
-
end
|
570
|
-
|
571
|
-
describe "HTML request" do
|
572
|
-
it "should redirect to Contacts index when a contact gets deleted from its landing page" do
|
573
|
-
delete :destroy, params: { id: @contact.id }
|
574
|
-
|
575
|
-
expect(flash[:notice]).not_to eq(nil)
|
576
|
-
expect(response).to redirect_to(contacts_path)
|
577
|
-
end
|
578
|
-
|
579
|
-
it "should redirect to contact index with the flash message is the contact got deleted" do
|
580
|
-
@contact = create(:contact, user: current_user)
|
581
|
-
@contact.destroy
|
582
|
-
|
583
|
-
delete :destroy, params: { id: @contact.id }
|
584
|
-
expect(flash[:warning]).not_to eq(nil)
|
585
|
-
expect(response).to redirect_to(contacts_path)
|
586
|
-
end
|
587
|
-
|
588
|
-
it "should redirect to contact index with the flash message if the contact is protected" do
|
589
|
-
@private = create(:contact, user: create(:user), access: "Private")
|
590
|
-
|
591
|
-
delete :destroy, params: { id: @private.id }
|
592
|
-
expect(flash[:warning]).not_to eq(nil)
|
593
|
-
expect(response).to redirect_to(contacts_path)
|
594
|
-
end
|
595
|
-
end
|
596
|
-
end
|
597
|
-
|
598
|
-
# PUT /contacts/1/attach
|
599
|
-
# PUT /contacts/1/attach.xml AJAX
|
600
|
-
#----------------------------------------------------------------------------
|
601
|
-
describe "responding to PUT attach" do
|
602
|
-
describe "tasks" do
|
603
|
-
before do
|
604
|
-
@model = create(:contact)
|
605
|
-
@attachment = create(:task, asset: nil)
|
606
|
-
end
|
607
|
-
it_should_behave_like("attach")
|
608
|
-
end
|
609
|
-
|
610
|
-
describe "opportunities" do
|
611
|
-
before do
|
612
|
-
@model = create(:contact)
|
613
|
-
@attachment = create(:opportunity)
|
614
|
-
end
|
615
|
-
it_should_behave_like("attach")
|
616
|
-
end
|
617
|
-
end
|
618
|
-
|
619
|
-
# PUT /contacts/1/attach
|
620
|
-
# PUT /contacts/1/attach.xml AJAX
|
621
|
-
#----------------------------------------------------------------------------
|
622
|
-
describe "responding to PUT attach" do
|
623
|
-
describe "tasks" do
|
624
|
-
before do
|
625
|
-
@model = create(:contact)
|
626
|
-
@attachment = create(:task, asset: nil)
|
627
|
-
end
|
628
|
-
it_should_behave_like("attach")
|
629
|
-
end
|
630
|
-
|
631
|
-
describe "opportunities" do
|
632
|
-
before do
|
633
|
-
@model = create(:contact)
|
634
|
-
@attachment = create(:opportunity)
|
635
|
-
end
|
636
|
-
it_should_behave_like("attach")
|
637
|
-
end
|
638
|
-
end
|
639
|
-
|
640
|
-
# POST /contacts/1/discard
|
641
|
-
# POST /contacts/1/discard.xml AJAX
|
642
|
-
#----------------------------------------------------------------------------
|
643
|
-
describe "responding to POST discard" do
|
644
|
-
describe "tasks" do
|
645
|
-
before do
|
646
|
-
@model = create(:contact)
|
647
|
-
@attachment = create(:task, asset: @model)
|
648
|
-
end
|
649
|
-
it_should_behave_like("discard")
|
650
|
-
end
|
651
|
-
|
652
|
-
describe "opportunities" do
|
653
|
-
before do
|
654
|
-
@attachment = create(:opportunity)
|
655
|
-
@model = create(:contact)
|
656
|
-
@model.opportunities << @attachment
|
657
|
-
end
|
658
|
-
it_should_behave_like("discard")
|
659
|
-
end
|
660
|
-
end
|
661
|
-
|
662
|
-
# POST /contacts/auto_complete/query AJAX
|
663
|
-
#----------------------------------------------------------------------------
|
664
|
-
describe "responding to POST auto_complete" do
|
665
|
-
before(:each) do
|
666
|
-
@auto_complete_matches = [create(:contact, first_name: "Hello", last_name: "World", user: current_user)]
|
667
|
-
end
|
668
|
-
|
669
|
-
it_should_behave_like("auto complete")
|
670
|
-
end
|
671
|
-
|
672
|
-
# GET /contacts/redraw AJAX
|
673
|
-
#----------------------------------------------------------------------------
|
674
|
-
describe "responding to POST redraw" do
|
675
|
-
it "should save user selected contact preference" do
|
676
|
-
get :redraw, params: { per_page: 42, view: "long", sort_by: "first_name", naming: "after" }, xhr: true
|
677
|
-
expect(current_user.preference[:contacts_per_page].to_i).to eq(42)
|
678
|
-
expect(current_user.preference[:contacts_index_view]).to eq("long")
|
679
|
-
expect(current_user.preference[:contacts_sort_by]).to eq("contacts.first_name ASC")
|
680
|
-
expect(current_user.preference[:contacts_naming]).to eq("after")
|
681
|
-
end
|
682
|
-
|
683
|
-
it "should set similar options for Leads" do
|
684
|
-
get :redraw, params: { sort_by: "first_name", naming: "after" }, xhr: true
|
685
|
-
expect(current_user.pref[:leads_sort_by]).to eq("leads.first_name ASC")
|
686
|
-
expect(current_user.pref[:leads_naming]).to eq("after")
|
687
|
-
end
|
688
|
-
|
689
|
-
it "should reset current page to 1" do
|
690
|
-
get :redraw, params: { per_page: 42, view: "long", sort_by: "first_name", naming: "after" }, xhr: true
|
691
|
-
expect(session[:contacts_current_page]).to eq(1)
|
692
|
-
end
|
693
|
-
|
694
|
-
it "should select @contacts and render [index] template" do
|
695
|
-
@contacts = [
|
696
|
-
create(:contact, first_name: "Alice", user: current_user),
|
697
|
-
create(:contact, first_name: "Bobby", user: current_user)
|
698
|
-
]
|
699
|
-
|
700
|
-
get :redraw, params: { per_page: 1, sort_by: "first_name" }, xhr: true
|
701
|
-
expect(assigns(:contacts)).to eq([@contacts.first])
|
702
|
-
expect(response).to render_template("contacts/index")
|
703
|
-
end
|
704
|
-
end
|
705
|
-
end
|