diff --git a/app/assets/javascripts/base_tool.js.coffee b/app/assets/javascripts/base_tool.js.coffee index aaf659e..4509254 100644 --- a/app/assets/javascripts/base_tool.js.coffee +++ b/app/assets/javascripts/base_tool.js.coffee @@ -1,10 +1,7 @@ class @BaseTool # Static Method - @choose_metric: (mezuro_configuration_id, metric_name, base_tool_name) -> - $.post '/mezuro_configurations/' + mezuro_configuration_id + '/metric_configurations/new', - { - mezuro_configuration_id: mezuro_configuration_id, - metric_name: metric_name, - base_tool_name: base_tool_name - } + @choose_metric: (metric_name, base_tool_name) -> + $("#metric_name").val(metric_name) + $("#base_tool_name").val(base_tool_name) + $("form").submit() diff --git a/app/controllers/metric_configurations_controller.rb b/app/controllers/metric_configurations_controller.rb index 4774e04..26414cc 100644 --- a/app/controllers/metric_configurations_controller.rb +++ b/app/controllers/metric_configurations_controller.rb @@ -9,6 +9,7 @@ class MetricConfigurationsController < ApplicationController def choose_metric @mezuro_configuration_id = params[:mezuro_configuration_id].to_i + @metric_configuration_id = params[:metric_configuration_id].to_i @base_tools = KalibroGem::Entities::BaseTool.all end @@ -17,8 +18,6 @@ class MetricConfigurationsController < ApplicationController @metric_configuration.configuration_id = params[:mezuro_configuration_id].to_i @metric_configuration.base_tool_name = params[:base_tool_name] @metric_configuration.metric = KalibroGem::Entities::BaseTool.find_by_name(params[:base_tool_name]).metric params[:metric_name] - format.html { redirect_to mezuro_configuration_path(@metric_configuration.configuration_id), notice: 'Metric Configuration was successfully created.' } - end def create diff --git a/app/views/metric_configurations/choose_metric.html.erb b/app/views/metric_configurations/choose_metric.html.erb index daff816..7f9db98 100644 --- a/app/views/metric_configurations/choose_metric.html.erb +++ b/app/views/metric_configurations/choose_metric.html.erb @@ -2,14 +2,17 @@

Choose a metric from a base tool:

+<%= form_tag mezuro_configuration_new_metric_configuration_path(@mezuro_configuration_id) do %> + <%= hidden_field_tag(:base_tool_name,) %> + <%= hidden_field_tag(:metric_name) %> +<% end %> +
- <% @base_tools.each do |base_tool| %> + <% @base_tools.each do |base_tool| %>

<%= base_tool.name %>

<% base_tool.supported_metrics.each do |metric| %> - <%= link_to metric.name, '', - onclick: "BaseTool.choose_metric(#{@mezuro_configuration_id}, '#{metric.name}', '#{base_tool.name}')", - remote: true%>
+ <%= link_to metric.name, '#', onclick: "BaseTool.choose_metric('#{metric.name}', '#{base_tool.name}')", remote: true %>
<% end %>
<% end %> diff --git a/features/metric_configuration/create.feature b/features/metric_configuration/create.feature index 607edd1..8126361 100644 --- a/features/metric_configuration/create.feature +++ b/features/metric_configuration/create.feature @@ -9,7 +9,7 @@ Feature: Metric Configuration Creation And I am at the Sample Configuration page Then I should not see New Metric Configuration - @kalibro_restart + @kalibro_restart @javascript Scenario: metric configuration creation Given I am a regular user And I am signed in diff --git a/spec/controllers/metric_configurations_controller_spec.rb b/spec/controllers/metric_configurations_controller_spec.rb index 574fe3c..5d5dddf 100644 --- a/spec/controllers/metric_configurations_controller_spec.rb +++ b/spec/controllers/metric_configurations_controller_spec.rb @@ -20,32 +20,30 @@ describe MetricConfigurationsController do end end - pending 'testing the js behavior first' do - describe 'new' do - let(:base_tool) { FactoryGirl.build(:base_tool) } + describe 'new' do + let(:base_tool) { FactoryGirl.build(:base_tool) } + before :each do + sign_in FactoryGirl.create(:user) + end + + context 'when the current user owns the mezuro configuration' do before :each do - sign_in FactoryGirl.create(:user) + subject.expects(:mezuro_configuration_owner?).returns true + KalibroGem::Entities::BaseTool.expects(:find_by_name).with(base_tool.name).returns(base_tool) + post :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", base_tool_name: base_tool.name end - context 'when the current user owns the mezuro configuration' do - before :each do - subject.expects(:mezuro_configuration_owner?).returns true - KalibroGem::Entities::BaseTool.expects(:find_by_name).with(base_tool.name).returns(base_tool) - get :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", base_tool_name: base_tool.name - end + it { should respond_with(:success) } + it { should render_template(:new) } + end - it { should respond_with(:success) } - it { should render_template(:new) } + context "when the current user doesn't owns the mezuro configuration" do + before :each do + post :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", base_tool_name: base_tool.name end - context "when the current user doesn't owns the mezuro configuration" do - before :each do - get :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", base_tool_name: base_tool.name - end - - it { should redirect_to(mezuro_configurations_url) } - it { should respond_with(:redirect) } - end + it { should redirect_to(mezuro_configurations_url) } + it { should respond_with(:redirect) } end end -- libgit2 0.21.2