@@ -5,7 +5,7 @@
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
FactoryGirl.define do
FactoryBot.define do
sequence :opportunity_status do |_s|
%w[prospecting analysis presentation proposal negotiation final_review won lost].sample
end
@@ -22,18 +22,18 @@
name { FFaker::Lorem.sentence[0, 64] }
access "Public"
source { %w[campaign cold_call conference online referral self web word_of_mouth other].sample }
stage { FactoryGirl.generate(:opportunity_status) }
stage { FactoryBot.generate(:opportunity_status) }
probability { rand(50) }
amount { rand(1000) }
discount { rand(100) }
closes_on { FactoryGirl.generate(:date) }
closes_on { FactoryBot.generate(:date) }
background_info { FFaker::Lorem.paragraph[0, 255] }
deleted_at nil
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
updated_at { FactoryBot.generate(:time) }
created_at { FactoryBot.generate(:time) }
end

factory :opportunity_in_pipeline, parent: :opportunity do
stage { FactoryGirl.generate(:opportunity_open_status) }
stage { FactoryBot.generate(:opportunity_open_status) }
end
end
@@ -5,7 +5,7 @@
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
FactoryGirl.define do
FactoryBot.define do
sequence :address do |_n|
FFaker::Address.street_address + " " + FFaker::Address.secondary_address + "\n" + FFaker::Address.city + ", " + FFaker::AddressUS.state_abbr + " " + FFaker::AddressUS.zip_code
end
@@ -5,11 +5,11 @@
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
FactoryGirl.define do
FactoryBot.define do
factory :setting do
name "foo"
value nil
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
updated_at { FactoryBot.generate(:time) }
created_at { FactoryBot.generate(:time) }
end
end
@@ -5,23 +5,23 @@
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
FactoryGirl.define do
FactoryBot.define do
factory :version do
whodunnit ""
item { raise "Please specify :item for the version" }
event "create"
created_at { FactoryGirl.generate(:time) }
created_at { FactoryBot.generate(:time) }
end

factory :comment do
user
commentable { raise "Please specify :commentable for the comment" }
title { FactoryGirl.generate(:title) }
title { FactoryBot.generate(:title) }
private false
comment { FFaker::Lorem.paragraph }
state "Expanded"
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
updated_at { FactoryBot.generate(:time) }
created_at { FactoryBot.generate(:time) }
end

factory :email do
@@ -35,12 +35,12 @@
subject { FFaker::Lorem.sentence }
body { FFaker::Lorem.paragraph[0, 255] }
header nil
sent_at { FactoryGirl.generate(:time) }
received_at { FactoryGirl.generate(:time) }
sent_at { FactoryBot.generate(:time) }
received_at { FactoryBot.generate(:time) }
deleted_at nil
state "Expanded"
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
updated_at { FactoryBot.generate(:time) }
created_at { FactoryBot.generate(:time) }
end

factory :address do
@@ -51,18 +51,18 @@
state { FFaker::AddressUS.state_abbr }
zipcode { FFaker::AddressUS.zip_code }
country { FFaker::AddressUK.country }
full_address { FactoryGirl.generate(:address) }
full_address { FactoryBot.generate(:address) }
address_type { %w[Business Billing Shipping].sample }
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
updated_at { FactoryBot.generate(:time) }
created_at { FactoryBot.generate(:time) }
deleted_at nil
end

factory :avatar do
user
entity { raise "Please specify :entity for the avatar" }
image { File.new(Rails.root.join('spec', 'fixtures', 'rails.png')) }
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
updated_at { FactoryBot.generate(:time) }
created_at { FactoryBot.generate(:time) }
end
end
@@ -7,7 +7,7 @@
#------------------------------------------------------------------------------
# Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do
FactoryBot.define do
factory :subscription do
end
end
@@ -5,7 +5,7 @@
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
FactoryGirl.define do
FactoryBot.define do
factory :tag do
name { FFaker::Internet.user_name }
end
@@ -5,7 +5,7 @@
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
FactoryGirl.define do
FactoryBot.define do
factory :task do
user
asset nil
@@ -15,12 +15,12 @@
priority nil
category { %w[call email follow_up lunch meeting money presentation trip].sample }
bucket "due_asap"
due_at { FactoryGirl.generate(:time) }
due_at { FactoryBot.generate(:time) }
background_info { FFaker::Lorem.paragraph[0, 255] }
completed_at nil
deleted_at nil
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
updated_at { FactoryBot.generate(:time) }
created_at { FactoryBot.generate(:time) }
end

factory :completed_task, parent: :task do
@@ -5,13 +5,13 @@
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
FactoryGirl.define do
FactoryBot.define do
factory :user do
username { FactoryGirl.generate(:username) }
username { FactoryBot.generate(:username) }
email { FFaker::Internet.email }
first_name { FFaker::Name.first_name }
last_name { FFaker::Name.last_name }
title { FactoryGirl.generate(:title) }
title { FactoryBot.generate(:title) }
company { FFaker::Company.name }
alt_email { FFaker::Internet.email }
phone { FFaker::PhoneNumber.phone_number }
@@ -26,14 +26,14 @@
persistence_token { SecureRandom.hex(64) }
perishable_token { SecureRandom.hex(10) }
single_access_token nil
current_login_at { FactoryGirl.generate(:time) }
last_login_at { FactoryGirl.generate(:time) }
current_login_at { FactoryBot.generate(:time) }
last_login_at { FactoryBot.generate(:time) }
last_login_ip "127.0.0.1"
current_login_ip "127.0.0.1"
login_count { rand(1..100) }
deleted_at nil
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
updated_at { FactoryBot.generate(:time) }
created_at { FactoryBot.generate(:time) }
suspended_at nil
password "password"
password_confirmation "password"
@@ -46,21 +46,21 @@
factory :permission do
user
asset { raise "Please specify :asset for the permission" }
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
updated_at { FactoryBot.generate(:time) }
created_at { FactoryBot.generate(:time) }
end

factory :preference do
user
name { raise "Please specify :name for the preference" }
value { raise "Please specify :value for the preference" }
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
updated_at { FactoryBot.generate(:time) }
created_at { FactoryBot.generate(:time) }
end

factory :group do
name { FFaker::Company.name }
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
updated_at { FactoryBot.generate(:time) }
created_at { FactoryBot.generate(:time) }
end
end
@@ -17,7 +17,7 @@
end

scenario 'should view a list of accounts' do
2.times { |i| FactoryGirl.create(:account, name: "Account #{i}") }
2.times { |i| create(:account, name: "Account #{i}") }
visit accounts_page
expect(page).to have_content('Account 0')
expect(page).to have_content('Account 1')
@@ -70,7 +70,7 @@
end

scenario 'should view and edit an account', js: true, versioning: true do
FactoryGirl.create(:account, name: "A new account")
create(:account, name: "A new account")
with_versioning do
visit accounts_page
find('div#accounts').click_link('A new account')
@@ -86,7 +86,7 @@
end

scenario 'should delete an account', js: true do
FactoryGirl.create(:account, name: "My new account")
create(:account, name: "My new account")
visit accounts_page
find('div#accounts').click_link('My new account')
click_link 'Delete?'
@@ -96,7 +96,7 @@
end

scenario 'should search for an account', js: true do
2.times { |i| FactoryGirl.create(:account, name: "Account #{i}") }
2.times { |i| create(:account, name: "Account #{i}") }
visit accounts_page
expect(find('#accounts')).to have_content("Account 0")
expect(find('#accounts')).to have_content("Account 1")
@@ -110,4 +110,17 @@
expect(find('#accounts')).not_to have_content("Account 0")
expect(find('#accounts')).not_to have_content("Account 1")
end

scenario 'should attach task to account', js: true, versioning: true do
create(:task, name: 'Task', user: @user)
create(:account, name: 'Account')
with_versioning do
visit accounts_page
expect(find('#accounts')).to have_content("Account")
click_link 'Account'
click_link 'Select Task'
fill_autocomplete('auto_complete_query', with: 'Ta')
expect(find('#tasks')).to have_content('Task re: Account')
end
end
end
@@ -17,7 +17,7 @@
end

scenario 'should create a new group', js: true do
FactoryGirl.create(:user, first_name: "Mr", last_name: "Spock")
create(:user, first_name: "Mr", last_name: "Spock")
visit admin_groups_path
expect(page).to have_content("Couldn't find any Groups.")
click_link 'create a new group'
@@ -17,7 +17,7 @@
end

scenario 'should create a new user', js: true do
FactoryGirl.create(:group, name: "Superheroes")
create(:group, name: "Superheroes")
visit admin_users_path
click_link 'Create User'
expect(page).to have_selector('#user_username', visible: true)
@@ -17,7 +17,7 @@
end

scenario 'should view a list of campaigns' do
3.times { |i| FactoryGirl.create(:campaign, name: "Campaign #{i}") }
3.times { |i| create(:campaign, name: "Campaign #{i}") }
visit campaigns_page
expect(page).to have_content('Campaign 0')
expect(page).to have_content('Campaign 1')
@@ -60,7 +60,7 @@
end

scenario 'should view and edit a campaign', js: true do
FactoryGirl.create(:campaign, name: "My Cool Campaign")
create(:campaign, name: "My Cool Campaign")
with_versioning do
visit campaigns_page
click_link 'My Cool Campaign'
@@ -76,7 +76,7 @@
end

scenario 'should delete a campaign', js: true do
FactoryGirl.create(:campaign, name: "Old Campaign")
create(:campaign, name: "Old Campaign")
visit campaigns_page
click_link 'Old Campaign'
click_link 'Delete?'
@@ -87,7 +87,7 @@
end

scenario 'should search for a campaign', js: true do
2.times { |i| FactoryGirl.create(:campaign, name: "Campaign #{i}") }
2.times { |i| create(:campaign, name: "Campaign #{i}") }
visit campaigns_page
expect(find('#campaigns')).to have_content("Campaign 0")
expect(find('#campaigns')).to have_content("Campaign 1")
@@ -17,7 +17,7 @@
end

scenario 'should view a list of contacts' do
4.times { |i| FactoryGirl.create(:contact, first_name: "Test", last_name: "Subject \##{i}") }
4.times { |i| create(:contact, first_name: "Test", last_name: "Subject \##{i}") }
visit contacts_page
expect(contacts_element).to have_content('Test Subject #0')
expect(contacts_element).to have_content('Test Subject #1')
@@ -30,6 +30,9 @@
with_versioning do
visit contacts_page
click_link 'Create Contact'
select = find('#account_name', visible: true)
expect(select).to have_text("")
expect(page).to have_selector('#select2-account_id-container', visible: false)
expect(page).to have_selector('#contact_first_name', visible: true)
fill_in 'contact_first_name', with: 'Testy'
fill_in 'contact_last_name', with: 'McTest'
@@ -62,11 +65,14 @@
end

scenario 'should view and edit a contact', js: true do
FactoryGirl.create(:contact, first_name: "Testy", last_name: "McTest")
create(:contact, first_name: "Testy", last_name: "McTest", account: create(:account, name: "Toast"))
with_versioning do
visit contacts_page
click_link 'Testy McTest'
click_link 'Edit'
select = find('#select2-account_id-container', visible: true)
expect(select).to have_text("Toast")
expect(page).to have_selector('#account_name', visible: false)
fill_in 'contact_first_name', with: 'Test'
fill_in 'contact_last_name', with: 'Subject'
fill_in 'contact_email', with: "test.subject@example.com"
@@ -79,7 +85,7 @@
end

