Commit 3e26c2be4f6e87b47c3d3cc6515a181559253751
1 parent
2ca9dda6
Exists in
staging
and in
42 other branches
[Mezuro] Refactoring mezuro_plugin_base_tool controller
Showing
7 changed files
with
95 additions
and
32 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
| ... | ... | @@ -11,18 +11,6 @@ class MezuroPluginMyprofileController < ProfileController |
| 11 | 11 | @message = params[:message] |
| 12 | 12 | end |
| 13 | 13 | |
| 14 | - def choose_base_tool | |
| 15 | - @configuration_content = profile.articles.find(params[:id]) | |
| 16 | - @base_tools = Kalibro::BaseTool.all_names | |
| 17 | - end | |
| 18 | - | |
| 19 | - def choose_metric | |
| 20 | - @configuration_content = profile.articles.find(params[:id]) | |
| 21 | - @base_tool = params[:base_tool] | |
| 22 | - base_tool = Kalibro::BaseTool.find_by_name(@base_tool) | |
| 23 | - @supported_metrics = base_tool.nil? ? [] : base_tool.supported_metrics | |
| 24 | - end | |
| 25 | - | |
| 26 | 14 | def new_metric_configuration |
| 27 | 15 | @configuration_content = profile.articles.find(params[:id]) |
| 28 | 16 | @metric = Kalibro::BaseTool.find_by_name(params[:base_tool]).metric params[:metric_name] | ... | ... |
plugins/mezuro/controllers/myprofile/mezuro_plugin_base_tool_controller.rb
0 → 100644
| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | +class MezuroPluginBaseToolController < MezuroPluginMyprofileController | |
| 2 | + | |
| 3 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') | |
| 4 | + | |
| 5 | + def choose_base_tool | |
| 6 | + @configuration_content = profile.articles.find(params[:id]) | |
| 7 | + @base_tools = Kalibro::BaseTool.all_names | |
| 8 | + end | |
| 9 | + | |
| 10 | + def choose_metric | |
| 11 | + @configuration_content = profile.articles.find(params[:id]) | |
| 12 | + @base_tool = params[:base_tool] | |
| 13 | + base_tool = Kalibro::BaseTool.find_by_name(@base_tool) | |
| 14 | + @supported_metrics = base_tool.nil? ? [] : base_tool.supported_metrics | |
| 15 | + end | |
| 16 | + | |
| 17 | +end | ... | ... |
plugins/mezuro/test/functional/mezuro_plugin_myprofile_controller_test.rb
| ... | ... | @@ -36,23 +36,6 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
| 36 | 36 | @compound_hash.delete :attributes! |
| 37 | 37 | end |
| 38 | 38 | |
| 39 | - should 'test choose base tool' do | |
| 40 | - Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => @base_tool.name}) | |
| 41 | - get :choose_base_tool, :profile => @profile.identifier, :id => @content.id | |
| 42 | - assert_equal [@base_tool.name], assigns(:base_tools) | |
| 43 | - assert_equal @content, assigns(:configuration_content) | |
| 44 | - assert_response 200 | |
| 45 | - end | |
| 46 | - | |
| 47 | - should 'test choose metric' do | |
| 48 | - Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, {:base_tool_name => @base_tool.name}).returns({:base_tool => @base_tool_hash}) | |
| 49 | - get :choose_metric, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name | |
| 50 | - assert_equal @content, assigns(:configuration_content) | |
| 51 | - assert_equal @base_tool.name, assigns(:base_tool) | |
| 52 | - assert_equal @base_tool.supported_metric[0].name, assigns(:supported_metrics)[0].name | |
| 53 | - assert_response 200 | |
| 54 | - end | |
| 55 | - | |
| 56 | 39 | should 'test new metric configuration' do |
| 57 | 40 | Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, {:base_tool_name => @base_tool.name}).returns({:base_tool => @base_tool_hash}) |
| 58 | 41 | get :new_metric_configuration, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name, :metric_name => @metric.name |
| ... | ... | @@ -60,8 +43,7 @@ class MezuroPluginMyprofileControllerTest < ActionController::TestCase |
| 60 | 43 | assert_equal @metric.name, assigns(:metric).name |
| 61 | 44 | assert_response 200 |
| 62 | 45 | end |
| 63 | - | |
| 64 | - | |
| 46 | + | |
| 65 | 47 | should 'test new compound metric configuration' do |
| 66 | 48 | Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, {:configuration_name => @content.name}).returns({:configuration => @configuration_hash}) |
| 67 | 49 | get :new_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id | ... | ... |
plugins/mezuro/test/functional/myprofile/mezuro_plugin_base_tool_controller_test.rb
0 → 100644
| ... | ... | @@ -0,0 +1,42 @@ |
| 1 | +require 'test_helper' | |
| 2 | + | |
| 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures" | |
| 4 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" | |
| 5 | + | |
| 6 | +class MezuroPluginBaseToolControllerTest < ActionController::TestCase | |
| 7 | + | |
| 8 | + def setup | |
| 9 | + @controller = MezuroPluginBaseToolController.new | |
| 10 | + @request = ActionController::TestRequest.new | |
| 11 | + @response = ActionController::TestResponse.new | |
| 12 | + @profile = fast_create(Community) | |
| 13 | + | |
| 14 | + @base_tool = BaseToolFixtures.base_tool | |
| 15 | + @base_tool_hash = BaseToolFixtures.base_tool_hash | |
| 16 | + @configuration = ConfigurationFixtures.configuration | |
| 17 | + | |
| 18 | + Kalibro::Configuration.expects(:all_names).returns([]) | |
| 19 | + @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name) | |
| 20 | + @content.expects(:send_kalibro_configuration_to_service).returns(nil) | |
| 21 | + @content.stubs(:solr_save) | |
| 22 | + @content.save | |
| 23 | + end | |
| 24 | + | |
| 25 | + should 'test choose base tool' do | |
| 26 | + Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => @base_tool.name}) | |
| 27 | + get :choose_base_tool, :profile => @profile.identifier, :id => @content.id | |
| 28 | + assert_equal [@base_tool.name], assigns(:base_tools) | |
| 29 | + assert_equal @content, assigns(:configuration_content) | |
| 30 | + assert_response 200 | |
| 31 | + end | |
| 32 | + | |
| 33 | + should 'test choose metric' do | |
| 34 | + Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, {:base_tool_name => @base_tool.name}).returns({:base_tool => @base_tool_hash}) | |
| 35 | + get :choose_metric, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name | |
| 36 | + assert_equal @content, assigns(:configuration_content) | |
| 37 | + assert_equal @base_tool.name, assigns(:base_tool) | |
| 38 | + assert_equal @base_tool.supported_metric[0].name, assigns(:supported_metrics)[0].name | |
| 39 | + assert_response 200 | |
| 40 | + end | |
| 41 | + | |
| 42 | +end | ... | ... |
plugins/mezuro/views/content_viewer/show_configuration.rhtml
| ... | ... | @@ -22,7 +22,7 @@ |
| 22 | 22 | |
| 23 | 23 | <br/> |
| 24 | 24 | |
| 25 | - <%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_myprofile", | |
| 25 | + <%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_base_tool", | |
| 26 | 26 | :action => "choose_base_tool", :params => { :id => @configuration_content.id } %><br/> |
| 27 | 27 | |
| 28 | 28 | <table> | ... | ... |
plugins/mezuro/views/mezuro_plugin_base_tool/choose_base_tool.html.erb
0 → 100644
| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | +<h2><%= @configuration_content.name%> Configuration</h2> | |
| 2 | + | |
| 3 | +<%= link_to "New Compound Metric", :controller => "mezuro_plugin_myprofile", :action => "new_compound_metric_configuration", :params => | |
| 4 | +{ :id => @configuration_content.id } %> | |
| 5 | + | |
| 6 | +<h5>Base Tools:</h5> | |
| 7 | +<table id="project_info"> | |
| 8 | + <% @base_tools.each do |base_tool| %> | |
| 9 | + <tr> | |
| 10 | + <td> | |
| 11 | + <%= link_to base_tool, :controller => "mezuro_plugin_base_tool", :action => "choose_metric", :params => | |
| 12 | + { :base_tool => base_tool, :id => @configuration_content.id} %> | |
| 13 | + </td> | |
| 14 | + </tr> | |
| 15 | + <% end %> | |
| 16 | +</table> | ... | ... |
plugins/mezuro/views/mezuro_plugin_base_tool/choose_metric.html.erb
0 → 100644
| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | +<h2><%= @configuration_content.name %> Configuration</h2> | |
| 2 | + | |
| 3 | +<table id="project_info"> | |
| 4 | + <tr> | |
| 5 | + <h5>Metric Collector: <%= @base_tool %></h5> | |
| 6 | + </tr> | |
| 7 | + <tr> | |
| 8 | + <h5>Choose a metric to add:</h5> | |
| 9 | + </tr> | |
| 10 | + <% @supported_metrics.each do |metric| %> | |
| 11 | + <tr class="metric" title="<%= metric.name %>"> | |
| 12 | + <td> | |
| 13 | + <%= link_to metric.name, :controller => "mezuro_plugin_myprofile", :action => "new_metric_configuration", :params => {:metric_name => metric.name, | |
| 14 | + :base_tool => @base_tool, :id => @configuration_content.id } %> | |
| 15 | + </td> | |
| 16 | + </tr> | |
| 17 | + <% end %> | |
| 18 | +</table> | ... | ... |