diff --git a/plugins/community_track/lib/community_track_plugin/step_helper.rb b/plugins/community_track/lib/community_track_plugin/step_helper.rb index c14e881..7834113 100644 --- a/plugins/community_track/lib/community_track_plugin/step_helper.rb +++ b/plugins/community_track/lib/community_track_plugin/step_helper.rb @@ -16,13 +16,10 @@ module CommunityTrackPlugin::StepHelper CommunityTrackPlugin::StepHelper.status_classes[status_index(step)] end - def link_to_step_tool(step, options={}) - if step.tool - link_to step.tool.view_url, options do - yield - end - else - yield + def link_to_step(step, options={}, name=nil) + url = step.tool ? step.tool.view_url : step.view_url + link_to url, options do + block_given? ? yield : name end end diff --git a/plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb b/plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb index 59b8d67..cfec65e 100644 --- a/plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb +++ b/plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb @@ -6,6 +6,8 @@ class StepHelperTest < ActiveSupport::TestCase def setup @step = CommunityTrackPlugin::Step.new + @profile = fast_create(Community) + @step.stubs(:profile).returns(@profile) @step.stubs(:active?).returns(false) @step.stubs(:finished?).returns(false) @step.stubs(:waiting?).returns(false) @@ -31,21 +33,28 @@ class StepHelperTest < ActiveSupport::TestCase assert_equal _('Soon'), status_description(@step) end - should 'return content without link if there is no tool in a step' do - link = link_to_step_tool(@step) do + should 'return link to step if there is no tool in a step' do + expects(:link_to).with(@step.view_url, {}).once + link = link_to_step(@step) do "content" end - assert_equal 'content', link end should 'return link to step tool if there is a tool' do - profile = fast_create(Community) - tool = fast_create(Article, :profile_id => profile.id) + tool = fast_create(Article, :profile_id => @profile.id) @step.stubs(:tool).returns(tool) expects(:link_to).with(tool.view_url, {}).once - link = link_to_step_tool(@step) do + link = link_to_step(@step) do "content" end end + should 'return link with name if no block is given' do + def link_to(url, options) + yield + end + link = link_to_step(@step, {}, 'link name') + assert_equal 'link name', link + end + end diff --git a/plugins/community_track/views/blocks/_track.rhtml b/plugins/community_track/views/blocks/_track.rhtml index 1eca751..76bea50 100644 --- a/plugins/community_track/views/blocks/_track.rhtml +++ b/plugins/community_track/views/blocks/_track.rhtml @@ -11,7 +11,7 @@