spec/helpers/application_helper_spec.rb in mitamirri-0.13.8 vs spec/helpers/application_helper_spec.rb in mitamirri-2.0.8

- old
+ new

@@ -1,57 +1,45 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -require 'mitamirri' -include Mitamirri::Helper -describe "application helper methods" do - +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{ - track_action('view', :label => 'Some Label') + 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') + @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') - track_action('click').should_not be_nil + helper.track_action('click').should_not be_nil end - - it 'needs more robust tests for this method' - + end - + it 'returns appropriate track_click_code' do - expected = %{<script type="text/javascript"> - Event.observe(window, 'load', function() { - Event.observe('my_button', 'mousedown', track_mousedown_my_button_event); - }); - function track_mousedown_my_button_event() { - new Ajax.Updater('tracking', '/trackable_actions/', {asynchronous:true, evalScripts:true, parameters:'action=create&kind=click&label=my_action&referrer=/&remote_ip=123.123.123.123&site=www.seologic.com&url=/&session_id=asdf&destination='}) - Event.stopObserving('my_button', 'mousedown', track_mousedown_my_button_event); - } - </script>} - track_event_code('click', 'mousedown', 'my_button', 'my_action', '/', '123.123.123.123', 'www.seologic.com', '/', 'asdf').should == expected + 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 - - it 'returns a legend tag' do - legend_tag('Foo', {:id => 'foo'}).should == %{<div id="foo" class="faux_legend">Foo</div>\r} - end - - it 'returns page break code' do - page_break.should == %{<div class="page_break" /><p>(Continued on next page)</p></div>} - end - - + end