fat_free_crm 0.17.3 → 0.18.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.
- checksums.yaml +4 -4
- data/.dockerignore +11 -0
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +30 -8
- data/.travis.yml +14 -9
- data/CHANGELOG.md +43 -7
- data/CONTRIBUTORS.md +95 -53
- data/Gemfile +11 -7
- data/Gemfile.lock +83 -83
- data/README.md +7 -4
- data/app/assets/javascripts/crm.js.coffee +3 -3
- data/app/assets/javascripts/crm_select2.js.coffee +15 -14
- data/app/controllers/admin/field_groups_controller.rb +8 -1
- data/app/controllers/admin/fields_controller.rb +4 -4
- data/app/controllers/admin/groups_controller.rb +1 -1
- data/app/controllers/admin/tags_controller.rb +1 -1
- data/app/controllers/application_controller.rb +11 -0
- data/app/controllers/authentications_controller.rb +1 -1
- data/app/controllers/comments_controller.rb +15 -7
- data/app/controllers/entities/campaigns_controller.rb +7 -2
- data/app/controllers/entities/leads_controller.rb +9 -2
- data/app/controllers/entities/opportunities_controller.rb +13 -2
- data/app/controllers/entities_controller.rb +10 -5
- data/app/controllers/lists_controller.rb +5 -1
- data/app/controllers/tasks_controller.rb +15 -1
- data/app/helpers/accounts_helper.rb +1 -1
- data/app/helpers/application_helper.rb +2 -2
- data/app/helpers/leads_helper.rb +1 -1
- data/app/helpers/opportunities_helper.rb +56 -3
- data/app/helpers/tags_helper.rb +1 -1
- data/app/models/entities/lead.rb +0 -7
- data/app/models/entities/opportunity.rb +3 -2
- data/app/models/observers/opportunity_observer.rb +4 -4
- data/app/models/users/ability.rb +3 -4
- data/app/views/campaigns/_metrics.html.haml +3 -3
- data/app/views/home/_opportunity.html.haml +4 -19
- data/app/views/opportunities/_index_long.html.haml +1 -24
- data/app/views/opportunities/_sidebar_show.html.haml +3 -3
- data/app/views/opportunities/_top_section.html.haml +1 -1
- data/db/schema.rb +0 -3
- data/fat_free_crm.gemspec +1 -1
- data/lib/fat_free_crm/core_ext/string.rb +1 -1
- data/lib/fat_free_crm/engine.rb +2 -2
- data/lib/fat_free_crm/fields.rb +1 -1
- data/lib/fat_free_crm/permissions.rb +0 -14
- data/lib/fat_free_crm/version.rb +2 -2
- data/lib/tasks/ffcrm/setup.rake +4 -4
- data/spec/controllers/admin/users_controller_spec.rb +27 -27
- data/spec/controllers/authentications_controller_spec.rb +7 -7
- data/spec/controllers/comments_controller_spec.rb +13 -13
- data/spec/controllers/emails_controller_spec.rb +2 -2
- data/spec/controllers/entities/accounts_controller_spec.rb +56 -56
- data/spec/controllers/entities/campaigns_controller_spec.rb +66 -66
- data/spec/controllers/entities/contacts_controller_spec.rb +67 -67
- data/spec/controllers/entities/leads_controller_spec.rb +125 -125
- data/spec/controllers/entities/opportunities_controller_spec.rb +100 -100
- data/spec/controllers/home_controller_spec.rb +26 -26
- data/spec/controllers/passwords_controller_spec.rb +1 -1
- data/spec/controllers/tasks_controller_spec.rb +37 -37
- data/spec/controllers/users_controller_spec.rb +18 -18
- data/spec/factories/account_factories.rb +8 -8
- data/spec/factories/campaign_factories.rb +5 -5
- data/spec/factories/contact_factories.rb +10 -10
- data/spec/factories/field_factories.rb +7 -7
- data/spec/factories/lead_factories.rb +8 -8
- data/spec/factories/list_factories.rb +1 -1
- data/spec/factories/opportunity_factories.rb +6 -6
- data/spec/factories/sequences.rb +1 -1
- data/spec/factories/setting_factories.rb +3 -3
- data/spec/factories/shared_factories.rb +14 -14
- data/spec/factories/subscription_factories.rb +1 -1
- data/spec/factories/tag_factories.rb +1 -1
- data/spec/factories/task_factories.rb +4 -4
- data/spec/factories/user_factories.rb +13 -13
- data/spec/features/accounts_spec.rb +17 -4
- data/spec/features/admin/groups_spec.rb +1 -1
- data/spec/features/admin/users_spec.rb +1 -1
- data/spec/features/campaigns_spec.rb +4 -4
- data/spec/features/contacts_spec.rb +10 -4
- data/spec/features/dashboard_spec.rb +7 -7
- data/spec/features/leads_spec.rb +4 -4
- data/spec/features/opportunities_overview_spec.rb +15 -15
- data/spec/features/opportunities_spec.rb +34 -8
- data/spec/features/support/autocomlete_helper.rb +17 -0
- data/spec/features/support/browser.rb +3 -8
- data/spec/features/support/helpers.rb +1 -1
- data/spec/features/tasks_spec.rb +4 -4
- data/spec/helpers/admin/field_groups_helper_spec.rb +1 -1
- data/spec/helpers/application_helper_spec.rb +1 -1
- data/spec/helpers/tasks_helper_spec.rb +1 -1
- data/spec/helpers/users_helper_spec.rb +3 -3
- data/spec/lib/comment_extensions_spec.rb +1 -1
- data/spec/lib/mail_processor/base_spec.rb +3 -3
- data/spec/lib/mail_processor/comment_replies_spec.rb +3 -3
- data/spec/lib/mail_processor/dropbox_spec.rb +16 -16
- data/spec/lib/permissions_spec.rb +7 -25
- data/spec/mailers/user_mailer_spec.rb +7 -7
- data/spec/models/entities/account_spec.rb +31 -32
- data/spec/models/entities/campaign_spec.rb +18 -25
- data/spec/models/entities/contact_spec.rb +18 -21
- data/spec/models/entities/lead_spec.rb +9 -11
- data/spec/models/entities/opportunity_spec.rb +45 -45
- data/spec/models/fields/custom_field_spec.rb +17 -17
- data/spec/models/list_spec.rb +2 -2
- data/spec/models/observers/entity_observer_spec.rb +6 -6
- data/spec/models/polymorphic/address_spec.rb +1 -1
- data/spec/models/polymorphic/avatar_spec.rb +5 -5
- data/spec/models/polymorphic/comment_spec.rb +5 -5
- data/spec/models/polymorphic/task_spec.rb +65 -58
- data/spec/models/polymorphic/version_spec.rb +26 -26
- data/spec/models/setting_spec.rb +2 -2
- data/spec/models/users/preference_spec.rb +6 -6
- data/spec/models/users/user_spec.rb +26 -26
- data/spec/shared/models.rb +22 -22
- data/spec/spec_helper.rb +2 -2
- data/spec/support/auth_macros.rb +1 -1
- data/spec/support/macros.rb +3 -3
- data/spec/views/accounts/_edit.haml_spec.rb +1 -1
- data/spec/views/accounts/create.js.haml_spec.rb +2 -2
- data/spec/views/accounts/destroy.js.haml_spec.rb +1 -1
- data/spec/views/accounts/edit.js.haml_spec.rb +2 -2
- data/spec/views/accounts/index.haml_spec.rb +2 -2
- data/spec/views/accounts/index.js.haml_spec.rb +1 -1
- data/spec/views/accounts/show.haml_spec.rb +4 -4
- data/spec/views/accounts/update.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/create.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/destroy.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/edit.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/new.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/update.js.haml_spec.rb +1 -1
- data/spec/views/admin/users/create.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/destroy.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/edit.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/index.haml_spec.rb +1 -1
- data/spec/views/admin/users/index.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/reactivate.js.haml_spec.rb +1 -1
- data/spec/views/admin/users/suspend.js.haml_spec.rb +1 -1
- data/spec/views/admin/users/update.js.haml_spec.rb +1 -1
- data/spec/views/application/auto_complete.haml_spec.rb +3 -3
- data/spec/views/campaigns/_edit.haml_spec.rb +1 -1
- data/spec/views/campaigns/create.js.haml_spec.rb +3 -3
- data/spec/views/campaigns/destroy.js.haml_spec.rb +1 -1
- data/spec/views/campaigns/edit.js.haml_spec.rb +2 -2
- data/spec/views/campaigns/index.haml_spec.rb +1 -1
- data/spec/views/campaigns/index.js.haml_spec.rb +1 -1
- data/spec/views/campaigns/show.haml_spec.rb +4 -4
- data/spec/views/campaigns/update.js.haml_spec.rb +1 -1
- data/spec/views/contacts/_edit.haml_spec.rb +7 -7
- data/spec/views/contacts/_new.haml_spec.rb +1 -1
- data/spec/views/contacts/create.js.haml_spec.rb +4 -4
- data/spec/views/contacts/destroy.js.haml_spec.rb +1 -1
- data/spec/views/contacts/edit.js.haml_spec.rb +3 -3
- data/spec/views/contacts/index.haml_spec.rb +1 -1
- data/spec/views/contacts/index.js.html_spec.rb +1 -1
- data/spec/views/contacts/new.js.haml_spec.rb +1 -1
- data/spec/views/contacts/show.haml_spec.rb +3 -3
- data/spec/views/contacts/update.js.haml_spec.rb +2 -2
- data/spec/views/home/index.haml_spec.rb +1 -1
- data/spec/views/home/index.js.haml_spec.rb +1 -1
- data/spec/views/home/options.js.haml_spec.rb +2 -2
- data/spec/views/leads/_convert.haml_spec.rb +3 -3
- data/spec/views/leads/_edit.haml_spec.rb +2 -2
- data/spec/views/leads/_new.haml_spec.rb +2 -2
- data/spec/views/leads/_sidebar_show.haml_spec.rb +5 -5
- data/spec/views/leads/convert.js.haml_spec.rb +4 -4
- data/spec/views/leads/create.js.haml_spec.rb +5 -5
- data/spec/views/leads/destroy.js.haml_spec.rb +2 -2
- data/spec/views/leads/edit.js.haml_spec.rb +4 -4
- data/spec/views/leads/index.haml_spec.rb +1 -1
- data/spec/views/leads/index.js.haml_spec.rb +1 -1
- data/spec/views/leads/new.js.haml_spec.rb +1 -1
- data/spec/views/leads/promote.js.haml_spec.rb +7 -7
- data/spec/views/leads/reject.js.haml_spec.rb +2 -2
- data/spec/views/leads/show.haml_spec.rb +2 -2
- data/spec/views/leads/update.js.haml_spec.rb +4 -4
- data/spec/views/opportunities/_edit.haml_spec.rb +7 -7
- data/spec/views/opportunities/_new.haml_spec.rb +2 -2
- data/spec/views/opportunities/create.js.haml_spec.rb +6 -6
- data/spec/views/opportunities/destroy.js.haml_spec.rb +3 -3
- data/spec/views/opportunities/edit.js.haml_spec.rb +3 -3
- data/spec/views/opportunities/index.haml_spec.rb +1 -1
- data/spec/views/opportunities/index.js.haml_spec.rb +1 -1
- data/spec/views/opportunities/new.js.haml_spec.rb +1 -1
- data/spec/views/opportunities/show.haml_spec.rb +3 -3
- data/spec/views/opportunities/update.js.haml_spec.rb +4 -4
- data/spec/views/tasks/_edit.haml_spec.rb +1 -1
- data/spec/views/tasks/complete.js.haml_spec.rb +4 -4
- data/spec/views/tasks/create.js.haml_spec.rb +6 -6
- data/spec/views/tasks/destroy.js.haml_spec.rb +2 -2
- data/spec/views/tasks/index.haml_spec.rb +4 -4
- data/spec/views/tasks/new.js.haml_spec.rb +1 -1
- data/spec/views/tasks/uncomplete.js.haml_spec.rb +2 -2
- data/spec/views/tasks/update.js.haml_spec.rb +18 -18
- data/spec/views/users/upload_avatar.js.haml_spec.rb +2 -2
- metadata +5 -3
@@ -26,7 +26,7 @@ describe CampaignsController do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should expose all campaigns as @campaigns and render [index] template" do
|
29
|
-
@campaigns = [
|
29
|
+
@campaigns = [create(:campaign, user: current_user)]
|
30
30
|
|
31
31
|
get :index
|
32
32
|
expect(assigns[:campaigns]).to eq(@campaigns)
|
@@ -34,7 +34,7 @@ describe CampaignsController do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should collect the data for the opportunities sidebar" do
|
37
|
-
@campaigns = [
|
37
|
+
@campaigns = [create(:campaign, user: current_user)]
|
38
38
|
|
39
39
|
get :index
|
40
40
|
expect(assigns[:campaign_status_total].keys.map(&:to_sym) - (@status << :all << :other)).to eq([])
|
@@ -43,12 +43,12 @@ describe CampaignsController do
|
|
43
43
|
it "should filter out campaigns by status" do
|
44
44
|
controller.session[:campaigns_filter] = "planned,started"
|
45
45
|
@campaigns = [
|
46
|
-
|
47
|
-
|
46
|
+
create(:campaign, user: current_user, status: "started"),
|
47
|
+
create(:campaign, user: current_user, status: "planned")
|
48
48
|
]
|
49
49
|
|
50
50
|
# This one should be filtered out.
|
51
|
-
|
51
|
+
create(:campaign, user: current_user, status: "completed")
|
52
52
|
|
53
53
|
get :index
|
54
54
|
# Note: can't compare campaigns directly because of BigDecimal objects.
|
@@ -57,8 +57,8 @@ describe CampaignsController do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should perform lookup using query string" do
|
60
|
-
@first =
|
61
|
-
@second =
|
60
|
+
@first = create(:campaign, user: current_user, name: "Hello, world!")
|
61
|
+
@second = create(:campaign, user: current_user, name: "Hello again")
|
62
62
|
|
63
63
|
get :index, params: { query: "again" }
|
64
64
|
expect(assigns[:campaigns]).to eq([@second])
|
@@ -68,7 +68,7 @@ describe CampaignsController do
|
|
68
68
|
|
69
69
|
describe "AJAX pagination" do
|
70
70
|
it "should pick up page number from params" do
|
71
|
-
@campaigns = [
|
71
|
+
@campaigns = [create(:campaign, user: current_user)]
|
72
72
|
get :index, params: { page: 42 }, xhr: true
|
73
73
|
|
74
74
|
expect(assigns[:current_page].to_i).to eq(42)
|
@@ -79,7 +79,7 @@ describe CampaignsController do
|
|
79
79
|
|
80
80
|
it "should pick up saved page number from session" do
|
81
81
|
session[:campaigns_current_page] = 42
|
82
|
-
@campaigns = [
|
82
|
+
@campaigns = [create(:campaign, user: current_user)]
|
83
83
|
get :index, xhr: true
|
84
84
|
|
85
85
|
expect(assigns[:current_page]).to eq(42)
|
@@ -90,7 +90,7 @@ describe CampaignsController do
|
|
90
90
|
it "should reset current_page when query is altered" do
|
91
91
|
session[:campaigns_current_page] = 42
|
92
92
|
session[:campaigns_current_query] = "bill"
|
93
|
-
@campaigns = [
|
93
|
+
@campaigns = [create(:campaign, user: current_user)]
|
94
94
|
get :index, xhr: true
|
95
95
|
|
96
96
|
expect(assigns[:current_page]).to eq(1)
|
@@ -128,7 +128,7 @@ describe CampaignsController do
|
|
128
128
|
describe "responding to GET show" do
|
129
129
|
describe "with mime type of HTML" do
|
130
130
|
before(:each) do
|
131
|
-
@campaign =
|
131
|
+
@campaign = create(:campaign, id: 42, user: current_user)
|
132
132
|
@stage = Setting.unroll(:opportunity_stage)
|
133
133
|
@comment = Comment.new
|
134
134
|
end
|
@@ -149,7 +149,7 @@ describe CampaignsController do
|
|
149
149
|
|
150
150
|
describe "with mime type of JSON" do
|
151
151
|
it "should render the requested campaign as JSON" do
|
152
|
-
@campaign =
|
152
|
+
@campaign = create(:campaign, id: 42, user: current_user)
|
153
153
|
expect(Campaign).to receive(:find).and_return(@campaign)
|
154
154
|
expect(@campaign).to receive(:to_json).and_return("generated JSON")
|
155
155
|
|
@@ -161,7 +161,7 @@ describe CampaignsController do
|
|
161
161
|
|
162
162
|
describe "with mime type of XML" do
|
163
163
|
it "should render the requested campaign as XML" do
|
164
|
-
@campaign =
|
164
|
+
@campaign = create(:campaign, id: 42, user: current_user)
|
165
165
|
expect(Campaign).to receive(:find).and_return(@campaign)
|
166
166
|
expect(@campaign).to receive(:to_xml).and_return("generated XML")
|
167
167
|
|
@@ -173,7 +173,7 @@ describe CampaignsController do
|
|
173
173
|
|
174
174
|
describe "campaign got deleted or otherwise unavailable" do
|
175
175
|
it "should redirect to campaign index if the campaign got deleted" do
|
176
|
-
@campaign =
|
176
|
+
@campaign = create(:campaign, user: current_user)
|
177
177
|
@campaign.destroy
|
178
178
|
|
179
179
|
get :show, params: { id: @campaign.id }
|
@@ -182,7 +182,7 @@ describe CampaignsController do
|
|
182
182
|
end
|
183
183
|
|
184
184
|
it "should redirect to campaign index if the campaign is protected" do
|
185
|
-
@campaign =
|
185
|
+
@campaign = create(:campaign, user: create(:user), access: "Private")
|
186
186
|
|
187
187
|
get :show, params: { id: @campaign.id }
|
188
188
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -190,7 +190,7 @@ describe CampaignsController do
|
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should return 404 (Not Found) JSON error" do
|
193
|
-
@campaign =
|
193
|
+
@campaign = create(:campaign, user: current_user)
|
194
194
|
@campaign.destroy
|
195
195
|
request.env["HTTP_ACCEPT"] = "application/json"
|
196
196
|
|
@@ -199,7 +199,7 @@ describe CampaignsController do
|
|
199
199
|
end
|
200
200
|
|
201
201
|
it "should return 404 (Not Found) XML error" do
|
202
|
-
@campaign =
|
202
|
+
@campaign = create(:campaign, user: current_user)
|
203
203
|
@campaign.destroy
|
204
204
|
request.env["HTTP_ACCEPT"] = "application/xml"
|
205
205
|
|
@@ -222,7 +222,7 @@ describe CampaignsController do
|
|
222
222
|
end
|
223
223
|
|
224
224
|
it "should create related object when necessary" do
|
225
|
-
@lead =
|
225
|
+
@lead = create(:lead, id: 42)
|
226
226
|
|
227
227
|
get :new, params: { related: "lead_42" }, xhr: true
|
228
228
|
expect(assigns[:lead]).to eq(@lead)
|
@@ -233,7 +233,7 @@ describe CampaignsController do
|
|
233
233
|
#----------------------------------------------------------------------------
|
234
234
|
describe "responding to GET edit" do
|
235
235
|
it "should expose the requested campaign as @campaign and render [edit] template" do
|
236
|
-
@campaign =
|
236
|
+
@campaign = create(:campaign, id: 42, user: current_user)
|
237
237
|
|
238
238
|
get :edit, params: { id: 42 }, xhr: true
|
239
239
|
expect(assigns[:campaign]).to eq(@campaign)
|
@@ -241,8 +241,8 @@ describe CampaignsController do
|
|
241
241
|
end
|
242
242
|
|
243
243
|
it "should find previous campaign as necessary" do
|
244
|
-
@campaign =
|
245
|
-
@previous =
|
244
|
+
@campaign = create(:campaign, id: 42)
|
245
|
+
@previous = create(:campaign, id: 99)
|
246
246
|
|
247
247
|
get :edit, params: { id: 42, previous: 99 }, xhr: true
|
248
248
|
expect(assigns[:campaign]).to eq(@campaign)
|
@@ -251,7 +251,7 @@ describe CampaignsController do
|
|
251
251
|
|
252
252
|
describe "(campaign got deleted or is otherwise unavailable)" do
|
253
253
|
it "should reload current page with the flash message if the campaign got deleted" do
|
254
|
-
@campaign =
|
254
|
+
@campaign = create(:campaign, user: current_user)
|
255
255
|
@campaign.destroy
|
256
256
|
|
257
257
|
get :edit, params: { id: @campaign.id }, xhr: true
|
@@ -260,7 +260,7 @@ describe CampaignsController do
|
|
260
260
|
end
|
261
261
|
|
262
262
|
it "should reload current page with the flash message if the campaign is protected" do
|
263
|
-
@private =
|
263
|
+
@private = create(:campaign, user: create(:user), access: "Private")
|
264
264
|
|
265
265
|
get :edit, params: { id: @private.id }, xhr: true
|
266
266
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -270,8 +270,8 @@ describe CampaignsController do
|
|
270
270
|
|
271
271
|
describe "(previous campaign got deleted or is otherwise unavailable)" do
|
272
272
|
before(:each) do
|
273
|
-
@campaign =
|
274
|
-
@previous =
|
273
|
+
@campaign = create(:campaign, user: current_user)
|
274
|
+
@previous = create(:campaign, user: create(:user))
|
275
275
|
end
|
276
276
|
|
277
277
|
it "should notify the view if previous campaign got deleted" do
|
@@ -300,7 +300,7 @@ describe CampaignsController do
|
|
300
300
|
describe "responding to POST create" do
|
301
301
|
describe "with valid params" do
|
302
302
|
it "should expose a newly created campaign as @campaign and render [create] template" do
|
303
|
-
@campaign =
|
303
|
+
@campaign = build(:campaign, name: "Hello", user: current_user)
|
304
304
|
allow(Campaign).to receive(:new).and_return(@campaign)
|
305
305
|
|
306
306
|
post :create, params: { campaign: { name: "Hello" } }, xhr: true
|
@@ -309,7 +309,7 @@ describe CampaignsController do
|
|
309
309
|
end
|
310
310
|
|
311
311
|
it "should get data to update campaign sidebar" do
|
312
|
-
@campaign =
|
312
|
+
@campaign = build(:campaign, name: "Hello", user: current_user)
|
313
313
|
allow(Campaign).to receive(:new).and_return(@campaign)
|
314
314
|
|
315
315
|
post :create, params: { campaign: { name: "Hello" } }, xhr: true
|
@@ -317,7 +317,7 @@ describe CampaignsController do
|
|
317
317
|
end
|
318
318
|
|
319
319
|
it "should reload campaigns to update pagination" do
|
320
|
-
@campaign =
|
320
|
+
@campaign = build(:campaign, user: current_user)
|
321
321
|
allow(Campaign).to receive(:new).and_return(@campaign)
|
322
322
|
|
323
323
|
post :create, params: { campaign: { name: "Hello" } }, xhr: true
|
@@ -325,7 +325,7 @@ describe CampaignsController do
|
|
325
325
|
end
|
326
326
|
|
327
327
|
it "should add a new comment to the newly created campaign when specified" do
|
328
|
-
@campaign =
|
328
|
+
@campaign = build(:campaign, name: "Hello world", user: current_user)
|
329
329
|
allow(Campaign).to receive(:new).and_return(@campaign)
|
330
330
|
|
331
331
|
post :create, params: { campaign: { name: "Hello world" }, comment_body: "Awesome comment is awesome" }, xhr: true
|
@@ -335,7 +335,7 @@ describe CampaignsController do
|
|
335
335
|
|
336
336
|
describe "with invalid params" do
|
337
337
|
it "should expose a newly created but unsaved campaign as @campaign and still render [create] template" do
|
338
|
-
@campaign =
|
338
|
+
@campaign = build(:campaign, id: nil, name: nil, user: current_user)
|
339
339
|
allow(Campaign).to receive(:new).and_return(@campaign)
|
340
340
|
|
341
341
|
post :create, params: { campaign: {} }, xhr: true
|
@@ -351,7 +351,7 @@ describe CampaignsController do
|
|
351
351
|
describe "responding to PUT update" do
|
352
352
|
describe "with valid params" do
|
353
353
|
it "should update the requested campaign and render [update] template" do
|
354
|
-
@campaign =
|
354
|
+
@campaign = create(:campaign, id: 42, name: "Bye")
|
355
355
|
|
356
356
|
put :update, params: { id: 42, campaign: { name: "Hello" } }, xhr: true
|
357
357
|
expect(@campaign.reload.name).to eq("Hello")
|
@@ -360,7 +360,7 @@ describe CampaignsController do
|
|
360
360
|
end
|
361
361
|
|
362
362
|
it "should get data for campaigns sidebar when called from Campaigns index" do
|
363
|
-
@campaign =
|
363
|
+
@campaign = create(:campaign, id: 42)
|
364
364
|
request.env["HTTP_REFERER"] = "http://localhost/campaigns"
|
365
365
|
|
366
366
|
put :update, params: { id: 42, campaign: { name: "Hello" } }, xhr: true
|
@@ -369,9 +369,9 @@ describe CampaignsController do
|
|
369
369
|
end
|
370
370
|
|
371
371
|
it "should update campaign permissions when sharing with specific users" do
|
372
|
-
@campaign =
|
373
|
-
he =
|
374
|
-
she =
|
372
|
+
@campaign = create(:campaign, id: 42, access: "Public")
|
373
|
+
he = create(:user, id: 7)
|
374
|
+
she = create(:user, id: 8)
|
375
375
|
|
376
376
|
put :update, params: { id: 42, campaign: { name: "Hello", access: "Shared", user_ids: %w[7 8] } }, xhr: true
|
377
377
|
expect(assigns[:campaign].access).to eq("Shared")
|
@@ -380,7 +380,7 @@ describe CampaignsController do
|
|
380
380
|
|
381
381
|
describe "campaign got deleted or otherwise unavailable" do
|
382
382
|
it "should reload current page with the flash message if the campaign got deleted" do
|
383
|
-
@campaign =
|
383
|
+
@campaign = create(:campaign, user: current_user)
|
384
384
|
@campaign.destroy
|
385
385
|
|
386
386
|
put :update, params: { id: @campaign.id }, xhr: true
|
@@ -389,7 +389,7 @@ describe CampaignsController do
|
|
389
389
|
end
|
390
390
|
|
391
391
|
it "should reload current page with the flash message if the campaign is protected" do
|
392
|
-
@private =
|
392
|
+
@private = create(:campaign, user: create(:user), access: "Private")
|
393
393
|
|
394
394
|
put :update, params: { id: @private.id }, xhr: true
|
395
395
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -400,7 +400,7 @@ describe CampaignsController do
|
|
400
400
|
|
401
401
|
describe "with invalid params" do
|
402
402
|
it "should not update the requested campaign, but still expose it as @campaign and still render [update] template" do
|
403
|
-
@campaign =
|
403
|
+
@campaign = create(:campaign, id: 42, name: "Hello", user: current_user)
|
404
404
|
|
405
405
|
put :update, params: { id: 42, campaign: { name: nil } }, xhr: true
|
406
406
|
expect(@campaign.reload.name).to eq("Hello")
|
@@ -415,12 +415,12 @@ describe CampaignsController do
|
|
415
415
|
#----------------------------------------------------------------------------
|
416
416
|
describe "responding to DELETE destroy" do
|
417
417
|
before(:each) do
|
418
|
-
@campaign =
|
418
|
+
@campaign = create(:campaign, user: current_user)
|
419
419
|
end
|
420
420
|
|
421
421
|
describe "AJAX request" do
|
422
422
|
it "should destroy the requested campaign and render [destroy] template" do
|
423
|
-
@another_campaign =
|
423
|
+
@another_campaign = create(:campaign, user: current_user)
|
424
424
|
delete :destroy, params: { id: @campaign.id }, xhr: true
|
425
425
|
|
426
426
|
expect(assigns[:campaigns]).to eq([@another_campaign])
|
@@ -452,7 +452,7 @@ describe CampaignsController do
|
|
452
452
|
|
453
453
|
describe "campaign got deleted or otherwise unavailable" do
|
454
454
|
it "should reload current page with the flash message if the campaign got deleted" do
|
455
|
-
@campaign =
|
455
|
+
@campaign = create(:campaign, user: current_user)
|
456
456
|
@campaign.destroy
|
457
457
|
|
458
458
|
delete :destroy, params: { id: @campaign.id }, xhr: true
|
@@ -461,7 +461,7 @@ describe CampaignsController do
|
|
461
461
|
end
|
462
462
|
|
463
463
|
it "should reload current page with the flash message if the campaign is protected" do
|
464
|
-
@private =
|
464
|
+
@private = create(:campaign, user: create(:user), access: "Private")
|
465
465
|
|
466
466
|
delete :destroy, params: { id: @private.id }, xhr: true
|
467
467
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -479,7 +479,7 @@ describe CampaignsController do
|
|
479
479
|
end
|
480
480
|
|
481
481
|
it "should redirect to campaign index with the flash message is the campaign got deleted" do
|
482
|
-
@campaign =
|
482
|
+
@campaign = create(:campaign, user: current_user)
|
483
483
|
@campaign.destroy
|
484
484
|
|
485
485
|
delete :destroy, params: { id: @campaign.id }
|
@@ -488,7 +488,7 @@ describe CampaignsController do
|
|
488
488
|
end
|
489
489
|
|
490
490
|
it "should redirect to campaign index with the flash message if the campaign is protected" do
|
491
|
-
@private =
|
491
|
+
@private = create(:campaign, user: create(:user), access: "Private")
|
492
492
|
|
493
493
|
delete :destroy, params: { id: @private.id }
|
494
494
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -503,24 +503,24 @@ describe CampaignsController do
|
|
503
503
|
describe "responding to PUT attach" do
|
504
504
|
describe "tasks" do
|
505
505
|
before do
|
506
|
-
@model =
|
507
|
-
@attachment =
|
506
|
+
@model = create(:campaign)
|
507
|
+
@attachment = create(:task, asset: nil)
|
508
508
|
end
|
509
509
|
it_should_behave_like("attach")
|
510
510
|
end
|
511
511
|
|
512
512
|
describe "leads" do
|
513
513
|
before do
|
514
|
-
@model =
|
515
|
-
@attachment =
|
514
|
+
@model = create(:campaign)
|
515
|
+
@attachment = create(:lead, campaign: nil)
|
516
516
|
end
|
517
517
|
it_should_behave_like("attach")
|
518
518
|
end
|
519
519
|
|
520
520
|
describe "opportunities" do
|
521
521
|
before do
|
522
|
-
@model =
|
523
|
-
@attachment =
|
522
|
+
@model = create(:campaign)
|
523
|
+
@attachment = create(:opportunity, campaign: nil)
|
524
524
|
end
|
525
525
|
it_should_behave_like("attach")
|
526
526
|
end
|
@@ -532,24 +532,24 @@ describe CampaignsController do
|
|
532
532
|
describe "responding to PUT attach" do
|
533
533
|
describe "tasks" do
|
534
534
|
before do
|
535
|
-
@model =
|
536
|
-
@attachment =
|
535
|
+
@model = create(:campaign)
|
536
|
+
@attachment = create(:task, asset: nil)
|
537
537
|
end
|
538
538
|
it_should_behave_like("attach")
|
539
539
|
end
|
540
540
|
|
541
541
|
describe "leads" do
|
542
542
|
before do
|
543
|
-
@model =
|
544
|
-
@attachment =
|
543
|
+
@model = create(:campaign)
|
544
|
+
@attachment = create(:lead, campaign: nil)
|
545
545
|
end
|
546
546
|
it_should_behave_like("attach")
|
547
547
|
end
|
548
548
|
|
549
549
|
describe "opportunities" do
|
550
550
|
before do
|
551
|
-
@model =
|
552
|
-
@attachment =
|
551
|
+
@model = create(:campaign)
|
552
|
+
@attachment = create(:opportunity, campaign: nil)
|
553
553
|
end
|
554
554
|
it_should_behave_like("attach")
|
555
555
|
end
|
@@ -561,16 +561,16 @@ describe CampaignsController do
|
|
561
561
|
describe "responding to POST discard" do
|
562
562
|
describe "tasks" do
|
563
563
|
before do
|
564
|
-
@model =
|
565
|
-
@attachment =
|
564
|
+
@model = create(:campaign)
|
565
|
+
@attachment = create(:task, asset: @model)
|
566
566
|
end
|
567
567
|
it_should_behave_like("discard")
|
568
568
|
end
|
569
569
|
|
570
570
|
describe "leads" do
|
571
571
|
before do
|
572
|
-
@attachment =
|
573
|
-
@model =
|
572
|
+
@attachment = create(:lead)
|
573
|
+
@model = create(:campaign)
|
574
574
|
@model.leads << @attachment
|
575
575
|
end
|
576
576
|
it_should_behave_like("discard")
|
@@ -578,8 +578,8 @@ describe CampaignsController do
|
|
578
578
|
|
579
579
|
describe "opportunities" do
|
580
580
|
before do
|
581
|
-
@attachment =
|
582
|
-
@model =
|
581
|
+
@attachment = create(:opportunity)
|
582
|
+
@model = create(:campaign)
|
583
583
|
@model.opportunities << @attachment
|
584
584
|
end
|
585
585
|
it_should_behave_like("discard")
|
@@ -590,7 +590,7 @@ describe CampaignsController do
|
|
590
590
|
#----------------------------------------------------------------------------
|
591
591
|
describe "responding to POST auto_complete" do
|
592
592
|
before(:each) do
|
593
|
-
@auto_complete_matches = [
|
593
|
+
@auto_complete_matches = [create(:campaign, name: "Hello World", user: current_user)]
|
594
594
|
end
|
595
595
|
|
596
596
|
it_should_behave_like("auto complete")
|
@@ -613,8 +613,8 @@ describe CampaignsController do
|
|
613
613
|
|
614
614
|
it "should select @campaigns and render [index] template" do
|
615
615
|
@campaigns = [
|
616
|
-
|
617
|
-
|
616
|
+
create(:campaign, name: "A", user: current_user),
|
617
|
+
create(:campaign, name: "B", user: current_user)
|
618
618
|
]
|
619
619
|
|
620
620
|
get :redraw, params: { per_page: 1, sort_by: "name" }, xhr: true
|
@@ -628,7 +628,7 @@ describe CampaignsController do
|
|
628
628
|
describe "responding to POST filter" do
|
629
629
|
it "should expose filtered campaigns as @campaigns and render [index] template" do
|
630
630
|
session[:campaigns_filter] = "planned,started"
|
631
|
-
@campaigns = [
|
631
|
+
@campaigns = [create(:campaign, status: "completed", user: current_user)]
|
632
632
|
|
633
633
|
post :filter, params: { status: "completed" }, xhr: true
|
634
634
|
expect(assigns(:campaigns)).to eq(@campaigns)
|
@@ -18,7 +18,7 @@ describe ContactsController do
|
|
18
18
|
#----------------------------------------------------------------------------
|
19
19
|
describe "responding to GET index" do
|
20
20
|
it "should expose all contacts as @contacts and render [index] template" do
|
21
|
-
@contacts = [
|
21
|
+
@contacts = [create(:contact, user: current_user)]
|
22
22
|
get :index
|
23
23
|
expect(assigns[:contacts].count).to eq(@contacts.count)
|
24
24
|
expect(assigns[:contacts]).to eq(@contacts)
|
@@ -26,8 +26,8 @@ describe ContactsController do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should perform lookup using query string" do
|
29
|
-
@billy_bones =
|
30
|
-
@captain_flint =
|
29
|
+
@billy_bones = create(:contact, user: current_user, first_name: "Billy", last_name: "Bones")
|
30
|
+
@captain_flint = create(:contact, user: current_user, first_name: "Captain", last_name: "Flint")
|
31
31
|
|
32
32
|
get :index, params: { query: @billy_bones.email }
|
33
33
|
expect(assigns[:contacts]).to eq([@billy_bones])
|
@@ -37,7 +37,7 @@ describe ContactsController do
|
|
37
37
|
|
38
38
|
describe "AJAX pagination" do
|
39
39
|
it "should pick up page number from params" do
|
40
|
-
@contacts = [
|
40
|
+
@contacts = [create(:contact, user: current_user)]
|
41
41
|
get :index, params: { page: 42 }, xhr: true
|
42
42
|
|
43
43
|
expect(assigns[:current_page].to_i).to eq(42)
|
@@ -48,7 +48,7 @@ describe ContactsController do
|
|
48
48
|
|
49
49
|
it "should pick up saved page number from session" do
|
50
50
|
session[:contacts_current_page] = 42
|
51
|
-
@contacts = [
|
51
|
+
@contacts = [create(:contact, user: current_user)]
|
52
52
|
get :index, xhr: true
|
53
53
|
|
54
54
|
expect(assigns[:current_page]).to eq(42)
|
@@ -59,7 +59,7 @@ describe ContactsController do
|
|
59
59
|
it "should reset current_page when query is altered" do
|
60
60
|
session[:contacts_current_page] = 42
|
61
61
|
session[:contacts_current_query] = "bill"
|
62
|
-
@contacts = [
|
62
|
+
@contacts = [create(:contact, user: current_user)]
|
63
63
|
get :index, xhr: true
|
64
64
|
|
65
65
|
expect(assigns[:current_page]).to eq(1)
|
@@ -97,7 +97,7 @@ describe ContactsController do
|
|
97
97
|
describe "responding to GET show" do
|
98
98
|
describe "with mime type of HTML" do
|
99
99
|
before(:each) do
|
100
|
-
@contact =
|
100
|
+
@contact = create(:contact, id: 42)
|
101
101
|
@stage = Setting.unroll(:opportunity_stage)
|
102
102
|
@comment = Comment.new
|
103
103
|
end
|
@@ -118,7 +118,7 @@ describe ContactsController do
|
|
118
118
|
|
119
119
|
describe "with mime type of JSON" do
|
120
120
|
it "should render the requested contact as JSON" do
|
121
|
-
@contact =
|
121
|
+
@contact = create(:contact, id: 42)
|
122
122
|
expect(Contact).to receive(:find).and_return(@contact)
|
123
123
|
expect(@contact).to receive(:to_json).and_return("generated JSON")
|
124
124
|
|
@@ -130,7 +130,7 @@ describe ContactsController do
|
|
130
130
|
|
131
131
|
describe "with mime type of XML" do
|
132
132
|
it "should render the requested contact as xml" do
|
133
|
-
@contact =
|
133
|
+
@contact = create(:contact, id: 42)
|
134
134
|
expect(Contact).to receive(:find).and_return(@contact)
|
135
135
|
expect(@contact).to receive(:to_xml).and_return("generated XML")
|
136
136
|
|
@@ -142,7 +142,7 @@ describe ContactsController do
|
|
142
142
|
|
143
143
|
describe "contact got deleted or otherwise unavailable" do
|
144
144
|
it "should redirect to contact index if the contact got deleted" do
|
145
|
-
@contact =
|
145
|
+
@contact = create(:contact, user: current_user)
|
146
146
|
@contact.destroy
|
147
147
|
|
148
148
|
get :show, params: { id: @contact.id }
|
@@ -151,7 +151,7 @@ describe ContactsController do
|
|
151
151
|
end
|
152
152
|
|
153
153
|
it "should redirect to contact index if the contact is protected" do
|
154
|
-
@private =
|
154
|
+
@private = create(:contact, user: create(:user), access: "Private")
|
155
155
|
|
156
156
|
get :show, params: { id: @private.id }
|
157
157
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -159,7 +159,7 @@ describe ContactsController do
|
|
159
159
|
end
|
160
160
|
|
161
161
|
it "should return 404 (Not Found) XML error" do
|
162
|
-
@contact =
|
162
|
+
@contact = create(:contact, user: current_user)
|
163
163
|
@contact.destroy
|
164
164
|
request.env["HTTP_ACCEPT"] = "application/xml"
|
165
165
|
|
@@ -177,7 +177,7 @@ describe ContactsController do
|
|
177
177
|
@contact = Contact.new(user: current_user,
|
178
178
|
access: Setting.default_access)
|
179
179
|
@account = Account.new(user: current_user)
|
180
|
-
@accounts = [
|
180
|
+
@accounts = [create(:account, user: current_user)]
|
181
181
|
|
182
182
|
get :new, xhr: true
|
183
183
|
expect(assigns[:contact].attributes).to eq(@contact.attributes)
|
@@ -188,7 +188,7 @@ describe ContactsController do
|
|
188
188
|
end
|
189
189
|
|
190
190
|
it "should created an instance of related object when necessary" do
|
191
|
-
@opportunity =
|
191
|
+
@opportunity = create(:opportunity)
|
192
192
|
|
193
193
|
get :new, params: { related: "opportunity_#{@opportunity.id}" }, xhr: true
|
194
194
|
expect(assigns[:opportunity]).to eq(@opportunity)
|
@@ -196,7 +196,7 @@ describe ContactsController do
|
|
196
196
|
|
197
197
|
describe "(when creating related contact)" do
|
198
198
|
it "should redirect to parent asset's index page with the message if parent asset got deleted" do
|
199
|
-
@account =
|
199
|
+
@account = create(:account)
|
200
200
|
@account.destroy
|
201
201
|
|
202
202
|
get :new, params: { related: "account_#{@account.id}" }, xhr: true
|
@@ -205,7 +205,7 @@ describe ContactsController do
|
|
205
205
|
end
|
206
206
|
|
207
207
|
it "should redirect to parent asset's index page with the message if parent asset got protected" do
|
208
|
-
@account =
|
208
|
+
@account = create(:account, access: "Private")
|
209
209
|
|
210
210
|
get :new, params: { related: "account_#{@account.id}" }, xhr: true
|
211
211
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -219,7 +219,7 @@ describe ContactsController do
|
|
219
219
|
describe "responding to GET field_group" do
|
220
220
|
context "with an existing tag" do
|
221
221
|
before :each do
|
222
|
-
@tag =
|
222
|
+
@tag = create(:tag)
|
223
223
|
end
|
224
224
|
|
225
225
|
it "should return with an existing tag name" do
|
@@ -252,7 +252,7 @@ describe ContactsController do
|
|
252
252
|
#----------------------------------------------------------------------------
|
253
253
|
describe "responding to GET edit" do
|
254
254
|
it "should expose the requested contact as @contact and render [edit] template" do
|
255
|
-
@contact =
|
255
|
+
@contact = create(:contact, id: 42, user: current_user, lead: nil)
|
256
256
|
@account = Account.new(user: current_user)
|
257
257
|
|
258
258
|
get :edit, params: { id: 42 }, xhr: true
|
@@ -263,9 +263,9 @@ describe ContactsController do
|
|
263
263
|
end
|
264
264
|
|
265
265
|
it "should expose the requested contact as @contact and linked account as @account" do
|
266
|
-
@account =
|
267
|
-
@contact =
|
268
|
-
|
266
|
+
@account = create(:account, id: 99)
|
267
|
+
@contact = create(:contact, id: 42, user: current_user, lead: nil)
|
268
|
+
create(:account_contact, account: @account, contact: @contact)
|
269
269
|
|
270
270
|
get :edit, params: { id: 42 }, xhr: true
|
271
271
|
expect(assigns[:contact]).to eq(@contact)
|
@@ -273,8 +273,8 @@ describe ContactsController do
|
|
273
273
|
end
|
274
274
|
|
275
275
|
it "should expose previous contact as @previous when necessary" do
|
276
|
-
@contact =
|
277
|
-
@previous =
|
276
|
+
@contact = create(:contact, id: 42)
|
277
|
+
@previous = create(:contact, id: 1992)
|
278
278
|
|
279
279
|
get :edit, params: { id: 42, previous: 1992 }, xhr: true
|
280
280
|
expect(assigns[:previous]).to eq(@previous)
|
@@ -282,7 +282,7 @@ describe ContactsController do
|
|
282
282
|
|
283
283
|
describe "(contact got deleted or is otherwise unavailable)" do
|
284
284
|
it "should reload current page with the flash message if the contact got deleted" do
|
285
|
-
@contact =
|
285
|
+
@contact = create(:contact, user: current_user)
|
286
286
|
@contact.destroy
|
287
287
|
|
288
288
|
get :edit, params: { id: @contact.id }, xhr: true
|
@@ -291,7 +291,7 @@ describe ContactsController do
|
|
291
291
|
end
|
292
292
|
|
293
293
|
it "should reload current page with the flash message if the contact is protected" do
|
294
|
-
@private =
|
294
|
+
@private = create(:contact, user: create(:user), access: "Private")
|
295
295
|
|
296
296
|
get :edit, params: { id: @private.id }, xhr: true
|
297
297
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -301,8 +301,8 @@ describe ContactsController do
|
|
301
301
|
|
302
302
|
describe "(previous contact got deleted or is otherwise unavailable)" do
|
303
303
|
before(:each) do
|
304
|
-
@contact =
|
305
|
-
@previous =
|
304
|
+
@contact = create(:contact, user: current_user)
|
305
|
+
@previous = create(:contact, user: create(:user))
|
306
306
|
end
|
307
307
|
|
308
308
|
it "should notify the view if previous contact got deleted" do
|
@@ -331,7 +331,7 @@ describe ContactsController do
|
|
331
331
|
describe "responding to POST create" do
|
332
332
|
describe "with valid params" do
|
333
333
|
it "should expose a newly created contact as @contact and render [create] template" do
|
334
|
-
@contact =
|
334
|
+
@contact = build(:contact, first_name: "Billy", last_name: "Bones")
|
335
335
|
allow(Contact).to receive(:new).and_return(@contact)
|
336
336
|
|
337
337
|
post :create, params: { contact: { first_name: "Billy", last_name: "Bones" }, account: { name: "Hello world" } }, xhr: true
|
@@ -341,8 +341,8 @@ describe ContactsController do
|
|
341
341
|
end
|
342
342
|
|
343
343
|
it "should be able to associate newly created contact with the opportunity" do
|
344
|
-
@opportunity =
|
345
|
-
@contact =
|
344
|
+
@opportunity = create(:opportunity, id: 987)
|
345
|
+
@contact = build(:contact)
|
346
346
|
allow(Contact).to receive(:new).and_return(@contact)
|
347
347
|
|
348
348
|
post :create, params: { contact: { first_name: "Billy" }, account: {}, opportunity: 987 }, xhr: true
|
@@ -351,7 +351,7 @@ describe ContactsController do
|
|
351
351
|
end
|
352
352
|
|
353
353
|
it "should reload contacts to update pagination if called from contacts index" do
|
354
|
-
@contact =
|
354
|
+
@contact = build(:contact, user: current_user)
|
355
355
|
allow(Contact).to receive(:new).and_return(@contact)
|
356
356
|
|
357
357
|
request.env["HTTP_REFERER"] = "http://localhost/contacts"
|
@@ -360,7 +360,7 @@ describe ContactsController do
|
|
360
360
|
end
|
361
361
|
|
362
362
|
it "should add a new comment to the newly created contact when specified" do
|
363
|
-
@contact =
|
363
|
+
@contact = build(:contact, user: current_user)
|
364
364
|
allow(Contact).to receive(:new).and_return(@contact)
|
365
365
|
|
366
366
|
post :create, params: { contact: { first_name: "Testy", last_name: "McTest" }, account: { name: "Hello world" }, comment_body: "Awesome comment is awesome" }, xhr: true
|
@@ -370,13 +370,13 @@ describe ContactsController do
|
|
370
370
|
|
371
371
|
describe "with invalid params" do
|
372
372
|
before(:each) do
|
373
|
-
@contact =
|
373
|
+
@contact = build(:contact, first_name: nil, user: current_user, lead: nil)
|
374
374
|
allow(Contact).to receive(:new).and_return(@contact)
|
375
375
|
end
|
376
376
|
|
377
377
|
# Redraw [create] form with selected account.
|
378
378
|
it "should redraw [Create Contact] form with selected account" do
|
379
|
-
@account =
|
379
|
+
@account = create(:account, id: 42, user: current_user)
|
380
380
|
|
381
381
|
# This redraws [create] form with blank account.
|
382
382
|
post :create, params: { contact: {}, account: { id: 42, user_id: current_user.id } }, xhr: true
|
@@ -388,7 +388,7 @@ describe ContactsController do
|
|
388
388
|
|
389
389
|
# Redraw [create] form with related account.
|
390
390
|
it "should redraw [Create Contact] form with related account" do
|
391
|
-
@account =
|
391
|
+
@account = create(:account, id: 123, user: current_user)
|
392
392
|
|
393
393
|
request.env["HTTP_REFERER"] = "http://localhost/accounts/123"
|
394
394
|
post :create, params: { contact: { first_name: nil }, account: { name: nil, user_id: current_user.id } }, xhr: true
|
@@ -399,7 +399,7 @@ describe ContactsController do
|
|
399
399
|
end
|
400
400
|
|
401
401
|
it "should redraw [Create Contact] form with blank account" do
|
402
|
-
@accounts = [
|
402
|
+
@accounts = [create(:account, user: current_user)]
|
403
403
|
@account = Account.new(user: current_user)
|
404
404
|
|
405
405
|
post :create, params: { contact: { first_name: nil }, account: { name: nil, user_id: current_user.id } }, xhr: true
|
@@ -410,7 +410,7 @@ describe ContactsController do
|
|
410
410
|
end
|
411
411
|
|
412
412
|
it "should preserve Opportunity when called from Oppotuunity page" do
|
413
|
-
@opportunity =
|
413
|
+
@opportunity = create(:opportunity, id: 987)
|
414
414
|
|
415
415
|
post :create, params: { contact: {}, account: {}, opportunity: 987 }, xhr: true
|
416
416
|
expect(assigns(:opportunity)).to eq(@opportunity)
|
@@ -425,7 +425,7 @@ describe ContactsController do
|
|
425
425
|
describe "responding to PUT update" do
|
426
426
|
describe "with valid params" do
|
427
427
|
it "should update the requested contact and render [update] template" do
|
428
|
-
@contact =
|
428
|
+
@contact = create(:contact, id: 42, first_name: "Billy")
|
429
429
|
|
430
430
|
put :update, params: { id: 42, contact: { first_name: "Bones" }, account: {} }, xhr: true
|
431
431
|
expect(assigns[:contact].first_name).to eq("Bones")
|
@@ -434,7 +434,7 @@ describe ContactsController do
|
|
434
434
|
end
|
435
435
|
|
436
436
|
it "should be able to create a new account and link it to the contact" do
|
437
|
-
@contact =
|
437
|
+
@contact = create(:contact, id: 42, first_name: "Billy")
|
438
438
|
|
439
439
|
put :update, params: { id: 42, contact: { first_name: "Bones" }, account: { name: "new account" } }, xhr: true
|
440
440
|
expect(assigns[:contact].first_name).to eq("Bones")
|
@@ -442,8 +442,8 @@ describe ContactsController do
|
|
442
442
|
end
|
443
443
|
|
444
444
|
it "should be able to link existing account with the contact" do
|
445
|
-
@account =
|
446
|
-
@contact =
|
445
|
+
@account = create(:account, id: 99, name: "Hello world")
|
446
|
+
@contact = create(:contact, id: 42, first_name: "Billy")
|
447
447
|
|
448
448
|
put :update, params: { id: 42, contact: { first_name: "Bones" }, account: { id: 99 } }, xhr: true
|
449
449
|
expect(assigns[:contact].first_name).to eq("Bones")
|
@@ -451,7 +451,7 @@ describe ContactsController do
|
|
451
451
|
end
|
452
452
|
|
453
453
|
it "should update contact permissions when sharing with specific users" do
|
454
|
-
@contact =
|
454
|
+
@contact = create(:contact, id: 42, access: "Public")
|
455
455
|
|
456
456
|
put :update, params: { id: 42, contact: { first_name: "Hello", access: "Shared", user_ids: [7, 8] }, account: {} }, xhr: true
|
457
457
|
expect(assigns[:contact].access).to eq("Shared")
|
@@ -461,7 +461,7 @@ describe ContactsController do
|
|
461
461
|
|
462
462
|
describe "contact got deleted or otherwise unavailable" do
|
463
463
|
it "should reload current page is the contact got deleted" do
|
464
|
-
@contact =
|
464
|
+
@contact = create(:contact, user: current_user)
|
465
465
|
@contact.destroy
|
466
466
|
|
467
467
|
put :update, params: { id: @contact.id }, xhr: true
|
@@ -470,7 +470,7 @@ describe ContactsController do
|
|
470
470
|
end
|
471
471
|
|
472
472
|
it "should reload current page with the flash message if the contact is protected" do
|
473
|
-
@private =
|
473
|
+
@private = create(:contact, user: create(:user), access: "Private")
|
474
474
|
|
475
475
|
put :update, params: { id: @private.id }, xhr: true
|
476
476
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -481,7 +481,7 @@ describe ContactsController do
|
|
481
481
|
|
482
482
|
describe "with invalid params" do
|
483
483
|
it "should not update the contact, but still expose it as @contact and render [update] template" do
|
484
|
-
@contact =
|
484
|
+
@contact = create(:contact, id: 42, user: current_user, first_name: "Billy", lead: nil)
|
485
485
|
|
486
486
|
put :update, params: { id: 42, contact: { first_name: nil }, account: {} }, xhr: true
|
487
487
|
expect(assigns[:contact].reload.first_name).to eq("Billy")
|
@@ -490,8 +490,8 @@ describe ContactsController do
|
|
490
490
|
end
|
491
491
|
|
492
492
|
it "should expose existing account as @account if selected" do
|
493
|
-
@account =
|
494
|
-
@contact =
|
493
|
+
@account = create(:account, id: 99)
|
494
|
+
@contact = create(:contact, id: 42, account: @account)
|
495
495
|
|
496
496
|
put :update, params: { id: 42, contact: { first_name: nil }, account: { id: 99 } }, xhr: true
|
497
497
|
expect(assigns[:account]).to eq(@account)
|
@@ -504,7 +504,7 @@ describe ContactsController do
|
|
504
504
|
#----------------------------------------------------------------------------
|
505
505
|
describe "responding to DELETE destroy" do
|
506
506
|
before(:each) do
|
507
|
-
@contact =
|
507
|
+
@contact = create(:contact, user: current_user)
|
508
508
|
end
|
509
509
|
|
510
510
|
describe "AJAX request" do
|
@@ -549,7 +549,7 @@ describe ContactsController do
|
|
549
549
|
|
550
550
|
describe "contact got deleted or otherwise unavailable" do
|
551
551
|
it "should reload current page is the contact got deleted" do
|
552
|
-
@contact =
|
552
|
+
@contact = create(:contact, user: current_user)
|
553
553
|
@contact.destroy
|
554
554
|
|
555
555
|
delete :destroy, params: { id: @contact.id }, xhr: true
|
@@ -558,7 +558,7 @@ describe ContactsController do
|
|
558
558
|
end
|
559
559
|
|
560
560
|
it "should reload current page with the flash message if the contact is protected" do
|
561
|
-
@private =
|
561
|
+
@private = create(:contact, user: create(:user), access: "Private")
|
562
562
|
|
563
563
|
delete :destroy, params: { id: @private.id }, xhr: true
|
564
564
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -576,7 +576,7 @@ describe ContactsController do
|
|
576
576
|
end
|
577
577
|
|
578
578
|
it "should redirect to contact index with the flash message is the contact got deleted" do
|
579
|
-
@contact =
|
579
|
+
@contact = create(:contact, user: current_user)
|
580
580
|
@contact.destroy
|
581
581
|
|
582
582
|
delete :destroy, params: { id: @contact.id }
|
@@ -585,7 +585,7 @@ describe ContactsController do
|
|
585
585
|
end
|
586
586
|
|
587
587
|
it "should redirect to contact index with the flash message if the contact is protected" do
|
588
|
-
@private =
|
588
|
+
@private = create(:contact, user: create(:user), access: "Private")
|
589
589
|
|
590
590
|
delete :destroy, params: { id: @private.id }
|
591
591
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -600,16 +600,16 @@ describe ContactsController do
|
|
600
600
|
describe "responding to PUT attach" do
|
601
601
|
describe "tasks" do
|
602
602
|
before do
|
603
|
-
@model =
|
604
|
-
@attachment =
|
603
|
+
@model = create(:contact)
|
604
|
+
@attachment = create(:task, asset: nil)
|
605
605
|
end
|
606
606
|
it_should_behave_like("attach")
|
607
607
|
end
|
608
608
|
|
609
609
|
describe "opportunities" do
|
610
610
|
before do
|
611
|
-
@model =
|
612
|
-
@attachment =
|
611
|
+
@model = create(:contact)
|
612
|
+
@attachment = create(:opportunity)
|
613
613
|
end
|
614
614
|
it_should_behave_like("attach")
|
615
615
|
end
|
@@ -621,16 +621,16 @@ describe ContactsController do
|
|
621
621
|
describe "responding to PUT attach" do
|
622
622
|
describe "tasks" do
|
623
623
|
before do
|
624
|
-
@model =
|
625
|
-
@attachment =
|
624
|
+
@model = create(:contact)
|
625
|
+
@attachment = create(:task, asset: nil)
|
626
626
|
end
|
627
627
|
it_should_behave_like("attach")
|
628
628
|
end
|
629
629
|
|
630
630
|
describe "opportunities" do
|
631
631
|
before do
|
632
|
-
@model =
|
633
|
-
@attachment =
|
632
|
+
@model = create(:contact)
|
633
|
+
@attachment = create(:opportunity)
|
634
634
|
end
|
635
635
|
it_should_behave_like("attach")
|
636
636
|
end
|
@@ -642,16 +642,16 @@ describe ContactsController do
|
|
642
642
|
describe "responding to POST discard" do
|
643
643
|
describe "tasks" do
|
644
644
|
before do
|
645
|
-
@model =
|
646
|
-
@attachment =
|
645
|
+
@model = create(:contact)
|
646
|
+
@attachment = create(:task, asset: @model)
|
647
647
|
end
|
648
648
|
it_should_behave_like("discard")
|
649
649
|
end
|
650
650
|
|
651
651
|
describe "opportunities" do
|
652
652
|
before do
|
653
|
-
@attachment =
|
654
|
-
@model =
|
653
|
+
@attachment = create(:opportunity)
|
654
|
+
@model = create(:contact)
|
655
655
|
@model.opportunities << @attachment
|
656
656
|
end
|
657
657
|
it_should_behave_like("discard")
|
@@ -662,7 +662,7 @@ describe ContactsController do
|
|
662
662
|
#----------------------------------------------------------------------------
|
663
663
|
describe "responding to POST auto_complete" do
|
664
664
|
before(:each) do
|
665
|
-
@auto_complete_matches = [
|
665
|
+
@auto_complete_matches = [create(:contact, first_name: "Hello", last_name: "World", user: current_user)]
|
666
666
|
end
|
667
667
|
|
668
668
|
it_should_behave_like("auto complete")
|
@@ -692,8 +692,8 @@ describe ContactsController do
|
|
692
692
|
|
693
693
|
it "should select @contacts and render [index] template" do
|
694
694
|
@contacts = [
|
695
|
-
|
696
|
-
|
695
|
+
create(:contact, first_name: "Alice", user: current_user),
|
696
|
+
create(:contact, first_name: "Bobby", user: current_user)
|
697
697
|
]
|
698
698
|
|
699
699
|
get :redraw, params: { per_page: 1, sort_by: "first_name" }, xhr: true
|