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.

Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +11 -0
  3. data/.rubocop.yml +1 -1
  4. data/.rubocop_todo.yml +30 -8
  5. data/.travis.yml +14 -9
  6. data/CHANGELOG.md +43 -7
  7. data/CONTRIBUTORS.md +95 -53
  8. data/Gemfile +11 -7
  9. data/Gemfile.lock +83 -83
  10. data/README.md +7 -4
  11. data/app/assets/javascripts/crm.js.coffee +3 -3
  12. data/app/assets/javascripts/crm_select2.js.coffee +15 -14
  13. data/app/controllers/admin/field_groups_controller.rb +8 -1
  14. data/app/controllers/admin/fields_controller.rb +4 -4
  15. data/app/controllers/admin/groups_controller.rb +1 -1
  16. data/app/controllers/admin/tags_controller.rb +1 -1
  17. data/app/controllers/application_controller.rb +11 -0
  18. data/app/controllers/authentications_controller.rb +1 -1
  19. data/app/controllers/comments_controller.rb +15 -7
  20. data/app/controllers/entities/campaigns_controller.rb +7 -2
  21. data/app/controllers/entities/leads_controller.rb +9 -2
  22. data/app/controllers/entities/opportunities_controller.rb +13 -2
  23. data/app/controllers/entities_controller.rb +10 -5
  24. data/app/controllers/lists_controller.rb +5 -1
  25. data/app/controllers/tasks_controller.rb +15 -1
  26. data/app/helpers/accounts_helper.rb +1 -1
  27. data/app/helpers/application_helper.rb +2 -2
  28. data/app/helpers/leads_helper.rb +1 -1
  29. data/app/helpers/opportunities_helper.rb +56 -3
  30. data/app/helpers/tags_helper.rb +1 -1
  31. data/app/models/entities/lead.rb +0 -7
  32. data/app/models/entities/opportunity.rb +3 -2
  33. data/app/models/observers/opportunity_observer.rb +4 -4
  34. data/app/models/users/ability.rb +3 -4
  35. data/app/views/campaigns/_metrics.html.haml +3 -3
  36. data/app/views/home/_opportunity.html.haml +4 -19
  37. data/app/views/opportunities/_index_long.html.haml +1 -24
  38. data/app/views/opportunities/_sidebar_show.html.haml +3 -3
  39. data/app/views/opportunities/_top_section.html.haml +1 -1
  40. data/db/schema.rb +0 -3
  41. data/fat_free_crm.gemspec +1 -1
  42. data/lib/fat_free_crm/core_ext/string.rb +1 -1
  43. data/lib/fat_free_crm/engine.rb +2 -2
  44. data/lib/fat_free_crm/fields.rb +1 -1
  45. data/lib/fat_free_crm/permissions.rb +0 -14
  46. data/lib/fat_free_crm/version.rb +2 -2
  47. data/lib/tasks/ffcrm/setup.rake +4 -4
  48. data/spec/controllers/admin/users_controller_spec.rb +27 -27
  49. data/spec/controllers/authentications_controller_spec.rb +7 -7
  50. data/spec/controllers/comments_controller_spec.rb +13 -13
  51. data/spec/controllers/emails_controller_spec.rb +2 -2
  52. data/spec/controllers/entities/accounts_controller_spec.rb +56 -56
  53. data/spec/controllers/entities/campaigns_controller_spec.rb +66 -66
  54. data/spec/controllers/entities/contacts_controller_spec.rb +67 -67
  55. data/spec/controllers/entities/leads_controller_spec.rb +125 -125
  56. data/spec/controllers/entities/opportunities_controller_spec.rb +100 -100
  57. data/spec/controllers/home_controller_spec.rb +26 -26
  58. data/spec/controllers/passwords_controller_spec.rb +1 -1
  59. data/spec/controllers/tasks_controller_spec.rb +37 -37
  60. data/spec/controllers/users_controller_spec.rb +18 -18
  61. data/spec/factories/account_factories.rb +8 -8
  62. data/spec/factories/campaign_factories.rb +5 -5
  63. data/spec/factories/contact_factories.rb +10 -10
  64. data/spec/factories/field_factories.rb +7 -7
  65. data/spec/factories/lead_factories.rb +8 -8
  66. data/spec/factories/list_factories.rb +1 -1
  67. data/spec/factories/opportunity_factories.rb +6 -6
  68. data/spec/factories/sequences.rb +1 -1
  69. data/spec/factories/setting_factories.rb +3 -3
  70. data/spec/factories/shared_factories.rb +14 -14
  71. data/spec/factories/subscription_factories.rb +1 -1
  72. data/spec/factories/tag_factories.rb +1 -1
  73. data/spec/factories/task_factories.rb +4 -4
  74. data/spec/factories/user_factories.rb +13 -13
  75. data/spec/features/accounts_spec.rb +17 -4
  76. data/spec/features/admin/groups_spec.rb +1 -1
  77. data/spec/features/admin/users_spec.rb +1 -1
  78. data/spec/features/campaigns_spec.rb +4 -4
  79. data/spec/features/contacts_spec.rb +10 -4
  80. data/spec/features/dashboard_spec.rb +7 -7
  81. data/spec/features/leads_spec.rb +4 -4
  82. data/spec/features/opportunities_overview_spec.rb +15 -15
  83. data/spec/features/opportunities_spec.rb +34 -8
  84. data/spec/features/support/autocomlete_helper.rb +17 -0
  85. data/spec/features/support/browser.rb +3 -8
  86. data/spec/features/support/helpers.rb +1 -1
  87. data/spec/features/tasks_spec.rb +4 -4
  88. data/spec/helpers/admin/field_groups_helper_spec.rb +1 -1
  89. data/spec/helpers/application_helper_spec.rb +1 -1
  90. data/spec/helpers/tasks_helper_spec.rb +1 -1
  91. data/spec/helpers/users_helper_spec.rb +3 -3
  92. data/spec/lib/comment_extensions_spec.rb +1 -1
  93. data/spec/lib/mail_processor/base_spec.rb +3 -3
  94. data/spec/lib/mail_processor/comment_replies_spec.rb +3 -3
  95. data/spec/lib/mail_processor/dropbox_spec.rb +16 -16
  96. data/spec/lib/permissions_spec.rb +7 -25
  97. data/spec/mailers/user_mailer_spec.rb +7 -7
  98. data/spec/models/entities/account_spec.rb +31 -32
  99. data/spec/models/entities/campaign_spec.rb +18 -25
  100. data/spec/models/entities/contact_spec.rb +18 -21
  101. data/spec/models/entities/lead_spec.rb +9 -11
  102. data/spec/models/entities/opportunity_spec.rb +45 -45
  103. data/spec/models/fields/custom_field_spec.rb +17 -17
  104. data/spec/models/list_spec.rb +2 -2
  105. data/spec/models/observers/entity_observer_spec.rb +6 -6
  106. data/spec/models/polymorphic/address_spec.rb +1 -1
  107. data/spec/models/polymorphic/avatar_spec.rb +5 -5
  108. data/spec/models/polymorphic/comment_spec.rb +5 -5
  109. data/spec/models/polymorphic/task_spec.rb +65 -58
  110. data/spec/models/polymorphic/version_spec.rb +26 -26
  111. data/spec/models/setting_spec.rb +2 -2
  112. data/spec/models/users/preference_spec.rb +6 -6
  113. data/spec/models/users/user_spec.rb +26 -26
  114. data/spec/shared/models.rb +22 -22
  115. data/spec/spec_helper.rb +2 -2
  116. data/spec/support/auth_macros.rb +1 -1
  117. data/spec/support/macros.rb +3 -3
  118. data/spec/views/accounts/_edit.haml_spec.rb +1 -1
  119. data/spec/views/accounts/create.js.haml_spec.rb +2 -2
  120. data/spec/views/accounts/destroy.js.haml_spec.rb +1 -1
  121. data/spec/views/accounts/edit.js.haml_spec.rb +2 -2
  122. data/spec/views/accounts/index.haml_spec.rb +2 -2
  123. data/spec/views/accounts/index.js.haml_spec.rb +1 -1
  124. data/spec/views/accounts/show.haml_spec.rb +4 -4
  125. data/spec/views/accounts/update.js.haml_spec.rb +1 -1
  126. data/spec/views/admin/field_groups/create.js.haml_spec.rb +1 -1
  127. data/spec/views/admin/field_groups/destroy.js.haml_spec.rb +1 -1
  128. data/spec/views/admin/field_groups/edit.js.haml_spec.rb +1 -1
  129. data/spec/views/admin/field_groups/new.js.haml_spec.rb +1 -1
  130. data/spec/views/admin/field_groups/update.js.haml_spec.rb +1 -1
  131. data/spec/views/admin/users/create.js.haml_spec.rb +2 -2
  132. data/spec/views/admin/users/destroy.js.haml_spec.rb +2 -2
  133. data/spec/views/admin/users/edit.js.haml_spec.rb +2 -2
  134. data/spec/views/admin/users/index.haml_spec.rb +1 -1
  135. data/spec/views/admin/users/index.js.haml_spec.rb +2 -2
  136. data/spec/views/admin/users/reactivate.js.haml_spec.rb +1 -1
  137. data/spec/views/admin/users/suspend.js.haml_spec.rb +1 -1
  138. data/spec/views/admin/users/update.js.haml_spec.rb +1 -1
  139. data/spec/views/application/auto_complete.haml_spec.rb +3 -3
  140. data/spec/views/campaigns/_edit.haml_spec.rb +1 -1
  141. data/spec/views/campaigns/create.js.haml_spec.rb +3 -3
  142. data/spec/views/campaigns/destroy.js.haml_spec.rb +1 -1
  143. data/spec/views/campaigns/edit.js.haml_spec.rb +2 -2
  144. data/spec/views/campaigns/index.haml_spec.rb +1 -1
  145. data/spec/views/campaigns/index.js.haml_spec.rb +1 -1
  146. data/spec/views/campaigns/show.haml_spec.rb +4 -4
  147. data/spec/views/campaigns/update.js.haml_spec.rb +1 -1
  148. data/spec/views/contacts/_edit.haml_spec.rb +7 -7
  149. data/spec/views/contacts/_new.haml_spec.rb +1 -1
  150. data/spec/views/contacts/create.js.haml_spec.rb +4 -4
  151. data/spec/views/contacts/destroy.js.haml_spec.rb +1 -1
  152. data/spec/views/contacts/edit.js.haml_spec.rb +3 -3
  153. data/spec/views/contacts/index.haml_spec.rb +1 -1
  154. data/spec/views/contacts/index.js.html_spec.rb +1 -1
  155. data/spec/views/contacts/new.js.haml_spec.rb +1 -1
  156. data/spec/views/contacts/show.haml_spec.rb +3 -3
  157. data/spec/views/contacts/update.js.haml_spec.rb +2 -2
  158. data/spec/views/home/index.haml_spec.rb +1 -1
  159. data/spec/views/home/index.js.haml_spec.rb +1 -1
  160. data/spec/views/home/options.js.haml_spec.rb +2 -2
  161. data/spec/views/leads/_convert.haml_spec.rb +3 -3
  162. data/spec/views/leads/_edit.haml_spec.rb +2 -2
  163. data/spec/views/leads/_new.haml_spec.rb +2 -2
  164. data/spec/views/leads/_sidebar_show.haml_spec.rb +5 -5
  165. data/spec/views/leads/convert.js.haml_spec.rb +4 -4
  166. data/spec/views/leads/create.js.haml_spec.rb +5 -5
  167. data/spec/views/leads/destroy.js.haml_spec.rb +2 -2
  168. data/spec/views/leads/edit.js.haml_spec.rb +4 -4
  169. data/spec/views/leads/index.haml_spec.rb +1 -1
  170. data/spec/views/leads/index.js.haml_spec.rb +1 -1
  171. data/spec/views/leads/new.js.haml_spec.rb +1 -1
  172. data/spec/views/leads/promote.js.haml_spec.rb +7 -7
  173. data/spec/views/leads/reject.js.haml_spec.rb +2 -2
  174. data/spec/views/leads/show.haml_spec.rb +2 -2
  175. data/spec/views/leads/update.js.haml_spec.rb +4 -4
  176. data/spec/views/opportunities/_edit.haml_spec.rb +7 -7
  177. data/spec/views/opportunities/_new.haml_spec.rb +2 -2
  178. data/spec/views/opportunities/create.js.haml_spec.rb +6 -6
  179. data/spec/views/opportunities/destroy.js.haml_spec.rb +3 -3
  180. data/spec/views/opportunities/edit.js.haml_spec.rb +3 -3
  181. data/spec/views/opportunities/index.haml_spec.rb +1 -1
  182. data/spec/views/opportunities/index.js.haml_spec.rb +1 -1
  183. data/spec/views/opportunities/new.js.haml_spec.rb +1 -1
  184. data/spec/views/opportunities/show.haml_spec.rb +3 -3
  185. data/spec/views/opportunities/update.js.haml_spec.rb +4 -4
  186. data/spec/views/tasks/_edit.haml_spec.rb +1 -1
  187. data/spec/views/tasks/complete.js.haml_spec.rb +4 -4
  188. data/spec/views/tasks/create.js.haml_spec.rb +6 -6
  189. data/spec/views/tasks/destroy.js.haml_spec.rb +2 -2
  190. data/spec/views/tasks/index.haml_spec.rb +4 -4
  191. data/spec/views/tasks/new.js.haml_spec.rb +1 -1
  192. data/spec/views/tasks/uncomplete.js.haml_spec.rb +2 -2
  193. data/spec/views/tasks/update.js.haml_spec.rb +18 -18
  194. data/spec/views/users/upload_avatar.js.haml_spec.rb +2 -2
  195. metadata +5 -3
