Commit b36660ac3203cbe4dff84fe98a8b7aa47e346d0a

Authored by João M. M. da Silva + Diego Araújo
Committed by Paulo Meireles
1 parent 92330f68

[Mezuro] Tests for range controller.

plugins/mezuro/controllers/myprofile/mezuro_plugin_range_controller.rb
... ... @@ -14,7 +14,6 @@ class MezuroPluginRangeController < MezuroPluginMyprofileController
14 14 ranges = Kalibro::Range.ranges_of params[:metric_configuration_id].to_i
15 15 @range = (ranges.select { |range| range.id == params[:range_id].to_i }).first
16 16 @reading_labels_and_ids = reading_labels_and_ids
17   - @selected_reading_label = @range.label
18 17 end
19 18  
20 19 def create
... ...
plugins/mezuro/lib/kalibro/range.rb
... ... @@ -34,6 +34,10 @@ class Kalibro::Range < Kalibro::Model
34 34 end
35 35 end
36 36  
  37 + def reading_id=(value)
  38 + @reading_id = value.to_i
  39 + end
  40 +
37 41 def label
38 42 reading.label
39 43 end
... ...
plugins/mezuro/test/functional/myprofile/mezuro_plugin_range_controller_test.rb
... ... @@ -57,7 +57,7 @@ class MezuroPluginRangeControllerTest < ActionController::TestCase
57 57 :metric_configuration_id => @metric_configuration.id,
58 58 :range => @created_range.to_hash}).returns(:range_id => @range.id)
59 59 Kalibro::Reading.expects(:find).with(@created_range.reading_id).returns(@reading)
60   - get :create, :range => @created_range_hash, :metric_configuration_id => @metric_configuration.id
  60 + get :create, :profile => @profile.identifier, :range => @created_range_hash, :metric_configuration_id => @metric_configuration.id
61 61 assert_equal @range.id, assigns(:range).id
62 62 assert_response 200
63 63 end
... ... @@ -66,8 +66,7 @@ class MezuroPluginRangeControllerTest < ActionController::TestCase
66 66 Kalibro::Range.expects(:request).with(:save_range, {
67 67 :metric_configuration_id => @metric_configuration.id,
68 68 :range => @range.to_hash}).returns(:range_id => @range.id)
69   - Kalibro::Reading.expects(:find).with(@range.reading_id).returns(@reading)
70   - get :update, :range => @range_hash, :metric_configuration_id => @metric_configuration.id
  69 + get :update, :profile => @profile.identifier, :range => @range_hash, :metric_configuration_id => @metric_configuration.id
71 70 assert_equal @range.id, assigns(:range).id
72 71 assert_response 200
73 72 end
... ... @@ -75,7 +74,7 @@ class MezuroPluginRangeControllerTest < ActionController::TestCase
75 74 should 'test remove range in native metric configuration' do
76 75 Kalibro::Range.expects(:new).with({:id => @range.id}).returns(@range)
77 76 @range.expects(:destroy).with().returns()
78   - get :remove, :id => @content.id, :metric_configuration_id => @metric_configuration.id, :range_id => @range.id, :compound => false
  77 + get :remove, :profile => @profile.identifier, :id => @content.id, :metric_configuration_id => @metric_configuration.id, :range_id => @range.id, :compound => false
79 78 assert_response 302
80 79 end
81 80 end
... ...
plugins/mezuro/views/mezuro_plugin_metric_configuration/edit_compound.html.erb
... ... @@ -50,20 +50,14 @@
50 50 Color
51 51 </td>
52 52 </tr>
53   - <%
54   - #if (@metric_configuration.ranges!=nil)
55   - # @metric_configuration.ranges.each do |range|
56   - %>
57   - <%= #render :partial => "mezuro_plugin_range/range", :locals => {:range => range, :id => @configuration_content.id,
58   - #:metric_name => @metric_configuration.metric.name}
59   - %>
60   - <% #end
61   - #end
62   - %>
  53 + <% @ranges.each do |range| %>
  54 + <%= render :partial => "mezuro_plugin_range/range", :locals => {:range => range, :id => @configuration_content.id,
  55 + :metric_configuration_id => @metric_configuration.id, :reading_group_id => @metric_configuration.reading_group_id, :compound => @metric_configuration.metric.compound} %>
  56 + <% end %>
63 57 </table>
64 58  
65 59 <br/>
66   -<%= link_to_remote "New Range", :url => {:action =>"new_range", :controller => "mezuro_plugin_range", :id => @configuration_content.id, :metric_name => @metric.name} %>
67   -<div id="range_form" style="display:none"></div>
68   -<br/>
69   -<%= render :partial => "metric_codes", :locals => {:metric_configurations => @metric_configurations} %>
  60 +<% if owner %>
  61 + <%= link_to_remote "New Range", :url => {:action =>"new", :controller => "mezuro_plugin_range", :id => @configuration_content.id, :metric_configuration_id => @metric_configuration.id, :reading_group_id => @metric_configuration.reading_group_id} %>
  62 +<% end %>
  63 +<div id="form" style="display:none"></div>
... ...
plugins/mezuro/views/mezuro_plugin_range/_form.html.erb
... ... @@ -4,7 +4,7 @@
4 4 <%= f.hidden_field :id %>
5 5  
6 6 <%= required labelled_form_field _('Label'),
7   - f.select(:reading_id, @reading_labels_and_ids, :selected => @selected_reading_label) %><br/>
  7 + f.select(:reading_id, @reading_labels_and_ids) %><br/>
8 8 <table>
9 9 <tr>
10 10 <td>
... ...