fat_free_crm 0.20.1 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (286) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +170 -0
  3. data/README.md +3 -6
  4. data/app/assets/config/manifest.js +3 -0
  5. data/app/helpers/accounts_helper.rb +2 -0
  6. data/app/helpers/application_helper.rb +22 -3
  7. data/app/helpers/tasks_helper.rb +1 -2
  8. data/app/models/entities/account.rb +1 -1
  9. data/app/models/entities/campaign.rb +1 -1
  10. data/app/models/entities/contact.rb +1 -1
  11. data/app/models/entities/lead.rb +1 -1
  12. data/app/models/entities/opportunity.rb +1 -1
  13. data/app/models/polymorphic/avatar.rb +1 -30
  14. data/app/models/polymorphic/task.rb +1 -0
  15. data/app/views/home/index.xls.builder +1 -0
  16. data/app/views/shared/_address.html.haml +1 -1
  17. data/config/application.rb +13 -0
  18. data/config/environments/development.rb +3 -0
  19. data/config/puma.rb +2 -2
  20. data/config/storage.yml +34 -0
  21. data/db/migrate/20100928030617_drop_openid_tables.rb +2 -1
  22. data/db/migrate/20230526211831_create_active_storage_tables.active_storage.rb +51 -0
  23. data/db/migrate/20230526212613_convert_to_active_storage.rb +91 -0
  24. data/db/schema.rb +65 -35
  25. data/db/seeds/fields.rb +7 -21
  26. data/lib/development_tasks/license.rake +10 -10
  27. data/lib/fat_free_crm/errors.rb +2 -10
  28. data/lib/fat_free_crm/exceptions.rb +1 -0
  29. data/lib/fat_free_crm/fields.rb +4 -5
  30. data/lib/fat_free_crm/gem_dependencies.rb +0 -1
  31. data/lib/fat_free_crm/i18n.rb +1 -1
  32. data/lib/fat_free_crm/version.rb +3 -3
  33. metadata +16 -279
  34. data/.docker/nginx/sites-enabled/ffcrm.conf +0 -8
  35. data/.github/workflows/brakeman-analysis.yml +0 -46
  36. data/.github/workflows/rubocop-analysis.yml +0 -40
  37. data/.github/workflows/ruby.yml +0 -52
  38. data/.gitignore +0 -39
  39. data/.rubocop.yml +0 -73
  40. data/.rubocop_todo.yml +0 -286
  41. data/.teatro.yml +0 -3
  42. data/.travis.yml +0 -60
  43. data/CONTRIBUTORS.md +0 -135
  44. data/Capfile +0 -27
  45. data/Dockerfile +0 -51
  46. data/Gemfile +0 -106
  47. data/Gemfile.lock +0 -529
  48. data/Guardfile +0 -26
  49. data/Procfile +0 -1
  50. data/SECURITY.md +0 -11
  51. data/Vagrantfile +0 -92
  52. data/custom_plan.rb +0 -11
  53. data/docker-compose.yml +0 -27
  54. data/fat_free_crm.gemspec +0 -62
  55. data/lib/tasks/.gitkeep +0 -0
  56. data/lib/tasks/.gitkeep~master +0 -0
  57. data/script/rails +0 -8
  58. data/spec/controllers/admin/groups_controller_spec.rb +0 -11
  59. data/spec/controllers/admin/users_controller_spec.rb +0 -251
  60. data/spec/controllers/applications_controller_spec.rb +0 -43
  61. data/spec/controllers/comments_controller_spec.rb +0 -195
  62. data/spec/controllers/emails_controller_spec.rb +0 -37
  63. data/spec/controllers/entities/accounts_controller_spec.rb +0 -607
  64. data/spec/controllers/entities/campaigns_controller_spec.rb +0 -645
  65. data/spec/controllers/entities/contacts_controller_spec.rb +0 -705
  66. data/spec/controllers/entities/leads_controller_spec.rb +0 -1009
  67. data/spec/controllers/entities/opportunities_controller_spec.rb +0 -904
  68. data/spec/controllers/entities_controller_spec.rb +0 -47
  69. data/spec/controllers/home_controller_spec.rb +0 -235
  70. data/spec/controllers/lists_controller_spec.rb +0 -11
  71. data/spec/controllers/tasks_controller_spec.rb +0 -517
  72. data/spec/controllers/users_controller_spec.rb +0 -375
  73. data/spec/factories/account_factories.rb +0 -40
  74. data/spec/factories/campaign_factories.rb +0 -30
  75. data/spec/factories/contact_factories.rb +0 -45
  76. data/spec/factories/field_factories.rb +0 -40
  77. data/spec/factories/lead_factories.rb +0 -36
  78. data/spec/factories/list_factories.rb +0 -13
  79. data/spec/factories/opportunity_factories.rb +0 -39
  80. data/spec/factories/sequences.rb +0 -32
  81. data/spec/factories/setting_factories.rb +0 -15
  82. data/spec/factories/shared_factories.rb +0 -70
  83. data/spec/factories/subscription_factories.rb +0 -13
  84. data/spec/factories/tag_factories.rb +0 -12
  85. data/spec/factories/task_factories.rb +0 -29
  86. data/spec/factories/user_factories.rb +0 -66
  87. data/spec/features/acceptance_helper.rb +0 -11
  88. data/spec/features/accounts_spec.rb +0 -126
  89. data/spec/features/admin/groups_spec.rb +0 -31
  90. data/spec/features/admin/users_spec.rb +0 -40
  91. data/spec/features/campaigns_spec.rb +0 -104
  92. data/spec/features/contacts_spec.rb +0 -134
  93. data/spec/features/dashboard_spec.rb +0 -67
  94. data/spec/features/devise/sign_in_spec.rb +0 -58
  95. data/spec/features/devise/sign_up_spec.rb +0 -36
  96. data/spec/features/leads_spec.rb +0 -138
  97. data/spec/features/opportunities_overview_spec.rb +0 -88
  98. data/spec/features/opportunities_spec.rb +0 -132
  99. data/spec/features/support/autocomlete_helper.rb +0 -17
  100. data/spec/features/support/browser.rb +0 -28
  101. data/spec/features/support/headless.rb +0 -19
  102. data/spec/features/support/paths.rb +0 -48
  103. data/spec/features/support/selector_helpers.rb +0 -36
  104. data/spec/features/tasks_spec.rb +0 -94
  105. data/spec/fixtures/rails.png +0 -0
  106. data/spec/helpers/accounts_helper_spec.rb +0 -73
  107. data/spec/helpers/admin/field_groups_helper_spec.rb +0 -20
  108. data/spec/helpers/admin/plugins_helper_spec.rb +0 -11
  109. data/spec/helpers/admin/settings_helper_spec.rb +0 -11
  110. data/spec/helpers/admin/users_helper_spec.rb +0 -11
  111. data/spec/helpers/application_helper_spec.rb +0 -86
  112. data/spec/helpers/authentications_helper_spec.rb +0 -16
  113. data/spec/helpers/campaigns_helper_spec.rb +0 -16
  114. data/spec/helpers/comments_helper_spec.rb +0 -16
  115. data/spec/helpers/contacts_helper_spec.rb +0 -16
  116. data/spec/helpers/emails_helper_spec.rb +0 -11
  117. data/spec/helpers/fields_helper_spec.rb +0 -12
  118. data/spec/helpers/groups_helper_spec.rb +0 -21
  119. data/spec/helpers/home_helper_spec.rb +0 -16
  120. data/spec/helpers/leads_helper_spec.rb +0 -16
  121. data/spec/helpers/lists_helper_spec.rb +0 -21
  122. data/spec/helpers/opportunities_helper_spec.rb +0 -16
  123. data/spec/helpers/passwords_helper_spec.rb +0 -16
  124. data/spec/helpers/tasks_helper_spec.rb +0 -20
  125. data/spec/helpers/users_helper_spec.rb +0 -39
  126. data/spec/lib/comment_extensions_spec.rb +0 -42
  127. data/spec/lib/core_ext/string_spec.rb +0 -23
  128. data/spec/lib/errors_spec.rb +0 -32
  129. data/spec/lib/fields_spec.rb +0 -101
  130. data/spec/lib/mail_processor/base_spec.rb +0 -169
  131. data/spec/lib/mail_processor/comment_replies_spec.rb +0 -70
  132. data/spec/lib/mail_processor/dropbox_spec.rb +0 -306
  133. data/spec/lib/mail_processor/sample_emails/dropbox.rb +0 -173
  134. data/spec/lib/permissions_spec.rb +0 -155
  135. data/spec/lib/secret_token_generator_spec.rb +0 -69
  136. data/spec/lib/view_factory_spec.rb +0 -69
  137. data/spec/mailers/devise_mailer_spec.rb +0 -35
  138. data/spec/mailers/subscription_mailer_spec.rb +0 -48
  139. data/spec/mailers/user_mailer_spec.rb +0 -115
  140. data/spec/models/entities/account_contact_spec.rb +0 -34
  141. data/spec/models/entities/account_opportunity_spec.rb +0 -34
  142. data/spec/models/entities/account_spec.rb +0 -206
  143. data/spec/models/entities/campaign_spec.rb +0 -131
  144. data/spec/models/entities/contact_opportunity_spec.rb +0 -34
  145. data/spec/models/entities/contact_spec.rb +0 -314
  146. data/spec/models/entities/lead_spec.rb +0 -102
  147. data/spec/models/entities/opportunity_spec.rb +0 -299
  148. data/spec/models/fields/custom_field_date_pair_spec.rb +0 -92
  149. data/spec/models/fields/custom_field_pair_spec.rb +0 -76
  150. data/spec/models/fields/custom_field_spec.rb +0 -129
  151. data/spec/models/fields/field_group_spec.rb +0 -29
  152. data/spec/models/fields/field_spec.rb +0 -69
  153. data/spec/models/list_spec.rb +0 -19
  154. data/spec/models/observers/entity_observer_spec.rb +0 -74
  155. data/spec/models/polymorphic/address_spec.rb +0 -34
  156. data/spec/models/polymorphic/avatar_spec.rb +0 -46
  157. data/spec/models/polymorphic/comment_spec.rb +0 -45
  158. data/spec/models/polymorphic/email_spec.rb +0 -53
  159. data/spec/models/polymorphic/task_spec.rb +0 -395
  160. data/spec/models/polymorphic/version_spec.rb +0 -241
  161. data/spec/models/setting_spec.rb +0 -77
  162. data/spec/models/users/abilities/user_ability_spec.rb +0 -70
  163. data/spec/models/users/group_spec.rb +0 -11
  164. data/spec/models/users/permission_spec.rb +0 -58
  165. data/spec/models/users/preference_spec.rb +0 -71
  166. data/spec/models/users/user_spec.rb +0 -238
  167. data/spec/routing/accounts_routing_spec.rb +0 -60
  168. data/spec/routing/admin/users_routing_spec.rb +0 -40
  169. data/spec/routing/campaigns_routing_spec.rb +0 -64
  170. data/spec/routing/comments_routing_spec.rb +0 -32
  171. data/spec/routing/contacts_routing_spec.rb +0 -60
  172. data/spec/routing/emails_routing_spec.rb +0 -40
  173. data/spec/routing/leads_routing_spec.rb +0 -88
  174. data/spec/routing/opportunities_routing_spec.rb +0 -64
  175. data/spec/routing/tasks_routing_spec.rb +0 -68
  176. data/spec/routing/users_routing_spec.rb +0 -106
  177. data/spec/shared/controllers.rb +0 -99
  178. data/spec/shared/models.rb +0 -141
  179. data/spec/spec_helper.rb +0 -117
  180. data/spec/support/assert_select.rb +0 -167
  181. data/spec/support/devise_helpers.rb +0 -28
  182. data/spec/support/feature_helpers.rb +0 -32
  183. data/spec/support/macros.rb +0 -49
  184. data/spec/support/mail_processor_mocks.rb +0 -37
  185. data/spec/support/uploaded_file.rb +0 -10
  186. data/spec/views/accounts/_edit.haml_spec.rb +0 -43
  187. data/spec/views/accounts/_new.haml_spec.rb +0 -42
  188. data/spec/views/accounts/create.js.haml_spec.rb +0 -52
  189. data/spec/views/accounts/destroy.js.haml_spec.rb +0 -34
  190. data/spec/views/accounts/edit.js.haml_spec.rb +0 -66
  191. data/spec/views/accounts/index.haml_spec.rb +0 -43
  192. data/spec/views/accounts/index.js.haml_spec.rb +0 -34
  193. data/spec/views/accounts/new.js.haml_spec.rb +0 -44
  194. data/spec/views/accounts/show.haml_spec.rb +0 -38
  195. data/spec/views/accounts/update.js.haml_spec.rb +0 -93
  196. data/spec/views/admin/field_groups/create.js.haml_spec.rb +0 -30
  197. data/spec/views/admin/field_groups/destroy.js.haml_spec.rb +0 -31
  198. data/spec/views/admin/field_groups/edit.js.haml_spec.rb +0 -24
  199. data/spec/views/admin/field_groups/new.js.haml_spec.rb +0 -25
  200. data/spec/views/admin/field_groups/update.js.haml_spec.rb +0 -29
  201. data/spec/views/admin/users/_create.haml_spec.rb +0 -23
  202. data/spec/views/admin/users/create.js.haml_spec.rb +0 -41
  203. data/spec/views/admin/users/destroy.js.haml_spec.rb +0 -47
  204. data/spec/views/admin/users/edit.js.haml_spec.rb +0 -44
  205. data/spec/views/admin/users/index.haml_spec.rb +0 -22
  206. data/spec/views/admin/users/index.js.haml_spec.rb +0 -26
  207. data/spec/views/admin/users/new.js.haml_spec.rb +0 -34
  208. data/spec/views/admin/users/reactivate.js.haml_spec.rb +0 -22
  209. data/spec/views/admin/users/show.haml_spec.rb +0 -18
  210. data/spec/views/admin/users/suspend.js.haml_spec.rb +0 -22
  211. data/spec/views/admin/users/update.js.haml_spec.rb +0 -37
  212. data/spec/views/application/auto_complete.haml_spec.rb +0 -48
  213. data/spec/views/campaigns/_edit.haml_spec.rb +0 -44
  214. data/spec/views/campaigns/_new.haml_spec.rb +0 -41
  215. data/spec/views/campaigns/create.js.haml_spec.rb +0 -49
  216. data/spec/views/campaigns/destroy.js.haml_spec.rb +0 -31
  217. data/spec/views/campaigns/edit.js.haml_spec.rb +0 -66
  218. data/spec/views/campaigns/index.haml_spec.rb +0 -37
  219. data/spec/views/campaigns/index.js.haml_spec.rb +0 -34
  220. data/spec/views/campaigns/new.js.haml_spec.rb +0 -50
  221. data/spec/views/campaigns/show.haml_spec.rb +0 -38
  222. data/spec/views/campaigns/update.js.haml_spec.rb +0 -78
  223. data/spec/views/comments/edit.js.haml_spec.rb +0 -30
  224. data/spec/views/contacts/_edit.haml_spec.rb +0 -73
  225. data/spec/views/contacts/_new.haml_spec.rb +0 -52
  226. data/spec/views/contacts/create.js.haml_spec.rb +0 -65
  227. data/spec/views/contacts/destroy.js.haml_spec.rb +0 -45
  228. data/spec/views/contacts/edit.js.haml_spec.rb +0 -74
  229. data/spec/views/contacts/index.haml_spec.rb +0 -37
  230. data/spec/views/contacts/index.js.html_spec.rb +0 -34
  231. data/spec/views/contacts/new.js.haml_spec.rb +0 -47
  232. data/spec/views/contacts/show.haml_spec.rb +0 -35
  233. data/spec/views/contacts/update.js.haml_spec.rb +0 -128
  234. data/spec/views/home/index.haml_spec.rb +0 -36
  235. data/spec/views/home/index.js.haml_spec.rb +0 -33
  236. data/spec/views/home/options.js.haml_spec.rb +0 -53
  237. data/spec/views/leads/_convert.haml_spec.rb +0 -30
  238. data/spec/views/leads/_edit.haml_spec.rb +0 -47
  239. data/spec/views/leads/_new.haml_spec.rb +0 -45
  240. data/spec/views/leads/_sidebar_show.haml_spec.rb +0 -31
  241. data/spec/views/leads/convert.js.haml_spec.rb +0 -79
  242. data/spec/views/leads/create.js.haml_spec.rb +0 -67
  243. data/spec/views/leads/destroy.js.haml_spec.rb +0 -47
  244. data/spec/views/leads/edit.js.haml_spec.rb +0 -76
  245. data/spec/views/leads/index.haml_spec.rb +0 -37
  246. data/spec/views/leads/index.js.haml_spec.rb +0 -34
  247. data/spec/views/leads/new.js.haml_spec.rb +0 -47
  248. data/spec/views/leads/promote.js.haml_spec.rb +0 -135
  249. data/spec/views/leads/reject.js.haml_spec.rb +0 -45
  250. data/spec/views/leads/show.haml_spec.rb +0 -32
  251. data/spec/views/leads/update.js.haml_spec.rb +0 -118
  252. data/spec/views/opportunities/_edit.haml_spec.rb +0 -70
  253. data/spec/views/opportunities/_new.haml_spec.rb +0 -51
  254. data/spec/views/opportunities/create.js.haml_spec.rb +0 -86
  255. data/spec/views/opportunities/destroy.js.haml_spec.rb +0 -64
  256. data/spec/views/opportunities/edit.js.haml_spec.rb +0 -75
  257. data/spec/views/opportunities/index.haml_spec.rb +0 -38
  258. data/spec/views/opportunities/index.js.haml_spec.rb +0 -35
  259. data/spec/views/opportunities/new.js.haml_spec.rb +0 -54
  260. data/spec/views/opportunities/show.haml_spec.rb +0 -35
  261. data/spec/views/opportunities/update.js.haml_spec.rb +0 -143
  262. data/spec/views/tasks/_edit.haml_spec.rb +0 -50
  263. data/spec/views/tasks/complete.js.haml_spec.rb +0 -67
  264. data/spec/views/tasks/create.js.haml_spec.rb +0 -119
  265. data/spec/views/tasks/destroy.js.haml_spec.rb +0 -57
  266. data/spec/views/tasks/edit.js.haml_spec.rb +0 -76
  267. data/spec/views/tasks/index.haml_spec.rb +0 -46
  268. data/spec/views/tasks/new.js.haml_spec.rb +0 -49
  269. data/spec/views/tasks/uncomplete.js.haml_spec.rb +0 -45
  270. data/spec/views/tasks/update.js.haml_spec.rb +0 -140
  271. data/spec/views/users/avatar.js.haml_spec.rb +0 -35
  272. data/spec/views/users/change_password.js.haml_spec.rb +0 -51
  273. data/spec/views/users/edit.js.haml_spec.rb +0 -35
  274. data/spec/views/users/password.js.haml_spec.rb +0 -36
  275. data/spec/views/users/update.js.haml_spec.rb +0 -46
  276. data/spec/views/users/upload_avatar.js.haml_spec.rb +0 -45
  277. data/vendor/gems/globby-0.1.2/LICENSE.txt +0 -20
  278. data/vendor/gems/globby-0.1.2/README.md +0 -65
  279. data/vendor/gems/globby-0.1.2/Rakefile +0 -9
  280. data/vendor/gems/globby-0.1.2/lib/globby/glob.rb +0 -90
  281. data/vendor/gems/globby-0.1.2/lib/globby/globject.rb +0 -18
  282. data/vendor/gems/globby-0.1.2/lib/globby/result.rb +0 -20
  283. data/vendor/gems/globby-0.1.2/lib/globby.rb +0 -47
  284. data/vendor/gems/globby-0.1.2/spec/gitignore_spec.rb +0 -109
  285. data/vendor/gems/globby-0.1.2/spec/globby_spec.rb +0 -93
  286. data/zeus.json +0 -22