@@ -41,16 +41,13 @@
41
41
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
42
42
 
43
43
  describe Contact do
44
- let(:current_user) { FactoryGirl.create(:user) }
45
-
46
44
  it "should create a new instance given valid attributes" do
47
45
  Contact.create!(first_name: "Billy", last_name: "Bones")
48
46
  end
49
47
 
50
48
  describe "Update existing contact" do
51
49
  before(:each) do
52
- @account = FactoryGirl.create(:account)
53
- @contact = FactoryGirl.create(:contact, account: @account)
50
+ @contact = create(:contact, account: create(:account))
54
51
  end
55
52
 
56
53
  it "should create new account if requested so" do
@@ -65,7 +62,7 @@ describe Contact do
65
62
  end
66
63
 
67
64
  it "should change account if another account was selected" do
68
- @another_account = FactoryGirl.create(:account)
65
+ @another_account = create(:account)
69
66
  expect do
70
67
  @contact.update_with_account_and_permissions(
71
68
  account: { id: @another_account.id },
@@ -99,7 +96,7 @@ describe Contact do
99
96
  end
100
97
 
101
98
  it "should change account if entered name of another account was found" do
102
- @another_account = FactoryGirl.create(:account, name: "Another name")
99
+ @another_account = create(:account, name: "Another name")
103
100
  expect do
104
101
  @contact.update_with_account_and_permissions(
105
102
  account: { name: "Another name" },
@@ -113,12 +110,12 @@ describe Contact do
113
110
 
114
111
  describe "Attach" do
115
112
  before do
116
- @contact = FactoryGirl.create(:contact)
113
+ @contact = create(:contact)
117
114
  end
118
115
 
119
116
  it "should return nil when attaching existing asset" do
120
- @task = FactoryGirl.create(:task, asset: @contact, user: current_user)
121
- @opportunity = FactoryGirl.create(:opportunity)
117
+ @task = create(:task, asset: @contact)
118
+ @opportunity = create(:opportunity)
122
119
  @contact.opportunities << @opportunity
123
120
 
124
121
  expect(@contact.attach!(@task)).to eq(nil)
@@ -126,8 +123,8 @@ describe Contact do
126
123
  end
127
124
 
128
125
  it "should return non-empty list of attachments when attaching new asset" do
129
- @task = FactoryGirl.create(:task, user: current_user)
130
- @opportunity = FactoryGirl.create(:opportunity)
126
+ @task = create(:task)
127
+ @opportunity = create(:opportunity)
131
128
 
132
129
  expect(@contact.attach!(@task)).to eq([@task])
133
130
  expect(@contact.attach!(@opportunity)).to eq([@opportunity])
@@ -136,11 +133,11 @@ describe Contact do
136
133
 
137
134
  describe "Discard" do
138
135
  before do
139
- @contact = FactoryGirl.create(:contact)
136
+ @contact = create(:contact)
140
137
  end
141
138
 
142
139
  it "should discard a task" do
143
- @task = FactoryGirl.create(:task, asset: @contact, user: current_user)
140
+ @task = create(:task, asset: @contact)
144
141
  expect(@contact.tasks.count).to eq(1)
145
142
 
146
143
  @contact.discard!(@task)
@@ -149,7 +146,7 @@ describe Contact do
149
146
  end
150
147
 
151
148
  it "should discard an opportunity" do
152
- @opportunity = FactoryGirl.create(:opportunity)
149
+ @opportunity = create(:opportunity)
153
150
  @contact.opportunities << @opportunity
154
151
  expect(@contact.opportunities.count).to eq(1)
155
152
 
@@ -161,16 +158,16 @@ describe Contact do
161
158
 
162
159
  describe "Exportable" do
163
160
  describe "assigned contact" do
164
- let(:contact1) { FactoryGirl.build(:contact, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user)) }
165
- let(:contact2) { FactoryGirl.build(:contact, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: FactoryGirl.create(:user, first_name: nil, last_name: nil)) }
161
+ let(:contact1) { build(:contact, assignee: create(:user)) }
162
+ let(:contact2) { build(:contact, user: create(:user, first_name: nil, last_name: nil), assignee: create(:user, first_name: nil, last_name: nil)) }
166
163
  it_should_behave_like("exportable") do
167
164
  let(:exported) { [contact1, contact2] }
168
165
  end
169
166
  end
170
167
 
171
168
  describe "unassigned contact" do
172
- let(:contact1) { FactoryGirl.build(:contact, user: FactoryGirl.create(:user), assignee: nil) }
173
- let(:contact2) { FactoryGirl.build(:contact, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: nil) }
169
+ let(:contact1) { build(:contact, assignee: nil) }
170
+ let(:contact2) { build(:contact, user: create(:user, first_name: nil, last_name: nil), assignee: nil) }
174
171
  it_should_behave_like("exportable") do
175
172
  let(:exported) { [contact1, contact2] }
176
173
  end
@@ -182,8 +179,8 @@ describe Contact do
182
179
  end
183
180
 
184
181
  describe "text_search" do
185
- before(:each) do
186
- @contact = FactoryGirl.create(:contact, first_name: "Bob", last_name: "Dillion", email: 'bob_dillion@example.com', phone: '+1 123 456 789')
182
+ before do
183
+ @contact = create(:contact, first_name: "Bob", last_name: "Dillion", email: 'bob_dillion@example.com', phone: '+1 123 456 789')
187
184
  end
188
185
 
189
186
  it "should search first_name" do
@@ -211,7 +208,7 @@ describe Contact do
211
208
  end
212
209
 
213
210
  it "should not break with a single quote" do
214
- contact2 = FactoryGirl.create(:contact, first_name: "Shamus", last_name: "O'Connell", email: 'bob_dillion@example.com', phone: '+1 123 456 789')
211
+ contact2 = create(:contact, first_name: "Shamus", last_name: "O'Connell", email: 'bob_dillion@example.com', phone: '+1 123 456 789')
215
212
  expect(Contact.text_search("O'Connell")).to eq([contact2])
216
213
  end
217
214
 
@@ -41,25 +41,23 @@
41
41
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
42
42
 
43
43
  describe Lead do
44
- let(:current_user) { FactoryGirl.create(:user) }
45
-
46
44
  it "should create a new instance given valid attributes" do
47
45
  Lead.create!(first_name: "Billy", last_name: "Bones")
48
46
  end
49
47
 
50
48
  describe "Attach" do
51
49
  before do
52
- @lead = FactoryGirl.create(:lead)
50
+ @lead = create(:lead)
53
51
  end
54
52
 
55
53
  it "should return nil when attaching existing task" do
56
- @task = FactoryGirl.create(:task, asset: @lead, user: current_user)
54
+ @task = create(:task, asset: @lead)
57
55
 
58
56
  expect(@lead.attach!(@task)).to eq(nil)
59
57
  end
60
58
 
61
59
  it "should return non-empty list of tasks when attaching new task" do
62
- @task = FactoryGirl.create(:task, user: current_user)
60
+ @task = create(:task)
63
61
 
64
62
  expect(@lead.attach!(@task)).to eq([@task])
65
63
  end
@@ -67,11 +65,11 @@ describe Lead do
67
65
 
68
66
  describe "Discard" do
69
67
  before do
70
- @lead = FactoryGirl.create(:lead)
68
+ @lead = create(:lead)
71
69
  end
72
70
 
73
71
  it "should discard a task" do
74
- @task = FactoryGirl.create(:task, asset: @lead, user: current_user)
72
+ @task = create(:task, asset: @lead)
75
73
  expect(@lead.tasks.count).to eq(1)
76
74
 
77
75
  @lead.discard!(@task)
@@ -82,16 +80,16 @@ describe Lead do
82
80
 
83
81
  describe "Exportable" do
84
82
  describe "assigned lead" do
85
- let(:lead1) { FactoryGirl.build(:lead, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user)) }
86
- let(:lead2) { FactoryGirl.build(:lead, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: FactoryGirl.create(:user, first_name: nil, last_name: nil)) }
83
+ let(:lead1) { build(:lead, assignee: create(:user)) }
84
+ let(:lead2) { build(:lead, user: create(:user, first_name: nil, last_name: nil), assignee: create(:user, first_name: nil, last_name: nil)) }
87
85
  it_should_behave_like("exportable") do
