fat_free_crm 0.11.3 → 0.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fat_free_crm might be problematic. Click here for more details.

Files changed (637) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +2 -2
  3. data/CHANGELOG +6 -1
  4. data/CONTRIBUTORS +40 -1
  5. data/Capfile +5 -0
  6. data/Gemfile +25 -6
  7. data/Gemfile.lock +128 -86
  8. data/README.md +23 -16
  9. data/{vendor → app}/assets/images/delete.png +0 -0
  10. data/app/assets/javascripts/admin/fields.js.coffee +62 -0
  11. data/app/assets/javascripts/application.js.erb +8 -1
  12. data/app/assets/javascripts/crm.js +44 -46
  13. data/app/assets/javascripts/crm_chosen.js.coffee +10 -7
  14. data/app/assets/javascripts/datepicker.js.coffee +15 -0
  15. data/app/assets/javascripts/format_buttons.js.coffee +48 -0
  16. data/app/assets/javascripts/{admin/field_groups.js.coffee → groups.js.coffee} +0 -0
  17. data/app/assets/javascripts/lists.js.coffee +1 -1
  18. data/app/assets/javascripts/search.js.coffee +56 -38
  19. data/app/assets/stylesheets/admin/{field_groups.css.scss → fields.css.scss} +4 -0
  20. data/app/assets/stylesheets/advanced_search.css.scss +79 -0
  21. data/app/assets/stylesheets/application.css.erb +4 -0
  22. data/app/assets/stylesheets/base.scss +3 -3
  23. data/app/assets/stylesheets/common.scss +72 -25
  24. data/app/assets/stylesheets/fields.scss +14 -0
  25. data/app/assets/stylesheets/format_buttons.css.scss +30 -0
  26. data/app/assets/stylesheets/groups.css.scss +3 -0
  27. data/app/assets/stylesheets/header.scss +7 -6
  28. data/{vendor/plugins/.gitkeep → app/assets/stylesheets/index_headers.css.scss} +0 -0
  29. data/app/assets/stylesheets/print.css.scss +12 -3
  30. data/app/assets/stylesheets/rails.scss +12 -3
  31. data/app/controllers/admin/application_controller.rb +1 -1
  32. data/app/controllers/admin/field_groups_controller.rb +2 -0
  33. data/app/controllers/admin/fields_controller.rb +41 -17
  34. data/app/controllers/admin/groups_controller.rb +70 -0
  35. data/app/controllers/admin/tags_controller.rb +1 -0
  36. data/app/controllers/admin/users_controller.rb +8 -7
  37. data/app/controllers/application_controller.rb +34 -5
  38. data/app/controllers/comments_controller.rb +2 -3
  39. data/app/controllers/entities/accounts_controller.rb +30 -37
  40. data/app/controllers/entities/campaigns_controller.rb +56 -29
  41. data/app/controllers/entities/contacts_controller.rb +24 -26
  42. data/app/controllers/entities/leads_controller.rb +38 -37
  43. data/app/controllers/entities/opportunities_controller.rb +28 -34
  44. data/app/controllers/entities_controller.rb +71 -43
  45. data/app/controllers/home_controller.rb +29 -27
  46. data/app/controllers/tasks_controller.rb +18 -17
  47. data/app/controllers/users_controller.rb +12 -8
  48. data/app/helpers/accounts_helper.rb +58 -16
  49. data/app/helpers/addresses_helper.rb +4 -1
  50. data/app/helpers/admin/fields_helper.rb +3 -4
  51. data/app/helpers/application_helper.rb +147 -100
  52. data/app/helpers/campaigns_helper.rb +2 -9
  53. data/app/helpers/fields_helper.rb +0 -1
  54. data/app/helpers/groups_helper.rb +2 -0
  55. data/app/helpers/home_helper.rb +11 -0
  56. data/app/helpers/leads_helper.rb +2 -9
  57. data/app/helpers/opportunities_helper.rb +2 -9
  58. data/app/helpers/{crm_tags_helper.rb → tags_helper.rb} +9 -8
  59. data/app/helpers/tasks_helper.rb +5 -21
  60. data/app/helpers/users_helper.rb +14 -7
  61. data/app/helpers/versions_helper.rb +46 -0
  62. data/app/inputs/date_time_input.rb +8 -25
  63. data/app/inputs/datepair_input.rb +77 -0
  64. data/app/inputs/datetimepair_input.rb +37 -0
  65. data/app/mailers/user_mailer.rb +10 -0
  66. data/app/models/entities/account.rb +18 -11
  67. data/app/models/entities/account_contact.rb +4 -3
  68. data/app/models/entities/account_opportunity.rb +0 -1
  69. data/app/models/entities/campaign.rb +6 -7
  70. data/app/models/entities/contact.rb +53 -25
  71. data/app/models/entities/contact_opportunity.rb +0 -1
  72. data/app/models/entities/lead.rb +24 -13
  73. data/app/models/entities/opportunity.rb +34 -16
  74. data/app/models/fields/custom_field.rb +29 -13
  75. data/app/models/fields/custom_field_date_pair.rb +58 -0
  76. data/app/models/fields/custom_field_datetime_pair.rb +28 -0
  77. data/app/models/fields/custom_field_pair.rb +54 -0
  78. data/app/models/fields/field.rb +60 -43
  79. data/app/models/fields/field_group.rb +0 -9
  80. data/app/models/observers/entity_observer.rb +29 -0
  81. data/app/models/observers/opportunity_observer.rb +3 -0
  82. data/app/models/polymorphic/address.rb +14 -0
  83. data/app/models/polymorphic/avatar.rb +13 -1
  84. data/app/models/polymorphic/email.rb +1 -1
  85. data/app/models/polymorphic/task.rb +14 -13
  86. data/app/models/setting.rb +14 -21
  87. data/app/models/users/ability.rb +25 -4
  88. data/app/models/users/group.rb +13 -0
  89. data/app/models/users/permission.rb +3 -1
  90. data/app/models/users/preference.rb +1 -2
  91. data/app/models/users/user.rb +25 -3
  92. data/app/views/accounts/_account.html.haml +5 -39
  93. data/app/views/accounts/_edit.html.haml +3 -2
  94. data/app/views/accounts/_index_brief.html.haml +32 -0
  95. data/app/views/accounts/_index_long.html.haml +42 -0
  96. data/app/views/accounts/_new.html.haml +3 -2
  97. data/app/views/accounts/_sidebar_index.html.haml +3 -4
  98. data/app/views/accounts/_sidebar_show.html.haml +2 -2
  99. data/app/views/accounts/_title_bar.html.haml +11 -0
  100. data/app/views/accounts/_top_section.html.haml +1 -1
  101. data/app/views/accounts/create.js.rjs +1 -2
  102. data/app/views/accounts/destroy.js.rjs +1 -1
  103. data/app/views/accounts/edit.js.rjs +0 -2
  104. data/app/views/accounts/index.html.haml +6 -13
  105. data/app/views/accounts/index.js.rjs +3 -1
  106. data/app/views/accounts/index.xls.builder +82 -0
  107. data/app/views/accounts/new.js.rjs +0 -2
  108. data/app/views/accounts/show.html.haml +17 -15
  109. data/app/views/accounts/show.js.erb +2 -0
  110. data/app/views/admin/custom_fields/_base_field.html.haml +21 -0
  111. data/app/views/admin/custom_fields/_check_boxes_field.html.haml +6 -0
  112. data/app/views/admin/custom_fields/_date_field.html.haml +14 -0
  113. data/app/views/admin/custom_fields/_date_pair_field.html.haml +21 -0
  114. data/app/views/admin/custom_fields/_datetime_field.html.haml +14 -0
  115. data/app/views/admin/custom_fields/_datetime_pair_field.html.haml +21 -0
  116. data/app/views/admin/custom_fields/_radio_field.html.haml +6 -0
  117. data/app/views/admin/custom_fields/_select_field.html.haml +25 -0
  118. data/app/views/admin/custom_fields/_string_field.html.haml +2 -0
  119. data/app/views/admin/field_groups/_field_group.html.haml +7 -5
  120. data/app/views/admin/field_groups/_top_section.html.haml +4 -3
  121. data/app/views/admin/field_groups/create.js.rjs +1 -2
  122. data/app/views/admin/fields/_field.html.haml +5 -3
  123. data/app/views/admin/fields/_form.html.haml +35 -0
  124. data/app/views/admin/fields/_subform.html.haml +6 -0
  125. data/app/views/admin/fields/create.js.erb +19 -0
  126. data/app/views/admin/fields/destroy.js.erb +9 -0
  127. data/app/views/admin/fields/edit.js.erb +1 -0
  128. data/app/views/admin/fields/index.html.haml +11 -8
  129. data/app/views/admin/fields/update.js.erb +13 -0
  130. data/app/views/admin/groups/_edit.html.haml +12 -0
  131. data/app/views/admin/groups/_form.html.haml +13 -0
  132. data/app/views/admin/groups/_group.html.haml +15 -0
  133. data/app/views/admin/groups/_new.html.haml +12 -0
  134. data/app/views/admin/groups/create.js.rjs +11 -0
  135. data/app/views/admin/{fields → groups}/destroy.js.rjs +3 -3
  136. data/app/views/admin/groups/edit.js.rjs +21 -0
  137. data/app/views/admin/groups/index.html.haml +18 -0
  138. data/app/views/admin/groups/index.js.rjs +2 -0
  139. data/app/views/admin/groups/new.js.rjs +9 -0
  140. data/app/views/admin/groups/show.html.haml +11 -0
  141. data/app/views/admin/groups/update.js.rjs +10 -0
  142. data/app/views/admin/users/_profile.html.haml +13 -1
  143. data/app/views/admin/users/_user.html.haml +7 -2
  144. data/app/views/admin/users/index.js.rjs +1 -0
  145. data/app/views/application/index.atom.builder +1 -1
  146. data/app/views/application/index.rss.builder +1 -1
  147. data/app/views/application/show.atom.builder +32 -0
  148. data/app/views/application/show.rss.builder +29 -0
  149. data/app/views/campaigns/_campaign.html.haml +5 -21
  150. data/app/views/campaigns/_edit.html.haml +3 -2
  151. data/app/views/campaigns/_index_brief.html.haml +15 -0
  152. data/app/views/campaigns/_index_long.html.haml +20 -0
  153. data/app/views/campaigns/_new.html.haml +4 -2
  154. data/app/views/campaigns/_sidebar_index.html.haml +3 -3
  155. data/app/views/campaigns/_title_bar.html.haml +11 -0
  156. data/app/views/campaigns/_top_section.html.haml +2 -2
  157. data/app/views/campaigns/create.js.rjs +1 -4
  158. data/app/views/campaigns/destroy.js.rjs +1 -1
  159. data/app/views/campaigns/edit.js.rjs +0 -4
  160. data/app/views/campaigns/index.html.haml +6 -13
  161. data/app/views/campaigns/index.js.rjs +3 -1
  162. data/app/views/campaigns/index.xls.builder +75 -0
  163. data/app/views/campaigns/new.js.rjs +0 -4
  164. data/app/views/campaigns/show.html.haml +17 -15
  165. data/app/views/campaigns/show.js.erb +2 -0
  166. data/app/views/campaigns/update.js.rjs +0 -2
  167. data/app/views/comments/_comment.html.haml +6 -5
  168. data/app/views/comments/_edit.html.haml +5 -5
  169. data/app/views/comments/_new.html.haml +6 -5
  170. data/app/views/comments/create.js.rjs +1 -1
  171. data/app/views/contacts/_contact.html.haml +5 -52
  172. data/app/views/contacts/_contacts.html.haml +1 -0
  173. data/app/views/contacts/_edit.html.haml +3 -2
  174. data/app/views/contacts/_index_brief.html.haml +25 -0
  175. data/app/views/contacts/_index_full.html.haml +57 -0
  176. data/app/views/contacts/_index_long.html.haml +43 -0
  177. data/app/views/contacts/_new.html.haml +4 -2
  178. data/app/views/contacts/_section_extra.html.haml +26 -0
  179. data/app/views/contacts/_section_general.html.haml +22 -0
  180. data/app/views/contacts/_sidebar_index.html.haml +0 -3
  181. data/app/views/contacts/_sidebar_show.html.haml +2 -10
  182. data/app/views/contacts/_title_bar.html.haml +11 -0
  183. data/app/views/contacts/_top_section.html.haml +1 -1
  184. data/app/views/contacts/create.js.rjs +1 -2
  185. data/app/views/contacts/destroy.js.rjs +1 -1
  186. data/app/views/contacts/edit.js.rjs +0 -2
  187. data/app/views/contacts/index.html.haml +6 -14
  188. data/app/views/contacts/index.js.rjs +3 -1
  189. data/app/views/contacts/index.xls.builder +102 -0
  190. data/app/views/contacts/new.js.rjs +0 -2
  191. data/app/views/contacts/show.html.haml +15 -15
  192. data/app/views/contacts/show.js.erb +2 -0
  193. data/app/views/entities/_basic_search.html.haml +22 -0
  194. data/app/views/entities/_permissions.html.haml +41 -0
  195. data/app/views/entities/_search.html.haml +15 -0
  196. data/app/views/entities/_section_custom_fields.html.haml +11 -0
  197. data/app/views/entities/_title_bar.html.haml +12 -0
  198. data/app/views/entities/attach.js.rjs +1 -1
  199. data/app/views/entities/opportunities.js.rjs +1 -1
  200. data/app/views/entities/versions.js.erb +3 -0
  201. data/app/views/fields/_edit_custom_field_group.html.haml +8 -0
  202. data/app/views/fields/_group.html.haml +11 -20
  203. data/app/views/fields/_group_table.html.haml +13 -0
  204. data/app/views/fields/_group_view.html.haml +7 -0
  205. data/app/views/fields/_groups.html.haml +1 -4
  206. data/app/views/fields/_sidebar_show.html.haml +5 -4
  207. data/app/views/home/_account.html.haml +29 -0
  208. data/app/views/home/_activity.html.haml +16 -6
  209. data/app/views/home/_opportunity.html.haml +41 -0
  210. data/app/views/home/_options.html.haml +1 -1
  211. data/app/views/home/_task.html.haml +46 -0
  212. data/app/views/home/index.html.haml +32 -1
  213. data/app/views/home/index.js.rjs +1 -0
  214. data/app/views/layouts/_header.html.haml +3 -3
  215. data/app/views/layouts/_sidebar.html.haml +1 -3
  216. data/app/views/layouts/_tabbed.html.haml +2 -3
  217. data/app/views/layouts/_tabless.html.haml +1 -1
  218. data/app/views/layouts/admin/_header.html.haml +1 -1
  219. data/app/views/layouts/application.html.haml +7 -8
  220. data/app/views/layouts/header.xls.builder +8 -0
  221. data/app/views/leads/_contact.html.haml +1 -2
  222. data/app/views/leads/_convert.html.haml +1 -2
  223. data/app/views/leads/_convert_permissions.html.haml +21 -11
  224. data/app/views/leads/_edit.html.haml +3 -2
  225. data/app/views/leads/_index_brief.html.haml +41 -0
  226. data/app/views/leads/_index_long.html.haml +62 -0
  227. data/app/views/leads/_lead.html.haml +5 -62
  228. data/app/views/leads/_new.html.haml +4 -2
  229. data/app/views/leads/_opportunity.html.haml +1 -1
  230. data/app/views/leads/_sidebar_index.html.haml +3 -3
  231. data/app/views/leads/_sidebar_show.html.haml +3 -3
  232. data/app/views/leads/_status.html.haml +1 -1
  233. data/app/views/leads/_title_bar.html.haml +16 -0
  234. data/app/views/leads/convert.js.rjs +0 -1
  235. data/app/views/leads/create.js.rjs +1 -2
  236. data/app/views/leads/destroy.js.rjs +1 -1
  237. data/app/views/leads/edit.js.rjs +0 -2
  238. data/app/views/leads/index.html.haml +6 -13
  239. data/app/views/leads/index.js.rjs +3 -1
  240. data/app/views/leads/index.xls.builder +100 -0
  241. data/app/views/leads/new.js.rjs +0 -2
  242. data/app/views/leads/promote.js.rjs +0 -1
  243. data/app/views/leads/show.html.haml +13 -18
  244. data/app/views/leads/show.js.erb +2 -0
  245. data/app/views/{shared/_lists.html.haml → lists/_sidebar.html.haml} +0 -0
  246. data/app/views/lists/create.js.rjs +1 -1
  247. data/app/views/opportunities/_edit.html.haml +3 -2
  248. data/app/views/opportunities/_index_brief.html.haml +29 -0
  249. data/app/views/opportunities/_index_long.html.haml +59 -0
  250. data/app/views/opportunities/_new.html.haml +4 -2
  251. data/app/views/opportunities/_opportunity.html.haml +5 -57
  252. data/app/views/opportunities/_sidebar_index.html.haml +3 -3
  253. data/app/views/opportunities/_sidebar_show.html.haml +2 -2
  254. data/app/views/opportunities/_title_bar.html.haml +11 -0
  255. data/app/views/opportunities/_top_section.html.haml +2 -2
  256. data/app/views/opportunities/create.js.rjs +4 -6
  257. data/app/views/opportunities/destroy.js.rjs +1 -1
  258. data/app/views/opportunities/edit.js.rjs +0 -3
  259. data/app/views/opportunities/index.html.haml +6 -14
  260. data/app/views/opportunities/index.js.rjs +3 -1
  261. data/app/views/opportunities/index.xls.builder +69 -0
  262. data/app/views/opportunities/new.js.rjs +1 -5
  263. data/app/views/opportunities/show.html.haml +14 -14
  264. data/app/views/opportunities/show.js.erb +2 -0
  265. data/app/views/opportunities/update.js.rjs +0 -1
  266. data/app/views/passwords/new.html.haml +1 -1
  267. data/app/views/shared/_add_comment.html.haml +8 -0
  268. data/app/views/shared/_address.html.haml +1 -1
  269. data/app/views/shared/_address_show.html.haml +1 -1
  270. data/app/views/shared/_edit_comment.html.haml +2 -2
  271. data/app/views/shared/_export.html.haml +2 -1
  272. data/app/views/shared/_paginate_with_per_page.html.haml +14 -0
  273. data/app/views/shared/_recently.html.haml +1 -1
  274. data/app/views/shared/_search.html.haml +1 -1
  275. data/app/views/shared/_tags.html.haml +1 -2
  276. data/app/views/shared/_tasks.html.haml +2 -2
  277. data/app/views/tasks/_completed.html.haml +3 -3
  278. data/app/views/tasks/_new.html.haml +1 -1
  279. data/app/views/tasks/_pending.html.haml +2 -3
  280. data/app/views/tasks/_sidebar_index.html.haml +2 -2
  281. data/app/views/tasks/_top_section.html.haml +5 -3
  282. data/app/views/tasks/create.js.rjs +3 -4
  283. data/app/views/tasks/edit.js.rjs +2 -4
  284. data/app/views/tasks/index.html.haml +1 -1
  285. data/app/views/tasks/index.xls.builder +47 -0
  286. data/app/views/tasks/new.js.rjs +0 -2
  287. data/app/views/tasks/update.js.rjs +0 -1
  288. data/app/views/user_mailer/assigned_entity_notification.html.haml +3 -0
  289. data/app/views/users/_user.html.haml +2 -2
  290. data/app/views/users/_user_report.html.haml +6 -0
  291. data/app/views/users/opportunities_overview.html.haml +16 -0
  292. data/app/views/users/show.html.haml +2 -3
  293. data/app/views/users/update.js.rjs +1 -1
  294. data/app/views/versions/_version.html.haml +4 -19
  295. data/app/views/versions/_version_item.html.haml +8 -0
  296. data/app/views/versions/_versions.html.haml +9 -9
  297. data/config/application.rb +10 -2
  298. data/config/deploy.example.rb +47 -0
  299. data/config/environments/development.rb +1 -0
  300. data/config/environments/production.rb +1 -3
  301. data/config/environments/staging.rb +1 -1
  302. data/config/initializers/action_mailer.rb +10 -8
  303. data/config/initializers/custom_fields.rb +21 -0
  304. data/config/initializers/gravatar.rb +7 -0
  305. data/config/initializers/paper_trail.rb +1 -0
  306. data/config/initializers/ransack.rb +15 -0
  307. data/config/initializers/simple_form.rb +1 -2
  308. data/config/initializers/views.rb +42 -0
  309. data/config/locales/cz_fat_free_crm.yml +0 -10
  310. data/config/locales/de_fat_free_crm.yml +23 -21
  311. data/config/locales/en-GB_fat_free_crm.yml +241 -25
  312. data/config/locales/en-US_fat_free_crm.yml +139 -57
  313. data/config/locales/en-US_ransack.yml +92 -0
  314. data/config/locales/es_fat_free_crm.yml +0 -6
  315. data/config/locales/fr-CA_fat_free_crm.yml +0 -6
  316. data/config/locales/fr_fat_free_crm.yml +3 -14
  317. data/config/locales/it_fat_free_crm.yml +0 -11
  318. data/config/locales/ja_fat_free_crm.yml +0 -10
  319. data/config/locales/pl_fat_free_crm.yml +0 -6
  320. data/config/locales/pt-BR_fat_free_crm.yml +0 -6
  321. data/config/locales/ru_fat_free_crm.yml +0 -9
  322. data/config/locales/sv-SE_fat_free_crm.yml +0 -10
  323. data/config/locales/th_fat_free_crm.yml +0 -6
  324. data/config/locales/zh-CN.yml +4 -0
  325. data/config/locales/zh-CN_fat_free_crm.yml +78 -47
  326. data/config/routes.rb +13 -0
  327. data/config/settings.default.yml +20 -20
  328. data/db/demo/addresses.yml +2 -2
  329. data/db/migrate/20100928030598_create_sessions.rb +5 -0
  330. data/db/migrate/20100928030627_acts_as_taggable_on_migration.rb +6 -6
  331. data/db/migrate/20111201030535_add_field_groups_klass_name.rb +2 -1
  332. data/db/migrate/20120406082136_create_groups.rb +19 -0
  333. data/db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb +21 -0
  334. data/db/migrate/20120528102124_increase_length_of_version_events.rb +9 -0
  335. data/db/migrate/20120801032706_add_pair_id_to_fields.rb +5 -0
  336. data/db/migrate/20121003063155_add_settings_to_custom_fields.rb +5 -0
  337. data/db/migrate/20121221033947_fix_country_mapping.rb +32 -0
  338. data/db/schema.rb +25 -6
  339. data/fat_free_crm.gemspec +16 -13
  340. data/lib/fat_free_crm.rb +2 -0
  341. data/lib/fat_free_crm/comment_extensions.rb +23 -0
  342. data/lib/fat_free_crm/core_ext/array.rb +8 -2
  343. data/lib/fat_free_crm/fields.rb +24 -2
  344. data/lib/fat_free_crm/gem_dependencies.rb +7 -1
  345. data/lib/fat_free_crm/permissions.rb +47 -26
  346. data/lib/fat_free_crm/version.rb +1 -1
  347. data/lib/fat_free_crm/view_factory.rb +95 -0
  348. data/lib/plugins/country_select/lib/country_select.rb +393 -374
  349. data/lib/tasks/{plugins.rake → db/migrate.rake} +1 -1
  350. data/lib/tasks/{schema_upgrade.rake → db/schema.rake} +2 -1
  351. data/lib/tasks/{mail_processing.rake → ffcrm/comment_replies.rake} +2 -21
  352. data/lib/tasks/ffcrm/config.rake +33 -0
  353. data/lib/tasks/{demo.rake → ffcrm/demo.rake} +3 -2
  354. data/lib/tasks/ffcrm/dropbox.rake +42 -0
  355. data/lib/tasks/ffcrm/settings.rake +46 -0
  356. data/lib/tasks/{fat_free_crm.rake → ffcrm/setup.rake} +1 -39
  357. data/lib/tasks/ffcrm/update_data.rake +256 -0
  358. data/{acceptance → spec/acceptance}/acceptance_helper.rb +5 -4
  359. data/{acceptance → spec/acceptance}/accounts_spec.rb +36 -10
  360. data/spec/acceptance/admin/groups_spec.rb +26 -0
  361. data/spec/acceptance/admin/users_spec.rb +34 -0
  362. data/spec/acceptance/campaigns_spec.rb +101 -0
  363. data/spec/acceptance/contacts_spec.rb +101 -0
  364. data/spec/acceptance/dashboard_spec.rb +62 -0
  365. data/spec/acceptance/leads_spec.rb +109 -0
  366. data/spec/acceptance/opportunities_overview_spec.rb +82 -0
  367. data/spec/acceptance/opportunities_spec.rb +103 -0
  368. data/{acceptance → spec/acceptance}/support/browser.rb +0 -0
  369. data/{acceptance → spec/acceptance}/support/headless.rb +0 -0
  370. data/{acceptance → spec/acceptance}/support/helpers.rb +8 -1
  371. data/{acceptance → spec/acceptance}/support/maintain_sessions.rb +0 -0
  372. data/spec/acceptance/support/paths.rb +42 -0
  373. data/spec/acceptance/support/selector_helpers.rb +31 -0
  374. data/spec/acceptance/tasks_spec.rb +85 -0
  375. data/spec/controllers/admin/groups_controller_spec.rb +5 -0
  376. data/spec/controllers/admin/users_controller_spec.rb +2 -3
  377. data/spec/controllers/applications_controller_spec.rb +40 -0
  378. data/spec/controllers/comments_controller_spec.rb +5 -6
  379. data/spec/controllers/emails_controller_spec.rb +1 -2
  380. data/spec/controllers/entities/accounts_controller_spec.rb +65 -81
  381. data/spec/controllers/entities/campaigns_controller_spec.rb +69 -85
  382. data/spec/controllers/entities/contacts_controller_spec.rb +78 -95
  383. data/spec/controllers/entities/leads_controller_spec.rb +105 -127
  384. data/spec/controllers/entities/opportunities_controller_spec.rb +88 -103
  385. data/spec/controllers/entities_controller_spec.rb +39 -0
  386. data/spec/controllers/home_controller_spec.rb +101 -11
  387. data/spec/controllers/tasks_controller_spec.rb +27 -32
  388. data/spec/controllers/users_controller_spec.rb +95 -28
  389. data/spec/factories/account_factories.rb +2 -2
  390. data/spec/factories/opportunity_factories.rb +12 -4
  391. data/spec/factories/task_factories.rb +4 -0
  392. data/spec/factories/user_factories.rb +9 -2
  393. data/spec/helpers/application_helper_spec.rb +15 -1
  394. data/spec/helpers/groups_helper_spec.rb +15 -0
  395. data/spec/helpers/users_helper_spec.rb +26 -4
  396. data/spec/lib/comment_extensions_spec.rb +29 -0
  397. data/spec/lib/core_ext/{string.rb → string_spec.rb} +0 -1
  398. data/spec/lib/fields_spec.rb +104 -0
  399. data/spec/lib/permissions_spec.rb +144 -0
  400. data/spec/lib/view_factory_spec.rb +68 -0
  401. data/spec/mailers/subscription_mailer_spec.rb +18 -4
  402. data/spec/mailers/user_mailer_spec.rb +134 -0
  403. data/spec/models/entities/account_spec.rb +44 -4
  404. data/spec/models/entities/campaign_spec.rb +3 -4
  405. data/spec/models/entities/contact_spec.rb +45 -5
  406. data/spec/models/entities/lead_spec.rb +3 -4
  407. data/spec/models/entities/opportunity_spec.rb +105 -9
  408. data/spec/models/fields/custom_field_date_pair_spec.rb +106 -0
  409. data/spec/models/fields/custom_field_pair_spec.rb +94 -0
  410. data/spec/models/fields/custom_field_spec.rb +43 -23
  411. data/spec/models/fields/field_spec.rb +3 -5
  412. data/spec/models/observers/entity_observer_spec.rb +65 -0
  413. data/spec/models/polymorphic/task_spec.rb +74 -118
  414. data/spec/models/polymorphic/version_spec.rb +18 -18
  415. data/spec/models/users/group_spec.rb +5 -0
  416. data/spec/models/users/permission_spec.rb +18 -1
  417. data/spec/models/users/preference_spec.rb +5 -1
  418. data/spec/models/users/user_spec.rb +55 -8
  419. data/spec/shared/models.rb +54 -0
  420. data/spec/spec_helper.rb +82 -87
  421. data/spec/support/auth_macros.rb +2 -3
  422. data/spec/views/accounts/_edit.haml_spec.rb +1 -2
  423. data/spec/views/accounts/_new.haml_spec.rb +1 -2
  424. data/spec/views/accounts/create.rjs_spec.rb +1 -3
  425. data/spec/views/accounts/edit.rjs_spec.rb +3 -4
  426. data/spec/views/accounts/index.haml_spec.rb +9 -6
  427. data/spec/views/accounts/new.rjs_spec.rb +2 -9
  428. data/spec/views/accounts/show.haml_spec.rb +1 -2
  429. data/spec/views/accounts/update.rjs_spec.rb +2 -3
  430. data/spec/views/admin/users/_create.haml_spec.rb +1 -2
  431. data/spec/views/admin/users/create.rjs_spec.rb +1 -2
  432. data/spec/views/campaigns/_edit.haml_spec.rb +2 -3
  433. data/spec/views/campaigns/_new.haml_spec.rb +2 -3
  434. data/spec/views/campaigns/create.rjs_spec.rb +0 -3
  435. data/spec/views/campaigns/destroy.rjs_spec.rb +1 -2
  436. data/spec/views/campaigns/edit.rjs_spec.rb +3 -6
  437. data/spec/views/campaigns/index.haml_spec.rb +6 -3
  438. data/spec/views/campaigns/new.rjs_spec.rb +2 -13
  439. data/spec/views/campaigns/show.haml_spec.rb +4 -6
  440. data/spec/views/campaigns/update.rjs_spec.rb +2 -7
  441. data/spec/views/contacts/_edit.haml_spec.rb +6 -7
  442. data/spec/views/contacts/_new.haml_spec.rb +2 -3
  443. data/spec/views/contacts/create.rjs_spec.rb +1 -3
  444. data/spec/views/contacts/edit.rjs_spec.rb +3 -4
  445. data/spec/views/contacts/index.haml_spec.rb +6 -3
  446. data/spec/views/contacts/new.rjs_spec.rb +2 -11
  447. data/spec/views/contacts/show.haml_spec.rb +1 -2
  448. data/spec/views/contacts/update.rjs_spec.rb +2 -3
  449. data/spec/views/home/index.haml_spec.rb +6 -2
  450. data/spec/views/home/index.rjs_spec.rb +1 -2
  451. data/spec/views/home/options.rjs_spec.rb +1 -2
  452. data/spec/views/leads/_convert.haml_spec.rb +1 -2
  453. data/spec/views/leads/_edit.haml_spec.rb +2 -3
  454. data/spec/views/leads/_new.haml_spec.rb +2 -3
  455. data/spec/views/leads/_sidebar_show.haml_spec.rb +1 -2
  456. data/spec/views/leads/convert.rjs_spec.rb +3 -5
  457. data/spec/views/leads/edit.rjs_spec.rb +4 -5
  458. data/spec/views/leads/index.haml_spec.rb +6 -3
  459. data/spec/views/leads/new.rjs_spec.rb +2 -11
  460. data/spec/views/leads/promote.rjs_spec.rb +3 -5
  461. data/spec/views/leads/show.haml_spec.rb +1 -2
  462. data/spec/views/leads/update.rjs_spec.rb +2 -3
  463. data/spec/views/opportunities/_edit.haml_spec.rb +5 -6
  464. data/spec/views/opportunities/_new.haml_spec.rb +2 -4
  465. data/spec/views/opportunities/create.rjs_spec.rb +0 -2
  466. data/spec/views/opportunities/edit.rjs_spec.rb +3 -4
  467. data/spec/views/opportunities/index.haml_spec.rb +7 -4
  468. data/spec/views/opportunities/new.rjs_spec.rb +2 -12
  469. data/spec/views/opportunities/show.haml_spec.rb +1 -2
  470. data/spec/views/opportunities/update.rjs_spec.rb +2 -3
  471. data/spec/views/tasks/_edit.haml_spec.rb +1 -3
  472. data/spec/views/tasks/complete.rjs_spec.rb +2 -3
  473. data/spec/views/tasks/create.rjs_spec.rb +2 -2
  474. data/spec/views/tasks/edit.rjs_spec.rb +1 -2
  475. data/spec/views/tasks/new.rjs_spec.rb +1 -18
  476. data/spec/views/users/avatar.rjs_spec.rb +1 -2
  477. data/spec/views/users/change_password.rjs_spec.rb +1 -2
  478. data/spec/views/users/edit.rjs_spec.rb +1 -2
  479. data/spec/views/users/password.rjs_spec.rb +1 -1
  480. data/spec/views/users/update.rjs_spec.rb +1 -2
  481. data/spec/views/users/upload_avatar.rjs_spec.rb +6 -7
  482. data/vendor/assets/images/brief.png +0 -0
  483. data/vendor/assets/images/chosen-sprite.png +0 -0
  484. data/vendor/assets/images/full.png +0 -0
  485. data/vendor/assets/images/jquery-ui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  486. data/vendor/assets/images/jquery-ui/ui-bg_flat_0_eeeeee_40x100.png +0 -0
  487. data/vendor/assets/images/jquery-ui/ui-bg_flat_100_ffffff_40x100.png +0 -0
  488. data/vendor/assets/images/jquery-ui/ui-bg_flat_25_3875d7_40x100.png +0 -0
  489. data/vendor/assets/images/jquery-ui/ui-bg_flat_55_ffffff_40x100.png +0 -0
  490. data/vendor/assets/images/jquery-ui/ui-bg_flat_65_3875d7_40x100.png +0 -0
  491. data/vendor/assets/images/jquery-ui/ui-bg_flat_75_ffffff_40x100.png +0 -0
  492. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_50_dddddd_1x100.png +0 -0
  493. data/vendor/assets/images/jquery-ui/{ui-icons_ef8c08_256x240.png → ui-icons_0073ea_256x240.png} +0 -0
  494. data/vendor/assets/images/jquery-ui/ui-icons_466bb1_256x240.png +0 -0
  495. data/vendor/assets/images/jquery-ui/{ui-icons_ffd27a_256x240.png → ui-icons_ff0084_256x240.png} +0 -0
  496. data/vendor/assets/images/long.png +0 -0
  497. data/vendor/assets/javascripts/chosen-jquery.js +3 -0
  498. data/vendor/assets/javascripts/chosen-prototype.js +3 -0
  499. data/vendor/assets/javascripts/chosen.jquery.coffee +574 -0
  500. data/vendor/assets/javascripts/chosen.proto.coffee +580 -0
  501. data/vendor/assets/javascripts/jquery.disable.js +23 -0
  502. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-addon.js +1882 -0
  503. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-af.js +20 -0
  504. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-ca.js +20 -0
  505. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-cz.js +20 -0
  506. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-de.js +20 -0
  507. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-el.js +20 -0
  508. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-es.js +20 -0
  509. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-et.js +20 -0
  510. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-fi.js +20 -0
  511. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-fr-CA.js +20 -0
  512. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-fr.js +20 -0
  513. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-gl.js +20 -0
  514. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-he.js +20 -0
  515. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-hu.js +20 -0
  516. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-id.js +20 -0
  517. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-it.js +20 -0
  518. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-ja.js +20 -0
  519. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-ko.js +20 -0
  520. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-lt.js +20 -0
  521. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-nl.js +20 -0
  522. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-no.js +20 -0
  523. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-pl.js +20 -0
  524. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-pt.js +20 -0
  525. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-ro.js +20 -0
  526. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-ru.js +20 -0
  527. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-sk.js +20 -0
  528. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-sv.js +20 -0
  529. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-tr.js +20 -0
  530. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-vi.js +20 -0
  531. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-zh-CN.js +20 -0
  532. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery-ui-timepicker-zh-TW.js +20 -0
  533. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-cz.js +23 -0
  534. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-de.js +23 -0
  535. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-en-GB.js +23 -0
  536. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-es.js +23 -0
  537. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-fr.js +23 -0
  538. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-it.js +23 -0
  539. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-ja.js +23 -0
  540. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-pl.js +23 -0
  541. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-pt-BR.js +23 -0
  542. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-ru.js +23 -0
  543. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-sv-SE.js +23 -0
  544. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-th.js +23 -0
  545. data/vendor/assets/javascripts/jquery_ui_datepicker/jquery.ui.datepicker-zh-CN.js +23 -0
  546. data/vendor/assets/javascripts/lib/abstract-chosen.coffee +110 -0
  547. data/vendor/assets/javascripts/lib/select-parser.coffee +51 -0
  548. data/vendor/assets/stylesheets/chosen.css.sass +361 -0
  549. data/vendor/assets/stylesheets/{jquery-ui.custom.css.erb → jquery-ui.custom.css} +70 -70
  550. data/zeus.json +21 -0
  551. metadata +304 -140
  552. data/acceptance/support/database_cleaner.rb +0 -16
  553. data/acceptance/support/paths.rb +0 -9
  554. data/app/views/accounts/_options.html.haml +0 -20
  555. data/app/views/accounts/_permissions.html.haml +0 -24
  556. data/app/views/accounts/options.js.rjs +0 -10
  557. data/app/views/admin/fields/_edit.html.haml +0 -9
  558. data/app/views/admin/fields/_new.html.haml +0 -10
  559. data/app/views/admin/fields/_options.html.haml +0 -12
  560. data/app/views/admin/fields/_top_section.html.haml +0 -54
  561. data/app/views/admin/fields/create.js.rjs +0 -16
  562. data/app/views/admin/fields/edit.js.rjs +0 -35
  563. data/app/views/admin/fields/index.js.rjs +0 -6
  564. data/app/views/admin/fields/new.js.rjs +0 -8
  565. data/app/views/admin/fields/options.js.rjs +0 -10
  566. data/app/views/admin/fields/update.js.rjs +0 -17
  567. data/app/views/campaigns/_options.html.haml +0 -20
  568. data/app/views/campaigns/_permissions.html.haml +0 -24
  569. data/app/views/campaigns/options.js.rjs +0 -10
  570. data/app/views/contacts/_options.html.haml +0 -21
  571. data/app/views/contacts/_permissions.html.haml +0 -24
  572. data/app/views/contacts/options.js.rjs +0 -10
  573. data/app/views/entities/_advanced_search.html.haml +0 -12
  574. data/app/views/entities/_condition_fields.html.haml +0 -14
  575. data/app/views/entities/_grouping_fields.html.haml +0 -12
  576. data/app/views/entities/advanced_search.js.rjs +0 -9
  577. data/app/views/entities/versions.js.rjs +0 -3
  578. data/app/views/leads/_options.html.haml +0 -21
  579. data/app/views/leads/_permissions.html.haml +0 -28
  580. data/app/views/leads/options.js.rjs +0 -10
  581. data/app/views/opportunities/_options.html.haml +0 -20
  582. data/app/views/opportunities/_permissions.html.haml +0 -24
  583. data/app/views/opportunities/options.js.rjs +0 -10
  584. data/app/views/shared/_outline.html.haml +0 -9
  585. data/app/views/shared/_per_page.html.haml +0 -10
  586. data/app/views/shared/_sort_by.html.haml +0 -10
  587. data/config/initializers/cancan.rb +0 -151
  588. data/config/initializers/squeel.rb +0 -5
  589. data/public/blank_iframe.html +0 -2
  590. data/spec/views/accounts/options.rjs_spec.rb +0 -59
  591. data/spec/views/campaigns/options.rjs_spec.rb +0 -60
  592. data/spec/views/contacts/options.rjs_spec.rb +0 -61
  593. data/spec/views/leads/options.rjs_spec.rb +0 -61
  594. data/spec/views/opportunities/options.rjs_spec.rb +0 -60
  595. data/vendor/assets/images/jquery-ui/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  596. data/vendor/assets/images/jquery-ui/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  597. data/vendor/assets/images/jquery-ui/ui-bg_flat_10_000000_40x100.png +0 -0
  598. data/vendor/assets/images/jquery-ui/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  599. data/vendor/assets/images/jquery-ui/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  600. data/vendor/assets/images/jquery-ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
  601. data/vendor/assets/images/jquery-ui/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  602. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  603. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  604. data/vendor/assets/images/jquery-ui/ui-icons_222222_256x240.png +0 -0
  605. data/vendor/assets/images/jquery-ui/ui-icons_228ef1_256x240.png +0 -0
  606. data/vendor/assets/javascripts/calendar_date_select/calendar_date_select.js +0 -446
  607. data/vendor/assets/javascripts/calendar_date_select/format_american.js +0 -35
  608. data/vendor/assets/javascripts/calendar_date_select/format_danish.js +0 -31
  609. data/vendor/assets/javascripts/calendar_date_select/format_db.js +0 -27
  610. data/vendor/assets/javascripts/calendar_date_select/format_euro_24hr.js +0 -7
  611. data/vendor/assets/javascripts/calendar_date_select/format_euro_24hr_ymd.js +0 -7
  612. data/vendor/assets/javascripts/calendar_date_select/format_finnish.js +0 -32
  613. data/vendor/assets/javascripts/calendar_date_select/format_french.js +0 -24
  614. data/vendor/assets/javascripts/calendar_date_select/format_hyphen_ampm.js +0 -37
  615. data/vendor/assets/javascripts/calendar_date_select/format_iso_date.js +0 -29
  616. data/vendor/assets/javascripts/calendar_date_select/format_italian.js +0 -24
  617. data/vendor/assets/javascripts/calendar_date_select/locale/ar.js +0 -10
  618. data/vendor/assets/javascripts/calendar_date_select/locale/da.js +0 -11
  619. data/vendor/assets/javascripts/calendar_date_select/locale/de.js +0 -11
  620. data/vendor/assets/javascripts/calendar_date_select/locale/es.js +0 -11
  621. data/vendor/assets/javascripts/calendar_date_select/locale/fi.js +0 -10
  622. data/vendor/assets/javascripts/calendar_date_select/locale/fr.js +0 -11
  623. data/vendor/assets/javascripts/calendar_date_select/locale/it.js +0 -9
  624. data/vendor/assets/javascripts/calendar_date_select/locale/ja.js +0 -11
  625. data/vendor/assets/javascripts/calendar_date_select/locale/nl.js +0 -11
  626. data/vendor/assets/javascripts/calendar_date_select/locale/pl.js +0 -11
  627. data/vendor/assets/javascripts/calendar_date_select/locale/pt.js +0 -11
  628. data/vendor/assets/javascripts/calendar_date_select/locale/ru.js +0 -10
  629. data/vendor/assets/javascripts/calendar_date_select/locale/sl.js +0 -11
  630. data/vendor/assets/javascripts/calendar_date_select/locale/sv.js +0 -9
  631. data/vendor/assets/stylesheets/calendar_date_select/blue.css +0 -130
  632. data/vendor/assets/stylesheets/calendar_date_select/default.css +0 -135
  633. data/vendor/assets/stylesheets/calendar_date_select/green.css +0 -142
  634. data/vendor/assets/stylesheets/calendar_date_select/plain.css +0 -128
  635. data/vendor/assets/stylesheets/calendar_date_select/red.css +0 -135
  636. data/vendor/assets/stylesheets/calendar_date_select/silver.css +0 -133
  637. data/vendor/plugins/.gitkeep~master +0 -0
