fat_free_crm 0.20.0 → 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 +2 -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 +2 -2
  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,607 +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 AccountsController do
11
- def get_data_for_sidebar
12
- @category = Setting.account_category.dup
13
- end
14
-
15
- before do
16
- login
17
- set_current_tab(:accounts)
18
- end
19
-
20
- # GET /accounts
21
- # GET /accounts.xml
22
- #----------------------------------------------------------------------------
23
- describe "responding to GET index" do
24
- before(:each) do
25
- get_data_for_sidebar
26
- end
27
-
28
- it "should expose all accounts as @accounts and render [index] template" do
29
- @accounts = [create(:account, user: current_user)]
30
- get :index
31
- expect(assigns[:accounts]).to eq(@accounts)
32
- expect(response).to render_template("accounts/index")
33
- end
34
-
35
- it "should collect the data for the accounts sidebar" do
36
- @accounts = [create(:account, user: current_user)]
37
-
38
- get :index
39
- expect(assigns[:account_category_total].keys.map(&:to_sym) - (@category << :all << :other)).to eq([])
40
- end
41
-
42
- it "should filter out accounts by category" do
43
- categories = %w[customer vendor]
44
- controller.session[:accounts_filter] = categories.join(',')
45
- @accounts = [
46
- create(:account, user: current_user, category: categories.first),
47
- create(:account, user: current_user, category: categories.last)
48
- ]
49
- # This one should be filtered out.
50
- create(:account, user: current_user, category: "competitor")
51
-
52
- get :index
53
- expect(assigns[:accounts]).to eq(@accounts)
54
- end
55
-
56
- it "should perform lookup using query string" do
57
- @first = create(:account, user: current_user, name: "The first one")
58
- @second = create(:account, user: current_user, name: "The second one")
59
-
60
- get :index, params: { query: "second" }
61
- expect(assigns[:accounts]).to eq([@second])
62
- expect(assigns[:current_query]).to eq("second")
63
- expect(session[:accounts_current_query]).to eq("second")
64
- end
65
-
66
- describe "AJAX pagination" do
67
- it "should pick up page number from params" do
68
- @accounts = [create(:account, user: current_user)]
69
- get :index, params: { page: 42 }, xhr: true
70
-
71
- expect(assigns[:current_page].to_i).to eq(42)
72
- expect(assigns[:accounts]).to eq([]) # page #42 should be empty if there's only one account ;-)
73
- expect(session[:accounts_current_page].to_i).to eq(42)
74
- expect(response).to render_template("accounts/index")
75
- end
76
-
77
- it "should pick up saved page number from session" do
78
- session[:accounts_current_page] = 42
79
- @accounts = [create(:account, user: current_user)]
80
- get :index, xhr: true
81
-
82
- expect(assigns[:current_page]).to eq(42)
83
- expect(assigns[:accounts]).to eq([])
84
- expect(response).to render_template("accounts/index")
85
- end
86
-
87
- it "should reset current_page when query is altered" do
88
- session[:accounts_current_page] = 42
89
- session[:accounts_current_query] = "bill"
90
- @accounts = [create(:account, user: current_user)]
91
- get :index, xhr: true
92
-
93
- expect(assigns[:current_page]).to eq(1)
94
- expect(assigns[:accounts]).to eq(@accounts)
95
- expect(response).to render_template("accounts/index")
96
- end
97
- end
98
-
99
- describe "with mime type of JSON" do
100
- it "should render all accounts as json" do
101
- expect(@controller).to receive(:get_accounts).and_return(accounts = double("Array of Accounts"))
102
- expect(accounts).to receive(:to_json).and_return("generated JSON")
103
-
104
- request.env["HTTP_ACCEPT"] = "application/json"
105
- get :index
106
- expect(response.body).to eq("generated JSON")
107
- end
108
- end
109
-
110
- describe "with mime type of XML" do
111
- it "should render all accounts as xml" do
112
- expect(@controller).to receive(:get_accounts).and_return(accounts = double("Array of Accounts"))
113
- expect(accounts).to receive(:to_xml).and_return("generated XML")
114
-
115
- request.env["HTTP_ACCEPT"] = "application/xml"
116
- get :index
117
- expect(response.body).to eq("generated XML")
118
- end
119
- end
120
- end
121
-
122
- # GET /accounts/1
123
- # GET /accounts/1.xml HTML
124
- #----------------------------------------------------------------------------
125
- describe "responding to GET show" do
126
- describe "with mime type of HTML" do
127
- before do
128
- @account = create(:account, user: current_user)
129
- @stage = Setting.unroll(:opportunity_stage)
130
- @comment = Comment.new
131
- end
132
-
133
- it "should expose the requested account as @account and render [show] template" do
134
- get :show, params: { id: @account.id }
135
- expect(assigns[:account]).to eq(@account)
136
- expect(assigns[:stage]).to eq(@stage)
137
- expect(assigns[:comment].attributes).to eq(@comment.attributes)
138
- expect(response).to render_template("accounts/show")
139
- end
140
-
141
- it "should update an activity when viewing the account" do
142
- get :show, params: { id: @account.id }
143
- expect(@account.versions.last.event).to eq('view')
144
- end
145
- end
146
-
147
- describe "with mime type of JSON" do
148
- it "should render the requested account as json" do
149
- @account = create(:account, user: current_user)
150
- expect(Account).to receive(:find).and_return(@account)
151
- expect(@account).to receive(:to_json).and_return("generated JSON")
152
-
153
- request.env["HTTP_ACCEPT"] = "application/json"
154
- get :show, params: { id: 42 }
155
- expect(response.body).to eq("generated JSON")
156
- end
157
- end
158
-
159
- describe "with mime type of XML" do
160
- it "should render the requested account as xml" do
161
- @account = create(:account, user: current_user)
162
- expect(Account).to receive(:find).and_return(@account)
163
- expect(@account).to receive(:to_xml).and_return("generated XML")
164
-
165
- request.env["HTTP_ACCEPT"] = "application/xml"
166
- get :show, params: { id: 42 }
167
- expect(response.body).to eq("generated XML")
168
- end
169
- end
170
-
171
- describe "account got deleted or otherwise unavailable" do
172
- it "should redirect to account index if the account got deleted" do
173
- @account = create(:account, user: current_user)
174
- @account.destroy
175
-
176
- get :show, params: { id: @account.id }
177
- expect(flash[:warning]).not_to eq(nil)
178
- expect(response).to redirect_to(accounts_path)
179
- end
180
-
181
- it "should redirect to account index if the account is protected" do
182
- @private = create(:account, user: create(:user), access: "Private")
183
-
184
- get :show, params: { id: @private.id }
185
- expect(flash[:warning]).not_to eq(nil)
186
- expect(response).to redirect_to(accounts_path)
187
- end
188
-
189
- it "should return 404 (Not Found) JSON error" do
190
- @account = create(:account, user: current_user)
191
- @account.destroy
192
- request.env["HTTP_ACCEPT"] = "application/json"
193
-
194
- get :show, params: { id: @account.id }
195
- expect(response.code).to eq("404") # :not_found
196
- end
197
-
198
- it "should return 404 (Not Found) XML error" do
199
- @account = create(:account, user: current_user)
200
- @account.destroy
201
- request.env["HTTP_ACCEPT"] = "application/xml"
202
-
203
- get :show, params: { id: @account.id }
204
- expect(response.code).to eq("404") # :not_found
205
- end
206
- end
207
- end
208
-
209
- # GET /accounts/new
210
- # GET /accounts/new.xml AJAX
211
- #----------------------------------------------------------------------------
212
- describe "responding to GET new" do
213
- it "should expose a new account as @account and render [new] template" do
214
- @account = Account.new(user: current_user,
215
- access: Setting.default_access)
216
- get :new, xhr: true
217
- expect(assigns[:account].attributes).to eq(@account.attributes)
218
- expect(assigns[:contact]).to eq(nil)
219
- expect(response).to render_template("accounts/new")
220
- end
221
-
222
- it "should created an instance of related object when necessary" do
223
- @contact = create(:contact, id: 42)
224
-
225
- get :new, params: { related: "contact_42" }, xhr: true
226
- expect(assigns[:contact]).to eq(@contact)
227
- end
228
- end
229
-
230
- # GET /accounts/1/edit AJAX
231
- #----------------------------------------------------------------------------
232
- describe "responding to GET edit" do
233
- it "should expose the requested account as @account and render [edit] template" do
234
- @account = create(:account, id: 42, user: current_user)
235
-
236
- get :edit, params: { id: 42 }, xhr: true
237
- expect(assigns[:account]).to eq(@account)
238
- expect(assigns[:previous]).to eq(nil)
239
- expect(response).to render_template("accounts/edit")
240
- end
241
-
242
- it "should expose previous account as @previous when necessary" do
243
- @account = create(:account, id: 42)
244
- @previous = create(:account, id: 41)
245
-
246
- get :edit, params: { id: 42, previous: 41 }, xhr: true
247
- expect(assigns[:previous]).to eq(@previous)
248
- end
249
-
250
- describe "(account got deleted or is otherwise unavailable)" do
251
- it "should reload current page with the flash message if the account got deleted" do
252
- @account = create(:account, user: current_user)
253
- @account.destroy
254
-
255
- get :edit, params: { id: @account.id }, xhr: true
256
- expect(flash[:warning]).not_to eq(nil)
257
- expect(response.body).to eq("window.location.reload();")
258
- end
259
-
260
- it "should reload current page with the flash message if the account is protected" do
261
- @private = create(:account, user: create(:user), access: "Private")
262
-
263
- get :edit, params: { id: @private.id }, xhr: true
264
- expect(flash[:warning]).not_to eq(nil)
265
- expect(response.body).to eq("window.location.reload();")
266
- end
267
- end
268
-
269
- describe "(previous account got deleted or is otherwise unavailable)" do
270
- before do
271
- @account = create(:account, user: current_user)
272
- @previous = create(:account, user: create(:user))
273
- end
274
-
275
- it "should notify the view if previous account got deleted" do
276
- @previous.destroy
277
-
278
- get :edit, params: { id: @account.id, previous: @previous.id }, xhr: true
279
- expect(flash[:warning]).to eq(nil) # no warning, just silently remove the div
280
- expect(assigns[:previous]).to eq(@previous.id)
281
- expect(response).to render_template("accounts/edit")
282
- end
283
-
284
- it "should notify the view if previous account got protected" do
285
- @previous.update_attribute(:access, "Private")
286
-
287
- get :edit, params: { id: @account.id, previous: @previous.id }, xhr: true
288
- expect(flash[:warning]).to eq(nil)
289
- expect(assigns[:previous]).to eq(@previous.id)
290
- expect(response).to render_template("accounts/edit")
291
- end
292
- end
293
- end
294
-
295
- # POST /accounts
296
- # POST /accounts.xml AJAX
297
- #----------------------------------------------------------------------------
298
- describe "responding to POST create" do
299
- describe "with valid params" do
300
- it "should expose a newly created account as @account and render [create] template" do
301
- @account = build(:account, name: "Hello world", user: current_user)
302
- allow(Account).to receive(:new).and_return(@account)
303
-
304
- post :create, params: { account: { name: "Hello world" } }, xhr: true
305
- expect(assigns(:account)).to eq(@account)
306
- expect(response).to render_template("accounts/create")
307
- end
308
-
309
- # Note: [Create Account] is shown only on Accounts index page.
310
- it "should reload accounts to update pagination" do
311
- @account = build(:account, user: current_user)
312
- allow(Account).to receive(:new).and_return(@account)
313
-
314
- post :create, params: { account: { name: "Hello" } }, xhr: true
315
- expect(assigns[:accounts]).to eq([@account])
316
- end
317
-
318
- it "should get data to update account sidebar" do
319
- @account = build(:account, name: "Hello", user: current_user)
320
- allow(Campaign).to receive(:new).and_return(@account)
321
-
322
- post :create, params: { account: { name: "Hello" } }, xhr: true
323
- expect(assigns[:account_category_total]).to be_instance_of(HashWithIndifferentAccess)
324
- end
325
-
326
- it "should add a new comment to the newly created account when specified" do
327
- @account = build(:account, name: "Hello world", user: current_user)
328
- allow(Account).to receive(:new).and_return(@account)
329
-
330
- post :create, params: { account: { name: "Hello world" }, comment_body: "Awesome comment is awesome" }, xhr: true
331
- expect(assigns[:account].comments.map(&:comment)).to include("Awesome comment is awesome")
332
- end
333
- end
334
-
335
- describe "with invalid params" do
336
- it "should expose a newly created but unsaved account as @account and still render [create] template" do
337
- @account = build(:account, name: nil, user: nil)
338
- allow(Account).to receive(:new).and_return(@account)
339
-
340
- post :create, params: { account: {} }, xhr: true
341
- expect(assigns(:account)).to eq(@account)
342
- expect(response).to render_template("accounts/create")
343
- end
344
- end
345
- end
346
-
347
- # PUT /accounts/1
348
- # PUT /accounts/1.xml AJAX
349
- #----------------------------------------------------------------------------
350
- describe "responding to PUT update" do
351
- describe "with valid params" do
352
- it "should update the requested account, expose the requested account as @account, and render [update] template" do
353
- @account = create(:account, id: 42, name: "Hello people")
354
-
355
- put :update, params: { id: 42, account: { name: "Hello world" } }, xhr: true
356
- expect(@account.reload.name).to eq("Hello world")
357
- expect(assigns(:account)).to eq(@account)
358
- expect(response).to render_template("accounts/update")
359
- end
360
-
361
- it "should get data for accounts sidebar when called from Campaigns index" do
362
- @account = create(:account, id: 42)
363
- request.env["HTTP_REFERER"] = "http://localhost/accounts"
364
-
365
- put :update, params: { id: 42, account: { name: "Hello" } }, xhr: true
366
- expect(assigns(:account)).to eq(@account)
367
- expect(assigns[:account_category_total]).to be_instance_of(HashWithIndifferentAccess)
368
- end
369
-
370
- it "should update account permissions when sharing with specific users" do
371
- @account = create(:account, id: 42, access: "Public")
372
-
373
- put :update, params: { id: 42, account: { name: "Hello", access: "Shared", user_ids: [7, 8] } }, xhr: true
374
- expect(assigns[:account].access).to eq("Shared")
375
- expect(assigns[:account].user_ids.sort).to eq([7, 8])
376
- end
377
-
378
- describe "account got deleted or otherwise unavailable" do
379
- it "should reload current page is the account got deleted" do
380
- @account = create(:account, user: current_user)
381
- @account.destroy
382
-
383
- put :update, params: { id: @account.id }, xhr: true
384
- expect(flash[:warning]).not_to eq(nil)
385
- expect(response.body).to eq("window.location.reload();")
386
- end
387
-
388
- it "should reload current page with the flash message if the account is protected" do
389
- @private = create(:account, user: create(:user), access: "Private")
390
-
391
- put :update, params: { id: @private.id }, xhr: true
392
- expect(flash[:warning]).not_to eq(nil)
393
- expect(response.body).to eq("window.location.reload();")
394
- end
395
- end
396
- end
397
-
398
- describe "with invalid params" do
399
- it "should not update the requested account but still expose the requested account as @account, and render [update] template" do
400
- @account = create(:account, id: 42, name: "Hello people")
401
-
402
- put :update, params: { id: 42, account: { name: nil } }, xhr: true
403
- expect(assigns(:account).reload.name).to eq("Hello people")
404
- expect(assigns(:account)).to eq(@account)
405
- expect(response).to render_template("accounts/update")
406
- end
407
- end
408
- end
409
-
410
- # DELETE /accounts/1
411
- # DELETE /accounts/1.xml
412
- #----------------------------------------------------------------------------
413
- describe "responding to DELETE destroy" do
414
- before do
415
- @account = create(:account, user: current_user)
416
- end
417
-
418
- describe "AJAX request" do
419
- it "should destroy the requested account and render [destroy] template" do
420
- @another_account = create(:account, user: current_user)
421
- delete :destroy, params: { id: @account.id }, xhr: true
422
-
423
- expect { Account.find(@account.id) }.to raise_error(ActiveRecord::RecordNotFound)
424
- expect(assigns[:accounts]).to eq([@another_account]) # @account got deleted
425
- expect(response).to render_template("accounts/destroy")
426
- end
427
-
428
- it "should get data for accounts sidebar" do
429
- delete :destroy, params: { id: @account.id }, xhr: true
430
-
431
- expect(assigns[:account_category_total]).to be_instance_of(HashWithIndifferentAccess)
432
- end
433
-
434
- it "should try previous page and render index action if current page has no accounts" do
435
- session[:accounts_current_page] = 42
436
-
437
- delete :destroy, params: { id: @account.id }, xhr: true
438
- expect(session[:accounts_current_page]).to eq(41)
439
- expect(response).to render_template("accounts/index")
440
- end
441
-
442
- it "should render index action when deleting last account" do
443
- session[:accounts_current_page] = 1
444
-
445
- delete :destroy, params: { id: @account.id }, xhr: true
446
- expect(session[:accounts_current_page]).to eq(1)
447
- expect(response).to render_template("accounts/index")
448
- end
449
-
450
- describe "account got deleted or otherwise unavailable" do
451
- it "should reload current page is the account got deleted" do
452
- @account = create(:account, user: current_user)
453
- @account.destroy
454
-
455
- delete :destroy, params: { id: @account.id }, xhr: true
456
- expect(flash[:warning]).not_to eq(nil)
457
- expect(response.body).to eq("window.location.reload();")
458
- end
459
-
460
- it "should reload current page with the flash message if the account is protected" do
461
- @private = create(:account, user: create(:user), access: "Private")
462
-
463
- delete :destroy, params: { id: @private.id }, xhr: true
464
- expect(flash[:warning]).not_to eq(nil)
465
- expect(response.body).to eq("window.location.reload();")
466
- end
467
- end
468
- end
469
-
470
- describe "HTML request" do
471
- it "should redirect to Accounts index when an account gets deleted from its landing page" do
472
- delete :destroy, params: { id: @account.id }
473
-
474
- expect(flash[:notice]).not_to eq(nil)
475
- expect(response).to redirect_to(accounts_path)
476
- end
477
-
478
- it "should redirect to account index with the flash message is the account got deleted" do
479
- @account = create(:account, user: current_user)
480
- @account.destroy
481
-
482
- delete :destroy, params: { id: @account.id }
483
- expect(flash[:warning]).not_to eq(nil)
484
- expect(response).to redirect_to(accounts_path)
485
- end
486
-
487
- it "should redirect to account index with the flash message if the account is protected" do
488
- @private = create(:account, user: create(:user), access: "Private")
489
-
490
- delete :destroy, params: { id: @private.id }
491
- expect(flash[:warning]).not_to eq(nil)
492
- expect(response).to redirect_to(accounts_path)
493
- end
494
- end
495
- end
496
-
497
- # PUT /accounts/1/attach
498
- # PUT /accounts/1/attach.xml AJAX
499
- #----------------------------------------------------------------------------
500
- describe "responding to PUT attach" do
501
- describe "tasks" do
502
- before do
503
- @model = create(:account)
504
- @attachment = create(:task, asset: nil)
505
- end
506
- it_should_behave_like("attach")
507
- end
508
-
509
- describe "contacts" do
510
- before do
511
- @model = create(:account)
512
- @attachment = create(:contact, account: nil)
513
- end
514
- it_should_behave_like("attach")
515
- end
516
- end
517
-
518
- # POST /accounts/1/discard
519
- # POST /accounts/1/discard.xml AJAX
520
- #----------------------------------------------------------------------------
521
- describe "responding to POST discard" do
522
- describe "tasks" do
523
- before do
524
- @model = create(:account)
525
- @attachment = create(:task, asset: @model)
526
- end
527
- it_should_behave_like("discard")
528
- end
529
-
530
- describe "contacts" do
531
- before do
532
- @attachment = create(:contact)
533
- @model = create(:account)
534
- @model.contacts << @attachment
535
- end
536
- it_should_behave_like("discard")
537
- end
538
-
539
- describe "opportunities" do
540
- before do
541
- @attachment = create(:opportunity)
542
- @model = create(:account)
543
- @model.opportunities << @attachment
544
- end
545
- # 'super from singleton method that is defined to multiple classes is not supported;'
546
- # TODO: Uncomment this when it is fixed in 1.9.3
547
- # it_should_behave_like("discard")
548
- end
549
- end
550
-
551
- # POST /accounts/auto_complete/query AJAX
552
- #----------------------------------------------------------------------------
553
- describe "responding to POST auto_complete" do
554
- before do
555
- @auto_complete_matches = [create(:account, name: "Hello World", user: current_user)]
556
- end
557
-
558
- it_should_behave_like("auto complete")
559
- end
560
-
561
- # GET /accounts/redraw AJAX
562
- #----------------------------------------------------------------------------
563
- describe "responding to GET redraw" do
564
- it "should save user selected account preference" do
565
- get :redraw, params: { per_page: 42, view: "brief", sort_by: "name" }, xhr: true
566
- expect(current_user.preference[:accounts_per_page]).to eq(42)
567
- expect(current_user.preference[:accounts_index_view]).to eq("brief")
568
- expect(current_user.preference[:accounts_sort_by]).to eq("accounts.name ASC")
569
- end
570
-
571
- it "should reset current page to 1" do
572
- get :redraw, params: { per_page: 42, view: "brief", sort_by: "name" }, xhr: true
573
- expect(session[:accounts_current_page]).to eq(1)
574
- end
575
-
576
- it "should select @accounts and render [index] template" do
577
- @accounts = [
578
- create(:account, name: "A", user: current_user),
579
- create(:account, name: "B", user: current_user)
580
- ]
581
-
582
- get :redraw, params: { per_page: 1, sort_by: "name" }, xhr: true
583
- expect(assigns(:accounts)).to eq([@accounts.first])
584
- expect(response).to render_template("accounts/index")
585
- end
586
- end
587
-
588
- # POST /accounts/filter AJAX
589
- #----------------------------------------------------------------------------
590
- describe "responding to POST filter" do
591
- it "should expose filtered accounts as @accounts and render [index] template" do
592
- session[:accounts_filter] = "customer,vendor"
593
- @accounts = [create(:account, category: "partner", user: current_user)]
594
-
595
- post :filter, params: { category: "partner" }, xhr: true
596
- expect(assigns(:accounts)).to eq(@accounts)
597
- expect(response).to render_template("accounts/index")
598
- end
599
-
600
- it "should reset current page to 1" do
601
- @accounts = []
602
- post :filter, params: { category: "partner" }, xhr: true
603
-
604
- expect(session[:accounts_current_page]).to eq(1)
605
- end
606
- end
607
- end