scenario 'should delete a contact', js: true do
FactoryGirl.create(:contact, first_name: "Test", last_name: "Subject")
create(:contact, first_name: "Test", last_name: "Subject")
visit contacts_page
click_link 'Test Subject'
click_link 'Delete?'
@@ -90,7 +96,7 @@
end

scenario 'should search for a contact', js: true do
2.times { |i| FactoryGirl.create(:contact, first_name: "Test", last_name: "Subject \##{i}") }
2.times { |i| create(:contact, first_name: "Test", last_name: "Subject \##{i}") }
visit contacts_page
expect(contacts_element).to have_content('Test Subject #0')
expect(contacts_element).to have_content('Test Subject #1')
@@ -13,12 +13,12 @@
I want to see a dashboard
' do
background do
@me = FactoryGirl.create(:user)
@me = create(:user)
login_as_user(@me)

FactoryGirl.create(:task, name: 'Do your homework!', assignee: @me)
FactoryGirl.create(:opportunity, name: 'Work with the Dolphins', assignee: @me, stage: 'proposal')
FactoryGirl.create(:account, name: 'Dolphin Manufacturer', assignee: @me)
create(:task, name: 'Do your homework!', assignee: @me)
create(:opportunity, name: 'Work with the Dolphins', assignee: @me, stage: 'proposal')
create(:account, name: 'Dolphin Manufacturer', assignee: @me)
end

scenario "Viewing my dashboard" do
@@ -42,9 +42,9 @@

scenario "Only show a maximum of 10 entities" do
10.times do
FactoryGirl.create(:task, assignee: @me)
FactoryGirl.create(:opportunity, assignee: @me, stage: 'proposal')
FactoryGirl.create(:account, assignee: @me)
create(:task, assignee: @me)
create(:opportunity, assignee: @me, stage: 'proposal')
create(:account, assignee: @me)
end

visit homepage
@@ -17,7 +17,7 @@
end

scenario 'should view a list of leads' do
4.times { |i| FactoryGirl.create(:lead, first_name: "L", last_name: "Ead #{i}") }
4.times { |i| create(:lead, first_name: "L", last_name: "Ead #{i}") }
visit leads_page
expect(leads_element).to have_content('L Ead 0')
expect(leads_element).to have_content('L Ead 1')
@@ -70,7 +70,7 @@
end

scenario 'should view and edit a lead', js: true do
FactoryGirl.create(:lead, first_name: "Mr", last_name: "Lead", email: "mr_lead@example.com")
create(:lead, first_name: "Mr", last_name: "Lead", email: "mr_lead@example.com")
with_versioning do
visit leads_page
click_link 'Mr Lead'
@@ -89,7 +89,7 @@
end

scenario 'should delete a lead', js: true do
FactoryGirl.create(:lead, first_name: "Mr", last_name: "Lead", email: "mr_lead@example.com")
create(:lead, first_name: "Mr", last_name: "Lead", email: "mr_lead@example.com")
visit leads_page
click_link 'Mr Lead'
click_link 'Delete?'
@@ -101,7 +101,7 @@
end

scenario 'should search for a lead', js: true do
2.times { |i| FactoryGirl.create(:lead, first_name: "Lead", last_name: "\##{i}", email: "lead#{i}@example.com") }
2.times { |i| create(:lead, first_name: "Lead", last_name: "\##{i}", email: "lead#{i}@example.com") }
visit leads_page
expect(leads_element).to have_content('Lead #0')
expect(leads_element).to have_content('Lead #1')
@@ -13,7 +13,7 @@
I want to see an overview of opportunities broken down by user
" do
background do
@me = FactoryGirl.create(:user)
@me = create(:user)

login_as_user(@me)
end
@@ -28,18 +28,18 @@
end

scenario "Viewing Opportunity Overview when all opportunities have been assigned" do
user1 = FactoryGirl.create(:user, first_name: "Brian", last_name: 'Doyle-Murray')
FactoryGirl.create(:opportunity, name: "Acting", stage: 'prospecting', assignee: user1)
FactoryGirl.create(:opportunity, name: "Directing", stage: 'won', assignee: user1)
user1 = create(:user, first_name: "Brian", last_name: 'Doyle-Murray')
create(:opportunity, name: "Acting", stage: 'prospecting', assignee: user1)
create(:opportunity, name: "Directing", stage: 'won', assignee: user1)

user2 = FactoryGirl.create(:user, first_name: "Dean", last_name: 'Stockwell')
account1 = FactoryGirl.create(:account, name: 'Quantum Leap')
FactoryGirl.create(:opportunity, name: "Leaping", stage: 'prospecting', account: account1, assignee: user2)
FactoryGirl.create(:opportunity, name: "Return Home", stage: 'prospecting', account: account1, assignee: user2)
user2 = create(:user, first_name: "Dean", last_name: 'Stockwell')
account1 = create(:account, name: 'Quantum Leap')
create(:opportunity, name: "Leaping", stage: 'prospecting', account: account1, assignee: user2)
create(:opportunity, name: "Return Home", stage: 'prospecting', account: account1, assignee: user2)

user3 = FactoryGirl.create(:user, first_name: "Chris", last_name: 'Jarvis')
FactoryGirl.create(:opportunity, stage: 'won', assignee: user3)
FactoryGirl.create(:opportunity, stage: 'lost', assignee: user3)
user3 = create(:user, first_name: "Chris", last_name: 'Jarvis')
create(:opportunity, stage: 'won', assignee: user3)
create(:opportunity, stage: 'lost', assignee: user3)

visit opportunity_overview_page

@@ -61,8 +61,8 @@
end

scenario "Viewing Opportunity Overview when all opportunities are unassigned" do
FactoryGirl.create(:opportunity, name: "Acting", stage: 'prospecting', assignee: nil)
FactoryGirl.create(:opportunity, name: "Presenting", stage: 'won', assignee: nil)
create(:opportunity, name: "Acting", stage: 'prospecting', assignee: nil)
create(:opportunity, name: "Presenting", stage: 'won', assignee: nil)

visit opportunity_overview_page

@@ -74,8 +74,8 @@
end

scenario "Viewing Opportunity Overview when there are no opportunities in the pipeline" do
FactoryGirl.create(:opportunity, name: "Presenting", stage: 'lost', assignee: FactoryGirl.create(:user))
FactoryGirl.create(:opportunity, name: "Eating", stage: 'won', assignee: nil)
create(:opportunity, name: "Presenting", stage: 'lost', assignee: create(:user))
create(:opportunity, name: "Eating", stage: 'won', assignee: nil)

visit opportunity_overview_page

@@ -17,7 +17,7 @@
end

scenario 'should view a list of opportunities' do
3.times { |i| FactoryGirl.create(:opportunity, name: "Opportunity #{i}") }
3.times { |i| create(:opportunity, name: "Opportunity #{i}") }
visit opportunities_page
expect(page).to have_content('Opportunity 0')
expect(page).to have_content('Opportunity 1')
@@ -26,13 +26,18 @@
end

scenario 'should create a new opportunity', js: true do
FactoryGirl.create(:account, name: 'Example Account')
create(:account, name: 'Example Account')
with_versioning do
visit opportunities_page
click_link 'Create Opportunity'
expect(page).to have_selector('#opportunity_name', visible: true)
fill_in 'opportunity_name', with: 'My Awesome Opportunity'
fill_in 'account_name', with: 'Example Account'
click_link 'select existing'
find('#select2-account_id-container').click
find('.select2-search--dropdown').find('input').set('Example Account')
sleep(1)
find('li', text: 'Example Account').click
expect(page).to have_content('Example Account')
select 'Prospecting', from: 'opportunity_stage'
click_link 'Comment'
fill_in 'comment_body', with: 'This is a very important opportunity.'
@@ -48,6 +53,17 @@
end
end

scenario 'should not display ammount with zero value', js: true do
with_amount = create(:opportunity, name: 'With Amount', amount: 3000, probability: 90, discount: nil, stage: 'proposal')
without_amount = create(:opportunity, name: 'Without Amount', amount: nil, probability: nil, discount: nil, stage: 'proposal')
with_versioning do
visit opportunities_page
click_link 'Long format'
expect(find("#opportunity_#{with_amount.id}")).to have_content('$3,000 | Probability 90%')
expect(find("#opportunity_#{without_amount.id}")).not_to have_content('$0 | Discount $0 | Probability 0%')
end
end

scenario "remembers the comment field when the creation was unsuccessful", js: true do
visit opportunities_page
click_link 'Create Opportunity'
@@ -61,9 +77,9 @@
end

scenario 'should view and edit an opportunity', js: true do
FactoryGirl.create(:account, name: 'Example Account')
FactoryGirl.create(:account, name: 'Other Example Account')
FactoryGirl.create(:opportunity, name: 'A Cool Opportunity')
create(:account, name: 'Example Account')
create(:account, name: 'Other Example Account')
create(:opportunity, name: 'A Cool Opportunity')
with_versioning do
visit opportunities_page
click_link 'A Cool Opportunity'
@@ -79,7 +95,7 @@
end

scenario 'should delete an opportunity', js: true do
FactoryGirl.create(:opportunity, name: 'Outdated Opportunity')
create(:opportunity, name: 'Outdated Opportunity')
visit opportunities_page
click_link 'Outdated Opportunity'
click_link 'Delete?'
@@ -89,7 +105,7 @@
end

scenario 'should search for an opportunity', js: true do
2.times { |i| FactoryGirl.create(:opportunity, name: "Opportunity #{i}") }
2.times { |i| create(:opportunity, name: "Opportunity #{i}") }
visit opportunities_page
expect(find('#opportunities')).to have_content("Opportunity 0")
expect(find('#opportunities')).to have_content("Opportunity 1")
@@ -103,4 +119,14 @@
expect(find('#opportunities')).not_to have_content("Opportunity 0")
expect(find('#opportunities')).not_to have_content("Opportunity 1")
end

scenario 'should add note to opportunity', js: true do
opportunity = create(:opportunity, name: 'Awesome Opportunity')
visit opportunities_page
click_link 'Awesome Opportunity'
find("#opportunity_#{opportunity.id}_post_new_note").click
fill_in 'comment[comment]', with: 'Most awesome opportunity'
click_button 'Add Note'
expect(page).to have_content('Most awesome opportunity')
end
end
@@ -0,0 +1,17 @@
# frozen_string_literal: true

# Copyright (c) 2008-2013 Michael Dvorkin and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
def fill_autocomplete(field, options = {})
fill_in field, with: options[:with]
page.execute_script %{ $('##{field}').trigger('focus') }
page.execute_script %{ $('##{field}').trigger('keydown') }

selector = %{ul.ui-autocomplete li.ui-menu-item a:contains("#{options[:select]}")}
sleep(1)
expect(page).to have_selector('ul.ui-autocomplete li.ui-menu-item a')
page.execute_script %{ $('#{selector}').trigger('mouseenter').click() }
end
@@ -5,9 +5,9 @@
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
#
# Allow tests to run in Chrome browser
#
Capaybara.app_host = ENV['APP_URL'] if ENV['APP_URL']
Capybara.default_max_wait_time = 7

if ENV['BROWSER'] == 'chrome'
Capybara.register_driver :selenium do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(chromeOptions: { args: ['no-sandbox', 'headless', 'disable-gpu'] })
@@ -21,8 +21,3 @@
Capybara::Selenium::Driver.new(app, browser: :firefox, options: options, desired_capabilities: capabilities)
end
end

