require 'spec_helper'

describe AffiliateReferralVisit do

  let!(:user) { FactoryGirl.create(:user) }
  let(:partner) {  FactoryGirl.create(:affiliate_partner) }
  let(:valid_track_options) {
    {
        affiliate_id: partner.id,
        visited: false,
        remote_ip: '1.2.2.1',
        visited_url: '/',
        referral_url: 'http://www.youtube.com',
        current_user: nil

    }
  }

  describe "track" do
    it "succeeds" do
      visit = AffiliateReferralVisit.track( valid_track_options )
      visit.valid?.should be_true
    end

    it "never fails with error" do
      visit = AffiliateReferralVisit.track( {})
      visit.valid?.should be_false

      options = valid_track_options
      options[:affiliate_id] = 111
      visit = AffiliateReferralVisit.track( options)
      visit.valid?.should be_true

      options = valid_track_options
      options[:current_user] = user
      visit = AffiliateReferralVisit.track( options)
      visit.valid?.should be_true
    end
  end
end