@@ -1,904 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2008-2013 Michael Dvorkin and contributors.
4
- #
5
- # Fat Free CRM is freely distributable under the terms of MIT license.
6
- # See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
7
- #------------------------------------------------------------------------------
8
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
9
-
10
- describe OpportunitiesController do
11
- def get_data_for_sidebar
12
- @stage = Setting.unroll(:opportunity_stage)
13
- end
14
-
15
- before do
16
- login
17
- set_current_tab(:opportunities)
18
- end
19
-
20
- # GET /opportunities
21
- # GET /opportunities.xml
22
- #----------------------------------------------------------------------------
23
- describe "responding to GET index" do
24
- before do
25
- get_data_for_sidebar
26
- end
27
-
28
- it "should expose all opportunities as @opportunities and render [index] template" do
29
- @opportunities = [create(:opportunity, user: current_user)]
30
-
31
- get :index
32
- expect(assigns[:opportunities]).to eq(@opportunities)
33
- expect(response).to render_template("opportunities/index")
34
- end
35
-
36
- it "should expose the data for the opportunities sidebar" do
37
- get :index
38
- expect(assigns[:stage]).to eq(@stage)
39
- expect(assigns[:opportunity_stage_total].keys.map(&:to_sym) - (@stage.map(&:last) << :all << :other)).to eq([])
40
- end
41
-
42
- it "should filter out opportunities by stage" do
43
- controller.session[:opportunities_filter] = "prospecting,negotiation"
44
- @opportunities = [
45
- create(:opportunity, user: current_user, stage: "negotiation"),
46
- create(:opportunity, user: current_user, stage: "prospecting")
47
- ]
48
- # This one should be filtered out.
49
- create(:opportunity, user: current_user, stage: "analysis")
50
-
51
- get :index
52
- # Note: can't compare opportunities directly because of BigDecimal objects.
53
- expect(assigns[:opportunities].size).to eq(2)
54
- expect(assigns[:opportunities].map(&:stage).sort).to eq(%w[negotiation prospecting])
55
- end
56
-
57
- it "should perform lookup using query string" do
58
- @first = create(:opportunity, user: current_user, name: "The first one")
59
- @second = create(:opportunity, user: current_user, name: "The second one")
60
-
61
- get :index, params: { query: "second" }
62
- expect(assigns[:opportunities]).to eq([@second])
63
- expect(assigns[:current_query]).to eq("second")
64
- expect(session[:opportunities_current_query]).to eq("second")
65
- end
66
-
67
- describe "AJAX pagination" do
68
- it "should pick up page number from params" do
69
- @opportunities = [create(:opportunity, user: current_user)]
70
- get :index, params: { page: 42 }, xhr: true
71
-
72
- expect(assigns[:current_page].to_i).to eq(42)
73
- expect(assigns[:opportunities]).to eq([]) # page #42 should be empty if there's only one opportunity ;-)
74
- expect(session[:opportunities_current_page].to_i).to eq(42)
75
- expect(response).to render_template("opportunities/index")
76
- end
77
-
78
- it "should pick up saved page number from session" do
79
- session[:opportunities_current_page] = 42
80
- @opportunities = [create(:opportunity, user: current_user)]
81
- get :index, xhr: true
82
-
83
- expect(assigns[:current_page]).to eq(42)
84
- expect(assigns[:opportunities]).to eq([])
85
- expect(response).to render_template("opportunities/index")
86
- end
87
-
88
- it "should reset current_page when query is altered" do
89
- session[:opportunities_current_page] = 42
90
- session[:opportunities_current_query] = "bill"
91
- @opportunities = [create(:opportunity, user: current_user)]
92
- get :index, xhr: true
93
-
94
- expect(assigns[:current_page]).to eq(1)
95
- expect(assigns[:opportunities]).to eq(@opportunities)
96
- expect(response).to render_template("opportunities/index")
97
- end
98
- end
99
-
100
- describe "with mime type of JSON" do
101
- it "should render all opportunities as JSON" do
102
- expect(@controller).to receive(:get_opportunities).and_return(opportunities = double("Array of Opportunities"))
103
- expect(opportunities).to receive(:to_json).and_return("generated JSON")
104
-
105
- request.env["HTTP_ACCEPT"] = "application/json"
106
- get :index
107
- expect(response.body).to eq("generated JSON")
108
- end
109
- end
110
-
111
- describe "with mime type of JSON" do
112
- it "should render all opportunities as JSON" do
113
- expect(@controller).to receive(:get_opportunities).and_return(opportunities = double("Array of Opportunities"))
114
- expect(opportunities).to receive(:to_json).and_return("generated JSON")
115
-
116
- request.env["HTTP_ACCEPT"] = "application/json"
117
- get :index
118
- expect(response.body).to eq("generated JSON")
119
- end
120
- end
121
-
122
- describe "with mime type of XML" do
123
- it "should render all opportunities as xml" do
124
- expect(@controller).to receive(:get_opportunities).and_return(opportunities = double("Array of Opportunities"))
125
- expect(opportunities).to receive(:to_xml).and_return("generated XML")
126
-
127
- request.env["HTTP_ACCEPT"] = "application/xml"
128
- get :index
129
- expect(response.body).to eq("generated XML")
130
- end
131
- end
132
- end
133
-
134
- # GET /opportunities/1
135
- # GET /opportunities/1.xml HTML
136
- #----------------------------------------------------------------------------
137
- describe "responding to GET show" do
138
- describe "with mime type of HTML" do
139
- before do
140
- @opportunity = create(:opportunity, id: 42)
141
- @stage = Setting.unroll(:opportunity_stage)
142
- @comment = Comment.new
143
- end
144
-
145
- it "should expose the requested opportunity as @opportunity and render [show] template" do
146
- get :show, params: { id: 42 }
147
- expect(assigns[:opportunity]).to eq(@opportunity)
148
- expect(assigns[:stage]).to eq(@stage)
149
- expect(assigns[:comment].attributes).to eq(@comment.attributes)
150
- expect(response).to render_template("opportunities/show")
151
- end
152
-
153
- it "should update an activity when viewing the opportunity" do
154
- get :show, params: { id: @opportunity.id }
155
- expect(@opportunity.versions.last.event).to eq('view')
156
- end
157
- end
158
-
159
- describe "with mime type of JSON" do
160
- it "should render the requested opportunity as JSON" do
161
- @opportunity = create(:opportunity, id: 42)
162
- expect(Opportunity).to receive(:find).and_return(@opportunity)
163
- expect(@opportunity).to receive(:to_json).and_return("generated JSON")
164
-
165
- request.env["HTTP_ACCEPT"] = "application/json"
166
- get :show, params: { id: 42 }
167
- expect(response.body).to eq("generated JSON")
168
- end
169
- end
170
-
171
- describe "with mime type of XML" do
172
- it "should render the requested opportunity as xml" do
173
- @opportunity = create(:opportunity, id: 42)
174
- expect(Opportunity).to receive(:find).and_return(@opportunity)
175
- expect(@opportunity).to receive(:to_xml).and_return("generated XML")
176
-
177
- request.env["HTTP_ACCEPT"] = "application/xml"
178
- get :show, params: { id: 42 }
179
- expect(response.body).to eq("generated XML")
180
- end
181
- end
182
-
183
- describe "opportunity got deleted or otherwise unavailable" do
184
- it "should redirect to opportunity index if the opportunity got deleted" do
185
- @opportunity = create(:opportunity, user: current_user)
186
- @opportunity.destroy
187
-
188
- get :show, params: { id: @opportunity.id }
189
- expect(flash[:warning]).not_to eq(nil)
190
- expect(response).to redirect_to(opportunities_path)
191
- end
192
-
193
- it "should redirect to opportunity index if the opportunity is protected" do
194
- @private = create(:opportunity, user: create(:user), access: "Private")
195
-
196
- get :show, params: { id: @private.id }
197
- expect(flash[:warning]).not_to eq(nil)
198
- expect(response).to redirect_to(opportunities_path)
199
- end
200
-
201
- it "should return 404 (Not Found) JSON error" do
202
- @opportunity = create(:opportunity, user: current_user)
203
- @opportunity.destroy
204
- request.env["HTTP_ACCEPT"] = "application/json"
205
-
206
- get :show, params: { id: @opportunity.id }
207
- expect(response.code).to eq("404") # :not_found
208
- end
209
-
210
- it "should return 404 (Not Found) XML error" do
211
- @opportunity = create(:opportunity, user: current_user)
212
- @opportunity.destroy
213
- request.env["HTTP_ACCEPT"] = "application/xml"
214
-
215
- get :show, params: { id: @opportunity.id }
216
- expect(response.code).to eq("404") # :not_found
217
- end
218
- end
219
- end
220
-
221
- # GET /opportunities/new
222
- # GET /opportunities/new.xml AJAX
223
- #----------------------------------------------------------------------------
224
- describe "responding to GET new" do
225
- it "should expose a new opportunity as @opportunity and render [new] template" do
226
- @opportunity = Opportunity.new(user: current_user, access: Setting.default_access, stage: "prospecting")
227
- @account = Account.new(user: current_user, access: Setting.default_access)
228
- @accounts = [create(:account, user: current_user)]
229
-
230
- get :new, xhr: true
231
- expect(assigns[:opportunity].attributes).to eq(@opportunity.attributes)
232
- expect(assigns[:account].attributes).to eq(@account.attributes)
233
- expect(assigns[:accounts]).to eq(@accounts)
234
- expect(response).to render_template("opportunities/new")
235
- end
236
-
237
- it "should created an instance of related object when necessary" do
238
- @contact = create(:contact, id: 42)
239
-
240
- get :new, params: { related: "contact_42" }, xhr: true
241
- expect(assigns[:contact]).to eq(@contact)
242
- end
243
-
244
- describe "(when creating related opportunity)" do
245
- it "should redirect to parent asset's index page with the message if parent asset got deleted" do
246
- @account = create(:account)
247
- @account.destroy
248
-
249
- get :new, params: { related: "account_#{@account.id}" }, xhr: true
250
- expect(flash[:warning]).not_to eq(nil)
251
- expect(response.body).to eq('window.location.href = "/accounts";')
252
- end
253
-
254
- it "should redirect to parent asset's index page with the message if parent asset got protected" do
255
- @account = create(:account, access: "Private")
256
-
257
- get :new, params: { related: "account_#{@account.id}" }, xhr: true
258
- expect(flash[:warning]).not_to eq(nil)
259
- expect(response.body).to eq('window.location.href = "/accounts";')
260
- end
261
- end
262
- end
263
-
264
- # GET /opportunities/1/edit AJAX
265
- #----------------------------------------------------------------------------
266
- describe "responding to GET edit" do
267
- it "should expose the requested opportunity as @opportunity and render [edit] template" do
268
- # Note: campaign => nil makes sure campaign factory is not invoked which has a side
269
- # effect of creating an extra (campaign) user.
270
- @account = create(:account, user: current_user)
271
- @opportunity = create(:opportunity, id: 42, user: current_user, campaign: nil,
272
- account: @account)
273
- @stage = Setting.unroll(:opportunity_stage)
274
- @accounts = [@account]
275
-
276
- get :edit, params: { id: 42 }, xhr: true
277
- @opportunity.reload
278
- expect(assigns[:opportunity]).to eq(@opportunity)
279
- expect(assigns[:account].attributes).to eq(@opportunity.account.attributes)
280
- expect(assigns[:accounts]).to eq(@accounts)
281
- expect(assigns[:stage]).to eq(@stage)
282
- expect(assigns[:previous]).to eq(nil)
283
- expect(response).to render_template("opportunities/edit")
284
- end
285
-
286
- it "should expose previous opportunity as @previous when necessary" do
287
- @opportunity = create(:opportunity, id: 42)
288
- @previous = create(:opportunity, id: 41)
289
-
290
- get :edit, params: { id: 42, previous: 41 }, xhr: true
291
- expect(assigns[:previous]).to eq(@previous)
292
- end
293
-
294
- describe "opportunity got deleted or is otherwise unavailable" do
295
- it "should reload current page with the flash message if the opportunity got deleted" do
296
- @opportunity = create(:opportunity, user: current_user)
297
- @opportunity.destroy
298
-
299
- get :edit, params: { id: @opportunity.id }, xhr: true
300
- expect(flash[:warning]).not_to eq(nil)
301
- expect(response.body).to eq("window.location.reload();")
302
- end
303
-
304
- it "should reload current page with the flash message if the opportunity is protected" do
305
- @private = create(:opportunity, user: create(:user), access: "Private")
306
-
307
- get :edit, params: { id: @private.id }, xhr: true
308
- expect(flash[:warning]).not_to eq(nil)
309
- expect(response.body).to eq("window.location.reload();")
310
- end
311
- end
312
-
313
- describe "(previous opportunity got deleted or is otherwise unavailable)" do
314
- before do
315
- @opportunity = create(:opportunity, user: current_user)
316
- @previous = create(:opportunity, user: create(:user))
317
- end
318
-
319
- it "should notify the view if previous opportunity got deleted" do
320
- @previous.destroy
321
-
322
- get :edit, params: { id: @opportunity.id, previous: @previous.id }, xhr: true
323
- expect(flash[:warning]).to eq(nil) # no warning, just silently remove the div
324
- expect(assigns[:previous]).to eq(@previous.id)
325
- expect(response).to render_template("opportunities/edit")
326
- end
327
-
328
- it "should notify the view if previous opportunity got protected" do
329
- @previous.update_attribute(:access, "Private")
330
-
331
- get :edit, params: { id: @opportunity.id, previous: @previous.id }, xhr: true
332
- expect(flash[:warning]).to eq(nil)
333
- expect(assigns[:previous]).to eq(@previous.id)
334
- expect(response).to render_template("opportunities/edit")
335
- end
336
- end
337
- end
338
-
339
- # POST /opportunities
340
- # POST /opportunities.xml AJAX
341
- #----------------------------------------------------------------------------
342
- describe "responding to POST create" do
343
- describe "with valid params" do
344
- before do
345
- @opportunity = build(:opportunity, user: current_user)
346
- allow(Opportunity).to receive(:new).and_return(@opportunity)
347
- @stage = Setting.unroll(:opportunity_stage)
348
- end
349
-
350
- it "should expose a newly created opportunity as @opportunity and render [create] template" do
351
- post :create, params: { opportunity: { name: "Hello" }, account: { name: "Hello again" } }, xhr: true
352
- expect(assigns(:opportunity)).to eq(@opportunity)
353
- expect(assigns(:stage)).to eq(@stage)
354
- expect(assigns(:opportunity_stage_total)).to be_nil
355
- expect(response).to render_template("opportunities/create")
356
- end
357
-
358
- it "should get sidebar data if called from opportunities index" do
359
- request.env["HTTP_REFERER"] = "http://localhost/opportunities"
360
- post :create, params: { opportunity: { name: "Hello" }, account: { name: "Hello again" } }, xhr: true
361
- expect(assigns(:opportunity_stage_total)).to be_an_instance_of(HashWithIndifferentAccess)
362
- end
363
-
364
- it "should find related account if called from account landing page" do
365
- @account = create(:account, user: current_user)
366
- request.env["HTTP_REFERER"] = "http://localhost/accounts/#{@account.id}"
367
-
368
- post :create, params: { opportunity: { name: "Hello" }, account: { id: @account.id } }, xhr: true
369
- expect(assigns(:account)).to eq(@account)
370
- end
371
-
372
- it "should find related campaign if called from campaign landing page" do
373
- @campaign = create(:campaign, user: current_user)
374
- request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
375
-
376
- post :create, params: { opportunity: { name: "Hello" }, campaign: @campaign.id, account: { name: "Hello again" } }, xhr: true
377
- expect(assigns(:campaign)).to eq(@campaign)
378
- end
379
-
380
- it "should reload opportunities to update pagination if called from opportunities index" do
381
- request.env["HTTP_REFERER"] = "http://localhost/opportunities"
382
- post :create, params: { opportunity: { name: "Hello" }, account: { name: "Hello again" } }, xhr: true
383
- expect(assigns[:opportunities]).to eq([@opportunity])
384
- end
385
-
386
- it "should associate opportunity with the campaign when called from campaign landing page" do
387
- @campaign = create(:campaign)
388
-
389
- request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
390
- post :create, params: { opportunity: { name: "Hello" }, campaign: @campaign.id, account: { name: "Test Account" } }, xhr: true
391
- expect(assigns(:opportunity)).to eq(@opportunity)
392
- expect(assigns(:campaign)).to eq(@campaign)
393
- expect(@opportunity.campaign).to eq(@campaign)
394
- end
395
-
396
- it "should associate opportunity with the contact when called from contact landing page" do
397
- @contact = create(:contact, id: 42)
398
-
399
- request.env["HTTP_REFERER"] = "http://localhost/contacts/42"
400
- post :create, params: { opportunity: { name: "Hello" }, contact: 42, account: { name: "Hello again" } }, xhr: true
401
- expect(assigns(:opportunity)).to eq(@opportunity)
402
- expect(@opportunity.contacts).to include(@contact)
403
- expect(@contact.opportunities).to include(@opportunity)
404
- end
405
-
406
- it "should create new account and associate it with the opportunity" do
407
- put :create, params: { opportunity: { name: "Hello" }, account: { name: "new account" } }, xhr: true
408
- expect(assigns(:opportunity)).to eq(@opportunity)
409
- expect(@opportunity.account.name).to eq("new account")
410
- end
411
-
412
- it "should associate opportunity with the existing account" do
413
- @account = create(:account, id: 42)
414
-
415
- post :create, params: { opportunity: { name: "Hello world" }, account: { id: 42 } }, xhr: true
416
- expect(assigns(:opportunity)).to eq(@opportunity)
417
- expect(@opportunity.account).to eq(@account)
418
- expect(@account.opportunities).to include(@opportunity)
419
- end
420
-
421
- it "should update related campaign revenue if won" do
422
- @campaign = create(:campaign, revenue: 0)
423
- @opportunity = build(:opportunity, user: current_user, stage: "won", amount: 1100, discount: 100)
424
- allow(Opportunity).to receive(:new).and_return(@opportunity)
425
-
426
- post :create, params: { opportunity: { name: "Hello world" }, campaign: @campaign.id, account: { name: "Test Account" } }, xhr: true
427
- expect(assigns(:opportunity)).to eq(@opportunity)
428
- expect(@opportunity.campaign).to eq(@campaign.reload)
429
- expect(@campaign.revenue.to_i).to eq(1000) # 1000 - 100 discount.
430
- end
431
-
432
- it "should add a new comment to the newly created opportunity when specified" do
433
- @opportunity = build(:opportunity, user: current_user)
434
- allow(Opportunity).to receive(:new).and_return(@opportunity)
435
-
436
- post :create, params: { opportunity: { name: "Opportunity Knocks" }, account: { name: "My Account" }, comment_body: "Awesome comment is awesome" }, xhr: true
437
- expect(@opportunity.reload.comments.map(&:comment)).to include("Awesome comment is awesome")
438
- end
439
- end
440
-
441
- describe "with invalid params" do
442
- it "should expose a newly created but unsaved opportunity as @opportunity with blank @account and render [create] template" do
443
- @account = Account.new(user: current_user)
444
- @opportunity = build(:opportunity, name: nil, campaign: nil, user: current_user,
445
- account: @account)
446
- allow(Opportunity).to receive(:new).and_return(@opportunity)
447
- @stage = Setting.unroll(:opportunity_stage)
448
- @accounts = [create(:account, user: current_user)]
449
-
450
- # Expect to redraw [create] form with blank account.
451
- post :create, params: { opportunity: {}, account: { user_id: current_user.id } }, xhr: true
452
- expect(assigns(:opportunity)).to eq(@opportunity)
453
- expect(assigns(:account).attributes).to eq(@account.attributes)
454
- expect(assigns(:accounts)).to eq(@accounts)
455
- expect(response).to render_template("opportunities/create")
456
- end
457
-
458
- it "should expose a newly created but unsaved opportunity as @opportunity with existing @account and render [create] template" do
459
- @account = create(:account, id: 42, user: current_user)
460
- @opportunity = build(:opportunity, name: nil, campaign: nil, user: current_user,
461
- account: @account)
462
- allow(Opportunity).to receive(:new).and_return(@opportunity)
463
- @stage = Setting.unroll(:opportunity_stage)
464
-
465
- # Expect to redraw [create] form with selected account.
466
- post :create, params: { opportunity: {}, account: { id: 42, user_id: current_user.id } }, xhr: true
467
- expect(assigns(:opportunity)).to eq(@opportunity)
468
- expect(assigns(:account)).to eq(@account)
469
- expect(assigns(:accounts)).to eq([@account])
470
- expect(response).to render_template("opportunities/create")
471
- end
472
-
473
- it "should preserve the campaign when called from campaign landing page" do
474
- @campaign = create(:campaign, id: 42)
475
-
476
- request.env["HTTP_REFERER"] = "http://localhost/campaigns/42"
477
- post :create, params: { opportunity: { name: nil }, campaign: 42, account: { name: "Test Account" } }, xhr: true
478
- expect(assigns(:campaign)).to eq(@campaign)
479
- expect(response).to render_template("opportunities/create")
480
- end
481
-
482
- it "should preserve the contact when called from contact landing page" do
483
- @contact = create(:contact, id: 42)
484
-
485
- request.env["HTTP_REFERER"] = "http://localhost/contacts/42"
486
- post :create, params: { opportunity: { name: nil }, contact: 42, account: { name: "Test Account" } }, xhr: true
487
- expect(assigns(:contact)).to eq(@contact)
488
- expect(response).to render_template("opportunities/create")
489
- end
490
- end
491
- end
492
-
493
- # PUT /opportunities/1
494
- # PUT /opportunities/1.xml AJAX
495
- #----------------------------------------------------------------------------
496
- describe "responding to PUT update" do
497
- describe "with valid params" do
498
- it "should update the requested opportunity, expose it as @opportunity, and render [update] template" do
499
- @opportunity = create(:opportunity, id: 42)
500
- @stage = Setting.unroll(:opportunity_stage)
501
-
502
- put :update, params: { id: 42, opportunity: { name: "Hello world" }, account: { name: "Test Account" } }, xhr: true
503
- expect(@opportunity.reload.name).to eq("Hello world")
504
- expect(assigns(:opportunity)).to eq(@opportunity)
505
- expect(assigns(:stage)).to eq(@stage)
506
- expect(assigns(:opportunity_stage_total)).to eq(nil)
507
- expect(response).to render_template("opportunities/update")
508
- end
509
-
510
- it "should get sidebar data if called from opportunities index" do
511
- @opportunity = create(:opportunity, id: 42)
512
-
513
- request.env["HTTP_REFERER"] = "http://localhost/opportunities"
514
- put :update, params: { id: 42, opportunity: { name: "Hello world" }, account: { name: "Test Account" } }, xhr: true
515
- expect(assigns(:opportunity_stage_total)).to be_an_instance_of(HashWithIndifferentAccess)
516
- end
517
-
518
- it "should find related account if called from account landing page" do
519
- @account = create(:account, user: current_user)
520
- @opportunity = create(:opportunity, id: 42, account: @account)
521
- request.env["HTTP_REFERER"] = "http://localhost/accounts/#{@account.id}"
522
-
523
- put :update, params: { id: 42, opportunity: { name: "Hello world" } }, xhr: true
524
- expect(assigns(:account)).to eq(@account)
525
- end
526
-
527
- it "should remove related account if blank :account param is given" do
528
- @account = create(:account, user: current_user)
529
- @opportunity = create(:opportunity, id: 42, account: @account)
530
- request.env["HTTP_REFERER"] = "http://localhost/accounts/#{@account.id}"
531
-
532
- put :update, params: { id: 42, opportunity: { name: "Hello world" }, account: { id: "" } }, xhr: true
533
- expect(assigns(:account)).to eq(nil)
534
- end
535
-
536
- it "should find related campaign if called from campaign landing page" do
537
- @campaign = create(:campaign, user: current_user)
538
- @opportunity = create(:opportunity, id: 42, user: current_user)
539
- @campaign.opportunities << @opportunity
540
- request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
541
-
542
- put :update, params: { id: 42, opportunity: { name: "Hello world", campaign_id: @campaign.id }, account: {} }, xhr: true
543
- expect(assigns(:campaign)).to eq(@campaign)
544
- end
545
-
546
- it "should be able to create an account and associate it with updated opportunity" do
547
- @opportunity = create(:opportunity, id: 42)
548
-
549
- put :update, params: { id: 42, opportunity: { name: "Hello" }, account: { name: "new account" } }, xhr: true
550
- expect(assigns[:opportunity]).to eq(@opportunity)
551
- expect(assigns[:opportunity].account).not_to be_nil
552
- expect(assigns[:opportunity].account.name).to eq("new account")
553
- end
554
-
555
- it "should be able to create an account and associate it with updated opportunity" do
556
- @old_account = create(:account, id: 111)
557
- @new_account = create(:account, id: 999)
558
- @opportunity = create(:opportunity, id: 42, account: @old_account)
559
-
560
- put :update, params: { id: 42, opportunity: { name: "Hello" }, account: { id: 999 } }, xhr: true
561
- expect(assigns[:opportunity]).to eq(@opportunity)
562
- expect(assigns[:opportunity].account).to eq(@new_account)
563
- end
564
-
565
- it "should update opportunity permissions when sharing with specific users" do
566
- @opportunity = create(:opportunity, id: 42, access: "Public")
567
-
568
- put :update, params: { id: 42, opportunity: { name: "Hello", access: "Shared", user_ids: [7, 8] }, account: { name: "Test Account" } }, xhr: true
569
- expect(assigns[:opportunity].access).to eq("Shared")
570
- expect(assigns[:opportunity].user_ids.sort).to eq([7, 8])
571
- end
572
-
573
- it "should reload opportunity campaign if called from campaign landing page" do
574
- @campaign = create(:campaign)
575
- @opportunity = create(:opportunity, campaign: @campaign)
576
-
577
- request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
578
- put :update, params: { id: @opportunity.id, opportunity: { name: "Hello" }, account: { name: "Test Account" } }, xhr: true
579
- expect(assigns[:campaign]).to eq(@campaign)
580
- end
581
-
582
- describe "updating campaign revenue (same campaign)" do
583
- it "should add to actual revenue when opportunity is closed/won" do
584
- @campaign = create(:campaign, revenue: 1000)
585
- @opportunity = create(:opportunity, campaign: @campaign, stage: 'prospecting', amount: 1100, discount: 100)
586
-
587
- put :update, params: { id: @opportunity, opportunity: { stage: "won" }, account: { name: "Test Account" } }, xhr: true
588
- expect(@campaign.reload.revenue.to_i).to eq(2000) # 1000 -> 2000
589
- end
590
-
591
- it "should substract from actual revenue when opportunity is no longer closed/won" do
592
- @campaign = create(:campaign, revenue: 1000)
593
- @opportunity = create(:opportunity, campaign: @campaign, stage: "won", amount: 1100, discount: 100)
594
- # @campaign.revenue is now $2000 since we created winning opportunity.
595
-
596
- put :update, params: { id: @opportunity, opportunity: { stage: 'prospecting' }, account: { name: "Test Account" } }, xhr: true
597
- expect(@campaign.reload.revenue.to_i).to eq(1000) # Should be adjusted back to $1000.
598
- end
599
-
600
- it "should not update actual revenue when opportunity is not closed/won" do
601
- @campaign = create(:campaign, revenue: 1000)
602
- @opportunity = create(:opportunity, campaign: @campaign, stage: 'prospecting', amount: 1100, discount: 100)
603
-
604
- put :update, params: { id: @opportunity, opportunity: { stage: "lost" }, account: { name: "Test Account" } }, xhr: true
605
- expect(@campaign.reload.revenue.to_i).to eq(1000) # Stays the same.
606
- end
607
- end
608
-
609
- describe "updating campaign revenue (diferent campaigns)" do
610
- it "should update newly assigned campaign when opportunity is closed/won" do
611
- @campaigns = { old: create(:campaign, revenue: 1000), new: create(:campaign, revenue: 1000) }
612
- @opportunity = create(:opportunity, campaign: @campaigns[:old], stage: 'prospecting', amount: 1100, discount: 100)
613
-
614
- put :update, params: { id: @opportunity, opportunity: { stage: "won", campaign_id: @campaigns[:new].id }, account: { name: "Test Account" } }, xhr: true
615
-
616
- expect(@campaigns[:old].reload.revenue.to_i).to eq(1000) # Stays the same.
617
- expect(@campaigns[:new].reload.revenue.to_i).to eq(2000) # 1000 -> 2000
618
- end
619
-
620
- it "should update old campaign when opportunity is no longer closed/won" do
621
- @campaigns = { old: create(:campaign, revenue: 1000), new: create(:campaign, revenue: 1000) }
622
- @opportunity = create(:opportunity, campaign: @campaigns[:old], stage: "won", amount: 1100, discount: 100)
623
- # @campaign.revenue is now $2000 since we created winning opportunity.
624
-
625
- put :update, params: { id: @opportunity, opportunity: { stage: 'prospecting', campaign_id: @campaigns[:new].id }, account: { name: "Test Account" } }, xhr: true
626
- expect(@campaigns[:old].reload.revenue.to_i).to eq(1000) # Should be adjusted back to $1000.
627
- expect(@campaigns[:new].reload.revenue.to_i).to eq(1000) # Stays the same.
628
- end
629
-
630
- it "should not update campaigns when opportunity is not closed/won" do
631
- @campaigns = { old: create(:campaign, revenue: 1000), new: create(:campaign, revenue: 1000) }
632
- @opportunity = create(:opportunity, campaign: @campaigns[:old], stage: 'prospecting', amount: 1100, discount: 100)
633
-
634
- put :update, params: { id: @opportunity, opportunity: { stage: "lost", campaign_id: @campaigns[:new].id }, account: { name: "Test Account" } }, xhr: true
635
- expect(@campaigns[:old].reload.revenue.to_i).to eq(1000) # Stays the same.
636
- expect(@campaigns[:new].reload.revenue.to_i).to eq(1000) # Stays the same.
637
- end
638
- end
639
-
640
- describe "opportunity got deleted or otherwise unavailable" do
641
- it "should reload current page with the flash message if the opportunity got deleted" do
642
- @opportunity = create(:opportunity, user: current_user)
643
- @opportunity.destroy
644
-
645
- put :update, params: { id: @opportunity.id }, xhr: true
646
- expect(flash[:warning]).not_to eq(nil)
647
- expect(response.body).to eq("window.location.reload();")
648
- end
649
-
650
- it "should reload current page with the flash message if the opportunity is protected" do
651
- @private = create(:opportunity, user: create(:user), access: "Private")
652
-
653
- put :update, params: { id: @private.id }, xhr: true
654
- expect(flash[:warning]).not_to eq(nil)
655
- expect(response.body).to eq("window.location.reload();")
656
- end
657
- end
658
- end
659
-
660
- describe "with invalid params" do
661
- it "should not update the requested opportunity but still expose it as @opportunity, and render [update] template" do
662
- @opportunity = create(:opportunity, id: 42, name: "Hello people")
663
-
664
- put :update, params: { id: 42, opportunity: { name: nil }, account: { name: "Test Account" } }, xhr: true
665
- expect(@opportunity.reload.name).to eq("Hello people")
666
- expect(assigns(:opportunity)).to eq(@opportunity)
667
- expect(assigns(:opportunity_stage_total)).to eq(nil)
668
- expect(response).to render_template("opportunities/update")
669
- end
670
-
671
- it "should expose existing account as @account if selected" do
672
- @account = create(:account, id: 99)
673
- @opportunity = create(:opportunity, id: 42)
674
- create(:account_opportunity, account: @account, opportunity: @opportunity)
675
-
676
- put :update, params: { id: 42, opportunity: { name: nil }, account: { id: 99 } }, xhr: true
677
- expect(assigns(:account)).to eq(@account)
678
- end
679
- end
680
- end
681
-
682
- # DELETE /opportunities/1
683
- # DELETE /opportunities/1.xml AJAX
684
- #----------------------------------------------------------------------------
685
- describe "responding to DELETE destroy" do
686
- before do
687
- @opportunity = create(:opportunity, user: current_user)
688
- end
689
-
690
- describe "AJAX request" do
691
- it "should destroy the requested opportunity and render [destroy] template" do
692
- delete :destroy, params: { id: @opportunity.id }, xhr: true
693
-
694
- expect { Opportunity.find(@opportunity.id) }.to raise_error(ActiveRecord::RecordNotFound)
695
- expect(assigns(:opportunity_stage_total)).to eq(nil)
696
- expect(response).to render_template("opportunities/destroy")
697
- end
698
-
699
- describe "when called from Opportunities index page" do
700
- before do
701
- request.env["HTTP_REFERER"] = "http://localhost/opportunities"
702
- end
703
-
704
- it "should get sidebar data if called from opportunities index" do
705
- delete :destroy, params: { id: @opportunity.id }, xhr: true
706
- expect(assigns(:opportunity_stage_total)).to be_an_instance_of(HashWithIndifferentAccess)
707
- end
708
-
709
- it "should try previous page and render index action if current page has no opportunities" do
710
- session[:opportunities_current_page] = 42
711
-
712
- delete :destroy, params: { id: @opportunity.id }, xhr: true
713
- expect(session[:opportunities_current_page]).to eq(41)
714
- expect(response).to render_template("opportunities/index")
715
- end
716
-
717
- it "should render index action when deleting last opportunity" do
718
- session[:opportunities_current_page] = 1
719
-
720
- delete :destroy, params: { id: @opportunity.id }, xhr: true
721
- expect(session[:opportunities_current_page]).to eq(1)
722
- expect(response).to render_template("opportunities/index")
723
- end
724
- end
725
-
726
- describe "when called from related asset page" do
727
- it "should reset current page to 1" do
728
- request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
729
-
730
- delete :destroy, params: { id: @opportunity.id }, xhr: true
731
- expect(session[:opportunities_current_page]).to eq(1)
732
- expect(response).to render_template("opportunities/destroy")
733
- end
734
-
735
- it "should reload campaiign to be able to refresh its summary" do
736
- @account = create(:account)
737
- @opportunity = create(:opportunity, user: current_user, account: @account)
738
- request.env["HTTP_REFERER"] = "http://localhost/accounts/#{@account.id}"
739
-
740
- delete :destroy, params: { id: @opportunity.id }, xhr: true
741
- expect(assigns[:account]).to eq(@account)
742
- expect(response).to render_template("opportunities/destroy")
743
- end
744
-
745
- it "should reload campaiign to be able to refresh its summary" do
746
- @campaign = create(:campaign)
747
- @opportunity = create(:opportunity, user: current_user, campaign: @campaign)
748
- request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
749
-
750
- delete :destroy, params: { id: @opportunity.id }, xhr: true
751
- expect(assigns[:campaign]).to eq(@campaign)
752
- expect(response).to render_template("opportunities/destroy")
753
- end
754
- end
755
-
756
- describe "opportunity got deleted or otherwise unavailable" do
757
- it "should reload current page is the opportunity got deleted" do
758
- @opportunity = create(:opportunity, user: current_user)
759
- @opportunity.destroy
760
-
761
- delete :destroy, params: { id: @opportunity.id }, xhr: true
762
- expect(flash[:warning]).not_to eq(nil)
763
- expect(response.body).to eq("window.location.reload();")
764
- end
765
-
766
- it "should reload current page with the flash message if the opportunity is protected" do
767
- @private = create(:opportunity, user: create(:user), access: "Private")
768
-
769
- delete :destroy, params: { id: @private.id }, xhr: true
770
- expect(flash[:warning]).not_to eq(nil)
771
- expect(response.body).to eq("window.location.reload();")
772
- end
773
- end
774
- end
775
-
776
- describe "HTML request" do
777
- it "should redirect to Opportunities index when an opportunity gets deleted from its landing page" do
778
- delete :destroy, params: { id: @opportunity.id }
779
- expect(flash[:notice]).not_to eq(nil)
780
- expect(response).to redirect_to(opportunities_path)
781
- end
782
-
783
- it "should redirect to opportunity index with the flash message is the opportunity got deleted" do
784
- @opportunity = create(:opportunity, user: current_user)
785
- @opportunity.destroy
786
-
787
- delete :destroy, params: { id: @opportunity.id }
788
- expect(flash[:warning]).not_to eq(nil)
789
- expect(response).to redirect_to(opportunities_path)
790
- end
791
-
792
- it "should redirect to opportunity index with the flash message if the opportunity is protected" do
793
- @private = create(:opportunity, user: create(:user), access: "Private")
794
-
795
- delete :destroy, params: { id: @private.id }
796
- expect(flash[:warning]).not_to eq(nil)
797
- expect(response).to redirect_to(opportunities_path)
798
- end
799
- end
800
- end
801
-
802
- # PUT /opportunities/1/attach
803
- # PUT /opportunities/1/attach.xml AJAX
804
- #----------------------------------------------------------------------------
805
- describe "responding to PUT attach" do
806
- describe "tasks" do
807
- before do
808
- @model = create(:opportunity)
809
- @attachment = create(:task, asset: nil)
810
- end
811
- it_should_behave_like("attach")
812
- end
813
-
814
- describe "contacts" do
815
- before do
816
- @model = create(:opportunity)
817
- @attachment = create(:contact)
818
- end
819
- it_should_behave_like("attach")
820
- end
821
- end
822
-
823
- # POST /opportunities/1/discard
824
- # POST /opportunities/1/discard.xml AJAX
825
- #----------------------------------------------------------------------------
826
- describe "responding to POST discard" do
827
- describe "tasks" do
828
- before do
829
- @model = create(:opportunity)
830
- @attachment = create(:task, asset: @model)
831
- end
832
- it_should_behave_like("discard")
833
- end
834
-
835
- describe "contacts" do
836
- before do
837
- @attachment = create(:contact)
838
- @model = create(:opportunity)
839
- @model.contacts << @attachment
840
- end
841
- it_should_behave_like("discard")
842
- end
843
- end
844
-
845
- # POST /opportunities/auto_complete/query AJAX
846
- #----------------------------------------------------------------------------
847
- describe "responding to POST auto_complete" do
848
- before do
849
- @auto_complete_matches = [create(:opportunity, name: "Hello World", user: current_user)]
850
- end
851
-
852
- it_should_behave_like("auto complete")
853
- end
854
-
855
- # GET /opportunities/redraw AJAX
856
- #----------------------------------------------------------------------------
857
- describe "responding to GET redraw" do
858
- it "should save user selected opportunity preference" do
859
- get :redraw, params: { per_page: 42, view: "brief", sort_by: "name" }, xhr: true
860
- expect(current_user.preference[:opportunities_per_page]).to eq(42)
861
- expect(current_user.preference[:opportunities_index_view]).to eq("brief")
862
- expect(current_user.preference[:opportunities_sort_by]).to eq("opportunities.name ASC")
863
- end
864
-
865
- it "should reset current page to 1" do
866
- get :redraw, params: { per_page: 42, view: "brief", sort_by: "name" }, xhr: true
867
- expect(session[:opportunities_current_page]).to eq(1)
868
- end
869
-
870
- it "should select @opportunities and render [index] template" do
871
- @opportunities = [
872
- create(:opportunity, name: "A", user: current_user),
873
- create(:opportunity, name: "B", user: current_user)
874
- ]
875
-
876
- get :redraw, params: { per_page: 1, sort_by: "name" }, xhr: true
877
- expect(assigns(:opportunities)).to eq([@opportunities.first])
878
- expect(response).to render_template("opportunities/index")
879
- end
880
- end
881
-
882
- # POST /opportunities/filter AJAX
883
- #----------------------------------------------------------------------------
884
- describe "responding to GET filter" do
885
- it "should expose filtered opportunities as @opportunity and render [filter] template" do
886
- session[:opportunities_filter] = "negotiation,analysis"
887
- @opportunities = [create(:opportunity, stage: "prospecting", user: current_user)]
888
- @stage = Setting.unroll(:opportunity_stage)
889
-
890
- get :filter, params: { stage: "prospecting" }, xhr: true
891
- expect(assigns(:opportunities)).to eq(@opportunities)
892
- expect(assigns[:stage]).to eq(@stage)
893
- expect(response).to be_successful
894
- expect(response).to render_template("opportunities/index")
895
- end
896
-
897
- it "should reset current page to 1" do
898
- @opportunities = []
899
- get :filter, params: { status: "new" }, xhr: true
900
-
901
- expect(session[:opportunities_current_page]).to eq(1)
902
- end
903
- end
904
- end