Skip to content

Instantly share code, notes, and snippets.

@tonatiuh
Created September 12, 2012 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonatiuh/3710358 to your computer and use it in GitHub Desktop.
Save tonatiuh/3710358 to your computer and use it in GitHub Desktop.
Records
## The vertical
#Be sure of that vertical with id 1 exists
## The campaign (form)
#Put to the campaign the state of washignton
#Set to the campaign the vertical: 1
## The contacts (on the rails console)
Contact.create(:name => 'Jodee Clore', :vertical_id => 1, :geo_id => '15121') #this geo_id's are citys of washington
Contact.create(:name => 'Trish Roudebush', :vertical_id => 1, :geo_id => '14974')
@antillas21
Copy link

what if:

vertical = FactoryGirl.create(:vertical)
geo = FactoryGirl.create(:geo)
campaign = FactoryGirl.create(:campaign, :geo => geo, :vertical => vertical)
contact = FactoryGirl.create(:contact, :geo => geo, :vertical => vertical)

This contact should automatically be purchased by the campaign object.

@tonatiuh
Copy link
Author

I adapted it like follows and it doesn't pass : /

it 'should purchase automatically a contact on matching campaign' do
    vertical = FactoryGirl.create(:vertical)
    geo = FactoryGirl.create(:geo)
    campaign = FactoryGirl.create(:campaign, :geos => [geo], :vertical => vertical)
    contact = FactoryGirl.create(:contact, :geo => geo, :vertical => vertical)
    Purchase.last.contact.should == contact
  end
Got
Failure/Error: Purchase.last.contact.should == contact
NoMethodError:
undefined method `contact' for nil:NilClass

Looks like it is not creating the purchase.

@antillas21
Copy link

it 'should purchase automatically a contact on matching campaign' do
  vertical = FactoryGirl.create(:vertical)
  geo = FactoryGirl.create(:geo)
  campaign = FactoryGirl.create(:campaign, :geos => [geo], :vertical => vertical)
  contact = FactoryGirl.create(:contact, :geo => geo, :vertical => vertical)
  contact.new_contact_obligations ## this triggers a notification to the ContactObserver, which in turn triggers the purchase transaction

  Purchase.last.contact.should == contact
end

@antillas21
Copy link

perhaps the test assertion could also be:

contact.purchases.count.should eq(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment