summaryrefslogtreecommitdiffstats
path: root/test/unit/helpers/commits_helper_test.rb
blob: b41d51908e19db477c760142afd3883d876d1850 (plain)
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
# encoding: utf-8
#--
#   Copyright (C) 2009 Johan Sørensen <johan@johansorensen.com>
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Affero General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#++

require File.dirname(__FILE__) + '/../../test_helper'

class CommitsHelperTest < ActionView::TestCase

  should "includes the RepostoriesHelper" do
    included_modules = (class << self; self; end).send(:included_modules)
    assert included_modules.include?(RepositoriesHelper)
  end
  
  context "render_diff_stats" do
    setup do
      @stat_data = [
        ["spec/database_spec.rb", 5, 12, 17],
        ["spec/integration/database_integration_spec.rb", 2, 2, 0],
      ]
      @stats = Grit::CommitStats.new(mock("Grit::Repo"), "a"*40, @stat_data)
    end
    
    should "renders a list of files as anchor links" do
      files = @stats.files.map{|f| f[0] }
      rendered_stats = render_diff_stats(@stats)
      files.each do |filename|
        assert rendered_stats.include?(%Q{<li><a href="##{h(filename)}">#{h(filename)}</a>})
      end
    end
    
    should "renders a graph of minuses for deletions" do
      assert render_diff_stats(@stats).include?(%Q{spec/database_spec.rb</a>&nbsp;17&nbsp;<small class="deletions">#{"-"*12}</small>})
    end
    
    should "renders a graph of plusses for inserts" do
      assert_match(/spec\/database_spec\.rb<\/a>&nbsp;17&nbsp;<small class="deletions.+<\/small><small class="insertions">#{"\\+"*5}<\/small>/, 
        render_diff_stats(@stats))
    end
  end

end