require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'lib/mitamirri' describe Mitamirri::Helper do describe 'track action' do it 'creates a trackable action object from view tracking invocation' do request = Object.new request.stubs(:referrer).returns('/') request.stubs(:remote_ip).returns('123.123.123.123') request.stubs(:url).returns('http://www.elizium.com/opiates') session = Object.new session.stubs(:session_id).returns('1234ab') lambda{ helper.track_action('view', :label => 'Some Label') }.should change(TrackableAction, :count).by(1) end it 'returns track click code for click tracking invocation' do @request = Object.new @request.stubs(:referrer).returns('/') @request.stubs(:remote_ip).returns('123.123.123.123') @request.stubs(:url).returns('http://www.elizium.com/opiates') session = Object.new session.stubs(:session_id).returns('1234ab') helper.track_action('click').should_not be_nil end end it 'returns appropriate track_click_code' do results = track_event_code('click', 'mousedown', 'my_button', 'my_action', '/', '123.123.123.123', 'www.seologic.com', '/', 'asdf') results =~ /kind=click/ results =~ /Event.observe('my_button', 'mousedown', track_mousedown_my_button_event);/ results =~ /label=my_action/ results =~ /referrer=\// results =~ /remote_ip=123.123.123.123/ results =~ /site=www.seologic.com/ results =~ /url=\// results =~ /destination=asdf/ end end