#
# Default timeout for extended for AJAX based application
#
Capybara.default_max_wait_time = 7
@@ -9,7 +9,7 @@ module HelperMethods
# Put helper methods you need to be available in all acceptance specs here.

def do_login(options = {})
@user = FactoryGirl.create(:user, options)
@user = create(:user, options)
visit '/login'
fill_in "authentication_username", with: @user.username
fill_in "authentication_password", with: @user.password
@@ -17,7 +17,7 @@
end

scenario 'should view a list of tasks which are assigned to the logged in user' do
4.times { |i| FactoryGirl.create(:task, name: "Task #{i}", user: @user) }
4.times { |i| create(:task, name: "Task #{i}", user: @user) }
visit tasks_page
expect(page).to have_content('Task 0')
expect(page).to have_content('Task 1')
@@ -45,7 +45,7 @@
end

scenario 'creating a task for another user', js: true do
FactoryGirl.create(:user, first_name: 'Another', last_name: 'User')
create(:user, first_name: 'Another', last_name: 'User')
with_versioning do
visit tasks_page
click_link 'Create Task'
@@ -72,7 +72,7 @@
end

scenario 'should view and edit a task', js: true do
FactoryGirl.create(:task, id: 42, name: 'Example Task', user: @user)
create(:task, id: 42, name: 'Example Task', user: @user)
with_versioning do
visit tasks_page
click_edit_for_task_id(42)
@@ -85,7 +85,7 @@
end

scenario 'should delete a task', js: true do
FactoryGirl.create(:task, id: 42, name: 'Outdated Task', user: @user)
create(:task, id: 42, name: 'Outdated Task', user: @user)
visit tasks_page
click_delete_for_task_id(42)
click_link 'Tasks'
@@ -9,7 +9,7 @@

describe Admin::FieldGroupsHelper do
it "should return the correct info text about tag restrictions and classes for groups" do
field_group = FactoryGirl.build(:field_group, klass_name: "Contact", label: "Test Field Group")
field_group = build(:field_group, klass_name: "Contact", label: "Test Field Group")
html = helper.field_group_subtitle(field_group)
expect(html).to include("Test Field Group")
expect(html).to include("This field group applies to contacts tagged with")
@@ -36,7 +36,7 @@
end

it "link_to_discard" do
lead = FactoryGirl.create(:lead)
lead = create(:lead)
allow(controller.request).to receive(:fullpath).and_return("http://www.example.com/leads/#{lead.id}")

link = helper.link_to_discard(lead)
@@ -10,7 +10,7 @@
describe TasksHelper do
describe "responding with generated links" do
before do
@task = FactoryGirl.create(:task)
@task = create(:task)
end

it "should render link to uncomplete of a task" do
@@ -8,9 +8,9 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe UsersHelper do
let(:myself) { FactoryGirl.create(:user, id: 54) }
let(:user1) { FactoryGirl.create(:user, id: 60, first_name: 'Bob', last_name: "Hope") }
let(:user2) { FactoryGirl.create(:user, id: 75, first_name: 'Billy', last_name: "Joel") }
let(:myself) { create(:user, id: 54) }
let(:user1) { create(:user, id: 60, first_name: 'Bob', last_name: "Hope") }
let(:user2) { create(:user, id: 75, first_name: 'Billy', last_name: "Joel") }

describe "user_options_for_select" do
it "includes 'myself'" do
@@ -9,7 +9,7 @@

describe FatFreeCRM::CommentExtensions do
describe "add_comment_by_user" do
let(:user) { FactoryGirl.create(:user) }
let(:user) { create(:user) }

before :each do
build_model(:commentable_entity) do
@@ -136,19 +136,19 @@
end

it "should find non-suspended user that matches From: field" do
@user = FactoryGirl.create(:user, email: @from.first, suspended_at: nil)
@user = create(:user, email: @from.first, suspended_at: nil)
expect(@crawler.send(:sent_from_known_user?, @email)).to eq(true)
expect(@crawler.instance_variable_get("@sender")).to eq(@user)
end

it "should not find user if his email doesn't match From: field" do
FactoryGirl.create(:user, email: "nobody@example.com")
create(:user, email: "nobody@example.com")
expect(@crawler.send(:sent_from_known_user?, @email)).to eq(false)
expect(@crawler.instance_variable_get("@sender")).to eq(nil)
end

it "should not find user if his email matches From: field but is suspended" do
FactoryGirl.create(:user, email: @from.first, suspended_at: Time.now)
create(:user, email: @from.first, suspended_at: Time.now)
expect(@crawler.send(:sent_from_known_user?, @email)).to eq(false)
expect(@crawler.instance_variable_get("@sender")).to eq(nil)
end
@@ -23,7 +23,7 @@
#------------------------------------------------------------------------------
describe "Processing new emails" do
before do
FactoryGirl.create(:user, email: "aaron@example.com")
create(:user, email: "aaron@example.com")
end

before(:each) do
@@ -32,7 +32,7 @@
end

it "should attach a new comment to a contact" do
@contact = FactoryGirl.create(:contact)
@contact = create(:contact)
comment_reply = "This is a new comment reply via email"

mail = Mail.new from: "Aaron Assembler <aaron@example.com>",
@@ -50,7 +50,7 @@
end

it "should attach a new comment to an opportunity, using the 'op' shortcut in subject" do
@opportunity = FactoryGirl.create(:opportunity)
@opportunity = create(:opportunity)
comment_reply = "This is a new comment reply via email"

mail = Mail.new from: "Aaron Assembler <aaron@example.com>",
@@ -28,7 +28,7 @@

it "should discard a message if it's invalid" do
expect(@crawler).to receive(:is_valid?).once.and_return(false)
FactoryGirl.create(:user, email: "aaron@example.com")
create(:user, email: "aaron@example.com")
expect(@crawler).not_to receive(:archive)
expect(@crawler).to receive(:discard).once
@crawler.run
@@ -42,7 +42,7 @@
end

it "should process a message if it finds the user" do
FactoryGirl.create(:user, email: "aaron@example.com")
create(:user, email: "aaron@example.com")
expect(@crawler).to receive(:archive).once
expect(@crawler).not_to receive(:discard)
@crawler.run
@@ -54,12 +54,12 @@
before(:each) do
mock_connect
mock_disconnect
FactoryGirl.create(:user, email: "aaron@example.com")
create(:user, email: "aaron@example.com")
end

it "should find the named asset and attach the email message" do
mock_message(DROPBOX_EMAILS[:first_line])
@campaign = FactoryGirl.create(:campaign, name: "Got milk!?")
@campaign = create(:campaign, name: "Got milk!?")
expect(@crawler).to receive(:archive).once
expect(@crawler).not_to receive(:with_recipients)
@crawler.run
@@ -82,7 +82,7 @@

it "should find the lead and attach the email message" do
mock_message(DROPBOX_EMAILS[:first_line_lead])
@lead = FactoryGirl.create(:lead, first_name: "Cindy", last_name: "Cluster")
@lead = create(:lead, first_name: "Cindy", last_name: "Cluster")
expect(@crawler).to receive(:archive).once
expect(@crawler).not_to receive(:with_recipients)
@crawler.run
@@ -106,7 +106,7 @@

it "should find the contact and attach the email message" do
mock_message(DROPBOX_EMAILS[:first_line_contact])
@contact = FactoryGirl.create(:contact, first_name: "Cindy", last_name: "Cluster")
@contact = create(:contact, first_name: "Cindy", last_name: "Cluster")
expect(@crawler).to receive(:archive).once
expect(@crawler).not_to receive(:with_recipients)
@crawler.run
@@ -141,11 +141,11 @@
mock_connect
mock_disconnect
mock_message(DROPBOX_EMAILS[:plain])
FactoryGirl.create(:user, email: "aaron@example.com")
create(:user, email: "aaron@example.com")
end

it "should find the asset and attach the email message" do
@lead = FactoryGirl.create(:lead, email: "ben@example.com", access: "Public")
@lead = create(:lead, email: "ben@example.com", access: "Public")
expect(@crawler).to receive(:archive).once
expect(@crawler).not_to receive(:with_forwarded_recipient)
@crawler.run
@@ -169,12 +169,12 @@
before(:each) do
mock_connect
mock_disconnect
FactoryGirl.create(:user, email: "aaron@example.com")
create(:user, email: "aaron@example.com")
mock_message(DROPBOX_EMAILS[:forwarded])
end

it "should find the asset and attach the email message" do
@lead = FactoryGirl.create(:lead, email: "ben@example.com", access: "Public")
@lead = create(:lead, email: "ben@example.com", access: "Public")
expect(@crawler).to receive(:archive).once
@crawler.run

@@ -187,7 +187,7 @@
timezone = ActiveRecord::Base.default_timezone
begin
ActiveRecord::Base.default_timezone = :utc
@lead = FactoryGirl.create(:lead, email: "ben@example.com", access: "Public", updated_at: 5.day.ago)
@lead = create(:lead, email: "ben@example.com", access: "Public", updated_at: 5.day.ago)

@crawler.run
expect(@lead.reload.updated_at.to_i).to be >= now.to_i
@@ -197,7 +197,7 @@
end

it "should change lead's status (:new => :contacted)" do
@lead = FactoryGirl.create(:lead, email: "ben@example.com", access: "Public", status: "new")
@lead = create(:lead, email: "ben@example.com", access: "Public", status: "new")

@crawler.run
expect(@lead.reload.status).to eq("contacted")
@@ -219,13 +219,13 @@
@settings = @crawler.instance_variable_get("@settings")
@settings[:address_aliases] = ["dropbox@example.com"]

FactoryGirl.create(:user, email: "aaron@example.com")
create(:user, email: "aaron@example.com")
mock_message(DROPBOX_EMAILS[:forwarded])
end

it "should not match the dropbox email address if routed to an alias" do
@lead = FactoryGirl.create(:lead, email: "ben@example.com", access: "Public")
@lead_dropbox = FactoryGirl.create(:lead, email: "dropbox@example.com", access: "Public")
@lead = create(:lead, email: "ben@example.com", access: "Public")
@lead_dropbox = create(:lead, email: "dropbox@example.com", access: "Public")

expect(@crawler).to receive(:archive).once
@crawler.run
@@ -240,7 +240,7 @@
before(:each) do
mock_connect
mock_disconnect
FactoryGirl.create(:user, email: "aaron@example.com")
create(:user, email: "aaron@example.com")
end

it "should create a contact from the email recipient (To: recipient, Bcc: dropbox)" do
@@ -44,8 +44,8 @@
end

it "should replace existing permissions" do
@entity.permissions << FactoryGirl.create(:permission, user_id: 1, asset: @entity)
@entity.permissions << FactoryGirl.create(:permission, user_id: 2, asset: @entity)
@entity.permissions << create(:permission, user_id: 1, asset: @entity)
@entity.permissions << create(:permission, user_id: 2, asset: @entity)
@entity.user_ids = %w[2 3]
@entity.save!
expect(@entity.permissions.size).to eq(2)
@@ -73,8 +73,8 @@
end

