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.

Files changed (534) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/.travis.yml +8 -5
  4. data/CHANGELOG +26 -0
  5. data/Gemfile +26 -26
  6. data/Gemfile.lock +280 -250
  7. data/Guardfile +0 -1
  8. data/README.md +7 -9
  9. data/Rakefile +1 -1
  10. data/app/assets/javascripts/application.js.erb +1 -0
  11. data/app/assets/javascripts/crm.js.coffee +6 -7
  12. data/app/assets/javascripts/search.js.coffee +7 -1
  13. data/app/assets/stylesheets/about.css.scss +10 -0
  14. data/app/assets/stylesheets/application.css.erb +2 -0
  15. data/app/assets/stylesheets/common.scss +1 -1
  16. data/app/controllers/admin/application_controller.rb +3 -3
  17. data/app/controllers/admin/field_groups_controller.rb +12 -7
  18. data/app/controllers/admin/fields_controller.rb +21 -17
  19. data/app/controllers/admin/groups_controller.rb +10 -4
  20. data/app/controllers/admin/plugins_controller.rb +1 -2
  21. data/app/controllers/admin/settings_controller.rb +1 -2
  22. data/app/controllers/admin/tags_controller.rb +10 -4
  23. data/app/controllers/admin/users_controller.rb +32 -12
  24. data/app/controllers/application_controller.rb +58 -38
  25. data/app/controllers/authentications_controller.rb +5 -8
  26. data/app/controllers/comments_controller.rb +15 -11
  27. data/app/controllers/emails_controller.rb +1 -2
  28. data/app/controllers/entities/accounts_controller.rb +20 -20
  29. data/app/controllers/entities/campaigns_controller.rb +25 -22
  30. data/app/controllers/entities/contacts_controller.rb +25 -24
  31. data/app/controllers/entities/leads_controller.rb +33 -31
  32. data/app/controllers/entities/opportunities_controller.rb +31 -28
  33. data/app/controllers/entities_controller.rb +26 -22
  34. data/app/controllers/home_controller.rb +18 -18
  35. data/app/controllers/lists_controller.rb +11 -7
  36. data/app/controllers/passwords_controller.rb +5 -6
  37. data/app/controllers/tasks_controller.rb +23 -18
  38. data/app/controllers/users_controller.rb +31 -7
  39. data/app/helpers/accounts_helper.rb +40 -42
  40. data/app/helpers/addresses_helper.rb +1 -3
  41. data/app/helpers/admin/application_helper.rb +4 -4
  42. data/app/helpers/admin/field_groups_helper.rb +5 -7
  43. data/app/helpers/admin/fields_helper.rb +2 -3
  44. data/app/helpers/admin/plugins_helper.rb +0 -1
  45. data/app/helpers/admin/settings_helper.rb +0 -1
  46. data/app/helpers/admin/tags_helper.rb +1 -1
  47. data/app/helpers/admin/users_helper.rb +16 -18
  48. data/app/helpers/application_helper.rb +127 -119
  49. data/app/helpers/authentications_helper.rb +0 -1
  50. data/app/helpers/campaigns_helper.rb +5 -7
  51. data/app/helpers/comments_helper.rb +0 -1
  52. data/app/helpers/contacts_helper.rb +0 -1
  53. data/app/helpers/home_helper.rb +14 -14
  54. data/app/helpers/javascript_helper.rb +30 -0
  55. data/app/helpers/leads_helper.rb +7 -7
  56. data/app/helpers/opportunities_helper.rb +8 -10
  57. data/app/helpers/passwords_helper.rb +0 -1
  58. data/app/helpers/tags_helper.rb +1 -3
  59. data/app/helpers/tasks_helper.rb +24 -26
  60. data/app/helpers/users_helper.rb +6 -7
  61. data/app/helpers/versions_helper.rb +3 -5
  62. data/app/inputs/date_pair_input.rb +6 -7
  63. data/app/inputs/date_time_input.rb +3 -4
  64. data/app/inputs/datetime_pair_input.rb +0 -1
  65. data/app/inputs/text_input.rb +2 -2
  66. data/app/mailers/dropbox_mailer.rb +4 -7
  67. data/app/mailers/subscription_mailer.rb +4 -5
  68. data/app/mailers/user_mailer.rb +7 -9
  69. data/app/models/entities/account.rb +31 -28
  70. data/app/models/entities/account_contact.rb +2 -1
  71. data/app/models/entities/account_opportunity.rb +1 -1
  72. data/app/models/entities/campaign.rb +22 -19
  73. data/app/models/entities/contact.rb +55 -53
  74. data/app/models/entities/contact_opportunity.rb +1 -1
  75. data/app/models/entities/lead.rb +49 -41
  76. data/app/models/entities/opportunity.rb +38 -38
  77. data/app/models/fields/custom_field.rb +21 -27
  78. data/app/models/fields/custom_field_date_pair.rb +7 -8
  79. data/app/models/fields/custom_field_datetime_pair.rb +0 -2
  80. data/app/models/fields/custom_field_pair.rb +8 -10
  81. data/app/models/fields/field.rb +29 -30
  82. data/app/models/fields/field_group.rb +4 -4
  83. data/app/models/list.rb +1 -1
  84. data/app/models/observers/entity_observer.rb +1 -1
  85. data/app/models/observers/lead_observer.rb +1 -1
  86. data/app/models/observers/opportunity_observer.rb +1 -1
  87. data/app/models/observers/task_observer.rb +1 -1
  88. data/app/models/polymorphic/address.rb +7 -7
  89. data/app/models/polymorphic/avatar.rb +8 -9
  90. data/app/models/polymorphic/comment.rb +16 -10
  91. data/app/models/polymorphic/email.rb +13 -6
  92. data/app/models/polymorphic/tag.rb +2 -2
  93. data/app/models/polymorphic/task.rb +45 -45
  94. data/{config/initializers/paper_trail.rb → app/models/polymorphic/version.rb} +26 -31
  95. data/app/models/setting.rb +12 -17
  96. data/app/models/users/ability.rb +5 -6
  97. data/app/models/users/authentication.rb +6 -5
  98. data/app/models/users/group.rb +1 -3
  99. data/app/models/users/permission.rb +3 -3
  100. data/app/models/users/preference.rb +7 -7
  101. data/app/models/users/user.rb +36 -43
  102. data/app/views/accounts/_top_section.html.haml +2 -2
  103. data/app/views/accounts/edit.js.haml +0 -1
  104. data/app/views/admin/fields/_field.html.haml +1 -1
  105. data/app/views/admin/tags/_tag.html.haml +1 -1
  106. data/app/views/admin/users/_user.html.haml +4 -4
  107. data/app/views/campaigns/_top_section.html.haml +1 -1
  108. data/app/views/campaigns/edit.js.haml +0 -2
  109. data/app/views/contacts/_top_section.html.haml +1 -1
  110. data/app/views/contacts/edit.js.haml +0 -1
  111. data/app/views/entities/_basic_search.html.haml +1 -1
  112. data/app/views/home/_account.html.haml +2 -2
  113. data/app/views/home/_opportunity.html.haml +2 -2
  114. data/app/views/layouts/_about.html.haml +1 -1
  115. data/app/views/leads/_top_section.html.haml +1 -1
  116. data/app/views/leads/edit.js.haml +0 -2
  117. data/app/views/lists/_sidebar.html.haml +1 -1
  118. data/app/views/opportunities/_top_section.html.haml +2 -2
  119. data/app/views/opportunities/edit.js.haml +0 -1
  120. data/app/views/shared/_tags.html.haml +2 -1
  121. data/app/views/tasks/_edit.html.haml +2 -3
  122. data/app/views/tasks/_top_section.html.haml +1 -1
  123. data/app/views/users/_user.html.haml +2 -1
  124. data/app/views/users/opportunities_overview.html.haml +2 -2
  125. data/bin/bundle +3 -0
  126. data/bin/rails +4 -0
  127. data/bin/rake +4 -0
  128. data/config/application.rb +16 -33
  129. data/config/boot.rb +1 -1
  130. data/config/database.mysql.mac.yml +1 -0
  131. data/config/database.mysql.yml +1 -0
  132. data/config/database.postgres.docker.yml +1 -1
  133. data/config/database.postgres.yml +1 -0
  134. data/config/database.sqlite.yml +1 -0
  135. data/config/deploy.example.rb +3 -5
  136. data/config/environments/development.rb +13 -14
  137. data/config/environments/production.rb +8 -7
  138. data/config/environments/staging.rb +43 -41
  139. data/config/environments/test.rb +12 -14
  140. data/config/initializers/assets.rb +14 -0
  141. data/config/initializers/backtrace_silencers.rb +7 -0
  142. data/config/initializers/cookies_serializer.rb +3 -0
  143. data/config/initializers/custom_field_ransack_translations.rb +1 -1
  144. data/config/initializers/filter_parameter_logging.rb +4 -0
  145. data/config/initializers/inflections.rb +16 -0
  146. data/config/initializers/mime_types.rb +0 -1
  147. data/config/initializers/paginate_arrays.rb +0 -1
  148. data/config/initializers/ransack.rb +5 -5
  149. data/config/initializers/session_store.rb +5 -0
  150. data/config/initializers/simple_form.rb +1 -1
  151. data/config/initializers/views.rb +33 -33
  152. data/config/initializers/wrap_parameters.rb +14 -0
  153. data/config/locales/cz_fat_free_crm.yml +1 -1
  154. data/config/locales/de_fat_free_crm.yml +2 -2
  155. data/config/locales/en-GB_fat_free_crm.yml +2 -3
  156. data/config/locales/en-US_fat_free_crm.yml +2 -3
  157. data/config/locales/en.yml +23 -0
  158. data/config/locales/es-CL.yml +227 -0
  159. data/config/locales/es-CL_fat_free_crm.yml +929 -0
  160. data/config/locales/es-CL_ransack.yml +91 -0
  161. data/config/locales/es.yml +53 -59
  162. data/config/locales/es_fat_free_crm.yml +708 -370
  163. data/config/locales/es_ransack.yml +91 -0
  164. data/config/locales/fr-CA_fat_free_crm.yml +7 -7
  165. data/config/locales/fr_fat_free_crm.yml +285 -81
  166. data/config/locales/it_fat_free_crm.yml +1 -1
  167. data/config/locales/ja_fat_free_crm.yml +1 -1
  168. data/config/locales/nl.yml +210 -0
  169. data/config/locales/nl_fat_free_crm.yml +920 -0
  170. data/config/locales/nl_ransack.yml +91 -0
  171. data/config/locales/pl_fat_free_crm.yml +1 -1
  172. data/config/locales/pt-BR_fat_free_crm.yml +111 -38
  173. data/config/locales/ru_fat_free_crm.yml +3 -4
  174. data/config/locales/sv-SE_fat_free_crm.yml +1 -1
  175. data/config/locales/th.rb +157 -158
  176. data/config/locales/th_fat_free_crm.yml +1 -1
  177. data/config/locales/zh-CN_fat_free_crm.yml +3 -4
  178. data/config/routes.rb +93 -94
  179. data/config/unicorn.rb +25 -2
  180. data/custom_plan.rb +0 -2
  181. data/db/demo/accounts.yml +4 -5
  182. data/db/demo/addresses.yml +5 -5
  183. data/db/demo/campaigns.yml +2 -2
  184. data/db/demo/comments.yml +1 -1
  185. data/db/demo/contacts.yml +8 -8
  186. data/db/demo/emails.yml +5 -5
  187. data/db/demo/leads.yml +10 -10
  188. data/db/demo/opportunities.yml +2 -2
  189. data/db/demo/tasks.yml +2 -2
  190. data/db/demo/users.yml +12 -16
  191. data/db/migrate/20100928030598_create_sessions.rb +1 -2
  192. data/db/migrate/20100928030599_create_users.rb +24 -25
  193. data/db/migrate/20100928030600_create_openid_tables.rb +11 -12
  194. data/db/migrate/20100928030601_create_accounts.rb +14 -15
  195. data/db/migrate/20100928030602_create_permissions.rb +2 -3
  196. data/db/migrate/20100928030603_create_settings.rb +4 -5
  197. data/db/migrate/20100928030604_create_preferences.rb +3 -4
  198. data/db/migrate/20100928030605_create_campaigns.rb +19 -20
  199. data/db/migrate/20100928030606_create_leads.rb +26 -27
  200. data/db/migrate/20100928030607_create_contacts.rb +26 -27
  201. data/db/migrate/20100928030608_create_opportunities.rb +15 -16
  202. data/db/migrate/20100928030609_create_account_contacts.rb +2 -3
  203. data/db/migrate/20100928030610_create_account_opportunities.rb +2 -3
  204. data/db/migrate/20100928030611_create_contact_opportunities.rb +3 -4
  205. data/db/migrate/20100928030612_create_tasks.rb +14 -15
  206. data/db/migrate/20100928030613_create_comments.rb +6 -7
  207. data/db/migrate/20100928030614_create_activities.rb +6 -7
  208. data/db/migrate/20100928030615_create_avatars.rb +5 -6
  209. data/db/migrate/20100928030616_rename_remember_token.rb +0 -1
  210. data/db/migrate/20100928030617_drop_openid_tables.rb +11 -11
  211. data/db/migrate/20100928030618_add_admin_to_users.rb +1 -2
  212. data/db/migrate/20100928030619_add_suspended_to_users.rb +0 -1
  213. data/db/migrate/20100928030620_remove_uuid.rb +3 -3
  214. data/db/migrate/20100928030621_add_email_to_accounts.rb +1 -2
  215. data/db/migrate/20100928030622_add_background_info_to_models.rb +0 -1
  216. data/db/migrate/20100928030623_create_addresses.rb +14 -16
  217. data/db/migrate/20100928030624_add_index_on_permissions.rb +2 -3
  218. data/db/migrate/20100928030625_create_emails.rb +15 -16
  219. data/db/migrate/20100928030626_add_state_to_timeline_objects.rb +2 -3
  220. data/db/migrate/20100928030627_acts_as_taggable_on_migration.rb +2 -3
  221. data/db/migrate/20101221123456_add_single_access_token_to_users.rb +0 -1
  222. data/db/migrate/20101221345678_add_rating_and_category_to_accounts.rb +2 -3
  223. data/db/migrate/20110719082054_add_skype_to_contacts_and_leads.rb +2 -3
  224. data/db/migrate/20111101083437_create_fields.rb +14 -15
  225. data/db/migrate/20111101090312_create_field_groups.rb +4 -5
  226. data/db/migrate/20111116091952_add_field_groups_tag_id.rb +0 -1
  227. data/db/migrate/20111117041311_change_fields_collection_to_text.rb +0 -1
  228. data/db/migrate/20111201030535_add_field_groups_klass_name.rb +4 -4
  229. data/db/migrate/20120121054235_create_lists.rb +1 -1
  230. data/db/migrate/20120216031616_create_versions.rb +5 -5
  231. data/db/migrate/20120216042541_is_paranoid_to_paper_trail.rb +1 -3
  232. data/db/migrate/20120224073107_remove_default_value_and_clear_settings.rb +1 -1
  233. data/db/migrate/20120316045804_activities_to_versions.rb +6 -6
  234. data/db/migrate/20120405080727_change_subscribed_users_to_set.rb +5 -5
  235. data/db/migrate/20120405080742_change_further_subscribed_users_to_set.rb +5 -5
  236. data/db/migrate/20120406082136_create_groups.rb +1 -1
  237. data/db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb +2 -1
  238. data/db/migrate/20120528102124_increase_length_of_version_events.rb +2 -2
  239. data/db/migrate/20121003063155_add_settings_to_custom_fields.rb +1 -1
  240. data/db/migrate/20121221033947_fix_country_mapping.rb +0 -1
  241. data/db/migrate/20131207033244_add_user_id_to_lists.rb +1 -1
  242. data/db/migrate/20141126031837_increase_email_to254_chars.rb +14 -14
  243. data/db/migrate/20141230021159_add_transaction_id_column_to_versions.rb +11 -0
  244. data/db/migrate/20141230205453_add_missing_unique_indices.acts_as_taggable_on_engine.rb +20 -0
  245. data/db/migrate/20141230205454_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +15 -0
  246. data/db/migrate/20141230205455_add_missing_taggable_index.acts_as_taggable_on_engine.rb +10 -0
  247. data/db/migrate/20150123060900_convert_radio_to_radio_buttons.rb +10 -0
  248. data/db/migrate/20150227123054_remove_last_request_at_from_users.rb +5 -0
  249. data/db/migrate/20150427131956_create_index_related_type.rb +9 -0
  250. data/db/migrate/20160511053730_add_account_contacts_index.rb +5 -0
  251. data/db/schema.rb +236 -228
  252. data/db/seeds.rb +1 -2
  253. data/db/seeds/fields.rb +36 -37
  254. data/{fig.yml → docker-compose.yml} +0 -0
  255. data/fat_free_crm.gemspec +31 -18
  256. data/lib/development_tasks/license.rake +29 -29
  257. data/lib/fat_free_crm.rb +1 -5
  258. data/lib/fat_free_crm/callback.rb +28 -20
  259. data/lib/fat_free_crm/comment_extensions.rb +1 -1
  260. data/lib/fat_free_crm/core_ext.rb +1 -1
  261. data/lib/fat_free_crm/core_ext/nil.rb +0 -3
  262. data/lib/fat_free_crm/core_ext/string.rb +7 -21
  263. data/lib/fat_free_crm/custom_fields.rb +2 -2
  264. data/lib/fat_free_crm/engine.rb +14 -0
  265. data/lib/fat_free_crm/errors.rb +0 -2
  266. data/lib/fat_free_crm/exceptions.rb +3 -4
  267. data/lib/fat_free_crm/export_csv.rb +0 -2
  268. data/lib/fat_free_crm/exportable.rb +5 -7
  269. data/lib/fat_free_crm/fields.rb +7 -8
  270. data/lib/fat_free_crm/gem_dependencies.rb +4 -1
  271. data/lib/fat_free_crm/gem_ext/active_record/schema_dumper.rb +2 -2
  272. data/lib/fat_free_crm/gem_ext/active_support/buffered_logger.rb +0 -3
  273. data/lib/fat_free_crm/gem_ext/rails/engine.rb +5 -12
  274. data/lib/fat_free_crm/gem_ext/rake/task.rb +1 -1
  275. data/lib/fat_free_crm/gem_ext/simple_form/action_view_extensions/form_helper.rb +1 -2
  276. data/lib/fat_free_crm/i18n.rb +2 -3
  277. data/lib/fat_free_crm/load_settings.rb +0 -2
  278. data/lib/fat_free_crm/mail_processor/base.rb +15 -16
  279. data/lib/fat_free_crm/mail_processor/comment_replies.rb +5 -10
  280. data/lib/fat_free_crm/mail_processor/dropbox.rb +56 -59
  281. data/lib/fat_free_crm/permissions.rb +18 -15
  282. data/lib/fat_free_crm/renderers.rb +2 -2
  283. data/lib/fat_free_crm/secret_token_generator.rb +3 -9
  284. data/lib/fat_free_crm/sortable.rb +4 -8
  285. data/lib/fat_free_crm/version.rb +2 -2
  286. data/lib/fat_free_crm/view_factory.rb +3 -8
  287. data/lib/gravatar_image_tag.rb +19 -24
  288. data/lib/missing_translation_detector.rb +10 -10
  289. data/lib/tasks/ffcrm/comment_replies.rake +3 -5
  290. data/lib/tasks/ffcrm/config.rake +3 -5
  291. data/lib/tasks/ffcrm/demo.rake +14 -16
  292. data/lib/tasks/ffcrm/dropbox.rake +3 -5
  293. data/lib/tasks/ffcrm/missing_translations.rake +1 -1
  294. data/lib/tasks/ffcrm/secret.rake +1 -3
  295. data/lib/tasks/ffcrm/settings.rake +2 -4
  296. data/lib/tasks/ffcrm/setup.rake +3 -6
  297. data/lib/tasks/ffcrm/update_data.rake +110 -116
  298. data/spec/controllers/admin/groups_controller_spec.rb +0 -1
  299. data/spec/controllers/admin/users_controller_spec.rb +98 -102
  300. data/spec/controllers/applications_controller_spec.rb +17 -21
  301. data/spec/controllers/authentications_controller_spec.rb +57 -61
  302. data/spec/controllers/comments_controller_spec.rb +32 -39
  303. data/spec/controllers/emails_controller_spec.rb +6 -7
  304. data/spec/controllers/entities/accounts_controller_spec.rb +204 -214
  305. data/spec/controllers/entities/campaigns_controller_spec.rb +210 -224
  306. data/spec/controllers/entities/contacts_controller_spec.rb +250 -270
  307. data/spec/controllers/entities/leads_controller_spec.rb +415 -438
  308. data/spec/controllers/entities/opportunities_controller_spec.rb +344 -359
  309. data/spec/controllers/entities_controller_spec.rb +10 -14
  310. data/spec/controllers/home_controller_spec.rb +85 -92
  311. data/spec/controllers/lists_controller_spec.rb +0 -1
  312. data/spec/controllers/passwords_controller_spec.rb +5 -9
  313. data/spec/controllers/tasks_controller_spec.rb +193 -210
  314. data/spec/controllers/users_controller_spec.rb +137 -146
  315. data/spec/factories/account_factories.rb +11 -13
  316. data/spec/factories/campaign_factories.rb +6 -6
  317. data/spec/factories/contact_factories.rb +21 -22
  318. data/spec/factories/field_factories.rb +8 -10
  319. data/spec/factories/lead_factories.rb +16 -16
  320. data/spec/factories/list_factories.rb +2 -2
  321. data/spec/factories/opportunity_factories.rb +8 -10
  322. data/spec/factories/sequences.rb +8 -9
  323. data/spec/factories/setting_factories.rb +2 -2
  324. data/spec/factories/shared_factories.rb +26 -30
  325. data/spec/factories/tag_factories.rb +1 -1
  326. data/spec/factories/task_factories.rb +11 -11
  327. data/spec/factories/user_factories.rb +22 -27
  328. data/spec/features/acceptance_helper.rb +1 -1
  329. data/spec/features/accounts_spec.rb +65 -61
  330. data/spec/features/admin/groups_spec.rb +11 -12
  331. data/spec/features/admin/users_spec.rb +17 -19
  332. data/spec/features/campaigns_spec.rb +61 -57
  333. data/spec/features/contacts_spec.rb +90 -59
  334. data/spec/features/dashboard_spec.rb +20 -21
  335. data/spec/features/leads_spec.rb +88 -67
  336. data/spec/features/opportunities_overview_spec.rb +31 -31
  337. data/spec/features/opportunities_spec.rb +64 -60
  338. data/spec/features/support/browser.rb +2 -2
  339. data/spec/features/support/headless.rb +1 -1
  340. data/spec/features/support/helpers.rb +5 -6
  341. data/spec/features/support/paths.rb +1 -2
  342. data/spec/features/support/selector_helpers.rb +2 -2
  343. data/spec/features/tasks_spec.rb +60 -54
  344. data/spec/helpers/accounts_helper_spec.rb +2 -5
  345. data/spec/helpers/admin/field_groups_helper_spec.rb +4 -4
  346. data/spec/helpers/admin/plugins_helper_spec.rb +0 -1
  347. data/spec/helpers/admin/settings_helper_spec.rb +0 -1
  348. data/spec/helpers/admin/users_helper_spec.rb +0 -1
  349. data/spec/helpers/application_helper_spec.rb +30 -33
  350. data/spec/helpers/authentications_helper_spec.rb +2 -5
  351. data/spec/helpers/campaigns_helper_spec.rb +2 -5
  352. data/spec/helpers/comments_helper_spec.rb +2 -5
  353. data/spec/helpers/contacts_helper_spec.rb +2 -5
  354. data/spec/helpers/emails_helper_spec.rb +0 -1
  355. data/spec/helpers/fields_helper_spec.rb +0 -1
  356. data/spec/helpers/groups_helper_spec.rb +0 -1
  357. data/spec/helpers/home_helper_spec.rb +2 -5
  358. data/spec/helpers/leads_helper_spec.rb +2 -5
  359. data/spec/helpers/lists_helper_spec.rb +0 -1
  360. data/spec/helpers/opportunities_helper_spec.rb +2 -5
  361. data/spec/helpers/passwords_helper_spec.rb +2 -5
  362. data/spec/helpers/tasks_helper_spec.rb +1 -5
  363. data/spec/helpers/users_helper_spec.rb +9 -11
  364. data/spec/lib/comment_extensions_spec.rb +3 -3
  365. data/spec/lib/core_ext/string_spec.rb +1 -1
  366. data/spec/lib/errors_spec.rb +10 -10
  367. data/spec/lib/fields_spec.rb +23 -33
  368. data/spec/lib/mail_processor/base_spec.rb +41 -43
  369. data/spec/lib/mail_processor/comment_replies_spec.rb +17 -17
  370. data/spec/lib/mail_processor/dropbox_spec.rb +91 -95
  371. data/spec/lib/mail_processor/sample_emails/dropbox.rb +13 -14
  372. data/spec/lib/permissions_spec.rb +44 -47
  373. data/spec/lib/secret_token_generator_spec.rb +16 -28
  374. data/spec/lib/view_factory_spec.rb +18 -24
  375. data/spec/mailers/subscription_mailer_spec.rb +14 -16
  376. data/spec/mailers/user_mailer_spec.rb +33 -34
  377. data/spec/models/entities/account_contact_spec.rb +2 -3
  378. data/spec/models/entities/account_opportunity_spec.rb +2 -3
  379. data/spec/models/entities/account_spec.rb +52 -59
  380. data/spec/models/entities/campaign_spec.rb +32 -39
  381. data/spec/models/entities/contact_opportunity_spec.rb +2 -3
  382. data/spec/models/entities/contact_spec.rb +71 -72
  383. data/spec/models/entities/lead_spec.rb +15 -22
  384. data/spec/models/entities/opportunity_spec.rb +104 -103
  385. data/spec/models/fields/custom_field_date_pair_spec.rb +38 -44
  386. data/spec/models/fields/custom_field_pair_spec.rb +28 -36
  387. data/spec/models/fields/custom_field_spec.rb +50 -56
  388. data/spec/models/fields/field_group_spec.rb +1 -2
  389. data/spec/models/fields/field_spec.rb +13 -15
  390. data/spec/models/list_spec.rb +4 -4
  391. data/spec/models/observers/entity_observer_spec.rb +18 -21
  392. data/spec/models/polymorphic/address_spec.rb +1 -3
  393. data/spec/models/polymorphic/avatar_spec.rb +6 -8
  394. data/spec/models/polymorphic/comment_spec.rb +7 -9
  395. data/spec/models/polymorphic/email_spec.rb +1 -2
  396. data/spec/models/polymorphic/task_spec.rb +130 -142
  397. data/spec/models/polymorphic/version_spec.rb +84 -91
  398. data/spec/models/setting_spec.rb +17 -19
  399. data/spec/models/users/abilities/user_ability_spec.rb +25 -20
  400. data/spec/models/users/authentication_spec.rb +0 -1
  401. data/spec/models/users/group_spec.rb +0 -1
  402. data/spec/models/users/permission_spec.rb +12 -13
  403. data/spec/models/users/preference_spec.rb +15 -15
  404. data/spec/models/users/user_spec.rb +53 -55
  405. data/spec/routing/accounts_routing_spec.rb +12 -14
  406. data/spec/routing/admin/users_routing_spec.rb +7 -9
  407. data/spec/routing/campaigns_routing_spec.rb +13 -14
  408. data/spec/routing/comments_routing_spec.rb +5 -6
  409. data/spec/routing/contacts_routing_spec.rb +12 -14
  410. data/spec/routing/emails_routing_spec.rb +7 -8
  411. data/spec/routing/leads_routing_spec.rb +19 -21
  412. data/spec/routing/opportunities_routing_spec.rb +13 -15
  413. data/spec/routing/tasks_routing_spec.rb +14 -15
  414. data/spec/routing/users_routing_spec.rb +18 -19
  415. data/spec/shared/controllers.rb +35 -35
  416. data/spec/shared/models.rb +52 -55
  417. data/spec/spec_helper.rb +21 -42
  418. data/spec/support/assert_select.rb +19 -18
  419. data/spec/support/auth_macros.rb +3 -3
  420. data/spec/support/macros.rb +5 -6
  421. data/spec/support/mail_processor_mocks.rb +11 -11
  422. data/spec/views/accounts/_edit.haml_spec.rb +9 -9
  423. data/spec/views/accounts/_new.haml_spec.rb +8 -9
  424. data/spec/views/accounts/create.js.haml_spec.rb +11 -12
  425. data/spec/views/accounts/destroy.js.haml_spec.rb +6 -7
  426. data/spec/views/accounts/edit.js.haml_spec.rb +12 -13
  427. data/spec/views/accounts/index.haml_spec.rb +8 -8
  428. data/spec/views/accounts/index.js.haml_spec.rb +7 -8
  429. data/spec/views/accounts/new.js.haml_spec.rb +7 -8
  430. data/spec/views/accounts/show.haml_spec.rb +11 -12
  431. data/spec/views/accounts/update.js.haml_spec.rb +18 -18
  432. data/spec/views/admin/field_groups/create.js.haml_spec.rb +8 -10
  433. data/spec/views/admin/field_groups/destroy.js.haml_spec.rb +7 -9
  434. data/spec/views/admin/field_groups/edit.js.haml_spec.rb +5 -7
  435. data/spec/views/admin/field_groups/new.js.haml_spec.rb +6 -8
  436. data/spec/views/admin/field_groups/update.js.haml_spec.rb +7 -9
  437. data/spec/views/admin/users/_create.haml_spec.rb +4 -4
  438. data/spec/views/admin/users/create.js.haml_spec.rb +8 -9
  439. data/spec/views/admin/users/destroy.js.haml_spec.rb +6 -6
  440. data/spec/views/admin/users/edit.js.haml_spec.rb +7 -9
  441. data/spec/views/admin/users/index.haml_spec.rb +4 -5
  442. data/spec/views/admin/users/index.js.haml_spec.rb +6 -8
  443. data/spec/views/admin/users/new.js.haml_spec.rb +4 -6
  444. data/spec/views/admin/users/reactivate.js.haml_spec.rb +4 -4
  445. data/spec/views/admin/users/show.haml_spec.rb +0 -1
  446. data/spec/views/admin/users/suspend.js.haml_spec.rb +4 -4
  447. data/spec/views/admin/users/update.js.haml_spec.rb +6 -7
  448. data/spec/views/application/auto_complete.haml_spec.rb +12 -14
  449. data/spec/views/authentications/new.haml_spec.rb +6 -7
  450. data/spec/views/campaigns/_edit.haml_spec.rb +9 -9
  451. data/spec/views/campaigns/_new.haml_spec.rb +8 -8
  452. data/spec/views/campaigns/create.js.haml_spec.rb +11 -12
  453. data/spec/views/campaigns/destroy.js.haml_spec.rb +7 -8
  454. data/spec/views/campaigns/edit.js.haml_spec.rb +12 -20
  455. data/spec/views/campaigns/index.haml_spec.rb +6 -7
  456. data/spec/views/campaigns/index.js.haml_spec.rb +9 -10
  457. data/spec/views/campaigns/new.js.haml_spec.rb +7 -8
  458. data/spec/views/campaigns/show.haml_spec.rb +12 -13
  459. data/spec/views/campaigns/update.js.haml_spec.rb +16 -16
  460. data/spec/views/comments/edit.js.haml_spec.rb +7 -7
  461. data/spec/views/contacts/_edit.haml_spec.rb +21 -21
  462. data/spec/views/contacts/_new.haml_spec.rb +12 -13
  463. data/spec/views/contacts/create.js.haml_spec.rb +12 -13
  464. data/spec/views/contacts/destroy.js.haml_spec.rb +6 -7
  465. data/spec/views/contacts/edit.js.haml_spec.rb +15 -17
  466. data/spec/views/contacts/index.haml_spec.rb +6 -7
  467. data/spec/views/contacts/index.js.html_spec.rb +7 -8
  468. data/spec/views/contacts/new.js.haml_spec.rb +8 -9
  469. data/spec/views/contacts/show.haml_spec.rb +9 -10
  470. data/spec/views/contacts/update.js.haml_spec.rb +26 -26
  471. data/spec/views/home/index.haml_spec.rb +4 -5
  472. data/spec/views/home/index.js.haml_spec.rb +6 -7
  473. data/spec/views/home/options.js.haml_spec.rb +10 -10
  474. data/spec/views/leads/_convert.haml_spec.rb +5 -6
  475. data/spec/views/leads/_edit.haml_spec.rb +13 -13
  476. data/spec/views/leads/_new.haml_spec.rb +11 -11
  477. data/spec/views/leads/_sidebar_show.haml_spec.rb +9 -9
  478. data/spec/views/leads/convert.js.haml_spec.rb +16 -17
  479. data/spec/views/leads/create.js.haml_spec.rb +16 -17
  480. data/spec/views/leads/destroy.js.haml_spec.rb +10 -11
  481. data/spec/views/leads/edit.js.haml_spec.rb +16 -17
  482. data/spec/views/leads/index.haml_spec.rb +7 -8
  483. data/spec/views/leads/index.js.haml_spec.rb +10 -11
  484. data/spec/views/leads/new.js.haml_spec.rb +8 -9
  485. data/spec/views/leads/promote.js.haml_spec.rb +30 -31
  486. data/spec/views/leads/reject.js.haml_spec.rb +10 -11
  487. data/spec/views/leads/show.haml_spec.rb +7 -8
  488. data/spec/views/leads/update.js.haml_spec.rb +28 -29
  489. data/spec/views/opportunities/_edit.haml_spec.rb +19 -19
  490. data/spec/views/opportunities/_new.haml_spec.rb +10 -10
  491. data/spec/views/opportunities/create.js.haml_spec.rb +19 -20
  492. data/spec/views/opportunities/destroy.js.haml_spec.rb +14 -15
  493. data/spec/views/opportunities/edit.js.haml_spec.rb +14 -16
  494. data/spec/views/opportunities/index.haml_spec.rb +6 -7
  495. data/spec/views/opportunities/index.js.haml_spec.rb +7 -8
  496. data/spec/views/opportunities/new.js.haml_spec.rb +8 -9
  497. data/spec/views/opportunities/show.haml_spec.rb +9 -10
  498. data/spec/views/opportunities/update.js.haml_spec.rb +35 -35
  499. data/spec/views/tasks/_edit.haml_spec.rb +9 -9
  500. data/spec/views/tasks/complete.js.haml_spec.rb +11 -12
  501. data/spec/views/tasks/create.js.haml_spec.rb +29 -31
  502. data/spec/views/tasks/destroy.js.haml_spec.rb +8 -8
  503. data/spec/views/tasks/edit.js.haml_spec.rb +12 -15
  504. data/spec/views/tasks/index.haml_spec.rb +7 -7
  505. data/spec/views/tasks/new.js.haml_spec.rb +7 -8
  506. data/spec/views/tasks/uncomplete.js.haml_spec.rb +6 -6
  507. data/spec/views/tasks/update.js.haml_spec.rb +41 -44
  508. data/spec/views/users/avatar.js.haml_spec.rb +7 -8
  509. data/spec/views/users/change_password.js.haml_spec.rb +9 -10
  510. data/spec/views/users/edit.js.haml_spec.rb +7 -8
  511. data/spec/views/users/password.js.haml_spec.rb +8 -9
  512. data/spec/views/users/update.js.haml_spec.rb +6 -7
  513. data/spec/views/users/upload_avatar.js.haml_spec.rb +9 -9
  514. data/vendor/assets/javascripts/jquery_timeago/index.js +2 -0
  515. data/vendor/assets/javascripts/jquery_timeago/jquery.timeago.es-CL.js +18 -0
  516. data/vendor/assets/javascripts/jquery_timeago/jquery.timeago.nl.js +20 -0
  517. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-es-CL.js +20 -0
  518. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-es-CL.js +23 -0
  519. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-nl.js +21 -0
  520. data/vendor/assets/stylesheets/{jquery-ui.custom.css → jquery-ui.custom.scss} +52 -51
  521. data/vendor/gems/globby-0.1.2/LICENSE.txt +20 -0
  522. data/vendor/gems/globby-0.1.2/README.md +65 -0
  523. data/vendor/gems/globby-0.1.2/Rakefile +9 -0
  524. data/vendor/gems/globby-0.1.2/lib/globby.rb +47 -0
  525. data/vendor/gems/globby-0.1.2/lib/globby/glob.rb +90 -0
  526. data/vendor/gems/globby-0.1.2/lib/globby/globject.rb +18 -0
  527. data/vendor/gems/globby-0.1.2/lib/globby/result.rb +20 -0
  528. data/vendor/gems/globby-0.1.2/spec/gitignore_spec.rb +109 -0
  529. data/vendor/gems/globby-0.1.2/spec/globby_spec.rb +93 -0
  530. metadata +177 -55
  531. data/Gemfile.ci +0 -13
  532. data/config/initializers/sass.rb +0 -18
  533. data/lib/country_select.rb +0 -570
  534. 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 = [ FactoryGirl.create(:lead, :user => current_user) ]
