Commit 983ad76a4b1eb919f21d8369288a703bd7ac7cab
1 parent
86ef31c1
Exists in
master
and in
22 other branches
Community track plugin: link to step if there is no tool
Showing
4 changed files
with
23 additions
and
15 deletions
Show diff stats
plugins/community_track/lib/community_track_plugin/step_helper.rb
... | ... | @@ -16,13 +16,10 @@ module CommunityTrackPlugin::StepHelper |
16 | 16 | CommunityTrackPlugin::StepHelper.status_classes[status_index(step)] |
17 | 17 | end |
18 | 18 | |
19 | - def link_to_step_tool(step, options={}) | |
20 | - if step.tool | |
21 | - link_to step.tool.view_url, options do | |
22 | - yield | |
23 | - end | |
24 | - else | |
25 | - yield | |
19 | + def link_to_step(step, options={}, name=nil) | |
20 | + url = step.tool ? step.tool.view_url : step.view_url | |
21 | + link_to url, options do | |
22 | + block_given? ? yield : name | |
26 | 23 | end |
27 | 24 | end |
28 | 25 | ... | ... |
plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb
... | ... | @@ -6,6 +6,8 @@ class StepHelperTest < ActiveSupport::TestCase |
6 | 6 | |
7 | 7 | def setup |
8 | 8 | @step = CommunityTrackPlugin::Step.new |
9 | + @profile = fast_create(Community) | |
10 | + @step.stubs(:profile).returns(@profile) | |
9 | 11 | @step.stubs(:active?).returns(false) |
10 | 12 | @step.stubs(:finished?).returns(false) |
11 | 13 | @step.stubs(:waiting?).returns(false) |
... | ... | @@ -31,21 +33,28 @@ class StepHelperTest < ActiveSupport::TestCase |
31 | 33 | assert_equal _('Soon'), status_description(@step) |
32 | 34 | end |
33 | 35 | |
34 | - should 'return content without link if there is no tool in a step' do | |
35 | - link = link_to_step_tool(@step) do | |
36 | + should 'return link to step if there is no tool in a step' do | |
37 | + expects(:link_to).with(@step.view_url, {}).once | |
38 | + link = link_to_step(@step) do | |
36 | 39 | "content" |
37 | 40 | end |
38 | - assert_equal 'content', link | |
39 | 41 | end |
40 | 42 | |
41 | 43 | should 'return link to step tool if there is a tool' do |
42 | - profile = fast_create(Community) | |
43 | - tool = fast_create(Article, :profile_id => profile.id) | |
44 | + tool = fast_create(Article, :profile_id => @profile.id) | |
44 | 45 | @step.stubs(:tool).returns(tool) |
45 | 46 | expects(:link_to).with(tool.view_url, {}).once |
46 | - link = link_to_step_tool(@step) do | |
47 | + link = link_to_step(@step) do | |
47 | 48 | "content" |
48 | 49 | end |
49 | 50 | end |
50 | 51 | |
52 | + should 'return link with name if no block is given' do | |
53 | + def link_to(url, options) | |
54 | + yield | |
55 | + end | |
56 | + link = link_to_step(@step, {}, 'link name') | |
57 | + assert_equal 'link name', link | |
58 | + end | |
59 | + | |
51 | 60 | end | ... | ... |
plugins/community_track/views/blocks/_track.rhtml
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | <div class="steps"> |
12 | 12 | <h3><%= _("Steps") %></h3> |
13 | 13 | <% track.steps.each do |step| %> |
14 | - <% link_to_step_tool(step) do %> | |
14 | + <% link_to_step(step) do %> | |
15 | 15 | <span class="step <%= block.status_class(step) %>"> |
16 | 16 | <span class="position"><%= step.position %></span> |
17 | 17 | <span class="legend"><%= status_description(step) %></span> | ... | ... |
plugins/community_track/views/content_viewer/_step_item.rhtml
... | ... | @@ -15,12 +15,14 @@ |
15 | 15 | <% if step_item.tool %> |
16 | 16 | <%= _('Tool: ') %> |
17 | 17 | |
18 | - <% link_to_step_tool(step_item, {:id => "step_link_#{step_item.id}"}) do %> | |
18 | + <% link_to_step(step_item, {:id => "step_link_#{step_item.id}"}) do %> | |
19 | 19 | <%= step_item.tool.name %> |
20 | 20 | <% end %> |
21 | 21 | |
22 | 22 | <% elsif step_item.allow_create?(user) && step_item.tool_class %> |
23 | 23 | <a id="step_link_<%= step_item.id %>" href="<%= url_for({:controller => 'cms', :action => 'new', :type => step_item.tool_class, :parent_id => step_item, :success_back_to => url_for(step_item.parent.view_url)}) %>" class="button icon-new with-text icon-new<%= step_item.tool_class.icon_name %>"><%= _('Create %s' % step_item.tool_class.short_description) %></a> |
24 | + <% else %> | |
25 | + <% link_to_step(step_item, {:id => "step_link_#{step_item.id}"}, '') %> | |
24 | 26 | <% end %> |
25 | 27 | </div> |
26 | 28 | </div> | ... | ... |