fruit_to_lime 2.5.1 → 2.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fruit_to_lime/model/deal.rb +36 -0
- data/lib/fruit_to_lime/model/note.rb +5 -1
- data/spec/note_spec.rb +12 -0
- metadata +1 -1
@@ -1,5 +1,34 @@
|
|
1
1
|
|
2
2
|
module FruitToLime
|
3
|
+
class DealReference
|
4
|
+
include SerializeHelper
|
5
|
+
attr_accessor :id, :integration_id
|
6
|
+
def serialize_variables
|
7
|
+
[ :id, :integration_id ].map { |prop| {:id => prop, :type => :string} }
|
8
|
+
end
|
9
|
+
|
10
|
+
def initalize()
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
return "(#{id}, #{integration_id})"
|
15
|
+
end
|
16
|
+
|
17
|
+
def empty?
|
18
|
+
return !@integration_id && !@id
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.from_deal(deal)
|
22
|
+
if deal.nil?
|
23
|
+
return nil
|
24
|
+
elsif deal.is_a?(Deal)
|
25
|
+
return deal.to_reference
|
26
|
+
elsif person.is_a?(DealReference)
|
27
|
+
return deal
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
3
32
|
class Deal
|
4
33
|
include SerializeHelper, ModelHasCustomFields, ModelHasTags
|
5
34
|
|
@@ -48,6 +77,13 @@ module FruitToLime
|
|
48
77
|
return "deal[id=#{@id}, integration_id=#{@integration_id}]"
|
49
78
|
end
|
50
79
|
|
80
|
+
def to_reference
|
81
|
+
reference = DealReference.new
|
82
|
+
reference.id = @id
|
83
|
+
reference.integration_id = @integration_id
|
84
|
+
return reference
|
85
|
+
end
|
86
|
+
|
51
87
|
def validate
|
52
88
|
error = String.new
|
53
89
|
|
@@ -3,7 +3,7 @@ module FruitToLime
|
|
3
3
|
include SerializeHelper
|
4
4
|
attr_accessor :id, :text, :integration_id, :classification, :date
|
5
5
|
|
6
|
-
attr_reader :organization, :created_by, :person
|
6
|
+
attr_reader :organization, :created_by, :person, :deal
|
7
7
|
|
8
8
|
def initialize(opt = nil)
|
9
9
|
if !opt.nil?
|
@@ -54,6 +54,10 @@ module FruitToLime
|
|
54
54
|
@person = PersonReference.from_person(person)
|
55
55
|
end
|
56
56
|
|
57
|
+
def deal=(deal)
|
58
|
+
@deal = DealReference.from_deal(deal)
|
59
|
+
end
|
60
|
+
|
57
61
|
def validate
|
58
62
|
error = String.new
|
59
63
|
|
data/spec/note_spec.rb
CHANGED
@@ -52,4 +52,16 @@ describe "Note" do
|
|
52
52
|
# then
|
53
53
|
note.created_by.is_a?(FruitToLime::CoworkerReference).should eq true
|
54
54
|
end
|
55
|
+
|
56
|
+
it "will auto convert deal to deal.ref during assignment" do
|
57
|
+
# given
|
58
|
+
deal = FruitToLime::Deal.new({:integration_id => "123" })
|
59
|
+
deal.name = "The new deal"
|
60
|
+
|
61
|
+
# when
|
62
|
+
note.deal = deal
|
63
|
+
|
64
|
+
# then
|
65
|
+
note.deal.is_a?(FruitToLime::DealReference).should eq true
|
66
|
+
end
|
55
67
|
end
|