19
+ @leads = [FactoryGirl.create(:lead, user: current_user)]
22
20
 
23
21
  get :index
24
- assigns[:leads].should == @leads
25
- response.should render_template("leads/index")
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 = [ FactoryGirl.create(:lead, :user => current_user) ]
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)).should == []
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, :status => "new", :user => current_user),
40
- FactoryGirl.create(:lead, :status => "contacted", :user => current_user)
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, :status => "rejected", :user => current_user)
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.should == 2
49
- assigns[:leads].map(&:status).sort.should == %w(contacted new)
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, :user => current_user, :first_name => "Billy", :last_name => "Bones")
54
- @captain_flint = FactoryGirl.create(:lead, :user => current_user, :first_name => "Captain", :last_name => "Flint")
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, :query => "bill"
57
- assigns[:leads].should == [ @billy_bones ]
58
- assigns[:current_query].should == "bill"
59
- session[:leads_current_query].should == "bill"
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 = [ FactoryGirl.create(:lead, :user => current_user) ]
65
- xhr :get, :index, :page => 42
62
+ @leads = [FactoryGirl.create(:lead, user: current_user)]
63
+ xhr :get, :index, page: 42
66
64
 
67
- assigns[:current_page].to_i.should == 42
68
- assigns[:leads].should == [] # page #42 should be empty if there's only one lead ;-)
69
- session[:leads_current_page].to_i.should == 42
70
- response.should render_template("leads/index")
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 = [ FactoryGirl.create(:lead, :user => current_user) ]
77
- xhr :get, :index, :query => "bill"
74
+ @leads = [FactoryGirl.create(:lead, user: current_user)]
75
+ xhr :get, :index, query: "bill"
78
76
 