@@ -13,15 +13,16 @@ describe ContactsController do
13
13
  describe "responding to GET index" do
14
14
 
15
15
  it "should expose all contacts as @contacts and render [index] template" do
16
- @contacts = [ FactoryGirl.create(:contact, :user => @current_user) ]
16
+ @contacts = [ FactoryGirl.create(:contact, :user => current_user) ]
17
17
  get :index
18
+ assigns[:contacts].count.should == @contacts.count
18
19
  assigns[:contacts].should == @contacts
19
20
  response.should render_template("contacts/index")
20
21
  end
21
22
 
22
23
  it "should perform lookup using query string" do
23
- @billy_bones = FactoryGirl.create(:contact, :user => @current_user, :first_name => "Billy", :last_name => "Bones")
24
- @captain_flint = FactoryGirl.create(:contact, :user => @current_user, :first_name => "Captain", :last_name => "Flint")
24
+ @billy_bones = FactoryGirl.create(:contact, :user => current_user, :first_name => "Billy", :last_name => "Bones")
25
+ @captain_flint = FactoryGirl.create(:contact, :user => current_user, :first_name => "Captain", :last_name => "Flint")
25
26
 
26
27
  get :index, :query => "bill"
27
28
  assigns[:contacts].should == [ @billy_bones ]