88
86
  let(:exported) { [lead1, lead2] }
89
87
  end
90
88
  end
91
89
 
92
90
  describe "unassigned lead" do
93
- let(:lead1) { FactoryGirl.build(:lead, user: FactoryGirl.create(:user), assignee: nil) }
94
- let(:lead2) { FactoryGirl.build(:lead, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: nil) }
91
+ let(:lead1) { build(:lead, assignee: nil) }
92
+ let(:lead2) { build(:lead, user: create(:user, first_name: nil, last_name: nil), assignee: nil) }
95
93
  it_should_behave_like("exportable") do
96
94
  let(:exported) { [lead1, lead2] }
97
95
  end
@@ -35,8 +35,8 @@ describe Opportunity do
35
35
  end
36
36
 
37
37
  it "should be possible to create opportunity with the same name" do
38
- FactoryGirl.create(:opportunity, name: "Hello")
39
- expect { FactoryGirl.create(:opportunity, name: "Hello") }.to_not raise_error
38
+ create(:opportunity, name: "Hello")
39
+ expect { create(:opportunity, name: "Hello") }.to_not raise_error
40
40
  end
41
41
 
42
42
  it "have a default stage" do
@@ -50,8 +50,8 @@ describe Opportunity do
50
50
 
51
51
  describe "Update existing opportunity" do
