Commit 2606840040ec7ec2fb8d502d1557f84a12bf0b26
1 parent
dd333bfe
Exists in
colab
and in
4 other branches
Fixed module name formating for the tree
Showing
3 changed files
with
39 additions
and
1 deletions
Show diff stats
app/helpers/processings_helper.rb
... | ... | @@ -14,4 +14,14 @@ module ProcessingsHelper |
14 | 14 | return range_snapshot if (range_snapshot.beginning <= metric_result.value && range_snapshot.end >= metric_result.value) |
15 | 15 | end |
16 | 16 | end |
17 | + | |
18 | + def format_module_name(module_name) | |
19 | + if module_name.is_a?(Array) | |
20 | + module_name.last | |
21 | + elsif module_name.is_a?(String) | |
22 | + module_name | |
23 | + else | |
24 | + module_name.to_s | |
25 | + end | |
26 | + end | |
17 | 27 | end |
18 | 28 | \ No newline at end of file | ... | ... |
app/views/repositories/_module_result.html.erb
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | <% else %> |
6 | 6 | <i class="icon-file"></i> |
7 | 7 | <% end %> |
8 | - <%= link_to module_result.module.name, project_repository_module_path(repository.project_id, repository.id, module_result.id) %> | |
8 | + <%= link_to format_module_name(module_result.module.name), project_repository_module_path(repository.project_id, repository.id, module_result.id) %> | |
9 | 9 | </td> |
10 | 10 | <td><%= module_result.module.granularity %></td> |
11 | 11 | <td><%= format_grade(module_result.grade) %></td> | ... | ... |
spec/helpers/processings_helper_spec.rb
... | ... | @@ -31,4 +31,32 @@ describe ProcessingsHelper do |
31 | 31 | helper.find_range_snapshot(metric_result).should eq(range_snapshot_5dot1_to_10) |
32 | 32 | end |
33 | 33 | end |
34 | + | |
35 | + describe 'format_module_name' do | |
36 | + context 'when it is a String' do | |
37 | + let(:name) { 'org' } | |
38 | + | |
39 | + it 'should not make any change' do | |
40 | + helper.format_module_name(name).should eq(name) | |
41 | + end | |
42 | + end | |
43 | + | |
44 | + context 'when it is a Array' do | |
45 | + let(:name) { ['org', 'mezuro'] } | |
46 | + | |
47 | + it "should return it's last element" do | |
48 | + helper.format_module_name(name).should eq(name.last) | |
49 | + end | |
50 | + end | |
51 | + | |
52 | + context 'when it is a neither Array or String' do | |
53 | + let(:name) { Object.new } | |
54 | + | |
55 | + it "should try to convert it to String" do | |
56 | + name.expects(:to_s) | |
57 | + | |
58 | + helper.format_module_name(name) | |
59 | + end | |
60 | + end | |
61 | + end | |
34 | 62 | end |
35 | 63 | \ No newline at end of file | ... | ... |