require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe TrackableAction do it 'returns a list of tracked actions' do TrackableAction.delete_all TrackableAction.create(:kind => 'clicks') TrackableAction.create(:kind => 'conversion') TrackableAction.kinds.include?('clicks').should be_true TrackableAction.kinds.include?('conversion').should be_true TrackableAction.kinds.should have(2).items end it 'returns a histogram of pages' do TrackableAction.delete_all ts = TrackableSession.make(:views_count => 3) ts.trackable_actions.create!(:kind => 'view', :url => 'http://www.seologic.com/foo') ts.trackable_actions.create!(:kind => 'view', :url => 'http://www.seologic.com/bar') ts.trackable_actions.create!(:kind => 'view', :url => 'http://www.seologic.com/bar') h = TrackableAction.pages_histogram({}) hash = Hash[*h.flatten] hash['/foo'].should == 1.0 hash['/bar'].should == 2.0 end describe 'creates a new object from parameters' do before :all do @new = TrackableAction.create_from_params( :session_id => 123456, :referrer => 'http://www.cnn.com/', :ip_address => '123.123.123.1', :site => 'www.seologic.com', :kind => 'click', :label => 'Some Random Click', :url => 'http://www.seologic.com/foo/bar/' ) end it 'with a kind' do @new.kind.should == 'click' end it 'with a label' do @new.label.should == 'Some Random Click' end it 'with a referrer' do @new.referrer.should == 'http://www.cnn.com/' end it 'with a URL' do @new.url.should == 'http://www.seologic.com/foo/bar/' end it 'with an associated trackable session' do @new.trackable_session_id.should_not be_nil end it 'rejects an unparsable referrer URL' do TrackableAction.create_from_params( :session_id => 123456, :referrer => '/foo/bar', :ip_address => '123.123.123.1', :site => 'www.seologic.com', :kind => 'click', :label => 'Some Random Click', :url => 'http://www.seologic.com/foo/bar/' ).referrer.should == '/foo/bar' end end end