fat_free_crm 0.15.0.beta.2 → 0.15.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 (225) hide show
  1. checksums.yaml +4 -4
  2. data/.docker/nginx/sites-enabled/ffcrm.conf +8 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +4 -1
  5. data/.rubocop_todo.yml +190 -89
  6. data/.travis.yml +10 -3
  7. data/CHANGELOG.md +27 -0
  8. data/{CONTRIBUTORS → CONTRIBUTORS.md} +2 -1
  9. data/Dockerfile +15 -13
  10. data/Gemfile +7 -4
  11. data/Gemfile.lock +200 -167
  12. data/README.md +4 -2
  13. data/app/assets/javascripts/crm_sortable.js.coffee +5 -0
  14. data/app/assets/javascripts/timeago.js.coffee +5 -0
  15. data/app/assets/stylesheets/about.css.scss +5 -0
  16. data/app/assets/stylesheets/common.scss +2 -1
  17. data/app/controllers/admin/fields_controller.rb +1 -1
  18. data/app/controllers/admin/groups_controller.rb +5 -1
  19. data/app/controllers/admin/tags_controller.rb +1 -1
  20. data/app/controllers/admin/users_controller.rb +10 -6
  21. data/app/controllers/application_controller.rb +13 -13
  22. data/app/controllers/authentications_controller.rb +2 -2
  23. data/app/controllers/comments_controller.rb +3 -2
  24. data/app/controllers/entities/contacts_controller.rb +9 -7
  25. data/app/controllers/entities/opportunities_controller.rb +1 -1
  26. data/app/controllers/entities_controller.rb +4 -4
  27. data/app/controllers/home_controller.rb +9 -9
  28. data/app/controllers/passwords_controller.rb +1 -1
  29. data/app/controllers/tasks_controller.rb +2 -1
  30. data/app/controllers/users_controller.rb +4 -2
  31. data/app/helpers/application_helper.rb +9 -9
  32. data/app/helpers/javascript_helper.rb +5 -0
  33. data/app/helpers/opportunities_helper.rb +1 -1
  34. data/app/helpers/remote_link_pagination_helper.rb +5 -0
  35. data/app/inputs/date_pair_input.rb +1 -1
  36. data/app/models/entities/account.rb +2 -2
  37. data/app/models/entities/account_contact.rb +1 -1
  38. data/app/models/entities/campaign.rb +3 -3
  39. data/app/models/entities/contact.rb +3 -3
  40. data/app/models/entities/lead.rb +2 -2
  41. data/app/models/entities/opportunity.rb +3 -3
  42. data/app/models/fields/custom_field.rb +1 -1
  43. data/app/models/fields/custom_field_pair.rb +2 -2
  44. data/app/models/fields/field.rb +1 -1
  45. data/app/models/polymorphic/address.rb +2 -2
  46. data/app/models/polymorphic/avatar.rb +4 -2
  47. data/app/models/polymorphic/email.rb +8 -6
  48. data/app/models/polymorphic/task.rb +3 -1
  49. data/app/models/polymorphic/version.rb +3 -3
  50. data/app/models/users/ability.rb +1 -1
  51. data/app/models/users/permission.rb +2 -0
  52. data/app/models/users/user.rb +2 -2
  53. data/app/views/accounts/index.js.haml +1 -1
  54. data/app/views/admin/fields/_sort_by.html.haml +1 -1
  55. data/app/views/admin/users/_user.html.haml +1 -1
  56. data/app/views/campaigns/index.js.haml +1 -1
  57. data/app/views/contacts/index.js.haml +1 -1
  58. data/app/views/entities/_basic_search.html.haml +1 -1
  59. data/app/views/home/_duration_menu.html.haml +1 -1
  60. data/app/views/home/_events_menu.html.haml +1 -1
  61. data/app/views/home/_users_menu.html.haml +1 -1
  62. data/app/views/layouts/application.html.haml +1 -1
  63. data/app/views/leads/index.js.haml +1 -1
  64. data/app/views/opportunities/index.js.haml +1 -1
  65. data/app/views/shared/_naming.html.haml +1 -1
  66. data/app/views/users/_languages.html.haml +1 -1
  67. data/config/application.rb +2 -3
  68. data/config/boot.rb +2 -0
  69. data/config/deploy.example.rb +1 -1
  70. data/config/environments/development.rb +2 -0
  71. data/config/environments/production.rb +1 -1
  72. data/config/environments/test.rb +2 -2
  73. data/config/initializers/assets.rb +6 -1
  74. data/config/initializers/backtrace_silencers.rb +5 -0
  75. data/config/initializers/constants.rb +1 -1
  76. data/config/initializers/cookies_serializer.rb +5 -0
  77. data/config/initializers/custom_field_ransack_translations.rb +5 -0
  78. data/config/initializers/filter_parameter_logging.rb +5 -0
  79. data/config/initializers/inflections.rb +5 -0
  80. data/config/initializers/paper_trail.rb +5 -0
  81. data/config/initializers/ransack.rb +3 -3
  82. data/config/initializers/session_store.rb +5 -0
  83. data/config/initializers/wrap_parameters.rb +5 -0
  84. data/config/locales/et.yml +207 -0
  85. data/config/locales/et_fat_free_crm.yml +928 -0
  86. data/config/locales/pt-BR_ransack.yml +81 -0
  87. data/config/locales/th.rb +1 -1
  88. data/config/routes.rb +18 -18
  89. data/db/migrate/20100928030598_create_sessions.rb +1 -1
  90. data/db/migrate/20100928030599_create_users.rb +2 -2
  91. data/db/migrate/20100928030600_create_openid_tables.rb +1 -1
  92. data/db/migrate/20100928030601_create_accounts.rb +2 -2
  93. data/db/migrate/20100928030602_create_permissions.rb +1 -1
  94. data/db/migrate/20100928030603_create_settings.rb +1 -1
  95. data/db/migrate/20100928030604_create_preferences.rb +2 -2
  96. data/db/migrate/20100928030605_create_campaigns.rb +2 -2
  97. data/db/migrate/20100928030606_create_leads.rb +2 -2
  98. data/db/migrate/20100928030607_create_contacts.rb +2 -2
  99. data/db/migrate/20100928030608_create_opportunities.rb +2 -2
  100. data/db/migrate/20100928030609_create_account_contacts.rb +1 -1
  101. data/db/migrate/20100928030610_create_account_opportunities.rb +1 -1
  102. data/db/migrate/20100928030611_create_contact_opportunities.rb +1 -1
  103. data/db/migrate/20100928030612_create_tasks.rb +2 -2
  104. data/db/migrate/20100928030613_create_comments.rb +1 -1
  105. data/db/migrate/20100928030614_create_activities.rb +1 -1
  106. data/db/migrate/20100928030615_create_avatars.rb +1 -1
  107. data/db/migrate/20100928030616_rename_remember_token.rb +1 -1
  108. data/db/migrate/20100928030617_drop_openid_tables.rb +1 -1
  109. data/db/migrate/20100928030618_add_admin_to_users.rb +1 -1
  110. data/db/migrate/20100928030619_add_suspended_to_users.rb +1 -1
  111. data/db/migrate/20100928030620_remove_uuid.rb +2 -2
  112. data/db/migrate/20100928030621_add_email_to_accounts.rb +1 -1
  113. data/db/migrate/20100928030622_add_background_info_to_models.rb +1 -1
  114. data/db/migrate/20100928030623_create_addresses.rb +2 -2
  115. data/db/migrate/20100928030624_add_index_on_permissions.rb +3 -3
  116. data/db/migrate/20100928030625_create_emails.rb +2 -2
  117. data/db/migrate/20100928030626_add_state_to_timeline_objects.rb +1 -1
  118. data/db/migrate/20100928030627_acts_as_taggable_on_migration.rb +2 -2
  119. data/db/migrate/20101221123456_add_single_access_token_to_users.rb +1 -1
  120. data/db/migrate/20101221345678_add_rating_and_category_to_accounts.rb +1 -1
  121. data/db/migrate/20110719082054_add_skype_to_contacts_and_leads.rb +1 -1
  122. data/db/migrate/20111101083437_create_fields.rb +1 -1
  123. data/db/migrate/20111101090312_create_field_groups.rb +1 -1
  124. data/db/migrate/20111116091952_add_field_groups_tag_id.rb +1 -1
  125. data/db/migrate/20111117041311_change_fields_collection_to_text.rb +1 -1
  126. data/db/migrate/20111201030535_add_field_groups_klass_name.rb +2 -2
  127. data/db/migrate/20120121054235_create_lists.rb +1 -1
  128. data/db/migrate/20120216031616_create_versions.rb +3 -3
  129. data/db/migrate/20120216042541_is_paranoid_to_paper_trail.rb +1 -1
  130. data/db/migrate/20120220233724_add_versions_object_changes.rb +1 -1
  131. data/db/migrate/20120224073107_remove_default_value_and_clear_settings.rb +1 -1
  132. data/db/migrate/20120309070209_add_versions_related.rb +1 -1
  133. data/db/migrate/20120314080441_add_subscribed_users_to_entities.rb +2 -2
  134. data/db/migrate/20120316045804_activities_to_versions.rb +1 -1
  135. data/db/migrate/20120405080727_change_subscribed_users_to_set.rb +1 -1
  136. data/db/migrate/20120405080742_change_further_subscribed_users_to_set.rb +2 -2
  137. data/db/migrate/20120406082136_create_groups.rb +2 -2
  138. data/db/migrate/20120413034923_add_index_on_versions_item_type.rb +1 -1
  139. data/db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb +3 -3
  140. data/db/migrate/20120528102124_increase_length_of_version_events.rb +1 -1
  141. data/db/migrate/20120801032706_add_pair_id_to_fields.rb +1 -1
  142. data/db/migrate/20121003063155_add_settings_to_custom_fields.rb +1 -1
  143. data/db/migrate/20121221033947_fix_country_mapping.rb +1 -1
  144. data/db/migrate/20131207033244_add_user_id_to_lists.rb +1 -1
  145. data/db/migrate/20140916011927_add_created_at_index_on_versions.rb +1 -1
  146. data/db/migrate/20140916012922_add_indexes_to_model_associations.rb +3 -3
  147. data/db/migrate/20141126031837_increase_email_to254_chars.rb +1 -1
  148. data/db/migrate/20141230021159_add_transaction_id_column_to_versions.rb +1 -1
  149. data/db/migrate/20141230205453_add_missing_unique_indices.acts_as_taggable_on_engine.rb +4 -4
  150. data/db/migrate/20141230205454_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +1 -1
  151. data/db/migrate/20141230205455_add_missing_taggable_index.acts_as_taggable_on_engine.rb +3 -3
  152. data/db/migrate/20150123060900_convert_radio_to_radio_buttons.rb +1 -1
  153. data/db/migrate/20150227123054_remove_last_request_at_from_users.rb +1 -1
  154. data/db/migrate/20150427131956_create_index_related_type.rb +3 -3
  155. data/db/migrate/20160511053730_add_account_contacts_index.rb +2 -2
  156. data/docker-compose.yml +17 -13
  157. data/fat_free_crm.gemspec +4 -6
  158. data/lib/development_tasks/license.rake +12 -9
  159. data/lib/fat_free_crm/callback.rb +4 -4
  160. data/lib/fat_free_crm/engine.rb +2 -2
  161. data/lib/fat_free_crm/exportable.rb +2 -2
  162. data/lib/fat_free_crm/fields.rb +2 -4
  163. data/lib/fat_free_crm/gem_ext.rb +0 -1
  164. data/lib/fat_free_crm/gem_ext/rake/task.rb +2 -0
  165. data/lib/fat_free_crm/mail_processor/base.rb +4 -4
  166. data/lib/fat_free_crm/mail_processor/dropbox.rb +1 -1
  167. data/lib/fat_free_crm/permissions.rb +5 -5
  168. data/lib/fat_free_crm/sortable.rb +1 -1
  169. data/lib/fat_free_crm/version.rb +1 -1
  170. data/lib/gravatar_image_tag.rb +1 -0
  171. data/lib/tasks/ffcrm/demo.rake +2 -2
  172. data/spec/controllers/admin/users_controller_spec.rb +25 -25
  173. data/spec/controllers/authentications_controller_spec.rb +9 -9
  174. data/spec/controllers/comments_controller_spec.rb +15 -15
  175. data/spec/controllers/emails_controller_spec.rb +2 -2
  176. data/spec/controllers/entities/accounts_controller_spec.rb +46 -46
  177. data/spec/controllers/entities/campaigns_controller_spec.rb +46 -46
  178. data/spec/controllers/entities/contacts_controller_spec.rb +55 -55
  179. data/spec/controllers/entities/leads_controller_spec.rb +85 -85
  180. data/spec/controllers/entities/opportunities_controller_spec.rb +74 -74
  181. data/spec/controllers/home_controller_spec.rb +11 -11
  182. data/spec/controllers/passwords_controller_spec.rb +2 -2
  183. data/spec/controllers/tasks_controller_spec.rb +37 -37
  184. data/spec/controllers/users_controller_spec.rb +31 -31
  185. data/spec/factories/campaign_factories.rb +1 -1
  186. data/spec/factories/contact_factories.rb +1 -1
  187. data/spec/factories/field_factories.rb +1 -1
  188. data/spec/factories/lead_factories.rb +2 -2
  189. data/spec/factories/opportunity_factories.rb +3 -3
  190. data/spec/factories/shared_factories.rb +1 -1
  191. data/spec/factories/task_factories.rb +1 -1
  192. data/spec/features/support/browser.rb +9 -1
  193. data/spec/lib/fields_spec.rb +2 -2
  194. data/spec/lib/permissions_spec.rb +38 -6
  195. data/spec/lib/view_factory_spec.rb +2 -2
  196. data/spec/models/fields/custom_field_spec.rb +3 -3
  197. data/spec/models/observers/entity_observer_spec.rb +1 -1
  198. data/spec/models/polymorphic/version_spec.rb +11 -11
  199. data/spec/models/users/abilities/user_ability_spec.rb +8 -3
  200. data/spec/models/users/permission_spec.rb +8 -0
  201. data/spec/models/users/user_spec.rb +1 -1
  202. data/spec/shared/controllers.rb +10 -10
  203. data/spec/spec_helper.rb +1 -1
  204. data/spec/views/accounts/index.haml_spec.rb +1 -1
  205. data/spec/views/accounts/update.js.haml_spec.rb +2 -2
  206. data/spec/views/admin/users/update.js.haml_spec.rb +2 -2
  207. data/spec/views/application/auto_complete.haml_spec.rb +1 -1
  208. data/spec/views/campaigns/index.haml_spec.rb +1 -1
  209. data/spec/views/campaigns/update.js.haml_spec.rb +2 -2
  210. data/spec/views/contacts/index.haml_spec.rb +1 -1
  211. data/spec/views/contacts/update.js.haml_spec.rb +2 -2
  212. data/spec/views/home/options.js.haml_spec.rb +1 -1
  213. data/spec/views/leads/index.haml_spec.rb +1 -1
  214. data/spec/views/leads/promote.js.haml_spec.rb +2 -2
  215. data/spec/views/leads/update.js.haml_spec.rb +2 -2
  216. data/spec/views/opportunities/index.haml_spec.rb +1 -1
  217. data/spec/views/opportunities/update.js.haml_spec.rb +1 -1
  218. data/spec/views/tasks/_edit.haml_spec.rb +2 -2
  219. data/spec/views/tasks/create.js.haml_spec.rb +2 -2
  220. data/spec/views/tasks/edit.js.haml_spec.rb +1 -1
  221. data/spec/views/users/change_password.js.haml_spec.rb +2 -2
  222. data/spec/views/users/update.js.haml_spec.rb +2 -2
  223. data/spec/views/users/upload_avatar.js.haml_spec.rb +2 -2
  224. metadata +17 -20
  225. data/lib/fat_free_crm/gem_ext/active_record/schema_dumper.rb +0 -27
