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
@@ -34,7 +34,7 @@ describe AuthenticationsController do
|
|
34
34
|
|
35
35
|
describe "user must not be logged in" do
|
36
36
|
before(:each) do
|
37
|
-
@user =
|
37
|
+
@user = create(:user, username: "user", password: "pass", password_confirmation: "pass")
|
38
38
|
allow(@controller).to receive(:current_user).and_return(@user)
|
39
39
|
end
|
40
40
|
|
@@ -74,7 +74,7 @@ describe AuthenticationsController do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
it "displays welcome message and redirects to the home page" do
|
77
|
-
@user =
|
77
|
+
@user = create(:user, username: "user", password: "pass", password_confirmation: "pass", login_count: 0)
|
78
78
|
allow(@authentication).to receive(:user).and_return(@user)
|
79
79
|
|
80
80
|
post :create, params: { authentication: @login }
|
@@ -84,7 +84,7 @@ describe AuthenticationsController do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it "displays last login time if it's not the first login" do
|
87
|
-
@user =
|
87
|
+
@user = create(:user, username: "user", password: "pass", password_confirmation: "pass", login_count: 42)
|
88
88
|
allow(@authentication).to receive(:user).and_return(@user)
|
89
89
|
|
90
90
|
post :create, params: { authentication: @login }
|
@@ -96,7 +96,7 @@ describe AuthenticationsController do
|
|
96
96
|
describe "authenticaion failure" do
|
97
97
|
describe "user is not suspended" do
|
98
98
|
it "redirects to login page if username or password are invalid" do
|
99
|
-
@user =
|
99
|
+
@user = create(:user, username: "user", password: "pass", password_confirmation: "pass")
|
100
100
|
allow(@authentication).to receive(:user).and_return(@user)
|
101
101
|
allow(@authentication).to receive(:save).and_return(false) # <--- Authentication failure.
|
102
102
|
allow(Authentication).to receive(:new).and_return(@authentication)
|
@@ -115,7 +115,7 @@ describe AuthenticationsController do
|
|
115
115
|
|
116
116
|
# This tests :before_save update_info callback in Authentication model.
|
117
117
|
it "keeps user login attributes intact" do
|
118
|
-
@user =
|
118
|
+
@user = create(:user, username: "user", password: "pass", password_confirmation: "pass", suspended_at: Date.yesterday, login_count: 0, last_login_at: nil, last_login_ip: nil)
|
119
119
|
allow(@authentication).to receive(:user).and_return(@user)
|
120
120
|
|
121
121
|
post :create, params: { authentication: @login }
|
@@ -125,7 +125,7 @@ describe AuthenticationsController do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
it "redirects to login page if user is suspended" do
|
128
|
-
@user =
|
128
|
+
@user = create(:user, username: "user", password: "pass", password_confirmation: "pass", suspended_at: Date.yesterday)
|
129
129
|
allow(@authentication).to receive(:user).and_return(@user)
|
130
130
|
|
131
131
|
post :create, params: { authentication: @login }
|
@@ -136,7 +136,7 @@ describe AuthenticationsController do
|
|
136
136
|
|
137
137
|
it "redirects to login page with the message if signup needs approval and user hasn't been activated yet" do
|
138
138
|
allow(Setting).to receive(:user_signup).and_return(:needs_approval)
|
139
|
-
@user =
|
139
|
+
@user = create(:user, username: "user", password: "pass", password_confirmation: "pass", suspended_at: Date.yesterday, login_count: 0)
|
140
140
|
allow(@authentication).to receive(:user).and_return(@user)
|
141
141
|
|
142
142
|
post :create, params: { authentication: @login }
|
@@ -21,7 +21,7 @@ describe CommentsController do
|
|
21
21
|
COMMENTABLE.each do |asset|
|
22
22
|
describe "(HTML)" do
|
23
23
|
before(:each) do
|
24
|
-
@asset =
|
24
|
+
@asset = create(asset)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should redirect to the asset landing page if the asset is found" do
|
@@ -38,8 +38,8 @@ describe CommentsController do
|
|
38
38
|
|
39
39
|
describe "(JSON)" do
|
40
40
|
before(:each) do
|
41
|
-
@asset =
|
42
|
-
@asset.comments = [
|
41
|
+
@asset = create(asset)
|
42
|
+
@asset.comments = [create(:comment, commentable: @asset)]
|
43
43
|
request.env["HTTP_ACCEPT"] = "application/json"
|
44
44
|
end
|
45
45
|
|
@@ -57,8 +57,8 @@ describe CommentsController do
|
|
57
57
|
|
58
58
|
describe "(XML)" do
|
59
59
|
before(:each) do
|
60
|
-
@asset =
|
61
|
-
@asset.comments = [
|
60
|
+
@asset = create(asset)
|
61
|
+
@asset.comments = [create(:comment, commentable: @asset)]
|
62
62
|
request.env["HTTP_ACCEPT"] = "application/xml"
|
63
63
|
end
|
64
64
|
|
@@ -81,8 +81,8 @@ describe CommentsController do
|
|
81
81
|
describe "responding to GET edit" do
|
82
82
|
COMMENTABLE.each do |asset|
|
83
83
|
it "should expose the requested comment as @commment and render [edit] template" do
|
84
|
-
@asset =
|
85
|
-
@comment =
|
84
|
+
@asset = create(asset)
|
85
|
+
@comment = create(:comment, id: 42, commentable: @asset, user: current_user)
|
86
86
|
allow(Comment).to receive(:new).and_return(@comment)
|
87
87
|
|
88
88
|
get :edit, params: { id: 42 }, xhr: true
|
@@ -99,8 +99,8 @@ describe CommentsController do
|
|
99
99
|
describe "with valid params" do
|
100
100
|
COMMENTABLE.each do |asset|
|
101
101
|
it "should expose a newly created comment as @comment for the #{asset}" do
|
102
|
-
@asset =
|
103
|
-
@comment =
|
102
|
+
@asset = create(asset)
|
103
|
+
@comment = build(:comment, commentable: @asset, user: current_user)
|
104
104
|
allow(Comment).to receive(:new).and_return(@comment)
|
105
105
|
|
106
106
|
post :create, params: { comment: { commentable_type: asset.to_s.classify, commentable_id: @asset.id, user_id: current_user.id, comment: "Hello" } }, xhr: true
|
@@ -113,8 +113,8 @@ describe CommentsController do
|
|
113
113
|
describe "with invalid params" do
|
114
114
|
COMMENTABLE.each do |asset|
|
115
115
|
it "should expose a newly created but unsaved comment as @comment for #{asset}" do
|
116
|
-
@asset =
|
117
|
-
@comment =
|
116
|
+
@asset = create(asset)
|
117
|
+
@comment = build(:comment, commentable: @asset, user: current_user)
|
118
118
|
allow(Comment).to receive(:new).and_return(@comment)
|
119
119
|
|
120
120
|
post :create, params: { comment: {} }, xhr: true
|
@@ -180,8 +180,8 @@ describe CommentsController do
|
|
180
180
|
describe "with valid params" do
|
181
181
|
COMMENTABLE.each do |asset|
|
182
182
|
it "should destroy the requested comment and render [destroy] template" do
|
183
|
-
@asset =
|
184
|
-
@comment =
|
183
|
+
@asset = create(asset)
|
184
|
+
@comment = create(:comment, commentable: @asset, user: current_user)
|
185
185
|
allow(Comment).to receive(:new).and_return(@comment)
|
186
186
|
|
187
187
|
delete :destroy, params: { id: @comment.id }, xhr: true
|
@@ -22,8 +22,8 @@ describe EmailsController, "handling GET /emails" do
|
|
22
22
|
describe "with valid params" do
|
23
23
|
MEDIATOR.each do |asset|
|
24
24
|
it "should destroy the requested email and render [destroy] template" do
|
25
|
-
@asset =
|
26
|
-
@email =
|
25
|
+
@asset = create(asset)
|
26
|
+
@email = create(:email, mediator: @asset, user: current_user)
|
27
27
|
allow(Email).to receive(:new).and_return(@email)
|
28
28
|
|
29
29
|
delete :destroy, params: { id: @email.id }, xhr: true
|
@@ -26,14 +26,14 @@ describe AccountsController do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should expose all accounts as @accounts and render [index] template" do
|
29
|
-
@accounts = [
|
29
|
+
@accounts = [create(:account, user: current_user)]
|
30
30
|
get :index
|
31
31
|
expect(assigns[:accounts]).to eq(@accounts)
|
32
32
|
expect(response).to render_template("accounts/index")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should collect the data for the accounts sidebar" do
|
36
|
-
@accounts = [
|
36
|
+
@accounts = [create(:account, user: current_user)]
|
37
37
|
|
38
38
|
get :index
|
39
39
|
expect(assigns[:account_category_total].keys.map(&:to_sym) - (@category << :all << :other)).to eq([])
|
@@ -43,19 +43,19 @@ describe AccountsController do
|
|
43
43
|
categories = %w[customer vendor]
|
44
44
|
controller.session[:accounts_filter] = categories.join(',')
|
45
45
|
@accounts = [
|
46
|
-
|
47
|
-
|
46
|
+
create(:account, user: current_user, category: categories.first),
|
47
|
+
create(:account, user: current_user, category: categories.last)
|
48
48
|
]
|
49
49
|
# This one should be filtered out.
|
50
|
-
|
50
|
+
create(:account, user: current_user, category: "competitor")
|
51
51
|
|
52
52
|
get :index
|
53
53
|
expect(assigns[:accounts]).to eq(@accounts)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should perform lookup using query string" do
|
57
|
-
@first =
|
58
|
-
@second =
|
57
|
+
@first = create(:account, user: current_user, name: "The first one")
|
58
|
+
@second = create(:account, user: current_user, name: "The second one")
|
59
59
|
|
60
60
|
get :index, params: { query: "second" }
|
61
61
|
expect(assigns[:accounts]).to eq([@second])
|
@@ -65,7 +65,7 @@ describe AccountsController do
|
|
65
65
|
|
66
66
|
describe "AJAX pagination" do
|
67
67
|
it "should pick up page number from params" do
|
68
|
-
@accounts = [
|
68
|
+
@accounts = [create(:account, user: current_user)]
|
69
69
|
get :index, params: { page: 42 }, xhr: true
|
70
70
|
|
71
71
|
expect(assigns[:current_page].to_i).to eq(42)
|
@@ -76,7 +76,7 @@ describe AccountsController do
|
|
76
76
|
|
77
77
|
it "should pick up saved page number from session" do
|
78
78
|
session[:accounts_current_page] = 42
|
79
|
-
@accounts = [
|
79
|
+
@accounts = [create(:account, user: current_user)]
|
80
80
|
get :index, xhr: true
|
81
81
|
|
82
82
|
expect(assigns[:current_page]).to eq(42)
|
@@ -87,7 +87,7 @@ describe AccountsController do
|
|
87
87
|
it "should reset current_page when query is altered" do
|
88
88
|
session[:accounts_current_page] = 42
|
89
89
|
session[:accounts_current_query] = "bill"
|
90
|
-
@accounts = [
|
90
|
+
@accounts = [create(:account, user: current_user)]
|
91
91
|
get :index, xhr: true
|
92
92
|
|
93
93
|
expect(assigns[:current_page]).to eq(1)
|
@@ -125,7 +125,7 @@ describe AccountsController do
|
|
125
125
|
describe "responding to GET show" do
|
126
126
|
describe "with mime type of HTML" do
|
127
127
|
before do
|
128
|
-
@account =
|
128
|
+
@account = create(:account, user: current_user)
|
129
129
|
@stage = Setting.unroll(:opportunity_stage)
|
130
130
|
@comment = Comment.new
|
131
131
|
end
|
@@ -146,7 +146,7 @@ describe AccountsController do
|
|
146
146
|
|
147
147
|
describe "with mime type of JSON" do
|
148
148
|
it "should render the requested account as json" do
|
149
|
-
@account =
|
149
|
+
@account = create(:account, user: current_user)
|
150
150
|
expect(Account).to receive(:find).and_return(@account)
|
151
151
|
expect(@account).to receive(:to_json).and_return("generated JSON")
|
152
152
|
|
@@ -158,7 +158,7 @@ describe AccountsController do
|
|
158
158
|
|
159
159
|
describe "with mime type of XML" do
|
160
160
|
it "should render the requested account as xml" do
|
161
|
-
@account =
|
161
|
+
@account = create(:account, user: current_user)
|
162
162
|
expect(Account).to receive(:find).and_return(@account)
|
163
163
|
expect(@account).to receive(:to_xml).and_return("generated XML")
|
164
164
|
|
@@ -170,7 +170,7 @@ describe AccountsController do
|
|
170
170
|
|
171
171
|
describe "account got deleted or otherwise unavailable" do
|
172
172
|
it "should redirect to account index if the account got deleted" do
|
173
|
-
@account =
|
173
|
+
@account = create(:account, user: current_user)
|
174
174
|
@account.destroy
|
175
175
|
|
176
176
|
get :show, params: { id: @account.id }
|
@@ -179,7 +179,7 @@ describe AccountsController do
|
|
179
179
|
end
|
180
180
|
|
181
181
|
it "should redirect to account index if the account is protected" do
|
182
|
-
@private =
|
182
|
+
@private = create(:account, user: create(:user), access: "Private")
|
183
183
|
|
184
184
|
get :show, params: { id: @private.id }
|
185
185
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -187,7 +187,7 @@ describe AccountsController do
|
|
187
187
|
end
|
188
188
|
|
189
189
|
it "should return 404 (Not Found) JSON error" do
|
190
|
-
@account =
|
190
|
+
@account = create(:account, user: current_user)
|
191
191
|
@account.destroy
|
192
192
|
request.env["HTTP_ACCEPT"] = "application/json"
|
193
193
|
|
@@ -196,7 +196,7 @@ describe AccountsController do
|
|
196
196
|
end
|
197
197
|
|
198
198
|
it "should return 404 (Not Found) XML error" do
|
199
|
-
@account =
|
199
|
+
@account = create(:account, user: current_user)
|
200
200
|
@account.destroy
|
201
201
|
request.env["HTTP_ACCEPT"] = "application/xml"
|
202
202
|
|
@@ -220,7 +220,7 @@ describe AccountsController do
|
|
220
220
|
end
|
221
221
|
|
222
222
|
it "should created an instance of related object when necessary" do
|
223
|
-
@contact =
|
223
|
+
@contact = create(:contact, id: 42)
|
224
224
|
|
225
225
|
get :new, params: { related: "contact_42" }, xhr: true
|
226
226
|
expect(assigns[:contact]).to eq(@contact)
|
@@ -231,7 +231,7 @@ describe AccountsController do
|
|
231
231
|
#----------------------------------------------------------------------------
|
232
232
|
describe "responding to GET edit" do
|
233
233
|
it "should expose the requested account as @account and render [edit] template" do
|
234
|
-
@account =
|
234
|
+
@account = create(:account, id: 42, user: current_user)
|
235
235
|
|
236
236
|
get :edit, params: { id: 42 }, xhr: true
|
237
237
|
expect(assigns[:account]).to eq(@account)
|
@@ -240,8 +240,8 @@ describe AccountsController do
|
|
240
240
|
end
|
241
241
|
|
242
242
|
it "should expose previous account as @previous when necessary" do
|
243
|
-
@account =
|
244
|
-
@previous =
|
243
|
+
@account = create(:account, id: 42)
|
244
|
+
@previous = create(:account, id: 41)
|
245
245
|
|
246
246
|
get :edit, params: { id: 42, previous: 41 }, xhr: true
|
247
247
|
expect(assigns[:previous]).to eq(@previous)
|
@@ -249,7 +249,7 @@ describe AccountsController do
|
|
249
249
|
|
250
250
|
describe "(account got deleted or is otherwise unavailable)" do
|
251
251
|
it "should reload current page with the flash message if the account got deleted" do
|
252
|
-
@account =
|
252
|
+
@account = create(:account, user: current_user)
|
253
253
|
@account.destroy
|
254
254
|
|
255
255
|
get :edit, params: { id: @account.id }, xhr: true
|
@@ -258,7 +258,7 @@ describe AccountsController do
|
|
258
258
|
end
|
259
259
|
|
260
260
|
it "should reload current page with the flash message if the account is protected" do
|
261
|
-
@private =
|
261
|
+
@private = create(:account, user: create(:user), access: "Private")
|
262
262
|
|
263
263
|
get :edit, params: { id: @private.id }, xhr: true
|
264
264
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -268,8 +268,8 @@ describe AccountsController do
|
|
268
268
|
|
269
269
|
describe "(previous account got deleted or is otherwise unavailable)" do
|
270
270
|
before do
|
271
|
-
@account =
|
272
|
-
@previous =
|
271
|
+
@account = create(:account, user: current_user)
|
272
|
+
@previous = create(:account, user: create(:user))
|
273
273
|
end
|
274
274
|
|
275
275
|
it "should notify the view if previous account got deleted" do
|
@@ -298,7 +298,7 @@ describe AccountsController do
|
|
298
298
|
describe "responding to POST create" do
|
299
299
|
describe "with valid params" do
|
300
300
|
it "should expose a newly created account as @account and render [create] template" do
|
301
|
-
@account =
|
301
|
+
@account = build(:account, name: "Hello world", user: current_user)
|
302
302
|
allow(Account).to receive(:new).and_return(@account)
|
303
303
|
|
304
304
|
post :create, params: { account: { name: "Hello world" } }, xhr: true
|
@@ -308,7 +308,7 @@ describe AccountsController do
|
|
308
308
|
|
309
309
|
# Note: [Create Account] is shown only on Accounts index page.
|
310
310
|
it "should reload accounts to update pagination" do
|
311
|
-
@account =
|
311
|
+
@account = build(:account, user: current_user)
|
312
312
|
allow(Account).to receive(:new).and_return(@account)
|
313
313
|
|
314
314
|
post :create, params: { account: { name: "Hello" } }, xhr: true
|
@@ -316,7 +316,7 @@ describe AccountsController do
|
|
316
316
|
end
|
317
317
|
|
318
318
|
it "should get data to update account sidebar" do
|
319
|
-
@account =
|
319
|
+
@account = build(:account, name: "Hello", user: current_user)
|
320
320
|
allow(Campaign).to receive(:new).and_return(@account)
|
321
321
|
|
322
322
|
post :create, params: { account: { name: "Hello" } }, xhr: true
|
@@ -324,7 +324,7 @@ describe AccountsController do
|
|
324
324
|
end
|
325
325
|
|
326
326
|
it "should add a new comment to the newly created account when specified" do
|
327
|
-
@account =
|
327
|
+
@account = build(:account, name: "Hello world", user: current_user)
|
328
328
|
allow(Account).to receive(:new).and_return(@account)
|
329
329
|
|
330
330
|
post :create, params: { account: { name: "Hello world" }, comment_body: "Awesome comment is awesome" }, xhr: true
|
@@ -334,7 +334,7 @@ describe AccountsController do
|
|
334
334
|
|
335
335
|
describe "with invalid params" do
|
336
336
|
it "should expose a newly created but unsaved account as @account and still render [create] template" do
|
337
|
-
@account =
|
337
|
+
@account = build(:account, name: nil, user: nil)
|
338
338
|
allow(Account).to receive(:new).and_return(@account)
|
339
339
|
|
340
340
|
post :create, params: { account: {} }, xhr: true
|
@@ -350,7 +350,7 @@ describe AccountsController do
|
|
350
350
|
describe "responding to PUT update" do
|
351
351
|
describe "with valid params" do
|
352
352
|
it "should update the requested account, expose the requested account as @account, and render [update] template" do
|
353
|
-
@account =
|
353
|
+
@account = create(:account, id: 42, name: "Hello people")
|
354
354
|
|
355
355
|
put :update, params: { id: 42, account: { name: "Hello world" } }, xhr: true
|
356
356
|
expect(@account.reload.name).to eq("Hello world")
|
@@ -359,7 +359,7 @@ describe AccountsController do
|
|
359
359
|
end
|
360
360
|
|
361
361
|
it "should get data for accounts sidebar when called from Campaigns index" do
|
362
|
-
@account =
|
362
|
+
@account = create(:account, id: 42)
|
363
363
|
request.env["HTTP_REFERER"] = "http://localhost/accounts"
|
364
364
|
|
365
365
|
put :update, params: { id: 42, account: { name: "Hello" } }, xhr: true
|
@@ -368,7 +368,7 @@ describe AccountsController do
|
|
368
368
|
end
|
369
369
|
|
370
370
|
it "should update account permissions when sharing with specific users" do
|
371
|
-
@account =
|
371
|
+
@account = create(:account, id: 42, access: "Public")
|
372
372
|
|
373
373
|
put :update, params: { id: 42, account: { name: "Hello", access: "Shared", user_ids: [7, 8] } }, xhr: true
|
374
374
|
expect(assigns[:account].access).to eq("Shared")
|
@@ -377,7 +377,7 @@ describe AccountsController do
|
|
377
377
|
|
378
378
|
describe "account got deleted or otherwise unavailable" do
|
379
379
|
it "should reload current page is the account got deleted" do
|
380
|
-
@account =
|
380
|
+
@account = create(:account, user: current_user)
|
381
381
|
@account.destroy
|
382
382
|
|
383
383
|
put :update, params: { id: @account.id }, xhr: true
|
@@ -386,7 +386,7 @@ describe AccountsController do
|
|
386
386
|
end
|
387
387
|
|
388
388
|
it "should reload current page with the flash message if the account is protected" do
|
389
|
-
@private =
|
389
|
+
@private = create(:account, user: create(:user), access: "Private")
|
390
390
|
|
391
391
|
put :update, params: { id: @private.id }, xhr: true
|
392
392
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -397,7 +397,7 @@ describe AccountsController do
|
|
397
397
|
|
398
398
|
describe "with invalid params" do
|
399
399
|
it "should not update the requested account but still expose the requested account as @account, and render [update] template" do
|
400
|
-
@account =
|
400
|
+
@account = create(:account, id: 42, name: "Hello people")
|
401
401
|
|
402
402
|
put :update, params: { id: 42, account: { name: nil } }, xhr: true
|
403
403
|
expect(assigns(:account).reload.name).to eq("Hello people")
|
@@ -412,12 +412,12 @@ describe AccountsController do
|
|
412
412
|
#----------------------------------------------------------------------------
|
413
413
|
describe "responding to DELETE destroy" do
|
414
414
|
before do
|
415
|
-
@account =
|
415
|
+
@account = create(:account, user: current_user)
|
416
416
|
end
|
417
417
|
|
418
418
|
describe "AJAX request" do
|
419
419
|
it "should destroy the requested account and render [destroy] template" do
|
420
|
-
@another_account =
|
420
|
+
@another_account = create(:account, user: current_user)
|
421
421
|
delete :destroy, params: { id: @account.id }, xhr: true
|
422
422
|
|
423
423
|
expect { Account.find(@account.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
@@ -449,7 +449,7 @@ describe AccountsController do
|
|
449
449
|
|
450
450
|
describe "account got deleted or otherwise unavailable" do
|
451
451
|
it "should reload current page is the account got deleted" do
|
452
|
-
@account =
|
452
|
+
@account = create(:account, user: current_user)
|
453
453
|
@account.destroy
|
454
454
|
|
455
455
|
delete :destroy, params: { id: @account.id }, xhr: true
|
@@ -458,7 +458,7 @@ describe AccountsController do
|
|
458
458
|
end
|
459
459
|
|
460
460
|
it "should reload current page with the flash message if the account is protected" do
|
461
|
-
@private =
|
461
|
+
@private = create(:account, user: create(:user), access: "Private")
|
462
462
|
|
463
463
|
delete :destroy, params: { id: @private.id }, xhr: true
|
464
464
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -476,7 +476,7 @@ describe AccountsController do
|
|
476
476
|
end
|
477
477
|
|
478
478
|
it "should redirect to account index with the flash message is the account got deleted" do
|
479
|
-
@account =
|
479
|
+
@account = create(:account, user: current_user)
|
480
480
|
@account.destroy
|
481
481
|
|
482
482
|
delete :destroy, params: { id: @account.id }
|
@@ -485,7 +485,7 @@ describe AccountsController do
|
|
485
485
|
end
|
486
486
|
|
487
487
|
it "should redirect to account index with the flash message if the account is protected" do
|
488
|
-
@private =
|
488
|
+
@private = create(:account, user: create(:user), access: "Private")
|
489
489
|
|
490
490
|
delete :destroy, params: { id: @private.id }
|
491
491
|
expect(flash[:warning]).not_to eq(nil)
|
@@ -500,16 +500,16 @@ describe AccountsController do
|
|
500
500
|
describe "responding to PUT attach" do
|
501
501
|
describe "tasks" do
|
502
502
|
before do
|
503
|
-
@model =
|
504
|
-
@attachment =
|
503
|
+
@model = create(:account)
|
504
|
+
@attachment = create(:task, asset: nil)
|
505
505
|
end
|
506
506
|
it_should_behave_like("attach")
|
507
507
|
end
|
508
508
|
|
509
509
|
describe "contacts" do
|
510
510
|
before do
|
511
|
-
@model =
|
512
|
-
@attachment =
|
511
|
+
@model = create(:account)
|
512
|
+
@attachment = create(:contact, account: nil)
|
513
513
|
end
|
514
514
|
it_should_behave_like("attach")
|
515
515
|
end
|
@@ -521,16 +521,16 @@ describe AccountsController do
|
|
521
521
|
describe "responding to POST discard" do
|
522
522
|
describe "tasks" do
|
523
523
|
before do
|
524
|
-
@model =
|
525
|
-
@attachment =
|
524
|
+
@model = create(:account)
|
525
|
+
@attachment = create(:task, asset: @model)
|
526
526
|
end
|
527
527
|
it_should_behave_like("discard")
|
528
528
|
end
|
529
529
|
|
530
530
|
describe "contacts" do
|
531
531
|
before do
|
532
|
-
@attachment =
|
533
|
-
@model =
|
532
|
+
@attachment = create(:contact)
|
533
|
+
@model = create(:account)
|
534
534
|
@model.contacts << @attachment
|
535
535
|
end
|
536
536
|
it_should_behave_like("discard")
|
@@ -538,8 +538,8 @@ describe AccountsController do
|
|
538
538
|
|
539
539
|
describe "opportunities" do
|
540
540
|
before do
|
541
|
-
@attachment =
|
542
|
-
@model =
|
541
|
+
@attachment = create(:opportunity)
|
542
|
+
@model = create(:account)
|
543
543
|
@model.opportunities << @attachment
|
544
544
|
end
|
545
545
|
# 'super from singleton method that is defined to multiple classes is not supported;'
|
@@ -552,7 +552,7 @@ describe AccountsController do
|
|
552
552
|
#----------------------------------------------------------------------------
|
553
553
|
describe "responding to POST auto_complete" do
|
554
554
|
before do
|
555
|
-
@auto_complete_matches = [
|
555
|
+
@auto_complete_matches = [create(:account, name: "Hello World", user: current_user)]
|
556
556
|
end
|
557
557
|
|
558
558
|
it_should_behave_like("auto complete")
|
@@ -575,8 +575,8 @@ describe AccountsController do
|
|
575
575
|
|
576
576
|
it "should select @accounts and render [index] template" do
|
577
577
|
@accounts = [
|
578
|
-
|
579
|
-
|
578
|
+
create(:account, name: "A", user: current_user),
|
579
|
+
create(:account, name: "B", user: current_user)
|
580
580
|
]
|
581
581
|
|
582
582
|
get :redraw, params: { per_page: 1, sort_by: "name" }, xhr: true
|
@@ -590,7 +590,7 @@ describe AccountsController do
|
|
590
590
|
describe "responding to POST filter" do
|
591
591
|
it "should expose filtered accounts as @accounts and render [index] template" do
|
592
592
|
session[:accounts_filter] = "customer,vendor"
|
593
|
-
@accounts = [
|
593
|
+
@accounts = [create(:account, category: "partner", user: current_user)]
|
594
594
|
|
595
595
|
post :filter, params: { category: "partner" }, xhr: true
|
596
596
|
expect(assigns(:accounts)).to eq(@accounts)
|