@@ -31,7 +32,7 @@ describe ContactsController do
31
32
 
32
33
  describe "AJAX pagination" do
33
34
  it "should pick up page number from params" do
34
- @contacts = [ FactoryGirl.create(:contact, :user => @current_user) ]
35
+ @contacts = [ FactoryGirl.create(:contact, :user => current_user) ]
35
36
  xhr :get, :index, :page => 42
36
37
 
37
38
  assigns[:current_page].to_i.should == 42
@@ -42,13 +43,24 @@ describe ContactsController do
42
43
 
43
44
  it "should pick up saved page number from session" do
44
45
  session[:contacts_current_page] = 42
45
- @contacts = [ FactoryGirl.create(:contact, :user => @current_user) ]
46
+ @contacts = [ FactoryGirl.create(:contact, :user => current_user) ]
46
47
  xhr :get, :index
47
48
 
48
49
  assigns[:current_page].should == 42
49
50
  assigns[:contacts].should == []
50
51
  response.should render_template("contacts/index")
51
52
  end
53
+
54
+ it "should reset current_page when query is altered" do
55
+ session[:contacts_current_page] = 42
56
+ session[:contacts_current_query] = "bill"
57
+ @contacts = [ FactoryGirl.create(:contact, :user => current_user) ]
58
+ xhr :get, :index
59
+
60
+ assigns[:current_page].should == 1
61
+ assigns[:contacts].should == @contacts
62
+ response.should render_template("contacts/index")
63
+ end
52
64
  end