@@ -49,14 +49,14 @@ describe OpportunitiesController do
49
49
  get :index
50
50
  # Note: can't compare opportunities directly because of BigDecimal objects.
51
51
  expect(assigns[:opportunities].size).to eq(2)
52
- expect(assigns[:opportunities].map(&:stage).sort).to eq(%w(negotiation prospecting))
52
+ expect(assigns[:opportunities].map(&:stage).sort).to eq(%w[negotiation prospecting])
53
53
  end
54
54
 
55
55
  it "should perform lookup using query string" do
56
56
  @first = FactoryGirl.create(:opportunity, user: current_user, name: "The first one")
57
57
  @second = FactoryGirl.create(:opportunity, user: current_user, name: "The second one")
58
58
 
59
- get :index, query: "second"
59
+ get :index, params: { query: "second" }
60
60
  expect(assigns[:opportunities]).to eq([@second])
61
61
  expect(assigns[:current_query]).to eq("second")
62
62
  expect(session[:opportunities_current_query]).to eq("second")
@@ -65,7 +65,7 @@ describe OpportunitiesController do
65
65
  describe "AJAX pagination" do
66
66
  it "should pick up page number from params" do
67
67
  @opportunities = [FactoryGirl.create(:opportunity, user: current_user)]
68
- xhr :get, :index, page: 42
68
+ get :index, params: { page: 42 }, xhr: true
69
69
 
