Sha256: 92d74319f8077084fd71c8e19a7d84d8dc6e1cbffcbd09461498e40772e6dee4

Contents?: true

Size: 1.44 KB

Versions: 16

Compression:

Stored size: 1.44 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

include FatFreeCRM::Cloudfuji::EventObservers

describe CustomerObserver do
  describe "Customer activity" do
    before do
      @observer = CustomerObserver.new
      @observer.params = {
        "data" => {
          "object" => "customer",
          "account_balance" => 0,
          "email" => "test_lead@example.com",
          "id" => "cus_8Ezl23ASXmAb7Y",
          "created" => 1336871750,
          "livemode" => true,
          "human" => "Customer CREATED (cus_8Ezl23ASXmAb7Y), test_lead@example.com"
        }
      }
    end

    it "should update a known lead when known customer is created" do
      user = FactoryGirl.create(:user, :ido_id => "1234")
      @lead = FactoryGirl.create(:lead, :email => 'test_lead@example.com', :user => user, :campaign => nil)

      @observer.customer_created

      # Should not create a new lead
      Lead.find_all_by_email('test_lead@example.com').size.should == 1

      @lead.reload
      @lead.versions.last.event.should include("test_lead@example.com created as a customer")
    end

    it "should create a new lead when unknown customer is created" do
      @observer.customer_created

      @lead = Lead.find_by_email('test_lead@example.com')
      @lead.first_name.should == "test_lead"
      @lead.last_name.should == "example.com"
      @lead.versions.last.event.should include("test_lead@example.com created as a customer")
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ffcrm_cloudfuji-0.4.1 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.3.1 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.3.0 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.2.11 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.2.10 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.2.9 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.2.8 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.2.7 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.2.6 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.2.5 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.2.4 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.2.3 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.2.2 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.2.1 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.2.0 spec/event_observers/customer_observer_spec.rb
ffcrm_cloudfuji-0.1.7 spec/event_observers/customer_observer_spec.rb