it "should replace existing permissions" do
@entity.permissions << FactoryGirl.build(:permission, group_id: 1, user_id: nil, asset: @entity)
@entity.permissions << FactoryGirl.build(:permission, group_id: 2, user_id: nil, asset: @entity)
@entity.permissions << build(:permission, group_id: 1, user_id: nil, asset: @entity)
@entity.permissions << build(:permission, group_id: 2, user_id: nil, asset: @entity)
expect(@entity.permissions.size).to eq(2)
@entity.group_ids = ['3']
@entity.save!
@@ -89,19 +89,19 @@
@entity = UserWithPermission.create
end
it "should delete all permissions if access is set to Public" do
perm = FactoryGirl.create(:permission, user_id: 1, asset: @entity)
perm = create(:permission, user_id: 1, asset: @entity)
expect(perm).to receive(:destroy)
expect(Permission).to receive(:where).with(asset_id: @entity.id, asset_type: @entity.class.to_s).and_return([perm])
@entity.update_attribute(:access, 'Public')
end
it "should delete all permissions if access is set to Private" do
perm = FactoryGirl.create(:permission, user_id: 1, asset: @entity)
perm = create(:permission, user_id: 1, asset: @entity)
expect(perm).to receive(:destroy)
expect(Permission).to receive(:where).with(asset_id: @entity.id, asset_type: @entity.class.to_s).and_return([perm])
@entity.update_attribute(:access, 'Private')
end
it "should not remove permissions if access is set to Shared" do
perm = FactoryGirl.create(:permission, user_id: 1, asset: @entity)
perm = create(:permission, user_id: 1, asset: @entity)
expect(perm).not_to receive(:destroy)
@entity.permissions << perm
expect(Permission).not_to receive(:find_all_by_asset_id)
@@ -110,24 +110,6 @@
end
end

describe "save_with_permissions" do
it "should raise deprecation warning and call save" do
entity = UserWithPermission.new
expect(ActiveSupport::Deprecation).to receive(:warn)
expect(entity).to receive(:save)
entity.save_with_permissions
end
end

describe "update_with_permissions" do
it "should raise deprecation warning and call update_attributes" do
entity = UserWithPermission.new
expect(ActiveSupport::Deprecation).to receive(:warn)
expect(entity).to receive(:update_attributes).with({})
entity.update_with_permissions({})
end
end

describe "save_with_model_permissions" do
it "should copy permissions from original model" do
entity = UserWithPermission.new
@@ -9,7 +9,7 @@

describe UserMailer do
describe "password_reset_instructions" do
let(:user) { FactoryGirl.build(:user, email: "forgot_my_password@example.com") }
let(:user) { build(:user, email: "forgot_my_password@example.com") }
let(:mail) { UserMailer.password_reset_instructions(user) }

before(:each) do
@@ -35,11 +35,11 @@
end

describe "assigned_entity_notification" do
let(:assigner) { FactoryGirl.build(:user, first_name: "Bob", last_name: "Hope") }
let(:assignee) { FactoryGirl.build(:user, email: "assignee@example.com") }
let(:assigner) { build(:user, first_name: "Bob", last_name: "Hope") }
let(:assignee) { build(:user, email: "assignee@example.com") }

context "for an account" do
let(:account) { FactoryGirl.build_stubbed(:account, id: 16, name: 'Ghostbusters', user: assigner, assignee: assignee) }
let(:account) { build_stubbed(:account, id: 16, name: 'Ghostbusters', user: assigner, assignee: assignee) }
let(:mail) { UserMailer.assigned_entity_notification(account, assigner) }

it "sets fatfree as the sender" do
@@ -64,7 +64,7 @@
end

context "for a contact" do
let(:contact) { FactoryGirl.build_stubbed(:contact, id: 56, first_name: 'Harold', last_name: 'Ramis', user: assigner, assignee: assignee) }
let(:contact) { build_stubbed(:contact, id: 56, first_name: 'Harold', last_name: 'Ramis', user: assigner, assignee: assignee) }
let(:mail) { UserMailer.assigned_entity_notification(contact, assigner) }

it "sets fatfree as the sender" do
@@ -89,7 +89,7 @@
end

context "for a lead" do
let(:lead) { FactoryGirl.build_stubbed(:lead, id: 42, first_name: 'Bill', last_name: 'Murray', user: assigner, assignee: assignee) }
let(:lead) { build_stubbed(:lead, id: 42, first_name: 'Bill', last_name: 'Murray', user: assigner, assignee: assignee) }
let(:mail) { UserMailer.assigned_entity_notification(lead, assigner) }

it "sets fatfree as the sender" do
@@ -114,7 +114,7 @@
end

context "for an opportunity" do
let(:opportunity) { FactoryGirl.create(:opportunity, id: 24, name: 'Big', user: assigner, assignee: assignee) }
let(:opportunity) { create(:opportunity, id: 24, name: 'Big', user: assigner, assignee: assignee) }
let(:mail) { UserMailer.assigned_entity_notification(opportunity, assigner) }

it "sets fatfree as the sender" do
@@ -30,22 +30,20 @@
require 'spec_helper'

describe Account do
let(:current_user) { FactoryGirl.create(:user) }

it "should create a new instance given valid attributes" do
Account.create!(name: "Test Account", user: FactoryGirl.create(:user))
Account.create!(name: "Test Account")
end

describe "Attach" do
before do
@account = FactoryGirl.create(:account)
@account = create(:account)
end

it "should return nil when attaching existing asset" do
@task = FactoryGirl.create(:task, asset: @account, user: current_user)
@contact = FactoryGirl.create(:contact)
@task = create(:task, asset: @account)
@contact = create(:contact)
@account.contacts << @contact
@opportunity = FactoryGirl.create(:opportunity)
@opportunity = create(:opportunity)
@account.opportunities << @opportunity

expect(@account.attach!(@task)).to eq(nil)
@@ -54,9 +52,9 @@
end

it "should return non-empty list of attachments when attaching new asset" do
@task = FactoryGirl.create(:task, user: current_user)
@contact = FactoryGirl.create(:contact)
@opportunity = FactoryGirl.create(:opportunity)
@task = create(:task)
@contact = create(:contact)
@opportunity = create(:opportunity)

expect(@account.attach!(@task)).to eq([@task])
expect(@account.attach!(@contact)).to eq([@contact])
@@ -66,11 +64,11 @@

describe "Discard" do
before do
@account = FactoryGirl.create(:account)
@account = create(:account)
end

it "should discard a task" do
@task = FactoryGirl.create(:task, asset: @account, user: current_user)
@task = create(:task, asset: @account)
expect(@account.tasks.count).to eq(1)

@account.discard!(@task)
@@ -79,7 +77,7 @@
end

it "should discard a contact" do
@contact = FactoryGirl.create(:contact)
@contact = create(:contact)
@account.contacts << @contact
expect(@account.contacts.count).to eq(1)

@@ -91,7 +89,7 @@
# Commented out this test. "super from singleton method that is defined to multiple classes is not supported;"
# ------------------------------------------------------
# it "should discard an opportunity" do
# @opportunity = FactoryGirl.create(:opportunity)
# @opportunity = create(:opportunity)
# @account.opportunities << @opportunity
# @account.opportunities.count.should == 1

@@ -103,16 +101,16 @@

describe "Exportable" do
describe "assigned account" do
let(:account1) { FactoryGirl.build(:account, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user)) }
let(:account2) { FactoryGirl.build(:account, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: FactoryGirl.create(:user, first_name: nil, last_name: nil)) }
let(:account1) { build(:account, assignee: create(:user)) }
let(:account2) { build(:account, user: create(:user, first_name: nil, last_name: nil), assignee: create(:user, first_name: nil, last_name: nil)) }
it_should_behave_like("exportable") do
let(:exported) { [account1, account2] }
end
end

describe "unassigned account" do
let(:account1) { FactoryGirl.build(:account, user: FactoryGirl.create(:user), assignee: nil) }
let(:account2) { FactoryGirl.build(:account, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: nil) }
let(:account1) { build(:account, assignee: nil) }
let(:account2) { build(:account, user: create(:user, first_name: nil, last_name: nil), assignee: nil) }
it_should_behave_like("exportable") do
let(:exported) { [account1, account2] }
end
@@ -121,13 +119,13 @@

describe "Before save" do
it "create new: should replace empty category string with nil" do
account = FactoryGirl.build(:account, category: '')
account = build(:account, category: '')
account.save
expect(account.category).to eq(nil)
end

it "update existing: should replace empty category string with nil" do
account = FactoryGirl.create(:account, category: '')
account = create(:account, category: '')
account.save
expect(account.category).to eq(nil)
end
@@ -139,13 +137,14 @@

describe "scopes" do
context "visible_on_dashboard" do
before :each do
@user = FactoryGirl.create(:user)
@a1 = FactoryGirl.create(:account, user: @user)
@a2 = FactoryGirl.create(:account, user: @user, assignee: FactoryGirl.create(:user))
@a3 = FactoryGirl.create(:account, user: FactoryGirl.create(:user), assignee: @user)
@a4 = FactoryGirl.create(:account, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user))
@a5 = FactoryGirl.create(:account, user: FactoryGirl.create(:user), assignee: @user)
before do
@another_user = create(:user)
@user = create(:user)
@a1 = create(:account, user: @user)
@a2 = create(:account, user: @user, assignee: @another_user)
@a3 = create(:account, assignee: @user)
@a4 = create(:account, assignee: @another_user)
@a5 = create(:account, assignee: @user)
end

it "should show accounts which have been created by the user and are unassigned" do
@@ -167,11 +166,11 @@

context "by_name" do
it "should show accounts ordered by name" do
@a1 = FactoryGirl.create(:account, name: "Account A")
@a2 = FactoryGirl.create(:account, name: "Account Z")
@a3 = FactoryGirl.create(:account, name: "Account J")
@a4 = FactoryGirl.create(:account, name: "Account X")
@a5 = FactoryGirl.create(:account, name: "Account L")
@a1 = create(:account, name: "Account A")
@a2 = create(:account, name: "Account Z")
@a3 = create(:account, name: "Account J")
@a4 = create(:account, name: "Account X")
@a5 = create(:account, name: "Account L")

expect(Account.by_name).to eq([@a1, @a3, @a5, @a4, @a2])
end
@@ -34,31 +34,25 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Campaign do
let(:current_user) { FactoryGirl.create(:user) }

it "should create a new instance given valid attributes" do
Campaign.create!(name: "Campaign", user: FactoryGirl.create(:user))
Campaign.create!(name: "Campaign")
end

describe "Attach" do
before do
@campaign = FactoryGirl.create(:campaign)
@campaign = create(:campaign)
end

it "should return nil when attaching existing asset" do
@task = FactoryGirl.create(:task, asset: @campaign, user: current_user)
@lead = FactoryGirl.create(:lead, campaign: @campaign)
@opportunity = FactoryGirl.create(:opportunity, campaign: @campaign)

expect(@campaign.attach!(@task)).to eq(nil)
expect(@campaign.attach!(@lead)).to eq(nil)
expect(@campaign.attach!(@opportunity)).to eq(nil)
expect(@campaign.attach!(create(:task, asset: @campaign))).to eq(nil)
expect(@campaign.attach!(create(:lead, campaign: @campaign))).to eq(nil)
expect(@campaign.attach!(create(:opportunity, campaign: @campaign))).to eq(nil)
end

it "should return non-empty list of attachments when attaching new asset" do
@task = FactoryGirl.create(:task, user: current_user)
@lead = FactoryGirl.create(:lead)
@opportunity = FactoryGirl.create(:opportunity)
@task = create(:task)
@lead = create(:lead)
@opportunity = create(:opportunity)