52
52
  before(:each) do
53
- @account = FactoryGirl.create(:account)
54
- @opportunity = FactoryGirl.create(:opportunity, account: @account)
53
+ @account = create(:account)
54
+ @opportunity = create(:opportunity, account: @account)
55
55
  end
56
56
 
57
57
  it "should create new account if requested so" do
@@ -66,7 +66,7 @@ describe Opportunity do
66
66
  end
67
67
 
68
68
  it "should update the account another account was selected" do
69
- @another_account = FactoryGirl.create(:account)
69
+ @another_account = create(:account)
70
70
  expect do
71
71
  @opportunity.update_with_account_and_permissions(
72
72
  account: { id: @another_account.id },
@@ -100,7 +100,7 @@ describe Opportunity do
100
100
  end
101
101
 
102
102
  it "should change account if entered name of another account was found" do
103
- @another_account = FactoryGirl.create(:account, name: "Another name")
103
+ @another_account = create(:account, name: "Another name")
104
104
  expect do
105
105
  @opportunity.update_with_account_and_permissions(
106
106
  account: { name: "Another name" },
@@ -112,14 +112,14 @@ describe Opportunity do
112
112
  end
113
113
 
114
114
  it "should set the probability to 0% if opportunity has been lost" do
115
- opportunity = FactoryGirl.create(:opportunity, stage: "prospecting", probability: 25)
115
+ opportunity = create(:opportunity, stage: "prospecting", probability: 25)
116
116
  opportunity.update_attributes(stage: 'lost')
117
117
  opportunity.reload
118
118
  expect(opportunity.probability).to eq(0)
119
119
  end
120
120
 
121
121
  it "should set the probablility to 100% if opportunity has been won" do
122
- opportunity = FactoryGirl.create(:opportunity, stage: "prospecting", probability: 65)
122
+ opportunity = create(:opportunity, stage: "prospecting", probability: 65)
123
123
  opportunity.update_attributes(stage: 'won')
124
124
  opportunity.reload
125
125
  expect(opportunity.probability).to eq(100)
@@ -130,12 +130,12 @@ describe Opportunity do
130
130
  it "should find non-closed opportunities" do
131
131
  Opportunity.delete_all
132
132
  @opportunities = [
133
- FactoryGirl.create(:opportunity, stage: "prospecting", amount: 1),
134
- FactoryGirl.create(:opportunity, stage: "analysis", amount: 1),
135
- FactoryGirl.create(:opportunity, stage: "won", amount: 2),
136
- FactoryGirl.create(:opportunity, stage: "won", amount: 2),
137
- FactoryGirl.create(:opportunity, stage: "lost", amount: 3),
138
- FactoryGirl.create(:opportunity, stage: "lost", amount: 3)
133
+ create(:opportunity, stage: "prospecting", amount: 1),
134
+ create(:opportunity, stage: "analysis", amount: 1),
135
+ create(:opportunity, stage: "won", amount: 2),
136
+ create(:opportunity, stage: "won", amount: 2),
137
+ create(:opportunity, stage: "lost", amount: 3),
138
+ create(:opportunity, stage: "lost", amount: 3)
139
139
  ]
140
140
  expect(Opportunity.pipeline.sum(:amount)).to eq(2)
141
141
  expect(Opportunity.won.sum(:amount)).to eq(4)
@@ -144,8 +144,8 @@ describe Opportunity do
144
144
  end
145
145
 
146
146
  context "unassigned" do
147
- let(:unassigned_opportunity) { FactoryGirl.create(:opportunity, assignee: nil) }
148
- let(:assigned_opportunity) { FactoryGirl.create(:opportunity, assignee: FactoryGirl.create(:user)) }
147
+ let(:unassigned_opportunity) { create(:opportunity, assignee: nil) }
148
+ let(:assigned_opportunity) { create(:opportunity, assignee: create(:user)) }
149
149
 
150
150
  it "includes unassigned opportunities" do
151
151
  expect(Opportunity.unassigned).to include(unassigned_opportunity)
@@ -159,12 +159,12 @@ describe Opportunity do
159
159
 
160
160
  describe "Attach" do
161
161
  before do
162
- @opportunity = FactoryGirl.create(:opportunity)
162
+ @opportunity = create(:opportunity)
163
163
  end
164
164
 
165
165
  it "should return nil when attaching existing asset" do
166
- @task = FactoryGirl.create(:task, asset: @opportunity)
167
- @contact = FactoryGirl.create(:contact)
166
+ @task = create(:task, asset: @opportunity)
167
+ @contact = create(:contact)
168
168
  @opportunity.contacts << @contact
169
169
 
170
170
  expect(@opportunity.attach!(@task)).to eq(nil)
@@ -172,8 +172,8 @@ describe Opportunity do
172
172
  end
173
173
 
174
174
  it "should return non-empty list of attachments when attaching new asset" do
175
- @task = FactoryGirl.create(:task)
176
- @contact = FactoryGirl.create(:contact)
175
+ @task = create(:task)
176
+ @contact = create(:contact)
177
177
 
178
178
  expect(@opportunity.attach!(@task)).to eq([@task])
179
179
  expect(@opportunity.attach!(@contact)).to eq([@contact])
@@ -182,11 +182,11 @@ describe Opportunity do
182
182
 
183
183
  describe "Discard" do
184
184
  before do
185
- @opportunity = FactoryGirl.create(:opportunity)
185
+ @opportunity = create(:opportunity)
186
186
  end
187
187
 
188
188
  it "should discard a task" do
189
- @task = FactoryGirl.create(:task, asset: @opportunity)
189
+ @task = create(:task, asset: @opportunity)
190
190
  expect(@opportunity.tasks.count).to eq(1)
191
191
 
192
192
  @opportunity.discard!(@task)
@@ -195,7 +195,7 @@ describe Opportunity do
195
195
  end
196
196
 
197
197
  it "should discard an contact" do
198
- @contact = FactoryGirl.create(:contact)
198
+ @contact = create(:contact)
199
199
  @opportunity.contacts << @contact
200
200
  expect(@opportunity.contacts.count).to eq(1)
201
201
 
@@ -207,16 +207,16 @@ describe Opportunity do
207
207
 
208
208
  describe "Exportable" do
209
209
  describe "assigned opportunity" do
210
- let(:opportunity1) { FactoryGirl.build(:opportunity, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user)) }
211
- let(:opportunity2) { FactoryGirl.build(:opportunity, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: FactoryGirl.create(:user, first_name: nil, last_name: nil)) }
210
+ let(:opportunity1) { build(:opportunity, user: create(:user), assignee: create(:user)) }
211
+ let(:opportunity2) { build(:opportunity, user: create(:user, first_name: nil, last_name: nil), assignee: create(:user, first_name: nil, last_name: nil)) }
212
212
  it_should_behave_like("exportable") do
213
213
  let(:exported) { [opportunity1, opportunity2] }
214
214
  end
215
215
  end
216
216
 
217
217
  describe "unassigned opportunity" do
218
- let(:opportunity1) { FactoryGirl.build(:opportunity, user: FactoryGirl.create(:user), assignee: nil) }
219
- let(:opportunity2) { FactoryGirl.build(:opportunity, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: nil) }
218
+ let(:opportunity1) { build(:opportunity, user: create(:user), assignee: nil) }
219
+ let(:opportunity2) { build(:opportunity, user: create(:user, first_name: nil, last_name: nil), assignee: nil) }
220
220
  it_should_behave_like("exportable") do
221
221
  let(:exported) { [opportunity1, opportunity2] }
222
222
  end
@@ -230,14 +230,14 @@ describe Opportunity do
230
230
  describe "scopes" do
231
231
  context "visible_on_dashboard" do
232
232
  before :each do
233
- @user = FactoryGirl.create(:user)
234
- @o1 = FactoryGirl.create(:opportunity_in_pipeline, user: @user, stage: 'prospecting')
235
- @o2 = FactoryGirl.create(:opportunity_in_pipeline, user: @user, assignee: FactoryGirl.create(:user), stage: 'prospecting')
236
- @o3 = FactoryGirl.create(:opportunity_in_pipeline, user: FactoryGirl.create(:user), assignee: @user, stage: 'prospecting')
237
- @o4 = FactoryGirl.create(:opportunity_in_pipeline, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user), stage: 'prospecting')
238
- @o5 = FactoryGirl.create(:opportunity_in_pipeline, user: FactoryGirl.create(:user), assignee: @user, stage: 'prospecting')
239
- @o6 = FactoryGirl.create(:opportunity, assignee: @user, stage: 'won')
240
- @o7 = FactoryGirl.create(:opportunity, assignee: @user, stage: 'lost')
233
+ @user = create(:user)
234
+ @o1 = create(:opportunity_in_pipeline, user: @user, stage: 'prospecting')
235
+ @o2 = create(:opportunity_in_pipeline, user: @user, assignee: create(:user), stage: 'prospecting')
236
+ @o3 = create(:opportunity_in_pipeline, user: create(:user), assignee: @user, stage: 'prospecting')
237
+ @o4 = create(:opportunity_in_pipeline, user: create(:user), assignee: create(:user), stage: 'prospecting')
238
+ @o5 = create(:opportunity_in_pipeline, user: create(:user), assignee: @user, stage: 'prospecting')
239
+ @o6 = create(:opportunity, assignee: @user, stage: 'won')
240
+ @o7 = create(:opportunity, assignee: @user, stage: 'lost')
241
241
  end