70
70
  expect(assigns[:current_page].to_i).to eq(42)
71
71
  expect(assigns[:opportunities]).to eq([]) # page #42 should be empty if there's only one opportunity ;-)
@@ -76,7 +76,7 @@ describe OpportunitiesController do
76
76
  it "should pick up saved page number from session" do
77
77
  session[:opportunities_current_page] = 42
78
78
  @opportunities = [FactoryGirl.create(:opportunity, user: current_user)]
79
- xhr :get, :index
79
+ get :index, xhr: true
80
80
 
81
81
  expect(assigns[:current_page]).to eq(42)
82
82
  expect(assigns[:opportunities]).to eq([])
@@ -87,7 +87,7 @@ describe OpportunitiesController do
87
87
  session[:opportunities_current_page] = 42
88
88
  session[:opportunities_current_query] = "bill"
89
89
  @opportunities = [FactoryGirl.create(:opportunity, user: current_user)]
90
- xhr :get, :index
90
+ get :index, xhr: true
91
91
 
92
92
  expect(assigns[:current_page]).to eq(1)
93
93
  expect(assigns[:opportunities]).to eq(@opportunities)
@@ -141,7 +141,7 @@ describe OpportunitiesController do
141
141
  end
142
142
 
143
143
  it "should expose the requested opportunity as @opportunity and render [show] template" do
144
- get :show, id: 42
144
+ get :show, params: { id: 42 }
145
145
  expect(assigns[:opportunity]).to eq(@opportunity)
146
146
  expect(assigns[:stage]).to eq(@stage)
147
147
  expect(assigns[:comment].attributes).to eq(@comment.attributes)
@@ -149,7 +149,7 @@ describe OpportunitiesController do
149
149
  end
150
150
 
151
151
  it "should update an activity when viewing the opportunity" do
152
- get :show, id: @opportunity.id
152
+ get :show, params: { id: @opportunity.id }
153
153
  expect(@opportunity.versions.last.event).to eq('view')
154
154
  end
155
155
  end
@@ -161,7 +161,7 @@ describe OpportunitiesController do
161
161
  expect(@opportunity).to receive(:to_json).and_return("generated JSON")
162
162
 
163
163
  request.env["HTTP_ACCEPT"] = "application/json"
164
- get :show, id: 42
164
+ get :show, params: { id: 42 }
165
165
  expect(response.body).to eq("generated JSON")
166
166
  end
167
167
  end
@@ -173,7 +173,7 @@ describe OpportunitiesController do
173
173
  expect(@opportunity).to receive(:to_xml).and_return("generated XML")
174
174
 
175
175
  request.env["HTTP_ACCEPT"] = "application/xml"
176
- get :show, id: 42
176
+ get :show, params: { id: 42 }
177
177
  expect(response.body).to eq("generated XML")
178
178
  end
179
179
  end
@@ -183,7 +183,7 @@ describe OpportunitiesController do
183
183
  @opportunity = FactoryGirl.create(:opportunity, user: current_user)
184
184
  @opportunity.destroy
185
185
 
186
- get :show, id: @opportunity.id
186
+ get :show, params: { id: @opportunity.id }
187
187
  expect(flash[:warning]).not_to eq(nil)
188
188
  expect(response).to redirect_to(opportunities_path)
189
189
  end
@@ -191,7 +191,7 @@ describe OpportunitiesController do
191
191
  it "should redirect to opportunity index if the opportunity is protected" do
192
192
  @private = FactoryGirl.create(:opportunity, user: FactoryGirl.create(:user), access: "Private")
193
193
 
194
- get :show, id: @private.id
194
+ get :show, params: { id: @private.id }
195
195
  expect(flash[:warning]).not_to eq(nil)
196
196
  expect(response).to redirect_to(opportunities_path)
197
197
  end
@@ -201,7 +201,7 @@ describe OpportunitiesController do
201
201
  @opportunity.destroy
202
202
  request.env["HTTP_ACCEPT"] = "application/json"
203
203
 
204
- get :show, id: @opportunity.id
204
+ get :show, params: { id: @opportunity.id }
205
205
  expect(response.code).to eq("404") # :not_found
206
206
  end
207
207
 
