Skip to content

Instantly share code, notes, and snippets.

@tonatiuh
Created September 14, 2012 23:37
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/3725616 to your computer and use it in GitHub Desktop.
Save tonatiuh/3725616 to your computer and use it in GitHub Desktop.
Failing test
def new_contact_obligations
# self.vertical = conversions.first.placement.vertical
self.attributes = load_loc_attrs
self.save!
notify_observers(:find_campaigns)
end
before :each do
@vertical = FactoryGirl.create(:vertical)
@geo = FactoryGirl.create(:geo)
end
context "when find_campaigns callback is called" do
it 'should automatically purchase a contact when a matching campaign', run: true do
campaign = FactoryGirl.create(:campaign, :geos => [@geo], :vertical => @vertical)
contact = FactoryGirl.create(:contact , :geo => @geo, :vertical => @vertical)
contact.new_contact_obligations
contact.campaigns.first.should eql campaign
campaign.purchases.first.contact.should eql contact
end
end
@tonatiuh
Copy link
Author

By this way it pases, but when I uncomment this line:
´´´ruby
self.vertical = conversions.first.placement.vertical
´´´
it fails, because two verticals are created, the problem is that I don't find how is that
´´´ruby
conversions.first.placement.vertical
´´´
can get a vertical.

@madhermit
Copy link

yeah i ran into that too. See line 9 of the spec/models/contact_observer_spec.rb file to see how i removed the campaign created by FactoryGirl.create(:contact) from test consideration. Kinda sloppy though. like i said we really should have a factory that creates a contact without the conversion

@tonatiuh
Copy link
Author

Do you mind on this test?

it "should find an associated campaign" do
      campaign = FactoryGirl.create(:campaign)  
      contact = FactoryGirl.create(:contact)
      contact.new_contact_obligations #until after_commit bug gets fixed

      contact.campaigns.first.should eql campaign
      campaign.purchases.first.contact.should eql contact
 end

I don't figure to which line are you referring.

@madhermit
Copy link

@tonatiuh, you need to merge/rebase my changes from staging, its also got some good new tests there relevant to what you're working on i think. Here is the version i'm referring to:
https://github.com/stonegiantlabs/ContactLogic/blob/staging/spec/models/contact_observer_spec.rb

@tonatiuh
Copy link
Author

Ok man, I'll check that then because looks like that line is the only issue that i have to finish this feature, thanks ( :

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