79
- assigns[:current_page].should == 42
80
- assigns[:leads].should == []
81
- response.should render_template("leads/index")
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 = [ FactoryGirl.create(:lead, :user => current_user) ]
85
+ @leads = [FactoryGirl.create(:lead, user: current_user)]
88
86
  xhr :get, :index
89
87
 
90
- assigns[:current_page].should == 1
91
- assigns[:leads].should == @leads
92
- response.should render_template("leads/index")
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.should_receive(:get_leads).and_return(leads = double("Array of Leads"))
99
- leads.should_receive(:to_json).and_return("generated JSON")
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.should == "generated JSON"
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.should_receive(:get_leads).and_return(leads = double("Array of Leads"))
110
- leads.should_receive(:to_xml).and_return("generated XML")
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.should == "generated XML"
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, :id => 42, :user => current_user)
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, :id => 42
132
- assigns[:lead].should == @lead
133
- assigns[:comment].attributes.should == @comment.attributes
134
- response.should render_template("leads/show")
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, :id => @lead.id
139
- @lead.versions.last.event.should == 'view'
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, :id => 42, :user => current_user)
146
- Lead.should_receive(:find).and_return(@lead)
147
- @lead.should_receive(:to_json).and_return("generated JSON")
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, :id => 42
151
- response.body.should == "generated JSON"
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, :id => 42, :user => current_user)
158
- Lead.should_receive(:find).and_return(@lead)
159
- @lead.should_receive(:to_xml).and_return("generated XML")
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, :id => 42
163
- response.body.should == "generated XML"
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, :user => current_user)
166
+ @lead = FactoryGirl.create(:lead, user: current_user)
170
167
  @lead.destroy
