Commit 73b93dec8bd64b15e816022a007ca7bada481fbc

Authored by Guilherme Rojas V. de Lima
Committed by Rafael Manzo
1 parent c5df944d

Choose metric page sends data using post method

Instead of send data via get: it causes error when the metric name had special characters.

signed-off-by: Diego Araújo <diegoamc90@gmail.com>
app/assets/javascripts/base_tool.js.coffee
1 1 class @BaseTool
2 2  
3 3 # Static Method
4   - @choose_metric: (mezuro_configuration_id, metric_name, base_tool_name) ->
5   - $.post '/mezuro_configurations/' + mezuro_configuration_id + '/metric_configurations/new',
6   - {
7   - mezuro_configuration_id: mezuro_configuration_id,
8   - metric_name: metric_name,
9   - base_tool_name: base_tool_name
10   - }
  4 + @choose_metric: (metric_name, base_tool_name) ->
  5 + $("#metric_name").val(metric_name)
  6 + $("#base_tool_name").val(base_tool_name)
  7 + $("form").submit()
... ...
app/controllers/metric_configurations_controller.rb
... ... @@ -9,6 +9,7 @@ class MetricConfigurationsController &lt; ApplicationController
9 9  
10 10 def choose_metric
11 11 @mezuro_configuration_id = params[:mezuro_configuration_id].to_i
  12 + @metric_configuration_id = params[:metric_configuration_id].to_i
12 13 @base_tools = KalibroGem::Entities::BaseTool.all
13 14 end
14 15  
... ... @@ -17,8 +18,6 @@ class MetricConfigurationsController &lt; ApplicationController
17 18 @metric_configuration.configuration_id = params[:mezuro_configuration_id].to_i
18 19 @metric_configuration.base_tool_name = params[:base_tool_name]
19 20 @metric_configuration.metric = KalibroGem::Entities::BaseTool.find_by_name(params[:base_tool_name]).metric params[:metric_name]
20   - format.html { redirect_to mezuro_configuration_path(@metric_configuration.configuration_id), notice: 'Metric Configuration was successfully created.' }
21   -
22 21 end
23 22  
24 23 def create
... ...
app/views/metric_configurations/choose_metric.html.erb
... ... @@ -2,14 +2,17 @@
2 2 <h1>Choose a metric from a base tool:</h1>
3 3 </div>
4 4  
  5 +<%= form_tag mezuro_configuration_new_metric_configuration_path(@mezuro_configuration_id) do %>
  6 + <%= hidden_field_tag(:base_tool_name,) %>
  7 + <%= hidden_field_tag(:metric_name) %>
  8 +<% end %>
  9 +
5 10 <div id="base-tool-accordion">
6   - <% @base_tools.each do |base_tool| %>
  11 + <% @base_tools.each do |base_tool| %>
7 12 <h3><%= base_tool.name %></h3>
8 13 <div>
9 14 <% base_tool.supported_metrics.each do |metric| %>
10   - <%= link_to metric.name, '',
11   - onclick: "BaseTool.choose_metric(#{@mezuro_configuration_id}, '#{metric.name}', '#{base_tool.name}')",
12   - remote: true%><br>
  15 + <%= link_to metric.name, '#', onclick: "BaseTool.choose_metric('#{metric.name}', '#{base_tool.name}')", remote: true %><br>
13 16 <% end %>
14 17 </div>
15 18 <% end %>
... ...
features/metric_configuration/create.feature
... ... @@ -9,7 +9,7 @@ Feature: Metric Configuration Creation
9 9 And I am at the Sample Configuration page
10 10 Then I should not see New Metric Configuration
11 11  
12   - @kalibro_restart
  12 + @kalibro_restart @javascript
13 13 Scenario: metric configuration creation
14 14 Given I am a regular user
15 15 And I am signed in
... ...
spec/controllers/metric_configurations_controller_spec.rb
... ... @@ -20,32 +20,30 @@ describe MetricConfigurationsController do
20 20 end
21 21 end
22 22  
23   - pending 'testing the js behavior first' do
24   - describe 'new' do
25   - let(:base_tool) { FactoryGirl.build(:base_tool) }
  23 + describe 'new' do
  24 + let(:base_tool) { FactoryGirl.build(:base_tool) }
  25 + before :each do
  26 + sign_in FactoryGirl.create(:user)
  27 + end
  28 +
  29 + context 'when the current user owns the mezuro configuration' do
26 30 before :each do
27   - sign_in FactoryGirl.create(:user)
  31 + subject.expects(:mezuro_configuration_owner?).returns true
  32 + KalibroGem::Entities::BaseTool.expects(:find_by_name).with(base_tool.name).returns(base_tool)
  33 + post :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", base_tool_name: base_tool.name
28 34 end
29 35  
30   - context 'when the current user owns the mezuro configuration' do
31   - before :each do
32   - subject.expects(:mezuro_configuration_owner?).returns true
33   - KalibroGem::Entities::BaseTool.expects(:find_by_name).with(base_tool.name).returns(base_tool)
34   - get :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", base_tool_name: base_tool.name
35   - end
  36 + it { should respond_with(:success) }
  37 + it { should render_template(:new) }
  38 + end
36 39  
37   - it { should respond_with(:success) }
38   - it { should render_template(:new) }
  40 + context "when the current user doesn't owns the mezuro configuration" do
  41 + before :each do
  42 + post :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", base_tool_name: base_tool.name
39 43 end
40 44  
41   - context "when the current user doesn't owns the mezuro configuration" do
42   - before :each do
43   - get :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", base_tool_name: base_tool.name
44   - end
45   -
46   - it { should redirect_to(mezuro_configurations_url) }
47   - it { should respond_with(:redirect) }
48   - end
  45 + it { should redirect_to(mezuro_configurations_url) }
  46 + it { should respond_with(:redirect) }
49 47 end
50 48 end
51 49  
... ...