@@ -210,7 +210,7 @@ describe OpportunitiesController do
210
210
  @opportunity.destroy
211
211
  request.env["HTTP_ACCEPT"] = "application/xml"
212
212
 
213
- get :show, id: @opportunity.id
213
+ get :show, params: { id: @opportunity.id }
214
214
  expect(response.code).to eq("404") # :not_found
215
215
  end
216
216
  end
@@ -225,7 +225,7 @@ describe OpportunitiesController do
225
225
  @account = Account.new(user: current_user, access: Setting.default_access)
226
226
  @accounts = [FactoryGirl.create(:account, user: current_user)]
227
227
 
228
- xhr :get, :new
228
+ get :new, xhr: true
229
229
  expect(assigns[:opportunity].attributes).to eq(@opportunity.attributes)
230
230
  expect(assigns[:account].attributes).to eq(@account.attributes)
231
231
  expect(assigns[:accounts]).to eq(@accounts)
@@ -235,7 +235,7 @@ describe OpportunitiesController do
235
235
  it "should created an instance of related object when necessary" do
236
236
  @contact = FactoryGirl.create(:contact, id: 42)
237
237
 
238
- xhr :get, :new, related: "contact_42"
238
+ get :new, params: { related: "contact_42" }, xhr: true
239
239
  expect(assigns[:contact]).to eq(@contact)
240
240
  end
241
241
 
@@ -244,7 +244,7 @@ describe OpportunitiesController do
244
244
  @account = FactoryGirl.create(:account)
245
245
  @account.destroy
246
246
 
247
- xhr :get, :new, related: "account_#{@account.id}"
247
+ get :new, params: { related: "account_#{@account.id}" }, xhr: true
248
248
  expect(flash[:warning]).not_to eq(nil)
249
249
  expect(response.body).to eq('window.location.href = "/accounts";')
250
250
  end
@@ -252,7 +252,7 @@ describe OpportunitiesController do
252
252
  it "should redirect to parent asset's index page with the message if parent asset got protected" do
253
253
  @account = FactoryGirl.create(:account, access: "Private")
254
254
 
255
- xhr :get, :new, related: "account_#{@account.id}"
255
+ get :new, params: { related: "account_#{@account.id}" }, xhr: true
256
256
  expect(flash[:warning]).not_to eq(nil)
257
257
  expect(response.body).to eq('window.location.href = "/accounts";')
258
258
  end
@@ -271,7 +271,7 @@ describe OpportunitiesController do
271
271
  @stage = Setting.unroll(:opportunity_stage)
272
272
  @accounts = [@account]
273
273
 
274
- xhr :get, :edit, id: 42
274
+ get :edit, params: { id: 42 }, xhr: true
275
275
  @opportunity.reload
276
276
  expect(assigns[:opportunity]).to eq(@opportunity)
277
277
  expect(assigns[:account].attributes).to eq(@opportunity.account.attributes)
@@ -285,7 +285,7 @@ describe OpportunitiesController do
285
285
  @opportunity = FactoryGirl.create(:opportunity, id: 42)
286
286
  @previous = FactoryGirl.create(:opportunity, id: 41)
287
287
 
288
- xhr :get, :edit, id: 42, previous: 41
288
+ get :edit, params: { id: 42, previous: 41 }, xhr: true
289
289
  expect(assigns[:previous]).to eq(@previous)
290
290
  end
291
291
 
@@ -294,7 +294,7 @@ describe OpportunitiesController do
294
294
  @opportunity = FactoryGirl.create(:opportunity, user: current_user)
295
295
  @opportunity.destroy
296
296
 
297
- xhr :get, :edit, id: @opportunity.id
297
+ get :edit, params: { id: @opportunity.id }, xhr: true
298
298
  expect(flash[:warning]).not_to eq(nil)
299
299
  expect(response.body).to eq("window.location.reload();")
300
300
  end
@@ -302,7 +302,7 @@ describe OpportunitiesController do
302
302
  it "should reload current page with the flash message if the opportunity is protected" do
303
303
  @private = FactoryGirl.create(:opportunity, user: FactoryGirl.create(:user), access: "Private")
304
304
 
305
- xhr :get, :edit, id: @private.id
305
+ get :edit, params: { id: @private.id }, xhr: true
306
306
  expect(flash[:warning]).not_to eq(nil)
307
307
  expect(response.body).to eq("window.location.reload();")
308
308
  end
@@ -317,7 +317,7 @@ describe OpportunitiesController do
317
317
  it "should notify the view if previous opportunity got deleted" do
318
318
  @previous.destroy
319
319
 
320
- xhr :get, :edit, id: @opportunity.id, previous: @previous.id
320
+ get :edit, params: { id: @opportunity.id, previous: @previous.id }, xhr: true
321
321
  expect(flash[:warning]).to eq(nil) # no warning, just silently remove the div
322
322
  expect(assigns[:previous]).to eq(@previous.id)
323
323
  expect(response).to render_template("opportunities/edit")
@@ -326,7 +326,7 @@ describe OpportunitiesController do
326
326
  it "should notify the view if previous opportunity got protected" do
327
327
  @previous.update_attribute(:access, "Private")
328
328
 
329
- xhr :get, :edit, id: @opportunity.id, previous: @previous.id
329
+ get :edit, params: { id: @opportunity.id, previous: @previous.id }, xhr: true
330
330
  expect(flash[:warning]).to eq(nil)
331
331
  expect(assigns[:previous]).to eq(@previous.id)
332
332
  expect(response).to render_template("opportunities/edit")
@@ -346,7 +346,7 @@ describe OpportunitiesController do
346
346
  end
347
347
 
348
348
  it "should expose a newly created opportunity as @opportunity and render [create] template" do
349
- xhr :post, :create, opportunity: { name: "Hello" }, account: { name: "Hello again" }
349
+ post :create, params: { opportunity: { name: "Hello" }, account: { name: "Hello again" } }, xhr: true
350
350
  expect(assigns(:opportunity)).to eq(@opportunity)
351
351
  expect(assigns(:stage)).to eq(@stage)
352
352
  expect(assigns(:opportunity_stage_total)).to be_nil
@@ -355,7 +355,7 @@ describe OpportunitiesController do
355
355
 
356
356
  it "should get sidebar data if called from opportunities index" do
357
357
  request.env["HTTP_REFERER"] = "http://localhost/opportunities"
358
- xhr :post, :create, opportunity: { name: "Hello" }, account: { name: "Hello again" }
358
+ post :create, params: { opportunity: { name: "Hello" }, account: { name: "Hello again" } }, xhr: true
359
359
  expect(assigns(:opportunity_stage_total)).to be_an_instance_of(HashWithIndifferentAccess)
360
360
  end
361
361
 
@@ -363,7 +363,7 @@ describe OpportunitiesController do
363
363
  @account = FactoryGirl.create(:account, user: current_user)
364
364
  request.env["HTTP_REFERER"] = "http://localhost/accounts/#{@account.id}"
365
365
 
366
- xhr :post, :create, opportunity: { name: "Hello" }, account: { id: @account.id }
366
+ post :create, params: { opportunity: { name: "Hello" }, account: { id: @account.id } }, xhr: true
367
367
  expect(assigns(:account)).to eq(@account)