171
168
 
172
- get :show, :id => @lead.id
173
- flash[:warning].should_not == nil
174
- response.should redirect_to(leads_path)
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, :user => FactoryGirl.create(:user), :access => "Private")
175
+ @private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
179
176
 
180
- get :show, :id => @private.id
181
- flash[:warning].should_not == nil
182
- response.should redirect_to(leads_path)
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, :user => current_user)
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, :id => @lead.id
191
- response.code.should == "404" # :not_found
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, :user => current_user)
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, :id => @lead.id
200
- response.code.should == "404" # :not_found
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, :user => current_user, :campaign => nil)
213
- Lead.stub(:new).and_return(@lead)
214
- @campaigns = [ FactoryGirl.create(:campaign, :user => current_user) ]
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.should == @lead.attributes
218
- assigns[:campaigns].should == @campaigns
219
- response.should render_template("leads/new")
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, :id => 123)
218
+ @campaign = FactoryGirl.create(:campaign, id: 123)
224
219
 
225
- xhr :get, :new, :related => "campaign_123"
226
- assigns[:campaign].should == @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, :related => "campaign_#{@campaign.id}"
235
- flash[:warning].should_not == nil
236
- response.body.should == 'window.location.href = "/campaigns";'
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, :access => "Private")
235
+ @campaign = FactoryGirl.create(:campaign, access: "Private")
241
236
 