242
242
 
243
243
  it "should show opportunities which have been created by the user and are unassigned" do
@@ -263,9 +263,9 @@ describe Opportunity do
263
263
  end
264
264
 
265
265
  context "by_closes_on" do
266
- let(:o1) { FactoryGirl.create(:opportunity, closes_on: 3.days.from_now) }
267
- let(:o2) { FactoryGirl.create(:opportunity, closes_on: 7.days.from_now) }
268
- let(:o3) { FactoryGirl.create(:opportunity, closes_on: 5.days.from_now) }
266
+ let(:o1) { create(:opportunity, closes_on: 3.days.from_now) }
267
+ let(:o2) { create(:opportunity, closes_on: 7.days.from_now) }
268
+ let(:o3) { create(:opportunity, closes_on: 5.days.from_now) }
269
269
 
270
270
  it "should show opportunities ordered by closes on" do
271
271
  expect(Opportunity.by_closes_on).to eq([o1, o3, o2])
@@ -273,9 +273,9 @@ describe Opportunity do
273
273
  end
274
274
 
275
275
  context "by_amount" do
276
- let(:o1) { FactoryGirl.create(:opportunity, amount: 50_000) }
277
- let(:o2) { FactoryGirl.create(:opportunity, amount: 10_000) }
278
- let(:o3) { FactoryGirl.create(:opportunity, amount: 750_000) }
276
+ let(:o1) { create(:opportunity, amount: 50_000) }
277
+ let(:o2) { create(:opportunity, amount: 10_000) }
278
+ let(:o3) { create(:opportunity, amount: 750_000) }
279
279
 