368
368
  end
369
369
 
@@ -371,13 +371,13 @@ describe OpportunitiesController do
371
371
  @campaign = FactoryGirl.create(:campaign, user: current_user)
372
372
  request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
373
373
 
374
- xhr :post, :create, opportunity: { name: "Hello" }, campaign: @campaign.id, account: { name: "Hello again" }
374
+ post :create, params: { opportunity: { name: "Hello" }, campaign: @campaign.id, account: { name: "Hello again" } }, xhr: true
375
375
  expect(assigns(:campaign)).to eq(@campaign)
376
376
  end
377
377
 
378
378
  it "should reload opportunities to update pagination if called from opportunities index" do
379
379
  request.env["HTTP_REFERER"] = "http://localhost/opportunities"
380
- xhr :post, :create, opportunity: { name: "Hello" }, account: { name: "Hello again" }
380
+ post :create, params: { opportunity: { name: "Hello" }, account: { name: "Hello again" } }, xhr: true
381
381
  expect(assigns[:opportunities]).to eq([@opportunity])
382
382
  end
383
383
 
@@ -385,7 +385,7 @@ describe OpportunitiesController do
385
385
  @campaign = FactoryGirl.create(:campaign)
386
386
 
387
387
  request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
388
- xhr :post, :create, opportunity: { name: "Hello" }, campaign: @campaign.id, account: { name: "Test Account" }
388
+ post :create, params: { opportunity: { name: "Hello" }, campaign: @campaign.id, account: { name: "Test Account" } }, xhr: true
389
389
  expect(assigns(:opportunity)).to eq(@opportunity)
390
390
  expect(assigns(:campaign)).to eq(@campaign)
391
391
  expect(@opportunity.campaign).to eq(@campaign)
@@ -395,14 +395,14 @@ describe OpportunitiesController do
395
395
  @contact = FactoryGirl.create(:contact, id: 42)
396
396
 
397
397
  request.env["HTTP_REFERER"] = "http://localhost/contacts/42"
398
- xhr :post, :create, opportunity: { name: "Hello" }, contact: 42, account: { name: "Hello again" }
398
+ post :create, params: { opportunity: { name: "Hello" }, contact: 42, account: { name: "Hello again" } }, xhr: true
399
399
  expect(assigns(:opportunity)).to eq(@opportunity)
400
400
  expect(@opportunity.contacts).to include(@contact)
401
401
  expect(@contact.opportunities).to include(@opportunity)
402
402
  end
403
403
 
404
404
  it "should create new account and associate it with the opportunity" do
405
- xhr :put, :create, opportunity: { name: "Hello" }, account: { name: "new account" }
405
+ put :create, params: { opportunity: { name: "Hello" }, account: { name: "new account" } }, xhr: true
406
406
  expect(assigns(:opportunity)).to eq(@opportunity)
407
407
  expect(@opportunity.account.name).to eq("new account")
408
408
  end
@@ -410,7 +410,7 @@ describe OpportunitiesController do
410
410
  it "should associate opportunity with the existing account" do
411
411
  @account = FactoryGirl.create(:account, id: 42)
412
412
 
413
- xhr :post, :create, opportunity: { name: "Hello world" }, account: { id: 42 }
413
+ post :create, params: { opportunity: { name: "Hello world" }, account: { id: 42 } }, xhr: true
414
414
  expect(assigns(:opportunity)).to eq(@opportunity)
415
415
  expect(@opportunity.account).to eq(@account)
416
416
  expect(@account.opportunities).to include(@opportunity)
@@ -421,7 +421,7 @@ describe OpportunitiesController do
421
421
  @opportunity = FactoryGirl.build(:opportunity, user: current_user, stage: "won", amount: 1100, discount: 100)
422
422
  allow(Opportunity).to receive(:new).and_return(@opportunity)
423
423
 
424
- xhr :post, :create, opportunity: { name: "Hello world" }, campaign: @campaign.id, account: { name: "Test Account" }
424
+ post :create, params: { opportunity: { name: "Hello world" }, campaign: @campaign.id, account: { name: "Test Account" } }, xhr: true
425
425
  expect(assigns(:opportunity)).to eq(@opportunity)
426
426
  expect(@opportunity.campaign).to eq(@campaign.reload)
427
427
  expect(@campaign.revenue.to_i).to eq(1000) # 1000 - 100 discount.
@@ -431,7 +431,7 @@ describe OpportunitiesController do
431
431
  @opportunity = FactoryGirl.build(:opportunity, user: current_user)
432
432
  allow(Opportunity).to receive(:new).and_return(@opportunity)
433
433
 
434
- xhr :post, :create, opportunity: { name: "Opportunity Knocks" }, account: { name: "My Account" }, comment_body: "Awesome comment is awesome"
434
+ post :create, params: { opportunity: { name: "Opportunity Knocks" }, account: { name: "My Account" }, comment_body: "Awesome comment is awesome" }, xhr: true
435
435
  expect(@opportunity.reload.comments.map(&:comment)).to include("Awesome comment is awesome")
436
436
  end
437
437
  end
@@ -446,7 +446,7 @@ describe OpportunitiesController do
446
446
  @accounts = [FactoryGirl.create(:account, user: current_user)]
447
447
 
448
448
  # Expect to redraw [create] form with blank account.
449
- xhr :post, :create, opportunity: {}, account: { user_id: current_user.id }
449
+ post :create, params: { opportunity: {}, account: { user_id: current_user.id } }, xhr: true
450
450
  expect(assigns(:opportunity)).to eq(@opportunity)
451
451
  expect(assigns(:account).attributes).to eq(@account.attributes)
452
452
  expect(assigns(:accounts)).to eq(@accounts)
@@ -461,7 +461,7 @@ describe OpportunitiesController do
461
461
  @stage = Setting.unroll(:opportunity_stage)
462
462
 
463
463
  # Expect to redraw [create] form with selected account.
464
- xhr :post, :create, opportunity: {}, account: { id: 42, user_id: current_user.id }
464
+ post :create, params: { opportunity: {}, account: { id: 42, user_id: current_user.id } }, xhr: true
465
465
  expect(assigns(:opportunity)).to eq(@opportunity)
466
466
  expect(assigns(:account)).to eq(@account)
467
467
  expect(assigns(:accounts)).to eq([@account])
@@ -472,7 +472,7 @@ describe OpportunitiesController do
472
472
  @campaign = FactoryGirl.create(:campaign, id: 42)
473
473
 
474
474
  request.env["HTTP_REFERER"] = "http://localhost/campaigns/42"
475
- xhr :post, :create, opportunity: { name: nil }, campaign: 42, account: { name: "Test Account" }
475
+ post :create, params: { opportunity: { name: nil }, campaign: 42, account: { name: "Test Account" } }, xhr: true
476
476
  expect(assigns(:campaign)).to eq(@campaign)
477
477
  expect(response).to render_template("opportunities/create")
478
478
  end
@@ -481,7 +481,7 @@ describe OpportunitiesController do
481
481
  @contact = FactoryGirl.create(:contact, id: 42)
482
482
 
483
483
  request.env["HTTP_REFERER"] = "http://localhost/contacts/42"