242
- xhr :get, :new, :related => "campaign_#{@campaign.id}"
243
- flash[:warning].should_not == nil
244
- response.body.should == 'window.location.href = "/campaigns";'
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, :id => 42, :user => current_user, :campaign => nil)
255
- @campaigns = [ FactoryGirl.create(:campaign, :user => current_user) ]
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, :id => 42
258
- assigns[:lead].should == @lead
259
- assigns[:campaigns].should == @campaigns
260
- response.should render_template("leads/edit")
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, :id => 42)
265
- @previous = FactoryGirl.create(:lead, :id => 321)
258
+ @lead = FactoryGirl.create(:lead, id: 42)
259
+ @previous = FactoryGirl.create(:lead, id: 321)
266
260
 
267
- xhr :get, :edit, :id => 42, :previous => 321
268
- assigns[:previous].should == @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, :user => current_user)
267
+ @lead = FactoryGirl.create(:lead, user: current_user)
274
268
  @lead.destroy
275
269
 
276
- xhr :get, :edit, :id => @lead.id
277
- flash[:warning].should_not == nil
278
- response.body.should == "window.location.reload();"
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, :user => FactoryGirl.create(:user), :access => "Private")
276
+ @private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
283
277
 
284
- xhr :get, :edit, :id => @private.id
285
- flash[:warning].should_not == nil
286
- response.body.should == "window.location.reload();"
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, :user => current_user)
293
- @previous = FactoryGirl.create(:lead, :user => FactoryGirl.create(:user))
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, :id => @lead.id, :previous => @previous.id
300
- flash[:warning].should == nil # no warning, just silently remove the div
301
- assigns[:previous].should == @previous.id
302
- response.should render_template("leads/edit")
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, :id => @lead.id, :previous => @previous.id
309
- flash[:warning].should == nil
310
- assigns[:previous].should == @previous.id
311
- response.should render_template("leads/edit")
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, :user => current_user, :campaign => nil)
325
- Lead.stub(:new).and_return(@lead)
326
- @campaigns = [ FactoryGirl.create(:campaign, :user => current_user) ]
327
-
328
- xhr :post, :create, :lead => { :first_name => "Billy", :last_name => "Bones" }
329
- assigns(:lead).should == @lead
330
- assigns(:campaigns).should == @campaigns
331
- assigns[:lead_status_total].should be_nil
332
- response.should render_template("leads/create")
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, :id => 7)
337
- she = FactoryGirl.create(:user, :id => 8)
338
- @campaign = FactoryGirl.build(:campaign, :access => "Shared")
339
- @campaign.permissions << FactoryGirl.build(:permission, :user => he, :asset => @campaign)
340
- @campaign.permissions << FactoryGirl.build(:permission, :user => she, :asset => @campaign)
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, :campaign => @campaign, :user => current_user, :access => "Shared")
344
- Lead.stub(:new).and_return(@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, :lead => { :first_name => "Billy", :last_name => "Bones", :access => "Campaign", :user_ids => %w(7 8) }, :campaign => @campaign.id
347
- assigns(:lead).should == @lead
348
- @lead.reload.access.should == "Shared"
349
- @lead.permissions.map(&:user_id).sort.should == [ 7, 8 ]
350
- @lead.permissions.map(&:asset_id).should == [ @lead.id, @lead.id ]
351
- @lead.permissions.map(&:asset_type).should == %w(Lead Lead)
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, :user => current_user, :campaign => nil)
356
- Lead.stub(:new).and_return(@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, :lead => { :first_name => "Billy", :last_name => "Bones" }
360
- assigns[:lead_status_total].should be_an_instance_of(HashWithIndifferentAccess)
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, :user => current_user, :campaign => nil)
365
- Lead.stub(:new).and_return(@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, :lead => { :first_name => "Billy", :last_name => "Bones" }
369
- assigns[:leads].should == [ @lead ]
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, :user => current_user, :campaign => @campaign)
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, :lead => { :first_name => "Billy", :last_name => "Bones"}, :campaign => @campaign.id
378
- assigns[:campaign].should == @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.stub(:new).and_return(@lead)
384
- xhr :post, :create, :lead => { :first_name => "Test", :last_name => "Lead" }, :comment_body => "This is an important lead."
385
- @lead.reload.comments.map(&:comment).should include("This is an important lead.")
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, :user => current_user, :first_name => nil, :campaign => nil)
393
- Lead.stub(:new).and_return(@lead)
394
- @campaigns = [ FactoryGirl.create(:campaign, :user => current_user) ]
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, :first_name => "Billy", :user => current_user)
402
+ @lead = FactoryGirl.create(:lead, first_name: "Billy", user: current_user)
416
403
 
