fat_free_crm 0.13.6 → 0.14.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/.rubocop.yml +5 -0
- data/.travis.yml +8 -5
- data/CHANGELOG +26 -0
- data/Gemfile +26 -26
- data/Gemfile.lock +280 -250
- data/Guardfile +0 -1
- data/README.md +7 -9
- data/Rakefile +1 -1
- data/app/assets/javascripts/application.js.erb +1 -0
- data/app/assets/javascripts/crm.js.coffee +6 -7
- data/app/assets/javascripts/search.js.coffee +7 -1
- data/app/assets/stylesheets/about.css.scss +10 -0
- data/app/assets/stylesheets/application.css.erb +2 -0
- data/app/assets/stylesheets/common.scss +1 -1
- data/app/controllers/admin/application_controller.rb +3 -3
- data/app/controllers/admin/field_groups_controller.rb +12 -7
- data/app/controllers/admin/fields_controller.rb +21 -17
- data/app/controllers/admin/groups_controller.rb +10 -4
- data/app/controllers/admin/plugins_controller.rb +1 -2
- data/app/controllers/admin/settings_controller.rb +1 -2
- data/app/controllers/admin/tags_controller.rb +10 -4
- data/app/controllers/admin/users_controller.rb +32 -12
- data/app/controllers/application_controller.rb +58 -38
- data/app/controllers/authentications_controller.rb +5 -8
- data/app/controllers/comments_controller.rb +15 -11
- data/app/controllers/emails_controller.rb +1 -2
- data/app/controllers/entities/accounts_controller.rb +20 -20
- data/app/controllers/entities/campaigns_controller.rb +25 -22
- data/app/controllers/entities/contacts_controller.rb +25 -24
- data/app/controllers/entities/leads_controller.rb +33 -31
- data/app/controllers/entities/opportunities_controller.rb +31 -28
- data/app/controllers/entities_controller.rb +26 -22
- data/app/controllers/home_controller.rb +18 -18
- data/app/controllers/lists_controller.rb +11 -7
- data/app/controllers/passwords_controller.rb +5 -6
- data/app/controllers/tasks_controller.rb +23 -18
- data/app/controllers/users_controller.rb +31 -7
- data/app/helpers/accounts_helper.rb +40 -42
- data/app/helpers/addresses_helper.rb +1 -3
- data/app/helpers/admin/application_helper.rb +4 -4
- data/app/helpers/admin/field_groups_helper.rb +5 -7
- data/app/helpers/admin/fields_helper.rb +2 -3
- data/app/helpers/admin/plugins_helper.rb +0 -1
- data/app/helpers/admin/settings_helper.rb +0 -1
- data/app/helpers/admin/tags_helper.rb +1 -1
- data/app/helpers/admin/users_helper.rb +16 -18
- data/app/helpers/application_helper.rb +127 -119
- data/app/helpers/authentications_helper.rb +0 -1
- data/app/helpers/campaigns_helper.rb +5 -7
- data/app/helpers/comments_helper.rb +0 -1
- data/app/helpers/contacts_helper.rb +0 -1
- data/app/helpers/home_helper.rb +14 -14
- data/app/helpers/javascript_helper.rb +30 -0
- data/app/helpers/leads_helper.rb +7 -7
- data/app/helpers/opportunities_helper.rb +8 -10
- data/app/helpers/passwords_helper.rb +0 -1
- data/app/helpers/tags_helper.rb +1 -3
- data/app/helpers/tasks_helper.rb +24 -26
- data/app/helpers/users_helper.rb +6 -7
- data/app/helpers/versions_helper.rb +3 -5
- data/app/inputs/date_pair_input.rb +6 -7
- data/app/inputs/date_time_input.rb +3 -4
- data/app/inputs/datetime_pair_input.rb +0 -1
- data/app/inputs/text_input.rb +2 -2
- data/app/mailers/dropbox_mailer.rb +4 -7
- data/app/mailers/subscription_mailer.rb +4 -5
- data/app/mailers/user_mailer.rb +7 -9
- data/app/models/entities/account.rb +31 -28
- data/app/models/entities/account_contact.rb +2 -1
- data/app/models/entities/account_opportunity.rb +1 -1
- data/app/models/entities/campaign.rb +22 -19
- data/app/models/entities/contact.rb +55 -53
- data/app/models/entities/contact_opportunity.rb +1 -1
- data/app/models/entities/lead.rb +49 -41
- data/app/models/entities/opportunity.rb +38 -38
- data/app/models/fields/custom_field.rb +21 -27
- data/app/models/fields/custom_field_date_pair.rb +7 -8
- data/app/models/fields/custom_field_datetime_pair.rb +0 -2
- data/app/models/fields/custom_field_pair.rb +8 -10
- data/app/models/fields/field.rb +29 -30
- data/app/models/fields/field_group.rb +4 -4
- data/app/models/list.rb +1 -1
- data/app/models/observers/entity_observer.rb +1 -1
- data/app/models/observers/lead_observer.rb +1 -1
- data/app/models/observers/opportunity_observer.rb +1 -1
- data/app/models/observers/task_observer.rb +1 -1
- data/app/models/polymorphic/address.rb +7 -7
- data/app/models/polymorphic/avatar.rb +8 -9
- data/app/models/polymorphic/comment.rb +16 -10
- data/app/models/polymorphic/email.rb +13 -6
- data/app/models/polymorphic/tag.rb +2 -2
- data/app/models/polymorphic/task.rb +45 -45
- data/{config/initializers/paper_trail.rb → app/models/polymorphic/version.rb} +26 -31
- data/app/models/setting.rb +12 -17
- data/app/models/users/ability.rb +5 -6
- data/app/models/users/authentication.rb +6 -5
- data/app/models/users/group.rb +1 -3
- data/app/models/users/permission.rb +3 -3
- data/app/models/users/preference.rb +7 -7
- data/app/models/users/user.rb +36 -43
- data/app/views/accounts/_top_section.html.haml +2 -2
- data/app/views/accounts/edit.js.haml +0 -1
- data/app/views/admin/fields/_field.html.haml +1 -1
- data/app/views/admin/tags/_tag.html.haml +1 -1
- data/app/views/admin/users/_user.html.haml +4 -4
- data/app/views/campaigns/_top_section.html.haml +1 -1
- data/app/views/campaigns/edit.js.haml +0 -2
- data/app/views/contacts/_top_section.html.haml +1 -1
- data/app/views/contacts/edit.js.haml +0 -1
- data/app/views/entities/_basic_search.html.haml +1 -1
- data/app/views/home/_account.html.haml +2 -2
- data/app/views/home/_opportunity.html.haml +2 -2
- data/app/views/layouts/_about.html.haml +1 -1
- data/app/views/leads/_top_section.html.haml +1 -1
- data/app/views/leads/edit.js.haml +0 -2
- data/app/views/lists/_sidebar.html.haml +1 -1
- data/app/views/opportunities/_top_section.html.haml +2 -2
- data/app/views/opportunities/edit.js.haml +0 -1
- data/app/views/shared/_tags.html.haml +2 -1
- data/app/views/tasks/_edit.html.haml +2 -3
- data/app/views/tasks/_top_section.html.haml +1 -1
- data/app/views/users/_user.html.haml +2 -1
- data/app/views/users/opportunities_overview.html.haml +2 -2
- data/bin/bundle +3 -0
- data/bin/rails +4 -0
- data/bin/rake +4 -0
- data/config/application.rb +16 -33
- data/config/boot.rb +1 -1
- data/config/database.mysql.mac.yml +1 -0
- data/config/database.mysql.yml +1 -0
- data/config/database.postgres.docker.yml +1 -1
- data/config/database.postgres.yml +1 -0
- data/config/database.sqlite.yml +1 -0
- data/config/deploy.example.rb +3 -5
- data/config/environments/development.rb +13 -14
- data/config/environments/production.rb +8 -7
- data/config/environments/staging.rb +43 -41
- data/config/environments/test.rb +12 -14
- data/config/initializers/assets.rb +14 -0
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/cookies_serializer.rb +3 -0
- data/config/initializers/custom_field_ransack_translations.rb +1 -1
- data/config/initializers/filter_parameter_logging.rb +4 -0
- data/config/initializers/inflections.rb +16 -0
- data/config/initializers/mime_types.rb +0 -1
- data/config/initializers/paginate_arrays.rb +0 -1
- data/config/initializers/ransack.rb +5 -5
- data/config/initializers/session_store.rb +5 -0
- data/config/initializers/simple_form.rb +1 -1
- data/config/initializers/views.rb +33 -33
- data/config/initializers/wrap_parameters.rb +14 -0
- data/config/locales/cz_fat_free_crm.yml +1 -1
- data/config/locales/de_fat_free_crm.yml +2 -2
- data/config/locales/en-GB_fat_free_crm.yml +2 -3
- data/config/locales/en-US_fat_free_crm.yml +2 -3
- data/config/locales/en.yml +23 -0
- data/config/locales/es-CL.yml +227 -0
- data/config/locales/es-CL_fat_free_crm.yml +929 -0
- data/config/locales/es-CL_ransack.yml +91 -0
- data/config/locales/es.yml +53 -59
- data/config/locales/es_fat_free_crm.yml +708 -370
- data/config/locales/es_ransack.yml +91 -0
- data/config/locales/fr-CA_fat_free_crm.yml +7 -7
- data/config/locales/fr_fat_free_crm.yml +285 -81
- data/config/locales/it_fat_free_crm.yml +1 -1
- data/config/locales/ja_fat_free_crm.yml +1 -1
- data/config/locales/nl.yml +210 -0
- data/config/locales/nl_fat_free_crm.yml +920 -0
- data/config/locales/nl_ransack.yml +91 -0
- data/config/locales/pl_fat_free_crm.yml +1 -1
- data/config/locales/pt-BR_fat_free_crm.yml +111 -38
- data/config/locales/ru_fat_free_crm.yml +3 -4
- data/config/locales/sv-SE_fat_free_crm.yml +1 -1
- data/config/locales/th.rb +157 -158
- data/config/locales/th_fat_free_crm.yml +1 -1
- data/config/locales/zh-CN_fat_free_crm.yml +3 -4
- data/config/routes.rb +93 -94
- data/config/unicorn.rb +25 -2
- data/custom_plan.rb +0 -2
- data/db/demo/accounts.yml +4 -5
- data/db/demo/addresses.yml +5 -5
- data/db/demo/campaigns.yml +2 -2
- data/db/demo/comments.yml +1 -1
- data/db/demo/contacts.yml +8 -8
- data/db/demo/emails.yml +5 -5
- data/db/demo/leads.yml +10 -10
- data/db/demo/opportunities.yml +2 -2
- data/db/demo/tasks.yml +2 -2
- data/db/demo/users.yml +12 -16
- data/db/migrate/20100928030598_create_sessions.rb +1 -2
- data/db/migrate/20100928030599_create_users.rb +24 -25
- data/db/migrate/20100928030600_create_openid_tables.rb +11 -12
- data/db/migrate/20100928030601_create_accounts.rb +14 -15
- data/db/migrate/20100928030602_create_permissions.rb +2 -3
- data/db/migrate/20100928030603_create_settings.rb +4 -5
- data/db/migrate/20100928030604_create_preferences.rb +3 -4
- data/db/migrate/20100928030605_create_campaigns.rb +19 -20
- data/db/migrate/20100928030606_create_leads.rb +26 -27
- data/db/migrate/20100928030607_create_contacts.rb +26 -27
- data/db/migrate/20100928030608_create_opportunities.rb +15 -16
- data/db/migrate/20100928030609_create_account_contacts.rb +2 -3
- data/db/migrate/20100928030610_create_account_opportunities.rb +2 -3
- data/db/migrate/20100928030611_create_contact_opportunities.rb +3 -4
- data/db/migrate/20100928030612_create_tasks.rb +14 -15
- data/db/migrate/20100928030613_create_comments.rb +6 -7
- data/db/migrate/20100928030614_create_activities.rb +6 -7
- data/db/migrate/20100928030615_create_avatars.rb +5 -6
- data/db/migrate/20100928030616_rename_remember_token.rb +0 -1
- data/db/migrate/20100928030617_drop_openid_tables.rb +11 -11
- data/db/migrate/20100928030618_add_admin_to_users.rb +1 -2
- data/db/migrate/20100928030619_add_suspended_to_users.rb +0 -1
- data/db/migrate/20100928030620_remove_uuid.rb +3 -3
- data/db/migrate/20100928030621_add_email_to_accounts.rb +1 -2
- data/db/migrate/20100928030622_add_background_info_to_models.rb +0 -1
- data/db/migrate/20100928030623_create_addresses.rb +14 -16
- data/db/migrate/20100928030624_add_index_on_permissions.rb +2 -3
- data/db/migrate/20100928030625_create_emails.rb +15 -16
- data/db/migrate/20100928030626_add_state_to_timeline_objects.rb +2 -3
- data/db/migrate/20100928030627_acts_as_taggable_on_migration.rb +2 -3
- data/db/migrate/20101221123456_add_single_access_token_to_users.rb +0 -1
- data/db/migrate/20101221345678_add_rating_and_category_to_accounts.rb +2 -3
- data/db/migrate/20110719082054_add_skype_to_contacts_and_leads.rb +2 -3
- data/db/migrate/20111101083437_create_fields.rb +14 -15
- data/db/migrate/20111101090312_create_field_groups.rb +4 -5
- data/db/migrate/20111116091952_add_field_groups_tag_id.rb +0 -1
- data/db/migrate/20111117041311_change_fields_collection_to_text.rb +0 -1
- data/db/migrate/20111201030535_add_field_groups_klass_name.rb +4 -4
- data/db/migrate/20120121054235_create_lists.rb +1 -1
- data/db/migrate/20120216031616_create_versions.rb +5 -5
- data/db/migrate/20120216042541_is_paranoid_to_paper_trail.rb +1 -3
- data/db/migrate/20120224073107_remove_default_value_and_clear_settings.rb +1 -1
- data/db/migrate/20120316045804_activities_to_versions.rb +6 -6
- data/db/migrate/20120405080727_change_subscribed_users_to_set.rb +5 -5
- data/db/migrate/20120405080742_change_further_subscribed_users_to_set.rb +5 -5
- data/db/migrate/20120406082136_create_groups.rb +1 -1
- data/db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb +2 -1
- data/db/migrate/20120528102124_increase_length_of_version_events.rb +2 -2
- data/db/migrate/20121003063155_add_settings_to_custom_fields.rb +1 -1
- data/db/migrate/20121221033947_fix_country_mapping.rb +0 -1
- data/db/migrate/20131207033244_add_user_id_to_lists.rb +1 -1
- data/db/migrate/20141126031837_increase_email_to254_chars.rb +14 -14
- data/db/migrate/20141230021159_add_transaction_id_column_to_versions.rb +11 -0
- data/db/migrate/20141230205453_add_missing_unique_indices.acts_as_taggable_on_engine.rb +20 -0
- data/db/migrate/20141230205454_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +15 -0
- data/db/migrate/20141230205455_add_missing_taggable_index.acts_as_taggable_on_engine.rb +10 -0
- data/db/migrate/20150123060900_convert_radio_to_radio_buttons.rb +10 -0
- data/db/migrate/20150227123054_remove_last_request_at_from_users.rb +5 -0
- data/db/migrate/20150427131956_create_index_related_type.rb +9 -0
- data/db/migrate/20160511053730_add_account_contacts_index.rb +5 -0
- data/db/schema.rb +236 -228
- data/db/seeds.rb +1 -2
- data/db/seeds/fields.rb +36 -37
- data/{fig.yml → docker-compose.yml} +0 -0
- data/fat_free_crm.gemspec +31 -18
- data/lib/development_tasks/license.rake +29 -29
- data/lib/fat_free_crm.rb +1 -5
- data/lib/fat_free_crm/callback.rb +28 -20
- data/lib/fat_free_crm/comment_extensions.rb +1 -1
- data/lib/fat_free_crm/core_ext.rb +1 -1
- data/lib/fat_free_crm/core_ext/nil.rb +0 -3
- data/lib/fat_free_crm/core_ext/string.rb +7 -21
- data/lib/fat_free_crm/custom_fields.rb +2 -2
- data/lib/fat_free_crm/engine.rb +14 -0
- data/lib/fat_free_crm/errors.rb +0 -2
- data/lib/fat_free_crm/exceptions.rb +3 -4
- data/lib/fat_free_crm/export_csv.rb +0 -2
- data/lib/fat_free_crm/exportable.rb +5 -7
- data/lib/fat_free_crm/fields.rb +7 -8
- data/lib/fat_free_crm/gem_dependencies.rb +4 -1
- data/lib/fat_free_crm/gem_ext/active_record/schema_dumper.rb +2 -2
- data/lib/fat_free_crm/gem_ext/active_support/buffered_logger.rb +0 -3
- data/lib/fat_free_crm/gem_ext/rails/engine.rb +5 -12
- data/lib/fat_free_crm/gem_ext/rake/task.rb +1 -1
- data/lib/fat_free_crm/gem_ext/simple_form/action_view_extensions/form_helper.rb +1 -2
- data/lib/fat_free_crm/i18n.rb +2 -3
- data/lib/fat_free_crm/load_settings.rb +0 -2
- data/lib/fat_free_crm/mail_processor/base.rb +15 -16
- data/lib/fat_free_crm/mail_processor/comment_replies.rb +5 -10
- data/lib/fat_free_crm/mail_processor/dropbox.rb +56 -59
- data/lib/fat_free_crm/permissions.rb +18 -15
- data/lib/fat_free_crm/renderers.rb +2 -2
- data/lib/fat_free_crm/secret_token_generator.rb +3 -9
- data/lib/fat_free_crm/sortable.rb +4 -8
- data/lib/fat_free_crm/version.rb +2 -2
- data/lib/fat_free_crm/view_factory.rb +3 -8
- data/lib/gravatar_image_tag.rb +19 -24
- data/lib/missing_translation_detector.rb +10 -10
- data/lib/tasks/ffcrm/comment_replies.rake +3 -5
- data/lib/tasks/ffcrm/config.rake +3 -5
- data/lib/tasks/ffcrm/demo.rake +14 -16
- data/lib/tasks/ffcrm/dropbox.rake +3 -5
- data/lib/tasks/ffcrm/missing_translations.rake +1 -1
- data/lib/tasks/ffcrm/secret.rake +1 -3
- data/lib/tasks/ffcrm/settings.rake +2 -4
- data/lib/tasks/ffcrm/setup.rake +3 -6
- data/lib/tasks/ffcrm/update_data.rake +110 -116
- data/spec/controllers/admin/groups_controller_spec.rb +0 -1
- data/spec/controllers/admin/users_controller_spec.rb +98 -102
- data/spec/controllers/applications_controller_spec.rb +17 -21
- data/spec/controllers/authentications_controller_spec.rb +57 -61
- data/spec/controllers/comments_controller_spec.rb +32 -39
- data/spec/controllers/emails_controller_spec.rb +6 -7
- data/spec/controllers/entities/accounts_controller_spec.rb +204 -214
- data/spec/controllers/entities/campaigns_controller_spec.rb +210 -224
- data/spec/controllers/entities/contacts_controller_spec.rb +250 -270
- data/spec/controllers/entities/leads_controller_spec.rb +415 -438
- data/spec/controllers/entities/opportunities_controller_spec.rb +344 -359
- data/spec/controllers/entities_controller_spec.rb +10 -14
- data/spec/controllers/home_controller_spec.rb +85 -92
- data/spec/controllers/lists_controller_spec.rb +0 -1
- data/spec/controllers/passwords_controller_spec.rb +5 -9
- data/spec/controllers/tasks_controller_spec.rb +193 -210
- data/spec/controllers/users_controller_spec.rb +137 -146
- data/spec/factories/account_factories.rb +11 -13
- data/spec/factories/campaign_factories.rb +6 -6
- data/spec/factories/contact_factories.rb +21 -22
- data/spec/factories/field_factories.rb +8 -10
- data/spec/factories/lead_factories.rb +16 -16
- data/spec/factories/list_factories.rb +2 -2
- data/spec/factories/opportunity_factories.rb +8 -10
- data/spec/factories/sequences.rb +8 -9
- data/spec/factories/setting_factories.rb +2 -2
- data/spec/factories/shared_factories.rb +26 -30
- data/spec/factories/tag_factories.rb +1 -1
- data/spec/factories/task_factories.rb +11 -11
- data/spec/factories/user_factories.rb +22 -27
- data/spec/features/acceptance_helper.rb +1 -1
- data/spec/features/accounts_spec.rb +65 -61
- data/spec/features/admin/groups_spec.rb +11 -12
- data/spec/features/admin/users_spec.rb +17 -19
- data/spec/features/campaigns_spec.rb +61 -57
- data/spec/features/contacts_spec.rb +90 -59
- data/spec/features/dashboard_spec.rb +20 -21
- data/spec/features/leads_spec.rb +88 -67
- data/spec/features/opportunities_overview_spec.rb +31 -31
- data/spec/features/opportunities_spec.rb +64 -60
- data/spec/features/support/browser.rb +2 -2
- data/spec/features/support/headless.rb +1 -1
- data/spec/features/support/helpers.rb +5 -6
- data/spec/features/support/paths.rb +1 -2
- data/spec/features/support/selector_helpers.rb +2 -2
- data/spec/features/tasks_spec.rb +60 -54
- data/spec/helpers/accounts_helper_spec.rb +2 -5
- data/spec/helpers/admin/field_groups_helper_spec.rb +4 -4
- data/spec/helpers/admin/plugins_helper_spec.rb +0 -1
- data/spec/helpers/admin/settings_helper_spec.rb +0 -1
- data/spec/helpers/admin/users_helper_spec.rb +0 -1
- data/spec/helpers/application_helper_spec.rb +30 -33
- data/spec/helpers/authentications_helper_spec.rb +2 -5
- data/spec/helpers/campaigns_helper_spec.rb +2 -5
- data/spec/helpers/comments_helper_spec.rb +2 -5
- data/spec/helpers/contacts_helper_spec.rb +2 -5
- data/spec/helpers/emails_helper_spec.rb +0 -1
- data/spec/helpers/fields_helper_spec.rb +0 -1
- data/spec/helpers/groups_helper_spec.rb +0 -1
- data/spec/helpers/home_helper_spec.rb +2 -5
- data/spec/helpers/leads_helper_spec.rb +2 -5
- data/spec/helpers/lists_helper_spec.rb +0 -1
- data/spec/helpers/opportunities_helper_spec.rb +2 -5
- data/spec/helpers/passwords_helper_spec.rb +2 -5
- data/spec/helpers/tasks_helper_spec.rb +1 -5
- data/spec/helpers/users_helper_spec.rb +9 -11
- data/spec/lib/comment_extensions_spec.rb +3 -3
- data/spec/lib/core_ext/string_spec.rb +1 -1
- data/spec/lib/errors_spec.rb +10 -10
- data/spec/lib/fields_spec.rb +23 -33
- data/spec/lib/mail_processor/base_spec.rb +41 -43
- data/spec/lib/mail_processor/comment_replies_spec.rb +17 -17
- data/spec/lib/mail_processor/dropbox_spec.rb +91 -95
- data/spec/lib/mail_processor/sample_emails/dropbox.rb +13 -14
- data/spec/lib/permissions_spec.rb +44 -47
- data/spec/lib/secret_token_generator_spec.rb +16 -28
- data/spec/lib/view_factory_spec.rb +18 -24
- data/spec/mailers/subscription_mailer_spec.rb +14 -16
- data/spec/mailers/user_mailer_spec.rb +33 -34
- data/spec/models/entities/account_contact_spec.rb +2 -3
- data/spec/models/entities/account_opportunity_spec.rb +2 -3
- data/spec/models/entities/account_spec.rb +52 -59
- data/spec/models/entities/campaign_spec.rb +32 -39
- data/spec/models/entities/contact_opportunity_spec.rb +2 -3
- data/spec/models/entities/contact_spec.rb +71 -72
- data/spec/models/entities/lead_spec.rb +15 -22
- data/spec/models/entities/opportunity_spec.rb +104 -103
- data/spec/models/fields/custom_field_date_pair_spec.rb +38 -44
- data/spec/models/fields/custom_field_pair_spec.rb +28 -36
- data/spec/models/fields/custom_field_spec.rb +50 -56
- data/spec/models/fields/field_group_spec.rb +1 -2
- data/spec/models/fields/field_spec.rb +13 -15
- data/spec/models/list_spec.rb +4 -4
- data/spec/models/observers/entity_observer_spec.rb +18 -21
- data/spec/models/polymorphic/address_spec.rb +1 -3
- data/spec/models/polymorphic/avatar_spec.rb +6 -8
- data/spec/models/polymorphic/comment_spec.rb +7 -9
- data/spec/models/polymorphic/email_spec.rb +1 -2
- data/spec/models/polymorphic/task_spec.rb +130 -142
- data/spec/models/polymorphic/version_spec.rb +84 -91
- data/spec/models/setting_spec.rb +17 -19
- data/spec/models/users/abilities/user_ability_spec.rb +25 -20
- data/spec/models/users/authentication_spec.rb +0 -1
- data/spec/models/users/group_spec.rb +0 -1
- data/spec/models/users/permission_spec.rb +12 -13
- data/spec/models/users/preference_spec.rb +15 -15
- data/spec/models/users/user_spec.rb +53 -55
- data/spec/routing/accounts_routing_spec.rb +12 -14
- data/spec/routing/admin/users_routing_spec.rb +7 -9
- data/spec/routing/campaigns_routing_spec.rb +13 -14
- data/spec/routing/comments_routing_spec.rb +5 -6
- data/spec/routing/contacts_routing_spec.rb +12 -14
- data/spec/routing/emails_routing_spec.rb +7 -8
- data/spec/routing/leads_routing_spec.rb +19 -21
- data/spec/routing/opportunities_routing_spec.rb +13 -15
- data/spec/routing/tasks_routing_spec.rb +14 -15
- data/spec/routing/users_routing_spec.rb +18 -19
- data/spec/shared/controllers.rb +35 -35
- data/spec/shared/models.rb +52 -55
- data/spec/spec_helper.rb +21 -42
- data/spec/support/assert_select.rb +19 -18
- data/spec/support/auth_macros.rb +3 -3
- data/spec/support/macros.rb +5 -6
- data/spec/support/mail_processor_mocks.rb +11 -11
- data/spec/views/accounts/_edit.haml_spec.rb +9 -9
- data/spec/views/accounts/_new.haml_spec.rb +8 -9
- data/spec/views/accounts/create.js.haml_spec.rb +11 -12
- data/spec/views/accounts/destroy.js.haml_spec.rb +6 -7
- data/spec/views/accounts/edit.js.haml_spec.rb +12 -13
- data/spec/views/accounts/index.haml_spec.rb +8 -8
- data/spec/views/accounts/index.js.haml_spec.rb +7 -8
- data/spec/views/accounts/new.js.haml_spec.rb +7 -8
- data/spec/views/accounts/show.haml_spec.rb +11 -12
- data/spec/views/accounts/update.js.haml_spec.rb +18 -18
- data/spec/views/admin/field_groups/create.js.haml_spec.rb +8 -10
- data/spec/views/admin/field_groups/destroy.js.haml_spec.rb +7 -9
- data/spec/views/admin/field_groups/edit.js.haml_spec.rb +5 -7
- data/spec/views/admin/field_groups/new.js.haml_spec.rb +6 -8
- data/spec/views/admin/field_groups/update.js.haml_spec.rb +7 -9
- data/spec/views/admin/users/_create.haml_spec.rb +4 -4
- data/spec/views/admin/users/create.js.haml_spec.rb +8 -9
- data/spec/views/admin/users/destroy.js.haml_spec.rb +6 -6
- data/spec/views/admin/users/edit.js.haml_spec.rb +7 -9
- data/spec/views/admin/users/index.haml_spec.rb +4 -5
- data/spec/views/admin/users/index.js.haml_spec.rb +6 -8
- data/spec/views/admin/users/new.js.haml_spec.rb +4 -6
- data/spec/views/admin/users/reactivate.js.haml_spec.rb +4 -4
- data/spec/views/admin/users/show.haml_spec.rb +0 -1
- data/spec/views/admin/users/suspend.js.haml_spec.rb +4 -4
- data/spec/views/admin/users/update.js.haml_spec.rb +6 -7
- data/spec/views/application/auto_complete.haml_spec.rb +12 -14
- data/spec/views/authentications/new.haml_spec.rb +6 -7
- data/spec/views/campaigns/_edit.haml_spec.rb +9 -9
- data/spec/views/campaigns/_new.haml_spec.rb +8 -8
- data/spec/views/campaigns/create.js.haml_spec.rb +11 -12
- data/spec/views/campaigns/destroy.js.haml_spec.rb +7 -8
- data/spec/views/campaigns/edit.js.haml_spec.rb +12 -20
- data/spec/views/campaigns/index.haml_spec.rb +6 -7
- data/spec/views/campaigns/index.js.haml_spec.rb +9 -10
- data/spec/views/campaigns/new.js.haml_spec.rb +7 -8
- data/spec/views/campaigns/show.haml_spec.rb +12 -13
- data/spec/views/campaigns/update.js.haml_spec.rb +16 -16
- data/spec/views/comments/edit.js.haml_spec.rb +7 -7
- data/spec/views/contacts/_edit.haml_spec.rb +21 -21
- data/spec/views/contacts/_new.haml_spec.rb +12 -13
- data/spec/views/contacts/create.js.haml_spec.rb +12 -13
- data/spec/views/contacts/destroy.js.haml_spec.rb +6 -7
- data/spec/views/contacts/edit.js.haml_spec.rb +15 -17
- data/spec/views/contacts/index.haml_spec.rb +6 -7
- data/spec/views/contacts/index.js.html_spec.rb +7 -8
- data/spec/views/contacts/new.js.haml_spec.rb +8 -9
- data/spec/views/contacts/show.haml_spec.rb +9 -10
- data/spec/views/contacts/update.js.haml_spec.rb +26 -26
- data/spec/views/home/index.haml_spec.rb +4 -5
- data/spec/views/home/index.js.haml_spec.rb +6 -7
- data/spec/views/home/options.js.haml_spec.rb +10 -10
- data/spec/views/leads/_convert.haml_spec.rb +5 -6
- data/spec/views/leads/_edit.haml_spec.rb +13 -13
- data/spec/views/leads/_new.haml_spec.rb +11 -11
- data/spec/views/leads/_sidebar_show.haml_spec.rb +9 -9
- data/spec/views/leads/convert.js.haml_spec.rb +16 -17
- data/spec/views/leads/create.js.haml_spec.rb +16 -17
- data/spec/views/leads/destroy.js.haml_spec.rb +10 -11
- data/spec/views/leads/edit.js.haml_spec.rb +16 -17
- data/spec/views/leads/index.haml_spec.rb +7 -8
- data/spec/views/leads/index.js.haml_spec.rb +10 -11
- data/spec/views/leads/new.js.haml_spec.rb +8 -9
- data/spec/views/leads/promote.js.haml_spec.rb +30 -31
- data/spec/views/leads/reject.js.haml_spec.rb +10 -11
- data/spec/views/leads/show.haml_spec.rb +7 -8
- data/spec/views/leads/update.js.haml_spec.rb +28 -29
- data/spec/views/opportunities/_edit.haml_spec.rb +19 -19
- data/spec/views/opportunities/_new.haml_spec.rb +10 -10
- data/spec/views/opportunities/create.js.haml_spec.rb +19 -20
- data/spec/views/opportunities/destroy.js.haml_spec.rb +14 -15
- data/spec/views/opportunities/edit.js.haml_spec.rb +14 -16
- data/spec/views/opportunities/index.haml_spec.rb +6 -7
- data/spec/views/opportunities/index.js.haml_spec.rb +7 -8
- data/spec/views/opportunities/new.js.haml_spec.rb +8 -9
- data/spec/views/opportunities/show.haml_spec.rb +9 -10
- data/spec/views/opportunities/update.js.haml_spec.rb +35 -35
- data/spec/views/tasks/_edit.haml_spec.rb +9 -9
- data/spec/views/tasks/complete.js.haml_spec.rb +11 -12
- data/spec/views/tasks/create.js.haml_spec.rb +29 -31
- data/spec/views/tasks/destroy.js.haml_spec.rb +8 -8
- data/spec/views/tasks/edit.js.haml_spec.rb +12 -15
- data/spec/views/tasks/index.haml_spec.rb +7 -7
- data/spec/views/tasks/new.js.haml_spec.rb +7 -8
- data/spec/views/tasks/uncomplete.js.haml_spec.rb +6 -6
- data/spec/views/tasks/update.js.haml_spec.rb +41 -44
- data/spec/views/users/avatar.js.haml_spec.rb +7 -8
- data/spec/views/users/change_password.js.haml_spec.rb +9 -10
- data/spec/views/users/edit.js.haml_spec.rb +7 -8
- data/spec/views/users/password.js.haml_spec.rb +8 -9
- data/spec/views/users/update.js.haml_spec.rb +6 -7
- data/spec/views/users/upload_avatar.js.haml_spec.rb +9 -9
- data/vendor/assets/javascripts/jquery_timeago/index.js +2 -0
- data/vendor/assets/javascripts/jquery_timeago/jquery.timeago.es-CL.js +18 -0
- data/vendor/assets/javascripts/jquery_timeago/jquery.timeago.nl.js +20 -0
- data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-es-CL.js +20 -0
- data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-es-CL.js +23 -0
- data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-nl.js +21 -0
- data/vendor/assets/stylesheets/{jquery-ui.custom.css → jquery-ui.custom.scss} +52 -51
- data/vendor/gems/globby-0.1.2/LICENSE.txt +20 -0
- data/vendor/gems/globby-0.1.2/README.md +65 -0
- data/vendor/gems/globby-0.1.2/Rakefile +9 -0
- data/vendor/gems/globby-0.1.2/lib/globby.rb +47 -0
- data/vendor/gems/globby-0.1.2/lib/globby/glob.rb +90 -0
- data/vendor/gems/globby-0.1.2/lib/globby/globject.rb +18 -0
- data/vendor/gems/globby-0.1.2/lib/globby/result.rb +20 -0
- data/vendor/gems/globby-0.1.2/spec/gitignore_spec.rb +109 -0
- data/vendor/gems/globby-0.1.2/spec/globby_spec.rb +93 -0
- metadata +177 -55
- data/Gemfile.ci +0 -13
- data/config/initializers/sass.rb +0 -18
- data/lib/country_select.rb +0 -570
- data/lib/fat_free_crm/plugin.rb +0 -94
@@ -6,7 +6,6 @@
|
|
6
6
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
7
7
|
|
8
8
|
describe LeadsController do
|
9
|
-
|
10
9
|
before(:each) do
|
11
10
|
require_user
|
12
11
|
set_current_tab(:leads)
|
@@ -16,102 +15,101 @@ describe LeadsController do
|
|
16
15
|
# GET /leads.xml AJAX and HTML
|
17
16
|
#----------------------------------------------------------------------------
|
18
17
|
describe "responding to GET index" do
|
19
|
-
|
20
18
|
it "should expose all leads as @leads and render [index] template" do
|
21
|
-
@leads = [
|
19
|
+
@leads = [FactoryGirl.create(:lead, user: current_user)]
|
22
20
|
|
23
21
|
get :index
|
24
|
-
assigns[:leads].
|
25
|
-
response.
|
22
|
+
expect(assigns[:leads]).to eq(@leads)
|
23
|
+
expect(response).to render_template("leads/index")
|
26
24
|
end
|
27
25
|
|
28
26
|
it "should collect the data for the leads sidebar" do
|
29
|
-
@leads = [
|
27
|
+
@leads = [FactoryGirl.create(:lead, user: current_user)]
|
30
28
|
@status = Setting.lead_status.dup
|
31
29
|
|
32
30
|
get :index
|
33
|
-
(assigns[:lead_status_total].keys.map(&:to_sym) - (@status << :all << :other)).
|
31
|
+
expect(assigns[:lead_status_total].keys.map(&:to_sym) - (@status << :all << :other)).to eq([])
|
34
32
|
end
|
35
33
|
|
36
34
|
it "should filter out leads by status" do
|
37
35
|
controller.session[:leads_filter] = "new,contacted"
|
38
36
|
@leads = [
|
39
|
-
FactoryGirl.create(:lead, :
|
40
|
-
FactoryGirl.create(:lead, :
|
37
|
+
FactoryGirl.create(:lead, status: "new", user: current_user),
|
38
|
+
FactoryGirl.create(:lead, status: "contacted", user: current_user)
|
41
39
|
]
|
42
40
|
|
43
41
|
# This one should be filtered out.
|
44
|
-
FactoryGirl.create(:lead, :
|
42
|
+
FactoryGirl.create(:lead, status: "rejected", user: current_user)
|
45
43
|
|
46
44
|
get :index
|
47
45
|
# Note: can't compare campaigns directly because of BigDecimals.
|
48
|
-
assigns[:leads].size.
|
49
|
-
assigns[:leads].map(&:status).sort.
|
46
|
+
expect(assigns[:leads].size).to eq(2)
|
47
|
+
expect(assigns[:leads].map(&:status).sort).to eq(%w(contacted new))
|
50
48
|
end
|
51
49
|
|
52
50
|
it "should perform lookup using query string" do
|
53
|
-
@billy_bones = FactoryGirl.create(:lead, :
|
54
|
-
@captain_flint = FactoryGirl.create(:lead, :
|
51
|
+
@billy_bones = FactoryGirl.create(:lead, user: current_user, first_name: "Billy", last_name: "Bones")
|
52
|
+
@captain_flint = FactoryGirl.create(:lead, user: current_user, first_name: "Captain", last_name: "Flint")
|
55
53
|
|
56
|
-
get :index, :
|
57
|
-
assigns[:leads].
|
58
|
-
assigns[:current_query].
|
59
|
-
session[:leads_current_query].
|
54
|
+
get :index, query: "bill"
|
55
|
+
expect(assigns[:leads]).to eq([@billy_bones])
|
56
|
+
expect(assigns[:current_query]).to eq("bill")
|
57
|
+
expect(session[:leads_current_query]).to eq("bill")
|
60
58
|
end
|
61
59
|
|
62
60
|
describe "AJAX pagination" do
|
63
61
|
it "should pick up page number from params" do
|
64
|
-
@leads = [
|
65
|
-
xhr :get, :index, :
|
62
|
+
@leads = [FactoryGirl.create(:lead, user: current_user)]
|
63
|
+
xhr :get, :index, page: 42
|
66
64
|
|
67
|
-
assigns[:current_page].to_i.
|
68
|
-
assigns[:leads].
|
69
|
-
session[:leads_current_page].to_i.
|
70
|
-
response.
|
65
|
+
expect(assigns[:current_page].to_i).to eq(42)
|
66
|
+
expect(assigns[:leads]).to eq([]) # page #42 should be empty if there's only one lead ;-)
|
67
|
+
expect(session[:leads_current_page].to_i).to eq(42)
|
68
|
+
expect(response).to render_template("leads/index")
|
71
69
|
end
|
72
70
|
|
73
71
|
it "should pick up saved page number from session" do
|
74
72
|
session[:leads_current_page] = 42
|
75
73
|
session[:leads_current_query] = "bill"
|
76
|
-
@leads = [
|
77
|
-
xhr :get, :index, :
|
74
|
+
@leads = [FactoryGirl.create(:lead, user: current_user)]
|
75
|
+
xhr :get, :index, query: "bill"
|
78
76
|
|
79
|
-
assigns[:current_page].
|
80
|
-
assigns[:leads].
|
81
|
-
response.
|
77
|
+
expect(assigns[:current_page]).to eq(42)
|
78
|
+
expect(assigns[:leads]).to eq([])
|
79
|
+
expect(response).to render_template("leads/index")
|
82
80
|
end
|
83
81
|
|
84
82
|
it "should reset current_page when query is altered" do
|
85
83
|
session[:leads_current_page] = 42
|
86
84
|
session[:leads_current_query] = "bill"
|
87
|
-
@leads = [
|
85
|
+
@leads = [FactoryGirl.create(:lead, user: current_user)]
|
88
86
|
xhr :get, :index
|
89
87
|
|
90
|
-
assigns[:current_page].
|
91
|
-
assigns[:leads].
|
92
|
-
response.
|
88
|
+
expect(assigns[:current_page]).to eq(1)
|
89
|
+
expect(assigns[:leads]).to eq(@leads)
|
90
|
+
expect(response).to render_template("leads/index")
|
93
91
|
end
|
94
92
|
end
|
95
93
|
|
96
94
|
describe "with mime type of JSON" do
|
97
95
|
it "should render all leads as JSON" do
|
98
|
-
@controller.
|
99
|
-
leads.
|
96
|
+
expect(@controller).to receive(:get_leads).and_return(leads = double("Array of Leads"))
|
97
|
+
expect(leads).to receive(:to_json).and_return("generated JSON")
|
100
98
|
|
101
99
|
request.env["HTTP_ACCEPT"] = "application/json"
|
102
100
|
get :index
|
103
|
-
response.body.
|
101
|
+
expect(response.body).to eq("generated JSON")
|
104
102
|
end
|
105
103
|
end
|
106
104
|
|
107
105
|
describe "with mime type of XML" do
|
108
106
|
it "should render all leads as xml" do
|
109
|
-
@controller.
|
110
|
-
leads.
|
107
|
+
expect(@controller).to receive(:get_leads).and_return(leads = double("Array of Leads"))
|
108
|
+
expect(leads).to receive(:to_xml).and_return("generated XML")
|
111
109
|
|
112
110
|
request.env["HTTP_ACCEPT"] = "application/xml"
|
113
111
|
get :index
|
114
|
-
response.body.
|
112
|
+
expect(response.body).to eq("generated XML")
|
115
113
|
end
|
116
114
|
end
|
117
115
|
end
|
@@ -120,110 +118,107 @@ describe LeadsController do
|
|
120
118
|
# GET /leads/1.xml HTML
|
121
119
|
#----------------------------------------------------------------------------
|
122
120
|
describe "responding to GET show" do
|
123
|
-
|
124
121
|
describe "with mime type of HTML" do
|
125
122
|
before(:each) do
|
126
|
-
@lead = FactoryGirl.create(:lead, :
|
123
|
+
@lead = FactoryGirl.create(:lead, id: 42, user: current_user)
|
127
124
|
@comment = Comment.new
|
128
125
|
end
|
129
126
|
|
130
127
|
it "should expose the requested lead as @lead and render [show] template" do
|
131
|
-
get :show, :
|
132
|
-
assigns[:lead].
|
133
|
-
assigns[:comment].attributes.
|
134
|
-
response.
|
128
|
+
get :show, id: 42
|
129
|
+
expect(assigns[:lead]).to eq(@lead)
|
130
|
+
expect(assigns[:comment].attributes).to eq(@comment.attributes)
|
131
|
+
expect(response).to render_template("leads/show")
|
135
132
|
end
|
136
133
|
|
137
134
|
it "should update an activity when viewing the lead" do
|
138
|
-
get :show, :
|
139
|
-
@lead.versions.last.event.
|
135
|
+
get :show, id: @lead.id
|
136
|
+
expect(@lead.versions.last.event).to eq('view')
|
140
137
|
end
|
141
138
|
end
|
142
139
|
|
143
140
|
describe "with mime type of JSON" do
|
144
141
|
it "should render the requested lead as JSON" do
|
145
|
-
@lead = FactoryGirl.create(:lead, :
|
146
|
-
Lead.
|
147
|
-
@lead.
|
142
|
+
@lead = FactoryGirl.create(:lead, id: 42, user: current_user)
|
143
|
+
expect(Lead).to receive(:find).and_return(@lead)
|
144
|
+
expect(@lead).to receive(:to_json).and_return("generated JSON")
|
148
145
|
|
149
146
|
request.env["HTTP_ACCEPT"] = "application/json"
|
150
|
-
get :show, :
|
151
|
-
response.body.
|
147
|
+
get :show, id: 42
|
148
|
+
expect(response.body).to eq("generated JSON")
|
152
149
|
end
|
153
150
|
end
|
154
151
|
|
155
152
|
describe "with mime type of XML" do
|
156
153
|
it "should render the requested lead as xml" do
|
157
|
-
@lead = FactoryGirl.create(:lead, :
|
158
|
-
Lead.
|
159
|
-
@lead.
|
154
|
+
@lead = FactoryGirl.create(:lead, id: 42, user: current_user)
|
155
|
+
expect(Lead).to receive(:find).and_return(@lead)
|
156
|
+
expect(@lead).to receive(:to_xml).and_return("generated XML")
|
160
157
|
|
161
158
|
request.env["HTTP_ACCEPT"] = "application/xml"
|
162
|
-
get :show, :
|
163
|
-
response.body.
|
159
|
+
get :show, id: 42
|
160
|
+
expect(response.body).to eq("generated XML")
|
164
161
|
end
|
165
162
|
end
|
166
163
|
|
167
164
|
describe "lead got deleted or otherwise unavailable" do
|
168
165
|
it "should redirect to lead index if the lead got deleted" do
|
169
|
-
@lead = FactoryGirl.create(:lead, :
|
166
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
170
167
|
@lead.destroy
|
171
168
|
|
172
|
-
get :show, :
|
173
|
-
flash[:warning].
|
174
|
-
response.
|
169
|
+
get :show, id: @lead.id
|
170
|
+
expect(flash[:warning]).not_to eq(nil)
|
171
|
+
expect(response).to redirect_to(leads_path)
|
175
172
|
end
|
176
173
|
|
177
174
|
it "should redirect to lead index if the lead is protected" do
|
178
|
-
@private = FactoryGirl.create(:lead, :
|
175
|
+
@private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
|
179
176
|
|
180
|
-
get :show, :
|
181
|
-
flash[:warning].
|
182
|
-
response.
|
177
|
+
get :show, id: @private.id
|
178
|
+
expect(flash[:warning]).not_to eq(nil)
|
179
|
+
expect(response).to redirect_to(leads_path)
|
183
180
|
end
|
184
181
|
|
185
182
|
it "should return 404 (Not Found) JSON error" do
|
186
|
-
@lead = FactoryGirl.create(:lead, :
|
183
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
187
184
|
@lead.destroy
|
188
185
|
request.env["HTTP_ACCEPT"] = "application/json"
|
189
186
|
|
190
|
-
get :show, :
|
191
|
-
response.code.
|
187
|
+
get :show, id: @lead.id
|
188
|
+
expect(response.code).to eq("404") # :not_found
|
192
189
|
end
|
193
190
|
|
194
191
|
it "should return 404 (Not Found) XML error" do
|
195
|
-
@lead = FactoryGirl.create(:lead, :
|
192
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
196
193
|
@lead.destroy
|
197
194
|
request.env["HTTP_ACCEPT"] = "application/xml"
|
198
195
|
|
199
|
-
get :show, :
|
200
|
-
response.code.
|
196
|
+
get :show, id: @lead.id
|
197
|
+
expect(response.code).to eq("404") # :not_found
|
201
198
|
end
|
202
199
|
end
|
203
|
-
|
204
200
|
end
|
205
201
|
|
206
202
|
# GET /leads/new
|
207
203
|
# GET /leads/new.xml AJAX
|
208
204
|
#----------------------------------------------------------------------------
|
209
205
|
describe "responding to GET new" do
|
210
|
-
|
211
206
|
it "should expose a new lead as @lead and render [new] template" do
|
212
|
-
@lead = FactoryGirl.build(:lead, :
|
213
|
-
Lead.
|
214
|
-
@campaigns = [
|
207
|
+
@lead = FactoryGirl.build(:lead, user: current_user, campaign: nil)
|
208
|
+
allow(Lead).to receive(:new).and_return(@lead)
|
209
|
+
@campaigns = [FactoryGirl.create(:campaign, user: current_user)]
|
215
210
|
|
216
211
|
xhr :get, :new
|
217
|
-
assigns[:lead].attributes.
|
218
|
-
assigns[:campaigns].
|
219
|
-
response.
|
212
|
+
expect(assigns[:lead].attributes).to eq(@lead.attributes)
|
213
|
+
expect(assigns[:campaigns]).to eq(@campaigns)
|
214
|
+
expect(response).to render_template("leads/new")
|
220
215
|
end
|
221
216
|
|
222
217
|
it "should create related object when necessary" do
|
223
|
-
@campaign = FactoryGirl.create(:campaign, :
|
218
|
+
@campaign = FactoryGirl.create(:campaign, id: 123)
|
224
219
|
|
225
|
-
xhr :get, :new, :
|
226
|
-
assigns[:campaign].
|
220
|
+
xhr :get, :new, related: "campaign_123"
|
221
|
+
expect(assigns[:campaign]).to eq(@campaign)
|
227
222
|
end
|
228
223
|
|
229
224
|
describe "(when creating related lead)" do
|
@@ -231,17 +226,17 @@ describe LeadsController do
|
|
231
226
|
@campaign = FactoryGirl.create(:campaign)
|
232
227
|
@campaign.destroy
|
233
228
|
|
234
|
-
xhr :get, :new, :
|
235
|
-
flash[:warning].
|
236
|
-
response.body.
|
229
|
+
xhr :get, :new, related: "campaign_#{@campaign.id}"
|
230
|
+
expect(flash[:warning]).not_to eq(nil)
|
231
|
+
expect(response.body).to eq('window.location.href = "/campaigns";')
|
237
232
|
end
|
238
233
|
|
239
234
|
it "should redirect to parent asset's index page with the message if parent asset got protected" do
|
240
|
-
@campaign = FactoryGirl.create(:campaign, :
|
235
|
+
@campaign = FactoryGirl.create(:campaign, access: "Private")
|
241
236
|
|
242
|
-
xhr :get, :new, :
|
243
|
-
flash[:warning].
|
244
|
-
response.body.
|
237
|
+
xhr :get, :new, related: "campaign_#{@campaign.id}"
|
238
|
+
expect(flash[:warning]).not_to eq(nil)
|
239
|
+
expect(response.body).to eq('window.location.href = "/campaigns";')
|
245
240
|
end
|
246
241
|
end
|
247
242
|
end
|
@@ -249,66 +244,65 @@ describe LeadsController do
|
|
249
244
|
# GET /leads/1/edit AJAX
|
250
245
|
#----------------------------------------------------------------------------
|
251
246
|
describe "responding to GET edit" do
|
252
|
-
|
253
247
|
it "should expose the requested lead as @lead and render [edit] template" do
|
254
|
-
@lead = FactoryGirl.create(:lead, :
|
255
|
-
@campaigns = [
|
248
|
+
@lead = FactoryGirl.create(:lead, id: 42, user: current_user, campaign: nil)
|
249
|
+
@campaigns = [FactoryGirl.create(:campaign, user: current_user)]
|
256
250
|
|
257
|
-
xhr :get, :edit, :
|
258
|
-
assigns[:lead].
|
259
|
-
assigns[:campaigns].
|
260
|
-
response.
|
251
|
+
xhr :get, :edit, id: 42
|
252
|
+
expect(assigns[:lead]).to eq(@lead)
|
253
|
+
expect(assigns[:campaigns]).to eq(@campaigns)
|
254
|
+
expect(response).to render_template("leads/edit")
|
261
255
|
end
|
262
256
|
|
263
257
|
it "should find previous lead when necessary" do
|
264
|
-
@lead = FactoryGirl.create(:lead, :
|
265
|
-
@previous = FactoryGirl.create(:lead, :
|
258
|
+
@lead = FactoryGirl.create(:lead, id: 42)
|
259
|
+
@previous = FactoryGirl.create(:lead, id: 321)
|
266
260
|
|
267
|
-
xhr :get, :edit, :
|
268
|
-
assigns[:previous].
|
261
|
+
xhr :get, :edit, id: 42, previous: 321
|
262
|
+
expect(assigns[:previous]).to eq(@previous)
|
269
263
|
end
|
270
264
|
|
271
265
|
describe "lead got deleted or is otherwise unavailable" do
|
272
266
|
it "should reload current page with the flash message if the lead got deleted" do
|
273
|
-
@lead = FactoryGirl.create(:lead, :
|
267
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
274
268
|
@lead.destroy
|
275
269
|
|
276
|
-
xhr :get, :edit, :
|
277
|
-
flash[:warning].
|
278
|
-
response.body.
|
270
|
+
xhr :get, :edit, id: @lead.id
|
271
|
+
expect(flash[:warning]).not_to eq(nil)
|
272
|
+
expect(response.body).to eq("window.location.reload();")
|
279
273
|
end
|
280
274
|
|
281
275
|
it "should reload current page with the flash message if the lead is protected" do
|
282
|
-
@private = FactoryGirl.create(:lead, :
|
276
|
+
@private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
|
283
277
|
|
284
|
-
xhr :get, :edit, :
|
285
|
-
flash[:warning].
|
286
|
-
response.body.
|
278
|
+
xhr :get, :edit, id: @private.id
|
279
|
+
expect(flash[:warning]).not_to eq(nil)
|
280
|
+
expect(response.body).to eq("window.location.reload();")
|
287
281
|
end
|
288
282
|
end
|
289
283
|
|
290
284
|
describe "(previous lead got deleted or is otherwise unavailable)" do
|
291
285
|
before(:each) do
|
292
|
-
@lead = FactoryGirl.create(:lead, :
|
293
|
-
@previous = FactoryGirl.create(:lead, :
|
286
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
287
|
+
@previous = FactoryGirl.create(:lead, user: FactoryGirl.create(:user))
|
294
288
|
end
|
295
289
|
|
296
290
|
it "should notify the view if previous lead got deleted" do
|
297
291
|
@previous.destroy
|
298
292
|
|
299
|
-
xhr :get, :edit, :
|
300
|
-
flash[:warning].
|
301
|
-
assigns[:previous].
|
302
|
-
response.
|
293
|
+
xhr :get, :edit, id: @lead.id, previous: @previous.id
|
294
|
+
expect(flash[:warning]).to eq(nil) # no warning, just silently remove the div
|
295
|
+
expect(assigns[:previous]).to eq(@previous.id)
|
296
|
+
expect(response).to render_template("leads/edit")
|
303
297
|
end
|
304
298
|
|
305
299
|
it "should notify the view if previous lead got protected" do
|
306
300
|
@previous.update_attribute(:access, "Private")
|
307
301
|
|
308
|
-
xhr :get, :edit, :
|
309
|
-
flash[:warning].
|
310
|
-
assigns[:previous].
|
311
|
-
response.
|
302
|
+
xhr :get, :edit, id: @lead.id, previous: @previous.id
|
303
|
+
expect(flash[:warning]).to eq(nil)
|
304
|
+
expect(assigns[:previous]).to eq(@previous.id)
|
305
|
+
expect(response).to render_template("leads/edit")
|
312
306
|
end
|
313
307
|
end
|
314
308
|
end
|
@@ -317,242 +311,231 @@ describe LeadsController do
|
|
317
311
|
# POST /leads.xml AJAX
|
318
312
|
#----------------------------------------------------------------------------
|
319
313
|
describe "responding to POST create" do
|
320
|
-
|
321
314
|
describe "with valid params" do
|
322
|
-
|
323
315
|
it "should expose a newly created lead as @lead and render [create] template" do
|
324
|
-
@lead = FactoryGirl.build(:lead, :
|
325
|
-
Lead.
|
326
|
-
@campaigns = [
|
327
|
-
|
328
|
-
xhr :post, :create, :
|
329
|
-
assigns(:lead).
|
330
|
-
assigns(:campaigns).
|
331
|
-
assigns[:lead_status_total].
|
332
|
-
response.
|
316
|
+
@lead = FactoryGirl.build(:lead, user: current_user, campaign: nil)
|
317
|
+
allow(Lead).to receive(:new).and_return(@lead)
|
318
|
+
@campaigns = [FactoryGirl.create(:campaign, user: current_user)]
|
319
|
+
|
320
|
+
xhr :post, :create, lead: { first_name: "Billy", last_name: "Bones" }
|
321
|
+
expect(assigns(:lead)).to eq(@lead)
|
322
|
+
expect(assigns(:campaigns)).to eq(@campaigns)
|
323
|
+
expect(assigns[:lead_status_total]).to be_nil
|
324
|
+
expect(response).to render_template("leads/create")
|
333
325
|
end
|
334
326
|
|
335
327
|
it "should copy selected campaign permissions unless asked otherwise" do
|
336
|
-
he = FactoryGirl.create(:user, :
|
337
|
-
she = FactoryGirl.create(:user, :
|
338
|
-
@campaign = FactoryGirl.build(:campaign, :
|
339
|
-
@campaign.permissions << FactoryGirl.build(:permission, :
|
340
|
-
@campaign.permissions << FactoryGirl.build(:permission, :
|
328
|
+
he = FactoryGirl.create(:user, id: 7)
|
329
|
+
she = FactoryGirl.create(:user, id: 8)
|
330
|
+
@campaign = FactoryGirl.build(:campaign, access: "Shared")
|
331
|
+
@campaign.permissions << FactoryGirl.build(:permission, user: he, asset: @campaign)
|
332
|
+
@campaign.permissions << FactoryGirl.build(:permission, user: she, asset: @campaign)
|
341
333
|
@campaign.save
|
342
334
|
|
343
|
-
@lead = FactoryGirl.build(:lead, :
|
344
|
-
Lead.
|
335
|
+
@lead = FactoryGirl.build(:lead, campaign: @campaign, user: current_user, access: "Shared")
|
336
|
+
allow(Lead).to receive(:new).and_return(@lead)
|
345
337
|
|
346
|
-
xhr :post, :create, :
|
347
|
-
assigns(:lead).
|
348
|
-
@lead.reload.access.
|
349
|
-
@lead.permissions.map(&:user_id).sort.
|
350
|
-
@lead.permissions.map(&:asset_id).
|
351
|
-
@lead.permissions.map(&:asset_type).
|
338
|
+
xhr :post, :create, lead: { first_name: "Billy", last_name: "Bones", access: "Campaign", user_ids: %w(7 8) }, campaign: @campaign.id
|
339
|
+
expect(assigns(:lead)).to eq(@lead)
|
340
|
+
expect(@lead.reload.access).to eq("Shared")
|
341
|
+
expect(@lead.permissions.map(&:user_id).sort).to eq([7, 8])
|
342
|
+
expect(@lead.permissions.map(&:asset_id)).to eq([@lead.id, @lead.id])
|
343
|
+
expect(@lead.permissions.map(&:asset_type)).to eq(%w(Lead Lead))
|
352
344
|
end
|
353
345
|
|
354
346
|
it "should get the data to update leads sidebar if called from leads index" do
|
355
|
-
@lead = FactoryGirl.build(:lead, :
|
356
|
-
Lead.
|
347
|
+
@lead = FactoryGirl.build(:lead, user: current_user, campaign: nil)
|
348
|
+
allow(Lead).to receive(:new).and_return(@lead)
|
357
349
|
|
358
350
|
request.env["HTTP_REFERER"] = "http://localhost/leads"
|
359
|
-
xhr :post, :create, :
|
360
|
-
assigns[:lead_status_total].
|
351
|
+
xhr :post, :create, lead: { first_name: "Billy", last_name: "Bones" }
|
352
|
+
expect(assigns[:lead_status_total]).to be_an_instance_of(HashWithIndifferentAccess)
|
361
353
|
end
|
362
354
|
|
363
355
|
it "should reload leads to update pagination if called from leads index" do
|
364
|
-
@lead = FactoryGirl.build(:lead, :
|
365
|
-
Lead.
|
356
|
+
@lead = FactoryGirl.build(:lead, user: current_user, campaign: nil)
|
357
|
+
allow(Lead).to receive(:new).and_return(@lead)
|
366
358
|
|
367
359
|
request.env["HTTP_REFERER"] = "http://localhost/leads"
|
368
|
-
xhr :post, :create, :
|
369
|
-
assigns[:leads].
|
360
|
+
xhr :post, :create, lead: { first_name: "Billy", last_name: "Bones" }
|
361
|
+
expect(assigns[:leads]).to eq([@lead])
|
370
362
|
end
|
371
363
|
|
372
364
|
it "should reload lead campaign if called from campaign landing page" do
|
373
365
|
@campaign = FactoryGirl.create(:campaign)
|
374
|
-
@lead = FactoryGirl.build(:lead, :
|
366
|
+
@lead = FactoryGirl.build(:lead, user: current_user, campaign: @campaign)
|
375
367
|
|
376
368
|
request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
|
377
|
-
xhr :put, :create, :
|
378
|
-
assigns[:campaign].
|
369
|
+
xhr :put, :create, lead: { first_name: "Billy", last_name: "Bones" }, campaign: @campaign.id
|
370
|
+
expect(assigns[:campaign]).to eq(@campaign)
|
379
371
|
end
|
380
372
|
|
381
373
|
it "should add a new comment to the newly created lead when specified" do
|
382
374
|
@lead = FactoryGirl.create(:lead)
|
383
|
-
Lead.
|
384
|
-
xhr :post, :create, :
|
385
|
-
@lead.reload.comments.map(&:comment).
|
375
|
+
allow(Lead).to receive(:new).and_return(@lead)
|
376
|
+
xhr :post, :create, lead: { first_name: "Test", last_name: "Lead" }, comment_body: "This is an important lead."
|
377
|
+
expect(@lead.reload.comments.map(&:comment)).to include("This is an important lead.")
|
386
378
|
end
|
387
379
|
end
|
388
380
|
|
389
381
|
describe "with invalid params" do
|
390
|
-
|
391
382
|
it "should expose a newly created but unsaved lead as @lead and still render [create] template" do
|
392
|
-
@lead = FactoryGirl.build(:lead, :
|
393
|
-
Lead.
|
394
|
-
@campaigns = [
|
395
|
-
|
396
|
-
xhr :post, :create, :lead => { :first_name => nil }
|
397
|
-
assigns(:lead).should == @lead
|
398
|
-
assigns(:campaigns).should == @campaigns
|
399
|
-
assigns[:lead_status_total].should == nil
|
400
|
-
response.should render_template("leads/create")
|
401
|
-
end
|
383
|
+
@lead = FactoryGirl.build(:lead, user: current_user, first_name: nil, campaign: nil)
|
384
|
+
allow(Lead).to receive(:new).and_return(@lead)
|
385
|
+
@campaigns = [FactoryGirl.create(:campaign, user: current_user)]
|
402
386
|
|
387
|
+
xhr :post, :create, lead: { first_name: nil }
|
388
|
+
expect(assigns(:lead)).to eq(@lead)
|
389
|
+
expect(assigns(:campaigns)).to eq(@campaigns)
|
390
|
+
expect(assigns[:lead_status_total]).to eq(nil)
|
391
|
+
expect(response).to render_template("leads/create")
|
392
|
+
end
|
403
393
|
end
|
404
|
-
|
405
394
|
end
|
406
395
|
|
407
396
|
# PUT /leads/1
|
408
397
|
# PUT /leads/1.xml
|
409
398
|
#----------------------------------------------------------------------------
|
410
399
|
describe "responding to PUT update" do
|
411
|
-
|
412
400
|
describe "with valid params" do
|
413
|
-
|
414
401
|
it "should update the requested lead, expose it as @lead, and render [update] template" do
|
415
|
-
@lead = FactoryGirl.create(:lead, :
|
402
|
+
@lead = FactoryGirl.create(:lead, first_name: "Billy", user: current_user)
|
416
403
|
|
417
|
-
xhr :put, :update, :
|
418
|
-
@lead.reload.first_name.
|
419
|
-
assigns[:lead].
|
420
|
-
assigns[:lead_status_total].
|
421
|
-
response.
|
404
|
+
xhr :put, :update, id: @lead.id, lead: { first_name: "Bones" }
|
405
|
+
expect(@lead.reload.first_name).to eq("Bones")
|
406
|
+
expect(assigns[:lead]).to eq(@lead)
|
407
|
+
expect(assigns[:lead_status_total]).to eq(nil)
|
408
|
+
expect(response).to render_template("leads/update")
|
422
409
|
end
|
423
410
|
|
424
411
|
it "should update lead status" do
|
425
|
-
@lead = FactoryGirl.create(:lead, :
|
412
|
+
@lead = FactoryGirl.create(:lead, status: "new", user: current_user)
|
426
413
|
|
427
|
-
xhr :put, :update, :
|
428
|
-
@lead.reload.status.
|
414
|
+
xhr :put, :update, id: @lead.id, lead: { status: "rejected" }
|
415
|
+
expect(@lead.reload.status).to eq("rejected")
|
429
416
|
end
|
430
417
|
|
431
418
|
it "should update lead source" do
|
432
|
-
@lead = FactoryGirl.create(:lead, :
|
419
|
+
@lead = FactoryGirl.create(:lead, source: "campaign", user: current_user)
|
433
420
|
|
434
|
-
xhr :put, :update, :
|
435
|
-
@lead.reload.source.
|
421
|
+
xhr :put, :update, id: @lead.id, lead: { source: "cald_call" }
|
422
|
+
expect(@lead.reload.source).to eq("cald_call")
|
436
423
|
end
|
437
424
|
|
438
425
|
it "should update lead campaign" do
|
439
|
-
@campaigns = { :
|
440
|
-
@lead = FactoryGirl.create(:lead, :
|
426
|
+
@campaigns = { old: FactoryGirl.create(:campaign), new: FactoryGirl.create(:campaign) }
|
427
|
+
@lead = FactoryGirl.create(:lead, campaign: @campaigns[:old])
|
441
428
|
|
442
|
-
xhr :put, :update, :
|
443
|
-
@lead.reload.campaign.
|
429
|
+
xhr :put, :update, id: @lead.id, lead: { campaign_id: @campaigns[:new].id }
|
430
|
+
expect(@lead.reload.campaign).to eq(@campaigns[:new])
|
444
431
|
end
|
445
432
|
|
446
433
|
it "should decrement campaign leads count if campaign has been removed" do
|
447
434
|
@campaign = FactoryGirl.create(:campaign)
|
448
|
-
@lead = FactoryGirl.create(:lead, :
|
435
|
+
@lead = FactoryGirl.create(:lead, campaign: @campaign)
|
449
436
|
@count = @campaign.reload.leads_count
|
450
437
|
|
451
|
-
xhr :put, :update, :
|
452
|
-
@lead.reload.campaign.
|
453
|
-
@campaign.reload.leads_count.
|
438
|
+
xhr :put, :update, id: @lead, lead: { campaign_id: nil }
|
439
|
+
expect(@lead.reload.campaign).to eq(nil)
|
440
|
+
expect(@campaign.reload.leads_count).to eq(@count - 1)
|
454
441
|
end
|
455
442
|
|
456
443
|
it "should increment campaign leads count if campaign has been assigned" do
|
457
444
|
@campaign = FactoryGirl.create(:campaign)
|
458
|
-
@lead = FactoryGirl.create(:lead, :
|
445
|
+
@lead = FactoryGirl.create(:lead, campaign: nil)
|
459
446
|
@count = @campaign.leads_count
|
460
447
|
|
461
|
-
xhr :put, :update, :
|
462
|
-
@lead.reload.campaign.
|
463
|
-
@campaign.reload.leads_count.
|
448
|
+
xhr :put, :update, id: @lead, lead: { campaign_id: @campaign.id }
|
449
|
+
expect(@lead.reload.campaign).to eq(@campaign)
|
450
|
+
expect(@campaign.reload.leads_count).to eq(@count + 1)
|
464
451
|
end
|
465
452
|
|
466
453
|
it "should update both campaign leads counts if reassigned to a new campaign" do
|
467
|
-
@campaigns = { :
|
468
|
-
@lead = FactoryGirl.create(:lead, :
|
469
|
-
@counts = { :
|
470
|
-
|
471
|
-
xhr :put, :update, :
|
472
|
-
@lead.reload.campaign.
|
473
|
-
@campaigns[:old].reload.leads_count.
|
474
|
-
@campaigns[:new].reload.leads_count.
|
454
|
+
@campaigns = { old: FactoryGirl.create(:campaign), new: FactoryGirl.create(:campaign) }
|
455
|
+
@lead = FactoryGirl.create(:lead, campaign: @campaigns[:old])
|
456
|
+
@counts = { old: @campaigns[:old].reload.leads_count, new: @campaigns[:new].leads_count }
|
457
|
+
|
458
|
+
xhr :put, :update, id: @lead, lead: { campaign_id: @campaigns[:new].id }
|
459
|
+
expect(@lead.reload.campaign).to eq(@campaigns[:new])
|
460
|
+
expect(@campaigns[:old].reload.leads_count).to eq(@counts[:old] - 1)
|
461
|
+
expect(@campaigns[:new].reload.leads_count).to eq(@counts[:new] + 1)
|
475
462
|
end
|
476
463
|
|
477
464
|
it "should update shared permissions for the lead" do
|
478
|
-
@lead = FactoryGirl.create(:lead, :
|
479
|
-
he = FactoryGirl.create(:user, :
|
480
|
-
she = FactoryGirl.create(:user, :
|
465
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
466
|
+
he = FactoryGirl.create(:user, id: 7)
|
467
|
+
she = FactoryGirl.create(:user, id: 8)
|
481
468
|
|
482
|
-
xhr :put, :update, :
|
483
|
-
@lead.user_ids.sort.
|
469
|
+
xhr :put, :update, id: @lead.id, lead: { access: "Shared", user_ids: %w(7 8) }
|
470
|
+
expect(@lead.user_ids.sort).to eq([7, 8])
|
484
471
|
end
|
485
472
|
|
486
473
|
it "should get the data for leads sidebar when called from leads index" do
|
487
474
|
@lead = FactoryGirl.create(:lead)
|
488
475
|
|
489
476
|
request.env["HTTP_REFERER"] = "http://localhost/leads"
|
490
|
-
xhr :put, :update, :
|
491
|
-
assigns[:lead_status_total].
|
492
|
-
assigns[:lead_status_total].
|
477
|
+
xhr :put, :update, id: @lead.id, lead: { first_name: "Billy" }
|
478
|
+
expect(assigns[:lead_status_total]).not_to be_nil
|
479
|
+
expect(assigns[:lead_status_total]).to be_an_instance_of(HashWithIndifferentAccess)
|
493
480
|
end
|
494
481
|
|
495
482
|
it "should reload lead campaign if called from campaign landing page" do
|
496
483
|
@campaign = FactoryGirl.create(:campaign)
|
497
|
-
@lead = FactoryGirl.create(:lead, :
|
484
|
+
@lead = FactoryGirl.create(:lead, campaign: @campaign)
|
498
485
|
|
499
486
|
request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
|
500
|
-
xhr :put, :update, :
|
501
|
-
assigns[:campaign].
|
487
|
+
xhr :put, :update, id: @lead.id, lead: { first_name: "Hello" }
|
488
|
+
expect(assigns[:campaign]).to eq(@campaign)
|
502
489
|
end
|
503
490
|
|
504
491
|
describe "lead got deleted or otherwise unavailable" do
|
505
492
|
it "should reload current page with the flash message if the lead got deleted" do
|
506
|
-
@lead = FactoryGirl.create(:lead, :
|
493
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
507
494
|
@lead.destroy
|
508
495
|
|
509
|
-
xhr :put, :update, :
|
510
|
-
flash[:warning].
|
511
|
-
response.body.
|
496
|
+
xhr :put, :update, id: @lead.id
|
497
|
+
expect(flash[:warning]).not_to eq(nil)
|
498
|
+
expect(response.body).to eq("window.location.reload();")
|
512
499
|
end
|
513
500
|
|
514
501
|
it "should reload current page with the flash message if the lead is protected" do
|
515
|
-
@private = FactoryGirl.create(:lead, :
|
502
|
+
@private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
|
516
503
|
|
517
|
-
xhr :put, :update, :
|
518
|
-
flash[:warning].
|
519
|
-
response.body.
|
504
|
+
xhr :put, :update, id: @private.id
|
505
|
+
expect(flash[:warning]).not_to eq(nil)
|
506
|
+
expect(response.body).to eq("window.location.reload();")
|
520
507
|
end
|
521
508
|
end
|
522
509
|
end
|
523
510
|
|
524
511
|
describe "with invalid params" do
|
525
|
-
|
526
512
|
it "should not update the lead, but still expose it as @lead and render [update] template" do
|
527
|
-
@lead = FactoryGirl.create(:lead, :
|
528
|
-
@campaigns = [
|
513
|
+
@lead = FactoryGirl.create(:lead, id: 42, user: current_user, campaign: nil)
|
514
|
+
@campaigns = [FactoryGirl.create(:campaign, user: current_user)]
|
529
515
|
|
530
|
-
xhr :put, :update, :
|
531
|
-
assigns[:lead].
|
532
|
-
assigns[:campaigns].
|
533
|
-
response.
|
516
|
+
xhr :put, :update, id: 42, lead: { first_name: nil }
|
517
|
+
expect(assigns[:lead]).to eq(@lead)
|
518
|
+
expect(assigns[:campaigns]).to eq(@campaigns)
|
519
|
+
expect(response).to render_template("leads/update")
|
534
520
|
end
|
535
|
-
|
536
521
|
end
|
537
|
-
|
538
522
|
end
|
539
523
|
|
540
524
|
# DELETE /leads/1
|
541
525
|
# DELETE /leads/1.xml AJAX and HTML
|
542
526
|
#----------------------------------------------------------------------------
|
543
527
|
describe "responding to DELETE destroy" do
|
544
|
-
|
545
528
|
before(:each) do
|
546
|
-
@lead = FactoryGirl.create(:lead, :
|
529
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
547
530
|
end
|
548
531
|
|
549
532
|
describe "AJAX request" do
|
550
533
|
it "should destroy the requested lead and render [destroy] template" do
|
551
|
-
xhr :delete, :destroy, :
|
534
|
+
xhr :delete, :destroy, id: @lead.id
|
552
535
|
|
553
|
-
assigns[:leads].
|
554
|
-
|
555
|
-
response.
|
536
|
+
expect(assigns[:leads]).to eq(nil) # @lead got deleted
|
537
|
+
expect { Lead.find(@lead.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
538
|
+
expect(response).to render_template("leads/destroy")
|
556
539
|
end
|
557
540
|
|
558
541
|
describe "when called from Leads index page" do
|
@@ -561,95 +544,95 @@ describe LeadsController do
|
|
561
544
|
end
|
562
545
|
|
563
546
|
it "should get data for the sidebar" do
|
564
|
-
@another_lead = FactoryGirl.create(:lead, :
|
547
|
+
@another_lead = FactoryGirl.create(:lead, user: current_user)
|
565
548
|
|
566
|
-
xhr :delete, :destroy, :
|
567
|
-
assigns[:leads].
|
568
|
-
assigns[:lead_status_total].
|
569
|
-
assigns[:lead_status_total].
|
570
|
-
response.
|
549
|
+
xhr :delete, :destroy, id: @lead.id
|
550
|
+
expect(assigns[:leads]).to eq([@another_lead]) # @lead got deleted
|
551
|
+
expect(assigns[:lead_status_total]).not_to be_nil
|
552
|
+
expect(assigns[:lead_status_total]).to be_an_instance_of(HashWithIndifferentAccess)
|
553
|
+
expect(response).to render_template("leads/destroy")
|
571
554
|
end
|
572
555
|
|
573
556
|
it "should try previous page and render index action if current page has no leads" do
|
574
557
|
session[:leads_current_page] = 42
|
575
558
|
|
576
|
-
xhr :delete, :destroy, :
|
577
|
-
session[:leads_current_page].
|
578
|
-
response.
|
559
|
+
xhr :delete, :destroy, id: @lead.id
|
560
|
+
expect(session[:leads_current_page]).to eq(41)
|
561
|
+
expect(response).to render_template("leads/index")
|
579
562
|
end
|
580
563
|
|
581
564
|
it "should render index action when deleting last lead" do
|
582
565
|
session[:leads_current_page] = 1
|
583
566
|
|
584
|
-
xhr :delete, :destroy, :
|
585
|
-
session[:leads_current_page].
|
586
|
-
response.
|
567
|
+
xhr :delete, :destroy, id: @lead.id
|
568
|
+
expect(session[:leads_current_page]).to eq(1)
|
569
|
+
expect(response).to render_template("leads/index")
|
587
570
|
end
|
588
571
|
end
|
589
572
|
|
590
573
|
describe "when called from campaign landing page" do
|
591
574
|
before(:each) do
|
592
575
|
@campaign = FactoryGirl.create(:campaign)
|
593
|
-
@lead = FactoryGirl.create(:lead, :
|
576
|
+
@lead = FactoryGirl.create(:lead, user: current_user, campaign: @campaign)
|
594
577
|
request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
|
595
578
|
end
|
596
579
|
|
597
580
|
it "should reset current page to 1" do
|
598
|
-
xhr :delete, :destroy, :
|
599
|
-
session[:leads_current_page].
|
600
|
-
response.
|
581
|
+
xhr :delete, :destroy, id: @lead.id
|
582
|
+
expect(session[:leads_current_page]).to eq(1)
|
583
|
+
expect(response).to render_template("leads/destroy")
|
601
584
|
end
|
602
585
|
|
603
586
|
it "should reload campaiign to be able to refresh its summary" do
|
604
|
-
xhr :delete, :destroy, :
|
605
|
-
assigns[:campaign].
|
606
|
-
response.
|
587
|
+
xhr :delete, :destroy, id: @lead.id
|
588
|
+
expect(assigns[:campaign]).to eq(@campaign)
|
589
|
+
expect(response).to render_template("leads/destroy")
|
607
590
|
end
|
608
591
|
end
|
609
592
|
|
610
593
|
describe "lead got deleted or otherwise unavailable" do
|
611
594
|
it "should reload current page with the flash message if the lead got deleted" do
|
612
|
-
@lead = FactoryGirl.create(:lead, :
|
595
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
613
596
|
@lead.destroy
|
614
597
|
|
615
|
-
xhr :delete, :destroy, :
|
616
|
-
flash[:warning].
|
617
|
-
response.body.
|
598
|
+
xhr :delete, :destroy, id: @lead.id
|
599
|
+
expect(flash[:warning]).not_to eq(nil)
|
600
|
+
expect(response.body).to eq("window.location.reload();")
|
618
601
|
end
|
619
602
|
|
620
603
|
it "should reload current page with the flash message if the lead is protected" do
|
621
|
-
@private = FactoryGirl.create(:lead, :
|
604
|
+
@private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
|
622
605
|
|
623
|
-
xhr :delete, :destroy, :
|
624
|
-
flash[:warning].
|
625
|
-
response.body.
|
606
|
+
xhr :delete, :destroy, id: @private.id
|
607
|
+
expect(flash[:warning]).not_to eq(nil)
|
608
|
+
expect(response.body).to eq("window.location.reload();")
|
626
609
|
end
|
627
610
|
end
|
628
611
|
end
|
629
612
|
|
630
613
|
describe "HTML request" do
|
631
614
|
it "should redirect to Leads index when a lead gets deleted from its landing page" do
|
632
|
-
delete :destroy, :
|
633
|
-
flash[:notice].
|
634
|
-
session[:leads_current_page].
|
635
|
-
response.
|
615
|
+
delete :destroy, id: @lead.id
|
616
|
+
expect(flash[:notice]).not_to eq(nil)
|
617
|
+
expect(session[:leads_current_page]).to eq(1)
|
618
|
+
expect(response).to redirect_to(leads_path)
|
636
619
|
end
|
637
620
|
|
638
621
|
it "should redirect to lead index with the flash message is the lead got deleted" do
|
639
|
-
@lead = FactoryGirl.create(:lead, :
|
622
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
640
623
|
@lead.destroy
|
641
624
|
|
642
|
-
delete :destroy, :
|
643
|
-
flash[:warning].
|
644
|
-
response.
|
625
|
+
delete :destroy, id: @lead.id
|
626
|
+
expect(flash[:warning]).not_to eq(nil)
|
627
|
+
expect(response).to redirect_to(leads_path)
|
645
628
|
end
|
646
629
|
|
647
630
|
it "should redirect to lead index with the flash message if the lead is protected" do
|
648
|
-
@private = FactoryGirl.create(:lead, :
|
631
|
+
@private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
|
649
632
|
|
650
|
-
delete :destroy, :
|
651
|
-
flash[:warning].
|
652
|
-
response.
|
633
|
+
delete :destroy, id: @private.id
|
634
|
+
expect(flash[:warning]).not_to eq(nil)
|
635
|
+
expect(response).to redirect_to(leads_path)
|
653
636
|
end
|
654
637
|
end
|
655
638
|
end
|
@@ -658,64 +641,63 @@ describe LeadsController do
|
|
658
641
|
# GET /leads/1/convert.xml AJAX
|
659
642
|
#----------------------------------------------------------------------------
|
660
643
|
describe "responding to GET convert" do
|
661
|
-
|
662
644
|
it "should should collect necessary data and render [convert] template" do
|
663
|
-
@campaign = FactoryGirl.create(:campaign, :
|
664
|
-
@lead = FactoryGirl.create(:lead, :
|
665
|
-
@accounts = [
|
666
|
-
@account = Account.new(:
|
667
|
-
@opportunity = Opportunity.new(:
|
668
|
-
|
669
|
-
xhr :get, :convert, :
|
670
|
-
assigns[:lead].
|
671
|
-
assigns[:accounts].
|
672
|
-
assigns[:account].attributes.
|
673
|
-
assigns[:opportunity].attributes.
|
674
|
-
assigns[:opportunity].campaign.
|
675
|
-
response.
|
645
|
+
@campaign = FactoryGirl.create(:campaign, user: current_user)
|
646
|
+
@lead = FactoryGirl.create(:lead, user: current_user, campaign: @campaign, source: "cold_call")
|
647
|
+
@accounts = [FactoryGirl.create(:account, user: current_user)]
|
648
|
+
@account = Account.new(user: current_user, name: @lead.company, access: "Lead")
|
649
|
+
@opportunity = Opportunity.new(user: current_user, access: "Lead", stage: "prospecting", campaign: @lead.campaign, source: @lead.source)
|
650
|
+
|
651
|
+
xhr :get, :convert, id: @lead.id
|
652
|
+
expect(assigns[:lead]).to eq(@lead)
|
653
|
+
expect(assigns[:accounts]).to eq(@accounts)
|
654
|
+
expect(assigns[:account].attributes).to eq(@account.attributes)
|
655
|
+
expect(assigns[:opportunity].attributes).to eq(@opportunity.attributes)
|
656
|
+
expect(assigns[:opportunity].campaign).to eq(@opportunity.campaign)
|
657
|
+
expect(response).to render_template("leads/convert")
|
676
658
|
end
|
677
659
|
|
678
660
|
describe "(lead got deleted or is otherwise unavailable)" do
|
679
661
|
it "should reload current page with the flash message if the lead got deleted" do
|
680
|
-
@lead = FactoryGirl.create(:lead, :
|
662
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
681
663
|
@lead.destroy
|
682
664
|
|
683
|
-
xhr :get, :convert, :
|
684
|
-
flash[:warning].
|
685
|
-
response.body.
|
665
|
+
xhr :get, :convert, id: @lead.id
|
666
|
+
expect(flash[:warning]).not_to eq(nil)
|
667
|
+
expect(response.body).to eq("window.location.reload();")
|
686
668
|
end
|
687
669
|
|
688
670
|
it "should reload current page with the flash message if the lead is protected" do
|
689
|
-
@private = FactoryGirl.create(:lead, :
|
671
|
+
@private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
|
690
672
|
|
691
|
-
xhr :get, :convert, :
|
692
|
-
flash[:warning].
|
693
|
-
response.body.
|
673
|
+
xhr :get, :convert, id: @private.id
|
674
|
+
expect(flash[:warning]).not_to eq(nil)
|
675
|
+
expect(response.body).to eq("window.location.reload();")
|
694
676
|
end
|
695
677
|
end
|
696
678
|
|
697
679
|
describe "(previous lead got deleted or is otherwise unavailable)" do
|
698
680
|
before(:each) do
|
699
|
-
@lead = FactoryGirl.create(:lead, :
|
700
|
-
@previous = FactoryGirl.create(:lead, :
|
681
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
682
|
+
@previous = FactoryGirl.create(:lead, user: FactoryGirl.create(:user))
|
701
683
|
end
|
702
684
|
|
703
685
|
it "should notify the view if previous lead got deleted" do
|
704
686
|
@previous.destroy
|
705
687
|
|
706
|
-
xhr :get, :convert, :
|
707
|
-
flash[:warning].
|
708
|
-
assigns[:previous].
|
709
|
-
response.
|
688
|
+
xhr :get, :convert, id: @lead.id, previous: @previous.id
|
689
|
+
expect(flash[:warning]).to eq(nil) # no warning, just silently remove the div
|
690
|
+
expect(assigns[:previous]).to eq(@previous.id)
|
691
|
+
expect(response).to render_template("leads/convert")
|
710
692
|
end
|
711
693
|
|
712
694
|
it "should notify the view if previous lead got protected" do
|
713
695
|
@previous.update_attribute(:access, "Private")
|
714
696
|
|
715
|
-
xhr :get, :convert, :
|
716
|
-
flash[:warning].
|
717
|
-
assigns[:previous].
|
718
|
-
response.
|
697
|
+
xhr :get, :convert, id: @lead.id, previous: @previous.id
|
698
|
+
expect(flash[:warning]).to eq(nil)
|
699
|
+
expect(assigns[:previous]).to eq(@previous.id)
|
700
|
+
expect(response).to render_template("leads/convert")
|
719
701
|
end
|
720
702
|
end
|
721
703
|
end
|
@@ -724,114 +706,113 @@ describe LeadsController do
|
|
724
706
|
# PUT /leads/1/promote.xml AJAX
|
725
707
|
#----------------------------------------------------------------------------
|
726
708
|
describe "responding to PUT promote" do
|
727
|
-
|
728
709
|
it "on success: should change lead's status to [converted] and render [promote] template" do
|
729
|
-
@lead = FactoryGirl.create(:lead, :
|
730
|
-
@account = FactoryGirl.create(:account, :
|
731
|
-
@opportunity = FactoryGirl.build(:opportunity, :
|
732
|
-
|
733
|
-
Opportunity.
|
734
|
-
@contact = FactoryGirl.build(:contact, :
|
735
|
-
Contact.
|
736
|
-
|
737
|
-
xhr :put, :promote, :
|
738
|
-
@lead.reload.status.
|
739
|
-
assigns[:lead].
|
740
|
-
assigns[:account].
|
741
|
-
assigns[:accounts].
|
742
|
-
assigns[:opportunity].
|
743
|
-
assigns[:contact].
|
744
|
-
assigns[:stage].
|
745
|
-
response.
|
710
|
+
@lead = FactoryGirl.create(:lead, id: 42, user: current_user, campaign: nil)
|
711
|
+
@account = FactoryGirl.create(:account, id: 123, user: current_user)
|
712
|
+
@opportunity = FactoryGirl.build(:opportunity, user: current_user, campaign: @lead.campaign,
|
713
|
+
account: @account)
|
714
|
+
allow(Opportunity).to receive(:new).and_return(@opportunity)
|
715
|
+
@contact = FactoryGirl.build(:contact, user: current_user, lead: @lead)
|
716
|
+
allow(Contact).to receive(:new).and_return(@contact)
|
717
|
+
|
718
|
+
xhr :put, :promote, id: 42, account: { id: 123 }, opportunity: { name: "Hello" }
|
719
|
+
expect(@lead.reload.status).to eq("converted")
|
720
|
+
expect(assigns[:lead]).to eq(@lead)
|
721
|
+
expect(assigns[:account]).to eq(@account)
|
722
|
+
expect(assigns[:accounts]).to eq([@account])
|
723
|
+
expect(assigns[:opportunity]).to eq(@opportunity)
|
724
|
+
expect(assigns[:contact]).to eq(@contact)
|
725
|
+
expect(assigns[:stage]).to be_instance_of(Array)
|
726
|
+
expect(response).to render_template("leads/promote")
|
746
727
|
end
|
747
728
|
|
748
729
|
it "should copy lead permissions to newly created account and opportunity when asked so" do
|
749
|
-
he = FactoryGirl.create(:user, :
|
750
|
-
she = FactoryGirl.create(:user, :
|
751
|
-
@lead = FactoryGirl.build(:lead, :
|
752
|
-
@lead.permissions << FactoryGirl.build(:permission, :
|
753
|
-
@lead.permissions << FactoryGirl.build(:permission, :
|
730
|
+
he = FactoryGirl.create(:user, id: 7)
|
731
|
+
she = FactoryGirl.create(:user, id: 8)
|
732
|
+
@lead = FactoryGirl.build(:lead, access: "Shared")
|
733
|
+
@lead.permissions << FactoryGirl.build(:permission, user: he, asset: @lead)
|
734
|
+
@lead.permissions << FactoryGirl.build(:permission, user: she, asset: @lead)
|
754
735
|
@lead.save
|
755
|
-
@account = FactoryGirl.build(:account, :
|
756
|
-
@account.permissions << FactoryGirl.create(:permission, :
|
757
|
-
@account.permissions << FactoryGirl.create(:permission, :
|
758
|
-
@account.
|
759
|
-
@opportunity = FactoryGirl.build(:opportunity, :
|
760
|
-
@opportunity.permissions << FactoryGirl.create(:permission, :
|
761
|
-
@opportunity.permissions << FactoryGirl.create(:permission, :
|
762
|
-
@opportunity.
|
763
|
-
|
764
|
-
xhr :put, :promote, :
|
765
|
-
@account.access.
|
766
|
-
@account.permissions.map(&:user_id).sort.
|
767
|
-
@account.permissions.map(&:asset_id).
|
768
|
-
@account.permissions.map(&:asset_type).
|
769
|
-
@opportunity.access.
|
770
|
-
@opportunity.permissions.map(&:user_id).sort.
|
771
|
-
@opportunity.permissions.map(&:asset_id).
|
772
|
-
@opportunity.permissions.map(&:asset_type).
|
736
|
+
@account = FactoryGirl.build(:account, user: current_user, access: "Shared")
|
737
|
+
@account.permissions << FactoryGirl.create(:permission, user: he, asset: @account)
|
738
|
+
@account.permissions << FactoryGirl.create(:permission, user: she, asset: @account)
|
739
|
+
allow(@account).to receive(:new).and_return(@account)
|
740
|
+
@opportunity = FactoryGirl.build(:opportunity, user: current_user, access: "Shared")
|
741
|
+
@opportunity.permissions << FactoryGirl.create(:permission, user: he, asset: @opportunity)
|
742
|
+
@opportunity.permissions << FactoryGirl.create(:permission, user: she, asset: @opportunity)
|
743
|
+
allow(@opportunity).to receive(:new).and_return(@opportunity)
|
744
|
+
|
745
|
+
xhr :put, :promote, id: @lead.id, access: "Lead", account: { name: "Hello", access: "Lead", user_id: current_user.id }, opportunity: { name: "World", access: "Lead", user_id: current_user.id }
|
746
|
+
expect(@account.access).to eq("Shared")
|
747
|
+
expect(@account.permissions.map(&:user_id).sort).to eq([7, 8])
|
748
|
+
expect(@account.permissions.map(&:asset_id)).to eq([@account.id, @account.id])
|
749
|
+
expect(@account.permissions.map(&:asset_type)).to eq(%w(Account Account))
|
750
|
+
expect(@opportunity.access).to eq("Shared")
|
751
|
+
expect(@opportunity.permissions.map(&:user_id).sort).to eq([7, 8])
|
752
|
+
expect(@opportunity.permissions.map(&:asset_id)).to eq([@opportunity.id, @opportunity.id])
|
753
|
+
expect(@opportunity.permissions.map(&:asset_type)).to eq(%w(Opportunity Opportunity))
|
773
754
|
end
|
774
755
|
|
775
756
|
it "should assign lead's campaign to the newly created opportunity" do
|
776
757
|
@campaign = FactoryGirl.create(:campaign)
|
777
|
-
@lead = FactoryGirl.create(:lead, :
|
758
|
+
@lead = FactoryGirl.create(:lead, user: current_user, campaign: @campaign)
|
778
759
|
|
779
|
-
xhr :put, :promote, :
|
780
|
-
assigns[:opportunity].campaign.
|
760
|
+
xhr :put, :promote, id: @lead.id, account: { name: "Hello" }, opportunity: { name: "Hello", campaign_id: @campaign.id }
|
761
|
+
expect(assigns[:opportunity].campaign).to eq(@campaign)
|
781
762
|
end
|
782
763
|
|
783
764
|
it "should assign lead's source to the newly created opportunity" do
|
784
|
-
@lead = FactoryGirl.create(:lead, :
|
765
|
+
@lead = FactoryGirl.create(:lead, user: current_user, source: "cold_call")
|
785
766
|
|
786
|
-
xhr :put, :promote, :
|
787
|
-
assigns[:opportunity].source.
|
767
|
+
xhr :put, :promote, id: @lead.id, account: { name: "Hello" }, opportunity: { name: "Hello", source: @lead.source }
|
768
|
+
expect(assigns[:opportunity].source).to eq(@lead.source)
|
788
769
|
end
|
789
770
|
|
790
771
|
it "should get the data for leads sidebar when called from leads index" do
|
791
772
|
@lead = FactoryGirl.create(:lead)
|
792
773
|
request.env["HTTP_REFERER"] = "http://localhost/leads"
|
793
774
|
|
794
|
-
xhr :put, :promote, :
|
795
|
-
assigns[:lead_status_total].
|
796
|
-
assigns[:lead_status_total].
|
775
|
+
xhr :put, :promote, id: @lead.id, account: { name: "Hello" }, opportunity: {}
|
776
|
+
expect(assigns[:lead_status_total]).not_to be_nil
|
777
|
+
expect(assigns[:lead_status_total]).to be_an_instance_of(HashWithIndifferentAccess)
|
797
778
|
end
|
798
779
|
|
799
780
|
it "should reload lead campaign if called from campaign landing page" do
|
800
781
|
@campaign = FactoryGirl.create(:campaign)
|
801
|
-
@lead = FactoryGirl.create(:lead, :
|
782
|
+
@lead = FactoryGirl.create(:lead, campaign: @campaign)
|
802
783
|
request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
|
803
784
|
|
804
|
-
xhr :put, :promote, :
|
805
|
-
assigns[:campaign].
|
785
|
+
xhr :put, :promote, id: @lead.id, account: { name: "Hello" }, opportunity: {}
|
786
|
+
expect(assigns[:campaign]).to eq(@campaign)
|
806
787
|
end
|
807
788
|
|
808
789
|
it "on failure: should not change lead's status and still render [promote] template" do
|
809
|
-
@lead = FactoryGirl.create(:lead, :
|
810
|
-
@account = FactoryGirl.create(:account, :
|
811
|
-
@contact = FactoryGirl.build(:contact, :
|
812
|
-
Contact.
|
813
|
-
|
814
|
-
xhr :put, :promote, :
|
815
|
-
@lead.reload.status.
|
816
|
-
response.
|
790
|
+
@lead = FactoryGirl.create(:lead, id: 42, user: current_user, status: "new")
|
791
|
+
@account = FactoryGirl.create(:account, id: 123, user: current_user)
|
792
|
+
@contact = FactoryGirl.build(:contact, first_name: nil) # make it fail
|
793
|
+
allow(Contact).to receive(:new).and_return(@contact)
|
794
|
+
|
795
|
+
xhr :put, :promote, id: 42, account: { id: 123 }
|
796
|
+
expect(@lead.reload.status).to eq("new")
|
797
|
+
expect(response).to render_template("leads/promote")
|
817
798
|
end
|
818
799
|
|
819
800
|
describe "lead got deleted or otherwise unavailable" do
|
820
801
|
it "should reload current page with the flash message if the lead got deleted" do
|
821
|
-
@lead = FactoryGirl.create(:lead, :
|
802
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
822
803
|
@lead.destroy
|
823
804
|
|
824
|
-
xhr :put, :promote, :
|
825
|
-
flash[:warning].
|
826
|
-
response.body.
|
805
|
+
xhr :put, :promote, id: @lead.id
|
806
|
+
expect(flash[:warning]).not_to eq(nil)
|
807
|
+
expect(response.body).to eq("window.location.reload();")
|
827
808
|
end
|
828
809
|
|
829
810
|
it "should reload current page with the flash message if the lead is protected" do
|
830
|
-
@private = FactoryGirl.create(:lead, :
|
811
|
+
@private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
|
831
812
|
|
832
|
-
xhr :put, :promote, :
|
833
|
-
flash[:warning].
|
834
|
-
response.body.
|
813
|
+
xhr :put, :promote, id: @private.id
|
814
|
+
expect(flash[:warning]).not_to eq(nil)
|
815
|
+
expect(response.body).to eq("window.location.reload();")
|
835
816
|
end
|
836
817
|
end
|
837
818
|
end
|
@@ -840,82 +821,81 @@ describe LeadsController do
|
|
840
821
|
# PUT /leads/1/reject.xml AJAX and HTML
|
841
822
|
#----------------------------------------------------------------------------
|
842
823
|
describe "responding to PUT reject" do
|
843
|
-
|
844
824
|
before(:each) do
|
845
|
-
@lead = FactoryGirl.create(:lead, :
|
825
|
+
@lead = FactoryGirl.create(:lead, user: current_user, status: "new")
|
846
826
|
end
|
847
827
|
|
848
828
|
describe "AJAX request" do
|
849
829
|
it "should reject the requested lead and render [reject] template" do
|
850
|
-
xhr :put, :reject, :
|
830
|
+
xhr :put, :reject, id: @lead.id
|
851
831
|
|
852
|
-
assigns[:lead].
|
853
|
-
@lead.status.
|
854
|
-
response.
|
832
|
+
expect(assigns[:lead]).to eq(@lead.reload)
|
833
|
+
expect(@lead.status).to eq("rejected")
|
834
|
+
expect(response).to render_template("leads/reject")
|
855
835
|
end
|
856
836
|
|
857
837
|
it "should get the data for leads sidebar when called from leads index" do
|
858
838
|
request.env["HTTP_REFERER"] = "http://localhost/leads"
|
859
|
-
xhr :put, :reject, :
|
860
|
-
assigns[:lead_status_total].
|
861
|
-
assigns[:lead_status_total].
|
839
|
+
xhr :put, :reject, id: @lead.id
|
840
|
+
expect(assigns[:lead_status_total]).not_to be_nil
|
841
|
+
expect(assigns[:lead_status_total]).to be_an_instance_of(HashWithIndifferentAccess)
|
862
842
|
end
|
863
843
|
|
864
844
|
it "should reload lead campaign if called from campaign landing page" do
|
865
845
|
@campaign = FactoryGirl.create(:campaign)
|
866
|
-
@lead = FactoryGirl.create(:lead, :
|
846
|
+
@lead = FactoryGirl.create(:lead, campaign: @campaign)
|
867
847
|
|
868
848
|
request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
|
869
|
-
xhr :put, :reject, :
|
870
|
-
assigns[:campaign].
|
849
|
+
xhr :put, :reject, id: @lead.id
|
850
|
+
expect(assigns[:campaign]).to eq(@campaign)
|
871
851
|
end
|
872
852
|
|
873
853
|
describe "lead got deleted or otherwise unavailable" do
|
874
854
|
it "should reload current page with the flash message if the lead got deleted" do
|
875
|
-
@lead = FactoryGirl.create(:lead, :
|
855
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
876
856
|
@lead.destroy
|
877
857
|
|
878
|
-
xhr :put, :reject, :
|
879
|
-
flash[:warning].
|
880
|
-
response.body.
|
858
|
+
xhr :put, :reject, id: @lead.id
|
859
|
+
expect(flash[:warning]).not_to eq(nil)
|
860
|
+
expect(response.body).to eq("window.location.reload();")
|
881
861
|
end
|
882
862
|
|
883
863
|
it "should reload current page with the flash message if the lead is protected" do
|
884
|
-
@private = FactoryGirl.create(:lead, :
|
864
|
+
@private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
|
885
865
|
|
886
|
-
xhr :put, :reject, :
|
887
|
-
flash[:warning].
|
888
|
-
response.body.
|
866
|
+
xhr :put, :reject, id: @private.id
|
867
|
+
expect(flash[:warning]).not_to eq(nil)
|
868
|
+
expect(response.body).to eq("window.location.reload();")
|
889
869
|
end
|
890
870
|
end
|
891
871
|
end
|
892
872
|
|
893
873
|
describe "HTML request" do
|
894
874
|
it "should redirect to Leads index when a lead gets rejected from its landing page" do
|
895
|
-
put :reject, :
|
875
|
+
put :reject, id: @lead.id
|
896
876
|
|
897
|
-
assigns[:lead].
|
898
|
-
@lead.status.
|
899
|
-
flash[:notice].
|
900
|
-
response.
|
877
|
+
expect(assigns[:lead]).to eq(@lead.reload)
|
878
|
+
expect(@lead.status).to eq("rejected")
|
879
|
+
expect(flash[:notice]).not_to eq(nil)
|
880
|
+
expect(response).to redirect_to(leads_path)
|
901
881
|
end
|
902
882
|
|
903
883
|
describe "lead got deleted or otherwise unavailable" do
|
904
884
|
it "should redirect to lead index if the lead got deleted" do
|
905
|
-
@lead = FactoryGirl.create(:lead, :
|
885
|
+
@lead = FactoryGirl.create(:lead, user: current_user)
|
906
886
|
@lead.destroy
|
907
887
|
|
908
|
-
put :reject, :
|
909
|
-
flash[:warning].
|
910
|
-
response.
|
888
|
+
put :reject, id: @lead.id
|
889
|
+
expect(flash[:warning]).not_to eq(nil)
|
890
|
+
expect(response).to redirect_to(leads_path)
|
911
891
|
end
|
912
892
|
|
913
893
|
it "should redirect to lead index if the lead is protected" do
|
914
|
-
@private = FactoryGirl.create(:lead, :
|
894
|
+
@private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
|
915
895
|
|
916
|
-
put :reject, :
|
917
|
-
flash[:warning].
|
918
|
-
response.
|
896
|
+
put :reject, id: @private.id
|
897
|
+
expect(flash[:warning]).not_to eq(nil)
|
898
|
+
expect(response).to redirect_to(leads_path)
|
919
899
|
end
|
920
900
|
end
|
921
901
|
end
|
@@ -928,7 +908,7 @@ describe LeadsController do
|
|
928
908
|
describe "tasks" do
|
929
909
|
before do
|
930
910
|
@model = FactoryGirl.create(:lead)
|
931
|
-
@attachment = FactoryGirl.create(:task, :
|
911
|
+
@attachment = FactoryGirl.create(:task, asset: nil)
|
932
912
|
end
|
933
913
|
it_should_behave_like("attach")
|
934
914
|
end
|
@@ -941,7 +921,7 @@ describe LeadsController do
|
|
941
921
|
describe "tasks" do
|
942
922
|
before do
|
943
923
|
@model = FactoryGirl.create(:lead)
|
944
|
-
@attachment = FactoryGirl.create(:task, :
|
924
|
+
@attachment = FactoryGirl.create(:task, asset: nil)
|
945
925
|
end
|
946
926
|
it_should_behave_like("attach")
|
947
927
|
end
|
@@ -952,7 +932,7 @@ describe LeadsController do
|
|
952
932
|
#----------------------------------------------------------------------------
|
953
933
|
describe "responding to POST discard" do
|
954
934
|
before(:each) do
|
955
|
-
@attachment = FactoryGirl.create(:task, :
|
935
|
+
@attachment = FactoryGirl.create(:task, assigned_to: current_user)
|
956
936
|
@model = FactoryGirl.create(:lead)
|
957
937
|
@model.tasks << @attachment
|
958
938
|
end
|
@@ -964,7 +944,7 @@ describe LeadsController do
|
|
964
944
|
#----------------------------------------------------------------------------
|
965
945
|
describe "responding to POST auto_complete" do
|
966
946
|
before(:each) do
|
967
|
-
@auto_complete_matches = [
|
947
|
+
@auto_complete_matches = [FactoryGirl.create(:lead, first_name: "Hello", last_name: "World", user: current_user)]
|
968
948
|
end
|
969
949
|
|
970
950
|
it_should_behave_like("auto complete")
|
@@ -974,57 +954,54 @@ describe LeadsController do
|
|
974
954
|
#----------------------------------------------------------------------------
|
975
955
|
describe "responding to GET redraw" do
|
976
956
|
it "should save user selected lead preference" do
|
977
|
-
xhr :get, :redraw, :
|
978
|
-
current_user.preference[:leads_per_page].
|
979
|
-
current_user.preference[:leads_index_view].
|
980
|
-
current_user.preference[:leads_sort_by].
|
981
|
-
current_user.preference[:leads_naming].
|
957
|
+
xhr :get, :redraw, per_page: 42, view: "long", sort_by: "first_name", naming: "after"
|
958
|
+
expect(current_user.preference[:leads_per_page]).to eq("42")
|
959
|
+
expect(current_user.preference[:leads_index_view]).to eq("long")
|
960
|
+
expect(current_user.preference[:leads_sort_by]).to eq("leads.first_name ASC")
|
961
|
+
expect(current_user.preference[:leads_naming]).to eq("after")
|
982
962
|
end
|
983
963
|
|
984
964
|
it "should set similar options for Contacts" do
|
985
|
-
xhr :get, :redraw, :
|
986
|
-
current_user.pref[:contacts_sort_by].
|
987
|
-
current_user.pref[:contacts_naming].
|
965
|
+
xhr :get, :redraw, sort_by: "first_name", naming: "after"
|
966
|
+
expect(current_user.pref[:contacts_sort_by]).to eq("contacts.first_name ASC")
|
967
|
+
expect(current_user.pref[:contacts_naming]).to eq("after")
|
988
968
|
end
|
989
969
|
|
990
970
|
it "should reset current page to 1" do
|
991
|
-
xhr :get, :redraw, :
|
992
|
-
session[:leads_current_page].
|
971
|
+
xhr :get, :redraw, per_page: 42, view: "long", sort_by: "first_name", naming: "after"
|
972
|
+
expect(session[:leads_current_page]).to eq(1)
|
993
973
|
end
|
994
974
|
|
995
975
|
it "should select @leads and render [index] template" do
|
996
976
|
@leads = [
|
997
|
-
FactoryGirl.create(:lead, :
|
998
|
-
FactoryGirl.create(:lead, :
|
977
|
+
FactoryGirl.create(:lead, first_name: "Alice", user: current_user),
|
978
|
+
FactoryGirl.create(:lead, first_name: "Bobby", user: current_user)
|
999
979
|
]
|
1000
980
|
|
1001
|
-
xhr :get, :redraw, :
|
1002
|
-
assigns(:leads).
|
1003
|
-
response.
|
981
|
+
xhr :get, :redraw, per_page: 1, sort_by: "first_name"
|
982
|
+
expect(assigns(:leads)).to eq([@leads.first])
|
983
|
+
expect(response).to render_template("leads/index")
|
1004
984
|
end
|
1005
985
|
end
|
1006
986
|
|
1007
987
|
# POST /leads/filter AJAX
|
1008
988
|
#----------------------------------------------------------------------------
|
1009
989
|
describe "responding to POST filter" do
|
1010
|
-
|
1011
990
|
it "should filter out leads as @leads and render :index action" do
|
1012
991
|
session[:leads_filter] = "contacted,rejected"
|
1013
992
|
|
1014
|
-
@leads = [
|
1015
|
-
xhr :post, :filter, :
|
1016
|
-
assigns[:leads].
|
1017
|
-
response.
|
1018
|
-
response.
|
993
|
+
@leads = [FactoryGirl.create(:lead, user: current_user, status: "new")]
|
994
|
+
xhr :post, :filter, status: "new"
|
995
|
+
expect(assigns[:leads]).to eq(@leads)
|
996
|
+
expect(response).to be_a_success
|
997
|
+
expect(response).to render_template("leads/index")
|
1019
998
|
end
|
1020
999
|
|
1021
1000
|
it "should reset current page to 1" do
|
1022
1001
|
@leads = []
|
1023
|
-
xhr :post, :filter, :
|
1002
|
+
xhr :post, :filter, status: "new"
|
1024
1003
|
|
1025
|
-
session[:leads_current_page].
|
1004
|
+
expect(session[:leads_current_page]).to eq(1)
|
1026
1005
|
end
|
1027
|
-
|
1028
1006
|
end
|
1029
|
-
|
1030
1007
|
end
|