484
- xhr :post, :create, opportunity: { name: nil }, contact: 42, account: { name: "Test Account" }
484
+ post :create, params: { opportunity: { name: nil }, contact: 42, account: { name: "Test Account" } }, xhr: true
485
485
  expect(assigns(:contact)).to eq(@contact)
486
486
  expect(response).to render_template("opportunities/create")
487
487
  end
@@ -497,7 +497,7 @@ describe OpportunitiesController do
497
497
  @opportunity = FactoryGirl.create(:opportunity, id: 42)
498
498
  @stage = Setting.unroll(:opportunity_stage)
499
499
 
500
- xhr :put, :update, id: 42, opportunity: { name: "Hello world" }, account: { name: "Test Account" }
500
+ put :update, params: { id: 42, opportunity: { name: "Hello world" }, account: { name: "Test Account" } }, xhr: true
501
501
  expect(@opportunity.reload.name).to eq("Hello world")
502
502
  expect(assigns(:opportunity)).to eq(@opportunity)
503
503
  expect(assigns(:stage)).to eq(@stage)
@@ -509,7 +509,7 @@ describe OpportunitiesController do
509
509
  @opportunity = FactoryGirl.create(:opportunity, id: 42)
510
510
 
511
511
  request.env["HTTP_REFERER"] = "http://localhost/opportunities"
512
- xhr :put, :update, id: 42, opportunity: { name: "Hello world" }, account: { name: "Test Account" }
512
+ put :update, params: { id: 42, opportunity: { name: "Hello world" }, account: { name: "Test Account" } }, xhr: true
513
513
  expect(assigns(:opportunity_stage_total)).to be_an_instance_of(HashWithIndifferentAccess)
514
514
  end
515
515
 
@@ -518,7 +518,7 @@ describe OpportunitiesController do
518
518
  @opportunity = FactoryGirl.create(:opportunity, id: 42, account: @account)
519
519
  request.env["HTTP_REFERER"] = "http://localhost/accounts/#{@account.id}"
520
520
 
521
- xhr :put, :update, id: 42, opportunity: { name: "Hello world" }
521
+ put :update, params: { id: 42, opportunity: { name: "Hello world" } }, xhr: true
522
522
  expect(assigns(:account)).to eq(@account)
523
523
  end
524
524
 
@@ -527,7 +527,7 @@ describe OpportunitiesController do
527
527
  @opportunity = FactoryGirl.create(:opportunity, id: 42, account: @account)
528
528
  request.env["HTTP_REFERER"] = "http://localhost/accounts/#{@account.id}"
529
529
 
530
- xhr :put, :update, id: 42, opportunity: { name: "Hello world" }, account: { id: "" }
530
+ put :update, params: { id: 42, opportunity: { name: "Hello world" }, account: { id: "" } }, xhr: true
531
531
  expect(assigns(:account)).to eq(nil)
532
532
  end
533
533
 
@@ -537,14 +537,14 @@ describe OpportunitiesController do
537
537
  @campaign.opportunities << @opportunity
538
538
  request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
539
539
 
540
- xhr :put, :update, id: 42, opportunity: { name: "Hello world", campaign_id: @campaign.id }, account: {}
540
+ put :update, params: { id: 42, opportunity: { name: "Hello world", campaign_id: @campaign.id }, account: {} }, xhr: true
541
541
  expect(assigns(:campaign)).to eq(@campaign)
542
542
  end
543
543
 
544
544
  it "should be able to create an account and associate it with updated opportunity" do
545
545
  @opportunity = FactoryGirl.create(:opportunity, id: 42)
546
546
 
547
- xhr :put, :update, id: 42, opportunity: { name: "Hello" }, account: { name: "new account" }
547
+ put :update, params: { id: 42, opportunity: { name: "Hello" }, account: { name: "new account" } }, xhr: true
548
548
  expect(assigns[:opportunity]).to eq(@opportunity)
549
549
  expect(assigns[:opportunity].account).not_to be_nil
550
550
  expect(assigns[:opportunity].account.name).to eq("new account")
@@ -555,7 +555,7 @@ describe OpportunitiesController do
555
555
  @new_account = FactoryGirl.create(:account, id: 999)
556
556
  @opportunity = FactoryGirl.create(:opportunity, id: 42, account: @old_account)
557
557
 
558
- xhr :put, :update, id: 42, opportunity: { name: "Hello" }, account: { id: 999 }
558
+ put :update, params: { id: 42, opportunity: { name: "Hello" }, account: { id: 999 } }, xhr: true
559
559
  expect(assigns[:opportunity]).to eq(@opportunity)
560
560
  expect(assigns[:opportunity].account).to eq(@new_account)
561
561
  end
@@ -563,7 +563,7 @@ describe OpportunitiesController do
563
563
  it "should update opportunity permissions when sharing with specific users" do
564
564
  @opportunity = FactoryGirl.create(:opportunity, id: 42, access: "Public")
565
565
 
566
- xhr :put, :update, id: 42, opportunity: { name: "Hello", access: "Shared", user_ids: [7, 8] }, account: { name: "Test Account" }
566
+ put :update, params: { id: 42, opportunity: { name: "Hello", access: "Shared", user_ids: [7, 8] }, account: { name: "Test Account" } }, xhr: true
567
567
  expect(assigns[:opportunity].access).to eq("Shared")
568
568
  expect(assigns[:opportunity].user_ids.sort).to eq([7, 8])
569
569
  end
@@ -573,7 +573,7 @@ describe OpportunitiesController do
573
573
  @opportunity = FactoryGirl.create(:opportunity, campaign: @campaign)
574
574
 
575
575
  request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
576
- xhr :put, :update, id: @opportunity.id, opportunity: { name: "Hello" }, account: { name: "Test Account" }
576
+ put :update, params: { id: @opportunity.id, opportunity: { name: "Hello" }, account: { name: "Test Account" } }, xhr: true
577
577
  expect(assigns[:campaign]).to eq(@campaign)
578
578
  end
579
579
 
@@ -582,7 +582,7 @@ describe OpportunitiesController do
582
582
  @campaign = FactoryGirl.create(:campaign, revenue: 1000)
583
583
  @opportunity = FactoryGirl.create(:opportunity, campaign: @campaign, stage: 'prospecting', amount: 1100, discount: 100)
584
584
 
585
- xhr :put, :update, id: @opportunity, opportunity: { stage: "won" }, account: { name: "Test Account" }
585
+ put :update, params: { id: @opportunity, opportunity: { stage: "won" }, account: { name: "Test Account" } }, xhr: true
586
586
  expect(@campaign.reload.revenue.to_i).to eq(2000) # 1000 -> 2000
587
587
  end
588
588
 
@@ -591,7 +591,7 @@ describe OpportunitiesController do
591
591
  @opportunity = FactoryGirl.create(:opportunity, campaign: @campaign, stage: "won", amount: 1100, discount: 100)
592
592
  # @campaign.revenue is now $2000 since we created winning opportunity.
593
593
 
594
- xhr :put, :update, id: @opportunity, opportunity: { stage: 'prospecting' }, account: { name: "Test Account" }
594
+ put :update, params: { id: @opportunity, opportunity: { stage: 'prospecting' }, account: { name: "Test Account" } }, xhr: true
595
595
  expect(@campaign.reload.revenue.to_i).to eq(1000) # Should be adjusted back to $1000.