53
65
 
54
66
  describe "with mime type of JSON" do
@@ -126,7 +138,7 @@ describe ContactsController do
126
138
 
127
139
  describe "contact got deleted or otherwise unavailable" do
128
140
  it "should redirect to contact index if the contact got deleted" do
129
- @contact = FactoryGirl.create(:contact, :user => @current_user)
141
+ @contact = FactoryGirl.create(:contact, :user => current_user)
130
142
  @contact.destroy
131
143
 
132
144
  get :show, :id => @contact.id
@@ -143,7 +155,7 @@ describe ContactsController do
143
155
  end
144
156
 
145
157
  it "should return 404 (Not Found) XML error" do
146
- @contact = FactoryGirl.create(:contact, :user => @current_user)
158
+ @contact = FactoryGirl.create(:contact, :user => current_user)
147
159
  @contact.destroy
148
160
  request.env["HTTP_ACCEPT"] = "application/xml"
149
161
 
@@ -159,15 +171,14 @@ describe ContactsController do
159
171
  describe "responding to GET new" do
160
172
 
161
173
  it "should expose a new contact as @contact and render [new] template" do
162
- @contact = Contact.new(:user => @current_user)
163
- @account = Account.new(:user => @current_user)
164
- @users = [ FactoryGirl.create(:user) ]
165
- @accounts = [ FactoryGirl.create(:account, :user => @current_user) ]
174
+ @contact = Contact.new(:user => current_user,
175
+ :access => Setting.default_access)
176
+ @account = Account.new(:user => current_user)
177
+ @accounts = [ FactoryGirl.create(:account, :user => current_user) ]
166
178
 
167
179
  xhr :get, :new
168
180
  assigns[:contact].attributes.should == @contact.attributes
169
181
  assigns[:account].attributes.should == @account.attributes
170
- assigns[:users].should == @users
171
182
  assigns[:accounts].should == @accounts
172
183
  assigns[:opportunity].should == nil
173
184
  response.should render_template("contacts/new")
@@ -205,13 +216,11 @@ describe ContactsController do
205
216
  describe "responding to GET edit" do
206
217
 
207
218
  it "should expose the requested contact as @contact and render [edit] template" do
208
- @contact = FactoryGirl.create(:contact, :id => 42, :user => @current_user, :lead => nil)
209
- @users = [ FactoryGirl.create(:user) ]
210
- @account = Account.new(:user => @current_user)
219
+ @contact = FactoryGirl.create(:contact, :id => 42, :user => current_user, :lead => nil)
220
+ @account = Account.new(:user => current_user)
211
221
 
212
222
  xhr :get, :edit, :id => 42
213
223
  assigns[:contact].should == @contact
214
- assigns[:users].should == @users
215
224
  assigns[:account].attributes.should == @account.attributes
216
225
  assigns[:previous].should == nil
217
226
  response.should render_template("contacts/edit")
@@ -219,7 +228,7 @@ describe ContactsController do
219
228
 
220
229
  it "should expose the requested contact as @contact and linked account as @account" do
221
230
  @account = FactoryGirl.create(:account, :id => 99)
222
- @contact = FactoryGirl.create(:contact, :id => 42, :user => @current_user, :lead => nil)
231
+ @contact = FactoryGirl.create(:contact, :id => 42, :user => current_user, :lead => nil)
223
232
  FactoryGirl.create(:account_contact, :account => @account, :contact => @contact)
224
233
 
225
234
  xhr :get, :edit, :id => 42
@@ -237,7 +246,7 @@ describe ContactsController do
237
246
 
238
247
  describe "(contact got deleted or is otherwise unavailable)" do
239
248
  it "should reload current page with the flash message if the contact got deleted" do
240
- @contact = FactoryGirl.create(:contact, :user => @current_user)
249
+ @contact = FactoryGirl.create(:contact, :user => current_user)
241
250
  @contact.destroy
242
251
 
243
252
  xhr :get, :edit, :id => @contact.id
@@ -256,7 +265,7 @@ describe ContactsController do
256
265
 
257
266
  describe "(previous contact got deleted or is otherwise unavailable)" do
258
267
  before(:each) do
259
- @contact = FactoryGirl.create(:contact, :user => @current_user)
268
+ @contact = FactoryGirl.create(:contact, :user => current_user)
260
269
  @previous = FactoryGirl.create(:contact, :user => FactoryGirl.create(:user))
261
270
  end
262
271
 
@@ -291,9 +300,9 @@ describe ContactsController do
291
300
  @contact = FactoryGirl.build(:contact, :first_name => "Billy", :last_name => "Bones")
292
301
  Contact.stub!(:new).and_return(@contact)
293
302
 
294
- xhr :post, :create, :contact => { :first_name => "Billy", :last_name => "Bones" }, :account => { :name => "Hello world" }, :users => %w(1 2 3)
303
+ xhr :post, :create, :contact => { :first_name => "Billy", :last_name => "Bones" }, :account => { :name => "Hello world" }
295
304
  assigns(:contact).should == @contact
