fat_free_crm 0.17.3 → 0.19.2
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/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +71 -148
- data/.travis.yml +35 -14
- data/CHANGELOG.md +92 -6
- data/CONTRIBUTORS.md +96 -53
- data/Dockerfile +45 -14
- data/Gemfile +23 -13
- data/Gemfile.lock +256 -248
- data/Procfile +1 -1
- data/README.md +9 -6
- data/Rakefile +1 -1
- data/app/assets/javascripts/crm.js.coffee +3 -3
- data/app/assets/javascripts/crm_select2.js.coffee +15 -14
- data/app/assets/stylesheets/common.scss +1 -1
- data/app/controllers/admin/application_controller.rb +1 -1
- data/app/controllers/admin/field_groups_controller.rb +9 -4
- data/app/controllers/admin/fields_controller.rb +4 -4
- data/app/controllers/admin/groups_controller.rb +1 -1
- data/app/controllers/admin/tags_controller.rb +2 -4
- data/app/controllers/admin/users_controller.rb +5 -8
- data/app/controllers/application_controller.rb +22 -45
- data/app/controllers/comments_controller.rb +16 -11
- data/{config/initializers/authlogic.rb → app/controllers/confirmations_controller.rb} +4 -2
- data/app/controllers/emails_controller.rb +0 -2
- data/app/controllers/entities/accounts_controller.rb +1 -3
- data/app/controllers/entities/campaigns_controller.rb +8 -5
- data/app/controllers/entities/contacts_controller.rb +4 -24
- data/app/controllers/entities/leads_controller.rb +16 -12
- data/app/controllers/entities/opportunities_controller.rb +17 -16
- data/app/controllers/entities_controller.rb +31 -12
- data/app/controllers/home_controller.rb +2 -4
- data/app/controllers/lists_controller.rb +5 -1
- data/app/controllers/passwords_controller.rb +3 -59
- data/{spec/features/support/maintain_sessions.rb → app/controllers/registrations_controller.rb} +12 -5
- data/{lib/development_tasks/gem.rake → app/controllers/sessions_controller.rb} +6 -6
- data/app/controllers/tasks_controller.rb +22 -17
- data/app/controllers/users_controller.rb +8 -29
- data/app/helpers/accounts_helper.rb +1 -1
- data/app/helpers/admin/users_helper.rb +1 -1
- data/app/helpers/application_helper.rb +28 -33
- data/app/helpers/campaigns_helper.rb +1 -1
- data/app/helpers/contacts_helper.rb +1 -3
- data/app/helpers/leads_helper.rb +1 -1
- data/app/helpers/opportunities_helper.rb +48 -3
- data/app/helpers/tasks_helper.rb +1 -1
- data/app/helpers/users_helper.rb +1 -3
- data/{config/initializers/paper_trail.rb → app/mailers/devise_mailer.rb} +5 -1
- data/app/mailers/user_mailer.rb +0 -9
- data/app/models/entities/account.rb +10 -10
- data/app/models/entities/campaign.rb +4 -6
- data/app/models/entities/contact.rb +24 -12
- data/app/models/entities/lead.rb +7 -14
- data/app/models/entities/opportunity.rb +10 -11
- data/app/models/fields/custom_field.rb +1 -0
- data/app/models/fields/custom_field_date_pair.rb +2 -0
- data/app/models/fields/field.rb +1 -3
- data/app/models/list.rb +1 -1
- data/app/models/observers/entity_observer.rb +3 -7
- data/app/models/observers/lead_observer.rb +2 -4
- data/app/models/observers/opportunity_observer.rb +5 -7
- data/app/models/observers/task_observer.rb +1 -1
- data/app/models/polymorphic/email.rb +2 -2
- data/app/models/polymorphic/task.rb +13 -9
- data/app/models/polymorphic/version.rb +3 -2
- data/app/models/setting.rb +2 -0
- data/app/models/users/ability.rb +3 -4
- data/app/models/users/permission.rb +3 -3
- data/app/models/users/preference.rb +2 -1
- data/app/models/users/user.rb +67 -42
- data/app/views/accounts/_top_section.html.haml +1 -1
- data/app/views/accounts/edit.js.haml +1 -1
- data/app/views/accounts/update.js.haml +2 -2
- data/app/views/admin/users/_user.html.haml +4 -4
- data/app/views/campaigns/_metrics.html.haml +3 -3
- data/app/views/contacts/_index_brief.html.haml +1 -1
- data/app/views/contacts/_index_full.html.haml +1 -1
- data/app/views/contacts/_index_long.html.haml +1 -1
- data/app/views/devise/confirmations/new.html.haml +9 -0
- data/app/views/devise/mailer/confirmation_instructions.html.haml +4 -0
- data/app/views/devise/mailer/password_change.html.haml +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.haml +6 -0
- data/app/views/devise/passwords/edit.html.haml +18 -0
- data/app/views/devise/passwords/new.html.haml +10 -0
- data/app/views/devise/registrations/new.html.haml +21 -0
- data/app/views/devise/sessions/new.html.haml +32 -0
- data/app/views/home/_opportunity.html.haml +4 -19
- data/app/views/layouts/_about.html.haml +5 -5
- data/app/views/layouts/_header.html.haml +3 -3
- data/app/views/layouts/admin/_header.html.haml +1 -1
- data/app/views/opportunities/_index_long.html.haml +1 -24
- data/app/views/opportunities/_sidebar_show.html.haml +3 -3
- data/app/views/opportunities/_top_section.html.haml +1 -1
- data/app/views/shared/_address.html.haml +5 -5
- data/app/views/shared/_empty.html.haml +1 -1
- data/app/views/shared/_paginate_with_per_page.html.haml +1 -0
- data/app/views/users/_avatar.html.haml +1 -1
- data/bin/bundle +1 -1
- data/bin/rails +1 -1
- data/bin/setup +38 -0
- data/bin/update +33 -0
- data/bin/yarn +13 -0
- data/config/application.rb +8 -6
- data/config/boot.rb +1 -1
- data/config/brakeman.ignore +2 -2
- data/config/database.postgres.docker.yml +5 -5
- data/config/environment.rb +1 -1
- data/config/environments/development.rb +1 -0
- data/config/environments/test.rb +7 -0
- data/config/initializers/action_mailer.rb +1 -3
- data/config/initializers/application_controller_renderer.rb +9 -0
- data/config/initializers/assets.rb +6 -11
- data/config/initializers/backtrace_silencers.rb +0 -6
- data/config/initializers/content_security_policy.rb +26 -0
- data/config/initializers/cookies_serializer.rb +3 -6
- data/config/initializers/devise.rb +289 -0
- data/config/initializers/filter_parameter_logging.rb +0 -5
- data/config/initializers/gravatar.rb +0 -1
- data/config/initializers/inflections.rb +0 -6
- data/config/initializers/mime_types.rb +1 -9
- data/config/initializers/new_framework_defaults_5_2.rb +40 -0
- data/config/initializers/relative_url_root.rb +1 -3
- data/config/initializers/session_store.rb +1 -3
- data/config/initializers/wrap_parameters.rb +4 -9
- data/config/locales/fat_free_crm.en-GB.yml +5 -5
- data/config/locales/fat_free_crm.en-US.yml +5 -5
- data/config/locales/fat_free_crm.fr.yml +1 -1
- data/config/locales/fat_free_crm.ru.yml +1 -0
- data/config/routes.rb +20 -9
- data/db/demo/users.yml +62 -81
- data/db/migrate/20100928030620_remove_uuid.rb +1 -2
- data/db/migrate/20120316045804_activities_to_versions.rb +1 -0
- data/db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb +1 -0
- data/db/migrate/20180107082701_authlogic_to_devise.rb +58 -0
- data/db/schema.rb +48 -46
- data/docker-compose.yml +10 -0
- data/fat_free_crm.gemspec +12 -14
- data/lib/development_tasks/license.rake +2 -2
- data/lib/fat_free_crm/callback.rb +2 -2
- data/lib/fat_free_crm/comment_extensions.rb +2 -4
- data/lib/fat_free_crm/core_ext/string.rb +1 -1
- data/lib/fat_free_crm/engine.rb +2 -2
- data/lib/fat_free_crm/errors.rb +1 -1
- data/lib/fat_free_crm/export_csv.rb +1 -0
- data/lib/fat_free_crm/exportable.rb +1 -1
- data/lib/fat_free_crm/fields.rb +2 -2
- data/lib/fat_free_crm/gem_dependencies.rb +1 -1
- data/lib/fat_free_crm/gem_ext/simple_form/action_view_extensions/form_helper.rb +1 -3
- data/lib/fat_free_crm/i18n.rb +2 -2
- data/lib/fat_free_crm/mail_processor/base.rb +4 -10
- data/lib/fat_free_crm/mail_processor/dropbox.rb +5 -15
- data/lib/fat_free_crm/permissions.rb +7 -18
- data/lib/fat_free_crm/sortable.rb +1 -1
- data/lib/fat_free_crm/tabs.rb +2 -2
- data/lib/fat_free_crm/version.rb +2 -2
- data/lib/gravatar_image_tag.rb +7 -8
- data/lib/missing_translation_detector.rb +1 -0
- data/lib/tasks/ffcrm/missing_translations.rake +1 -0
- data/lib/tasks/ffcrm/setup.rake +13 -4
- data/lib/tasks/ffcrm/update_data.rake +2 -2
- data/script/rails +2 -2
- data/spec/controllers/admin/users_controller_spec.rb +25 -81
- data/spec/controllers/comments_controller_spec.rb +19 -19
- data/spec/controllers/emails_controller_spec.rb +2 -2
- data/spec/controllers/entities/accounts_controller_spec.rb +56 -56
- data/spec/controllers/entities/campaigns_controller_spec.rb +66 -66
- data/spec/controllers/entities/contacts_controller_spec.rb +69 -68
- data/spec/controllers/entities/leads_controller_spec.rb +126 -126
- data/spec/controllers/entities/opportunities_controller_spec.rb +101 -101
- data/spec/controllers/entities_controller_spec.rb +5 -0
- data/spec/controllers/home_controller_spec.rb +30 -30
- data/spec/controllers/tasks_controller_spec.rb +42 -40
- data/spec/controllers/users_controller_spec.rb +43 -113
- data/spec/factories/account_factories.rb +13 -13
- data/spec/factories/campaign_factories.rb +8 -8
- data/spec/factories/contact_factories.rb +18 -18
- data/spec/factories/field_factories.rb +11 -10
- data/spec/factories/lead_factories.rb +13 -13
- data/spec/factories/list_factories.rb +3 -3
- data/spec/factories/opportunity_factories.rb +9 -9
- data/spec/factories/sequences.rb +1 -1
- data/spec/factories/setting_factories.rb +5 -5
- data/spec/factories/shared_factories.rb +25 -23
- data/spec/factories/subscription_factories.rb +1 -1
- data/spec/factories/tag_factories.rb +1 -1
- data/spec/factories/task_factories.rb +11 -11
- data/spec/factories/user_factories.rb +27 -30
- data/spec/features/accounts_spec.rb +17 -4
- data/spec/features/admin/groups_spec.rb +2 -2
- data/spec/features/admin/users_spec.rb +4 -2
- data/spec/features/campaigns_spec.rb +5 -5
- data/spec/features/contacts_spec.rb +11 -5
- data/spec/features/dashboard_spec.rb +8 -8
- data/spec/features/devise/sign_in_spec.rb +58 -0
- data/spec/features/devise/sign_up_spec.rb +36 -0
- data/spec/features/leads_spec.rb +5 -5
- data/spec/features/opportunities_overview_spec.rb +16 -16
- data/spec/features/opportunities_spec.rb +35 -9
- data/spec/features/support/autocomlete_helper.rb +17 -0
- data/spec/features/support/browser.rb +5 -9
- data/spec/features/tasks_spec.rb +5 -5
- data/spec/helpers/admin/field_groups_helper_spec.rb +1 -1
- data/spec/helpers/application_helper_spec.rb +1 -1
- data/spec/helpers/tasks_helper_spec.rb +1 -1
- data/spec/helpers/users_helper_spec.rb +7 -7
- data/spec/lib/comment_extensions_spec.rb +11 -5
- data/spec/lib/errors_spec.rb +2 -2
- data/spec/lib/mail_processor/base_spec.rb +3 -3
- data/spec/lib/mail_processor/comment_replies_spec.rb +3 -3
- data/spec/lib/mail_processor/dropbox_spec.rb +17 -17
- data/spec/lib/mail_processor/sample_emails/dropbox.rb +8 -8
- data/spec/lib/permissions_spec.rb +15 -28
- data/spec/mailers/devise_mailer_spec.rb +35 -0
- data/spec/mailers/user_mailer_spec.rb +6 -32
- data/spec/models/entities/account_spec.rb +58 -32
- data/spec/models/entities/campaign_spec.rb +18 -25
- data/spec/models/entities/contact_spec.rb +113 -21
- data/spec/models/entities/lead_spec.rb +9 -11
- data/spec/models/entities/opportunity_spec.rb +45 -45
- data/spec/models/fields/custom_field_date_pair_spec.rb +4 -2
- data/spec/models/fields/custom_field_spec.rb +21 -19
- data/spec/models/list_spec.rb +2 -2
- data/spec/models/observers/entity_observer_spec.rb +7 -7
- data/spec/models/polymorphic/address_spec.rb +1 -1
- data/spec/models/polymorphic/avatar_spec.rb +5 -5
- data/spec/models/polymorphic/comment_spec.rb +5 -5
- data/spec/models/polymorphic/task_spec.rb +65 -58
- data/spec/models/polymorphic/version_spec.rb +31 -31
- data/spec/models/setting_spec.rb +2 -2
- data/spec/models/users/preference_spec.rb +6 -6
- data/spec/models/users/user_spec.rb +46 -50
- data/spec/routing/users_routing_spec.rb +30 -8
- data/spec/shared/controllers.rb +3 -9
- data/spec/shared/models.rb +22 -22
- data/spec/spec_helper.rb +12 -4
- data/spec/support/assert_select.rb +1 -0
- data/spec/support/devise_helpers.rb +28 -0
- data/spec/{features/support/helpers.rb → support/feature_helpers.rb} +11 -11
- data/spec/support/macros.rb +7 -4
- data/spec/views/accounts/_edit.haml_spec.rb +1 -1
- data/spec/views/accounts/create.js.haml_spec.rb +3 -3
- data/spec/views/accounts/destroy.js.haml_spec.rb +1 -1
- data/spec/views/accounts/edit.js.haml_spec.rb +2 -2
- data/spec/views/accounts/index.haml_spec.rb +2 -2
- data/spec/views/accounts/index.js.haml_spec.rb +1 -1
- data/spec/views/accounts/show.haml_spec.rb +4 -4
- data/spec/views/accounts/update.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/create.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/destroy.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/edit.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/new.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/update.js.haml_spec.rb +1 -1
- data/spec/views/admin/users/create.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/destroy.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/edit.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/index.haml_spec.rb +1 -1
- data/spec/views/admin/users/index.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/reactivate.js.haml_spec.rb +1 -1
- data/spec/views/admin/users/suspend.js.haml_spec.rb +1 -1
- data/spec/views/admin/users/update.js.haml_spec.rb +1 -1
- data/spec/views/application/auto_complete.haml_spec.rb +3 -3
- data/spec/views/campaigns/_edit.haml_spec.rb +1 -1
- data/spec/views/campaigns/create.js.haml_spec.rb +4 -4
- data/spec/views/campaigns/destroy.js.haml_spec.rb +1 -1
- data/spec/views/campaigns/edit.js.haml_spec.rb +4 -4
- data/spec/views/campaigns/index.haml_spec.rb +1 -1
- data/spec/views/campaigns/index.js.haml_spec.rb +2 -2
- data/spec/views/campaigns/show.haml_spec.rb +4 -4
- data/spec/views/campaigns/update.js.haml_spec.rb +2 -2
- data/spec/views/contacts/_edit.haml_spec.rb +7 -7
- data/spec/views/contacts/_new.haml_spec.rb +1 -1
- data/spec/views/contacts/create.js.haml_spec.rb +5 -5
- data/spec/views/contacts/destroy.js.haml_spec.rb +1 -1
- data/spec/views/contacts/edit.js.haml_spec.rb +4 -4
- data/spec/views/contacts/index.haml_spec.rb +1 -1
- data/spec/views/contacts/index.js.html_spec.rb +2 -2
- data/spec/views/contacts/new.js.haml_spec.rb +1 -1
- data/spec/views/contacts/show.haml_spec.rb +3 -3
- data/spec/views/contacts/update.js.haml_spec.rb +5 -5
- data/spec/views/home/index.haml_spec.rb +1 -1
- data/spec/views/home/index.js.haml_spec.rb +1 -1
- data/spec/views/home/options.js.haml_spec.rb +2 -2
- data/spec/views/leads/_convert.haml_spec.rb +3 -3
- data/spec/views/leads/_edit.haml_spec.rb +2 -2
- data/spec/views/leads/_new.haml_spec.rb +2 -2
- data/spec/views/leads/_sidebar_show.haml_spec.rb +5 -5
- data/spec/views/leads/convert.js.haml_spec.rb +4 -4
- data/spec/views/leads/create.js.haml_spec.rb +5 -5
- data/spec/views/leads/destroy.js.haml_spec.rb +2 -2
- data/spec/views/leads/edit.js.haml_spec.rb +4 -4
- data/spec/views/leads/index.haml_spec.rb +1 -1
- data/spec/views/leads/index.js.haml_spec.rb +1 -1
- data/spec/views/leads/new.js.haml_spec.rb +1 -1
- data/spec/views/leads/promote.js.haml_spec.rb +7 -7
- data/spec/views/leads/reject.js.haml_spec.rb +2 -2
- data/spec/views/leads/show.haml_spec.rb +2 -2
- data/spec/views/leads/update.js.haml_spec.rb +4 -4
- data/spec/views/opportunities/_edit.haml_spec.rb +7 -7
- data/spec/views/opportunities/_new.haml_spec.rb +2 -2
- data/spec/views/opportunities/create.js.haml_spec.rb +6 -6
- data/spec/views/opportunities/destroy.js.haml_spec.rb +3 -3
- data/spec/views/opportunities/edit.js.haml_spec.rb +3 -3
- data/spec/views/opportunities/index.haml_spec.rb +1 -1
- data/spec/views/opportunities/index.js.haml_spec.rb +1 -1
- data/spec/views/opportunities/new.js.haml_spec.rb +1 -1
- data/spec/views/opportunities/show.haml_spec.rb +3 -3
- data/spec/views/opportunities/update.js.haml_spec.rb +5 -5
- data/spec/views/tasks/_edit.haml_spec.rb +1 -1
- data/spec/views/tasks/complete.js.haml_spec.rb +4 -4
- data/spec/views/tasks/create.js.haml_spec.rb +6 -6
- data/spec/views/tasks/destroy.js.haml_spec.rb +2 -2
- data/spec/views/tasks/index.haml_spec.rb +4 -4
- data/spec/views/tasks/new.js.haml_spec.rb +1 -1
- data/spec/views/tasks/uncomplete.js.haml_spec.rb +2 -2
- data/spec/views/tasks/update.js.haml_spec.rb +18 -18
- data/spec/views/users/upload_avatar.js.haml_spec.rb +2 -2
- metadata +49 -71
- data/app/controllers/authentications_controller.rb +0 -53
- data/app/models/users/authentication.rb +0 -56
- data/app/views/authentications/new.html.haml +0 -19
- data/app/views/passwords/edit.html.haml +0 -15
- data/app/views/passwords/new.html.haml +0 -10
- data/app/views/user_mailer/password_reset_instructions.html.haml +0 -6
- data/app/views/users/new.html.haml +0 -19
- data/spec/controllers/authentications_controller_spec.rb +0 -150
- data/spec/controllers/passwords_controller_spec.rb +0 -32
- data/spec/models/users/authentication_spec.rb +0 -19
- data/spec/support/auth_macros.rb +0 -49
- data/spec/views/authentications/new.haml_spec.rb +0 -31
@@ -26,7 +26,7 @@ describe CampaignsController do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should expose all campaigns as @campaigns and render [index] template" do
|
29
|
-
@campaigns = [
|
29
|
+
@campaigns = [create(:campaign, user: current_user)]
|
30
30
|
|
31
31
|
get :index
|
32
32
|
expect(assigns[:campaigns]).to eq(@campaigns)
|
@@ -34,7 +34,7 @@ describe CampaignsController do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should collect the data for the opportunities sidebar" do
|
37
|
-
@campaigns = [
|
37
|
+
@campaigns = [create(:campaign, user: current_user)]
|
38
38
|
|
39
39
|
get :index
|
40
40
|
expect(assigns[:campaign_status_total].keys.map(&:to_sym) - (@status << :all << :other)).to eq([])
|
@@ -43,12 +43,12 @@ describe CampaignsController do
|
|
43
43
|
it "should filter out campaigns by status" do
|
44
44
|
controller.session[:campaigns_filter] = "planned,started"
|
45
45
|
@campaigns = [
|
46
|
-
|
47
|
-
|
46
|
+
create(:campaign, user: current_user, status: "started"),
|
47
|
+
create(:campaign, user: current_user, status: "planned")
|
48
48
|
]
|
49
49
|
|
50
50
|
# This one should be filtered out.
|
51
|
-
|
51
|
+
create(:campaign, user: current_user, status: "completed")
|
52
52
|
|
53
53
|
get :index
|
54
54
|
# Note: can't compare campaigns directly because of BigDecimal objects.
|
@@ -57,8 +57,8 @@ describe CampaignsController do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should perform lookup using query string" do
|
60
|
-
@first =
|
61
|
-
@second =
|
60
|
+
@first = create(:campaign, user: current_user, name: "Hello, world!")
|
61
|
+
@second = create(:campaign, user: current_user, name: "Hello again")
|
62
62
|
|
63
63
|
get :index, params: { query: "again" }
|
64
64
|
expect(assigns[:campaigns]).to eq([@second])
|
@@ -68,7 +68,7 @@ describe CampaignsController do
|
|
68
68
|
|
69
69
|
describe "AJAX pagination" do
|
70
70
|
it "should pick up page number from params" do
|
71
|
-
@campaigns = [
|
71
|
+
@campaigns = [create(:campaign, user: current_user)]
|
72
72
|
get :index, params: { page: 42 }, xhr: true
|
73
73
|
|
74
74
|
expect(assigns[:current_page].to_i).to eq(42)
|
@@ -79,7 +79,7 @@ describe CampaignsController do
|
|
79
79
|
|
80
80
|
it "should pick up saved page number from session" do
|
81
81
|
session[:campaigns_current_page] = 42
|
82
|
-
@campaigns = [
|
82
|
+
@campaigns = [create(:campaign, user: current_user)]
|
83
83
|
get :index, xhr: true
|
84
84
|
|
85
85
|
expect(assigns[:current_page]).to eq(42)
|
@@ -90,7 +90,7 @@ describe CampaignsController do
|
|
90
90
|
it "should reset current_page when query is altered" do
|
91
91
|
session[:campaigns_current_page] = 42
|
92
92
|
session[:campaigns_current_query] = "bill"
|
93
|
-
@campaigns = [
|
93
|
+
@campaigns = [create(:campaign, user: current_user)]
|
94
94
|
get :index, xhr: true
|
95
95
|
|
96
96
|
expect(assigns[:current_page]).to eq(1)
|
@@ -128,7 +128,7 @@ describe CampaignsController do
|
|
128
128
|
describe "responding to GET show" do
|
129
129
|
describe "with mime type of HTML" do
|
130
130
|
before(:each) do
|
131
|
-
@campaign =
|
131
|
+
@campaign = create(:campaign, id: 42, user: current_user)
|
132
132
|
@stage = Setting.unroll(:opportunity_stage)
|
133
133
|
@comment = Comment.new
|
134
134
|
end
|
@@ -149,7 +149,7 @@ describe CampaignsController do
|
|
149
149
|
|
150
150
|
describe "with mime type of JSON" do
|
151
151
|
it "should render the requested campaign as JSON" do
|
152
|
-
@campaign =
|
152
|
+
@campaign = create(:campaign, id: 42, user: current_user)
|
153
153
|
expect(Campaign).to receive(:find).and_return(@campaign)
|
154
154
|
expect(@campaign).to receive(:to_json).and_return("generated JSON")
|
155
155
|
|
@@ -161,7 +161,7 @@ describe CampaignsController do
|
|
161
161
|
|
162
162
|
describe "with mime type of XML" do
|
163
163
|
it "should render the requested campaign as XML" do
|
164
|
-
@campaign =
|
164
|
+
@campaign = create(:campaign, id: 42, user: current_user)
|
165
165
|
expect(Campaign).to receive(:find).and_return(@campaign)
|
166
166
|
expect(@campaign).to receive(:to_xml).and_return("generated XML")
|
167
167
|
|
@@ -173,7 +173,7 @@ describe CampaignsController do
|
|
173
173
|
|
174
174
|
describe "campaign got deleted or otherwise unavailable" do
|
175
175
|
it "should redirect to campaign index if the campaign got deleted" do
|
176
|
-
@campaign =
|
176
|
+
@campaign = create(:campaign, user: current_user)
|
177
177
|
@campaign.destroy
|
178
178
|
|
179
179
|
get :show, params: { id: @campaign.id }
|
@@ -182,7 +182,7 @@ describe CampaignsController do
|
|
182
182
|
end
|
183
183
|
|
184
184
|
it "should redirect to campaign index if the campaign is protected" do
|
185
|
-
@campaign =
|
185
|
+
@campaign = create(:campaign, user: create(:user), access: "Private")
|
186
186
|
|
187
187
|
get :show, params: { id: @campaign.id }
|
188
188
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -190,7 +190,7 @@ describe CampaignsController do
|
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should return 404 (Not Found) JSON error" do
|
193
|
-
@campaign =
|
193
|
+
@campaign = create(:campaign, user: current_user)
|
194
194
|
@campaign.destroy
|
195
195
|
request.env["HTTP_ACCEPT"] = "application/json"
|
196
196
|
|
@@ -199,7 +199,7 @@ describe CampaignsController do
|
|
199
199
|
end
|
200
200
|
|
201
201
|
it "should return 404 (Not Found) XML error" do
|
202
|
-
@campaign =
|
202
|
+
@campaign = create(:campaign, user: current_user)
|
203
203
|
@campaign.destroy
|
204
204
|
request.env["HTTP_ACCEPT"] = "application/xml"
|
205
205
|
|
@@ -222,7 +222,7 @@ describe CampaignsController do
|
|
222
222
|
end
|
223
223
|
|
224
224
|
it "should create related object when necessary" do
|
225
|
-
@lead =
|
225
|
+
@lead = create(:lead, id: 42)
|
226
226
|
|
227
227
|
get :new, params: { related: "lead_42" }, xhr: true
|
228
228
|
expect(assigns[:lead]).to eq(@lead)
|
@@ -233,7 +233,7 @@ describe CampaignsController do
|
|
233
233
|
#----------------------------------------------------------------------------
|
234
234
|
describe "responding to GET edit" do
|
235
235
|
it "should expose the requested campaign as @campaign and render [edit] template" do
|
236
|
-
@campaign =
|
236
|
+
@campaign = create(:campaign, id: 42, user: current_user)
|
237
237
|
|
238
238
|
get :edit, params: { id: 42 }, xhr: true
|
239
239
|
expect(assigns[:campaign]).to eq(@campaign)
|
@@ -241,8 +241,8 @@ describe CampaignsController do
|
|
241
241
|
end
|
242
242
|
|
243
243
|
it "should find previous campaign as necessary" do
|
244
|
-
@campaign =
|
245
|
-
@previous =
|
244
|
+
@campaign = create(:campaign, id: 42)
|
245
|
+
@previous = create(:campaign, id: 99)
|
246
246
|
|
247
247
|
get :edit, params: { id: 42, previous: 99 }, xhr: true
|
248
248
|
expect(assigns[:campaign]).to eq(@campaign)
|
@@ -251,7 +251,7 @@ describe CampaignsController do
|
|
251
251
|
|
252
252
|
describe "(campaign got deleted or is otherwise unavailable)" do
|
253
253
|
it "should reload current page with the flash message if the campaign got deleted" do
|
254
|
-
@campaign =
|
254
|
+
@campaign = create(:campaign, user: current_user)
|
255
255
|
@campaign.destroy
|
256
256
|
|
257
257
|
get :edit, params: { id: @campaign.id }, xhr: true
|
@@ -260,7 +260,7 @@ describe CampaignsController do
|
|
260
260
|
end
|
261
261
|
|
262
262
|
it "should reload current page with the flash message if the campaign is protected" do
|
263
|
-
@private =
|
263
|
+
@private = create(:campaign, user: create(:user), access: "Private")
|
264
264
|
|
265
265
|
get :edit, params: { id: @private.id }, xhr: true
|
266
266
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -270,8 +270,8 @@ describe CampaignsController do
|
|
270
270
|
|
271
271
|
describe "(previous campaign got deleted or is otherwise unavailable)" do
|
272
272
|
before(:each) do
|
273
|
-
@campaign =
|
274
|
-
@previous =
|
273
|
+
@campaign = create(:campaign, user: current_user)
|
274
|
+
@previous = create(:campaign, user: create(:user))
|
275
275
|
end
|
276
276
|
|
277
277
|
it "should notify the view if previous campaign got deleted" do
|
@@ -300,7 +300,7 @@ describe CampaignsController do
|
|
300
300
|
describe "responding to POST create" do
|
301
301
|
describe "with valid params" do
|
302
302
|
it "should expose a newly created campaign as @campaign and render [create] template" do
|
303
|
-
@campaign =
|
303
|
+
@campaign = build(:campaign, name: "Hello", user: current_user)
|
304
304
|
allow(Campaign).to receive(:new).and_return(@campaign)
|
305
305
|
|
306
306
|
post :create, params: { campaign: { name: "Hello" } }, xhr: true
|
@@ -309,7 +309,7 @@ describe CampaignsController do
|
|
309
309
|
end
|
310
310
|
|
311
311
|
it "should get data to update campaign sidebar" do
|
312
|
-
@campaign =
|
312
|
+
@campaign = build(:campaign, name: "Hello", user: current_user)
|
313
313
|
allow(Campaign).to receive(:new).and_return(@campaign)
|
314
314
|
|
315
315
|
post :create, params: { campaign: { name: "Hello" } }, xhr: true
|
@@ -317,7 +317,7 @@ describe CampaignsController do
|
|
317
317
|
end
|
318
318
|
|
319
319
|
it "should reload campaigns to update pagination" do
|
320
|
-
@campaign =
|
320
|
+
@campaign = build(:campaign, user: current_user)
|
321
321
|
allow(Campaign).to receive(:new).and_return(@campaign)
|
322
322
|
|
323
323
|
post :create, params: { campaign: { name: "Hello" } }, xhr: true
|
@@ -325,7 +325,7 @@ describe CampaignsController do
|
|
325
325
|
end
|
326
326
|
|
327
327
|
it "should add a new comment to the newly created campaign when specified" do
|
328
|
-
@campaign =
|
328
|
+
@campaign = build(:campaign, name: "Hello world", user: current_user)
|
329
329
|
allow(Campaign).to receive(:new).and_return(@campaign)
|
330
330
|
|
331
331
|
post :create, params: { campaign: { name: "Hello world" }, comment_body: "Awesome comment is awesome" }, xhr: true
|
@@ -335,7 +335,7 @@ describe CampaignsController do
|
|
335
335
|
|
336
336
|
describe "with invalid params" do
|
337
337
|
it "should expose a newly created but unsaved campaign as @campaign and still render [create] template" do
|
338
|
-
@campaign =
|
338
|
+
@campaign = build(:campaign, id: nil, name: nil, user: current_user)
|
339
339
|
allow(Campaign).to receive(:new).and_return(@campaign)
|
340
340
|
|
341
341
|
post :create, params: { campaign: {} }, xhr: true
|
@@ -351,7 +351,7 @@ describe CampaignsController do
|
|
351
351
|
describe "responding to PUT update" do
|
352
352
|
describe "with valid params" do
|
353
353
|
it "should update the requested campaign and render [update] template" do
|
354
|
-
@campaign =
|
354
|
+
@campaign = create(:campaign, id: 42, name: "Bye")
|
355
355
|
|
356
356
|
put :update, params: { id: 42, campaign: { name: "Hello" } }, xhr: true
|
357
357
|
expect(@campaign.reload.name).to eq("Hello")
|
@@ -360,7 +360,7 @@ describe CampaignsController do
|
|
360
360
|
end
|
361
361
|
|
362
362
|
it "should get data for campaigns sidebar when called from Campaigns index" do
|
363
|
-
@campaign =
|
363
|
+
@campaign = create(:campaign, id: 42)
|
364
364
|
request.env["HTTP_REFERER"] = "http://localhost/campaigns"
|
365
365
|
|
366
366
|
put :update, params: { id: 42, campaign: { name: "Hello" } }, xhr: true
|
@@ -369,9 +369,9 @@ describe CampaignsController do
|
|
369
369
|
end
|
370
370
|
|
371
371
|
it "should update campaign permissions when sharing with specific users" do
|
372
|
-
@campaign =
|
373
|
-
he
|
374
|
-
she =
|
372
|
+
@campaign = create(:campaign, id: 42, access: "Public")
|
373
|
+
he = create(:user, id: 7)
|
374
|
+
she = create(:user, id: 8)
|
375
375
|
|
376
376
|
put :update, params: { id: 42, campaign: { name: "Hello", access: "Shared", user_ids: %w[7 8] } }, xhr: true
|
377
377
|
expect(assigns[:campaign].access).to eq("Shared")
|
@@ -380,7 +380,7 @@ describe CampaignsController do
|
|
380
380
|
|
381
381
|
describe "campaign got deleted or otherwise unavailable" do
|
382
382
|
it "should reload current page with the flash message if the campaign got deleted" do
|
383
|
-
@campaign =
|
383
|
+
@campaign = create(:campaign, user: current_user)
|
384
384
|
@campaign.destroy
|
385
385
|
|
386
386
|
put :update, params: { id: @campaign.id }, xhr: true
|
@@ -389,7 +389,7 @@ describe CampaignsController do
|
|
389
389
|
end
|
390
390
|
|
391
391
|
it "should reload current page with the flash message if the campaign is protected" do
|
392
|
-
@private =
|
392
|
+
@private = create(:campaign, user: create(:user), access: "Private")
|
393
393
|
|
394
394
|
put :update, params: { id: @private.id }, xhr: true
|
395
395
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -400,7 +400,7 @@ describe CampaignsController do
|
|
400
400
|
|
401
401
|
describe "with invalid params" do
|
402
402
|
it "should not update the requested campaign, but still expose it as @campaign and still render [update] template" do
|
403
|
-
@campaign =
|
403
|
+
@campaign = create(:campaign, id: 42, name: "Hello", user: current_user)
|
404
404
|
|
405
405
|
put :update, params: { id: 42, campaign: { name: nil } }, xhr: true
|
406
406
|
expect(@campaign.reload.name).to eq("Hello")
|
@@ -415,12 +415,12 @@ describe CampaignsController do
|
|
415
415
|
#----------------------------------------------------------------------------
|
416
416
|
describe "responding to DELETE destroy" do
|
417
417
|
before(:each) do
|
418
|
-
@campaign =
|
418
|
+
@campaign = create(:campaign, user: current_user)
|
419
419
|
end
|
420
420
|
|
421
421
|
describe "AJAX request" do
|
422
422
|
it "should destroy the requested campaign and render [destroy] template" do
|
423
|
-
@another_campaign =
|
423
|
+
@another_campaign = create(:campaign, user: current_user)
|
424
424
|
delete :destroy, params: { id: @campaign.id }, xhr: true
|
425
425
|
|
426
426
|
expect(assigns[:campaigns]).to eq([@another_campaign])
|
@@ -452,7 +452,7 @@ describe CampaignsController do
|
|
452
452
|
|
453
453
|
describe "campaign got deleted or otherwise unavailable" do
|
454
454
|
it "should reload current page with the flash message if the campaign got deleted" do
|
455
|
-
@campaign =
|
455
|
+
@campaign = create(:campaign, user: current_user)
|
456
456
|
@campaign.destroy
|
457
457
|
|
458
458
|
delete :destroy, params: { id: @campaign.id }, xhr: true
|
@@ -461,7 +461,7 @@ describe CampaignsController do
|
|
461
461
|
end
|
462
462
|
|
463
463
|
it "should reload current page with the flash message if the campaign is protected" do
|
464
|
-
@private =
|
464
|
+
@private = create(:campaign, user: create(:user), access: "Private")
|
465
465
|
|
466
466
|
delete :destroy, params: { id: @private.id }, xhr: true
|
467
467
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -479,7 +479,7 @@ describe CampaignsController do
|
|
479
479
|
end
|
480
480
|
|
481
481
|
it "should redirect to campaign index with the flash message is the campaign got deleted" do
|
482
|
-
@campaign =
|
482
|
+
@campaign = create(:campaign, user: current_user)
|
483
483
|
@campaign.destroy
|
484
484
|
|
485
485
|
delete :destroy, params: { id: @campaign.id }
|
@@ -488,7 +488,7 @@ describe CampaignsController do
|
|
488
488
|
end
|
489
489
|
|
490
490
|
it "should redirect to campaign index with the flash message if the campaign is protected" do
|
491
|
-
@private =
|
491
|
+
@private = create(:campaign, user: create(:user), access: "Private")
|
492
492
|
|
493
493
|
delete :destroy, params: { id: @private.id }
|
494
494
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -503,24 +503,24 @@ describe CampaignsController do
|
|
503
503
|
describe "responding to PUT attach" do
|
504
504
|
describe "tasks" do
|
505
505
|
before do
|
506
|
-
@model =
|
507
|
-
@attachment =
|
506
|
+
@model = create(:campaign)
|
507
|
+
@attachment = create(:task, asset: nil)
|
508
508
|
end
|
509
509
|
it_should_behave_like("attach")
|
510
510
|
end
|
511
511
|
|
512
512
|
describe "leads" do
|
513
513
|
before do
|
514
|
-
@model =
|
515
|
-
@attachment =
|
514
|
+
@model = create(:campaign)
|
515
|
+
@attachment = create(:lead, campaign: nil)
|
516
516
|
end
|
517
517
|
it_should_behave_like("attach")
|
518
518
|
end
|
519
519
|
|
520
520
|
describe "opportunities" do
|
521
521
|
before do
|
522
|
-
@model =
|
523
|
-
@attachment =
|
522
|
+
@model = create(:campaign)
|
523
|
+
@attachment = create(:opportunity, campaign: nil)
|
524
524
|
end
|
525
525
|
it_should_behave_like("attach")
|
526
526
|
end
|
@@ -532,24 +532,24 @@ describe CampaignsController do
|
|
532
532
|
describe "responding to PUT attach" do
|
533
533
|
describe "tasks" do
|
534
534
|
before do
|
535
|
-
@model =
|
536
|
-
@attachment =
|
535
|
+
@model = create(:campaign)
|
536
|
+
@attachment = create(:task, asset: nil)
|
537
537
|
end
|
538
538
|
it_should_behave_like("attach")
|
539
539
|
end
|
540
540
|
|
541
541
|
describe "leads" do
|
542
542
|
before do
|
543
|
-
@model =
|
544
|
-
@attachment =
|
543
|
+
@model = create(:campaign)
|
544
|
+
@attachment = create(:lead, campaign: nil)
|
545
545
|
end
|
546
546
|
it_should_behave_like("attach")
|
547
547
|
end
|
548
548
|
|
549
549
|
describe "opportunities" do
|
550
550
|
before do
|
551
|
-
@model =
|
552
|
-
@attachment =
|
551
|
+
@model = create(:campaign)
|
552
|
+
@attachment = create(:opportunity, campaign: nil)
|
553
553
|
end
|
554
554
|
it_should_behave_like("attach")
|
555
555
|
end
|
@@ -561,16 +561,16 @@ describe CampaignsController do
|
|
561
561
|
describe "responding to POST discard" do
|
562
562
|
describe "tasks" do
|
563
563
|
before do
|
564
|
-
@model =
|
565
|
-
@attachment =
|
564
|
+
@model = create(:campaign)
|
565
|
+
@attachment = create(:task, asset: @model)
|
566
566
|
end
|
567
567
|
it_should_behave_like("discard")
|
568
568
|
end
|
569
569
|
|
570
570
|
describe "leads" do
|
571
571
|
before do
|
572
|
-
@attachment =
|
573
|
-
@model =
|
572
|
+
@attachment = create(:lead)
|
573
|
+
@model = create(:campaign)
|
574
574
|
@model.leads << @attachment
|
575
575
|
end
|
576
576
|
it_should_behave_like("discard")
|
@@ -578,8 +578,8 @@ describe CampaignsController do
|
|
578
578
|
|
579
579
|
describe "opportunities" do
|
580
580
|
before do
|
581
|
-
@attachment =
|
582
|
-
@model =
|
581
|
+
@attachment = create(:opportunity)
|
582
|
+
@model = create(:campaign)
|
583
583
|
@model.opportunities << @attachment
|
584
584
|
end
|
585
585
|
it_should_behave_like("discard")
|
@@ -590,7 +590,7 @@ describe CampaignsController do
|
|
590
590
|
#----------------------------------------------------------------------------
|
591
591
|
describe "responding to POST auto_complete" do
|
592
592
|
before(:each) do
|
593
|
-
@auto_complete_matches = [
|
593
|
+
@auto_complete_matches = [create(:campaign, name: "Hello World", user: current_user)]
|
594
594
|
end
|
595
595
|
|
596
596
|
it_should_behave_like("auto complete")
|
@@ -613,8 +613,8 @@ describe CampaignsController do
|
|
613
613
|
|
614
614
|
it "should select @campaigns and render [index] template" do
|
615
615
|
@campaigns = [
|
616
|
-
|
617
|
-
|
616
|
+
create(:campaign, name: "A", user: current_user),
|
617
|
+
create(:campaign, name: "B", user: current_user)
|
618
618
|
]
|
619
619
|
|
620
620
|
get :redraw, params: { per_page: 1, sort_by: "name" }, xhr: true
|
@@ -628,7 +628,7 @@ describe CampaignsController do
|
|
628
628
|
describe "responding to POST filter" do
|
629
629
|
it "should expose filtered campaigns as @campaigns and render [index] template" do
|
630
630
|
session[:campaigns_filter] = "planned,started"
|
631
|
-
@campaigns = [
|
631
|
+
@campaigns = [create(:campaign, status: "completed", user: current_user)]
|
632
632
|
|
633
633
|
post :filter, params: { status: "completed" }, xhr: true
|
634
634
|
expect(assigns(:campaigns)).to eq(@campaigns)
|
@@ -18,7 +18,7 @@ describe ContactsController do
|
|
18
18
|
#----------------------------------------------------------------------------
|
19
19
|
describe "responding to GET index" do
|
20
20
|
it "should expose all contacts as @contacts and render [index] template" do
|
21
|
-
@contacts = [
|
21
|
+
@contacts = [create(:contact, user: current_user)]
|
22
22
|
get :index
|
23
23
|
expect(assigns[:contacts].count).to eq(@contacts.count)
|
24
24
|
expect(assigns[:contacts]).to eq(@contacts)
|
@@ -26,8 +26,8 @@ describe ContactsController do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should perform lookup using query string" do
|
29
|
-
@billy_bones =
|
30
|
-
@captain_flint =
|
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
31
|
|
32
32
|
get :index, params: { query: @billy_bones.email }
|
33
33
|
expect(assigns[:contacts]).to eq([@billy_bones])
|
@@ -37,7 +37,7 @@ describe ContactsController do
|
|
37
37
|
|
38
38
|
describe "AJAX pagination" do
|
39
39
|
it "should pick up page number from params" do
|
40
|
-
@contacts = [
|
40
|
+
@contacts = [create(:contact, user: current_user)]
|
41
41
|
get :index, params: { page: 42 }, xhr: true
|
42
42
|
|
43
43
|
expect(assigns[:current_page].to_i).to eq(42)
|
@@ -48,7 +48,7 @@ describe ContactsController do
|
|
48
48
|
|
49
49
|
it "should pick up saved page number from session" do
|
50
50
|
session[:contacts_current_page] = 42
|
51
|
-
@contacts = [
|
51
|
+
@contacts = [create(:contact, user: current_user)]
|
52
52
|
get :index, xhr: true
|
53
53
|
|
54
54
|
expect(assigns[:current_page]).to eq(42)
|
@@ -59,7 +59,7 @@ describe ContactsController do
|
|
59
59
|
it "should reset current_page when query is altered" do
|
60
60
|
session[:contacts_current_page] = 42
|
61
61
|
session[:contacts_current_query] = "bill"
|
62
|
-
@contacts = [
|
62
|
+
@contacts = [create(:contact, user: current_user)]
|
63
63
|
get :index, xhr: true
|
64
64
|
|
65
65
|
expect(assigns[:current_page]).to eq(1)
|
@@ -97,7 +97,7 @@ describe ContactsController do
|
|
97
97
|
describe "responding to GET show" do
|
98
98
|
describe "with mime type of HTML" do
|
99
99
|
before(:each) do
|
100
|
-
@contact =
|
100
|
+
@contact = create(:contact, id: 42)
|
101
101
|
@stage = Setting.unroll(:opportunity_stage)
|
102
102
|
@comment = Comment.new
|
103
103
|
end
|
@@ -118,7 +118,7 @@ describe ContactsController do
|
|
118
118
|
|
119
119
|
describe "with mime type of JSON" do
|
120
120
|
it "should render the requested contact as JSON" do
|
121
|
-
@contact =
|
121
|
+
@contact = create(:contact, id: 42)
|
122
122
|
expect(Contact).to receive(:find).and_return(@contact)
|
123
123
|
expect(@contact).to receive(:to_json).and_return("generated JSON")
|
124
124
|
|
@@ -130,7 +130,7 @@ describe ContactsController do
|
|
130
130
|
|
131
131
|
describe "with mime type of XML" do
|
132
132
|
it "should render the requested contact as xml" do
|
133
|
-
@contact =
|
133
|
+
@contact = create(:contact, id: 42)
|
134
134
|
expect(Contact).to receive(:find).and_return(@contact)
|
135
135
|
expect(@contact).to receive(:to_xml).and_return("generated XML")
|
136
136
|
|
@@ -142,7 +142,7 @@ describe ContactsController do
|
|
142
142
|
|
143
143
|
describe "contact got deleted or otherwise unavailable" do
|
144
144
|
it "should redirect to contact index if the contact got deleted" do
|
145
|
-
@contact =
|
145
|
+
@contact = create(:contact, user: current_user)
|
146
146
|
@contact.destroy
|
147
147
|
|
148
148
|
get :show, params: { id: @contact.id }
|
@@ -151,7 +151,7 @@ describe ContactsController do
|
|
151
151
|
end
|
152
152
|
|
153
153
|
it "should redirect to contact index if the contact is protected" do
|
154
|
-
@private =
|
154
|
+
@private = create(:contact, user: create(:user), access: "Private")
|
155
155
|
|
156
156
|
get :show, params: { id: @private.id }
|
157
157
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -159,7 +159,7 @@ describe ContactsController do
|
|
159
159
|
end
|
160
160
|
|
161
161
|
it "should return 404 (Not Found) XML error" do
|
162
|
-
@contact =
|
162
|
+
@contact = create(:contact, user: current_user)
|
163
163
|
@contact.destroy
|
164
164
|
request.env["HTTP_ACCEPT"] = "application/xml"
|
165
165
|
|
@@ -177,7 +177,7 @@ describe ContactsController do
|
|
177
177
|
@contact = Contact.new(user: current_user,
|
178
178
|
access: Setting.default_access)
|
179
179
|
@account = Account.new(user: current_user)
|
180
|
-
@accounts = [
|
180
|
+
@accounts = [create(:account, user: current_user)]
|
181
181
|
|
182
182
|
get :new, xhr: true
|
183
183
|
expect(assigns[:contact].attributes).to eq(@contact.attributes)
|
@@ -188,7 +188,7 @@ describe ContactsController do
|
|
188
188
|
end
|
189
189
|
|
190
190
|
it "should created an instance of related object when necessary" do
|
191
|
-
@opportunity =
|
191
|
+
@opportunity = create(:opportunity)
|
192
192
|
|
193
193
|
get :new, params: { related: "opportunity_#{@opportunity.id}" }, xhr: true
|
194
194
|
expect(assigns[:opportunity]).to eq(@opportunity)
|
@@ -196,7 +196,7 @@ describe ContactsController do
|
|
196
196
|
|
197
197
|
describe "(when creating related contact)" do
|
198
198
|
it "should redirect to parent asset's index page with the message if parent asset got deleted" do
|
199
|
-
@account =
|
199
|
+
@account = create(:account)
|
200
200
|
@account.destroy
|
201
201
|
|
202
202
|
get :new, params: { related: "account_#{@account.id}" }, xhr: true
|
@@ -205,7 +205,7 @@ describe ContactsController do
|
|
205
205
|
end
|
206
206
|
|
207
207
|
it "should redirect to parent asset's index page with the message if parent asset got protected" do
|
208
|
-
@account =
|
208
|
+
@account = create(:account, access: "Private")
|
209
209
|
|
210
210
|
get :new, params: { related: "account_#{@account.id}" }, xhr: true
|
211
211
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -219,7 +219,7 @@ describe ContactsController do
|
|
219
219
|
describe "responding to GET field_group" do
|
220
220
|
context "with an existing tag" do
|
221
221
|
before :each do
|
222
|
-
@tag =
|
222
|
+
@tag = create(:tag)
|
223
223
|
end
|
224
224
|
|
225
225
|
it "should return with an existing tag name" do
|
@@ -252,7 +252,7 @@ describe ContactsController do
|
|
252
252
|
#----------------------------------------------------------------------------
|
253
253
|
describe "responding to GET edit" do
|
254
254
|
it "should expose the requested contact as @contact and render [edit] template" do
|
255
|
-
@contact =
|
255
|
+
@contact = create(:contact, id: 42, user: current_user, lead: nil)
|
256
256
|
@account = Account.new(user: current_user)
|
257
257
|
|
258
258
|
get :edit, params: { id: 42 }, xhr: true
|
@@ -263,9 +263,9 @@ describe ContactsController do
|
|
263
263
|
end
|
264
264
|
|
265
265
|
it "should expose the requested contact as @contact and linked account as @account" do
|
266
|
-
@account =
|
267
|
-
@contact =
|
268
|
-
|
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
269
|
|
270
270
|
get :edit, params: { id: 42 }, xhr: true
|
271
271
|
expect(assigns[:contact]).to eq(@contact)
|
@@ -273,8 +273,8 @@ describe ContactsController do
|
|
273
273
|
end
|
274
274
|
|
275
275
|
it "should expose previous contact as @previous when necessary" do
|
276
|
-
@contact =
|
277
|
-
@previous =
|
276
|
+
@contact = create(:contact, id: 42)
|
277
|
+
@previous = create(:contact, id: 1992)
|
278
278
|
|
279
279
|
get :edit, params: { id: 42, previous: 1992 }, xhr: true
|
280
280
|
expect(assigns[:previous]).to eq(@previous)
|
@@ -282,7 +282,7 @@ describe ContactsController do
|
|
282
282
|
|
283
283
|
describe "(contact got deleted or is otherwise unavailable)" do
|
284
284
|
it "should reload current page with the flash message if the contact got deleted" do
|
285
|
-
@contact =
|
285
|
+
@contact = create(:contact, user: current_user)
|
286
286
|
@contact.destroy
|
287
287
|
|
288
288
|
get :edit, params: { id: @contact.id }, xhr: true
|
@@ -291,7 +291,7 @@ describe ContactsController do
|
|
291
291
|
end
|
292
292
|
|
293
293
|
it "should reload current page with the flash message if the contact is protected" do
|
294
|
-
@private =
|
294
|
+
@private = create(:contact, user: create(:user), access: "Private")
|
295
295
|
|
296
296
|
get :edit, params: { id: @private.id }, xhr: true
|
297
297
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -301,8 +301,8 @@ describe ContactsController do
|
|
301
301
|
|
302
302
|
describe "(previous contact got deleted or is otherwise unavailable)" do
|
303
303
|
before(:each) do
|
304
|
-
@contact =
|
305
|
-
@previous =
|
304
|
+
@contact = create(:contact, user: current_user)
|
305
|
+
@previous = create(:contact, user: create(:user))
|
306
306
|
end
|
307
307
|
|
308
308
|
it "should notify the view if previous contact got deleted" do
|
@@ -331,18 +331,19 @@ describe ContactsController do
|
|
331
331
|
describe "responding to POST create" do
|
332
332
|
describe "with valid params" do
|
333
333
|
it "should expose a newly created contact as @contact and render [create] template" do
|
334
|
-
@contact =
|
334
|
+
@contact = build(:contact, first_name: "Billy", last_name: "Bones")
|
335
335
|
allow(Contact).to receive(:new).and_return(@contact)
|
336
336
|
|
337
|
-
post :create, params: { contact: { first_name: "Billy", last_name: "Bones" }, account: { name: "Hello world" } }, xhr: true
|
337
|
+
post :create, params: { contact: { first_name: "Billy", last_name: "Bones" }, account: { id: "", name: "Hello world" } }, xhr: true
|
338
338
|
expect(assigns(:contact)).to eq(@contact)
|
339
339
|
expect(assigns(:contact).reload.account.name).to eq("Hello world")
|
340
|
+
expect(assigns(:contact).account.user).to eq(assigns(:contact).user)
|
340
341
|
expect(response).to render_template("contacts/create")
|
341
342
|
end
|
342
343
|
|
343
344
|
it "should be able to associate newly created contact with the opportunity" do
|
344
|
-
@opportunity =
|
345
|
-
@contact =
|
345
|
+
@opportunity = create(:opportunity, id: 987)
|
346
|
+
@contact = build(:contact)
|
346
347
|
allow(Contact).to receive(:new).and_return(@contact)
|
347
348
|
|
348
349
|
post :create, params: { contact: { first_name: "Billy" }, account: {}, opportunity: 987 }, xhr: true
|
@@ -351,7 +352,7 @@ describe ContactsController do
|
|
351
352
|
end
|
352
353
|
|
353
354
|
it "should reload contacts to update pagination if called from contacts index" do
|
354
|
-
@contact =
|
355
|
+
@contact = build(:contact, user: current_user)
|
355
356
|
allow(Contact).to receive(:new).and_return(@contact)
|
356
357
|
|
357
358
|
request.env["HTTP_REFERER"] = "http://localhost/contacts"
|
@@ -360,7 +361,7 @@ describe ContactsController do
|
|
360
361
|
end
|
361
362
|
|
362
363
|
it "should add a new comment to the newly created contact when specified" do
|
363
|
-
@contact =
|
364
|
+
@contact = build(:contact, user: current_user)
|
364
365
|
allow(Contact).to receive(:new).and_return(@contact)
|
365
366
|
|
366
367
|
post :create, params: { contact: { first_name: "Testy", last_name: "McTest" }, account: { name: "Hello world" }, comment_body: "Awesome comment is awesome" }, xhr: true
|
@@ -370,13 +371,13 @@ describe ContactsController do
|
|
370
371
|
|
371
372
|
describe "with invalid params" do
|
372
373
|
before(:each) do
|
373
|
-
@contact =
|
374
|
+
@contact = build(:contact, first_name: nil, user: current_user, lead: nil)
|
374
375
|
allow(Contact).to receive(:new).and_return(@contact)
|
375
376
|
end
|
376
377
|
|
377
378
|
# Redraw [create] form with selected account.
|
378
379
|
it "should redraw [Create Contact] form with selected account" do
|
379
|
-
@account =
|
380
|
+
@account = create(:account, id: 42, user: current_user)
|
380
381
|
|
381
382
|
# This redraws [create] form with blank account.
|
382
383
|
post :create, params: { contact: {}, account: { id: 42, user_id: current_user.id } }, xhr: true
|
@@ -388,7 +389,7 @@ describe ContactsController do
|
|
388
389
|
|
389
390
|
# Redraw [create] form with related account.
|
390
391
|
it "should redraw [Create Contact] form with related account" do
|
391
|
-
@account =
|
392
|
+
@account = create(:account, id: 123, user: current_user)
|
392
393
|
|
393
394
|
request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
|
394
395
|
post :create, params: { contact: { first_name: nil }, account: { name: nil, user_id: current_user.id } }, xhr: true
|
@@ -399,7 +400,7 @@ describe ContactsController do
|
|
399
400
|
end
|
400
401
|
|
401
402
|
it "should redraw [Create Contact] form with blank account" do
|
402
|
-
@accounts = [
|
403
|
+
@accounts = [create(:account, user: current_user)]
|
403
404
|
@account = Account.new(user: current_user)
|
404
405
|
|
405
406
|
post :create, params: { contact: { first_name: nil }, account: { name: nil, user_id: current_user.id } }, xhr: true
|
@@ -410,7 +411,7 @@ describe ContactsController do
|
|
410
411
|
end
|
411
412
|
|
412
413
|
it "should preserve Opportunity when called from Oppotuunity page" do
|
413
|
-
@opportunity =
|
414
|
+
@opportunity = create(:opportunity, id: 987)
|
414
415
|
|
415
416
|
post :create, params: { contact: {}, account: {}, opportunity: 987 }, xhr: true
|
416
417
|
expect(assigns(:opportunity)).to eq(@opportunity)
|
@@ -425,7 +426,7 @@ describe ContactsController do
|
|
425
426
|
describe "responding to PUT update" do
|
426
427
|
describe "with valid params" do
|
427
428
|
it "should update the requested contact and render [update] template" do
|
428
|
-
@contact =
|
429
|
+
@contact = create(:contact, id: 42, first_name: "Billy")
|
429
430
|
|
430
431
|
put :update, params: { id: 42, contact: { first_name: "Bones" }, account: {} }, xhr: true
|
431
432
|
expect(assigns[:contact].first_name).to eq("Bones")
|
@@ -434,7 +435,7 @@ describe ContactsController do
|
|
434
435
|
end
|
435
436
|
|
436
437
|
it "should be able to create a new account and link it to the contact" do
|
437
|
-
@contact =
|
438
|
+
@contact = create(:contact, id: 42, first_name: "Billy")
|
438
439
|
|
439
440
|
put :update, params: { id: 42, contact: { first_name: "Bones" }, account: { name: "new account" } }, xhr: true
|
440
441
|
expect(assigns[:contact].first_name).to eq("Bones")
|
@@ -442,8 +443,8 @@ describe ContactsController do
|
|
442
443
|
end
|
443
444
|
|
444
445
|
it "should be able to link existing account with the contact" do
|
445
|
-
@account =
|
446
|
-
@contact =
|
446
|
+
@account = create(:account, id: 99, name: "Hello world")
|
447
|
+
@contact = create(:contact, id: 42, first_name: "Billy")
|
447
448
|
|
448
449
|
put :update, params: { id: 42, contact: { first_name: "Bones" }, account: { id: 99 } }, xhr: true
|
449
450
|
expect(assigns[:contact].first_name).to eq("Bones")
|
@@ -451,7 +452,7 @@ describe ContactsController do
|
|
451
452
|
end
|
452
453
|
|
453
454
|
it "should update contact permissions when sharing with specific users" do
|
454
|
-
@contact =
|
455
|
+
@contact = create(:contact, id: 42, access: "Public")
|
455
456
|
|
456
457
|
put :update, params: { id: 42, contact: { first_name: "Hello", access: "Shared", user_ids: [7, 8] }, account: {} }, xhr: true
|
457
458
|
expect(assigns[:contact].access).to eq("Shared")
|
@@ -461,7 +462,7 @@ describe ContactsController do
|
|
461
462
|
|
462
463
|
describe "contact got deleted or otherwise unavailable" do
|
463
464
|
it "should reload current page is the contact got deleted" do
|
464
|
-
@contact =
|
465
|
+
@contact = create(:contact, user: current_user)
|
465
466
|
@contact.destroy
|
466
467
|
|
467
468
|
put :update, params: { id: @contact.id }, xhr: true
|
@@ -470,7 +471,7 @@ describe ContactsController do
|
|
470
471
|
end
|
471
472
|
|
472
473
|
it "should reload current page with the flash message if the contact is protected" do
|
473
|
-
@private =
|
474
|
+
@private = create(:contact, user: create(:user), access: "Private")
|
474
475
|
|
475
476
|
put :update, params: { id: @private.id }, xhr: true
|
476
477
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -481,7 +482,7 @@ describe ContactsController do
|
|
481
482
|
|
482
483
|
describe "with invalid params" do
|
483
484
|
it "should not update the contact, but still expose it as @contact and render [update] template" do
|
484
|
-
@contact =
|
485
|
+
@contact = create(:contact, id: 42, user: current_user, first_name: "Billy", lead: nil)
|
485
486
|
|
486
487
|
put :update, params: { id: 42, contact: { first_name: nil }, account: {} }, xhr: true
|
487
488
|
expect(assigns[:contact].reload.first_name).to eq("Billy")
|
@@ -490,8 +491,8 @@ describe ContactsController do
|
|
490
491
|
end
|
491
492
|
|
492
493
|
it "should expose existing account as @account if selected" do
|
493
|
-
@account =
|
494
|
-
@contact =
|
494
|
+
@account = create(:account, id: 99)
|
495
|
+
@contact = create(:contact, id: 42, account: @account)
|
495
496
|
|
496
497
|
put :update, params: { id: 42, contact: { first_name: nil }, account: { id: 99 } }, xhr: true
|
497
498
|
expect(assigns[:account]).to eq(@account)
|
@@ -504,7 +505,7 @@ describe ContactsController do
|
|
504
505
|
#----------------------------------------------------------------------------
|
505
506
|
describe "responding to DELETE destroy" do
|
506
507
|
before(:each) do
|
507
|
-
@contact =
|
508
|
+
@contact = create(:contact, user: current_user)
|
508
509
|
end
|
509
510
|
|
510
511
|
describe "AJAX request" do
|
@@ -549,7 +550,7 @@ describe ContactsController do
|
|
549
550
|
|
550
551
|
describe "contact got deleted or otherwise unavailable" do
|
551
552
|
it "should reload current page is the contact got deleted" do
|
552
|
-
@contact =
|
553
|
+
@contact = create(:contact, user: current_user)
|
553
554
|
@contact.destroy
|
554
555
|
|
555
556
|
delete :destroy, params: { id: @contact.id }, xhr: true
|
@@ -558,7 +559,7 @@ describe ContactsController do
|
|
558
559
|
end
|
559
560
|
|
560
561
|
it "should reload current page with the flash message if the contact is protected" do
|
561
|
-
@private =
|
562
|
+
@private = create(:contact, user: create(:user), access: "Private")
|
562
563
|
|
563
564
|
delete :destroy, params: { id: @private.id }, xhr: true
|
564
565
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -576,7 +577,7 @@ describe ContactsController do
|
|
576
577
|
end
|
577
578
|
|
578
579
|
it "should redirect to contact index with the flash message is the contact got deleted" do
|
579
|
-
@contact =
|
580
|
+
@contact = create(:contact, user: current_user)
|
580
581
|
@contact.destroy
|
581
582
|
|
582
583
|
delete :destroy, params: { id: @contact.id }
|
@@ -585,7 +586,7 @@ describe ContactsController do
|
|
585
586
|
end
|
586
587
|
|
587
588
|
it "should redirect to contact index with the flash message if the contact is protected" do
|
588
|
-
@private =
|
589
|
+
@private = create(:contact, user: create(:user), access: "Private")
|
589
590
|
|
590
591
|
delete :destroy, params: { id: @private.id }
|
591
592
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -600,16 +601,16 @@ describe ContactsController do
|
|
600
601
|
describe "responding to PUT attach" do
|
601
602
|
describe "tasks" do
|
602
603
|
before do
|
603
|
-
@model =
|
604
|
-
@attachment =
|
604
|
+
@model = create(:contact)
|
605
|
+
@attachment = create(:task, asset: nil)
|
605
606
|
end
|
606
607
|
it_should_behave_like("attach")
|
607
608
|
end
|
608
609
|
|
609
610
|
describe "opportunities" do
|
610
611
|
before do
|
611
|
-
@model =
|
612
|
-
@attachment =
|
612
|
+
@model = create(:contact)
|
613
|
+
@attachment = create(:opportunity)
|
613
614
|
end
|
614
615
|
it_should_behave_like("attach")
|
615
616
|
end
|
@@ -621,16 +622,16 @@ describe ContactsController do
|
|
621
622
|
describe "responding to PUT attach" do
|
622
623
|
describe "tasks" do
|
623
624
|
before do
|
624
|
-
@model =
|
625
|
-
@attachment =
|
625
|
+
@model = create(:contact)
|
626
|
+
@attachment = create(:task, asset: nil)
|
626
627
|
end
|
627
628
|
it_should_behave_like("attach")
|
628
629
|
end
|
629
630
|
|
630
631
|
describe "opportunities" do
|
631
632
|
before do
|
632
|
-
@model =
|
633
|
-
@attachment =
|
633
|
+
@model = create(:contact)
|
634
|
+
@attachment = create(:opportunity)
|
634
635
|
end
|
635
636
|
it_should_behave_like("attach")
|
636
637
|
end
|
@@ -642,16 +643,16 @@ describe ContactsController do
|
|
642
643
|
describe "responding to POST discard" do
|
643
644
|
describe "tasks" do
|
644
645
|
before do
|
645
|
-
@model =
|
646
|
-
@attachment =
|
646
|
+
@model = create(:contact)
|
647
|
+
@attachment = create(:task, asset: @model)
|
647
648
|
end
|
648
649
|
it_should_behave_like("discard")
|
649
650
|
end
|
650
651
|
|
651
652
|
describe "opportunities" do
|
652
653
|
before do
|
653
|
-
@attachment =
|
654
|
-
@model =
|
654
|
+
@attachment = create(:opportunity)
|
655
|
+
@model = create(:contact)
|
655
656
|
@model.opportunities << @attachment
|
656
657
|
end
|
657
658
|
it_should_behave_like("discard")
|
@@ -662,7 +663,7 @@ describe ContactsController do
|
|
662
663
|
#----------------------------------------------------------------------------
|
663
664
|
describe "responding to POST auto_complete" do
|
664
665
|
before(:each) do
|
665
|
-
@auto_complete_matches = [
|
666
|
+
@auto_complete_matches = [create(:contact, first_name: "Hello", last_name: "World", user: current_user)]
|
666
667
|
end
|
667
668
|
|
668
669
|
it_should_behave_like("auto complete")
|
@@ -692,8 +693,8 @@ describe ContactsController do
|
|
692
693
|
|
693
694
|
it "should select @contacts and render [index] template" do
|
694
695
|
@contacts = [
|
695
|
-
|
696
|
-
|
696
|
+
create(:contact, first_name: "Alice", user: current_user),
|
697
|
+
create(:contact, first_name: "Bobby", user: current_user)
|
697
698
|
]
|
698
699
|
|
699
700
|
get :redraw, params: { per_page: 1, sort_by: "first_name" }, xhr: true
|