417
- xhr :put, :update, :id => @lead.id, :lead => { :first_name => "Bones" }
418
- @lead.reload.first_name.should == "Bones"
419
- assigns[:lead].should == @lead
420
- assigns[:lead_status_total].should == nil
421
- response.should render_template("leads/update")
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, :status => "new", :user => current_user)
412
+ @lead = FactoryGirl.create(:lead, status: "new", user: current_user)
426
413
 
427
- xhr :put, :update, :id => @lead.id, :lead => { :status => "rejected" }
428
- @lead.reload.status.should == "rejected"
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, :source => "campaign", :user => current_user)
419
+ @lead = FactoryGirl.create(:lead, source: "campaign", user: current_user)
433
420
 
434
- xhr :put, :update, :id => @lead.id, :lead => { :source => "cald_call" }
435
- @lead.reload.source.should == "cald_call"
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 = { :old => FactoryGirl.create(:campaign), :new => FactoryGirl.create(:campaign) }
440
- @lead = FactoryGirl.create(:lead, :campaign => @campaigns[:old])
426
+ @campaigns = { old: FactoryGirl.create(:campaign), new: FactoryGirl.create(:campaign) }
427
+ @lead = FactoryGirl.create(:lead, campaign: @campaigns[:old])
441
428
 
442
- xhr :put, :update, :id => @lead.id, :lead => { :campaign_id => @campaigns[:new].id }
443
- @lead.reload.campaign.should == @campaigns[:new]
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, :campaign => @campaign)
435
+ @lead = FactoryGirl.create(:lead, campaign: @campaign)
449
436
  @count = @campaign.reload.leads_count