296
- assigns(:contact).account.name.should == "Hello world"
305
+ assigns(:contact).reload.account.name.should == "Hello world"
297
306
  response.should render_template("contacts/create")
298
307
  end
299
308
 
@@ -308,31 +317,37 @@ describe ContactsController do
308
317
  end
309
318
 
310
319
  it "should reload contacts to update pagination if called from contacts index" do
311
- @contact = FactoryGirl.build(:contact, :user => @current_user)
320
+ @contact = FactoryGirl.build(:contact, :user => current_user)
312
321
  Contact.stub!(:new).and_return(@contact)
313
322
 
314
323
  request.env["HTTP_REFERER"] = "http://localhost/contacts"
315
- xhr :post, :create, :contact => { :first_name => "Billy", :last_name => "Bones" }, :account => {}, :users => %w(1 2 3)
324
+ xhr :post, :create, :contact => { :first_name => "Billy", :last_name => "Bones" }, :account => {}
316
325
  assigns[:contacts].should == [ @contact ]
317
326
  end
327
+
328
+ it "should add a new comment to the newly created contact when specified" do
329
+ @contact = FactoryGirl.build(:contact, :user => current_user)
330
+ Contact.stub!(:new).and_return(@contact)
331
+
332
+ xhr :post, :create, :contact => { :first_name => "Testy", :last_name => "McTest" }, :account => { :name => "Hello world" }, :comment_body => "Awesome comment is awesome"
333
+ assigns[:contact].comments.map(&:comment).should include("Awesome comment is awesome")
334
+ end
318
335
  end
319
336
 
320
337
  describe "with invalid params" do
321
338
 
322
339
  before(:each) do
323
- @contact = FactoryGirl.build(:contact, :first_name => nil, :user => @current_user, :lead => nil)
340
+ @contact = FactoryGirl.build(:contact, :first_name => nil, :user => current_user, :lead => nil)
324
341
  Contact.stub!(:new).and_return(@contact)
325
- @users = [ FactoryGirl.create(:user) ]
326
342
  end
327
343
 
328
344
  # Redraw [create] form with selected account.
329
345
  it "should redraw [Create Contact] form with selected account" do
330
- @account = FactoryGirl.create(:account, :id => 42, :user => @current_user)
346
+ @account = FactoryGirl.create(:account, :id => 42, :user => current_user)
331
347
 
332
348
  # This redraws [create] form with blank account.
333
- xhr :post, :create, :contact => {}, :account => { :id => 42, :user_id => @current_user.id }
349
+ xhr :post, :create, :contact => {}, :account => { :id => 42, :user_id => current_user.id }
334
350
  assigns(:contact).should == @contact
335
- assigns(:users).should == @users
336
351
  assigns(:account).should == @account
337
352
  assigns(:accounts).should == [ @account ]
338
353
  response.should render_template("contacts/create")
@@ -340,24 +355,22 @@ describe ContactsController do
340
355
 
341
356
  # Redraw [create] form with related account.
342
357
  it "should redraw [Create Contact] form with related account" do
343
- @account = FactoryGirl.create(:account, :id => 123, :user => @current_user)
358
+ @account = FactoryGirl.create(:account, :id => 123, :user => current_user)
344
359
 
345
360
  request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
346
- xhr :post, :create, :contact => { :first_name => nil }, :account => { :name => nil, :user_id => @current_user.id }
361
+ xhr :post, :create, :contact => { :first_name => nil }, :account => { :name => nil, :user_id => current_user.id }
347
362
  assigns(:contact).should == @contact
348
- assigns(:users).should == @users
349
363
  assigns(:account).should == @account
350
364
  assigns(:accounts).should == [ @account ]
351
365
  response.should render_template("contacts/create")
352
366
  end
353
367
 
354
368
  it "should redraw [Create Contact] form with blank account" do
355
- @accounts = [ FactoryGirl.create(:account, :user => @current_user) ]
356
- @account = Account.new(:user => @current_user)
369
+ @accounts = [ FactoryGirl.create(:account, :user => current_user) ]
370
+ @account = Account.new(:user => current_user)
357
371
 
358
- xhr :post, :create, :contact => { :first_name => nil }, :account => { :name => nil, :user_id => @current_user.id }
372
+ xhr :post, :create, :contact => { :first_name => nil }, :account => { :name => nil, :user_id => current_user.id }
359
373
  assigns(:contact).should == @contact
360
- assigns(:users).should == @users
361
374
  assigns(:account).attributes.should == @account.attributes
362
375
  assigns(:accounts).should == @accounts
363
376
  response.should render_template("contacts/create")
@@ -384,8 +397,8 @@ describe ContactsController do
384
397
  @contact = FactoryGirl.create(:contact, :id => 42, :first_name => "Billy")
385
398
 
386
399
  xhr :put, :update, :id => 42, :contact => { :first_name => "Bones" }, :account => {}
387
- @contact.reload.first_name.should == "Bones"
388
- assigns(:contact).should == @contact
400
+ assigns[:contact].first_name.should == "Bones"
401
+ assigns[:contact].should == @contact
389
402
  response.should render_template("contacts/update")
390
403
  end
391
404
 
@@ -393,8 +406,8 @@ describe ContactsController do
393
406
  @contact = FactoryGirl.create(:contact, :id => 42, :first_name => "Billy")
394
407
 
395
408
  xhr :put, :update, :id => 42, :contact => { :first_name => "Bones" }, :account => { :name => "new account" }
396
- @contact.reload.first_name.should == "Bones"
397
- @contact.account.name.should == "new account"
409
+ assigns[:contact].first_name.should == "Bones"
410
+ assigns[:contact].account.name.should == "new account"
398
411
  end
399
412
 
400
413
  it "should be able to link existing account with the contact" do
@@ -402,24 +415,22 @@ describe ContactsController do
402
415
  @contact = FactoryGirl.create(:contact, :id => 42, :first_name => "Billy")
403
416
 
404
417
  xhr :put, :update, :id => 42, :contact => { :first_name => "Bones" }, :account => { :id => 99 }
405
- @contact.reload.first_name.should == "Bones"
406
- @contact.account.id.should == 99
418
+ assigns[:contact].first_name.should == "Bones"
419
+ assigns[:contact].account.id.should == 99
407
420
  end
408
421
 
409
422
  it "should update contact permissions when sharing with specific users" do
410
423
  @contact = FactoryGirl.create(:contact, :id => 42, :access => "Public")
411
- he = FactoryGirl.create(:user, :id => 7)
412
- she = FactoryGirl.create(:user, :id => 8)
413
424
 
414
- xhr :put, :update, :id => 42, :contact => { :first_name => "Hello", :access => "Shared" }, :users => %w(7 8), :account => {}
415
- @contact.reload.access.should == "Shared"
416
- @contact.permissions.map(&:user_id).sort.should == [ 7, 8 ]
425
+ xhr :put, :update, :id => 42, :contact => { :first_name => "Hello", :access => "Shared", :user_ids => [7, 8] }, :account => {}
426
+ assigns[:contact].access.should == "Shared"
427
+ assigns[:contact].user_ids.sort.should == [ 7, 8 ]
417
428
  assigns[:contact].should == @contact
418
429
  end
419
430
 
420
431
  describe "contact got deleted or otherwise unavailable" do
421
432
  it "should reload current page is the contact got deleted" do
422
- @contact = FactoryGirl.create(:contact, :user => @current_user)
433
+ @contact = FactoryGirl.create(:contact, :user => current_user)
423
434
  @contact.destroy
424
435
 
425
436
  xhr :put, :update, :id => @contact.id
@@ -441,15 +452,13 @@ describe ContactsController do
441
452
  describe "with invalid params" do
442
453
 
443
454
  it "should not update the contact, but still expose it as @contact and render [update] template" do
444
- @contact = FactoryGirl.create(:contact, :id => 42, :user => @current_user, :first_name => "Billy", :lead => nil)
445
- @account = Account.new(:user => @current_user)
446
- @users = [ FactoryGirl.create(:user) ]
455
+ @contact = FactoryGirl.create(:contact, :id => 42, :user => current_user, :first_name => "Billy", :lead => nil)
456
+ @account = Account.new(:user => current_user)
447
457
 
448
458
  xhr :put, :update, :id => 42, :contact => { :first_name => nil }, :account => {}
449
- @contact.reload.first_name.should == "Billy"
450
- assigns(:contact).should == @contact
451
- assigns(:account).attributes.should == @account.attributes
452
- assigns(:users).should == @users
459
+ assigns[:contact].reload.first_name.should == "Billy"
460
+ assigns[:contact].should == @contact
461
+ assigns[:account].attributes.should == @account.attributes
453
462
  response.should render_template("contacts/update")
454
463
  end
455
464
 
@@ -458,7 +467,7 @@ describe ContactsController do
458
467
  @contact = FactoryGirl.create(:contact, :id => 42, :account => @account)
459
468
 
460
469
  xhr :put, :update, :id => 42, :contact => { :first_name => nil }, :account => { :id => 99 }
461
- assigns(:account).should == @account
470
+ assigns[:account].should == @account
462
471
  end
463
472
 
464
473
  end
@@ -470,7 +479,7 @@ describe ContactsController do
470
479
  #----------------------------------------------------------------------------
471
480
  describe "responding to DELETE destroy" do
472
481
  before(:each) do
473
- @contact = FactoryGirl.create(:contact, :user => @current_user)
482
+ @contact = FactoryGirl.create(:contact, :user => current_user)
474
483
  end
475
484
 
476
485
  describe "AJAX request" do
@@ -515,7 +524,7 @@ describe ContactsController do
515
524
 
516
525
  describe "contact got deleted or otherwise unavailable" do
517
526
  it "should reload current page is the contact got deleted" do
518
- @contact = FactoryGirl.create(:contact, :user => @current_user)
527
+ @contact = FactoryGirl.create(:contact, :user => current_user)
519
528
  @contact.destroy
520
529
 
521
530
  xhr :delete, :destroy, :id => @contact.id
@@ -542,7 +551,7 @@ describe ContactsController do
542
551
  end
543
552
 
544
553
  it "should redirect to contact index with the flash message is the contact got deleted" do
545
- @contact = FactoryGirl.create(:contact, :user => @current_user)
554
+ @contact = FactoryGirl.create(:contact, :user => current_user)
546
555
  @contact.destroy
547
556
 
548
557
  delete :destroy, :id => @contact.id
@@ -628,63 +637,38 @@ describe ContactsController do
628
637
  #----------------------------------------------------------------------------
629
638
  describe "responding to POST auto_complete" do
630
639
  before(:each) do
631
- @auto_complete_matches = [ FactoryGirl.create(:contact, :first_name => "Hello", :last_name => "World", :user => @current_user) ]
640
+ @auto_complete_matches = [ FactoryGirl.create(:contact, :first_name => "Hello", :last_name => "World", :user => current_user) ]
632
641
  end
633
642
 
634
643
  it_should_behave_like("auto complete")
635
644
  end
636
645
 
637
- # GET /contacts/options AJAX
638
- #----------------------------------------------------------------------------
639
- describe "responding to GET options" do
640
- it "should set current user preferences when showing options" do
641
- @per_page = FactoryGirl.create(:preference, :user => @current_user, :name => "contacts_per_page", :value => Base64.encode64(Marshal.dump(42)))
642
- @outline = FactoryGirl.create(:preference, :user => @current_user, :name => "contacts_outline", :value => Base64.encode64(Marshal.dump("option_long")))
643
- @sort_by = FactoryGirl.create(:preference, :user => @current_user, :name => "contacts_sort_by", :value => Base64.encode64(Marshal.dump("contacts.first_name ASC")))
644
- @naming = FactoryGirl.create(:preference, :user => @current_user, :name => "contacts_naming", :value => Base64.encode64(Marshal.dump("option_after")))
645
-
646
- xhr :get, :options
647
- assigns[:per_page].should == 42
648
- assigns[:outline].should == "option_long"
649
- assigns[:sort_by].should == "contacts.first_name ASC"
650
- assigns[:naming].should == "option_after"
651
- end
652
-
653
- it "should not assign instance variables when hiding options" do
654
- xhr :get, :options, :cancel => "true"
655
- assigns[:per_page].should == nil
656
- assigns[:outline].should == nil
657
- assigns[:sort_by].should == nil
658
- assigns[:naming].should == nil
659
- end
660
- end
661
-
662
646
  # POST /contacts/redraw AJAX
663
647
  #----------------------------------------------------------------------------
664
648
  describe "responding to POST redraw" do
665
649
  it "should save user selected contact preference" do