596
596
  end
597
597
 
@@ -599,7 +599,7 @@ describe OpportunitiesController do
599
599
  @campaign = FactoryGirl.create(:campaign, revenue: 1000)
600
600
  @opportunity = FactoryGirl.create(:opportunity, campaign: @campaign, stage: 'prospecting', amount: 1100, discount: 100)
601
601
 
602
- xhr :put, :update, id: @opportunity, opportunity: { stage: "lost" }, account: { name: "Test Account" }
602
+ put :update, params: { id: @opportunity, opportunity: { stage: "lost" }, account: { name: "Test Account" } }, xhr: true
603
603
  expect(@campaign.reload.revenue.to_i).to eq(1000) # Stays the same.
604
604
  end
605
605
  end
@@ -609,7 +609,7 @@ describe OpportunitiesController do
609
609
  @campaigns = { old: FactoryGirl.create(:campaign, revenue: 1000), new: FactoryGirl.create(:campaign, revenue: 1000) }
610
610
  @opportunity = FactoryGirl.create(:opportunity, campaign: @campaigns[:old], stage: 'prospecting', amount: 1100, discount: 100)
611
611
 
612
- xhr :put, :update, id: @opportunity, opportunity: { stage: "won", campaign_id: @campaigns[:new].id }, account: { name: "Test Account" }
612
+ put :update, params: { id: @opportunity, opportunity: { stage: "won", campaign_id: @campaigns[:new].id }, account: { name: "Test Account" } }, xhr: true
613
613
 
614
614
  expect(@campaigns[:old].reload.revenue.to_i).to eq(1000) # Stays the same.
615
615
  expect(@campaigns[:new].reload.revenue.to_i).to eq(2000) # 1000 -> 2000
@@ -620,7 +620,7 @@ describe OpportunitiesController do
620
620
  @opportunity = FactoryGirl.create(:opportunity, campaign: @campaigns[:old], stage: "won", amount: 1100, discount: 100)
621
621
  # @campaign.revenue is now $2000 since we created winning opportunity.
622
622
 
623
- xhr :put, :update, id: @opportunity, opportunity: { stage: 'prospecting', campaign_id: @campaigns[:new].id }, account: { name: "Test Account" }
623
+ put :update, params: { id: @opportunity, opportunity: { stage: 'prospecting', campaign_id: @campaigns[:new].id }, account: { name: "Test Account" } }, xhr: true
624
624
  expect(@campaigns[:old].reload.revenue.to_i).to eq(1000) # Should be adjusted back to $1000.
625
625
  expect(@campaigns[:new].reload.revenue.to_i).to eq(1000) # Stays the same.
626
626
  end
@@ -629,7 +629,7 @@ describe OpportunitiesController do
629
629
  @campaigns = { old: FactoryGirl.create(:campaign, revenue: 1000), new: FactoryGirl.create(:campaign, revenue: 1000) }
630
630
  @opportunity = FactoryGirl.create(:opportunity, campaign: @campaigns[:old], stage: 'prospecting', amount: 1100, discount: 100)
631
631
 
632
- xhr :put, :update, id: @opportunity, opportunity: { stage: "lost", campaign_id: @campaigns[:new].id }, account: { name: "Test Account" }
632
+ put :update, params: { id: @opportunity, opportunity: { stage: "lost", campaign_id: @campaigns[:new].id }, account: { name: "Test Account" } }, xhr: true
633
633
  expect(@campaigns[:old].reload.revenue.to_i).to eq(1000) # Stays the same.
634
634
  expect(@campaigns[:new].reload.revenue.to_i).to eq(1000) # Stays the same.
635
635
  end
@@ -640,7 +640,7 @@ describe OpportunitiesController do
640
640
  @opportunity = FactoryGirl.create(:opportunity, user: current_user)
641
641
  @opportunity.destroy
642
642
 
643
- xhr :put, :update, id: @opportunity.id
643
+ put :update, params: { id: @opportunity.id }, xhr: true
644
644
  expect(flash[:warning]).not_to eq(nil)
645
645
  expect(response.body).to eq("window.location.reload();")
646
646
  end
@@ -648,7 +648,7 @@ describe OpportunitiesController do
648
648
  it "should reload current page with the flash message if the opportunity is protected" do
649
649
  @private = FactoryGirl.create(:opportunity, user: FactoryGirl.create(:user), access: "Private")
650
650
 
651
- xhr :put, :update, id: @private.id
651
+ put :update, params: { id: @private.id }, xhr: true
652
652
  expect(flash[:warning]).not_to eq(nil)
653
653
  expect(response.body).to eq("window.location.reload();")
654
654
  end
@@ -659,7 +659,7 @@ describe OpportunitiesController do
659
659
  it "should not update the requested opportunity but still expose it as @opportunity, and render [update] template" do
660
660
  @opportunity = FactoryGirl.create(:opportunity, id: 42, name: "Hello people")
661
661
 
662
- xhr :put, :update, id: 42, opportunity: { name: nil }, account: { name: "Test Account" }
662
+ put :update, params: { id: 42, opportunity: { name: nil }, account: { name: "Test Account" } }, xhr: true
663
663
  expect(@opportunity.reload.name).to eq("Hello people")
664
664
  expect(assigns(:opportunity)).to eq(@opportunity)
665
665
  expect(assigns(:opportunity_stage_total)).to eq(nil)
@@ -671,7 +671,7 @@ describe OpportunitiesController do
671
671
  @opportunity = FactoryGirl.create(:opportunity, id: 42)
672
672
  FactoryGirl.create(:account_opportunity, account: @account, opportunity: @opportunity)
673
673
 
674
- xhr :put, :update, id: 42, opportunity: { name: nil }, account: { id: 99 }
674
+ put :update, params: { id: 42, opportunity: { name: nil }, account: { id: 99 } }, xhr: true
675
675
  expect(assigns(:account)).to eq(@account)
676
676
  end
677
677
  end
@@ -687,7 +687,7 @@ describe OpportunitiesController do
687
687
 
688
688
  describe "AJAX request" do
689
689
  it "should destroy the requested opportunity and render [destroy] template" do
690
- xhr :delete, :destroy, id: @opportunity.id
690
+ delete :destroy, params: { id: @opportunity.id }, xhr: true
691
691
 
692
692
  expect { Opportunity.find(@opportunity.id) }.to raise_error(ActiveRecord::RecordNotFound)
693
693
  expect(assigns(:opportunity_stage_total)).to eq(nil)
@@ -700,14 +700,14 @@ describe OpportunitiesController do
700
700
  end
701
701
 
702
702
  it "should get sidebar data if called from opportunities index" do
703
- xhr :delete, :destroy, id: @opportunity.id
703
+ delete :destroy, params: { id: @opportunity.id }, xhr: true
704
704
  expect(assigns(:opportunity_stage_total)).to be_an_instance_of(HashWithIndifferentAccess)
705
705
  end
706
706
 
707
707
  it "should try previous page and render index action if current page has no opportunities" do
708
708
  session[:opportunities_current_page] = 42
709
709
 
710
- xhr :delete, :destroy, id: @opportunity.id
710
+ delete :destroy, params: { id: @opportunity.id }, xhr: true
711
711
  expect(session[:opportunities_current_page]).to eq(41)