450
437
 
451
- xhr :put, :update, :id => @lead, :lead => { :campaign_id => nil }
452
- @lead.reload.campaign.should == nil
453
- @campaign.reload.leads_count.should == @count - 1
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, :campaign => nil)
445
+ @lead = FactoryGirl.create(:lead, campaign: nil)
459
446
  @count = @campaign.leads_count
460
447
 
461
- xhr :put, :update, :id => @lead, :lead => { :campaign_id => @campaign.id }
462
- @lead.reload.campaign.should == @campaign
463
- @campaign.reload.leads_count.should == @count + 1
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 = { :old => FactoryGirl.create(:campaign), :new => FactoryGirl.create(:campaign) }
468
- @lead = FactoryGirl.create(:lead, :campaign => @campaigns[:old])
469
- @counts = { :old => @campaigns[:old].reload.leads_count, :new => @campaigns[:new].leads_count }
470
-
471
- xhr :put, :update, :id => @lead, :lead => { :campaign_id => @campaigns[:new].id }
472
- @lead.reload.campaign.should == @campaigns[:new]
473
- @campaigns[:old].reload.leads_count.should == @counts[:old] - 1
474
- @campaigns[:new].reload.leads_count.should == @counts[:new] + 1
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, :user => current_user)
479
- he = FactoryGirl.create(:user, :id => 7)
480
- she = FactoryGirl.create(:user, :id => 8)
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, :id => @lead.id, :lead => { :access => "Shared", :user_ids => %w(7 8) }
483
- @lead.user_ids.sort.should == [ 7, 8 ]
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, :id => @lead.id, :lead => { :first_name => "Billy" }
491
- assigns[:lead_status_total].should_not be_nil
492
- assigns[:lead_status_total].should be_an_instance_of(HashWithIndifferentAccess)
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, :campaign => @campaign)
484
+ @lead = FactoryGirl.create(:lead, campaign: @campaign)
498
485
 
499
486
  request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
500
- xhr :put, :update, :id => @lead.id, :lead => { :first_name => "Hello" }
501
- assigns[:campaign].should == @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, :user => current_user)
493
+ @lead = FactoryGirl.create(:lead, user: current_user)
507
494
  @lead.destroy
508
495
 
509
- xhr :put, :update, :id => @lead.id
510
- flash[:warning].should_not == nil
511
- response.body.should == "window.location.reload();"
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, :user => FactoryGirl.create(:user), :access => "Private")
502
+ @private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
516
503
 
517
- xhr :put, :update, :id => @private.id
518
- flash[:warning].should_not == nil
519
- response.body.should == "window.location.reload();"
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, :id => 42, :user => current_user, :campaign => nil)
528
- @campaigns = [ FactoryGirl.create(:campaign, :user => current_user) ]
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, :id => 42, :lead => { :first_name => nil }
531
- assigns[:lead].should == @lead
532
- assigns[:campaigns].should == @campaigns
533
- response.should render_template("leads/update")
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, :user => current_user)
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, :id => @lead.id
534
+ xhr :delete, :destroy, id: @lead.id
552
535
 
553
- assigns[:leads].should == nil # @lead got deleted
554
- lambda { Lead.find(@lead) }.should raise_error(ActiveRecord::RecordNotFound)
555
- response.should render_template("leads/destroy")
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, :user => current_user)
547
+ @another_lead = FactoryGirl.create(:lead, user: current_user)
565
548
 
566
- xhr :delete, :destroy, :id => @lead.id
567
- assigns[:leads].should == [ @another_lead ] # @lead got deleted
568
- assigns[:lead_status_total].should_not be_nil
569
- assigns[:lead_status_total].should be_an_instance_of(HashWithIndifferentAccess)
570
- response.should render_template("leads/destroy")
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, :id => @lead.id
577
- session[:leads_current_page].should == 41
578
- response.should render_template("leads/index")
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, :id => @lead.id
585
- session[:leads_current_page].should == 1
586
- response.should render_template("leads/index")
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, :user => current_user, :campaign => @campaign)
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, :id => @lead.id
599
- session[:leads_current_page].should == 1
600
- response.should render_template("leads/destroy")
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, :id => @lead.id
605
- assigns[:campaign].should == @campaign
606
- response.should render_template("leads/destroy")
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, :user => current_user)
595
+ @lead = FactoryGirl.create(:lead, user: current_user)
613
596
  @lead.destroy
614
597
 
615
- xhr :delete, :destroy, :id => @lead.id
616
- flash[:warning].should_not == nil
617
- response.body.should == "window.location.reload();"
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, :user => FactoryGirl.create(:user), :access => "Private")
604
+ @private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
622
605
 
623
- xhr :delete, :destroy, :id => @private.id
624
- flash[:warning].should_not == nil
625
- response.body.should == "window.location.reload();"
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, :id => @lead.id
633
- flash[:notice].should_not == nil
634
- session[:leads_current_page].should == 1
635
- response.should redirect_to(leads_path)
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, :user => current_user)
622
+ @lead = FactoryGirl.create(:lead, user: current_user)
640
623
  @lead.destroy
641
624
 
642
- delete :destroy, :id => @lead.id
643
- flash[:warning].should_not == nil
644
- response.should redirect_to(leads_path)
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, :user => FactoryGirl.create(:user), :access => "Private")
631
+ @private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
649
632
 
650
- delete :destroy, :id => @private.id
651
- flash[:warning].should_not == nil
652
- response.should redirect_to(leads_path)
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, :user => current_user)
664
- @lead = FactoryGirl.create(:lead, :user => current_user, :campaign => @campaign, :source => "cold_call")
665
- @accounts = [ FactoryGirl.create(:account, :user => current_user) ]
666
- @account = Account.new(:user => current_user, :name => @lead.company, :access => "Lead")
667
- @opportunity = Opportunity.new(:user => current_user, :access => "Lead", :stage => "prospecting", :campaign => @lead.campaign, :source => @lead.source)
668
-
669
- xhr :get, :convert, :id => @lead.id
670
- assigns[:lead].should == @lead
671
- assigns[:accounts].should == @accounts
672
- assigns[:account].attributes.should == @account.attributes
673
- assigns[:opportunity].attributes.should == @opportunity.attributes
674
- assigns[:opportunity].campaign.should == @opportunity.campaign
675
- response.should render_template("leads/convert")
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, :user => current_user)
662
+ @lead = FactoryGirl.create(:lead, user: current_user)
681
663
  @lead.destroy
682
664
 
683
- xhr :get, :convert, :id => @lead.id
684
- flash[:warning].should_not == nil
685
- response.body.should == "window.location.reload();"
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, :user => FactoryGirl.create(:user), :access => "Private")
671
+ @private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
690
672
 