expect(@campaign.attach!(@task)).to eq([@task])
expect(@campaign.attach!(@lead)).to eq([@lead])
@@ -67,27 +61,26 @@

it "should increment leads count when attaching a new lead" do
@leads_count = @campaign.leads_count
@lead = FactoryGirl.create(:lead)

@campaign.attach!(@lead)
@campaign.attach!(create(:lead))
expect(@campaign.reload.leads_count).to eq(@leads_count + 1)
end

it "should increment opportunities count when attaching new opportunity" do
@opportunities_count = @campaign.opportunities_count
@opportunity = FactoryGirl.create(:opportunity)
@opportunity = create(:opportunity)
@campaign.attach!(@opportunity)
expect(@campaign.reload.opportunities_count).to eq(@opportunities_count + 1)
end
end

describe "Detach" do
before do
@campaign = FactoryGirl.create(:campaign, leads_count: 42, opportunities_count: 42)
@campaign = create(:campaign, leads_count: 42, opportunities_count: 42)
end

it "should discard a task" do
@task = FactoryGirl.create(:task, asset: @campaign, user: current_user)
@task = create(:task, asset: @campaign)
expect(@campaign.tasks.count).to eq(1)

@campaign.discard!(@task)
@@ -96,7 +89,7 @@
end

it "should discard a lead" do
@lead = FactoryGirl.create(:lead, campaign: @campaign)
@lead = create(:lead, campaign: @campaign)
expect(@campaign.reload.leads_count).to eq(43)

@campaign.discard!(@lead)
@@ -105,7 +98,7 @@
end

it "should discard an opportunity" do
@opportunity = FactoryGirl.create(:opportunity, campaign: @campaign)
@opportunity = create(:opportunity, campaign: @campaign)
expect(@campaign.reload.opportunities_count).to eq(43)

@campaign.discard!(@opportunity)
@@ -116,16 +109,16 @@

describe "Exportable" do
describe "assigned campaign" do
let(:campaign1) { FactoryGirl.build(:campaign, user: FactoryGirl.create(:user, first_name: "John", last_name: "Smith"), assignee: FactoryGirl.create(:user)) }
let(:campaign2) { FactoryGirl.build(:campaign, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: FactoryGirl.create(:user, first_name: nil, last_name: nil)) }
let(:campaign1) { build(:campaign, user: create(:user, first_name: "John", last_name: "Smith"), assignee: create(:user)) }
let(:campaign2) { build(:campaign, user: create(:user, first_name: nil, last_name: nil), assignee: create(:user, first_name: nil, last_name: nil)) }
it_should_behave_like("exportable") do
let(:exported) { [campaign1, campaign2] }
end
end

describe "unassigned campaign" do
let(:campaign1) { FactoryGirl.build(:campaign, user: FactoryGirl.create(:user), assignee: nil) }
let(:campaign2) { FactoryGirl.build(:campaign, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: nil) }
let(:campaign1) { build(:campaign, user: create(:user), assignee: nil) }
let(:campaign2) { build(:campaign, user: create(:user, first_name: nil, last_name: nil), assignee: nil) }
it_should_behave_like("exportable") do
let(:exported) { [campaign1, campaign2] }
end
@@ -41,16 +41,13 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Contact do
let(:current_user) { FactoryGirl.create(:user) }

it "should create a new instance given valid attributes" do
Contact.create!(first_name: "Billy", last_name: "Bones")
end

describe "Update existing contact" do
before(:each) do
@account = FactoryGirl.create(:account)
@contact = FactoryGirl.create(:contact, account: @account)
@contact = create(:contact, account: create(:account))
end

it "should create new account if requested so" do
@@ -65,7 +62,7 @@
end

it "should change account if another account was selected" do
@another_account = FactoryGirl.create(:account)
@another_account = create(:account)
expect do
@contact.update_with_account_and_permissions(
account: { id: @another_account.id },
@@ -99,7 +96,7 @@
end

it "should change account if entered name of another account was found" do
@another_account = FactoryGirl.create(:account, name: "Another name")
@another_account = create(:account, name: "Another name")
expect do
@contact.update_with_account_and_permissions(
account: { name: "Another name" },
@@ -113,21 +110,21 @@

describe "Attach" do
before do
@contact = FactoryGirl.create(:contact)
@contact = create(:contact)
end

it "should return nil when attaching existing asset" do
@task = FactoryGirl.create(:task, asset: @contact, user: current_user)
@opportunity = FactoryGirl.create(:opportunity)
@task = create(:task, asset: @contact)
@opportunity = create(:opportunity)
@contact.opportunities << @opportunity

expect(@contact.attach!(@task)).to eq(nil)
expect(@contact.attach!(@opportunity)).to eq(nil)
end

it "should return non-empty list of attachments when attaching new asset" do
@task = FactoryGirl.create(:task, user: current_user)
@opportunity = FactoryGirl.create(:opportunity)
@task = create(:task)
@opportunity = create(:opportunity)

expect(@contact.attach!(@task)).to eq([@task])
expect(@contact.attach!(@opportunity)).to eq([@opportunity])
@@ -136,11 +133,11 @@

describe "Discard" do
before do
@contact = FactoryGirl.create(:contact)
@contact = create(:contact)
end

it "should discard a task" do
@task = FactoryGirl.create(:task, asset: @contact, user: current_user)
@task = create(:task, asset: @contact)
expect(@contact.tasks.count).to eq(1)

@contact.discard!(@task)
@@ -149,7 +146,7 @@
end

it "should discard an opportunity" do
@opportunity = FactoryGirl.create(:opportunity)
@opportunity = create(:opportunity)
@contact.opportunities << @opportunity
expect(@contact.opportunities.count).to eq(1)

@@ -161,16 +158,16 @@

describe "Exportable" do
describe "assigned contact" do
let(:contact1) { FactoryGirl.build(:contact, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user)) }
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)) }
let(:contact1) { build(:contact, assignee: create(:user)) }
let(:contact2) { build(:contact, user: create(:user, first_name: nil, last_name: nil), assignee: create(:user, first_name: nil, last_name: nil)) }
it_should_behave_like("exportable") do
let(:exported) { [contact1, contact2] }
end
end

describe "unassigned contact" do
let(:contact1) { FactoryGirl.build(:contact, user: FactoryGirl.create(:user), assignee: nil) }
let(:contact2) { FactoryGirl.build(:contact, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: nil) }
let(:contact1) { build(:contact, assignee: nil) }
let(:contact2) { build(:contact, user: create(:user, first_name: nil, last_name: nil), assignee: nil) }
it_should_behave_like("exportable") do
let(:exported) { [contact1, contact2] }
end
@@ -182,8 +179,8 @@
end

describe "text_search" do
before(:each) do
@contact = FactoryGirl.create(:contact, first_name: "Bob", last_name: "Dillion", email: 'bob_dillion@example.com', phone: '+1 123 456 789')
before do
@contact = create(:contact, first_name: "Bob", last_name: "Dillion", email: 'bob_dillion@example.com', phone: '+1 123 456 789')
end

it "should search first_name" do
@@ -211,7 +208,7 @@
end

it "should not break with a single quote" do
contact2 = FactoryGirl.create(:contact, first_name: "Shamus", last_name: "O'Connell", email: 'bob_dillion@example.com', phone: '+1 123 456 789')
contact2 = create(:contact, first_name: "Shamus", last_name: "O'Connell", email: 'bob_dillion@example.com', phone: '+1 123 456 789')
expect(Contact.text_search("O'Connell")).to eq([contact2])
end

@@ -41,37 +41,35 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Lead do
let(:current_user) { FactoryGirl.create(:user) }

it "should create a new instance given valid attributes" do
Lead.create!(first_name: "Billy", last_name: "Bones")
end

describe "Attach" do
before do
@lead = FactoryGirl.create(:lead)
@lead = create(:lead)
end

it "should return nil when attaching existing task" do
@task = FactoryGirl.create(:task, asset: @lead, user: current_user)
@task = create(:task, asset: @lead)

expect(@lead.attach!(@task)).to eq(nil)
end

it "should return non-empty list of tasks when attaching new task" do
@task = FactoryGirl.create(:task, user: current_user)
@task = create(:task)

expect(@lead.attach!(@task)).to eq([@task])
end
end

describe "Discard" do
before do
@lead = FactoryGirl.create(:lead)
@lead = create(:lead)
end

it "should discard a task" do
@task = FactoryGirl.create(:task, asset: @lead, user: current_user)
@task = create(:task, asset: @lead)
expect(@lead.tasks.count).to eq(1)

@lead.discard!(@task)
@@ -82,16 +80,16 @@

describe "Exportable" do
describe "assigned lead" do
let(:lead1) { FactoryGirl.build(:lead, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user)) }
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)) }
let(:lead1) { build(:lead, assignee: create(:user)) }
let(:lead2) { build(:lead, user: create(:user, first_name: nil, last_name: nil), assignee: create(:user, first_name: nil, last_name: nil)) }
it_should_behave_like("exportable") do
let(:exported) { [lead1, lead2] }
end
end

describe "unassigned lead" do
let(:lead1) { FactoryGirl.build(:lead, user: FactoryGirl.create(:user), assignee: nil) }
let(:lead2) { FactoryGirl.build(:lead, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: nil) }
let(:lead1) { build(:lead, assignee: nil) }
let(:lead2) { build(:lead, user: create(:user, first_name: nil, last_name: nil), assignee: nil) }
it_should_behave_like("exportable") do
let(:exported) { [lead1, lead2] }
end
@@ -35,8 +35,8 @@
end

it "should be possible to create opportunity with the same name" do
FactoryGirl.create(:opportunity, name: "Hello")
expect { FactoryGirl.create(:opportunity, name: "Hello") }.to_not raise_error
create(:opportunity, name: "Hello")
expect { create(:opportunity, name: "Hello") }.to_not raise_error
end

it "have a default stage" do
@@ -50,8 +50,8 @@

describe "Update existing opportunity" do
before(:each) do
@account = FactoryGirl.create(:account)
@opportunity = FactoryGirl.create(:opportunity, account: @account)
@account = create(:account)
@opportunity = create(:opportunity, account: @account)
end

it "should create new account if requested so" do
@@ -66,7 +66,7 @@
end

it "should update the account another account was selected" do
@another_account = FactoryGirl.create(:account)
@another_account = create(:account)
expect do
@opportunity.update_with_account_and_permissions(
account: { id: @another_account.id },
@@ -100,7 +100,7 @@
end

it "should change account if entered name of another account was found" do
@another_account = FactoryGirl.create(:account, name: "Another name")
@another_account = create(:account, name: "Another name")
expect do
@opportunity.update_with_account_and_permissions(
account: { name: "Another name" },
@@ -112,14 +112,14 @@
end

it "should set the probability to 0% if opportunity has been lost" do
opportunity = FactoryGirl.create(:opportunity, stage: "prospecting", probability: 25)
opportunity = create(:opportunity, stage: "prospecting", probability: 25)
opportunity.update_attributes(stage: 'lost')
opportunity.reload
expect(opportunity.probability).to eq(0)
end

it "should set the probablility to 100% if opportunity has been won" do
opportunity = FactoryGirl.create(:opportunity, stage: "prospecting", probability: 65)
opportunity = create(:opportunity, stage: "prospecting", probability: 65)
opportunity.update_attributes(stage: 'won')
opportunity.reload
expect(opportunity.probability).to eq(100)
@@ -130,12 +130,12 @@
it "should find non-closed opportunities" do
Opportunity.delete_all
@opportunities = [
FactoryGirl.create(:opportunity, stage: "prospecting", amount: 1),
FactoryGirl.create(:opportunity, stage: "analysis", amount: 1),
FactoryGirl.create(:opportunity, stage: "won", amount: 2),
FactoryGirl.create(:opportunity, stage: "won", amount: 2),
FactoryGirl.create(:opportunity, stage: "lost", amount: 3),
FactoryGirl.create(:opportunity, stage: "lost", amount: 3)
create(:opportunity, stage: "prospecting", amount: 1),
create(:opportunity, stage: "analysis", amount: 1),
create(:opportunity, stage: "won", amount: 2),
create(:opportunity, stage: "won", amount: 2),
create(:opportunity, stage: "lost", amount: 3),
create(:opportunity, stage: "lost", amount: 3)
]
expect(Opportunity.pipeline.sum(:amount)).to eq(2)
expect(Opportunity.won.sum(:amount)).to eq(4)
@@ -144,8 +144,8 @@
end

context "unassigned" do
let(:unassigned_opportunity) { FactoryGirl.create(:opportunity, assignee: nil) }
let(:assigned_opportunity) { FactoryGirl.create(:opportunity, assignee: FactoryGirl.create(:user)) }
let(:unassigned_opportunity) { create(:opportunity, assignee: nil) }
let(:assigned_opportunity) { create(:opportunity, assignee: create(:user)) }

it "includes unassigned opportunities" do
expect(Opportunity.unassigned).to include(unassigned_opportunity)
@@ -159,21 +159,21 @@

describe "Attach" do
before do
@opportunity = FactoryGirl.create(:opportunity)
@opportunity = create(:opportunity)
end

it "should return nil when attaching existing asset" do
@task = FactoryGirl.create(:task, asset: @opportunity)
@contact = FactoryGirl.create(:contact)
@task = create(:task, asset: @opportunity)
@contact = create(:contact)
@opportunity.contacts << @contact

expect(@opportunity.attach!(@task)).to eq(nil)
expect(@opportunity.attach!(@contact)).to eq(nil)
end

it "should return non-empty list of attachments when attaching new asset" do
@task = FactoryGirl.create(:task)
@contact = FactoryGirl.create(:contact)
@task = create(:task)
@contact = create(:contact)

expect(@opportunity.attach!(@task)).to eq([@task])
expect(@opportunity.attach!(@contact)).to eq([@contact])
@@ -182,11 +182,11 @@

describe "Discard" do
before do
@opportunity = FactoryGirl.create(:opportunity)
@opportunity = create(:opportunity)
end

it "should discard a task" do
@task = FactoryGirl.create(:task, asset: @opportunity)
@task = create(:task, asset: @opportunity)
expect(@opportunity.tasks.count).to eq(1)

@opportunity.discard!(@task)
@@ -195,7 +195,7 @@
end

it "should discard an contact" do
@contact = FactoryGirl.create(:contact)
@contact = create(:contact)
@opportunity.contacts << @contact
expect(@opportunity.contacts.count).to eq(1)

@@ -207,16 +207,16 @@

describe "Exportable" do
describe "assigned opportunity" do
let(:opportunity1) { FactoryGirl.build(:opportunity, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user)) }
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)) }
let(:opportunity1) { build(:opportunity, user: create(:user), assignee: create(:user)) }
let(:opportunity2) { build(:opportunity, user: create(:user, first_name: nil, last_name: nil), assignee: create(:user, first_name: nil, last_name: nil)) }
it_should_behave_like("exportable") do
let(:exported) { [opportunity1, opportunity2] }
end
end

describe "unassigned opportunity" do
let(:opportunity1) { FactoryGirl.build(:opportunity, user: FactoryGirl.create(:user), assignee: nil) }
let(:opportunity2) { FactoryGirl.build(:opportunity, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: nil) }
let(:opportunity1) { build(:opportunity, user: create(:user), assignee: nil) }
let(:opportunity2) { build(:opportunity, user: create(:user, first_name: nil, last_name: nil), assignee: nil) }
it_should_behave_like("exportable") do
let(:exported) { [opportunity1, opportunity2] }
end
@@ -230,14 +230,14 @@
describe "scopes" do
context "visible_on_dashboard" do
before :each do
@user = FactoryGirl.create(:user)
@o1 = FactoryGirl.create(:opportunity_in_pipeline, user: @user, stage: 'prospecting')
@o2 = FactoryGirl.create(:opportunity_in_pipeline, user: @user, assignee: FactoryGirl.create(:user), stage: 'prospecting')
@o3 = FactoryGirl.create(:opportunity_in_pipeline, user: FactoryGirl.create(:user), assignee: @user, stage: 'prospecting')
@o4 = FactoryGirl.create(:opportunity_in_pipeline, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user), stage: 'prospecting')
@o5 = FactoryGirl.create(:opportunity_in_pipeline, user: FactoryGirl.create(:user), assignee: @user, stage: 'prospecting')
@o6 = FactoryGirl.create(:opportunity, assignee: @user, stage: 'won')
@o7 = FactoryGirl.create(:opportunity, assignee: @user, stage: 'lost')
@user = create(:user)
@o1 = create(:opportunity_in_pipeline, user: @user, stage: 'prospecting')
@o2 = create(:opportunity_in_pipeline, user: @user, assignee: create(:user), stage: 'prospecting')
@o3 = create(:opportunity_in_pipeline, user: create(:user), assignee: @user, stage: 'prospecting')
@o4 = create(:opportunity_in_pipeline, user: create(:user), assignee: create(:user), stage: 'prospecting')
@o5 = create(:opportunity_in_pipeline, user: create(:user), assignee: @user, stage: 'prospecting')
@o6 = create(:opportunity, assignee: @user, stage: 'won')
@o7 = create(:opportunity, assignee: @user, stage: 'lost')
end

it "should show opportunities which have been created by the user and are unassigned" do
@@ -263,29 +263,29 @@
end

context "by_closes_on" do
let(:o1) { FactoryGirl.create(:opportunity, closes_on: 3.days.from_now) }
let(:o2) { FactoryGirl.create(:opportunity, closes_on: 7.days.from_now) }
let(:o3) { FactoryGirl.create(:opportunity, closes_on: 5.days.from_now) }
let(:o1) { create(:opportunity, closes_on: 3.days.from_now) }
let(:o2) { create(:opportunity, closes_on: 7.days.from_now) }
let(:o3) { create(:opportunity, closes_on: 5.days.from_now) }

it "should show opportunities ordered by closes on" do
expect(Opportunity.by_closes_on).to eq([o1, o3, o2])
end
end

context "by_amount" do
let(:o1) { FactoryGirl.create(:opportunity, amount: 50_000) }
let(:o2) { FactoryGirl.create(:opportunity, amount: 10_000) }
let(:o3) { FactoryGirl.create(:opportunity, amount: 750_000) }
let(:o1) { create(:opportunity, amount: 50_000) }
let(:o2) { create(:opportunity, amount: 10_000) }
let(:o3) { create(:opportunity, amount: 750_000) }

it "should show opportunities ordered by amount" do
expect(Opportunity.by_amount).to eq([o3, o1, o2])
end
end

context "not lost" do
let(:o1) { FactoryGirl.create(:opportunity, stage: 'won') }
let(:o2) { FactoryGirl.create(:opportunity, stage: 'lost') }
let(:o3) { FactoryGirl.create(:opportunity, stage: 'analysis') }
let(:o1) { create(:opportunity, stage: 'won') }
let(:o2) { create(:opportunity, stage: 'lost') }
let(:o3) { create(:opportunity, stage: 'analysis') }

it "should show opportunities which are not lost" do
expect(Opportunity.not_lost).to include(o1, o3)
@@ -35,16 +35,16 @@
expect(Contact).to receive(:reset_column_information)
expect(Contact).to receive(:serialize_custom_fields!)

FactoryGirl.create(:custom_field,
as: "string",
name: "cf_test_field",
label: "Test Field",
field_group: FactoryGirl.create(:field_group, klass_name: "Contact"))
create(:custom_field,
as: "string",
name: "cf_test_field",
label: "Test Field",
field_group: create(:field_group, klass_name: "Contact"))
end

it "should generate a unique column name for a custom field" do
field_group = FactoryGirl.build(:field_group, klass_name: "Contact")
c = FactoryGirl.build(:custom_field, label: "Test Field", field_group: field_group)
field_group = build(:field_group, klass_name: "Contact")
c = build(:custom_field, label: "Test Field", field_group: field_group)

columns = []
%w[cf_test_field cf_test_field_2 cf_test_field_3 cf_test_field_4].each do |field|
@@ -54,20 +54,20 @@
end

it "should evaluate the safety of database transitions" do
c = FactoryGirl.build(:custom_field, as: "string")
c = build(:custom_field, as: "string")
expect(c.send(:db_transition_safety, c.as, "email")).to eq(:null)
expect(c.send(:db_transition_safety, c.as, "text")).to eq(:safe)
expect(c.send(:db_transition_safety, c.as, "datetime")).to eq(:unsafe)

c = FactoryGirl.build(:custom_field, as: "datetime")
c = build(:custom_field, as: "datetime")
expect(c.send(:db_transition_safety, c.as, "date")).to eq(:safe)
expect(c.send(:db_transition_safety, c.as, "url")).to eq(:unsafe)
end

it "should return a safe list of types for the 'as' select options" do
{ "email" => %w[check_boxes text string email url tel select radio_buttons],
"integer" => %w[integer float] }.each do |type, expected_arr|
c = FactoryGirl.build(:custom_field, as: type)
c = build(:custom_field, as: type)
opts = c.available_as
expect(opts.map(&:first)).to match_array(expected_arr)
end
@@ -81,12 +81,12 @@
expect(Contact).to receive(:reset_column_information).twice
expect(Contact).to receive(:serialize_custom_fields!).twice

field_group = FactoryGirl.create(:field_group, klass_name: "Contact")
c = FactoryGirl.create(:custom_field,
label: "Test Field",
name: nil,
as: "email",
field_group: field_group)
field_group = create(:field_group, klass_name: "Contact")
c = create(:custom_field,
label: "Test Field",
name: nil,
as: "email",
field_group: field_group)
c.as = "text"
c.save
end
@@ -102,7 +102,7 @@
expect(Contact).to receive(:reset_column_information)
expect(Contact).to receive(:serialize_custom_fields!)

contact = FactoryGirl.build(:contact)
contact = build(:contact)
expect(contact.cf_another_new_field).to eq(nil)
end
end
@@ -10,10 +10,10 @@
describe List do
it "should parse the controller from the url" do
["/controller/action", "controller/action?utf8=%E2%9C%93"].each do |url|
list = FactoryGirl.build(:list, url: url)
list = build(:list, url: url)
expect(list.controller).to eq("controller")
end
list = FactoryGirl.build(:list, url: nil)
list = build(:list, url: nil)
expect(list.controller).to eq(nil)
end
end
@@ -15,9 +15,9 @@

%i[account contact lead opportunity].each do |entity_type|
describe "on creation of #{entity_type}" do
let(:assignee) { FactoryGirl.create(:user) }
let(:assigner) { FactoryGirl.create(:user) }
let!(:entity) { FactoryGirl.build(entity_type, user: assigner, assignee: assignee) }
let(:assignee) { create(:user) }
let(:assigner) { create(:user) }
let!(:entity) { build(entity_type, user: assigner, assignee: assignee) }
let(:mail) { double('mail', deliver_now: true) }

