From 80e5af82fa803d687c8da5d96684ec0cffc21270 Mon Sep 17 00:00:00 2001 From: Renan Fichberg Date: Tue, 26 Nov 2013 17:05:40 -0200 Subject: [PATCH] Routes are in REST pattern. Also, fixed acceptance test for graphic show --- app/assets/javascripts/module/graphic.js.coffee | 3 +-- app/controllers/modules_controller.rb | 4 ++-- app/views/modules/_metric_result.html.erb | 2 +- config/routes.rb | 2 +- features/step_definitions/repository_steps.rb | 2 +- spec/routing/modules_routing_spec.rb | 4 ++-- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/module/graphic.js.coffee b/app/assets/javascripts/module/graphic.js.coffee index acb8ba4..dc6387f 100644 --- a/app/assets/javascripts/module/graphic.js.coffee +++ b/app/assets/javascripts/module/graphic.js.coffee @@ -9,9 +9,8 @@ class Module.Graphic container = @container display = this.display - $.get '/modules/metric_history', + $.get '/modules/' + @module_id + '/metric_history', metric_name: @metric_name - module_id: @module_id (data) -> display(data,container) diff --git a/app/controllers/modules_controller.rb b/app/controllers/modules_controller.rb index e0a3db0..5ad33e5 100644 --- a/app/controllers/modules_controller.rb +++ b/app/controllers/modules_controller.rb @@ -1,8 +1,8 @@ class ModulesController < ApplicationController - # GET /modules/metric_history + # GET /modules/1/metric_history def metric_history - module_result = ModuleResult.new({ id: params[:module_id] }) + module_result = ModuleResult.new({ id: params[:id] }) metric_history = module_result.metric_history(params[:metric_name]) # pending: sort this hash. dates = Array.new values = Array.new diff --git a/app/views/modules/_metric_result.html.erb b/app/views/modules/_metric_result.html.erb index af59702..de48ea4 100644 --- a/app/views/modules/_metric_result.html.erb +++ b/app/views/modules/_metric_result.html.erb @@ -4,7 +4,7 @@ metric_name = metric_configuration_snapshot.metric.name %> - <%= link_to metric_name, "#metric_#{module_result.id}", + <%= link_to metric_name, "", onclick: "new Module.Graphic('container#{metric_result.id}', '#{metric_name}', '#{module_result.id}')", id: "metric_#{module_result.id}", remote: true %> diff --git a/config/routes.rb b/config/routes.rb index 0dd8936..bfb0234 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,7 +11,7 @@ Mezuro::Application.routes.draw do end #resources :modules - get '/modules/metric_history' => 'modules#metric_history' + get '/modules/:id/metric_history' => 'modules#metric_history' post '/modules/:id/tree' => 'modules#load_module_tree' root "home#index" diff --git a/features/step_definitions/repository_steps.rb b/features/step_definitions/repository_steps.rb index af923f8..434af1e 100644 --- a/features/step_definitions/repository_steps.rb +++ b/features/step_definitions/repository_steps.rb @@ -97,5 +97,5 @@ Then(/^I should see a loaded graphic for the sample metric$/) do while (page.driver.network_traffic.last.response_parts.empty?) do sleep(10) end - page.all("img#container" + @metric_results.first.id.to_s).first.should_not be_nil + page.all("img#container" + @metric_results.first.id.to_s)[0].should_not be_nil end \ No newline at end of file diff --git a/spec/routing/modules_routing_spec.rb b/spec/routing/modules_routing_spec.rb index cbe5843..3803704 100644 --- a/spec/routing/modules_routing_spec.rb +++ b/spec/routing/modules_routing_spec.rb @@ -4,7 +4,7 @@ describe ModulesController do describe "routing" do it { should route(:post, '/modules/1/tree'). to(controller: :modules, action: :load_module_tree, id: 1) } - it { should route(:get, '/modules/metric_history'). - to(controller: :modules, action: :metric_history) } + it { should route(:get, '/modules/1/metric_history'). + to(controller: :modules, action: :metric_history, id: 1) } end end \ No newline at end of file -- libgit2 0.21.2