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
data/spec/models/list_spec.rb
CHANGED
@@ -10,10 +10,10 @@ require 'spec_helper'
|
|
10
10
|
describe List do
|
11
11
|
it "should parse the controller from the url" do
|
12
12
|
["/controller/action", "controller/action?utf8=%E2%9C%93"].each do |url|
|
13
|
-
list =
|
13
|
+
list = build(:list, url: url)
|
14
14
|
expect(list.controller).to eq("controller")
|
15
15
|
end
|
16
|
-
list =
|
16
|
+
list = build(:list, url: nil)
|
17
17
|
expect(list.controller).to eq(nil)
|
18
18
|
end
|
19
19
|
end
|
@@ -15,9 +15,9 @@ describe EntityObserver do
|
|
15
15
|
|
16
16
|
%i[account contact lead opportunity].each do |entity_type|
|
17
17
|
describe "on creation of #{entity_type}" do
|
18
|
-
let(:assignee) {
|
19
|
-
let(:assigner) {
|
20
|
-
let!(:entity) {
|
18
|
+
let(:assignee) { create(:user) }
|
19
|
+
let(:assigner) { create(:user) }
|
20
|
+
let!(:entity) { build(entity_type, user: assigner, assignee: assignee) }
|
21
21
|
let(:mail) { double('mail', deliver_now: true) }
|
22
22
|
|
23
23
|
after :each do
|
@@ -45,9 +45,9 @@ describe EntityObserver do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "on update of #{entity_type}" do
|
48
|
-
let(:assignee) {
|
49
|
-
let(:assigner) {
|
50
|
-
let!(:entity) {
|
48
|
+
let(:assignee) { create(:user) }
|
49
|
+
let(:assigner) { create(:user) }
|
50
|
+
let!(:entity) { create(entity_type, user: create(:user)) }
|
51
51
|
let(:mail) { double('mail', deliver_now: true) }
|
52
52
|
|
53
53
|
it "notifies the new owner if the entity is re-assigned" do
|
@@ -29,6 +29,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
29
29
|
|
30
30
|
describe Address do
|
31
31
|
it "should create a new instance given valid attributes" do
|
32
|
-
Address.create!(street1: "street1", street2: "street2", city: "city", state: "state", zipcode: "zipcode", country: "country", full_address: "fa", address_type: "Lead", addressable:
|
32
|
+
Address.create!(street1: "street1", street2: "street2", city: "city", state: "state", zipcode: "zipcode", country: "country", full_address: "fa", address_type: "Lead", addressable: create(:lead))
|
33
33
|
end
|
34
34
|
end
|
@@ -24,22 +24,22 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
24
24
|
|
25
25
|
describe Avatar do
|
26
26
|
before(:each) do
|
27
|
-
@user =
|
27
|
+
@user = create(:user)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should create a new instance given valid attributes" do
|
31
|
-
expect(
|
31
|
+
expect(create(:avatar, entity: @user)).to be_valid
|
32
32
|
end
|
33
33
|
|
34
34
|
it "user should have one avatar as entity" do
|
35
|
-
avatar =
|
35
|
+
avatar = create(:avatar, entity: @user)
|
36
36
|
expect(@user.avatar).to eq(avatar)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "user might have many avatars as owner" do
|
40
40
|
avatars = [
|
41
|
-
|
42
|
-
|
41
|
+
create(:avatar, user: @user, entity: create(:user)),
|
42
|
+
create(:avatar, user: @user, entity: create(:user))
|
43
43
|
]
|
44
44
|
expect(@user.avatars).to eq(avatars)
|
45
45
|
end
|
@@ -25,17 +25,17 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
25
25
|
|
26
26
|
describe Comment do
|
27
27
|
it "should create a new instance given valid attributes" do
|
28
|
-
Comment.create!(comment: "Hello", user:
|
28
|
+
Comment.create!(comment: "Hello", user: create(:user), commentable: create(:lead))
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should subscribe users mentioned in the comment to the entity, and notify them via email" do
|
32
32
|
expected_users = [
|
33
|
-
|
34
|
-
|
33
|
+
create(:user, username: "test_user"),
|
34
|
+
create(:user, username: "another_user")
|
35
35
|
]
|
36
|
-
entity =
|
36
|
+
entity = create(:lead)
|
37
37
|
Comment.create!(comment: "Hey @test_user, take a look at this. Also show @another_user",
|
38
|
-
user:
|
38
|
+
user: create(:user),
|
39
39
|
commentable: entity)
|
40
40
|
|
41
41
|
expected_users.each do |user|
|
@@ -32,11 +32,9 @@
|
|
32
32
|
require 'spec_helper'
|
33
33
|
|
34
34
|
describe Task do
|
35
|
-
let(:current_user) { FactoryGirl.create(:user) }
|
36
|
-
|
37
35
|
describe "Task/Create" do
|
38
36
|
it "should create a new task instance given valid attributes" do
|
39
|
-
task =
|
37
|
+
task = create(:task)
|
40
38
|
expect(task).to be_valid
|
41
39
|
expect(task.errors).to be_empty
|
42
40
|
end
|
@@ -47,14 +45,14 @@ describe Task do
|
|
47
45
|
end
|
48
46
|
|
49
47
|
it "should create a task with due date selected from dropdown within #{offset ? 'different' : 'current'} timezone" do
|
50
|
-
task =
|
48
|
+
task = create(:task, due_at: Time.now.end_of_week, bucket: "due_this_week")
|
51
49
|
expect(task.errors).to be_empty
|
52
50
|
expect(task.bucket).to eq("due_this_week")
|
53
51
|
expect(task.due_at.change(usec: 0)).to eq(Time.zone.now.end_of_week.change(usec: 0))
|
54
52
|
end
|
55
53
|
|
56
54
|
it "should create a task with due date selected from the calendar within #{offset ? 'different' : 'current'} timezone" do
|
57
|
-
task =
|
55
|
+
task = create(:task, bucket: "specific_time", calendar: "2020-03-20")
|
58
56
|
expect(task.errors).to be_empty
|
59
57
|
expect(task.bucket).to eq("specific_time")
|
60
58
|
expect(task.due_at.to_i).to eq(Time.parse("2020-03-20").to_i)
|
@@ -64,23 +62,23 @@ describe Task do
|
|
64
62
|
|
65
63
|
describe "Task/Update" do
|
66
64
|
it "should update task name" do
|
67
|
-
task =
|
65
|
+
task = create(:task, name: "Hello")
|
68
66
|
task.update_attributes(name: "World")
|
69
67
|
expect(task.errors).to be_empty
|
70
68
|
expect(task.name).to eq("World")
|
71
69
|
end
|
72
70
|
|
73
71
|
it "should update task category" do
|
74
|
-
task =
|
72
|
+
task = create(:task, category: "call")
|
75
73
|
task.update_attributes(category: "email")
|
76
74
|
expect(task.errors).to be_empty
|
77
75
|
expect(task.category).to eq("email")
|
78
76
|
end
|
79
77
|
|
80
78
|
it "should reassign the task to another person" do
|
81
|
-
him =
|
82
|
-
her =
|
83
|
-
task =
|
79
|
+
him = create(:user)
|
80
|
+
her = create(:user)
|
81
|
+
task = create(:task, assigned_to: him.id)
|
84
82
|
task.update_attributes(assigned_to: her.id)
|
85
83
|
expect(task.errors).to be_empty
|
86
84
|
expect(task.assigned_to).to eq(her.id)
|
@@ -88,8 +86,8 @@ describe Task do
|
|
88
86
|
end
|
89
87
|
|
90
88
|
it "should reassign the task from another person to myself" do
|
91
|
-
him =
|
92
|
-
task =
|
89
|
+
him = create(:user)
|
90
|
+
task = create(:task, assigned_to: him.id)
|
93
91
|
task.update_attributes(assigned_to: "")
|
94
92
|
expect(task.errors).to be_empty
|
95
93
|
expect(task.assigned_to).to eq(nil)
|
@@ -102,7 +100,7 @@ describe Task do
|
|
102
100
|
end
|
103
101
|
|
104
102
|
it "should update due date based on selected bucket within #{offset ? 'different' : 'current'} timezone" do
|
105
|
-
task =
|
103
|
+
task = create(:task, due_at: Time.now.midnight.tomorrow, bucket: "due_tomorrow")
|
106
104
|
task.update_attributes(bucket: "due_this_week")
|
107
105
|
expect(task.errors).to be_empty
|
108
106
|
expect(task.bucket).to eq("due_this_week")
|
@@ -110,7 +108,7 @@ describe Task do
|
|
110
108
|
end
|
111
109
|
|
112
110
|
it "should update due date if specific calendar date selected within #{offset ? 'different' : 'current'} timezone" do
|
113
|
-
task =
|
111
|
+
task = create(:task, due_at: Time.now.midnight.tomorrow, bucket: "due_tomorrow")
|
114
112
|
task.update_attributes(bucket: "specific_time", calendar: "2020-03-20")
|
115
113
|
expect(task.errors).to be_empty
|
116
114
|
expect(task.bucket).to eq("specific_time")
|
@@ -120,45 +118,48 @@ describe Task do
|
|
120
118
|
end
|
121
119
|
|
122
120
|
describe "Task/Complete" do
|
123
|
-
it "should
|
124
|
-
task =
|
125
|
-
task.update_attributes(completed_at: Time.now, completed_by:
|
121
|
+
it "should complete a task that is overdue" do
|
122
|
+
task = create(:task, due_at: 2.days.ago, bucket: "overdue")
|
123
|
+
task.update_attributes(completed_at: Time.now, completed_by: task.user.id)
|
124
|
+
|
126
125
|
expect(task.errors).to be_empty
|
127
126
|
expect(task.completed_at).not_to eq(nil)
|
128
|
-
expect(task.completor).to eq(
|
127
|
+
expect(task.completor).to eq(task.user)
|
129
128
|
end
|
130
129
|
|
131
130
|
it "should complete a task due sometime in the future" do
|
132
|
-
task =
|
133
|
-
task.update_attributes(completed_at: Time.now, completed_by:
|
131
|
+
task = create(:task, due_at: Time.now.midnight.tomorrow, bucket: "due_tomorrow")
|
132
|
+
task.update_attributes(completed_at: Time.now, completed_by: task.user.id)
|
133
|
+
|
134
134
|
expect(task.errors).to be_empty
|
135
135
|
expect(task.completed_at).not_to eq(nil)
|
136
|
-
expect(task.completor).to eq(
|
136
|
+
expect(task.completor).to eq(task.user)
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should complete a task that is due on specific date in the future" do
|
140
|
-
task =
|
140
|
+
task = create(:task, calendar: "10/10/2022 12:00 AM", bucket: "specific_time")
|
141
141
|
task.calendar = nil # Calendar is not saved in the database; we need it only to set the :due_at.
|
142
|
-
task.update_attributes(completed_at: Time.now, completed_by:
|
142
|
+
task.update_attributes(completed_at: Time.now, completed_by: task.user.id)
|
143
143
|
expect(task.errors).to be_empty
|
144
144
|
expect(task.completed_at).not_to eq(nil)
|
145
|
-
expect(task.completor).to eq(
|
145
|
+
expect(task.completor).to eq(task.user)
|
146
146
|
end
|
147
147
|
|
148
148
|
it "should complete a task that is due on specific date in the past" do
|
149
|
-
task =
|
149
|
+
task = create(:task, calendar: "10/10/1992 12:00 AM", bucket: "specific_time")
|
150
150
|
task.calendar = nil # Calendar is not saved in the database; we need it only to set the :due_at.
|
151
|
-
task.update_attributes(completed_at: Time.now, completed_by:
|
151
|
+
task.update_attributes(completed_at: Time.now, completed_by: task.user.id)
|
152
152
|
expect(task.errors).to be_empty
|
153
153
|
expect(task.completed_at).not_to eq(nil)
|
154
|
-
expect(task.completor).to eq(
|
154
|
+
expect(task.completor).to eq(task.user)
|
155
155
|
end
|
156
156
|
|
157
157
|
it "completion should preserve original due date" do
|
158
158
|
due_at = Time.now - 42.days
|
159
|
-
task =
|
160
|
-
|
161
|
-
task.update_attributes(completed_at: Time.now, completed_by:
|
159
|
+
task = create(:task, due_at: due_at, bucket: "specific_time",
|
160
|
+
calendar: due_at.strftime('%Y-%m-%d %H:%M'))
|
161
|
+
task.update_attributes(completed_at: Time.now, completed_by: task.user.id, calendar: '')
|
162
|
+
|
162
163
|
expect(task.completed?).to eq(true)
|
163
164
|
expect(task.due_at).to eq(due_at.utc.strftime('%Y-%m-%d %H:%M'))
|
164
165
|
end
|
@@ -166,64 +167,70 @@ describe Task do
|
|
166
167
|
|
167
168
|
# named_scope :my, lambda { |user| { :conditions => [ "(user_id = ? AND assigned_to IS NULL) OR assigned_to = ?", user.id, user.id ], :include => :assignee } }
|
168
169
|
describe "task.my?" do
|
170
|
+
let(:current_user) { create(:user) }
|
171
|
+
|
169
172
|
it "should match a task created by the user" do
|
170
|
-
task =
|
173
|
+
task = create(:task, user: current_user, assignee: nil)
|
171
174
|
expect(task.my?(current_user)).to eq(true)
|
172
175
|
end
|
173
176
|
|
174
177
|
it "should match a task assigned to the user" do
|
175
|
-
task =
|
178
|
+
task = create(:task, user: create(:user), assignee: current_user)
|
176
179
|
expect(task.my?(current_user)).to eq(true)
|
177
180
|
end
|
178
181
|
|
179
182
|
it "should Not match a task not created by the user" do
|
180
|
-
task =
|
183
|
+
task = create(:task, user: create(:user))
|
181
184
|
expect(task.my?(current_user)).to eq(false)
|
182
185
|
end
|
183
186
|
|
184
187
|
it "should Not match a task created by the user but assigned to somebody else" do
|
185
|
-
task =
|
188
|
+
task = create(:task, user: current_user, assignee: create(:user))
|
186
189
|
expect(task.my?(current_user)).to eq(false)
|
187
190
|
end
|
188
191
|
end
|
189
192
|
|
190
193
|
# named_scope :assigned_by, lambda { |user| { :conditions => [ "user_id = ? AND assigned_to IS NOT NULL AND assigned_to != ?", user.id, user.id ], :include => :assignee } }
|
191
194
|
describe "task.assigned_by?" do
|
195
|
+
let(:current_user) { create(:user) }
|
196
|
+
|
192
197
|
it "should match a task assigned by the user to somebody else" do
|
193
|
-
task =
|
198
|
+
task = create(:task, user: current_user, assignee: create(:user))
|
194
199
|
expect(task.assigned_by?(current_user)).to eq(true)
|
195
200
|
end
|
196
201
|
|
197
202
|
it "should Not match a task not created by the user" do
|
198
|
-
task =
|
203
|
+
task = create(:task, user: create(:user))
|
199
204
|
expect(task.assigned_by?(current_user)).to eq(false)
|
200
205
|
end
|
201
206
|
|
202
207
|
it "should Not match a task not assigned to anybody" do
|
203
|
-
task =
|
208
|
+
task = create(:task, assignee: nil)
|
204
209
|
expect(task.assigned_by?(current_user)).to eq(false)
|
205
210
|
end
|
206
211
|
|
207
212
|
it "should Not match a task assigned to the user" do
|
208
|
-
task =
|
213
|
+
task = create(:task, assignee: current_user)
|
209
214
|
expect(task.assigned_by?(current_user)).to eq(false)
|
210
215
|
end
|
211
216
|
end
|
212
217
|
|
213
218
|
# named_scope :tracked_by, lambda { |user| { :conditions => [ "user_id = ? OR assigned_to = ?", user.id, user.id ], :include => :assignee } }
|
214
219
|
describe "task.tracked_by?" do
|
220
|
+
let(:current_user) { create(:user) }
|
221
|
+
|
215
222
|
it "should match a task created by the user" do
|
216
|
-
task =
|
223
|
+
task = create(:task, user: current_user)
|
217
224
|
expect(task.tracked_by?(current_user)).to eq(true)
|
218
225
|
end
|
219
226
|
|
220
227
|
it "should match a task assigned to the user" do
|
221
|
-
task =
|
228
|
+
task = create(:task, assignee: current_user)
|
222
229
|
expect(task.tracked_by?(current_user)).to eq(true)
|
223
230
|
end
|
224
231
|
|
225
232
|
it "should Not match a task that is neither created nor assigned to the user" do
|
226
|
-
task =
|
233
|
+
task = create(:task, user: create(:user), assignee: create(:user))
|
227
234
|
expect(task.tracked_by?(current_user)).to eq(false)
|
228
235
|
end
|
229
236
|
end
|
@@ -310,24 +317,24 @@ describe Task do
|
|
310
317
|
|
311
318
|
describe "Exportable" do
|
312
319
|
describe "unassigned tasks" do
|
313
|
-
let(:task1) {
|
314
|
-
let(:task2) {
|
320
|
+
let(:task1) { build(:task, user: create(:user), assignee: nil) }
|
321
|
+
let(:task2) { build(:task, user: create(:user, first_name: nil, last_name: nil), assignee: nil) }
|
315
322
|
it_should_behave_like("exportable") do
|
316
323
|
let(:exported) { [task1, task2] }
|
317
324
|
end
|
318
325
|
end
|
319
326
|
|
320
327
|
describe "assigned tasks" do
|
321
|
-
let(:task1) {
|
322
|
-
let(:task2) {
|
328
|
+
let(:task1) { build(:task, user: create(:user), assignee: create(:user)) }
|
329
|
+
let(:task2) { build(:task, user: create(:user, first_name: nil, last_name: nil), assignee: create(:user, first_name: nil, last_name: nil)) }
|
323
330
|
it_should_behave_like("exportable") do
|
324
331
|
let(:exported) { [task1, task2] }
|
325
332
|
end
|
326
333
|
end
|
327
334
|
|
328
335
|
describe "completed tasks" do
|
329
|
-
let(:task1) {
|
330
|
-
let(:task2) {
|
336
|
+
let(:task1) { build(:task, user: create(:user), completor: create(:user), completed_at: 1.day.ago) }
|
337
|
+
let(:task2) { build(:task, user: create(:user, first_name: nil, last_name: nil), completor: create(:user, first_name: nil, last_name: nil), completed_at: 1.day.ago) }
|
331
338
|
it_should_behave_like("exportable") do
|
332
339
|
let(:exported) { [task1, task2] }
|
333
340
|
end
|
@@ -345,13 +352,13 @@ describe Task do
|
|
345
352
|
describe "scopes" do
|
346
353
|
context "visible_on_dashboard" do
|
347
354
|
before :each do
|
348
|
-
@user =
|
349
|
-
@t1 =
|
350
|
-
@t2 =
|
351
|
-
@t3 =
|
352
|
-
@t4 =
|
353
|
-
@t5 =
|
354
|
-
@t6 =
|
355
|
+
@user = create(:user)
|
356
|
+
@t1 = create(:task, user: @user)
|
357
|
+
@t2 = create(:task, user: @user, assignee: create(:user))
|
358
|
+
@t3 = create(:task, user: create(:user), assignee: @user)
|
359
|
+
@t4 = create(:task, user: create(:user), assignee: create(:user))
|
360
|
+
@t5 = create(:task, user: create(:user), assignee: @user)
|
361
|
+
@t6 = create(:completed_task, assignee: @user)
|
355
362
|
end
|
356
363
|
|
357
364
|
it "should show tasks which have been created by the user and are unassigned" do
|
@@ -377,10 +384,10 @@ describe Task do
|
|
377
384
|
|
378
385
|
context "by_due_at" do
|
379
386
|
it "should show tasks ordered by due_at" do
|
380
|
-
t1 =
|
381
|
-
t2 =
|
382
|
-
t3 =
|
383
|
-
t4 =
|
387
|
+
t1 = create(:task, name: 't1', bucket: "due_asap")
|
388
|
+
t2 = create(:task, calendar: 5.days.from_now.strftime("%Y-%m-%d %H:%M"), bucket: "specific_time")
|
389
|
+
t3 = create(:task, name: 't3', bucket: "due_next_week")
|
390
|
+
t4 = create(:task, calendar: 20.days.from_now.strftime("%Y-%m-%d %H:%M"), bucket: "specific_time")
|
384
391
|
expect(Task.by_due_at).to eq([t1, t2, t3, t4])
|
385
392
|
end
|
386
393
|
end
|
@@ -23,20 +23,20 @@
|
|
23
23
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
24
24
|
|
25
25
|
describe Version, versioning: true do
|
26
|
-
let(:current_user) {
|
26
|
+
let(:current_user) { create(:user) }
|
27
27
|
before { PaperTrail.whodunnit = current_user.id.to_s }
|
28
28
|
|
29
29
|
it "should create a new instance given valid attributes" do
|
30
|
-
|
30
|
+
create(:version, whodunnit: PaperTrail.whodunnit, item: create(:lead))
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "with multiple version records" do
|
34
34
|
before do
|
35
|
-
@lead =
|
35
|
+
@lead = create(:lead)
|
36
36
|
|
37
37
|
%w[create destroy update view].each do |event|
|
38
|
-
|
39
|
-
|
38
|
+
create(:version, event: event, item: @lead, whodunnit: PaperTrail.whodunnit)
|
39
|
+
create(:version, event: event, item: @lead, whodunnit: "1")
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -71,7 +71,7 @@ describe Version, versioning: true do
|
|
71
71
|
%w[account campaign contact lead opportunity task].each do |item|
|
72
72
|
describe "Create, update, and delete (#{item})" do
|
73
73
|
before :each do
|
74
|
-
@item =
|
74
|
+
@item = create(item.to_sym, user: current_user)
|
75
75
|
@conditions = { item_id: @item.id, item_type: @item.class.name, whodunnit: PaperTrail.whodunnit }
|
76
76
|
end
|
77
77
|
|
@@ -99,7 +99,7 @@ describe Version, versioning: true do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should add a version when commenting on a #{item}" do
|
102
|
-
@comment =
|
102
|
+
@comment = create(:comment, commentable: @item, user: current_user)
|
103
103
|
|
104
104
|
@version = Version.where(related_id: @item.id, related_type: @item.class.name, whodunnit: PaperTrail.whodunnit, event: 'create').first
|
105
105
|
expect(@version).not_to eq(nil)
|
@@ -109,7 +109,7 @@ describe Version, versioning: true do
|
|
109
109
|
|
110
110
|
describe "Recently viewed items (task)" do
|
111
111
|
before do
|
112
|
-
@task =
|
112
|
+
@task = create(:task)
|
113
113
|
@conditions = { item_id: @task.id, item_type: @task.class.name }
|
114
114
|
end
|
115
115
|
|
@@ -128,7 +128,7 @@ describe Version, versioning: true do
|
|
128
128
|
|
129
129
|
describe "Action refinements for task updates" do
|
130
130
|
before do
|
131
|
-
@task =
|
131
|
+
@task = create(:task, user: current_user)
|
132
132
|
@conditions = { item_id: @task.id, item_type: @task.class.name, whodunnit: PaperTrail.whodunnit }
|
133
133
|
end
|
134
134
|
|
@@ -147,7 +147,7 @@ describe Version, versioning: true do
|
|
147
147
|
end
|
148
148
|
|
149
149
|
it "should create 'rescheduled' task event" do
|
150
|
-
@task.update(bucket: "due_tomorrow") #
|
150
|
+
@task.update(bucket: "due_tomorrow") # FactoryBot creates :due_asap task
|
151
151
|
|
152
152
|
versions = Version.where(@conditions)
|
153
153
|
expect(versions.pluck(:event)).to include('reschedule')
|
@@ -156,7 +156,7 @@ describe Version, versioning: true do
|
|
156
156
|
|
157
157
|
describe "Rejecting a lead" do
|
158
158
|
before do
|
159
|
-
@lead =
|
159
|
+
@lead = create(:lead, user: current_user, status: "new")
|
160
160
|
@conditions = { item_id: @lead.id, item_type: @lead.class.name, whodunnit: PaperTrail.whodunnit }
|
161
161
|
end
|
162
162
|
|
@@ -170,12 +170,12 @@ describe Version, versioning: true do
|
|
170
170
|
|
171
171
|
describe "Permissions" do
|
172
172
|
before do
|
173
|
-
@user =
|
173
|
+
@user = create(:user)
|
174
174
|
Version.delete_all
|
175
175
|
end
|
176
176
|
|
177
177
|
it "should not show the create/update versions if the item is private" do
|
178
|
-
@item =
|
178
|
+
@item = create(:account, user: current_user, access: "Private")
|
179
179
|
@item.update(name: 'New Name')
|
180
180
|
|
181
181
|
versions = Version.where(item_id: @item.id, item_type: @item.class.name)
|
@@ -186,7 +186,7 @@ describe Version, versioning: true do
|
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should not show the destroy version if the item is private" do
|
189
|
-
@item =
|
189
|
+
@item = create(:account, user: current_user, access: "Private")
|
190
190
|
@item.destroy
|
191
191
|
|
192
192
|
versions = Version.where(item_id: @item.id, item_type: @item.class.name)
|
@@ -197,10 +197,10 @@ describe Version, versioning: true do
|
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should not show create/update versions if the item was not shared with the user" do
|
200
|
-
@item =
|
201
|
-
|
202
|
-
|
203
|
-
|
200
|
+
@item = create(:account,
|
201
|
+
user: current_user,
|
202
|
+
access: "Shared",
|
203
|
+
permissions: [build(:permission, user: current_user, asset: @item)])
|
204
204
|
@item.update(name: 'New Name')
|
205
205
|
|
206
206
|
versions = Version.where(item_id: @item.id, item_type: @item.class.name)
|
@@ -211,10 +211,10 @@ describe Version, versioning: true do
|
|
211
211
|
end
|
212
212
|
|
213
213
|
it "should not show the destroy version if the item was not shared with the user" do
|
214
|
-
@item =
|
215
|
-
|
216
|
-
|
217
|
-
|
214
|
+
@item = create(:account,
|
215
|
+
user: current_user,
|
216
|
+
access: "Shared",
|
217
|
+
permissions: [build(:permission, user: current_user, asset: @item)])
|
218
218
|
@item.destroy
|
219
219
|
|
220
220
|
versions = Version.where(item_id: @item.id, item_type: @item.class.name)
|
@@ -225,10 +225,10 @@ describe Version, versioning: true do
|
|
225
225
|
end
|
226
226
|
|
227
227
|
it "should show create/update versions if the item was shared with the user" do
|
228
|
-
@item =
|
229
|
-
|
230
|
-
|
231
|
-
|
228
|
+
@item = create(:account,
|
229
|
+
user: current_user,
|
230
|
+
access: "Shared",
|
231
|
+
permissions: [build(:permission, user: @user, asset: @item)])
|
232
232
|
@item.update(name: 'New Name')
|
233
233
|
|
234
234
|
versions = Version.where(item_id: @item.id, item_type: @item.class.name)
|