after :each do
@@ -45,9 +45,9 @@
end

describe "on update of #{entity_type}" do
let(:assignee) { FactoryGirl.create(:user) }
let(:assigner) { FactoryGirl.create(:user) }
let!(:entity) { FactoryGirl.create(entity_type, user: FactoryGirl.create(:user)) }
let(:assignee) { create(:user) }
let(:assigner) { create(:user) }
let!(:entity) { create(entity_type, user: create(:user)) }
let(:mail) { double('mail', deliver_now: true) }

it "notifies the new owner if the entity is re-assigned" do
@@ -29,6 +29,6 @@

describe Address do
it "should create a new instance given valid attributes" do
Address.create!(street1: "street1", street2: "street2", city: "city", state: "state", zipcode: "zipcode", country: "country", full_address: "fa", address_type: "Lead", addressable: FactoryGirl.create(:lead))
Address.create!(street1: "street1", street2: "street2", city: "city", state: "state", zipcode: "zipcode", country: "country", full_address: "fa", address_type: "Lead", addressable: create(:lead))
end
end
@@ -24,22 +24,22 @@

describe Avatar do
before(:each) do
@user = FactoryGirl.create(:user)
@user = create(:user)
end

it "should create a new instance given valid attributes" do
expect(FactoryGirl.create(:avatar, entity: @user)).to be_valid
expect(create(:avatar, entity: @user)).to be_valid
end

it "user should have one avatar as entity" do
avatar = FactoryGirl.create(:avatar, entity: @user)
avatar = create(:avatar, entity: @user)
expect(@user.avatar).to eq(avatar)
end

it "user might have many avatars as owner" do
avatars = [
FactoryGirl.create(:avatar, user: @user, entity: FactoryGirl.create(:user)),
FactoryGirl.create(:avatar, user: @user, entity: FactoryGirl.create(:user))
create(:avatar, user: @user, entity: create(:user)),
create(:avatar, user: @user, entity: create(:user))
]
expect(@user.avatars).to eq(avatars)
end
@@ -25,17 +25,17 @@

describe Comment do
it "should create a new instance given valid attributes" do
Comment.create!(comment: "Hello", user: FactoryGirl.create(:user), commentable: FactoryGirl.create(:lead))
Comment.create!(comment: "Hello", user: create(:user), commentable: create(:lead))
end

it "should subscribe users mentioned in the comment to the entity, and notify them via email" do
expected_users = [
FactoryGirl.create(:user, username: "test_user"),
FactoryGirl.create(:user, username: "another_user")
create(:user, username: "test_user"),
create(:user, username: "another_user")
]
entity = FactoryGirl.create(:lead)
entity = create(:lead)
Comment.create!(comment: "Hey @test_user, take a look at this. Also show @another_user",
user: FactoryGirl.create(:user),
user: create(:user),
commentable: entity)

expected_users.each do |user|
@@ -32,11 +32,9 @@
require 'spec_helper'

describe Task do
let(:current_user) { FactoryGirl.create(:user) }

describe "Task/Create" do
it "should create a new task instance given valid attributes" do
task = FactoryGirl.create(:task)
task = create(:task)
expect(task).to be_valid
expect(task.errors).to be_empty
end
@@ -47,14 +45,14 @@
end

it "should create a task with due date selected from dropdown within #{offset ? 'different' : 'current'} timezone" do
task = FactoryGirl.create(:task, due_at: Time.now.end_of_week, bucket: "due_this_week")
task = create(:task, due_at: Time.now.end_of_week, bucket: "due_this_week")
expect(task.errors).to be_empty
expect(task.bucket).to eq("due_this_week")
expect(task.due_at.change(usec: 0)).to eq(Time.zone.now.end_of_week.change(usec: 0))
end

it "should create a task with due date selected from the calendar within #{offset ? 'different' : 'current'} timezone" do
task = FactoryGirl.create(:task, bucket: "specific_time", calendar: "2020-03-20")
task = create(:task, bucket: "specific_time", calendar: "2020-03-20")
expect(task.errors).to be_empty
expect(task.bucket).to eq("specific_time")
expect(task.due_at.to_i).to eq(Time.parse("2020-03-20").to_i)
@@ -64,32 +62,32 @@

describe "Task/Update" do
it "should update task name" do
task = FactoryGirl.create(:task, name: "Hello")
task = create(:task, name: "Hello")
task.update_attributes(name: "World")
expect(task.errors).to be_empty
expect(task.name).to eq("World")
end

it "should update task category" do
task = FactoryGirl.create(:task, category: "call")
task = create(:task, category: "call")
task.update_attributes(category: "email")
expect(task.errors).to be_empty
expect(task.category).to eq("email")
end

it "should reassign the task to another person" do
him = FactoryGirl.create(:user)
her = FactoryGirl.create(:user)
task = FactoryGirl.create(:task, assigned_to: him.id)
him = create(:user)
her = create(:user)
task = create(:task, assigned_to: him.id)
task.update_attributes(assigned_to: her.id)
expect(task.errors).to be_empty
expect(task.assigned_to).to eq(her.id)
expect(task.assignee).to eq(her)
end

it "should reassign the task from another person to myself" do
him = FactoryGirl.create(:user)
task = FactoryGirl.create(:task, assigned_to: him.id)
him = create(:user)
task = create(:task, assigned_to: him.id)
task.update_attributes(assigned_to: "")
expect(task.errors).to be_empty
expect(task.assigned_to).to eq(nil)
@@ -102,15 +100,15 @@
end

it "should update due date based on selected bucket within #{offset ? 'different' : 'current'} timezone" do
task = FactoryGirl.create(:task, due_at: Time.now.midnight.tomorrow, bucket: "due_tomorrow")
task = create(:task, due_at: Time.now.midnight.tomorrow, bucket: "due_tomorrow")
task.update_attributes(bucket: "due_this_week")
expect(task.errors).to be_empty
expect(task.bucket).to eq("due_this_week")
expect(task.due_at.change(usec: 0)).to eq(Time.zone.now.end_of_week.change(usec: 0))
end

it "should update due date if specific calendar date selected within #{offset ? 'different' : 'current'} timezone" do
task = FactoryGirl.create(:task, due_at: Time.now.midnight.tomorrow, bucket: "due_tomorrow")
task = create(:task, due_at: Time.now.midnight.tomorrow, bucket: "due_tomorrow")
task.update_attributes(bucket: "specific_time", calendar: "2020-03-20")
expect(task.errors).to be_empty
expect(task.bucket).to eq("specific_time")
@@ -120,110 +118,119 @@
end

describe "Task/Complete" do
it "should comlete a task that is overdue" do
task = FactoryGirl.create(:task, due_at: 2.days.ago, bucket: "overdue")
task.update_attributes(completed_at: Time.now, completed_by: current_user.id)
it "should complete a task that is overdue" do
task = create(:task, due_at: 2.days.ago, bucket: "overdue")
task.update_attributes(completed_at: Time.now, completed_by: task.user.id)

expect(task.errors).to be_empty
expect(task.completed_at).not_to eq(nil)
expect(task.completor).to eq(current_user)
expect(task.completor).to eq(task.user)
end

it "should complete a task due sometime in the future" do
task = FactoryGirl.create(:task, due_at: Time.now.midnight.tomorrow, bucket: "due_tomorrow")
task.update_attributes(completed_at: Time.now, completed_by: current_user.id)
task = create(:task, due_at: Time.now.midnight.tomorrow, bucket: "due_tomorrow")
task.update_attributes(completed_at: Time.now, completed_by: task.user.id)

expect(task.errors).to be_empty
expect(task.completed_at).not_to eq(nil)
expect(task.completor).to eq(current_user)
expect(task.completor).to eq(task.user)
end

it "should complete a task that is due on specific date in the future" do
task = FactoryGirl.create(:task, calendar: "10/10/2022 12:00 AM", bucket: "specific_time")
task = create(:task, calendar: "10/10/2022 12:00 AM", bucket: "specific_time")
task.calendar = nil # Calendar is not saved in the database; we need it only to set the :due_at.
task.update_attributes(completed_at: Time.now, completed_by: current_user.id)
task.update_attributes(completed_at: Time.now, completed_by: task.user.id)
expect(task.errors).to be_empty
expect(task.completed_at).not_to eq(nil)
expect(task.completor).to eq(current_user)
expect(task.completor).to eq(task.user)
end

it "should complete a task that is due on specific date in the past" do
task = FactoryGirl.create(:task, calendar: "10/10/1992 12:00 AM", bucket: "specific_time")
task = create(:task, calendar: "10/10/1992 12:00 AM", bucket: "specific_time")
task.calendar = nil # Calendar is not saved in the database; we need it only to set the :due_at.
task.update_attributes(completed_at: Time.now, completed_by: current_user.id)
task.update_attributes(completed_at: Time.now, completed_by: task.user.id)
expect(task.errors).to be_empty
expect(task.completed_at).not_to eq(nil)
expect(task.completor).to eq(current_user)
expect(task.completor).to eq(task.user)
end

it "completion should preserve original due date" do
due_at = Time.now - 42.days
task = FactoryGirl.create(:task, due_at: due_at, bucket: "specific_time",
calendar: due_at.strftime('%Y-%m-%d %H:%M'))
task.update_attributes(completed_at: Time.now, completed_by: current_user.id, calendar: '')
task = create(:task, due_at: due_at, bucket: "specific_time",
calendar: due_at.strftime('%Y-%m-%d %H:%M'))
task.update_attributes(completed_at: Time.now, completed_by: task.user.id, calendar: '')

expect(task.completed?).to eq(true)
expect(task.due_at).to eq(due_at.utc.strftime('%Y-%m-%d %H:%M'))
end
end

# named_scope :my, lambda { |user| { :conditions => [ "(user_id = ? AND assigned_to IS NULL) OR assigned_to = ?", user.id, user.id ], :include => :assignee } }
describe "task.my?" do
let(:current_user) { create(:user) }

it "should match a task created by the user" do
task = FactoryGirl.create(:task, user: current_user, assignee: nil)
task = create(:task, user: current_user, assignee: nil)
expect(task.my?(current_user)).to eq(true)
end

it "should match a task assigned to the user" do
task = FactoryGirl.create(:task, user: FactoryGirl.create(:user), assignee: current_user)
task = create(:task, user: create(:user), assignee: current_user)
expect(task.my?(current_user)).to eq(true)
end

it "should Not match a task not created by the user" do
task = FactoryGirl.create(:task, user: FactoryGirl.create(:user))
task = create(:task, user: create(:user))
expect(task.my?(current_user)).to eq(false)
end

it "should Not match a task created by the user but assigned to somebody else" do
task = FactoryGirl.create(:task, user: current_user, assignee: FactoryGirl.create(:user))
task = create(:task, user: current_user, assignee: create(:user))
expect(task.my?(current_user)).to eq(false)
end
end

# named_scope :assigned_by, lambda { |user| { :conditions => [ "user_id = ? AND assigned_to IS NOT NULL AND assigned_to != ?", user.id, user.id ], :include => :assignee } }
describe "task.assigned_by?" do
let(:current_user) { create(:user) }

it "should match a task assigned by the user to somebody else" do
task = FactoryGirl.create(:task, user: current_user, assignee: FactoryGirl.create(:user))
task = create(:task, user: current_user, assignee: create(:user))
expect(task.assigned_by?(current_user)).to eq(true)
end