280
280
  it "should show opportunities ordered by amount" do
281
281
  expect(Opportunity.by_amount).to eq([o3, o1, o2])
@@ -283,9 +283,9 @@ describe Opportunity do
283
283
  end
284
284
 
285
285
  context "not lost" do
286
- let(:o1) { FactoryGirl.create(:opportunity, stage: 'won') }
287
- let(:o2) { FactoryGirl.create(:opportunity, stage: 'lost') }
288
- let(:o3) { FactoryGirl.create(:opportunity, stage: 'analysis') }
286
+ let(:o1) { create(:opportunity, stage: 'won') }
287
+ let(:o2) { create(:opportunity, stage: 'lost') }
288
+ let(:o3) { create(:opportunity, stage: 'analysis') }
289
289
 
290
290
  it "should show opportunities which are not lost" do
291
291
  expect(Opportunity.not_lost).to include(o1, o3)
@@ -35,16 +35,16 @@ describe CustomField do
35
35
  expect(Contact).to receive(:reset_column_information)
36
36
  expect(Contact).to receive(:serialize_custom_fields!)
37
37
 
38
- FactoryGirl.create(:custom_field,
39
- as: "string",
40
- name: "cf_test_field",
41
- label: "Test Field",
42
- field_group: FactoryGirl.create(:field_group, klass_name: "Contact"))
38
+ create(:custom_field,
39
+ as: "string",
40
+ name: "cf_test_field",
41
+ label: "Test Field",
42
+ field_group: create(:field_group, klass_name: "Contact"))
43
43
  end