666
- xhr :post, :redraw, :per_page => 42, :outline => "long", :sort_by => "first_name", :naming => "after"
667
- @current_user.preference[:contacts_per_page].to_i.should == 42
668
- @current_user.preference[:contacts_outline].should == "long"
669
- @current_user.preference[:contacts_sort_by].should == "contacts.first_name ASC"
670
- @current_user.preference[:contacts_naming].should == "after"
650
+ xhr :post, :redraw, :per_page => 42, :view => "long", :sort_by => "first_name", :naming => "after"
651
+ current_user.preference[:contacts_per_page].to_i.should == 42
652
+ current_user.preference[:contacts_index_view].should == "long"
653
+ current_user.preference[:contacts_sort_by].should == "contacts.first_name ASC"
654
+ current_user.preference[:contacts_naming].should == "after"
671
655
  end
672
656
 
673
657
  it "should set similar options for Leads" do
674
658
  xhr :post, :redraw, :sort_by => "first_name", :naming => "after"
675
- @current_user.pref[:leads_sort_by].should == "leads.first_name ASC"
676
- @current_user.pref[:leads_naming].should == "after"
659
+ current_user.pref[:leads_sort_by].should == "leads.first_name ASC"
660
+ current_user.pref[:leads_naming].should == "after"
677
661
  end
678
662
 
679
663
  it "should reset current page to 1" do
680
- xhr :post, :redraw, :per_page => 42, :outline => "long", :sort_by => "first_name", :naming => "after"
664
+ xhr :post, :redraw, :per_page => 42, :view => "long", :sort_by => "first_name", :naming => "after"
681
665
  session[:contacts_current_page].should == 1
682
666
  end
683
667
 
684
668
  it "should select @contacts and render [index] template" do
685
669
  @contacts = [
686
- FactoryGirl.create(:contact, :first_name => "Alice", :user => @current_user),
687
- FactoryGirl.create(:contact, :first_name => "Bobby", :user => @current_user)
670
+ FactoryGirl.create(:contact, :first_name => "Alice", :user => current_user),
671
+ FactoryGirl.create(:contact, :first_name => "Bobby", :user => current_user)
688
672
  ]
689
673
 
690
674
  xhr :post, :redraw, :per_page => 1, :sort_by => "first_name"
@@ -694,4 +678,3 @@ describe ContactsController do
694
678
  end
695
679
 
696
680
  end
697
-
@@ -13,7 +13,7 @@ describe LeadsController do
13
13
  describe "responding to GET index" do
14
14
 
15
15
  it "should expose all leads as @leads and render [index] template" do
16
- @leads = [ FactoryGirl.create(:lead, :user => @current_user) ]
16
+ @leads = [ FactoryGirl.create(:lead, :user => current_user) ]
17
17
 
18
18
  get :index
19
19
  assigns[:leads].should == @leads
@@ -21,7 +21,7 @@ describe LeadsController do
21
21
  end
22
22
 
23
23
  it "should collect the data for the leads sidebar" do
24
- @leads = [ FactoryGirl.create(:lead, :user => @current_user) ]
24
+ @leads = [ FactoryGirl.create(:lead, :user => current_user) ]
25
25
  @status = Setting.lead_status.dup
26
26
 
27
27
  get :index
@@ -31,12 +31,12 @@ describe LeadsController do
31
31
  it "should filter out leads by status" do
32
32
  controller.session[:leads_filter] = "new,contacted"
33
33
  @leads = [
34
- FactoryGirl.create(:lead, :status => "new", :user => @current_user),
35
- FactoryGirl.create(:lead, :status => "contacted", :user => @current_user)
34
+ FactoryGirl.create(:lead, :status => "new", :user => current_user),
35
+ FactoryGirl.create(:lead, :status => "contacted", :user => current_user)
36
36
  ]
37
37
 
38
38
  # This one should be filtered out.
39
- FactoryGirl.create(:lead, :status => "rejected", :user => @current_user)
39
+ FactoryGirl.create(:lead, :status => "rejected", :user => current_user)
40
40
 
41
41
  get :index
42
42
  # Note: can't compare campaigns directly because of BigDecimals.
@@ -45,8 +45,8 @@ describe LeadsController do
45
45
  end
46
46
 
47
47
  it "should perform lookup using query string" do
48
- @billy_bones = FactoryGirl.create(:lead, :user => @current_user, :first_name => "Billy", :last_name => "Bones")
49
- @captain_flint = FactoryGirl.create(:lead, :user => @current_user, :first_name => "Captain", :last_name => "Flint")
48
+ @billy_bones = FactoryGirl.create(:lead, :user => current_user, :first_name => "Billy", :last_name => "Bones")
49
+ @captain_flint = FactoryGirl.create(:lead, :user => current_user, :first_name => "Captain", :last_name => "Flint")
50
50
 
51
51
  get :index, :query => "bill"
52
52
  assigns[:leads].should == [ @billy_bones ]
@@ -56,7 +56,7 @@ describe LeadsController do
56
56
 
57
57
  describe "AJAX pagination" do
58
58
  it "should pick up page number from params" do
59
- @leads = [ FactoryGirl.create(:lead, :user => @current_user) ]
59
+ @leads = [ FactoryGirl.create(:lead, :user => current_user) ]
60
60
  xhr :get, :index, :page => 42
61
61
 
62
62
  assigns[:current_page].to_i.should == 42
@@ -67,13 +67,25 @@ describe LeadsController do
67
67
 
68
68
  it "should pick up saved page number from session" do
69
69
  session[:leads_current_page] = 42
70
- @leads = [ FactoryGirl.create(:lead, :user => @current_user) ]
71
- xhr :get, :index
70
+ session[:leads_current_query] = "bill"
71
+ @leads = [ FactoryGirl.create(:lead, :user => current_user) ]
72
+ xhr :get, :index, :query => "bill"
72
73
 
73
74
  assigns[:current_page].should == 42
74
75
  assigns[:leads].should == []
75
76
  response.should render_template("leads/index")
76
77
  end
78
+
79
+ it "should reset current_page when query is altered" do
80
+ session[:leads_current_page] = 42
81
+ session[:leads_current_query] = "bill"
82
+ @leads = [ FactoryGirl.create(:lead, :user => current_user) ]
83
+ xhr :get, :index
84
+
85
+ assigns[:current_page].should == 1
86
+ assigns[:leads].should == @leads
87
+ response.should render_template("leads/index")
88
+ end
77
89
  end
78
90
 
79
91
  describe "with mime type of JSON" do
@@ -106,7 +118,7 @@ describe LeadsController do
106
118
 
107
119
  describe "with mime type of HTML" do
108
120
  before(:each) do
109
- @lead = FactoryGirl.create(:lead, :id => 42, :user => @current_user)
121
+ @lead = FactoryGirl.create(:lead, :id => 42, :user => current_user)
110
122
  @comment = Comment.new
111
123
  end
112
124
 
@@ -125,7 +137,7 @@ describe LeadsController do
125
137
 
126
138
  describe "with mime type of JSON" do
127
139
  it "should render the requested lead as JSON" do
128
- @lead = FactoryGirl.create(:lead, :id => 42, :user => @current_user)
140
+ @lead = FactoryGirl.create(:lead, :id => 42, :user => current_user)
129
141
  Lead.should_receive(:find).and_return(@lead)
130
142
  @lead.should_receive(:to_json).and_return("generated JSON")
131
143
 
@@ -137,7 +149,7 @@ describe LeadsController do
137
149
 
138
150
  describe "with mime type of XML" do
139
151
  it "should render the requested lead as xml" do
140
- @lead = FactoryGirl.create(:lead, :id => 42, :user => @current_user)
152
+ @lead = FactoryGirl.create(:lead, :id => 42, :user => current_user)
141
153
  Lead.should_receive(:find).and_return(@lead)
142
154
  @lead.should_receive(:to_xml).and_return("generated XML")
143
155
 
@@ -149,7 +161,7 @@ describe LeadsController do
149
161
 
150
162
  describe "lead got deleted or otherwise unavailable" do
151
163
  it "should redirect to lead index if the lead got deleted" do
152
- @lead = FactoryGirl.create(:lead, :user => @current_user)
164
+ @lead = FactoryGirl.create(:lead, :user => current_user)
153
165
  @lead.destroy
154
166
 
155
167
  get :show, :id => @lead.id
@@ -166,7 +178,7 @@ describe LeadsController do
166
178
  end
167
179
 
168
180
  it "should return 404 (Not Found) JSON error" do
169
- @lead = FactoryGirl.create(:lead, :user => @current_user)
181
+ @lead = FactoryGirl.create(:lead, :user => current_user)
170
182
  @lead.destroy
171
183
  request.env["HTTP_ACCEPT"] = "application/json"
172
184
 
@@ -175,7 +187,7 @@ describe LeadsController do
175
187
  end
176
188
 
177
189
  it "should return 404 (Not Found) XML error" do
178
- @lead = FactoryGirl.create(:lead, :user => @current_user)
190
+ @lead = FactoryGirl.create(:lead, :user => current_user)
179
191
  @lead.destroy
180
192
  request.env["HTTP_ACCEPT"] = "application/xml"
181
193
 
@@ -192,14 +204,12 @@ describe LeadsController do
192
204
  describe "responding to GET new" do
193
205
 
194
206
  it "should expose a new lead as @lead and render [new] template" do
195
- @lead = FactoryGirl.build(:lead, :user => @current_user, :campaign => nil)
207
+ @lead = FactoryGirl.build(:lead, :user => current_user, :campaign => nil)
196
208
  Lead.stub!(:new).and_return(@lead)
197
- @users = [ FactoryGirl.create(:user) ]
198
- @campaigns = [ FactoryGirl.create(:campaign, :user => @current_user) ]
209
+ @campaigns = [ FactoryGirl.create(:campaign, :user => current_user) ]
199
210
 
200
211
  xhr :get, :new
201
212
  assigns[:lead].attributes.should == @lead.attributes
202
- assigns[:users].should == @users
203
213
  assigns[:campaigns].should == @campaigns
204
214
  response.should render_template("leads/new")
205
215
  end
@@ -236,13 +246,11 @@ describe LeadsController do
236
246
  describe "responding to GET edit" do
237
247
 
238
248
  it "should expose the requested lead as @lead and render [edit] template" do
239
- @lead = FactoryGirl.create(:lead, :id => 42, :user => @current_user, :campaign => nil)
240
- @users = [ FactoryGirl.create(:user) ]
241
- @campaigns = [ FactoryGirl.create(:campaign, :user => @current_user) ]
249
+ @lead = FactoryGirl.create(:lead, :id => 42, :user => current_user, :campaign => nil)
250
+ @campaigns = [ FactoryGirl.create(:campaign, :user => current_user) ]
242
251
 
243
252
  xhr :get, :edit, :id => 42
244
253
  assigns[:lead].should == @lead
245
- assigns[:users].should == @users
246
254
  assigns[:campaigns].should == @campaigns
247
255
  response.should render_template("leads/edit")
248
256
  end
@@ -257,7 +265,7 @@ describe LeadsController do
257
265
 
258
266
  describe "lead got deleted or is otherwise unavailable" do
259
267
  it "should reload current page with the flash message if the lead got deleted" do
260
- @lead = FactoryGirl.create(:lead, :user => @current_user)
268
+ @lead = FactoryGirl.create(:lead, :user => current_user)
261
269
  @lead.destroy
262
270
 
263
271
  xhr :get, :edit, :id => @lead.id
@@ -276,7 +284,7 @@ describe LeadsController do
276
284
 
277
285
  describe "(previous lead got deleted or is otherwise unavailable)" do
278
286
  before(:each) do
279
- @lead = FactoryGirl.create(:lead, :user => @current_user)
287
+ @lead = FactoryGirl.create(:lead, :user => current_user)
280
288
  @previous = FactoryGirl.create(:lead, :user => FactoryGirl.create(:user))
281
289
  end
282
290
 
@@ -308,14 +316,12 @@ describe LeadsController do
308
316
  describe "with valid params" do
309
317
 
310
318
  it "should expose a newly created lead as @lead and render [create] template" do
311
- @lead = FactoryGirl.build(:lead, :user => @current_user, :campaign => nil)
319
+ @lead = FactoryGirl.build(:lead, :user => current_user, :campaign => nil)
312
320
  Lead.stub!(:new).and_return(@lead)
313
- @users = [ FactoryGirl.create(:user) ]
314
- @campaigns = [ FactoryGirl.create(:campaign, :user => @current_user) ]
321
+ @campaigns = [ FactoryGirl.create(:campaign, :user => current_user) ]
315
322
 
316
- xhr :post, :create, :lead => { :first_name => "Billy", :last_name => "Bones" }, :users => %w(1 2 3)
323
+ xhr :post, :create, :lead => { :first_name => "Billy", :last_name => "Bones" }
317
324
  assigns(:lead).should == @lead
318
- assigns(:users).should == @users
319
325
  assigns(:campaigns).should == @campaigns
320
326
  assigns[:lead_status_total].should be_nil
321
327
  response.should render_template("leads/create")
@@ -329,10 +335,11 @@ describe LeadsController do
329
335
  @campaign.permissions << FactoryGirl.build(:permission, :user => she, :asset => @campaign)
330
336
  @campaign.save