712
712
  expect(response).to render_template("opportunities/index")
713
713
  end
@@ -715,7 +715,7 @@ describe OpportunitiesController do
715
715
  it "should render index action when deleting last opportunity" do
716
716
  session[:opportunities_current_page] = 1
717
717
 
718
- xhr :delete, :destroy, id: @opportunity.id
718
+ delete :destroy, params: { id: @opportunity.id }, xhr: true
719
719
  expect(session[:opportunities_current_page]).to eq(1)
720
720
  expect(response).to render_template("opportunities/index")
721
721
  end
@@ -725,7 +725,7 @@ describe OpportunitiesController do
725
725
  it "should reset current page to 1" do
726
726
  request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
727
727
 
728
- xhr :delete, :destroy, id: @opportunity.id
728
+ delete :destroy, params: { id: @opportunity.id }, xhr: true
729
729
  expect(session[:opportunities_current_page]).to eq(1)
730
730
  expect(response).to render_template("opportunities/destroy")
731
731
  end
@@ -735,7 +735,7 @@ describe OpportunitiesController do
735
735
  @opportunity = FactoryGirl.create(:opportunity, user: current_user, account: @account)
736
736
  request.env["HTTP_REFERER"] = "http://localhost/accounts/#{@account.id}"
737
737
 
738
- xhr :delete, :destroy, id: @opportunity.id
738
+ delete :destroy, params: { id: @opportunity.id }, xhr: true
739
739
  expect(assigns[:account]).to eq(@account)
740
740
  expect(response).to render_template("opportunities/destroy")
741
741
  end
@@ -745,7 +745,7 @@ describe OpportunitiesController do
745
745
  @opportunity = FactoryGirl.create(:opportunity, user: current_user, campaign: @campaign)
746
746
  request.env["HTTP_REFERER"] = "http://localhost/campaigns/#{@campaign.id}"
747
747
 
748
- xhr :delete, :destroy, id: @opportunity.id
748
+ delete :destroy, params: { id: @opportunity.id }, xhr: true
749
749
  expect(assigns[:campaign]).to eq(@campaign)
750
750
  expect(response).to render_template("opportunities/destroy")
751
751
  end
@@ -756,7 +756,7 @@ describe OpportunitiesController do
756
756
  @opportunity = FactoryGirl.create(:opportunity, user: current_user)
757
757
  @opportunity.destroy
758
758
 
759
- xhr :delete, :destroy, id: @opportunity.id
759
+ delete :destroy, params: { id: @opportunity.id }, xhr: true
760
760
  expect(flash[:warning]).not_to eq(nil)
761
761
  expect(response.body).to eq("window.location.reload();")
762
762
  end
@@ -764,7 +764,7 @@ describe OpportunitiesController do
764
764
  it "should reload current page with the flash message if the opportunity is protected" do
765
765
  @private = FactoryGirl.create(:opportunity, user: FactoryGirl.create(:user), access: "Private")
766
766
 
767
- xhr :delete, :destroy, id: @private.id
767
+ delete :destroy, params: { id: @private.id }, xhr: true
768
768
  expect(flash[:warning]).not_to eq(nil)
769
769
  expect(response.body).to eq("window.location.reload();")
770
770
  end
@@ -773,7 +773,7 @@ describe OpportunitiesController do
773
773
 
774
774
  describe "HTML request" do
775
775
  it "should redirect to Opportunities index when an opportunity gets deleted from its landing page" do
776
- delete :destroy, id: @opportunity.id
776
+ delete :destroy, params: { id: @opportunity.id }
777
777
  expect(flash[:notice]).not_to eq(nil)
778
778
  expect(response).to redirect_to(opportunities_path)
779
779
  end
@@ -782,7 +782,7 @@ describe OpportunitiesController do
782
782
  @opportunity = FactoryGirl.create(:opportunity, user: current_user)
783
783
  @opportunity.destroy
784
784
 
785
- delete :destroy, id: @opportunity.id
785
+ delete :destroy, params: { id: @opportunity.id }
786
786
  expect(flash[:warning]).not_to eq(nil)
787
787
  expect(response).to redirect_to(opportunities_path)
788
788
  end
@@ -790,7 +790,7 @@ describe OpportunitiesController do
790
790
  it "should redirect to opportunity index with the flash message if the opportunity is protected" do
791
791
  @private = FactoryGirl.create(:opportunity, user: FactoryGirl.create(:user), access: "Private")
792
792
 
793
- delete :destroy, id: @private.id
793
+ delete :destroy, params: { id: @private.id }
794
794
  expect(flash[:warning]).not_to eq(nil)
795
795
  expect(response).to redirect_to(opportunities_path)
796
796
  end
@@ -854,14 +854,14 @@ describe OpportunitiesController do
854
854
  #----------------------------------------------------------------------------
855
855
  describe "responding to GET redraw" do
856
856
  it "should save user selected opportunity preference" do
857
- xhr :get, :redraw, per_page: 42, view: "brief", sort_by: "name"
857
+ get :redraw, params: { per_page: 42, view: "brief", sort_by: "name" }, xhr: true
858
858
  expect(current_user.preference[:opportunities_per_page]).to eq("42")
859
859
  expect(current_user.preference[:opportunities_index_view]).to eq("brief")
860
860
  expect(current_user.preference[:opportunities_sort_by]).to eq("opportunities.name ASC")
861
861
  end
862
862
 
863
863
  it "should reset current page to 1" do
864
- xhr :get, :redraw, per_page: 42, view: "brief", sort_by: "name"
864
+ get :redraw, params: { per_page: 42, view: "brief", sort_by: "name" }, xhr: true
865
865
  expect(session[:opportunities_current_page]).to eq(1)
866
866
  end
867
867
 
@@ -871,7 +871,7 @@ describe OpportunitiesController do
871
871
  FactoryGirl.create(:opportunity, name: "B", user: current_user)
872
872
  ]
873
873
 
874
- xhr :get, :redraw, per_page: 1, sort_by: "name"
874
+ get :redraw, params: { per_page: 1, sort_by: "name" }, xhr: true
875
875
  expect(assigns(:opportunities)).to eq([@opportunities.first])
876
876
  expect(response).to render_template("opportunities/index")
877
877
  end
@@ -885,7 +885,7 @@ describe OpportunitiesController do
885
885
  @opportunities = [FactoryGirl.create(:opportunity, stage: "prospecting", user: current_user)]
886
886
  @stage = Setting.unroll(:opportunity_stage)
887
887
 
888
- xhr :get, :filter, stage: "prospecting"
888
+ get :filter, params: { stage: "prospecting" }, xhr: true
889
889
  expect(assigns(:opportunities)).to eq(@opportunities)
890
890
  expect(assigns[:stage]).to eq(@stage)
891
891
  expect(response).to be_a_success
@@ -894,7 +894,7 @@ describe OpportunitiesController do
894
894
 
895
895
  it "should reset current page to 1" do
896
896
  @opportunities = []
897
- xhr :get, :filter, status: "new"
897
+ get :filter, params: { status: "new" }, xhr: true
898
898
 
899
899
  expect(session[:opportunities_current_page]).to eq(1)
900
900
  end