Commit 30bc795d119679f717f5b3d41971ae51553e03c7
Committed by
Rafael Manzo
1 parent
b2503573
Exists in
colab
and in
4 other branches
Helper for edit links of metric configurations.
signed-off-by: Guilherme Rojas V. de Lima <guilhermehrojas@gmail.com>
Showing
3 changed files
with
28 additions
and
5 deletions
Show diff stats
app/helpers/mezuro_configurations_helper.rb
| @@ -2,4 +2,12 @@ module MezuroConfigurationsHelper | @@ -2,4 +2,12 @@ module MezuroConfigurationsHelper | ||
| 2 | def mezuro_configuration_owner?(mezuro_configuration_id) | 2 | def mezuro_configuration_owner?(mezuro_configuration_id) |
| 3 | user_signed_in? && !current_user.mezuro_configuration_ownerships.find_by_mezuro_configuration_id(mezuro_configuration_id).nil? | 3 | user_signed_in? && !current_user.mezuro_configuration_ownerships.find_by_mezuro_configuration_id(mezuro_configuration_id).nil? |
| 4 | end | 4 | end |
| 5 | -end | ||
| 6 | \ No newline at end of file | 5 | \ No newline at end of file |
| 6 | + | ||
| 7 | + def link_to_edit_form(metric_configuration, mezuro_configuration_id) | ||
| 8 | + if (metric_configuration.metric.compound) | ||
| 9 | + link_to('Edit', edit_mezuro_configuration_compound_metric_configuration_path(mezuro_configuration_id, metric_configuration.id), class: 'btn btn-info') | ||
| 10 | + else | ||
| 11 | + link_to('Edit', edit_mezuro_configuration_metric_configuration_path(mezuro_configuration_id, metric_configuration.id), class: 'btn btn-info') | ||
| 12 | + end | ||
| 13 | + end | ||
| 14 | +end |
app/views/mezuro_configurations/_metric_configurations.html.erb
| @@ -4,8 +4,7 @@ | @@ -4,8 +4,7 @@ | ||
| 4 | <td><%= metric_configuration.weight %></td> | 4 | <td><%= metric_configuration.weight %></td> |
| 5 | <% if mezuro_configuration_owner? @mezuro_configuration.id %> | 5 | <% if mezuro_configuration_owner? @mezuro_configuration.id %> |
| 6 | <td> | 6 | <td> |
| 7 | - <%= link_to 'Edit', edit_mezuro_configuration_metric_configuration_path(@mezuro_configuration.id, metric_configuration.id), | ||
| 8 | - class: 'btn btn-info' %> | 7 | + <%= link_to_edit_form(metric_configuration, @mezuro_configuration.id) %> |
| 9 | </td> | 8 | </td> |
| 10 | <td> | 9 | <td> |
| 11 | <%= link_to 'Destroy', mezuro_configuration_metric_configuration_path(@mezuro_configuration.id, metric_configuration.id), | 10 | <%= link_to 'Destroy', mezuro_configuration_metric_configuration_path(@mezuro_configuration.id, metric_configuration.id), |
| @@ -14,4 +13,4 @@ | @@ -14,4 +13,4 @@ | ||
| 14 | </td> | 13 | </td> |
| 15 | </td> | 14 | </td> |
| 16 | <% end %> | 15 | <% end %> |
| 17 | -</tr> | ||
| 18 | \ No newline at end of file | 16 | \ No newline at end of file |
| 17 | +</tr> |
spec/helpers/mezuro_configurations_helper_spec.rb
| @@ -41,4 +41,20 @@ describe MezuroConfigurationsHelper do | @@ -41,4 +41,20 @@ describe MezuroConfigurationsHelper do | ||
| 41 | it { helper.mezuro_configuration_owner?(@subject.id).should be_true } | 41 | it { helper.mezuro_configuration_owner?(@subject.id).should be_true } |
| 42 | end | 42 | end |
| 43 | end | 43 | end |
| 44 | -end | ||
| 45 | \ No newline at end of file | 44 | \ No newline at end of file |
| 45 | + | ||
| 46 | + describe 'link to edit form' do | ||
| 47 | + context 'when the metric is native' do | ||
| 48 | + let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } | ||
| 49 | + let(:response_link) {"<a class=\"btn btn-info\" href=\"/mezuro_configurations/#{metric_configuration.configuration_id}/metric_configurations/#{metric_configuration.id}/edit\">Edit</a>"} | ||
| 50 | + | ||
| 51 | + it { helper.link_to_edit_form(metric_configuration, metric_configuration.configuration_id).should eq(response_link) } | ||
| 52 | + end | ||
| 53 | + | ||
| 54 | + context 'when the metric is compound' do | ||
| 55 | + let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration) } | ||
| 56 | + let(:response_link) {"<a class=\"btn btn-info\" href=\"/mezuro_configurations/#{compound_metric_configuration.configuration_id}/compound_metric_configurations/#{compound_metric_configuration.id}/edit\">Edit</a>"} | ||
| 57 | + | ||
| 58 | + it { helper.link_to_edit_form(compound_metric_configuration, compound_metric_configuration.configuration_id).should eq(response_link) } | ||
| 59 | + end | ||
| 60 | + end | ||
| 61 | +end |