Commit c574b3275e10bd798a3acb81f4b96cf94ea62dbd
1 parent
dd27350b
Exists in
colab
and in
4 other branches
Refactored method metric_results from Processing to ModuleResult
So it gets easier to implement the navigation through Modules Signed-off by: João M. M. da Silva <jaodsilv@linux.ime.usp.br>
Showing
10 changed files
with
28 additions
and
18 deletions
Show diff stats
app/controllers/repositories_controller.rb
| @@ -8,11 +8,12 @@ class RepositoriesController < ApplicationController | @@ -8,11 +8,12 @@ class RepositoriesController < ApplicationController | ||
| 8 | 8 | ||
| 9 | # GET /projects/1/repositories/1 | 9 | # GET /projects/1/repositories/1 |
| 10 | # GET /projects/1/repositories/1.json | 10 | # GET /projects/1/repositories/1.json |
| 11 | + # GET /projects/1/repositories/1/modules/1 | ||
| 12 | + # GET /projects/1/repositories/1/modules/1.json | ||
| 11 | def show | 13 | def show |
| 12 | @configuration = KalibroEntities::Entities::Configuration.find(@repository.configuration_id) #FIXME: As soon as the Configuration model gets created refactor this! | 14 | @configuration = KalibroEntities::Entities::Configuration.find(@repository.configuration_id) #FIXME: As soon as the Configuration model gets created refactor this! |
| 13 | @processing = @repository.last_processing | 15 | @processing = @repository.last_processing |
| 14 | if @processing.ready? | 16 | if @processing.ready? |
| 15 | - @metric_results = @processing.metric_results | ||
| 16 | @root_module_result = @processing.root_module_result | 17 | @root_module_result = @processing.root_module_result |
| 17 | end | 18 | end |
| 18 | end | 19 | end |
app/models/module_result.rb
| 1 | class ModuleResult < KalibroEntities::Entities::ModuleResult | 1 | class ModuleResult < KalibroEntities::Entities::ModuleResult |
| 2 | include KalibroRecord | 2 | include KalibroRecord |
| 3 | + | ||
| 4 | + def metric_results | ||
| 5 | + KalibroEntities::Entities::MetricResult.metric_results_of(@id) | ||
| 6 | + end | ||
| 3 | end | 7 | end |
| 4 | \ No newline at end of file | 8 | \ No newline at end of file |
app/models/processing.rb
| @@ -5,10 +5,6 @@ class Processing < KalibroEntities::Entities::Processing | @@ -5,10 +5,6 @@ class Processing < KalibroEntities::Entities::Processing | ||
| 5 | @state == "READY" | 5 | @state == "READY" |
| 6 | end | 6 | end |
| 7 | 7 | ||
| 8 | - def metric_results | ||
| 9 | - KalibroEntities::Entities::MetricResult.metric_results_of(@results_root_id) | ||
| 10 | - end | ||
| 11 | - | ||
| 12 | def root_module_result | 8 | def root_module_result |
| 13 | KalibroEntities::Entities::ModuleResult.find(@results_root_id) | 9 | KalibroEntities::Entities::ModuleResult.find(@results_root_id) |
| 14 | end | 10 | end |
app/views/repositories/show.html.erb
| @@ -60,7 +60,7 @@ | @@ -60,7 +60,7 @@ | ||
| 60 | <th>Grade</th> | 60 | <th>Grade</th> |
| 61 | </thead> | 61 | </thead> |
| 62 | <tbody> | 62 | <tbody> |
| 63 | - <%= render partial: 'module_result', collection: children %> | 63 | + <%= render partial: 'module_result', collection: children %> |
| 64 | </tbody> | 64 | </tbody> |
| 65 | </table> | 65 | </table> |
| 66 | <% end %> | 66 | <% end %> |
| @@ -77,7 +77,7 @@ | @@ -77,7 +77,7 @@ | ||
| 77 | </thead> | 77 | </thead> |
| 78 | 78 | ||
| 79 | <tbody> | 79 | <tbody> |
| 80 | - <%= render partial: 'metric_result', collection: @metric_results %> | 80 | + <%= render partial: 'metric_result', collection: @root_module_result.metric_results %> |
| 81 | </tbody> | 81 | </tbody> |
| 82 | 82 | ||
| 83 | </table> | 83 | </table> |
config/routes.rb
| @@ -8,6 +8,7 @@ Mezuro::Application.routes.draw do | @@ -8,6 +8,7 @@ Mezuro::Application.routes.draw do | ||
| 8 | 8 | ||
| 9 | resources :projects do | 9 | resources :projects do |
| 10 | resources :repositories, except: [:update, :index] | 10 | resources :repositories, except: [:update, :index] |
| 11 | + get '/repositories/:id/modules/:module_id' => 'repositories#show', as: :repository_module | ||
| 11 | put '/repositories/:id' => 'repositories#update', as: :repository_update | 12 | put '/repositories/:id' => 'repositories#update', as: :repository_update |
| 12 | end | 13 | end |
| 13 | # The priority is based upon order of creation: first created -> highest priority. | 14 | # The priority is based upon order of creation: first created -> highest priority. |
spec/controllers/repositories_controller_spec.rb
| @@ -85,7 +85,6 @@ describe RepositoriesController do | @@ -85,7 +85,6 @@ describe RepositoriesController do | ||
| 85 | before :each do | 85 | before :each do |
| 86 | processing = FactoryGirl.build(:processing) | 86 | processing = FactoryGirl.build(:processing) |
| 87 | 87 | ||
| 88 | - processing.expects(:metric_results).returns(nil) | ||
| 89 | processing.expects(:root_module_result).returns(FactoryGirl.build(:module_result)) | 88 | processing.expects(:root_module_result).returns(FactoryGirl.build(:module_result)) |
| 90 | repository.expects(:last_processing).returns(processing) | 89 | repository.expects(:last_processing).returns(processing) |
| 91 | KalibroEntities::Entities::Configuration.expects(:find).with(repository.id).returns(FactoryGirl.build(:configuration)) | 90 | KalibroEntities::Entities::Configuration.expects(:find).with(repository.id).returns(FactoryGirl.build(:configuration)) |
spec/factories/module_results.rb
| 1 | FactoryGirl.define do | 1 | FactoryGirl.define do |
| 2 | - factory :module_result, class: KalibroEntities::Entities::ModuleResult do | 2 | + factory :module_result, class: ModuleResult do |
| 3 | id "42" | 3 | id "42" |
| 4 | self.module { FactoryGirl.build(:module) } | 4 | self.module { FactoryGirl.build(:module) } |
| 5 | grade "10.0" | 5 | grade "10.0" |
| @@ -7,7 +7,7 @@ FactoryGirl.define do | @@ -7,7 +7,7 @@ FactoryGirl.define do | ||
| 7 | height "6" | 7 | height "6" |
| 8 | end | 8 | end |
| 9 | 9 | ||
| 10 | - factory :root_module_result, class: KalibroEntities::Entities::ModuleResult do | 10 | + factory :root_module_result, class: ModuleResult do |
| 11 | id "21" | 11 | id "21" |
| 12 | self.module { FactoryGirl.build(:module) } | 12 | self.module { FactoryGirl.build(:module) } |
| 13 | grade "6.0" | 13 | grade "6.0" |
| @@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe ModuleResult do | ||
| 4 | + describe 'methods' do | ||
| 5 | + describe 'metric_results' do | ||
| 6 | + subject { FactoryGirl.build(:module_result) } | ||
| 7 | + | ||
| 8 | + it 'should call the metric_results_of method' do | ||
| 9 | + KalibroEntities::Entities::MetricResult.expects(:metric_results_of).with(subject.id).returns(nil) | ||
| 10 | + | ||
| 11 | + subject.metric_results | ||
| 12 | + end | ||
| 13 | + end | ||
| 14 | + end | ||
| 15 | +end | ||
| 0 | \ No newline at end of file | 16 | \ No newline at end of file |
spec/models/processing_spec.rb
| @@ -20,14 +20,6 @@ describe Processing do | @@ -20,14 +20,6 @@ describe Processing do | ||
| 20 | end | 20 | end |
| 21 | end | 21 | end |
| 22 | 22 | ||
| 23 | - describe 'metric_results' do | ||
| 24 | - it 'should call the metric_results_of method' do | ||
| 25 | - KalibroEntities::Entities::MetricResult.expects(:metric_results_of).with(subject.results_root_id).returns(nil) | ||
| 26 | - | ||
| 27 | - subject.metric_results | ||
| 28 | - end | ||
| 29 | - end | ||
| 30 | - | ||
| 31 | describe 'root_module_result' do | 23 | describe 'root_module_result' do |
| 32 | it 'should call the root_module_result method' do | 24 | it 'should call the root_module_result method' do |
| 33 | KalibroEntities::Entities::ModuleResult.expects(:find).with(subject.results_root_id).returns(FactoryGirl.build(:module_result)) | 25 | KalibroEntities::Entities::ModuleResult.expects(:find).with(subject.results_root_id).returns(FactoryGirl.build(:module_result)) |
spec/routing/repositories_routing_spec.rb
| @@ -10,6 +10,8 @@ describe RepositoriesController do | @@ -10,6 +10,8 @@ describe RepositoriesController do | ||
| 10 | to(controller: :repositories, action: :edit, project_id: 1, id: 1) } | 10 | to(controller: :repositories, action: :edit, project_id: 1, id: 1) } |
| 11 | it { should route(:get, '/projects/1/repositories/1'). | 11 | it { should route(:get, '/projects/1/repositories/1'). |
| 12 | to(controller: :repositories, action: :show, project_id: 1, id: 1) } | 12 | to(controller: :repositories, action: :show, project_id: 1, id: 1) } |
| 13 | + it { should route(:get, '/projects/1/repositories/1/modules/1'). | ||
| 14 | + to(controller: :repositories, action: :show, project_id: 1, module_id: 1, id: 1) } | ||
| 13 | it { should route(:delete, '/projects/1/repositories/1'). | 15 | it { should route(:delete, '/projects/1/repositories/1'). |
| 14 | to(controller: :repositories, action: :destroy, project_id: 1, id: 1) } | 16 | to(controller: :repositories, action: :destroy, project_id: 1, id: 1) } |
| 15 | it { should route(:put, '/projects/1/repositories/1'). | 17 | it { should route(:put, '/projects/1/repositories/1'). |