ffcrm_cloudfuji 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -21,8 +21,11 @@ module FatFreeCRM
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def note_customer_activity(message)
|
24
|
+
# Be verbose in development environment
|
25
|
+
@debug = Rails.env == 'development'
|
26
|
+
|
24
27
|
subject = find_or_create_activity_subject!
|
25
|
-
puts "Found subject: #{subject.inspect}"
|
28
|
+
puts "Found subject: #{subject.inspect}" if @debug
|
26
29
|
|
27
30
|
subject.versions.create! :event => message
|
28
31
|
end
|
@@ -31,24 +34,20 @@ module FatFreeCRM
|
|
31
34
|
params['data']
|
32
35
|
end
|
33
36
|
|
34
|
-
def recipient
|
35
|
-
data['recipient']
|
36
|
-
end
|
37
|
-
|
38
37
|
def find_or_create_activity_subject!
|
39
38
|
lookups = [Account, Lead, Contact]
|
40
39
|
lookups.each do |model|
|
41
|
-
puts "#{model}.find_by_email( #{data['email']} )"
|
40
|
+
puts "#{model}.find_by_email( #{data['email']} )" if @debug
|
42
41
|
result = model.find_by_email(data['email'])
|
43
42
|
return result if result
|
44
43
|
end
|
45
44
|
|
46
|
-
lead = Lead.find_by_email(data['email'])
|
45
|
+
lead = Lead.find_by_email(data['email']) || Lead.new
|
47
46
|
lead ||= Lead.new
|
48
47
|
|
49
|
-
lead.email
|
50
|
-
lead.first_name
|
51
|
-
lead.last_name
|
48
|
+
lead.email = data['email']
|
49
|
+
lead.first_name = data['first_name'] || data['email'].split("@").first if lead.first_name.blank?
|
50
|
+
lead.last_name = data['last_name'] || data['email'].split("@").last if lead.last_name.blank?
|
52
51
|
|
53
52
|
lead.save!
|
54
53
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
include FatFreeCRM::Cloudfuji::EventObservers
|
4
|
+
|
5
|
+
describe CustomerObserver do
|
6
|
+
describe "Customer activity" do
|
7
|
+
before do
|
8
|
+
@observer = CustomerObserver.new
|
9
|
+
@observer.params = {
|
10
|
+
"data" => {
|
11
|
+
"object" => "customer",
|
12
|
+
"account_balance" => 0,
|
13
|
+
"email" => "test_lead@example.com",
|
14
|
+
"id" => "cus_8Ezl23ASXmAb7Y",
|
15
|
+
"created" => 1336871750,
|
16
|
+
"livemode" => true,
|
17
|
+
"human" => "Customer CREATED (cus_8Ezl23ASXmAb7Y), test_lead@example.com"
|
18
|
+
}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should update a known lead when known customer is created" do
|
23
|
+
user = FactoryGirl.create(:user, :ido_id => "1234")
|
24
|
+
@lead = FactoryGirl.create(:lead, :email => 'test_lead@example.com', :user => user, :campaign => nil)
|
25
|
+
|
26
|
+
@observer.customer_created
|
27
|
+
|
28
|
+
# Should not create a new lead
|
29
|
+
Lead.find_all_by_email('test_lead@example.com').size.should == 1
|
30
|
+
|
31
|
+
@lead.reload
|
32
|
+
@lead.versions.last.event.should include("test_lead@example.com created as a customer")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should create a new lead when unknown customer is created" do
|
36
|
+
@observer.customer_created
|
37
|
+
|
38
|
+
@lead = Lead.find_by_email('test_lead@example.com')
|
39
|
+
@lead.first_name.should == "test_lead"
|
40
|
+
@lead.last_name.should == "example.com"
|
41
|
+
@lead.versions.last.event.should include("test_lead@example.com created as a customer")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffcrm_cloudfuji
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-05-
|
13
|
+
date: 2012-05-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec-rails
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/fat_free_crm/cloudfuji/version.rb
|
123
123
|
- lib/ffcrm_cloudfuji.rb
|
124
124
|
- spec/event_observers/app_observer_spec.rb
|
125
|
+
- spec/event_observers/customer_observer_spec.rb
|
125
126
|
- spec/internal/config/database.yml
|
126
127
|
- spec/internal/db/schema.rb
|
127
128
|
- spec/spec_helper.rb
|
@@ -140,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
141
|
version: '0'
|
141
142
|
segments:
|
142
143
|
- 0
|
143
|
-
hash: -
|
144
|
+
hash: -431378669
|
144
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
146
|
none: false
|
146
147
|
requirements:
|
@@ -149,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
150
|
version: '0'
|
150
151
|
segments:
|
151
152
|
- 0
|
152
|
-
hash: -
|
153
|
+
hash: -431378669
|
153
154
|
requirements: []
|
154
155
|
rubyforge_project:
|
155
156
|
rubygems_version: 1.8.24
|