691
- xhr :get, :convert, :id => @private.id
692
- flash[:warning].should_not == nil
693
- response.body.should == "window.location.reload();"
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, :user => current_user)
700
- @previous = FactoryGirl.create(:lead, :user => FactoryGirl.create(:user))
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, :id => @lead.id, :previous => @previous.id
707
- flash[:warning].should == nil # no warning, just silently remove the div
708
- assigns[:previous].should == @previous.id
709
- response.should render_template("leads/convert")
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, :id => @lead.id, :previous => @previous.id
716
- flash[:warning].should == nil
717
- assigns[:previous].should == @previous.id
718
- response.should render_template("leads/convert")
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, :id => 42, :user => current_user, :campaign => nil)
730
- @account = FactoryGirl.create(:account, :id => 123, :user => current_user)
731
- @opportunity = FactoryGirl.build(:opportunity, :user => current_user, :campaign => @lead.campaign,
732
- :account => @account)
733
- Opportunity.stub(:new).and_return(@opportunity)
734
- @contact = FactoryGirl.build(:contact, :user => current_user, :lead => @lead)
735
- Contact.stub(:new).and_return(@contact)
736
-
737
- xhr :put, :promote, :id => 42, :account => { :id => 123 }, :opportunity => { :name => "Hello" }
738
- @lead.reload.status.should == "converted"
739
- assigns[:lead].should == @lead
740
- assigns[:account].should == @account
741
- assigns[:accounts].should == [ @account ]
742
- assigns[:opportunity].should == @opportunity
743
- assigns[:contact].should == @contact
744
- assigns[:stage].should be_instance_of(Array)
745
- response.should render_template("leads/promote")
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, :id => 7)
750
- she = FactoryGirl.create(:user, :id => 8)
751
- @lead = FactoryGirl.build(:lead, :access => "Shared")
752
- @lead.permissions << FactoryGirl.build(:permission, :user => he, :asset => @lead)
753
- @lead.permissions << FactoryGirl.build(:permission, :user => she, :asset => @lead)
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, :user => current_user, :access => "Shared")
756
- @account.permissions << FactoryGirl.create(:permission, :user => he, :asset => @account)
757
- @account.permissions << FactoryGirl.create(:permission, :user => she, :asset => @account)
758
- @account.stub(:new).and_return(@account)
759
- @opportunity = FactoryGirl.build(:opportunity, :user => current_user, :access => "Shared")
760
- @opportunity.permissions << FactoryGirl.create(:permission, :user => he, :asset => @opportunity)
761
- @opportunity.permissions << FactoryGirl.create(:permission, :user => she, :asset => @opportunity)
762
- @opportunity.stub(:new).and_return(@opportunity)
763
-
764
- 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 }
765
- @account.access.should == "Shared"
766
- @account.permissions.map(&:user_id).sort.should == [ 7, 8 ]
767
- @account.permissions.map(&:asset_id).should == [ @account.id, @account.id ]
768
- @account.permissions.map(&:asset_type).should == %w(Account Account)
769
- @opportunity.access.should == "Shared"
770
- @opportunity.permissions.map(&:user_id).sort.should == [ 7, 8 ]
771
- @opportunity.permissions.map(&:asset_id).should == [ @opportunity.id, @opportunity.id ]
772
- @opportunity.permissions.map(&:asset_type).should == %w(Opportunity Opportunity)
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, :user => current_user, :campaign => @campaign)
758
+ @lead = FactoryGirl.create(:lead, user: current_user, campaign: @campaign)
778
759
 
779
- xhr :put, :promote, :id => @lead.id, :account => { :name => "Hello" }, :opportunity => { :name => "Hello", :campaign_id => @campaign.id }
780
- assigns[:opportunity].campaign.should == @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, :user => current_user, :source => "cold_call")
765
+ @lead = FactoryGirl.create(:lead, user: current_user, source: "cold_call")
785
766
 
786
- xhr :put, :promote, :id => @lead.id, :account => { :name => "Hello" }, :opportunity => { :name => "Hello", :source => @lead.source }
787
- assigns[:opportunity].source.should == @lead.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, :id => @lead.id, :account => { :name => "Hello" }, :opportunity => {}
795
- assigns[:lead_status_total].should_not be_nil
796
- assigns[:lead_status_total].should be_an_instance_of(HashWithIndifferentAccess)
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, :campaign => @campaign)
782
+ @lead = FactoryGirl.create(:lead, campaign: @campaign)
802
783
  request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
803
784
 
804
- xhr :put, :promote, :id => @lead.id, :account => { :name => "Hello" }, :opportunity => {}
805
- assigns[:campaign].should == @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, :id => 42, :user => current_user, :status => "new")
810
- @account = FactoryGirl.create(:account, :id => 123, :user => current_user)
811
- @contact = FactoryGirl.build(:contact, :first_name => nil) # make it fail
812
- Contact.stub(:new).and_return(@contact)
813
-
814
- xhr :put, :promote, :id => 42, :account => { :id => 123 }
815
- @lead.reload.status.should == "new"
816
- response.should render_template("leads/promote")
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, :user => current_user)
802
+ @lead = FactoryGirl.create(:lead, user: current_user)
822
803
  @lead.destroy
823
804
 
824
- xhr :put, :promote, :id => @lead.id
825
- flash[:warning].should_not == nil
826
- response.body.should == "window.location.reload();"
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, :user => FactoryGirl.create(:user), :access => "Private")
811
+ @private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
831
812
 
832
- xhr :put, :promote, :id => @private.id
833
- flash[:warning].should_not == nil
834
- response.body.should == "window.location.reload();"
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, :user => current_user, :status => "new")
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, :id => @lead.id
830
+ xhr :put, :reject, id: @lead.id
851
831
 
852
- assigns[:lead].should == @lead.reload
853
- @lead.status.should == "rejected"
854
- response.should render_template("leads/reject")
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, :id => @lead.id
860
- assigns[:lead_status_total].should_not be_nil
861
- assigns[:lead_status_total].should be_an_instance_of(HashWithIndifferentAccess)
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, :campaign => @campaign)
846
+ @lead = FactoryGirl.create(:lead, campaign: @campaign)
867
847
 
868
848
  request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
869
- xhr :put, :reject, :id => @lead.id
870
- assigns[:campaign].should == @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, :user => current_user)
855
+ @lead = FactoryGirl.create(:lead, user: current_user)
876
856
  @lead.destroy
877
857
 
878
- xhr :put, :reject, :id => @lead.id
879
- flash[:warning].should_not == nil
880
- response.body.should == "window.location.reload();"
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, :user => FactoryGirl.create(:user), :access => "Private")
864
+ @private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
885
865
 
886
- xhr :put, :reject, :id => @private.id
887
- flash[:warning].should_not == nil
888
- response.body.should == "window.location.reload();"
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, :id => @lead.id
875
+ put :reject, id: @lead.id
896
876
 
897
- assigns[:lead].should == @lead.reload
898
- @lead.status.should == "rejected"
899
- flash[:notice].should_not == nil
900
- response.should redirect_to(leads_path)
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, :user => current_user)
885
+ @lead = FactoryGirl.create(:lead, user: current_user)
906
886
  @lead.destroy
907
887
 
908
- put :reject, :id => @lead.id
909
- flash[:warning].should_not == nil
910
- response.should redirect_to(leads_path)
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, :user => FactoryGirl.create(:user), :access => "Private")
894
+ @private = FactoryGirl.create(:lead, user: FactoryGirl.create(:user), access: "Private")
915
895
 
916
- put :reject, :id => @private.id
917
- flash[:warning].should_not == nil
918
- response.should redirect_to(leads_path)
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, :asset => nil)
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, :asset => nil)
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, :assigned_to => current_user)
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 = [ FactoryGirl.create(:lead, :first_name => "Hello", :last_name => "World", :user => current_user) ]
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, :per_page => 42, :view => "long", :sort_by => "first_name", :naming => "after"
978
- current_user.preference[:leads_per_page].should == "42"
979
- current_user.preference[:leads_index_view].should == "long"
980
- current_user.preference[:leads_sort_by].should == "leads.first_name ASC"
981
- current_user.preference[:leads_naming].should == "after"
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, :sort_by => "first_name", :naming => "after"
986
- current_user.pref[:contacts_sort_by].should == "contacts.first_name ASC"
987
- current_user.pref[:contacts_naming].should == "after"
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, :per_page => 42, :view => "long", :sort_by => "first_name", :naming => "after"
992
- session[:leads_current_page].should == 1
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, :first_name => "Alice", :user => current_user),
998
- FactoryGirl.create(:lead, :first_name => "Bobby", :user => current_user)
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, :per_page => 1, :sort_by => "first_name"
1002
- assigns(:leads).should == [ @leads.first ]
1003
- response.should render_template("leads/index")
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 = [ FactoryGirl.create(:lead, :user => current_user, :status => "new") ]
1015
- xhr :post, :filter, :status => "new"
1016
- assigns[:leads].should == @leads
1017
- response.should be_a_success
1018
- response.should render_template("leads/index")
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, :status => "new"
1002
+ xhr :post, :filter, status: "new"
1024
1003
 
1025
- session[:leads_current_page].should == 1
1004
+ expect(session[:leads_current_page]).to eq(1)
1026
1005
  end
1027
-
1028
1006
  end
1029
-
1030
1007
  end