Commit 92330f68fe0f2405701628ae98b649f4b9f45611
Committed by
Paulo Meireles
1 parent
dbf169af
Exists in
staging
and in
42 other branches
[Mezuro] Draft to rages tests.
Showing
20 changed files
with
129 additions
and
138 deletions
Show diff stats
plugins/mezuro/controllers/myprofile/mezuro_plugin_range_controller.rb
| ... | ... | @@ -2,43 +2,44 @@ class MezuroPluginRangeController < MezuroPluginMyprofileController |
| 2 | 2 | |
| 3 | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
| 4 | 4 | |
| 5 | - def new_range | |
| 6 | - @content_id = params[:id] | |
| 7 | - @metric_configuration_id = params[:metric_configuration_id] | |
| 5 | + def new | |
| 6 | + @content_id = params[:id].to_i | |
| 7 | + @metric_configuration_id = params[:metric_configuration_id].to_i | |
| 8 | 8 | @reading_labels_and_ids = reading_labels_and_ids |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | - def edit_range | |
| 12 | - @content_id = params[:id] | |
| 13 | - @metric_configuration_id = params[:metric_configuration_id] | |
| 14 | - ranges = Kalibro::Range.ranges_of params[:metric_configuration_id] | |
| 11 | + def edit | |
| 12 | + @content_id = params[:id].to_i | |
| 13 | + @metric_configuration_id = params[:metric_configuration_id].to_i | |
| 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 | |
| 17 | 18 | end |
| 18 | 19 | |
| 19 | - def create_range | |
| 20 | + def create | |
| 20 | 21 | metric_configuration_id = params[:metric_configuration_id].to_i |
| 21 | 22 | @range = Kalibro::Range.new params[:range] |
| 22 | 23 | @range.save metric_configuration_id |
| 23 | 24 | if !@range.errors.empty? |
| 24 | - @error = metric_configuration.errors[0].message | |
| 25 | + @error = @range.errors[0].message | |
| 25 | 26 | end |
| 26 | 27 | end |
| 27 | 28 | |
| 28 | - def update_range | |
| 29 | + def update | |
| 29 | 30 | metric_configuration_id = params[:metric_configuration_id].to_i |
| 30 | 31 | @range = Kalibro::Range.new params[:range] |
| 31 | 32 | @range.save metric_configuration_id |
| 32 | 33 | if !@range.errors.empty? |
| 33 | - @error = metric_configuration.errors[0].message | |
| 34 | + @error = @range.errors[0].message | |
| 34 | 35 | end |
| 35 | 36 | end |
| 36 | 37 | |
| 37 | - def remove_range | |
| 38 | - configuration_content_id = params[:id] | |
| 39 | - metric_configuration_id = params[:metric_configuration_id] | |
| 38 | + def remove | |
| 39 | + configuration_content_id = params[:id].to_i | |
| 40 | + metric_configuration_id = params[:metric_configuration_id].to_i | |
| 40 | 41 | compound = params[:compound] |
| 41 | - Kalibro::Range.new({:id => params[:range_id]}).destroy | |
| 42 | + Kalibro::Range.new({:id => params[:range_id].to_i}).destroy | |
| 42 | 43 | if compound |
| 43 | 44 | redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/metric_configuration/edit_compound?id=#{configuration_content_id}&metric_configuration_id=#{metric_configuration_id}" |
| 44 | 45 | else |
| ... | ... | @@ -49,7 +50,7 @@ class MezuroPluginRangeController < MezuroPluginMyprofileController |
| 49 | 50 | private |
| 50 | 51 | |
| 51 | 52 | def reading_labels_and_ids |
| 52 | - array = Kalibro::Reading.readings_of(params[:reading_group_id]).map { |reading| [reading.label, reading.id] } | |
| 53 | + array = Kalibro::Reading.readings_of(params[:reading_group_id].to_i).map { |reading| [reading.label, reading.id] } | |
| 53 | 54 | array.sort { |x,y| x.first.downcase <=> y.first.downcase } |
| 54 | 55 | end |
| 55 | 56 | ... | ... |
plugins/mezuro/lib/kalibro/metric_configuration.rb
| ... | ... | @@ -28,8 +28,10 @@ class Kalibro::MetricConfiguration < Kalibro::Model |
| 28 | 28 | end |
| 29 | 29 | |
| 30 | 30 | def self.metric_configurations_of(configuration_id) |
| 31 | - hash = request(:metric_configurations_of, {:configuration_id => configuration_id}) | |
| 32 | - hash[:metric_configuration].to_a.map { |metric_configuration| new metric_configuration } | |
| 31 | + response = request(:metric_configurations_of, {:configuration_id => configuration_id})[:metric_configuration] | |
| 32 | + response = [] if response.nil? | |
| 33 | + response = [response] if response.is_a?(Hash) | |
| 34 | + response.map { |metric_configuration| new metric_configuration } | |
| 33 | 35 | end |
| 34 | 36 | |
| 35 | 37 | private | ... | ... |
plugins/mezuro/test/fixtures/range_fixtures.rb
| ... | ... | @@ -5,7 +5,11 @@ class RangeFixtures |
| 5 | 5 | end |
| 6 | 6 | |
| 7 | 7 | def self.created_range |
| 8 | - Kalibro::Range.new :beginning => "19.5", :end => "INF", :reading_id => "1", :comments => "Test range 1" | |
| 8 | + Kalibro::Range.new created_range_hash | |
| 9 | + end | |
| 10 | + | |
| 11 | + def self.created_range_hash | |
| 12 | + {:beginning => "19.5", :end => "INF", :reading_id => "1", :comments => "Test range 1"} | |
| 9 | 13 | end |
| 10 | 14 | |
| 11 | 15 | def self.range_hash | ... | ... |
plugins/mezuro/test/functional/myprofile/mezuro_plugin_range_controller_test.rb
| ... | ... | @@ -4,6 +4,7 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_fixtures" |
| 4 | 4 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" |
| 5 | 5 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" |
| 6 | 6 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" |
| 7 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_fixtures" | |
| 7 | 8 | |
| 8 | 9 | class MezuroPluginRangeControllerTest < ActionController::TestCase |
| 9 | 10 | |
| ... | ... | @@ -13,85 +14,68 @@ class MezuroPluginRangeControllerTest < ActionController::TestCase |
| 13 | 14 | @response = ActionController::TestResponse.new |
| 14 | 15 | @profile = fast_create(Community) |
| 15 | 16 | |
| 16 | - @metric = MetricFixtures.amloc | |
| 17 | 17 | @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration |
| 18 | 18 | @metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash |
| 19 | 19 | @configuration = ConfigurationFixtures.configuration |
| 20 | 20 | |
| 21 | - Kalibro::Configuration.expects(:all_names).returns([]) | |
| 22 | - @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name) | |
| 23 | - @content.expects(:send_kalibro_configuration_to_service).returns(nil) | |
| 21 | + @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name, :configuration_id => 42) | |
| 22 | + @content.expects(:send_configuration_to_service).returns(nil) | |
| 23 | + @content.expects(:validate_configuration_name).returns(true) | |
| 24 | 24 | @content.stubs(:solr_save) |
| 25 | 25 | @content.save |
| 26 | 26 | |
| 27 | - @range = RangeFixtures.range_excellent | |
| 28 | - @range_hash = RangeFixtures.range_excellent_hash | |
| 27 | + @created_range = RangeFixtures.created_range | |
| 28 | + @range = RangeFixtures.range | |
| 29 | + @created_range_hash = RangeFixtures.created_range_hash | |
| 30 | + @range_hash = RangeFixtures.range_hash | |
| 31 | + | |
| 32 | + @reading = ReadingFixtures.reading | |
| 29 | 33 | end |
| 30 | 34 | |
| 31 | - should 'test new range' do | |
| 32 | - get :new_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name | |
| 33 | - assert_equal @content.id.to_s, assigns(:content_id) | |
| 34 | - assert_equal @metric.name, assigns(:metric_name) | |
| 35 | + should 'set correct attributes to create a new range' do | |
| 36 | + Kalibro::Reading.expects(:readings_of).with(@metric_configuration.reading_group_id).returns([@reading]) | |
| 37 | + get :new, :profile => @profile.identifier, :id => @content.id, :metric_configuration_id => @metric_configuration.id, :reading_group_id => @metric_configuration.reading_group_id | |
| 38 | + assert_equal @content.id, assigns(:content_id) | |
| 39 | + assert_equal @metric_configuration.id, assigns(:metric_configuration_id) | |
| 40 | + assert_equal [[@reading.label,@reading.id]], assigns(:reading_labels_and_ids) | |
| 35 | 41 | assert_response 200 |
| 36 | 42 | end |
| 37 | 43 | |
| 38 | - should 'test edit range' do | |
| 39 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 40 | - :configuration_name => @content.name, | |
| 41 | - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
| 42 | - get :edit_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name, :beginning_id => @range.beginning | |
| 43 | - assert_equal @content.id.to_s, assigns(:content_id) | |
| 44 | - assert_equal @metric.name, assigns(:metric_name) | |
| 45 | - assert_equal @range.beginning, assigns(:beginning_id) | |
| 46 | - assert_equal @range.end, assigns(:range).end | |
| 44 | + should 'set correct attributes to edit a range' do | |
| 45 | + Kalibro::Reading.expects(:readings_of).with(@metric_configuration.reading_group_id).returns([@reading]) | |
| 46 | + Kalibro::Range.expects(:ranges_of).with(@metric_configuration.id).returns([@range]) | |
| 47 | + get :edit, :profile => @profile.identifier, :id => @content.id, :metric_configuration_id => @metric_configuration.id, :range_id => @range.id, :reading_group_id => @metric_configuration.reading_group_id | |
| 48 | + assert_equal @content.id, assigns(:content_id) | |
| 49 | + assert_equal @metric_configuration.id, assigns(:metric_configuration_id) | |
| 50 | + assert_equal [[@reading.label,@reading.id]], assigns(:reading_labels_and_ids) | |
| 51 | + assert_equal @range, assigns(:range) | |
| 47 | 52 | assert_response 200 |
| 48 | 53 | end |
| 49 | 54 | |
| 50 | 55 | should 'test create instance range' do |
| 51 | - metric_configuration = @metric_configuration | |
| 52 | - metric_configuration.add_range(@range) | |
| 53 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 54 | - :configuration_name => @content.name, | |
| 55 | - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
| 56 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
| 57 | - :metric_configuration => metric_configuration.to_hash, | |
| 58 | - :configuration_name => metric_configuration.configuration_name}) | |
| 59 | - get :create_range, :profile => @profile.identifier, :range => @range_hash, :id => @content.id, :metric_name => @metric.name | |
| 60 | - assert_equal @content, assigns(:configuration_content) | |
| 61 | - assert_equal @range.end, assigns(:range).end | |
| 56 | + Kalibro::Range.expects(:request).with(:save_range, { | |
| 57 | + :metric_configuration_id => @metric_configuration.id, | |
| 58 | + :range => @created_range.to_hash}).returns(:range_id => @range.id) | |
| 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 | |
| 61 | + assert_equal @range.id, assigns(:range).id | |
| 62 | 62 | assert_response 200 |
| 63 | 63 | end |
| 64 | 64 | |
| 65 | 65 | should 'test update range' do |
| 66 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 67 | - :configuration_name => @content.name, | |
| 68 | - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
| 69 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
| 70 | - :metric_configuration => @metric_configuration.to_hash, | |
| 71 | - :configuration_name => @metric_configuration.configuration_name}) | |
| 72 | - get :update_range, | |
| 73 | - :profile => @profile.identifier, | |
| 74 | - :range => @range_hash, | |
| 75 | - :id => @content.id, | |
| 76 | - :metric_name => @metric.name, | |
| 77 | - :beginning_id => @range.beginning | |
| 66 | + Kalibro::Range.expects(:request).with(:save_range, { | |
| 67 | + :metric_configuration_id => @metric_configuration.id, | |
| 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 | |
| 71 | + assert_equal @range.id, assigns(:range).id | |
| 78 | 72 | assert_response 200 |
| 79 | 73 | end |
| 80 | 74 | |
| 81 | - should 'test remove range' do | |
| 82 | - metric_configuration = @metric_configuration | |
| 83 | - metric_configuration.ranges.delete_if { |range| range.beginning == @range.beginning.to_f } | |
| 84 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
| 85 | - :configuration_name => @content.name, | |
| 86 | - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
| 87 | - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
| 88 | - :metric_configuration => metric_configuration.to_hash, | |
| 89 | - :configuration_name => metric_configuration.configuration_name}) | |
| 90 | - get :remove_range, | |
| 91 | - :profile => @profile.identifier, | |
| 92 | - :id => @content.id, | |
| 93 | - :metric_name => @metric.name, | |
| 94 | - :beginning_id => @range.beginning | |
| 75 | + should 'test remove range in native metric configuration' do | |
| 76 | + Kalibro::Range.expects(:new).with({:id => @range.id}).returns(@range) | |
| 77 | + @range.expects(:destroy).with().returns() | |
| 78 | + get :remove, :id => @content.id, :metric_configuration_id => @metric_configuration.id, :range_id => @range.id, :compound => false | |
| 95 | 79 | assert_response 302 |
| 96 | 80 | end |
| 97 | 81 | end | ... | ... |
plugins/mezuro/views/mezuro_plugin_metric_configuration/edit_native.html.erb
| ... | ... | @@ -42,7 +42,7 @@ |
| 42 | 42 | |
| 43 | 43 | <br/> |
| 44 | 44 | <% if owner %> |
| 45 | - <%= link_to_remote "New Range", :url => {:action =>"new_range", :controller => "mezuro_plugin_range", :id => @configuration_content.id, :metric_configuration_id => @metric_configuration.id, :reading_group_id => @metric_configuration.reading_group_id} %> | |
| 45 | + <%= 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} %> | |
| 46 | 46 | <% end %> |
| 47 | -<div id="range_form" style="display:none"></div> | |
| 47 | +<div id="form" style="display:none"></div> | |
| 48 | 48 | ... | ... |
plugins/mezuro/views/mezuro_plugin_range/_edit_range.html.erb
| ... | ... | @@ -0,0 +1,35 @@ |
| 1 | +<%= hidden_field_tag :id, @content_id %> | |
| 2 | +<%= hidden_field_tag :metric_configuration_id, @metric_configuration_id %> | |
| 3 | + | |
| 4 | +<%= f.hidden_field :id %> | |
| 5 | + | |
| 6 | + <%= required labelled_form_field _('Label'), | |
| 7 | + f.select(:reading_id, @reading_labels_and_ids, :selected => @selected_reading_label) %><br/> | |
| 8 | +<table> | |
| 9 | + <tr> | |
| 10 | + <td> | |
| 11 | + <%= f.label :beginning, "(*) Beginning:" %> | |
| 12 | + </td> | |
| 13 | + <td> | |
| 14 | + <%= required f.text_field :beginning, :id => "range_beginning" %> <%= link_to('-∞', 'javascript:void(0)', :onClick => "jQuery( '#range_beginning' ).val('-INF');") %> | |
| 15 | + </td> | |
| 16 | + </tr> | |
| 17 | + <tr> | |
| 18 | + <td> | |
| 19 | + <%= f.label :end, "(*) End:" %> | |
| 20 | + </td> | |
| 21 | + <td> | |
| 22 | + <%= required f.text_field(:end, :id => "range_end") %> <%= link_to('+∞', 'javascript:void(0)', :onClick => "jQuery( '#range_end' ).val('+INF');") %> | |
| 23 | + </td> | |
| 24 | + </tr> | |
| 25 | + <tr> | |
| 26 | + <td> | |
| 27 | + <%= f.label :comments, "(*) Comments:" %> | |
| 28 | + </td> | |
| 29 | + <td> | |
| 30 | + <%= required f.text_area :comments, :rows => 3 %> | |
| 31 | + </td> | |
| 32 | + </tr> | |
| 33 | +</table> | |
| 34 | +<br/> | |
| 35 | +<%= f.submit "Save Range" %> | ... | ... |
plugins/mezuro/views/mezuro_plugin_range/_new_range.html.erb
plugins/mezuro/views/mezuro_plugin_range/_range.html.erb
| ... | ... | @@ -13,9 +13,9 @@ |
| 13 | 13 | </td> |
| 14 | 14 | <td bgcolor="#<%= range.color %>"></td> |
| 15 | 15 | <% if (not user.nil?) && user.id == @profile.id %> |
| 16 | - <td><%= link_to_remote "Edit", :url => {:action =>"edit_range", :controller => "mezuro_plugin_range", :id => params[:id], :metric_configuration_id => params[:metric_configuration_id], :range_id => range.id, :reading_group_id => reading_group_id} %> | |
| 16 | + <td><%= link_to_remote "Edit", :url => {:action =>"edit", :controller => "mezuro_plugin_range", :id => params[:id], :metric_configuration_id => params[:metric_configuration_id], :range_id => range.id, :reading_group_id => reading_group_id} %> | |
| 17 | 17 | </td> |
| 18 | - <td><%= link_to "Remove", :action =>"remove_range", :controller => "mezuro_plugin_range", :id => params[:id], :metric_configuration_id => params[:metric_configuration_id], :range_id => range.id, :compound => compound %> | |
| 18 | + <td><%= link_to "Remove", :action =>"remove", :controller => "mezuro_plugin_range", :id => params[:id], :metric_configuration_id => params[:metric_configuration_id], :range_id => range.id, :compound => compound %> | |
| 19 | 19 | </td> |
| 20 | 20 | <% else %> |
| 21 | 21 | <td></td> | ... | ... |
plugins/mezuro/views/mezuro_plugin_range/_range_form.html.erb
| ... | ... | @@ -1,35 +0,0 @@ |
| 1 | -<%= hidden_field_tag :id, @content_id %> | |
| 2 | -<%= hidden_field_tag :metric_configuration_id, @metric_configuration_id %> | |
| 3 | - | |
| 4 | -<%= f.hidden_field :id %> | |
| 5 | - | |
| 6 | - <%= required labelled_form_field _('Label'), | |
| 7 | - f.select(:reading_id, @reading_labels_and_ids) %><br/> | |
| 8 | -<table> | |
| 9 | - <tr> | |
| 10 | - <td> | |
| 11 | - <%= f.label :beginning, "(*) Beginning:" %> | |
| 12 | - </td> | |
| 13 | - <td> | |
| 14 | - <%= required f.text_field :beginning, :id => "range_beginning" %> <%= link_to('-∞', 'javascript:void(0)', :onClick => "jQuery( '#range_beginning' ).val('-INF');") %> | |
| 15 | - </td> | |
| 16 | - </tr> | |
| 17 | - <tr> | |
| 18 | - <td> | |
| 19 | - <%= f.label :end, "(*) End:" %> | |
| 20 | - </td> | |
| 21 | - <td> | |
| 22 | - <%= required f.text_field(:end, :id => "range_end") %> <%= link_to('+∞', 'javascript:void(0)', :onClick => "jQuery( '#range_end' ).val('+INF');") %> | |
| 23 | - </td> | |
| 24 | - </tr> | |
| 25 | - <tr> | |
| 26 | - <td> | |
| 27 | - <%= f.label :comments, "(*) Comments:" %> | |
| 28 | - </td> | |
| 29 | - <td> | |
| 30 | - <%= required f.text_area :comments, :rows => 3 %> | |
| 31 | - </td> | |
| 32 | - </tr> | |
| 33 | -</table> | |
| 34 | -<br/> | |
| 35 | -<%= f.submit "Save Range" %> |
plugins/mezuro/views/mezuro_plugin_range/create_range.rjs
plugins/mezuro/views/mezuro_plugin_range/edit_range.rjs
plugins/mezuro/views/mezuro_plugin_range/new_range.rjs