331
337
 
332
- @lead = FactoryGirl.build(:lead, :campaign => @campaign, :user => @current_user, :access => "Shared")
338
+ @lead = FactoryGirl.build(:lead, :campaign => @campaign, :user => current_user, :access => "Shared")
333
339
  Lead.stub!(:new).and_return(@lead)
334
340
 
335
- xhr :put, :create, :lead => { :first_name => "Billy", :last_name => "Bones", :access => "Campaign" }, :campaign => @campaign.id, :users => %w(7 8)
341
+ xhr :post, :create, :lead => { :first_name => "Billy", :last_name => "Bones", :access => "Campaign", :user_ids => %w(7 8) }, :campaign => @campaign.id
342
+ assigns(:lead).should == @lead
336
343
  @lead.reload.access.should == "Shared"
337
344
  @lead.permissions.map(&:user_id).sort.should == [ 7, 8 ]
338
345
  @lead.permissions.map(&:asset_id).should == [ @lead.id, @lead.id ]
@@ -340,45 +347,49 @@ describe LeadsController do
340
347
  end
341
348
 
342
349
  it "should get the data to update leads sidebar if called from leads index" do
343
- @lead = FactoryGirl.build(:lead, :user => @current_user, :campaign => nil)
350
+ @lead = FactoryGirl.build(:lead, :user => current_user, :campaign => nil)
344
351
  Lead.stub!(:new).and_return(@lead)
345
352
 
346
353
  request.env["HTTP_REFERER"] = "http://localhost/leads"
347
- xhr :post, :create, :lead => { :first_name => "Billy", :last_name => "Bones" }, :users => %w(1 2 3)
354
+ xhr :post, :create, :lead => { :first_name => "Billy", :last_name => "Bones" }
348
355
  assigns[:lead_status_total].should be_an_instance_of(HashWithIndifferentAccess)
349
356
  end
350
357
 
351
358
  it "should reload leads to update pagination if called from leads index" do
352
- @lead = FactoryGirl.build(:lead, :user => @current_user, :campaign => nil)
359
+ @lead = FactoryGirl.build(:lead, :user => current_user, :campaign => nil)
353
360
  Lead.stub!(:new).and_return(@lead)
354
361
 
355
362
  request.env["HTTP_REFERER"] = "http://localhost/leads"
356
- xhr :post, :create, :lead => { :first_name => "Billy", :last_name => "Bones" }, :users => %w(1 2 3)
363
+ xhr :post, :create, :lead => { :first_name => "Billy", :last_name => "Bones" }
357
364
  assigns[:leads].should == [ @lead ]
358
365
  end
359
366
 
360
367
  it "should reload lead campaign if called from campaign landing page" do
361
368
  @campaign = FactoryGirl.create(:campaign)
362
- @lead = FactoryGirl.build(:lead, :user => @current_user, :campaign => @campaign)
369
+ @lead = FactoryGirl.build(:lead, :user => current_user, :campaign => @campaign)
363
370
 
364
371
  request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
365
372
  xhr :put, :create, :lead => { :first_name => "Billy", :last_name => "Bones"}, :campaign => @campaign.id
366
373
  assigns[:campaign].should == @campaign
367
374
  end
368
-
375
+
376
+ it "should add a new comment to the newly created lead when specified" do
377
+ @lead = FactoryGirl.create(:lead)
378
+ Lead.stub!(:new).and_return(@lead)
379
+ xhr :post, :create, :lead => { :first_name => "Test", :last_name => "Lead" }, :comment_body => "This is an important lead."
380
+ @lead.reload.comments.map(&:comment).should include("This is an important lead.")
381
+ end
369
382
  end
370
383
 
371
384
  describe "with invalid params" do
372
385
 
373
386
  it "should expose a newly created but unsaved lead as @lead and still render [create] template" do
374
- @lead = FactoryGirl.build(:lead, :user => @current_user, :first_name => nil, :campaign => nil)
387
+ @lead = FactoryGirl.build(:lead, :user => current_user, :first_name => nil, :campaign => nil)
375
388
  Lead.stub!(:new).and_return(@lead)
376
- @users = [ FactoryGirl.create(:user) ]
377
- @campaigns = [ FactoryGirl.create(:campaign, :user => @current_user) ]
389
+ @campaigns = [ FactoryGirl.create(:campaign, :user => current_user) ]
378
390
 
379
- xhr :post, :create, :lead => { :first_name => nil }, :users => nil
391
+ xhr :post, :create, :lead => { :first_name => nil }
380
392
  assigns(:lead).should == @lead
381
- assigns(:users).should == @users
382
393
  assigns(:campaigns).should == @campaigns
383
394
  assigns[:lead_status_total].should == nil
384
395
  response.should render_template("leads/create")
@@ -396,7 +407,7 @@ describe LeadsController do
396
407
  describe "with valid params" do
397
408
 
398
409
  it "should update the requested lead, expose it as @lead, and render [update] template" do
399
- @lead = FactoryGirl.create(:lead, :first_name => "Billy", :user => @current_user)
410
+ @lead = FactoryGirl.create(:lead, :first_name => "Billy", :user => current_user)
400
411
 
401
412
  xhr :put, :update, :id => @lead.id, :lead => { :first_name => "Bones" }
402
413
  @lead.reload.first_name.should == "Bones"
@@ -406,14 +417,14 @@ describe LeadsController do
406
417
  end
407
418
 
408
419
  it "should update lead status" do
409
- @lead = FactoryGirl.create(:lead, :status => "new", :user => @current_user)
420
+ @lead = FactoryGirl.create(:lead, :status => "new", :user => current_user)
410
421
 
411
422
  xhr :put, :update, :id => @lead.id, :lead => { :status => "rejected" }
412
423
  @lead.reload.status.should == "rejected"
413
424
  end
414
425
 
415
426
  it "should update lead source" do
416
- @lead = FactoryGirl.create(:lead, :source => "campaign", :user => @current_user)
427
+ @lead = FactoryGirl.create(:lead, :source => "campaign", :user => current_user)
417
428
 
418
429
  xhr :put, :update, :id => @lead.id, :lead => { :source => "cald_call" }
419
430
  @lead.reload.source.should == "cald_call"
@@ -458,13 +469,13 @@ describe LeadsController do
458
469
  @campaigns[:new].reload.leads_count.should == @counts[:new] + 1
459
470
  end
460
471
 
461
- it "should update shared permissions for the campaign" do
462
- @lead = FactoryGirl.create(:lead, :user => @current_user)
472
+ it "should update shared permissions for the lead" do
473
+ @lead = FactoryGirl.create(:lead, :user => current_user)
463
474
  he = FactoryGirl.create(:user, :id => 7)
464
475
  she = FactoryGirl.create(:user, :id => 8)
465
476
 
466
- xhr :put, :update, :id => @lead.id, :lead => { :access => "Shared" }, :users => %w(7 8)
467
- @lead.permissions.map(&:user_id).sort.should == [ 7, 8 ]
477
+ xhr :put, :update, :id => @lead.id, :lead => { :access => "Shared", :user_ids => %w(7 8) }
478
+ @lead.user_ids.sort.should == [ 7, 8 ]
468
479
  end
469
480
 
470
481
  it "should get the data for leads sidebar when called from leads index" do
@@ -487,7 +498,7 @@ describe LeadsController do
487
498
 
488
499
  describe "lead got deleted or otherwise unavailable" do
489
500
  it "should reload current page with the flash message if the lead got deleted" do
490
- @lead = FactoryGirl.create(:lead, :user => @current_user)
501
+ @lead = FactoryGirl.create(:lead, :user => current_user)
491
502
  @lead.destroy
492
503
 
493
504
  xhr :put, :update, :id => @lead.id
@@ -508,13 +519,11 @@ describe LeadsController do
508
519
  describe "with invalid params" do
509
520
 
510
521
  it "should not update the lead, but still expose it as @lead and render [update] template" do
511
- @lead = FactoryGirl.create(:lead, :id => 42, :user => @current_user, :campaign => nil)
512
- @users = [ FactoryGirl.create(:user) ]
513
- @campaigns = [ FactoryGirl.create(:campaign, :user => @current_user) ]
522
+ @lead = FactoryGirl.create(:lead, :id => 42, :user => current_user, :campaign => nil)
523
+ @campaigns = [ FactoryGirl.create(:campaign, :user => current_user) ]
514
524
 
515
525
  xhr :put, :update, :id => 42, :lead => { :first_name => nil }
516
526
  assigns[:lead].should == @lead
517
- assigns[:users].should == @users
518
527
  assigns[:campaigns].should == @campaigns
519
528
  response.should render_template("leads/update")
520
529
  end
@@ -529,7 +538,7 @@ describe LeadsController do
529
538
  describe "responding to DELETE destroy" do
530
539
 
531
540
  before(:each) do
532
- @lead = FactoryGirl.create(:lead, :user => @current_user)
541
+ @lead = FactoryGirl.create(:lead, :user => current_user)
533
542
  end
534
543
 
535
544
  describe "AJAX request" do
@@ -547,7 +556,7 @@ describe LeadsController do
547
556
  end
548
557
 
549
558
  it "should get data for the sidebar" do
550
- @another_lead = FactoryGirl.create(:lead, :user => @current_user)
559
+ @another_lead = FactoryGirl.create(:lead, :user => current_user)
551
560
 
552
561
  xhr :delete, :destroy, :id => @lead.id
553
562
  assigns[:leads].should == [ @another_lead ] # @lead got deleted
@@ -576,7 +585,7 @@ describe LeadsController do
576
585
  describe "when called from campaign landing page" do
577
586
  before(:each) do
578
587
  @campaign = FactoryGirl.create(:campaign)
579
- @lead = FactoryGirl.create(:lead, :user => @current_user, :campaign => @campaign)
588
+ @lead = FactoryGirl.create(:lead, :user => current_user, :campaign => @campaign)
580
589
  request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
581
590
  end
582
591
 
@@ -595,7 +604,7 @@ describe LeadsController do
595
604
 
596
605
  describe "lead got deleted or otherwise unavailable" do
597
606
  it "should reload current page with the flash message if the lead got deleted" do
598
- @lead = FactoryGirl.create(:lead, :user => @current_user)
607
+ @lead = FactoryGirl.create(:lead, :user => current_user)
599
608
  @lead.destroy
600
609
 
601
610
  xhr :delete, :destroy, :id => @lead.id
@@ -622,7 +631,7 @@ describe LeadsController do
622
631
  end
623
632
 
624
633
  it "should redirect to lead index with the flash message is the lead got deleted" do
625
- @lead = FactoryGirl.create(:lead, :user => @current_user)
634
+ @lead = FactoryGirl.create(:lead, :user => current_user)
626
635
  @lead.destroy
627
636
 
628
637
  delete :destroy, :id => @lead.id
@@ -646,16 +655,14 @@ describe LeadsController do
646
655
  describe "responding to GET convert" do
647
656
 
648
657
  it "should should collect necessary data and render [convert] template" do
649
- @campaign = FactoryGirl.create(:campaign, :user => @current_user)
650
- @lead = FactoryGirl.create(:lead, :user => @current_user, :campaign => @campaign, :source => "cold_call")
651
- @users = [ FactoryGirl.create(:user) ]
652
- @accounts = [ FactoryGirl.create(:account, :user => @current_user) ]
653
- @account = Account.new(:user => @current_user, :name => @lead.company, :access => "Lead")
654
- @opportunity = Opportunity.new(:user => @current_user, :access => "Lead", :stage => "prospecting", :campaign => @lead.campaign, :source => @lead.source)
658
+ @campaign = FactoryGirl.create(:campaign, :user => current_user)
659
+ @lead = FactoryGirl.create(:lead, :user => current_user, :campaign => @campaign, :source => "cold_call")
660
+ @accounts = [ FactoryGirl.create(:account, :user => current_user) ]
661
+ @account = Account.new(:user => current_user, :name => @lead.company, :access => "Lead")
662
+ @opportunity = Opportunity.new(:user => current_user, :access => "Lead", :stage => "prospecting", :campaign => @lead.campaign, :source => @lead.source)
655
663
 
656
664
  xhr :get, :convert, :id => @lead.id
657
665
  assigns[:lead].should == @lead
658
- assigns[:users].should == @users
659
666
  assigns[:accounts].should == @accounts
660
667
  assigns[:account].attributes.should == @account.attributes
661
668
  assigns[:opportunity].attributes.should == @opportunity.attributes
@@ -665,7 +672,7 @@ describe LeadsController do
665
672
 
666
673
  describe "(lead got deleted or is otherwise unavailable)" do
667
674
  it "should reload current page with the flash message if the lead got deleted" do
668
- @lead = FactoryGirl.create(:lead, :user => @current_user)
675
+ @lead = FactoryGirl.create(:lead, :user => current_user)
669
676
  @lead.destroy
670
677
 
671
678
  xhr :get, :convert, :id => @lead.id
