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,13 +16,10 @@ module CommunityTrackPlugin::StepHelper | ||
16 | CommunityTrackPlugin::StepHelper.status_classes[status_index(step)] | 16 | CommunityTrackPlugin::StepHelper.status_classes[status_index(step)] |
17 | end | 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 | end | 23 | end |
27 | end | 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 +6,8 @@ class StepHelperTest < ActiveSupport::TestCase | ||
6 | 6 | ||
7 | def setup | 7 | def setup |
8 | @step = CommunityTrackPlugin::Step.new | 8 | @step = CommunityTrackPlugin::Step.new |
9 | + @profile = fast_create(Community) | ||
10 | + @step.stubs(:profile).returns(@profile) | ||
9 | @step.stubs(:active?).returns(false) | 11 | @step.stubs(:active?).returns(false) |
10 | @step.stubs(:finished?).returns(false) | 12 | @step.stubs(:finished?).returns(false) |
11 | @step.stubs(:waiting?).returns(false) | 13 | @step.stubs(:waiting?).returns(false) |
@@ -31,21 +33,28 @@ class StepHelperTest < ActiveSupport::TestCase | @@ -31,21 +33,28 @@ class StepHelperTest < ActiveSupport::TestCase | ||
31 | assert_equal _('Soon'), status_description(@step) | 33 | assert_equal _('Soon'), status_description(@step) |
32 | end | 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 | "content" | 39 | "content" |
37 | end | 40 | end |
38 | - assert_equal 'content', link | ||
39 | end | 41 | end |
40 | 42 | ||
41 | should 'return link to step tool if there is a tool' do | 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 | @step.stubs(:tool).returns(tool) | 45 | @step.stubs(:tool).returns(tool) |
45 | expects(:link_to).with(tool.view_url, {}).once | 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 | "content" | 48 | "content" |
48 | end | 49 | end |
49 | end | 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 | end | 60 | end |
plugins/community_track/views/blocks/_track.rhtml
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | <div class="steps"> | 11 | <div class="steps"> |
12 | <h3><%= _("Steps") %></h3> | 12 | <h3><%= _("Steps") %></h3> |
13 | <% track.steps.each do |step| %> | 13 | <% track.steps.each do |step| %> |
14 | - <% link_to_step_tool(step) do %> | 14 | + <% link_to_step(step) do %> |
15 | <span class="step <%= block.status_class(step) %>"> | 15 | <span class="step <%= block.status_class(step) %>"> |
16 | <span class="position"><%= step.position %></span> | 16 | <span class="position"><%= step.position %></span> |
17 | <span class="legend"><%= status_description(step) %></span> | 17 | <span class="legend"><%= status_description(step) %></span> |
plugins/community_track/views/content_viewer/_step_item.rhtml
@@ -15,12 +15,14 @@ | @@ -15,12 +15,14 @@ | ||
15 | <% if step_item.tool %> | 15 | <% if step_item.tool %> |
16 | <%= _('Tool: ') %> | 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 | <%= step_item.tool.name %> | 19 | <%= step_item.tool.name %> |
20 | <% end %> | 20 | <% end %> |
21 | 21 | ||
22 | <% elsif step_item.allow_create?(user) && step_item.tool_class %> | 22 | <% elsif step_item.allow_create?(user) && step_item.tool_class %> |
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> | 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 | <% end %> | 26 | <% end %> |
25 | </div> | 27 | </div> |
26 | </div> | 28 | </div> |