fat_free_crm 0.14.2 → 0.15.0.beta
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 +5 -5
- data/.travis.yml +15 -5
- data/{CHANGELOG → CHANGELOG.md} +9 -8
- data/Gemfile +1 -1
- data/Gemfile.lock +78 -70
- data/README.md +8 -10
- data/app/controllers/admin/users_controller.rb +6 -1
- data/app/controllers/application_controller.rb +2 -0
- data/app/controllers/users_controller.rb +1 -0
- data/app/helpers/tags_helper.rb +1 -1
- data/app/models/users/user.rb +10 -9
- data/config/initializers/paper_trail.rb +1 -0
- data/fat_free_crm.gemspec +4 -4
- data/lib/development_tasks/rspec.rake +2 -6
- data/lib/fat_free_crm/engine.rb +5 -0
- data/lib/fat_free_crm/version.rb +3 -3
- data/spec/factories/field_factories.rb +1 -1
- data/spec/factories/opportunity_factories.rb +1 -1
- data/spec/mailers/subscription_mailer_spec.rb +5 -3
- data/spec/mailers/user_mailer_spec.rb +6 -6
- data/spec/models/users/abilities/user_ability_spec.rb +3 -3
- data/spec/models/users/user_spec.rb +73 -62
- data/spec/support/auth_macros.rb +8 -1
- data/spec/views/accounts/_edit.haml_spec.rb +1 -1
- data/spec/views/accounts/create.js.haml_spec.rb +1 -1
- 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/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/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 +1 -1
- data/spec/views/admin/users/destroy.js.haml_spec.rb +1 -1
- 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 +2 -2
- 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/_new.haml_spec.rb +1 -1
- data/spec/views/contacts/create.js.haml_spec.rb +3 -3
- 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/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 +2 -2
- 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 +1 -1
- data/spec/views/leads/_sidebar_show.haml_spec.rb +1 -1
- data/spec/views/leads/convert.js.haml_spec.rb +4 -4
- data/spec/views/leads/create.js.haml_spec.rb +3 -3
- 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 +5 -5
- data/spec/views/opportunities/_new.haml_spec.rb +1 -1
- data/spec/views/opportunities/create.js.haml_spec.rb +3 -3
- 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/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 +5 -5
- 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/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 +17 -14
@@ -44,8 +44,10 @@ class Admin::UsersController < Admin::ApplicationController
|
|
44
44
|
# POST /admin/users.xml AJAX
|
45
45
|
#----------------------------------------------------------------------------
|
46
46
|
def create
|
47
|
+
params[:user][:email].try(:strip!)
|
47
48
|
params[:user][:password_confirmation] = nil if params[:user][:password_confirmation].blank?
|
48
49
|
@user = User.new(user_params)
|
50
|
+
@user.check_if_needs_approval
|
49
51
|
@user.save_without_session_maintenance
|
50
52
|
|
51
53
|
respond_with(@user)
|
@@ -55,6 +57,7 @@ class Admin::UsersController < Admin::ApplicationController
|
|
55
57
|
# PUT /admin/users/1.xml AJAX
|
56
58
|
#----------------------------------------------------------------------------
|
57
59
|
def update
|
60
|
+
params[:user][:email].try(:strip!)
|
58
61
|
params[:user][:password_confirmation] = nil if params[:user][:password_confirmation].blank?
|
59
62
|
@user = User.find(params[:id])
|
60
63
|
@user.attributes = user_params
|
@@ -73,7 +76,9 @@ class Admin::UsersController < Admin::ApplicationController
|
|
73
76
|
# DELETE /admin/users/1.xml AJAX
|
74
77
|
#----------------------------------------------------------------------------
|
75
78
|
def destroy
|
76
|
-
|
79
|
+
unless @user.destroyable? && @user.destroy
|
80
|
+
flash[:warning] = t(:msg_cant_delete_user, @user.full_name)
|
81
|
+
end
|
77
82
|
|
78
83
|
respond_with(@user)
|
79
84
|
end
|
data/app/helpers/tags_helper.rb
CHANGED
@@ -15,7 +15,7 @@ module TagsHelper
|
|
15
15
|
elsif !query.include?(hashtag)
|
16
16
|
query += " #{hashtag}"
|
17
17
|
end
|
18
|
-
out << link_to_function(tag, "crm.search_tagged('#{
|
18
|
+
out << link_to_function(tag, "crm.search_tagged('#{query}', '#{model.class.to_s.tableize}')", title: tag)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
data/app/models/users/user.rb
CHANGED
@@ -39,9 +39,6 @@
|
|
39
39
|
#
|
40
40
|
|
41
41
|
class User < ActiveRecord::Base
|
42
|
-
before_create :check_if_needs_approval
|
43
|
-
before_destroy :check_if_current_user, :check_if_has_related_assets
|
44
|
-
|
45
42
|
has_one :avatar, as: :entity, dependent: :destroy # Personal avatar.
|
46
43
|
has_many :avatars # As owner who uploaded it, ex. Contact avatar.
|
47
44
|
has_many :comments, as: :commentable # As owner who created a comment.
|
@@ -143,7 +140,9 @@ class User < ActiveRecord::Base
|
|
143
140
|
[name].to_xml
|
144
141
|
end
|
145
142
|
|
146
|
-
|
143
|
+
def destroyable?
|
144
|
+
check_if_current_user && !has_related_assets?
|
145
|
+
end
|
147
146
|
|
148
147
|
# Suspend newly created user if signup requires an approval.
|
149
148
|
#----------------------------------------------------------------------------
|
@@ -159,15 +158,17 @@ class User < ActiveRecord::Base
|
|
159
158
|
|
160
159
|
# Prevent deleting a user unless she has no artifacts left.
|
161
160
|
#----------------------------------------------------------------------------
|
162
|
-
def
|
163
|
-
|
161
|
+
def has_related_assets?
|
162
|
+
sum = %w(Account Campaign Lead Contact Opportunity Comment Task).detect do |asset|
|
164
163
|
klass = asset.constantize
|
165
|
-
|
166
|
-
|
164
|
+
|
165
|
+
asset != "Comment" && klass.assigned_to(self).exists? || klass.created_by(self).exists?
|
167
166
|
end
|
168
|
-
|
167
|
+
!sum.nil?
|
169
168
|
end
|
170
169
|
|
170
|
+
private
|
171
|
+
|
171
172
|
# Define class methods
|
172
173
|
#----------------------------------------------------------------------------
|
173
174
|
class << self
|
@@ -0,0 +1 @@
|
|
1
|
+
PaperTrail.config.track_associations = false
|
data/fat_free_crm.gemspec
CHANGED
@@ -10,11 +10,11 @@ require 'fat_free_crm/version'
|
|
10
10
|
|
11
11
|
Gem::Specification.new do |gem|
|
12
12
|
gem.name = 'fat_free_crm'
|
13
|
-
gem.authors = ['Michael Dvorkin', 'Ben Tillman', 'Nathan Broadbent', 'Stephen Kenworthy']
|
13
|
+
gem.authors = ['Michael Dvorkin', 'Ben Tillman', 'Nathan Broadbent', 'Stephen Kenworthy', "Daniel O'Connor"]
|
14
14
|
gem.summary = 'Fat Free CRM'
|
15
15
|
gem.description = 'An open source, Ruby on Rails customer relationship management platform'
|
16
16
|
gem.homepage = 'http://fatfreecrm.com'
|
17
|
-
gem.email = ['mike@fatfreecrm.com', 'nathan@fatfreecrm.com', 'warp@fatfreecrm.com', 'steveyken@gmail.com']
|
17
|
+
gem.email = ['mike@fatfreecrm.com', 'nathan@fatfreecrm.com', 'warp@fatfreecrm.com', 'steveyken@gmail.com', 'daniel.oconnor@gmail.com']
|
18
18
|
gem.files = files
|
19
19
|
gem.version = FatFreeCRM::VERSION::STRING
|
20
20
|
gem.required_ruby_version = '>= 2.0.0'
|
@@ -28,13 +28,13 @@ Gem::Specification.new do |gem|
|
|
28
28
|
gem.add_dependency 'jquery-rails'
|
29
29
|
gem.add_dependency 'jquery-migrate-rails'
|
30
30
|
gem.add_dependency 'jquery-ui-rails'
|
31
|
-
gem.add_dependency 'select2-rails'
|
31
|
+
gem.add_dependency 'select2-rails'
|
32
32
|
gem.add_dependency 'simple_form'
|
33
33
|
gem.add_dependency 'will_paginate'
|
34
34
|
gem.add_dependency 'paperclip'
|
35
35
|
# Manually added paperclip gem dependency "cocaine" in order to fix load error: "no such file to load -- cocaine"
|
36
36
|
gem.add_dependency 'cocaine'
|
37
|
-
gem.add_dependency 'paper_trail', '
|
37
|
+
gem.add_dependency 'paper_trail', '~> 6.0.0'
|
38
38
|
gem.add_dependency 'authlogic', '>= 3.4.4'
|
39
39
|
gem.add_dependency 'acts_as_commentable'
|
40
40
|
gem.add_dependency 'acts-as-taggable-on', '>= 3.4.3'
|
@@ -7,8 +7,8 @@ if defined?(RSpec)
|
|
7
7
|
require 'rspec/core/rake_task'
|
8
8
|
|
9
9
|
namespace :spec do
|
10
|
-
desc "Preparing test env"
|
11
|
-
task :
|
10
|
+
desc "Preparing test env db"
|
11
|
+
task :preparedb do
|
12
12
|
tmp_env = Rails.env
|
13
13
|
Rails.env = "test"
|
14
14
|
Rake::Task["ffcrm:config:copy_database_yml"].invoke
|
@@ -17,8 +17,4 @@ if defined?(RSpec)
|
|
17
17
|
Rails.env = tmp_env
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
21
|
-
Rake::Task["spec"].prerequisites.clear
|
22
|
-
Rake::Task["spec"].prerequisites.push("spec:prepare")
|
23
|
-
|
24
20
|
end
|
data/lib/fat_free_crm/engine.rb
CHANGED
data/lib/fat_free_crm/version.rb
CHANGED
@@ -22,7 +22,7 @@ FactoryGirl.define do
|
|
22
22
|
|
23
23
|
factory :field do
|
24
24
|
type "Field"
|
25
|
-
field_group
|
25
|
+
field_group
|
26
26
|
position { FactoryGirl.generate(:field_position) }
|
27
27
|
label { FactoryGirl.generate(:field_label) }
|
28
28
|
name { |f| f.label.downcase.gsub(/[^a-z0-9]+/, '_') }
|
@@ -7,9 +7,11 @@ require 'spec_helper'
|
|
7
7
|
|
8
8
|
describe SubscriptionMailer do
|
9
9
|
describe "comment notification" do
|
10
|
-
let(:user) {
|
11
|
-
let(:
|
12
|
-
let(:
|
10
|
+
let(:user) { build(:user, email: 'notify_me@example.com') }
|
11
|
+
let(:campaign) { build(:campaign, user: user) }
|
12
|
+
let(:account) { build(:account, user: user) }
|
13
|
+
let(:commentable) { build_stubbed(:opportunity, id: 47, name: 'Opportunity name', account: account, campaign: campaign, user: user) }
|
14
|
+
let(:comment) { build(:comment, commentable: commentable, user: user) }
|
13
15
|
let(:mail) { SubscriptionMailer.comment_notification(user, comment) }
|
14
16
|
|
15
17
|
before :each do
|
@@ -7,7 +7,7 @@ require 'spec_helper'
|
|
7
7
|
|
8
8
|
describe UserMailer do
|
9
9
|
describe "password_reset_instructions" do
|
10
|
-
let(:user) { FactoryGirl.
|
10
|
+
let(:user) { FactoryGirl.build(:user, email: "forgot_my_password@example.com") }
|
11
11
|
let(:mail) { UserMailer.password_reset_instructions(user) }
|
12
12
|
|
13
13
|
before(:each) do
|
@@ -33,11 +33,11 @@ describe UserMailer do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "assigned_entity_notification" do
|
36
|
-
let(:assigner) { FactoryGirl.
|
37
|
-
let(:assignee) { FactoryGirl.
|
36
|
+
let(:assigner) { FactoryGirl.build(:user, first_name: "Bob", last_name: "Hope") }
|
37
|
+
let(:assignee) { FactoryGirl.build(:user, email: "assignee@example.com") }
|
38
38
|
|
39
39
|
context "for an account" do
|
40
|
-
let(:account) { FactoryGirl.
|
40
|
+
let(:account) { FactoryGirl.build_stubbed(:account, id: 16, name: 'Ghostbusters', user: assigner, assignee: assignee) }
|
41
41
|
let(:mail) { UserMailer.assigned_entity_notification(account, assigner) }
|
42
42
|
|
43
43
|
it "sets fatfree as the sender" do
|
@@ -62,7 +62,7 @@ describe UserMailer do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
context "for a contact" do
|
65
|
-
let(:contact) { FactoryGirl.
|
65
|
+
let(:contact) { FactoryGirl.build_stubbed(:contact, id: 56, first_name: 'Harold', last_name: 'Ramis', user: assigner, assignee: assignee) }
|
66
66
|
let(:mail) { UserMailer.assigned_entity_notification(contact, assigner) }
|
67
67
|
|
68
68
|
it "sets fatfree as the sender" do
|
@@ -87,7 +87,7 @@ describe UserMailer do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
context "for a lead" do
|
90
|
-
let(:lead) { FactoryGirl.
|
90
|
+
let(:lead) { FactoryGirl.build_stubbed(:lead, id: 42, first_name: 'Bill', last_name: 'Murray', user: assigner, assignee: assignee) }
|
91
91
|
let(:mail) { UserMailer.assigned_entity_notification(lead, assigner) }
|
92
92
|
|
93
93
|
it "sets fatfree as the sender" do
|
@@ -7,17 +7,17 @@ end
|
|
7
7
|
|
8
8
|
describe "User abilities" do
|
9
9
|
subject(:ability) { Ability.new(user) }
|
10
|
-
let(:subject_user) {
|
10
|
+
let(:subject_user) { build :user }
|
11
11
|
|
12
12
|
context "when site manager, I" do
|
13
|
-
let(:user) {
|
13
|
+
let(:user) { build :user, admin: true }
|
14
14
|
all_actions.each do |do_action|
|
15
15
|
it { is_expected.to be_able_to(do_action, subject_user) }
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
context "when myself, I" do
|
20
|
-
let(:user) {
|
20
|
+
let(:user) { build :user }
|
21
21
|
let(:subject_user) { user }
|
22
22
|
all_actions.each do |do_action|
|
23
23
|
it { is_expected.to be_able_to(do_action, subject_user) }
|
@@ -42,61 +42,59 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
42
42
|
|
43
43
|
describe User do
|
44
44
|
it "should create a new instance given valid attributes" do
|
45
|
-
User.
|
45
|
+
expect(User.new(
|
46
46
|
username: "username",
|
47
47
|
email: "user@example.com",
|
48
48
|
password: "password",
|
49
49
|
password_confirmation: "password"
|
50
|
-
)
|
50
|
+
).valid?).to eq true
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should have a valid factory" do
|
54
54
|
expect(FactoryGirl.build(:user)).to be_valid
|
55
55
|
end
|
56
56
|
|
57
|
-
describe
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
describe '#destroyable?' do
|
58
|
+
describe "Destroying users with and without related assets" do
|
59
|
+
before do
|
60
|
+
@user = FactoryGirl.build(:user)
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
%w(account campaign lead contact opportunity).each do |asset|
|
64
|
+
it "should not destroy the user if she owns #{asset}" do
|
65
|
+
FactoryGirl.create(asset, user: @user)
|
66
|
+
|
67
|
+
expect(@user.destroyable?).to eq(false)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not destroy the user if she has #{asset} assigned" do
|
71
|
+
FactoryGirl.create(asset, assignee: @user)
|
72
|
+
expect(@user.destroyable?).to eq(false)
|
73
|
+
end
|
68
74
|
end
|
69
75
|
|
70
|
-
it "should not destroy the user if she
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
expect(@user.
|
76
|
+
it "should not destroy the user if she owns a comment" do
|
77
|
+
login
|
78
|
+
account = build(:account, user: current_user)
|
79
|
+
FactoryGirl.create(:comment, user: @user, commentable: account)
|
80
|
+
expect(@user.destroyable?).to eq(false)
|
75
81
|
end
|
76
|
-
end
|
77
82
|
|
78
|
-
|
79
|
-
|
80
|
-
account = FactoryGirl.create(:account, user: current_user)
|
81
|
-
FactoryGirl.create(:comment, user: @user, commentable: account)
|
82
|
-
@user.destroy
|
83
|
-
expect { User.find(@user.id) }.to_not raise_error
|
84
|
-
expect(@user.destroyed?).to eq(false)
|
85
|
-
end
|
83
|
+
it "should not destroy the current user" do
|
84
|
+
login
|
86
85
|
|
87
|
-
|
88
|
-
|
89
|
-
current_user.destroy
|
90
|
-
expect { current_user.reload }.to_not raise_error
|
91
|
-
expect(current_user).not_to be_destroyed
|
92
|
-
end
|
86
|
+
expect(current_user.destroyable?).to eq(false)
|
87
|
+
end
|
93
88
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
89
|
+
it "should destroy the user" do
|
90
|
+
expect(@user.destroyable?).to eq(true)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
describe '#destroy' do
|
95
|
+
before do
|
96
|
+
@user = FactoryGirl.create(:user)
|
98
97
|
end
|
99
|
-
|
100
98
|
it "once the user gets deleted all her permissions must be deleted too" do
|
101
99
|
FactoryGirl.create(:permission, user: @user, asset: FactoryGirl.create(:account))
|
102
100
|
FactoryGirl.create(:permission, user: @user, asset: FactoryGirl.create(:contact))
|
@@ -114,69 +112,82 @@ describe User do
|
|
114
112
|
end
|
115
113
|
end
|
116
114
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
115
|
+
describe '#check_if_needs_approval' do
|
116
|
+
it "should set suspended timestamp upon creation if signups need approval and the user is not an admin" do
|
117
|
+
allow(Setting).to receive(:user_signup).and_return(:needs_approval)
|
118
|
+
@user = FactoryGirl.build(:user, suspended_at: nil)
|
119
|
+
|
120
|
+
@user.check_if_needs_approval
|
121
|
+
|
122
|
+
expect(@user).to be_suspended
|
123
|
+
end
|
122
124
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
125
|
+
it "should not set suspended timestamp upon creation if signups need approval and the user is an admin" do
|
126
|
+
allow(Setting).to receive(:user_signup).and_return(:needs_approval)
|
127
|
+
@user = FactoryGirl.build(:user, admin: true, suspended_at: nil)
|
128
|
+
|
129
|
+
@user.check_if_needs_approval
|
130
|
+
|
131
|
+
expect(@user).not_to be_suspended
|
132
|
+
end
|
127
133
|
end
|
128
134
|
|
129
135
|
context "scopes" do
|
130
136
|
describe "have_assigned_opportunities" do
|
131
|
-
before
|
137
|
+
before do
|
132
138
|
@user1 = FactoryGirl.create(:user)
|
133
|
-
FactoryGirl.create(:opportunity, assignee: @user1, stage: 'analysis')
|
139
|
+
FactoryGirl.create(:opportunity, assignee: @user1, stage: 'analysis', account: nil, campaign: nil, user: nil)
|
134
140
|
|
135
141
|
@user2 = FactoryGirl.create(:user)
|
136
142
|
|
137
143
|
@user3 = FactoryGirl.create(:user)
|
138
|
-
FactoryGirl.create(:opportunity, assignee: @user3, stage: 'won')
|
144
|
+
FactoryGirl.create(:opportunity, assignee: @user3, stage: 'won', account: nil, campaign: nil, user: nil)
|
139
145
|
|
140
146
|
@user4 = FactoryGirl.create(:user)
|
141
|
-
FactoryGirl.create(:opportunity, assignee: @user4, stage: 'lost')
|
147
|
+
FactoryGirl.create(:opportunity, assignee: @user4, stage: 'lost', account: nil, campaign: nil, user: nil)
|
148
|
+
|
149
|
+
@result = User.have_assigned_opportunities
|
142
150
|
end
|
143
151
|
|
144
152
|
it "includes users with assigned opportunities" do
|
145
|
-
expect(
|
153
|
+
expect(@result).to include(@user1)
|
146
154
|
end
|
147
155
|
|
148
156
|
it "excludes users without any assigned opportunities" do
|
149
|
-
expect(
|
157
|
+
expect(@result).not_to include(@user2)
|
150
158
|
end
|
151
159
|
|
152
160
|
it "excludes users with opportunities that have been won or lost" do
|
153
|
-
expect(
|
154
|
-
expect(
|
161
|
+
expect(@result).not_to include(@user3)
|
162
|
+
expect(@result).not_to include(@user4)
|
155
163
|
end
|
156
164
|
end
|
157
165
|
end
|
158
166
|
|
159
167
|
context "instance methods" do
|
160
168
|
describe "assigned_opportunities" do
|
161
|
-
before
|
169
|
+
before do
|
162
170
|
@user = FactoryGirl.create(:user)
|
163
|
-
|
164
|
-
@
|
171
|
+
|
172
|
+
@opportunity1 = FactoryGirl.create(:opportunity, assignee: @user, account: nil, campaign: nil, user: nil)
|
173
|
+
@opportunity2 = FactoryGirl.create(:opportunity, assignee: FactoryGirl.create(:user), account: nil, campaign: nil, user: nil)
|
174
|
+
|
175
|
+
@result = @user.assigned_opportunities
|
165
176
|
end
|
166
177
|
|
167
178
|
it "includes opportunities assigned to user" do
|
168
|
-
expect(@
|
179
|
+
expect(@result).to include(@opportunity1)
|
169
180
|
end
|
170
181
|
|
171
182
|
it "does not include opportunities assigned to another user" do
|
172
|
-
expect(@
|
183
|
+
expect(@result).not_to include(@opportunity2)
|
173
184
|
end
|
174
185
|
end
|
175
186
|
end
|
176
187
|
|
177
188
|
describe "Setting I18n.locale" do
|
178
189
|
before do
|
179
|
-
@user = FactoryGirl.
|
190
|
+
@user = FactoryGirl.build(:user)
|
180
191
|
@locale = I18n.locale
|
181
192
|
end
|
182
193
|
|
@@ -199,14 +210,14 @@ describe User do
|
|
199
210
|
|
200
211
|
describe "Setting single access token" do
|
201
212
|
it "should update single_access_token attribute if it is not set already" do
|
202
|
-
@user = FactoryGirl.
|
213
|
+
@user = FactoryGirl.build(:user, single_access_token: nil)
|
203
214
|
|
204
215
|
@user.set_single_access_token
|
205
216
|
expect(@user.single_access_token).not_to eq(nil)
|
206
217
|
end
|
207
218
|
|
208
219
|
it "should not update single_access_token attribute if it is set already" do
|
209
|
-
@user = FactoryGirl.
|
220
|
+
@user = FactoryGirl.build(:user, single_access_token: "token")
|
210
221
|
|
211
222
|
@user.set_single_access_token
|
212
223
|
expect(@user.single_access_token).to eq("token")
|