@@ -684,7 +691,7 @@ describe LeadsController do
684
691
 
685
692
  describe "(previous lead got deleted or is otherwise unavailable)" do
686
693
  before(:each) do
687
- @lead = FactoryGirl.create(:lead, :user => @current_user)
694
+ @lead = FactoryGirl.create(:lead, :user => current_user)
688
695
  @previous = FactoryGirl.create(:lead, :user => FactoryGirl.create(:user))
689
696
  end
690
697
 
@@ -714,19 +721,17 @@ describe LeadsController do
714
721
  describe "responding to PUT promote" do
715
722
 
716
723
  it "on success: should change lead's status to [converted] and render [promote] template" do
717
- @lead = FactoryGirl.create(:lead, :id => 42, :user => @current_user, :campaign => nil)
718
- @users = [ FactoryGirl.create(:user) ]
719
- @account = FactoryGirl.create(:account, :id => 123, :user => @current_user)
720
- @opportunity = FactoryGirl.build(:opportunity, :user => @current_user, :campaign => @lead.campaign,
724
+ @lead = FactoryGirl.create(:lead, :id => 42, :user => current_user, :campaign => nil)
725
+ @account = FactoryGirl.create(:account, :id => 123, :user => current_user)
726
+ @opportunity = FactoryGirl.build(:opportunity, :user => current_user, :campaign => @lead.campaign,
721
727
  :account => @account)
722
728
  Opportunity.stub!(:new).and_return(@opportunity)
723
- @contact = FactoryGirl.build(:contact, :user => @current_user, :lead => @lead)
729
+ @contact = FactoryGirl.build(:contact, :user => current_user, :lead => @lead)
724
730
  Contact.stub!(:new).and_return(@contact)
725
731
 
726
732
  xhr :put, :promote, :id => 42, :account => { :id => 123 }, :opportunity => { :name => "Hello" }
727
733
  @lead.reload.status.should == "converted"
728
734
  assigns[:lead].should == @lead
729
- assigns[:users].should == @users
730
735
  assigns[:account].should == @account
731
736
  assigns[:accounts].should == [ @account ]
732
737
  assigns[:opportunity].should == @opportunity
@@ -742,16 +747,16 @@ describe LeadsController do
742
747
  @lead.permissions << FactoryGirl.build(:permission, :user => he, :asset => @lead)
743
748
  @lead.permissions << FactoryGirl.build(:permission, :user => she, :asset => @lead)
744
749
  @lead.save
745
- @account = FactoryGirl.build(:account, :user => @current_user, :access => "Shared")
750
+ @account = FactoryGirl.build(:account, :user => current_user, :access => "Shared")
746
751
  @account.permissions << FactoryGirl.create(:permission, :user => he, :asset => @account)
747
752
  @account.permissions << FactoryGirl.create(:permission, :user => she, :asset => @account)
748
753
  @account.stub!(:new).and_return(@account)
749
- @opportunity = FactoryGirl.build(:opportunity, :user => @current_user, :access => "Shared")
754
+ @opportunity = FactoryGirl.build(:opportunity, :user => current_user, :access => "Shared")
750
755
  @opportunity.permissions << FactoryGirl.create(:permission, :user => he, :asset => @opportunity)
751
756
  @opportunity.permissions << FactoryGirl.create(:permission, :user => she, :asset => @opportunity)
752
757
  @opportunity.stub!(:new).and_return(@opportunity)
753
758
 
754
- 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 }
759
+ 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 }
755
760
  @account.access.should == "Shared"
756
761
  @account.permissions.map(&:user_id).sort.should == [ 7, 8 ]
757
762
  @account.permissions.map(&:asset_id).should == [ @account.id, @account.id ]
@@ -764,14 +769,14 @@ describe LeadsController do
764
769
 
765
770
  it "should assign lead's campaign to the newly created opportunity" do
766
771
  @campaign = FactoryGirl.create(:campaign)
767
- @lead = FactoryGirl.create(:lead, :user => @current_user, :campaign => @campaign)
772
+ @lead = FactoryGirl.create(:lead, :user => current_user, :campaign => @campaign)
768
773
 
769
774
  xhr :put, :promote, :id => @lead.id, :account => { :name => "Hello" }, :opportunity => { :name => "Hello", :campaign_id => @campaign.id }
770
775
  assigns[:opportunity].campaign.should == @campaign
771
776
  end
772
777
 
773
778
  it "should assign lead's source to the newly created opportunity" do
774
- @lead = FactoryGirl.create(:lead, :user => @current_user, :source => "cold_call")
779
+ @lead = FactoryGirl.create(:lead, :user => current_user, :source => "cold_call")
775
780
 
776
781
  xhr :put, :promote, :id => @lead.id, :account => { :name => "Hello" }, :opportunity => { :name => "Hello", :source => @lead.source }
777
782
  assigns[:opportunity].source.should == @lead.source
@@ -796,9 +801,8 @@ describe LeadsController do
796
801
  end
797
802
 
798
803
  it "on failure: should not change lead's status and still render [promote] template" do
799
- @lead = FactoryGirl.create(:lead, :id => 42, :user => @current_user, :status => "new")
800
- @users = [ FactoryGirl.create(:user) ]
801
- @account = FactoryGirl.create(:account, :id => 123, :user => @current_user)
804
+ @lead = FactoryGirl.create(:lead, :id => 42, :user => current_user, :status => "new")
805
+ @account = FactoryGirl.create(:account, :id => 123, :user => current_user)
802
806
  @contact = FactoryGirl.build(:contact, :first_name => nil) # make it fail
803
807
  Contact.stub!(:new).and_return(@contact)
804
808
 
@@ -809,7 +813,7 @@ describe LeadsController do
809
813
 
810
814
  describe "lead got deleted or otherwise unavailable" do
811
815
  it "should reload current page with the flash message if the lead got deleted" do
812
- @lead = FactoryGirl.create(:lead, :user => @current_user)
816
+ @lead = FactoryGirl.create(:lead, :user => current_user)
813
817
  @lead.destroy
814
818
 
815
819
  xhr :put, :promote, :id => @lead.id
@@ -833,7 +837,7 @@ describe LeadsController do
833
837
  describe "responding to PUT reject" do
834
838
 
835
839
  before(:each) do
836
- @lead = FactoryGirl.create(:lead, :user => @current_user, :status => "new")
840
+ @lead = FactoryGirl.create(:lead, :user => current_user, :status => "new")
837
841
  end
838
842
 
839
843
  describe "AJAX request" do
@@ -863,7 +867,7 @@ describe LeadsController do
863
867
 
864
868
  describe "lead got deleted or otherwise unavailable" do
865
869
  it "should reload current page with the flash message if the lead got deleted" do
866
- @lead = FactoryGirl.create(:lead, :user => @current_user)
870
+ @lead = FactoryGirl.create(:lead, :user => current_user)
867
871
  @lead.destroy
868
872
 
869
873
  xhr :put, :reject, :id => @lead.id
@@ -893,7 +897,7 @@ describe LeadsController do
893
897
 
894
898
  describe "lead got deleted or otherwise unavailable" do
895
899
  it "should redirect to lead index if the lead got deleted" do
896
- @lead = FactoryGirl.create(:lead, :user => @current_user)
900
+ @lead = FactoryGirl.create(:lead, :user => current_user)
897
901
  @lead.destroy
898
902
 
899
903
  put :reject, :id => @lead.id
@@ -943,7 +947,7 @@ describe LeadsController do
943
947
  #----------------------------------------------------------------------------
944
948
  describe "responding to POST discard" do
945
949
  before(:each) do
946
- @attachment = FactoryGirl.create(:task, :assigned_to => @current_user)
950
+ @attachment = FactoryGirl.create(:task, :assigned_to => current_user)
947
951
  @model = FactoryGirl.create(:lead)
948
952
  @model.tasks << @attachment
949
953
  end
@@ -955,63 +959,38 @@ describe LeadsController do
955
959
  #----------------------------------------------------------------------------
956
960
  describe "responding to POST auto_complete" do
957
961
  before(:each) do
958
- @auto_complete_matches = [ FactoryGirl.create(:lead, :first_name => "Hello", :last_name => "World", :user => @current_user) ]
962
+ @auto_complete_matches = [ FactoryGirl.create(:lead, :first_name => "Hello", :last_name => "World", :user => current_user) ]
959
963
  end
960
964
 
961
965
  it_should_behave_like("auto complete")
962
966
  end
963
967
 
964
- # GET /leads/options AJAX
965
- #----------------------------------------------------------------------------
966
- describe "responding to GET options" do
967
- it "should set current user preferences when showing options" do
968
- @per_page = FactoryGirl.create(:preference, :user => @current_user, :name => "leads_per_page", :value => Base64.encode64(Marshal.dump(42)))
969
- @outline = FactoryGirl.create(:preference, :user => @current_user, :name => "leads_outline", :value => Base64.encode64(Marshal.dump("option_long")))
970
- @sort_by = FactoryGirl.create(:preference, :user => @current_user, :name => "leads_sort_by", :value => Base64.encode64(Marshal.dump("leads.first_name ASC")))
971
- @naming = FactoryGirl.create(:preference, :user => @current_user, :name => "leads_naming", :value => Base64.encode64(Marshal.dump("option_after")))
972
-
973
- xhr :get, :options
974
- assigns[:per_page].should == 42
975
- assigns[:outline].should == "option_long"
976
- assigns[:sort_by].should == "leads.first_name ASC"
977
- assigns[:naming].should == "option_after"
978
- end
979
-
980
- it "should not assign instance variables when hiding options" do
981
- xhr :get, :options, :cancel => "true"
982
- assigns[:per_page].should == nil
983
- assigns[:outline].should == nil
984
- assigns[:sort_by].should == nil
985
- assigns[:naming].should == nil
986
- end
987
- end
988
-
989
968
  # POST /leads/redraw AJAX
990
969
  #----------------------------------------------------------------------------
991
970
  describe "responding to POST redraw" do
992
971
  it "should save user selected lead preference" do
993
- xhr :post, :redraw, :per_page => 42, :outline => "long", :sort_by => "first_name", :naming => "after"
994
- @current_user.preference[:leads_per_page].should == "42"
995
- @current_user.preference[:leads_outline].should == "long"
996
- @current_user.preference[:leads_sort_by].should == "leads.first_name ASC"
997
- @current_user.preference[:leads_naming].should == "after"
972
+ xhr :post, :redraw, :per_page => 42, :view => "long", :sort_by => "first_name", :naming => "after"
973
+ current_user.preference[:leads_per_page].should == "42"
974
+ current_user.preference[:leads_index_view].should == "long"
975
+ current_user.preference[:leads_sort_by].should == "leads.first_name ASC"
976
+ current_user.preference[:leads_naming].should == "after"
998
977
  end
999
978
 
1000
979
  it "should set similar options for Contacts" do
1001
980
  xhr :post, :redraw, :sort_by => "first_name", :naming => "after"
1002
- @current_user.pref[:contacts_sort_by].should == "contacts.first_name ASC"
1003
- @current_user.pref[:contacts_naming].should == "after"
981
+ current_user.pref[:contacts_sort_by].should == "contacts.first_name ASC"
982
+ current_user.pref[:contacts_naming].should == "after"
1004
983
  end
1005
984
 
1006
985
  it "should reset current page to 1" do
1007
- xhr :post, :redraw, :per_page => 42, :outline => "long", :sort_by => "first_name", :naming => "after"
986
+ xhr :post, :redraw, :per_page => 42, :view => "long", :sort_by => "first_name", :naming => "after"
1008
987
  session[:leads_current_page].should == 1
1009
988
  end
1010
989
 
1011
990
  it "should select @leads and render [index] template" do
1012
991
  @leads = [
1013
- FactoryGirl.create(:lead, :first_name => "Alice", :user => @current_user),
1014
- FactoryGirl.create(:lead, :first_name => "Bobby", :user => @current_user)
992
+ FactoryGirl.create(:lead, :first_name => "Alice", :user => current_user),
993
+ FactoryGirl.create(:lead, :first_name => "Bobby", :user => current_user)
1015
994
  ]
1016
995
 
1017
996
  xhr :post, :redraw, :per_page => 1, :sort_by => "first_name"
@@ -1027,7 +1006,7 @@ describe LeadsController do
1027
1006
  it "should filter out leads as @leads and render :index action" do
1028
1007
  session[:leads_filter] = "contacted,rejected"
1029
1008
 
1030
- @leads = [ FactoryGirl.create(:lead, :user => @current_user, :status => "new") ]
1009
+ @leads = [ FactoryGirl.create(:lead, :user => current_user, :status => "new") ]
1031
1010
  xhr :post, :filter, :status => "new"
1032
1011
  assigns[:leads].should == @leads
1033
1012
  response.should be_a_success
@@ -1044,4 +1023,3 @@ describe LeadsController do
1044
1023
  end
1045
1024
 
1046
1025
  end
1047
-