it "should Not match a task not created by the user" do
task = FactoryGirl.create(:task, user: FactoryGirl.create(:user))
task = create(:task, user: create(:user))
expect(task.assigned_by?(current_user)).to eq(false)
end

it "should Not match a task not assigned to anybody" do
task = FactoryGirl.create(:task, assignee: nil)
task = create(:task, assignee: nil)
expect(task.assigned_by?(current_user)).to eq(false)
end

it "should Not match a task assigned to the user" do
task = FactoryGirl.create(:task, assignee: current_user)
task = create(:task, assignee: current_user)
expect(task.assigned_by?(current_user)).to eq(false)
end
end

# named_scope :tracked_by, lambda { |user| { :conditions => [ "user_id = ? OR assigned_to = ?", user.id, user.id ], :include => :assignee } }
describe "task.tracked_by?" do
let(:current_user) { create(:user) }

it "should match a task created by the user" do
task = FactoryGirl.create(:task, user: current_user)
task = create(:task, user: current_user)
expect(task.tracked_by?(current_user)).to eq(true)
end

it "should match a task assigned to the user" do
task = FactoryGirl.create(:task, assignee: current_user)
task = create(:task, assignee: current_user)
expect(task.tracked_by?(current_user)).to eq(true)
end

it "should Not match a task that is neither created nor assigned to the user" do
task = FactoryGirl.create(:task, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user))
task = create(:task, user: create(:user), assignee: create(:user))
expect(task.tracked_by?(current_user)).to eq(false)
end
end
@@ -310,24 +317,24 @@

describe "Exportable" do
describe "unassigned tasks" do
let(:task1) { FactoryGirl.build(:task, user: FactoryGirl.create(:user), assignee: nil) }
let(:task2) { FactoryGirl.build(:task, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: nil) }
let(:task1) { build(:task, user: create(:user), assignee: nil) }
let(:task2) { build(:task, user: create(:user, first_name: nil, last_name: nil), assignee: nil) }
it_should_behave_like("exportable") do
let(:exported) { [task1, task2] }
end
end

describe "assigned tasks" do
let(:task1) { FactoryGirl.build(:task, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user)) }
let(:task2) { FactoryGirl.build(:task, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), assignee: FactoryGirl.create(:user, first_name: nil, last_name: nil)) }
let(:task1) { build(:task, user: create(:user), assignee: create(:user)) }
let(:task2) { build(:task, user: create(:user, first_name: nil, last_name: nil), assignee: create(:user, first_name: nil, last_name: nil)) }
it_should_behave_like("exportable") do
let(:exported) { [task1, task2] }
end
end

describe "completed tasks" do
let(:task1) { FactoryGirl.build(:task, user: FactoryGirl.create(:user), completor: FactoryGirl.create(:user), completed_at: 1.day.ago) }
let(:task2) { FactoryGirl.build(:task, user: FactoryGirl.create(:user, first_name: nil, last_name: nil), completor: FactoryGirl.create(:user, first_name: nil, last_name: nil), completed_at: 1.day.ago) }
let(:task1) { build(:task, user: create(:user), completor: create(:user), completed_at: 1.day.ago) }
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) }
it_should_behave_like("exportable") do
let(:exported) { [task1, task2] }
end
@@ -345,13 +352,13 @@
describe "scopes" do
context "visible_on_dashboard" do
before :each do
@user = FactoryGirl.create(:user)
@t1 = FactoryGirl.create(:task, user: @user)
@t2 = FactoryGirl.create(:task, user: @user, assignee: FactoryGirl.create(:user))
@t3 = FactoryGirl.create(:task, user: FactoryGirl.create(:user), assignee: @user)
@t4 = FactoryGirl.create(:task, user: FactoryGirl.create(:user), assignee: FactoryGirl.create(:user))
@t5 = FactoryGirl.create(:task, user: FactoryGirl.create(:user), assignee: @user)
@t6 = FactoryGirl.create(:completed_task, assignee: @user)
@user = create(:user)
@t1 = create(:task, user: @user)
@t2 = create(:task, user: @user, assignee: create(:user))
@t3 = create(:task, user: create(:user), assignee: @user)
@t4 = create(:task, user: create(:user), assignee: create(:user))
@t5 = create(:task, user: create(:user), assignee: @user)
@t6 = create(:completed_task, assignee: @user)
end

it "should show tasks which have been created by the user and are unassigned" do
@@ -377,10 +384,10 @@

context "by_due_at" do
it "should show tasks ordered by due_at" do
t1 = FactoryGirl.create(:task, name: 't1', bucket: "due_asap")
t2 = FactoryGirl.create(:task, calendar: 5.days.from_now.strftime("%Y-%m-%d %H:%M"), bucket: "specific_time")
t3 = FactoryGirl.create(:task, name: 't3', bucket: "due_next_week")
t4 = FactoryGirl.create(:task, calendar: 20.days.from_now.strftime("%Y-%m-%d %H:%M"), bucket: "specific_time")
t1 = create(:task, name: 't1', bucket: "due_asap")
t2 = create(:task, calendar: 5.days.from_now.strftime("%Y-%m-%d %H:%M"), bucket: "specific_time")
t3 = create(:task, name: 't3', bucket: "due_next_week")
t4 = create(:task, calendar: 20.days.from_now.strftime("%Y-%m-%d %H:%M"), bucket: "specific_time")
expect(Task.by_due_at).to eq([t1, t2, t3, t4])
end
end
@@ -23,20 +23,20 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Version, versioning: true do
let(:current_user) { FactoryGirl.create(:user) }
let(:current_user) { create(:user) }
before { PaperTrail.whodunnit = current_user.id.to_s }

it "should create a new instance given valid attributes" do
FactoryGirl.create(:version, whodunnit: PaperTrail.whodunnit, item: FactoryGirl.create(:lead))
create(:version, whodunnit: PaperTrail.whodunnit, item: create(:lead))
end

describe "with multiple version records" do
before do
@lead = FactoryGirl.create(:lead)
@lead = create(:lead)

%w[create destroy update view].each do |event|
FactoryGirl.create(:version, event: event, item: @lead, whodunnit: PaperTrail.whodunnit)
FactoryGirl.create(:version, event: event, item: @lead, whodunnit: "1")
create(:version, event: event, item: @lead, whodunnit: PaperTrail.whodunnit)
create(:version, event: event, item: @lead, whodunnit: "1")
end
end

@@ -71,7 +71,7 @@
%w[account campaign contact lead opportunity task].each do |item|
describe "Create, update, and delete (#{item})" do
before :each do
@item = FactoryGirl.create(item.to_sym, user: current_user)
@item = create(item.to_sym, user: current_user)
@conditions = { item_id: @item.id, item_type: @item.class.name, whodunnit: PaperTrail.whodunnit }
end

@@ -99,7 +99,7 @@
end

it "should add a version when commenting on a #{item}" do
@comment = FactoryGirl.create(:comment, commentable: @item, user: current_user)
@comment = create(:comment, commentable: @item, user: current_user)

@version = Version.where(related_id: @item.id, related_type: @item.class.name, whodunnit: PaperTrail.whodunnit, event: 'create').first
expect(@version).not_to eq(nil)
@@ -109,7 +109,7 @@

describe "Recently viewed items (task)" do
before do
@task = FactoryGirl.create(:task)
@task = create(:task)
@conditions = { item_id: @task.id, item_type: @task.class.name }
end

@@ -128,7 +128,7 @@

describe "Action refinements for task updates" do
before do
@task = FactoryGirl.create(:task, user: current_user)
@task = create(:task, user: current_user)
@conditions = { item_id: @task.id, item_type: @task.class.name, whodunnit: PaperTrail.whodunnit }
end

@@ -147,7 +147,7 @@
end

it "should create 'rescheduled' task event" do
@task.update(bucket: "due_tomorrow") # FactoryGirl creates :due_asap task
@task.update(bucket: "due_tomorrow") # FactoryBot creates :due_asap task

versions = Version.where(@conditions)
expect(versions.pluck(:event)).to include('reschedule')
@@ -156,7 +156,7 @@

describe "Rejecting a lead" do
before do
@lead = FactoryGirl.create(:lead, user: current_user, status: "new")
@lead = create(:lead, user: current_user, status: "new")
@conditions = { item_id: @lead.id, item_type: @lead.class.name, whodunnit: PaperTrail.whodunnit }
end

@@ -170,12 +170,12 @@

describe "Permissions" do
before do
@user = FactoryGirl.create(:user)
@user = create(:user)
Version.delete_all
end

it "should not show the create/update versions if the item is private" do
@item = FactoryGirl.create(:account, user: current_user, access: "Private")
@item = create(:account, user: current_user, access: "Private")
@item.update(name: 'New Name')

versions = Version.where(item_id: @item.id, item_type: @item.class.name)
@@ -186,7 +186,7 @@
end

it "should not show the destroy version if the item is private" do
@item = FactoryGirl.create(:account, user: current_user, access: "Private")
@item = create(:account, user: current_user, access: "Private")
@item.destroy

versions = Version.where(item_id: @item.id, item_type: @item.class.name)
@@ -197,10 +197,10 @@
end

it "should not show create/update versions if the item was not shared with the user" do
@item = FactoryGirl.create(:account,
user: current_user,
access: "Shared",
permissions: [FactoryGirl.build(:permission, user: current_user, asset: @item)])
@item = create(:account,
user: current_user,
access: "Shared",
permissions: [build(:permission, user: current_user, asset: @item)])
@item.update(name: 'New Name')

versions = Version.where(item_id: @item.id, item_type: @item.class.name)
@@ -211,10 +211,10 @@
end

it "should not show the destroy version if the item was not shared with the user" do
@item = FactoryGirl.create(:account,
user: current_user,
access: "Shared",
permissions: [FactoryGirl.build(:permission, user: current_user, asset: @item)])
@item = create(:account,
user: current_user,
access: "Shared",
permissions: [build(:permission, user: current_user, asset: @item)])
@item.destroy

versions = Version.where(item_id: @item.id, item_type: @item.class.name)
@@ -225,10 +225,10 @@
end

it "should show create/update versions if the item was shared with the user" do
@item = FactoryGirl.create(:account,
user: current_user,
access: "Shared",
permissions: [FactoryGirl.build(:permission, user: @user, asset: @item)])
@item = create(:account,
user: current_user,
access: "Shared",
permissions: [build(:permission, user: @user, asset: @item)])
@item.update(name: 'New Name')

versions = Version.where(item_id: @item.id, item_type: @item.class.name)
@@ -24,15 +24,15 @@
end

it "should find existing setting by its name using [] or method notations, and cache settings" do
@setting = FactoryGirl.create(:setting, name: "thingymabob", value: "magoody")
@setting = create(:setting, name: "thingymabob", value: "magoody")
expect(Setting.cache.key?("thingymabob")).to eq(false)
expect(Setting[:thingymabob]).to eq("magoody")
expect(Setting.cache.key?("thingymabob")).to eq(true)
expect(Setting.thingymabob).to eq("magoody")
end

it "should use value from YAML if setting is missing from database" do
@setting = FactoryGirl.create(:setting, name: "magoody", value: nil)
@setting = create(:setting, name: "magoody", value: nil)
Setting.yaml_settings[:magoody] = "thingymabob"
expect(Setting[:magoody]).to eq("thingymabob")
expect(Setting.magoody).to eq("thingymabob")