forked from isabanin/mercurial-ruby
/
test_diff_factory.rb
94 lines (77 loc) · 2.91 KB
/
test_diff_factory.rb
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require File.dirname(__FILE__) + '/helper'
describe Mercurial::DiffFactory do
before do
@repository = Mercurial::Repository.open(Fixtures.test_repo)
end
it "should find diffs for commit" do
commit = @repository.commits.by_hash_id('54d96f4b1a26')
diffs = @repository.diffs.for_commit(commit)
diffs.size.must_equal 6
diffs.map(&:file_name).sort.must_equal ['LICENSE4.txt', 'README.markup', 'Rakefile', 'Rakefile2', 'Rakefile3', 'superman.txt']
end
it "should work for files with dots in their names" do
commit = @repository.commits.by_hash_id('b66320fa72aa')
diffs = commit.diffs
diffs.size.must_equal 1
diffs.first.file_name.must_equal '.DotFile'
end
it "should handle binary files properly" do
commit = @repository.commits.by_hash_id('c2b3e46b986e')
commit.diffs.size.must_equal 1
diff = commit.diffs.first
diff.must_be_kind_of Mercurial::Diff
diff.file_name.must_equal 'goose.png'
diff.body.must_equal 'Binary files differ'
diff.binary?.must_equal true
end
it "should handle empty files properly" do
commit = @repository.commits.by_hash_id('8173f122b0d0')
commit.diffs.size.must_equal 0
end
it "should find diffs for path" do
diff = @repository.diffs.for_path('diff-test.rb', '57a6efe309bf', '9f76ea916c51')
diff.must_be_kind_of Mercurial::Diff
diff.hash_a.must_equal '57a6efe309bf'
diff.hash_b.must_equal'9f76ea916c51'
diff.file_a.must_equal 'diff-test.rb'
diff.file_b.must_equal 'diff-test.rb'
diff.body.must_equal diff_sample
end
it "should ignore whitespace" do
diff = @repository.diffs.for_path('superman.txt', 'b6f6f764b939', 'e47455b9a238', :ignore_whitespace => true)
diff.body.must_equal diff_sample_2
end
private
def diff_sample
%Q[--- a/diff-test.rb Thu Sep 15 23:43:02 2011 +0800
+++ b/diff-test.rb Thu Sep 15 23:43:52 2011 +0800
@@ -5,19 +5,17 @@
before_filter :repository_detected?, :except => :index
before_filter :welcome_screen, :only => :index
- before_filter :prepare_to_show, :only => [:show, :differences, :message]
before_filter :setup_page, :only => [:index, :repository]
caches_action :message, :differences
+ helper_method :current_branch
helper_method :repository_scope?
- helper_method :quick_changeset
helper_method :changesets_changes_limit
- helper_method :current_branch
helper_method :diff_taking_too_much_time_msg
def repository
- if current_repository.import_in_progress?
+ unless current_repository.import_in_progress?
return render(:template => "changesets/import_in_progress")
end
@changesets = find_changesets_for_current_scope
]
end
def diff_sample_2
%Q[--- a/superman.txt Thu Dec 01 15:52:30 2011 -0500
+++ b/superman.txt Thu Dec 01 15:57:43 2011 -0500
@@ -1,3 +1,3 @@
-^ whitespace change above
+^ whitespace change above and below
This is a superman file.
]
end
end