44
44
 
45
45
  it "should generate a unique column name for a custom field" do
46
- field_group = FactoryGirl.build(:field_group, klass_name: "Contact")
47
- c = FactoryGirl.build(:custom_field, label: "Test Field", field_group: field_group)
46
+ field_group = build(:field_group, klass_name: "Contact")
47
+ c = build(:custom_field, label: "Test Field", field_group: field_group)
48
48
 
49
49
  columns = []
50
50
  %w[cf_test_field cf_test_field_2 cf_test_field_3 cf_test_field_4].each do |field|
@@ -54,12 +54,12 @@ describe CustomField do
54
54
  end
55
55
 
56
56
  it "should evaluate the safety of database transitions" do
57
- c = FactoryGirl.build(:custom_field, as: "string")
57
+ c = build(:custom_field, as: "string")
58
58
  expect(c.send(:db_transition_safety, c.as, "email")).to eq(:null)
59
59
  expect(c.send(:db_transition_safety, c.as, "text")).to eq(:safe)
60
60
  expect(c.send(:db_transition_safety, c.as, "datetime")).to eq(:unsafe)
61
61
 
62
- c = FactoryGirl.build(:custom_field, as: "datetime")
62
+ c = build(:custom_field, as: "datetime")
63
63
  expect(c.send(:db_transition_safety, c.as, "date")).to eq(:safe)
