require 'test_helper' require 'active_support' require 'action_view/helpers' require 'gravatarify/view_helper' class GravatarifyViewHelperTest < Test::Unit::TestCase include ActionView::Helpers include Gravatarify::ViewHelper def setup # just ensure that no global options are defined when starting next test Gravatarify.options.clear end context "#gravatar_tag helper" do should "create tag with correct gravatar urls" do assert_equal 'bella@gmail.com', gravatar_tag('bella@gmail.com') end should "create tags and handle all options correctly, other options should be passed to Rails' image_tag" do assert_equal 'bella@gmail.com', gravatar_tag('bella@gmail.com', :size => 16) assert_equal 'bella@gmail.com', gravatar_tag('bella@gmail.com', :class => "gravatar", :size => 16) end end context "#gravatar_tag when passed in an object" do should "create -tag based on :email field" do obj = Object.new mock(obj).email.times(2) { "bella@gmail.com" } assert_equal 'bella@gmail.com', gravatar_tag(obj) end should "create -tag based on gravatar_url from object if object responds to gravatar_url" do obj = Object.new mock(obj).gravatar_url({ :size => 16 }) { "http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=16" } assert_equal 'Gravatar', gravatar_tag(obj, :size => 16, :alt => "Gravatar") end end end