public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Search Repo:
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
mephisto / test / functional / application_helper_test.rb
100644 71 lines (56 sloc) 1.992 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require File.dirname(__FILE__) + '/../test_helper'
require 'application_helper'
require 'digest/md5'
 
ApplicationHelperTestController = Class.new ApplicationController do
  # look at how i mock the action view request
  def request() self end
  def env
    @env ||= {}
  end
  def host_with_port
    'localhost:3000'
  end
end
 
class ApplicationHelperTest < Test::Unit::TestCase
  fixtures :assets, :users
  include ActionView::Helpers::TagHelper, ApplicationHelper, WhiteListHelper
  
  def request
    @request ||= ApplicationHelperTestController.new
    @request
  end
  
  def test_should_return_default_avatar_for_nil_users
    assert_equal 'mephisto/avatar.gif', gravatar_url_for(nil)
  end
  
  def test_should_return_gravatar_link_for_user
    expected = "http://www.gravatar.com/avatar.php?size=80&gravatar_id=#{Digest::MD5.hexdigest(users(:quentin).email)}&default=http://#{request.host_with_port}/images/mephisto/avatar.gif"
    assert_equal expected, gravatar_url_for(users(:quentin))
  end
 
  def test_should_return_movie_icon_for_movie
    assert_match /video\.png/, asset_image_for(assets(:mov))
  end
  
  def test_should_return_audio_icon_for_mp3
    assert_match /audio\.png/, asset_image_for(assets(:mp3))
  end
  
  def test_should_return_doc_icon_for_other
    assert_match /doc\.png/, asset_image_for(assets(:word))
  end
  
  def test_should_return_pdf_icon
    assert_match /pdf\.png/, asset_image_for(assets(:pdf))
  end
 
  def test_should_return_thumbnail
    assert_match assets(:gif).public_filename(:tiny), asset_image_for(assets(:gif))
  end
 
  def test_should_return_actual_image
    assert_match assets(:png).public_filename, asset_image_for(assets(:png))
  end
 
  protected
    def asset_image_args_for(*args)
      controller.send(:asset_image_args_for, *args)
    end
    
    def controller
      @controller ||= ApplicationHelperTestController.new
    end
  
    def image_tag(path, options = {})
      tag 'img', options.merge(:src => path)
    end
end