ffcrm_cloudfuji 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/event_rules.js.coffee +55 -0
- data/app/assets/javascripts/ffcrm_cloudfuji.js +1 -1
- data/app/assets/stylesheets/event_rules.css.scss +53 -0
- data/app/assets/stylesheets/ffcrm_cloudfuji.css +1 -1
- data/app/controllers/admin/{lead_scoring_controller.rb → event_rules_controller.rb} +12 -12
- data/app/helpers/admin/event_rules_helper.rb +47 -0
- data/app/models/event_rule.rb +112 -0
- data/app/models/lead_event_rule_count.rb +4 -0
- data/app/observers/cloudfuji_lead_observer.rb +27 -0
- data/app/views/admin/{lead_scoring → event_rules}/_errors.html.haml +1 -1
- data/app/views/admin/event_rules/_form.html.haml +39 -0
- data/app/views/admin/{lead_scoring → event_rules}/index.html.haml +7 -7
- data/app/views/leads/_sidebar_show_lead_scoring.html.haml +3 -3
- data/config/locales/en-US.yml +5 -0
- data/config/routes.rb +1 -1
- data/db/migrate/20120524031157_extend_lead_scoring_as_event_rules.rb +54 -0
- data/db/migrate/20120525151511_add_ido_id_to_lead.rb +5 -0
- data/lib/fat_free_crm/cloudfuji/event_observers/customer_observer.rb +3 -1
- data/lib/fat_free_crm/cloudfuji/event_observers/email_observer.rb +4 -2
- data/lib/fat_free_crm/cloudfuji/event_observers/event_rules_observer.rb +23 -0
- data/lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb +6 -5
- data/lib/fat_free_crm/cloudfuji.rb +1 -1
- data/lib/ffcrm_cloudfuji/engine.rb +9 -4
- data/lib/ffcrm_cloudfuji/version.rb +1 -1
- data/spec/event_observers/event_rules_observer_spec.rb +103 -0
- data/spec/factories/lead_scoring_factories.rb +9 -3
- data/spec/internal/db/schema.rb +19 -13
- data/spec/models/event_rule_spec.rb +47 -0
- data/spec/observers/cloudfuji_lead_observer_spec.rb +26 -0
- metadata +80 -92
- data/app/assets/javascripts/lead_scoring.js.coffee +0 -42
- data/app/assets/stylesheets/lead_scoring.css.scss +0 -47
- data/app/helpers/admin/lead_scoring_helper.rb +0 -10
- data/app/models/lead_scoring_rule.rb +0 -6
- data/app/models/lead_scoring_rule_count.rb +0 -4
- data/app/views/admin/lead_scoring/_form.html.haml +0 -14
- data/config/initializers/inflections.rb +0 -3
- data/lib/fat_free_crm/cloudfuji/event_observers/lead_scoring_observer.rb +0 -38
- data/spec/event_observers/lead_scoring_observer_spec.rb +0 -87
@@ -1,38 +0,0 @@
|
|
1
|
-
module FatFreeCRM
|
2
|
-
module Cloudfuji
|
3
|
-
module EventObservers
|
4
|
-
class LeadScoringObserver < ::Cloudfuji::EventObserver
|
5
|
-
# Fire for all events
|
6
|
-
def catch_all
|
7
|
-
data = params['data']
|
8
|
-
email = data['email'] || data['recipient']
|
9
|
-
# Look up Lead by email address
|
10
|
-
if lead = Lead.find_by_email(email)
|
11
|
-
event_name = "#{params['category']}_#{params['event']}"
|
12
|
-
|
13
|
-
LeadScoringRule.find_all_by_event(event_name).each do |rule|
|
14
|
-
# Find how many times this rule has been applied to this Lead
|
15
|
-
count = LeadScoringRuleCount.find_by_lead_id_and_lead_scoring_rule_id(lead, rule) ||
|
16
|
-
LeadScoringRuleCount.new(:lead => lead, :lead_scoring_rule => rule)
|
17
|
-
|
18
|
-
# Don't apply this rule more than once if :once flag is set
|
19
|
-
unless rule.once && count.count > 0
|
20
|
-
# If :match is present, only apply the rule if data matches string
|
21
|
-
if rule.match.blank? || params['data'].inspect.include?(rule.match)
|
22
|
-
lead.without_versioning do
|
23
|
-
lead.update_attribute :score, lead.score + rule.points
|
24
|
-
end
|
25
|
-
# Add history event to lead, to record change of score
|
26
|
-
lead.versions.create! :event => "Rule for '#{event_name}': Score changed by #{rule.points} points. (New total: #{lead.score})"
|
27
|
-
# Increment and save count of rule/lead applications
|
28
|
-
count.count += 1
|
29
|
-
count.save
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
include FatFreeCRM::Cloudfuji::EventObservers
|
4
|
-
|
5
|
-
describe LeadScoringObserver do
|
6
|
-
before do
|
7
|
-
@observer = LeadScoringObserver.new
|
8
|
-
@observer.params = {
|
9
|
-
'category' => 'customer',
|
10
|
-
'event' => 'had_tea',
|
11
|
-
"data" => {
|
12
|
-
"email" => "test_lead@example.com",
|
13
|
-
"type_of_tea" => "Jasmine"
|
14
|
-
}
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
|
-
def find_rule_count(lead, rule)
|
19
|
-
LeadScoringRuleCount.find_by_lead_id_and_lead_scoring_rule_id(lead, rule)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should increment a lead's score when an event is fired" 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
|
-
@rule = FactoryGirl.create :lead_scoring_rule,
|
27
|
-
:event => "customer_had_tea",
|
28
|
-
:points => 20
|
29
|
-
|
30
|
-
@observer.catch_all
|
31
|
-
@lead.reload
|
32
|
-
@lead.versions.last.event.should include("Rule for 'customer_had_tea': Score changed by 20 points")
|
33
|
-
@lead.score.should == 20
|
34
|
-
find_rule_count(@lead, @rule).count.should == 1
|
35
|
-
|
36
|
-
# Should increment score twice
|
37
|
-
@observer.catch_all
|
38
|
-
@lead.reload
|
39
|
-
@lead.score.should == 40
|
40
|
-
find_rule_count(@lead, @rule).count.should == 2
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should increment a lead's score only when matching data is present" do
|
44
|
-
user = FactoryGirl.create(:user, :ido_id => "1234")
|
45
|
-
@lead = FactoryGirl.create(:lead, :email => 'test_lead@example.com', :user => user, :campaign => nil)
|
46
|
-
|
47
|
-
@rule = FactoryGirl.create :lead_scoring_rule,
|
48
|
-
:event => "customer_had_tea",
|
49
|
-
:points => 15,
|
50
|
-
:match => "Russian Earl Grey"
|
51
|
-
|
52
|
-
@observer.catch_all
|
53
|
-
@lead.reload
|
54
|
-
@lead.score.should == 0
|
55
|
-
# No LeadScoringRuleCount should be created yet
|
56
|
-
find_rule_count(@lead, @rule).should == nil
|
57
|
-
|
58
|
-
@observer.params['data']['type_of_tea'] = "Russian Earl Grey"
|
59
|
-
@observer.catch_all
|
60
|
-
|
61
|
-
@lead.reload
|
62
|
-
@lead.score.should == 15
|
63
|
-
find_rule_count(@lead, @rule).count.should == 1
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should not decrement a lead's score twice if the rule should only be applied once" do
|
67
|
-
user = FactoryGirl.create(:user, :ido_id => "1234")
|
68
|
-
@lead = FactoryGirl.create(:lead, :email => 'test_lead@example.com', :user => user, :campaign => nil)
|
69
|
-
|
70
|
-
@rule = FactoryGirl.create :lead_scoring_rule,
|
71
|
-
:event => "customer_had_tea",
|
72
|
-
:points => -10,
|
73
|
-
:once => true
|
74
|
-
|
75
|
-
@observer.catch_all
|
76
|
-
@lead.reload
|
77
|
-
@lead.versions.last.event.should include("Rule for 'customer_had_tea': Score changed by -10 points")
|
78
|
-
@lead.score.should == -10
|
79
|
-
find_rule_count(@lead, @rule).count.should == 1
|
80
|
-
|
81
|
-
# Should only increment score once
|
82
|
-
@observer.catch_all
|
83
|
-
@lead.reload
|
84
|
-
@lead.score.should == -10
|
85
|
-
find_rule_count(@lead, @rule).count.should == 1
|
86
|
-
end
|
87
|
-
end
|