-
Notifications
You must be signed in to change notification settings - Fork 18
/
order_contact_test.rb
44 lines (37 loc) · 1.34 KB
/
order_contact_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Copyright (c) 2006-2017, Puzzle ITC GmbH. This file is part of
# PuzzleTime and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/puzzle/puzzletime.
# == Schema Information
#
# Table name: order_contacts
#
# false :integer not null, primary key
# contact_id :integer not null
# order_id :integer not null
# comment :string
#
require 'test_helper'
class OrderContactTest < ActiveSupport::TestCase
teardown :reset_crm
test 'list scope is ordered by contact' do
order = Fabricate(:order)
m = OrderContact.create!(order: order, contact: Fabricate(:contact, lastname: 'Miller', client: order.client))
a = OrderContact.create!(order: order, contact: Fabricate(:contact, lastname: 'Aber', client: order.client))
assert_equal [a, m], order.order_contacts.list
end
test 'crm ids are replaced' do
Crm.instance = Crm::Highrise.new
Crm.instance.expects(:find_person).returns(lastname: 'Miller', firstname: 'Fred', crm_key: '123')
c = OrderContact.new(order: Fabricate(:order), contact_id_or_crm: 'crm_123')
assert_difference('OrderContact.count') do
assert_difference('Contact.count') do
assert c.save
end
end
end
private
def reset_crm
Crm.instance = nil
end
end