64
64
  expect(c.send(:db_transition_safety, c.as, "url")).to eq(:unsafe)
65
65
  end
@@ -67,7 +67,7 @@ describe CustomField do
67
67
  it "should return a safe list of types for the 'as' select options" do
68
68
  { "email" => %w[check_boxes text string email url tel select radio_buttons],
69
69
  "integer" => %w[integer float] }.each do |type, expected_arr|
70
- c = FactoryGirl.build(:custom_field, as: type)
70
+ c = build(:custom_field, as: type)
71
71
  opts = c.available_as
72
72
  expect(opts.map(&:first)).to match_array(expected_arr)
73
73
  end
@@ -81,12 +81,12 @@ describe CustomField do
81
81
  expect(Contact).to receive(:reset_column_information).twice
82
82
  expect(Contact).to receive(:serialize_custom_fields!).twice
83
83
 
84
- field_group = FactoryGirl.create(:field_group, klass_name: "Contact")
85
- c = FactoryGirl.create(:custom_field,
86
- label: "Test Field",
87
- name: nil,
88
- as: "email",
89
- field_group: field_group)
84
+ field_group = create(:field_group, klass_name: "Contact")
85
+ c = create(:custom_field,
86
+ label: "Test Field",
87
+ name: nil,
88
+ as: "email",
89
+ field_group: field_group)
90
90
  c.as = "text"
91
91
  c.save
92
92
  end
@@ -102,7 +102,7 @@ describe CustomField do
102
102
  expect(Contact).to receive(:reset_column_information)
103
103
  expect(Contact).to receive(:serialize_custom_fields!)
104
104
 
105
- contact = FactoryGirl.build(:contact)
105
+ contact = build(:contact)
106
106
  expect(contact.cf_another_new_field).to eq(nil)
107
107
  end
108
108
  end