Commit 18794d7f90be6b6e19a0162cd55abdede5c902ae
Committed by
Rafael Manzo
1 parent
9567b36a
Exists in
colab
and in
4 other branches
[WIP] Fixing prezento's unit tests according to the new kalibro client gem
Signed off by: Daniel Paulino Alves <danpaulalves@gmail.com>
Showing
28 changed files
with
118 additions
and
161 deletions
Show diff stats
app/controllers/base_metric_configurations_controller.rb
| ... | ... | @@ -10,14 +10,12 @@ class BaseMetricConfigurationsController < ApplicationController |
| 10 | 10 | |
| 11 | 11 | def new |
| 12 | 12 | update_metric_configuration(MetricConfiguration.new) |
| 13 | - metric_configuration.configuration_id = params[:kalibro_configuration_id].to_i | |
| 14 | 13 | end |
| 15 | 14 | |
| 16 | 15 | def show |
| 17 | 16 | if metric_configuration |
| 18 | 17 | @reading_group = ReadingGroup.find(metric_configuration.reading_group_id) |
| 19 | 18 | @mezuro_ranges = metric_configuration.kalibro_ranges |
| 20 | - metric_configuration.configuration_id = params[:kalibro_configuration_id].to_i | |
| 21 | 19 | else |
| 22 | 20 | raise NotImplementedError |
| 23 | 21 | end |
| ... | ... | @@ -25,7 +23,6 @@ class BaseMetricConfigurationsController < ApplicationController |
| 25 | 23 | |
| 26 | 24 | def create |
| 27 | 25 | update_metric_configuration(MetricConfiguration.new(metric_configuration_params)) |
| 28 | - metric_configuration.configuration_id = params[:kalibro_configuration_id].to_i | |
| 29 | 26 | end |
| 30 | 27 | |
| 31 | 28 | protected |
| ... | ... | @@ -43,4 +40,4 @@ class BaseMetricConfigurationsController < ApplicationController |
| 43 | 40 | def metric_configuration_params |
| 44 | 41 | params[:metric_configuration] |
| 45 | 42 | end |
| 46 | -end | |
| 47 | 43 | \ No newline at end of file |
| 44 | +end | ... | ... |
app/controllers/compound_metric_configurations_controller.rb
| ... | ... | @@ -17,19 +17,19 @@ class CompoundMetricConfigurationsController < BaseMetricConfigurationsControlle |
| 17 | 17 | |
| 18 | 18 | def edit |
| 19 | 19 | @compound_metric_configuration = @metric_configuration |
| 20 | - @compound_metric_configuration.configuration_id = params[:kalibro_configuration_id].to_i | |
| 20 | + @compound_metric_configuration.kalibro_configuration_id = params[:kalibro_configuration_id].to_i | |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | 23 | def update |
| 24 | 24 | respond_to do |format| |
| 25 | 25 | edit |
| 26 | 26 | if @compound_metric_configuration.update(metric_configuration_params) |
| 27 | - format.html { redirect_to kalibro_configuration_path(@compound_metric_configuration.configuration_id), notice: 'Compound Metric Configuration was successfully updated.' } | |
| 27 | + format.html { redirect_to kalibro_configuration_path(@compound_metric_configuration.kalibro_configuration_id), notice: 'Compound Metric Configuration was successfully updated.' } | |
| 28 | 28 | format.json { head :no_content } |
| 29 | 29 | else |
| 30 | 30 | failed_action(format, 'edit') |
| 31 | 31 | end |
| 32 | - Rails.cache.delete("#{@compound_metric_configuration.configuration_id}_metric_configurations") | |
| 32 | + Rails.cache.delete("#{@compound_metric_configuration.kalibro_configuration_id}_metric_configurations") | |
| 33 | 33 | end |
| 34 | 34 | end |
| 35 | 35 | |
| ... | ... | @@ -62,7 +62,7 @@ class CompoundMetricConfigurationsController < BaseMetricConfigurationsControlle |
| 62 | 62 | #Code extracted from create action |
| 63 | 63 | def create_and_redir(format) |
| 64 | 64 | if @compound_metric_configuration.save |
| 65 | - format.html { redirect_to kalibro_configuration_path(@compound_metric_configuration.configuration_id), notice: 'Compound Metric Configuration was successfully created.' } | |
| 65 | + format.html { redirect_to kalibro_configuration_path(@compound_metric_configuration.kalibro_configuration_id), notice: 'Compound Metric Configuration was successfully created.' } | |
| 66 | 66 | else |
| 67 | 67 | failed_action(format, 'new') |
| 68 | 68 | end | ... | ... |
app/controllers/metric_configurations_controller.rb
| ... | ... | @@ -2,20 +2,17 @@ class MetricConfigurationsController < BaseMetricConfigurationsController |
| 2 | 2 | def choose_metric |
| 3 | 3 | @kalibro_configuration = KalibroConfiguration.find(params[:kalibro_configuration_id].to_i) |
| 4 | 4 | @metric_configuration_id = params[:metric_configuration_id].to_i |
| 5 | - @metric_collectors_names = KalibroClient::Processor::MetricCollector.all_names | |
| 5 | + @metric_collectors_names = KalibroClient::Entities::Processor::MetricCollectorDetails.all_names | |
| 6 | 6 | end |
| 7 | 7 | |
| 8 | 8 | def new |
| 9 | 9 | super |
| 10 | - metric_configuration.metric_collector_name = params[:metric_collector_name] | |
| 11 | - metric_configuration.metric = KalibroClient::Processor::MetricCollector.find(params[:metric_collector_name]).metric params[:metric_code] | |
| 10 | + metric_configuration.metric = KalibroClient::Entities::Processor::MetricCollectorDetails.find(params[:metric_collector_name]).metric params[:metric_code] | |
| 12 | 11 | end |
| 13 | 12 | |
| 14 | 13 | def create |
| 15 | 14 | super |
| 16 | - @metric_configuration.metric = KalibroClient::Processor::MetricCollector.find(params[:metric_collector_name]).metric params[:metric_name] | |
| 17 | - @metric_configuration.metric_collector_name = params[:metric_collector_name] | |
| 18 | - @metric_configuration.code = @metric_configuration.metric.code | |
| 15 | + @metric_configuration.metric = KalibroClient::Entities::Processor::MetricCollectorDetails.find(params[:metric_collector_name]).metric params[:metric_name] | |
| 19 | 16 | respond_to do |format| |
| 20 | 17 | create_and_redir(format) |
| 21 | 18 | end |
| ... | ... | @@ -25,16 +22,16 @@ class MetricConfigurationsController < BaseMetricConfigurationsController |
| 25 | 22 | def edit |
| 26 | 23 | #FIXME: set the configuration id just once! |
| 27 | 24 | @kalibro_configuration_id = params[:kalibro_configuration_id] |
| 28 | - @metric_configuration.configuration_id = @kalibro_configuration_id | |
| 25 | + @metric_configuration.kalibro_configuration_id = @kalibro_configuration_id | |
| 29 | 26 | end |
| 30 | 27 | |
| 31 | 28 | def update |
| 32 | 29 | respond_to do |format| |
| 33 | - @metric_configuration.configuration_id = params[:kalibro_configuration_id] | |
| 30 | + @metric_configuration.kalibro_configuration_id = params[:kalibro_configuration_id] | |
| 34 | 31 | if @metric_configuration.update(metric_configuration_params) |
| 35 | - format.html { redirect_to(kalibro_configuration_path(@metric_configuration.configuration_id), notice: 'Metric Configuration was successfully updated.') } | |
| 32 | + format.html { redirect_to(kalibro_configuration_path(@metric_configuration.kalibro_configuration_id), notice: 'Metric Configuration was successfully updated.') } | |
| 36 | 33 | format.json { head :no_content } |
| 37 | - Rails.cache.delete("#{@metric_configuration.configuration_id}_metric_configurations") | |
| 34 | + Rails.cache.delete("#{@metric_configuration.kalibro_configuration_id}_metric_configurations") | |
| 38 | 35 | else |
| 39 | 36 | failed_action(format, 'edit') |
| 40 | 37 | end |
| ... | ... | @@ -73,7 +70,7 @@ class MetricConfigurationsController < BaseMetricConfigurationsController |
| 73 | 70 | #Code extracted from create action |
| 74 | 71 | def create_and_redir(format) |
| 75 | 72 | if @metric_configuration.save |
| 76 | - format.html { redirect_to kalibro_configuration_path(@metric_configuration.configuration_id), notice: 'Metric Configuration was successfully created.' } | |
| 73 | + format.html { redirect_to kalibro_configuration_path(@metric_configuration.kalibro_configuration_id), notice: 'Metric Configuration was successfully created.' } | |
| 77 | 74 | else |
| 78 | 75 | failed_action(format, 'new') |
| 79 | 76 | end | ... | ... |
app/controllers/readings_controller.rb
| ... | ... | @@ -8,13 +8,11 @@ class ReadingsController < ApplicationController |
| 8 | 8 | before_action :set_reading, only: [:edit, :update, :destroy] |
| 9 | 9 | |
| 10 | 10 | def new |
| 11 | - @reading_group_id = params[:reading_group_id] | |
| 12 | 11 | @reading = Reading.new |
| 13 | 12 | end |
| 14 | 13 | |
| 15 | 14 | def create |
| 16 | 15 | @reading = Reading.new(reading_params) |
| 17 | - @reading.group_id = params[:reading_group_id].to_i | |
| 18 | 16 | respond_to do |format| |
| 19 | 17 | create_and_redir(format) |
| 20 | 18 | end |
| ... | ... | @@ -22,16 +20,14 @@ class ReadingsController < ApplicationController |
| 22 | 20 | |
| 23 | 21 | # GET /readings/1/edit |
| 24 | 22 | def edit |
| 25 | - @reading_group_id = params[:reading_group_id] | |
| 26 | 23 | end |
| 27 | 24 | |
| 28 | 25 | # PUT /reading_groups/1/readings/1 |
| 29 | 26 | # PUT /reading_groups/1/readings/1.json |
| 30 | 27 | def update |
| 31 | - @reading.group_id = params[:reading_group_id].to_i | |
| 32 | 28 | respond_to do |format| |
| 33 | 29 | if @reading.update(reading_params) |
| 34 | - format.html { redirect_to(reading_group_path(params[:reading_group_id].to_i), notice: 'Reading was successfully updated.') } | |
| 30 | + format.html { redirect_to(reading_group_path(@reading.reading_group_id), notice: 'Reading was successfully updated.') } | |
| 35 | 31 | format.json { head :no_content } |
| 36 | 32 | else |
| 37 | 33 | failed_action(format, 'edit') |
| ... | ... | @@ -58,8 +54,6 @@ class ReadingsController < ApplicationController |
| 58 | 54 | |
| 59 | 55 | # Duplicated code on create and update actions extracted here |
| 60 | 56 | def failed_action(format, destiny_action) |
| 61 | - @reading_group_id = params[:reading_group_id] | |
| 62 | - | |
| 63 | 57 | format.html { render action: destiny_action } |
| 64 | 58 | format.json { render json: @reading.errors, status: :unprocessable_entity } |
| 65 | 59 | end |
| ... | ... | @@ -67,7 +61,7 @@ class ReadingsController < ApplicationController |
| 67 | 61 | # Code extracted from create action |
| 68 | 62 | def create_and_redir(format) |
| 69 | 63 | if @reading.save |
| 70 | - format.html { redirect_to reading_group_path(@reading.group_id), notice: 'Reading was successfully created.' } | |
| 64 | + format.html { redirect_to reading_group_path(@reading.reading_group_id), notice: 'Reading was successfully created.' } | |
| 71 | 65 | else |
| 72 | 66 | failed_action(format, 'new') |
| 73 | 67 | end | ... | ... |
app/controllers/repositories_controller.rb
| ... | ... | @@ -109,7 +109,7 @@ private |
| 109 | 109 | end |
| 110 | 110 | |
| 111 | 111 | def set_kalibro_configuration |
| 112 | - @kalibro_configuration = KalibroConfiguration.find(@repository.configuration_id) | |
| 112 | + @kalibro_configuration = KalibroConfiguration.find(@repository.kalibro_configuration_id) | |
| 113 | 113 | end |
| 114 | 114 | |
| 115 | 115 | # Never trust parameters from the scary internet, only allow the white list through. | ... | ... |
app/helpers/kalibro_configurations_helper.rb
| ... | ... | @@ -4,7 +4,7 @@ module KalibroConfigurationsHelper |
| 4 | 4 | end |
| 5 | 5 | |
| 6 | 6 | def link_to_edit_form(metric_configuration, kalibro_configuration_id) |
| 7 | - if (metric_configuration.metric.compound) | |
| 7 | + if (metric_configuration.metric.is_a? KalibroClient::Entities::Miscellaneous::CompoundMetric) | |
| 8 | 8 | link_to('Edit', edit_kalibro_configuration_compound_metric_configuration_path(kalibro_configuration_id, metric_configuration.id), class: 'btn btn-info') |
| 9 | 9 | else |
| 10 | 10 | link_to('Edit', edit_kalibro_configuration_metric_configuration_path(kalibro_configuration_id, metric_configuration.id), class: 'btn btn-info') |
| ... | ... | @@ -12,7 +12,7 @@ module KalibroConfigurationsHelper |
| 12 | 12 | end |
| 13 | 13 | |
| 14 | 14 | def link_to_show_page(metric_configuration, kalibro_configuration_id) |
| 15 | - if (metric_configuration.metric.compound) | |
| 15 | + if (metric_configuration.metric.is_a? KalibroClient::Entities::Miscellaneous::CompoundMetric) | |
| 16 | 16 | link_to('Show', kalibro_configuration_compound_metric_configuration_path(kalibro_configuration_id, metric_configuration.id), class: 'btn btn-info') |
| 17 | 17 | else |
| 18 | 18 | link_to('Show', kalibro_configuration_metric_configuration_path(kalibro_configuration_id, metric_configuration.id), class: 'btn btn-info') | ... | ... |
app/helpers/metric_configurations_helper.rb
| ... | ... | @@ -10,11 +10,11 @@ module MetricConfigurationsHelper |
| 10 | 10 | |
| 11 | 11 | def native_metrics_of(kalibro_configuration_id) |
| 12 | 12 | MetricConfiguration.metric_configurations_of(kalibro_configuration_id).map do |metric_configuration| |
| 13 | - [ metric_configuration.code, metric_configuration.metric.name ] | |
| 13 | + [ metric_configuration.metric.code, metric_configuration.metric.name ] | |
| 14 | 14 | end |
| 15 | 15 | end |
| 16 | 16 | |
| 17 | 17 | def supported_metrics_of(metric_collector_name) |
| 18 | - KalibroClient::Processor::MetricCollector.find(metric_collector_name).supported_metrics | |
| 18 | + KalibroClient::Processor::MetricCollectorDetails.find(metric_collector_name).supported_metrics | |
| 19 | 19 | end |
| 20 | 20 | end | ... | ... |
app/models/module_result.rb
| ... | ... | @@ -13,6 +13,6 @@ class ModuleResult < KalibroClient::Entities::Processor::ModuleResult |
| 13 | 13 | private |
| 14 | 14 | |
| 15 | 15 | def find_grade_by_metric_name(metric_results, name) |
| 16 | - metric_results.each { |metric_result| return metric_result.value if metric_result.metric_configuration.metric_snapshot.name == name } | |
| 16 | + metric_results.each { |metric_result| return metric_result.value if metric_result.metric_configuration.metric.name == name } | |
| 17 | 17 | end |
| 18 | 18 | end | ... | ... |
spec/controllers/base_metric_configurations_controller_spec.rb
| ... | ... | @@ -86,8 +86,7 @@ describe InheritsFromBaseMetricConfigurationsController, :type => :controller do |
| 86 | 86 | end |
| 87 | 87 | |
| 88 | 88 | describe 'create' do |
| 89 | - let!(:metric_configuration_params) { Hash[FactoryGirl.attributes_for(:metric_configuration).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers | |
| 90 | - let!(:metric_params) { Hash[FactoryGirl.attributes_for(:metric).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers | |
| 89 | + let!(:metric_configuration_params) { FactoryGirl.build(:metric_configuration, metric: FactoryGirl.build(:metric)).to_hash } | |
| 91 | 90 | let(:metric_collector) { FactoryGirl.build(:metric_collector) } |
| 92 | 91 | |
| 93 | 92 | before :each do |
| ... | ... | @@ -121,7 +120,7 @@ describe InheritsFromBaseMetricConfigurationsController, :type => :controller do |
| 121 | 120 | subject.expects(:find_resource).with(MetricConfiguration, metric_configuration.id).returns(metric_configuration) |
| 122 | 121 | metric_configuration.expects(:kalibro_ranges).returns([mezuro_range]) |
| 123 | 122 | |
| 124 | - get :show, kalibro_configuration_id: metric_configuration.configuration_id.to_s, id: metric_configuration.id | |
| 123 | + get :show, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s, id: metric_configuration.id | |
| 125 | 124 | end |
| 126 | 125 | |
| 127 | 126 | it { expect(subject.mezuro_ranges).not_to be_nil} | ... | ... |
spec/controllers/compound_metric_configurations_controller_spec.rb
| ... | ... | @@ -79,7 +79,7 @@ describe CompoundMetricConfigurationsController, :type => :controller do |
| 79 | 79 | subject.expects(:find_resource).with(MetricConfiguration, compound_metric_configuration.id).returns(compound_metric_configuration) |
| 80 | 80 | compound_metric_configuration.expects(:kalibro_ranges).returns([mezuro_range]) |
| 81 | 81 | |
| 82 | - get :show, kalibro_configuration_id: compound_metric_configuration.configuration_id.to_s, id: compound_metric_configuration.id | |
| 82 | + get :show, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id.to_s, id: compound_metric_configuration.id | |
| 83 | 83 | end |
| 84 | 84 | |
| 85 | 85 | it { is_expected.to render_template(:show) } |
| ... | ... | @@ -98,7 +98,7 @@ describe CompoundMetricConfigurationsController, :type => :controller do |
| 98 | 98 | subject.expects(:metric_configuration_owner?).returns(true) |
| 99 | 99 | subject.expects(:find_resource).with(MetricConfiguration, compound_metric_configuration.id).returns(compound_metric_configuration) |
| 100 | 100 | MetricConfiguration.expects(:metric_configurations_of).with(kalibro_configuration.id).returns([compound_metric_configuration]) |
| 101 | - get :edit, id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.configuration_id.to_s | |
| 101 | + get :edit, id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id.to_s | |
| 102 | 102 | end |
| 103 | 103 | |
| 104 | 104 | it { is_expected.to render_template(:edit) } |
| ... | ... | @@ -106,7 +106,7 @@ describe CompoundMetricConfigurationsController, :type => :controller do |
| 106 | 106 | |
| 107 | 107 | context 'when the user does not own the compound metric configuration' do |
| 108 | 108 | before do |
| 109 | - get :edit, id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.configuration_id.to_s | |
| 109 | + get :edit, id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id.to_s | |
| 110 | 110 | end |
| 111 | 111 | |
| 112 | 112 | it { is_expected.to redirect_to(kalibro_configurations_path(kalibro_configuration.id)) } |
| ... | ... | @@ -117,7 +117,7 @@ describe CompoundMetricConfigurationsController, :type => :controller do |
| 117 | 117 | |
| 118 | 118 | context 'with no user logged in' do |
| 119 | 119 | before :each do |
| 120 | - get :edit, id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.configuration_id.to_s | |
| 120 | + get :edit, id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id.to_s | |
| 121 | 121 | end |
| 122 | 122 | |
| 123 | 123 | it { is_expected.to redirect_to new_user_session_path } |
| ... | ... | @@ -143,10 +143,10 @@ describe CompoundMetricConfigurationsController, :type => :controller do |
| 143 | 143 | subject.expects(:find_resource).with(MetricConfiguration, compound_metric_configuration.id).returns(compound_metric_configuration) |
| 144 | 144 | MetricConfiguration.any_instance.expects(:update).with(metric_configuration_params).returns(true) |
| 145 | 145 | |
| 146 | - post :update, kalibro_configuration_id: compound_metric_configuration.configuration_id, id: compound_metric_configuration.id, metric_configuration: metric_configuration_params | |
| 146 | + post :update, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id, id: compound_metric_configuration.id, metric_configuration: metric_configuration_params | |
| 147 | 147 | end |
| 148 | 148 | |
| 149 | - it { should redirect_to(kalibro_configuration_path(compound_metric_configuration.configuration_id)) } | |
| 149 | + it { should redirect_to(kalibro_configuration_path(compound_metric_configuration.kalibro_configuration_id)) } | |
| 150 | 150 | it { should respond_with(:redirect) } |
| 151 | 151 | end |
| 152 | 152 | |
| ... | ... | @@ -156,7 +156,7 @@ describe CompoundMetricConfigurationsController, :type => :controller do |
| 156 | 156 | MetricConfiguration.expects(:metric_configurations_of).with(kalibro_configuration.id).returns([compound_metric_configuration]) |
| 157 | 157 | MetricConfiguration.any_instance.expects(:update).with(metric_configuration_params).returns(false) |
| 158 | 158 | |
| 159 | - post :update, kalibro_configuration_id: compound_metric_configuration.configuration_id, id: compound_metric_configuration.id, metric_configuration: metric_configuration_params | |
| 159 | + post :update, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id, id: compound_metric_configuration.id, metric_configuration: metric_configuration_params | |
| 160 | 160 | end |
| 161 | 161 | |
| 162 | 162 | it { should render_template(:edit) } |
| ... | ... | @@ -165,10 +165,10 @@ describe CompoundMetricConfigurationsController, :type => :controller do |
| 165 | 165 | |
| 166 | 166 | context 'when the user does not own the reading' do |
| 167 | 167 | before :each do |
| 168 | - post :update, kalibro_configuration_id: compound_metric_configuration.configuration_id, id: compound_metric_configuration.id, metric_configuration: metric_configuration_params | |
| 168 | + post :update, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id, id: compound_metric_configuration.id, metric_configuration: metric_configuration_params | |
| 169 | 169 | end |
| 170 | 170 | |
| 171 | - it { should redirect_to kalibro_configurations_path(compound_metric_configuration.configuration_id) } | |
| 171 | + it { should redirect_to kalibro_configurations_path(compound_metric_configuration.kalibro_configuration_id) } | |
| 172 | 172 | end |
| 173 | 173 | end |
| 174 | 174 | end | ... | ... |
spec/controllers/metric_configurations_controller_spec.rb
| ... | ... | @@ -11,7 +11,7 @@ describe MetricConfigurationsController, :type => :controller do |
| 11 | 11 | context 'when adding new metrics' do |
| 12 | 12 | before :each do |
| 13 | 13 | subject.expects(:kalibro_configuration_owner?).returns true |
| 14 | - KalibroClient::Processor::MetricCollector.expects(:all_names).returns([metric_collector]) | |
| 14 | + KalibroClient::Entities::Processor::MetricCollectorDetails.expects(:all_names).returns([metric_collector]) | |
| 15 | 15 | KalibroConfiguration.expects(:find).with(kalibro_configuration.id).returns(kalibro_configuration) |
| 16 | 16 | get :choose_metric, kalibro_configuration_id: kalibro_configuration.id |
| 17 | 17 | end |
| ... | ... | @@ -31,7 +31,7 @@ describe MetricConfigurationsController, :type => :controller do |
| 31 | 31 | context 'when the current user owns the mezuro configuration' do |
| 32 | 32 | before :each do |
| 33 | 33 | subject.expects(:kalibro_configuration_owner?).returns true |
| 34 | - KalibroClient::Processor::MetricCollector.expects(:find).with(metric_collector.name).returns(metric_collector) | |
| 34 | + KalibroClient::Entities::Processor::MetricCollectorDetails.expects(:find).with(metric_collector.name).returns(metric_collector) | |
| 35 | 35 | metric_collector.expects(:metric).with(native_metric.code).returns(native_metric) |
| 36 | 36 | post :new, kalibro_configuration_id: kalibro_configuration.id, metric_code: native_metric.code, metric_collector_name: metric_collector.name |
| 37 | 37 | end |
| ... | ... | @@ -52,7 +52,7 @@ describe MetricConfigurationsController, :type => :controller do |
| 52 | 52 | |
| 53 | 53 | describe 'create' do |
| 54 | 54 | let!(:metric_configuration) { FactoryGirl.build(:metric_configuration) } |
| 55 | - let(:metric_configuration_params) { Hash[FactoryGirl.attributes_for(:metric_configuration).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers | |
| 55 | + let(:metric_configuration_params) { metric_configuration.to_hash } | |
| 56 | 56 | let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration) } |
| 57 | 57 | let(:metric_collector) { FactoryGirl.build(:metric_collector) } |
| 58 | 58 | |
| ... | ... | @@ -68,7 +68,7 @@ describe MetricConfigurationsController, :type => :controller do |
| 68 | 68 | context 'with valid fields' do |
| 69 | 69 | before :each do |
| 70 | 70 | MetricConfiguration.any_instance.expects(:save).returns(true) |
| 71 | - KalibroClient::Processor::MetricCollector.expects(:find).with(metric_collector.name).returns(metric_collector) | |
| 71 | + KalibroClient::Entities::Processor::MetricCollectorDetails.expects(:find).with(metric_collector.name).returns(metric_collector) | |
| 72 | 72 | metric_collector.expects(:metric).with(metric_configuration.metric.name).returns(metric_configuration.metric) |
| 73 | 73 | |
| 74 | 74 | post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params, metric_collector_name: metric_collector.name, metric_name: metric_configuration.metric.name |
| ... | ... | @@ -80,7 +80,7 @@ describe MetricConfigurationsController, :type => :controller do |
| 80 | 80 | context 'with invalid fields' do |
| 81 | 81 | before :each do |
| 82 | 82 | MetricConfiguration.any_instance.expects(:save).returns(false) |
| 83 | - KalibroClient::Processor::MetricCollector.expects(:find).with(metric_collector.name).returns(metric_collector) | |
| 83 | + KalibroClient::Entities::Processor::MetricCollectorDetails.expects(:find).with(metric_collector.name).returns(metric_collector) | |
| 84 | 84 | metric_collector.expects(:metric).with(metric_configuration.metric.name).returns(metric_configuration.metric) |
| 85 | 85 | |
| 86 | 86 | post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params, metric_collector_name: metric_collector.name, metric_name: metric_configuration.metric.name |
| ... | ... | @@ -101,7 +101,7 @@ describe MetricConfigurationsController, :type => :controller do |
| 101 | 101 | subject.expects(:find_resource).with(MetricConfiguration, metric_configuration.id).returns(metric_configuration) |
| 102 | 102 | metric_configuration.expects(:kalibro_ranges).returns([mezuro_range]) |
| 103 | 103 | |
| 104 | - get :show, kalibro_configuration_id: metric_configuration.configuration_id.to_s, id: metric_configuration.id | |
| 104 | + get :show, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s, id: metric_configuration.id | |
| 105 | 105 | end |
| 106 | 106 | |
| 107 | 107 | it { is_expected.to render_template(:show) } |
| ... | ... | @@ -119,7 +119,7 @@ describe MetricConfigurationsController, :type => :controller do |
| 119 | 119 | before :each do |
| 120 | 120 | subject.expects(:metric_configuration_owner?).returns(true) |
| 121 | 121 | subject.expects(:find_resource).with(MetricConfiguration, metric_configuration.id).returns(metric_configuration) |
| 122 | - get :edit, id: metric_configuration.id, kalibro_configuration_id: metric_configuration.configuration_id.to_s | |
| 122 | + get :edit, id: metric_configuration.id, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s | |
| 123 | 123 | end |
| 124 | 124 | |
| 125 | 125 | it { is_expected.to render_template(:edit) } |
| ... | ... | @@ -127,10 +127,10 @@ describe MetricConfigurationsController, :type => :controller do |
| 127 | 127 | |
| 128 | 128 | context 'when the user does not own the metric configuration' do |
| 129 | 129 | before do |
| 130 | - get :edit, id: metric_configuration.id, kalibro_configuration_id: metric_configuration.configuration_id.to_s | |
| 130 | + get :edit, id: metric_configuration.id, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s | |
| 131 | 131 | end |
| 132 | 132 | |
| 133 | - it { is_expected.to redirect_to(kalibro_configurations_path(metric_configuration.configuration_id)) } | |
| 133 | + it { is_expected.to redirect_to(kalibro_configurations_path(metric_configuration.kalibro_configuration_id)) } | |
| 134 | 134 | it { is_expected.to respond_with(:redirect) } |
| 135 | 135 | it { is_expected.to set_the_flash[:notice].to("You're not allowed to do this operation") } |
| 136 | 136 | end |
| ... | ... | @@ -138,7 +138,7 @@ describe MetricConfigurationsController, :type => :controller do |
| 138 | 138 | |
| 139 | 139 | context 'with no user logged in' do |
| 140 | 140 | before :each do |
| 141 | - get :edit, id: metric_configuration.id, kalibro_configuration_id: metric_configuration.configuration_id.to_s | |
| 141 | + get :edit, id: metric_configuration.id, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s | |
| 142 | 142 | end |
| 143 | 143 | |
| 144 | 144 | it { is_expected.to redirect_to new_user_session_path } |
| ... | ... | @@ -164,10 +164,10 @@ describe MetricConfigurationsController, :type => :controller do |
| 164 | 164 | subject.expects(:find_resource).with(MetricConfiguration, metric_configuration.id).returns(metric_configuration) |
| 165 | 165 | MetricConfiguration.any_instance.expects(:update).with(metric_configuration_params).returns(true) |
| 166 | 166 | |
| 167 | - post :update, kalibro_configuration_id: metric_configuration.configuration_id, id: metric_configuration.id, metric_configuration: metric_configuration_params | |
| 167 | + post :update, kalibro_configuration_id: metric_configuration.kalibro_configuration_id, id: metric_configuration.id, metric_configuration: metric_configuration_params | |
| 168 | 168 | end |
| 169 | 169 | |
| 170 | - it { is_expected.to redirect_to(kalibro_configuration_path(metric_configuration.configuration_id)) } | |
| 170 | + it { is_expected.to redirect_to(kalibro_configuration_path(metric_configuration.kalibro_configuration_id)) } | |
| 171 | 171 | it { is_expected.to respond_with(:redirect) } |
| 172 | 172 | end |
| 173 | 173 | |
| ... | ... | @@ -176,7 +176,7 @@ describe MetricConfigurationsController, :type => :controller do |
| 176 | 176 | subject.expects(:find_resource).with(MetricConfiguration, metric_configuration.id).returns(metric_configuration) |
| 177 | 177 | MetricConfiguration.any_instance.expects(:update).with(metric_configuration_params).returns(false) |
| 178 | 178 | |
| 179 | - post :update, kalibro_configuration_id: metric_configuration.configuration_id, id: metric_configuration.id, metric_configuration: metric_configuration_params | |
| 179 | + post :update, kalibro_configuration_id: metric_configuration.kalibro_configuration_id, id: metric_configuration.id, metric_configuration: metric_configuration_params | |
| 180 | 180 | end |
| 181 | 181 | |
| 182 | 182 | it { is_expected.to render_template(:edit) } |
| ... | ... | @@ -185,10 +185,10 @@ describe MetricConfigurationsController, :type => :controller do |
| 185 | 185 | |
| 186 | 186 | context 'when the user does not own the reading' do |
| 187 | 187 | before :each do |
| 188 | - post :update, kalibro_configuration_id: metric_configuration.configuration_id, id: metric_configuration.id, metric_configuration: metric_configuration_params | |
| 188 | + post :update, kalibro_configuration_id: metric_configuration.kalibro_configuration_id, id: metric_configuration.id, metric_configuration: metric_configuration_params | |
| 189 | 189 | end |
| 190 | 190 | |
| 191 | - it { is_expected.to redirect_to kalibro_configurations_path(metric_configuration.configuration_id) } | |
| 191 | + it { is_expected.to redirect_to kalibro_configurations_path(metric_configuration.kalibro_configuration_id) } | |
| 192 | 192 | end |
| 193 | 193 | end |
| 194 | 194 | end |
| ... | ... | @@ -208,19 +208,19 @@ describe MetricConfigurationsController, :type => :controller do |
| 208 | 208 | metric_configuration.expects(:destroy) |
| 209 | 209 | subject.expects(:find_resource).with(MetricConfiguration, metric_configuration.id).returns(metric_configuration) |
| 210 | 210 | |
| 211 | - delete :destroy, id: metric_configuration.id, kalibro_configuration_id: metric_configuration.configuration_id.to_s | |
| 211 | + delete :destroy, id: metric_configuration.id, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s | |
| 212 | 212 | end |
| 213 | 213 | |
| 214 | - it { is_expected.to redirect_to(kalibro_configuration_path(metric_configuration.configuration_id)) } | |
| 214 | + it { is_expected.to redirect_to(kalibro_configuration_path(metric_configuration.kalibro_configuration_id)) } | |
| 215 | 215 | it { is_expected.to respond_with(:redirect) } |
| 216 | 216 | end |
| 217 | 217 | |
| 218 | 218 | context "when the user doesn't own the configuration" do |
| 219 | 219 | before :each do |
| 220 | - delete :destroy, id: metric_configuration.id, kalibro_configuration_id: metric_configuration.configuration_id.to_s | |
| 220 | + delete :destroy, id: metric_configuration.id, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s | |
| 221 | 221 | end |
| 222 | 222 | |
| 223 | - it { is_expected.to redirect_to(kalibro_configurations_path(metric_configuration.configuration_id)) } | |
| 223 | + it { is_expected.to redirect_to(kalibro_configurations_path(metric_configuration.kalibro_configuration_id)) } | |
| 224 | 224 | it { is_expected.to respond_with(:redirect) } |
| 225 | 225 | end |
| 226 | 226 | end | ... | ... |
spec/controllers/mezuro_ranges_controller_spec.rb
| ... | ... | @@ -82,26 +82,26 @@ describe MezuroRangesController, :type => :controller do |
| 82 | 82 | mezuro_range.expects(:destroy) |
| 83 | 83 | subject.expects(:find_resource).with(MezuroRange, mezuro_range.id).returns(mezuro_range) |
| 84 | 84 | |
| 85 | - delete :destroy, id: mezuro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, kalibro_configuration_id: metric_configuration.configuration_id.to_s | |
| 85 | + delete :destroy, id: mezuro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s | |
| 86 | 86 | end |
| 87 | 87 | |
| 88 | - it { is_expected.to redirect_to(kalibro_configuration_metric_configuration_path(metric_configuration.configuration_id, metric_configuration.id)) } | |
| 88 | + it { is_expected.to redirect_to(kalibro_configuration_metric_configuration_path(metric_configuration.kalibro_configuration_id, metric_configuration.id)) } | |
| 89 | 89 | it { is_expected.to respond_with(:redirect) } |
| 90 | 90 | end |
| 91 | 91 | |
| 92 | 92 | context "when the user doesn't own the metric configuration" do |
| 93 | 93 | before :each do |
| 94 | - delete :destroy, id: mezuro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, kalibro_configuration_id: metric_configuration.configuration_id.to_s | |
| 94 | + delete :destroy, id: mezuro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s | |
| 95 | 95 | end |
| 96 | 96 | |
| 97 | - it { is_expected.to redirect_to(kalibro_configurations_path(metric_configuration.configuration_id)) } | |
| 97 | + it { is_expected.to redirect_to(kalibro_configurations_path(metric_configuration.kalibro_configuration_id)) } | |
| 98 | 98 | it { is_expected.to respond_with(:redirect) } |
| 99 | 99 | end |
| 100 | 100 | end |
| 101 | 101 | |
| 102 | 102 | context 'with no User logged in' do |
| 103 | 103 | before :each do |
| 104 | - delete :destroy, id: mezuro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, kalibro_configuration_id: metric_configuration.configuration_id.to_s | |
| 104 | + delete :destroy, id: mezuro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s | |
| 105 | 105 | end |
| 106 | 106 | |
| 107 | 107 | it { is_expected.to redirect_to new_user_session_path } |
| ... | ... | @@ -111,7 +111,7 @@ describe MezuroRangesController, :type => :controller do |
| 111 | 111 | describe 'edit' do |
| 112 | 112 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } |
| 113 | 113 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1, metric_configuration_id: metric_configuration.id) } |
| 114 | - let(:reading) { FactoryGirl.build(:reading, group_id: metric_configuration.reading_group_id) } | |
| 114 | + let(:reading) { FactoryGirl.build(:reading, reading_group_id: metric_configuration.reading_group_id) } | |
| 115 | 115 | |
| 116 | 116 | context 'with an User logged in' do |
| 117 | 117 | before do |
| ... | ... | @@ -124,7 +124,7 @@ describe MezuroRangesController, :type => :controller do |
| 124 | 124 | subject.expects(:find_resource).with(MezuroRange, mezuro_range.id).returns(mezuro_range) |
| 125 | 125 | MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) |
| 126 | 126 | Reading.expects(:readings_of).with(metric_configuration.reading_group_id).returns([reading]) |
| 127 | - get :edit, id: mezuro_range.id, kalibro_configuration_id: metric_configuration.configuration_id, metric_configuration_id: metric_configuration.id | |
| 127 | + get :edit, id: mezuro_range.id, kalibro_configuration_id: metric_configuration.kalibro_configuration_id, metric_configuration_id: metric_configuration.id | |
| 128 | 128 | end |
| 129 | 129 | |
| 130 | 130 | it { is_expected.to render_template(:edit) } |
| ... | ... | @@ -134,10 +134,10 @@ describe MezuroRangesController, :type => :controller do |
| 134 | 134 | let!(:reading_group) { FactoryGirl.build(:reading_group, id: metric_configuration.reading_group_id) } |
| 135 | 135 | |
| 136 | 136 | before do |
| 137 | - get :edit, id: mezuro_range.id, kalibro_configuration_id: metric_configuration.configuration_id, metric_configuration_id: metric_configuration.id | |
| 137 | + get :edit, id: mezuro_range.id, kalibro_configuration_id: metric_configuration.kalibro_configuration_id, metric_configuration_id: metric_configuration.id | |
| 138 | 138 | end |
| 139 | 139 | |
| 140 | - it { is_expected.to redirect_to(kalibro_configurations_url(metric_configuration.configuration_id)) } | |
| 140 | + it { is_expected.to redirect_to(kalibro_configurations_url(metric_configuration.kalibro_configuration_id)) } | |
| 141 | 141 | it { is_expected.to respond_with(:redirect) } |
| 142 | 142 | it { is_expected.to set_the_flash[:notice].to("You're not allowed to do this operation") } |
| 143 | 143 | end |
| ... | ... | @@ -145,7 +145,7 @@ describe MezuroRangesController, :type => :controller do |
| 145 | 145 | |
| 146 | 146 | context 'with no user logged in' do |
| 147 | 147 | before :each do |
| 148 | - get :edit, id: mezuro_range.id, kalibro_configuration_id: metric_configuration.configuration_id, metric_configuration_id: metric_configuration.id | |
| 148 | + get :edit, id: mezuro_range.id, kalibro_configuration_id: metric_configuration.kalibro_configuration_id, metric_configuration_id: metric_configuration.id | |
| 149 | 149 | end |
| 150 | 150 | |
| 151 | 151 | it { is_expected.to redirect_to new_user_session_path } |
| ... | ... | @@ -156,7 +156,7 @@ describe MezuroRangesController, :type => :controller do |
| 156 | 156 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } |
| 157 | 157 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1, metric_configuration_id: metric_configuration.id) } |
| 158 | 158 | let(:mezuro_range_params) { Hash[FactoryGirl.attributes_for(:mezuro_range).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers |
| 159 | - let(:reading) { FactoryGirl.build(:reading, group_id: metric_configuration.reading_group_id) } | |
| 159 | + let(:reading) { FactoryGirl.build(:reading, reading_group_id: metric_configuration.reading_group_id) } | |
| 160 | 160 | |
| 161 | 161 | context 'when the user is logged in' do |
| 162 | 162 | before do |
| ... | ... | @@ -173,10 +173,10 @@ describe MezuroRangesController, :type => :controller do |
| 173 | 173 | subject.expects(:find_resource).with(MezuroRange, mezuro_range.id).returns(mezuro_range) |
| 174 | 174 | MezuroRange.any_instance.expects(:update).with(mezuro_range_params).returns(true) |
| 175 | 175 | |
| 176 | - post :update, kalibro_configuration_id: metric_configuration.configuration_id, id: mezuro_range.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | |
| 176 | + post :update, kalibro_configuration_id: metric_configuration.kalibro_configuration_id, id: mezuro_range.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | |
| 177 | 177 | end |
| 178 | 178 | |
| 179 | - it { is_expected.to redirect_to(kalibro_configuration_metric_configuration_path(metric_configuration.configuration_id, metric_configuration.id)) } | |
| 179 | + it { is_expected.to redirect_to(kalibro_configuration_metric_configuration_path(metric_configuration.kalibro_configuration_id, metric_configuration.id)) } | |
| 180 | 180 | it { is_expected.to respond_with(:redirect) } |
| 181 | 181 | end |
| 182 | 182 | |
| ... | ... | @@ -187,7 +187,7 @@ describe MezuroRangesController, :type => :controller do |
| 187 | 187 | MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) |
| 188 | 188 | Reading.expects(:readings_of).with(metric_configuration.reading_group_id).returns([reading]) |
| 189 | 189 | |
| 190 | - post :update, kalibro_configuration_id: metric_configuration.configuration_id, id: mezuro_range.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | |
| 190 | + post :update, kalibro_configuration_id: metric_configuration.kalibro_configuration_id, id: mezuro_range.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | |
| 191 | 191 | end |
| 192 | 192 | |
| 193 | 193 | it { is_expected.to render_template(:edit) } |
| ... | ... | @@ -196,10 +196,10 @@ describe MezuroRangesController, :type => :controller do |
| 196 | 196 | |
| 197 | 197 | context 'when the user does not own the mezuro range' do |
| 198 | 198 | before :each do |
| 199 | - post :update, kalibro_configuration_id: metric_configuration.configuration_id, id: mezuro_range.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | |
| 199 | + post :update, kalibro_configuration_id: metric_configuration.kalibro_configuration_id, id: mezuro_range.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | |
| 200 | 200 | end |
| 201 | 201 | |
| 202 | - it { is_expected.to redirect_to kalibro_configurations_path(metric_configuration.configuration_id) } | |
| 202 | + it { is_expected.to redirect_to kalibro_configurations_path(metric_configuration.kalibro_configuration_id) } | |
| 203 | 203 | end |
| 204 | 204 | end |
| 205 | 205 | end | ... | ... |
spec/controllers/readings_controller_spec.rb
| ... | ... | @@ -102,7 +102,7 @@ describe ReadingsController, :type => :controller do |
| 102 | 102 | end |
| 103 | 103 | |
| 104 | 104 | describe 'update' do |
| 105 | - let(:reading) { FactoryGirl.build(:reading) } | |
| 105 | + let(:reading) { FactoryGirl.build(:reading, reading_group_id: reading_group.id) } | |
| 106 | 106 | let(:reading_params) { Hash[FactoryGirl.attributes_for(:reading).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers |
| 107 | 107 | |
| 108 | 108 | context 'when the user is logged in' do |
| ... | ... | @@ -171,30 +171,30 @@ describe ReadingsController, :type => :controller do |
| 171 | 171 | reading.expects(:destroy) |
| 172 | 172 | subject.expects(:find_resource).with(Reading, reading.id).returns(reading) |
| 173 | 173 | |
| 174 | - delete :destroy, id: reading.id, reading_group_id: reading.group_id.to_s | |
| 174 | + delete :destroy, id: reading.id, reading_group_id: reading.reading_group_id.to_s | |
| 175 | 175 | end |
| 176 | 176 | |
| 177 | - it { is_expected.to redirect_to(reading_group_path(reading.group_id)) } | |
| 177 | + it { is_expected.to redirect_to(reading_group_path(reading.reading_group_id)) } | |
| 178 | 178 | it { is_expected.to respond_with(:redirect) } |
| 179 | 179 | end |
| 180 | 180 | |
| 181 | 181 | context "when the user doesn't own the reading group" do |
| 182 | 182 | before :each do |
| 183 | - delete :destroy, id: reading.id, reading_group_id: reading.group_id.to_s | |
| 183 | + delete :destroy, id: reading.id, reading_group_id: reading.reading_group_id.to_s | |
| 184 | 184 | end |
| 185 | 185 | |
| 186 | - it { is_expected.to redirect_to(reading_group_path(reading.group_id)) } | |
| 186 | + it { is_expected.to redirect_to(reading_group_path(reading.reading_group_id)) } | |
| 187 | 187 | it { is_expected.to respond_with(:redirect) } |
| 188 | 188 | end |
| 189 | 189 | end |
| 190 | 190 | |
| 191 | 191 | context 'with no User logged in' do |
| 192 | 192 | before :each do |
| 193 | - delete :destroy, id: reading.id, reading_group_id: reading.group_id.to_s | |
| 193 | + delete :destroy, id: reading.id, reading_group_id: reading.reading_group_id.to_s | |
| 194 | 194 | end |
| 195 | 195 | |
| 196 | 196 | it { is_expected.to redirect_to new_user_session_path } |
| 197 | 197 | end |
| 198 | 198 | end |
| 199 | 199 | |
| 200 | -end | |
| 201 | 200 | \ No newline at end of file |
| 201 | +end | ... | ... |
spec/factories/metric_collectors.rb
| ... | ... | @@ -2,7 +2,7 @@ FactoryGirl.define do |
| 2 | 2 | factory :metric_collector, class: KalibroClient::Entities::Processor::MetricCollectorDetails do |
| 3 | 3 | name 'Analizo' |
| 4 | 4 | description 'A metric collector' |
| 5 | - supported_metrics { { "total_abstract_classes" => FactoryGirl.build(:metric), "loc" => FactoryGirl.build(:loc)} } | |
| 5 | + supported_metrics { { "total_abstract_classes" => FactoryGirl.build(:metric).to_hash, "loc" => FactoryGirl.build(:loc).to_hash} } | |
| 6 | 6 | |
| 7 | 7 | initialize_with { new({"name" => name, "description" => description, "supported_metrics" => supported_metrics}) } |
| 8 | 8 | end | ... | ... |
spec/factories/metric_configurations.rb
| 1 | 1 | FactoryGirl.define do |
| 2 | 2 | factory :metric_configuration, class: MetricConfiguration do |
| 3 | 3 | id 1 |
| 4 | - code 'total_abstract_classes' | |
| 5 | - metric {FactoryGirl.build(:metric)} | |
| 6 | - metric_collector_name "Analizo" | |
| 4 | + metric {FactoryGirl.build(:metric, code: 'total_abstract_classes')} | |
| 7 | 5 | weight 1 |
| 8 | 6 | aggregation_form "AVERAGE" |
| 9 | 7 | reading_group_id 1 |
| ... | ... | @@ -12,19 +10,16 @@ FactoryGirl.define do |
| 12 | 10 | |
| 13 | 11 | factory :compound_metric_configuration, class: MetricConfiguration do |
| 14 | 12 | id 1 |
| 15 | - code 'compound' | |
| 16 | - metric { FactoryGirl.build(:compound_metric, script: 'native*2;') } | |
| 13 | + metric { FactoryGirl.build(:compound_metric, script: 'native*2;', code: 'compound') } | |
| 17 | 14 | weight 1 |
| 18 | 15 | aggregation_form "AVERAGE" |
| 19 | 16 | reading_group_id 1 |
| 20 | 17 | kalibro_configuration_id 1 |
| 21 | 18 | end |
| 22 | 19 | |
| 23 | - factory :metric_configuration_with_snapshot, class: MetricConfiguration do | |
| 20 | + factory :another_metric_configuration, class: MetricConfiguration do | |
| 24 | 21 | id 1 |
| 25 | - code 'total_modules' | |
| 26 | - metric_snapshot {FactoryGirl.build(:metric)} | |
| 27 | - metric_collector_name "Analizo" | |
| 22 | + metric {FactoryGirl.build(:metric, code: 'total_modules')} | |
| 28 | 23 | weight 1 |
| 29 | 24 | aggregation_form "MEDIAN" |
| 30 | 25 | reading_group_id 1 | ... | ... |
spec/factories/metric_configurations_snapshot.rb
| ... | ... | @@ -1,26 +0,0 @@ |
| 1 | -# This file is part of KalibroEntities | |
| 2 | -# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file) | |
| 3 | -# | |
| 4 | -# This program is free software: you can redistribute it and/or modify | |
| 5 | -# it under the terms of the GNU General Public License as published by | |
| 6 | -# the Free Software Foundation, either version 3 of the License, or | |
| 7 | -# (at your option) any later version. | |
| 8 | -# | |
| 9 | -# This program is distributed in the hope that it will be useful, | |
| 10 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 | -# GNU General Public License for more details. | |
| 13 | - | |
| 14 | -# You should have received a copy of the GNU General Public License | |
| 15 | -# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 16 | - | |
| 17 | -FactoryGirl.define do | |
| 18 | - factory :metric_configuration_snapshot, class: KalibroClient::Entities::Configurations::MetricSnapshot do | |
| 19 | - code "code" | |
| 20 | - weight "1.0" | |
| 21 | - aggregation_form 'AVERAGE' | |
| 22 | - metric {FactoryGirl.build(:metric)} | |
| 23 | - metric_collector_name "Analizo" | |
| 24 | - range {FactoryGirl.build(:range_snapshot)} | |
| 25 | - end | |
| 26 | -end |
spec/factories/metric_results.rb
| ... | ... | @@ -17,7 +17,7 @@ |
| 17 | 17 | FactoryGirl.define do |
| 18 | 18 | factory :metric_result, class: KalibroClient::Entities::Processor::MetricResult do |
| 19 | 19 | id "42" |
| 20 | - self.configuration { FactoryGirl.build(:metric_configuration) } | |
| 20 | + metric_configuration { FactoryGirl.build(:metric_configuration) } | |
| 21 | 21 | value "10.0" |
| 22 | 22 | aggregated_value "21" |
| 23 | 23 | end | ... | ... |
spec/factories/metrics.rb
| 1 | 1 | FactoryGirl.define do |
| 2 | - factory :metric, class: KalibroClient::Entities::Processor::NativeMetric do | |
| 2 | + factory :metric, class: KalibroClient::Entities::Miscellaneous::NativeMetric do | |
| 3 | 3 | name "Total Abstract Classes" |
| 4 | 4 | code "total_abstract_classes" |
| 5 | 5 | scope "SOFTWARE" |
| 6 | 6 | description nil |
| 7 | 7 | languages { [:C] } |
| 8 | + metric_collector_name "Analizo" | |
| 8 | 9 | |
| 9 | 10 | initialize_with { new(name, code, scope, description, languages) } |
| 10 | 11 | end |
| 11 | 12 | |
| 12 | - factory :loc, class: KalibroClient::Entities::Processor::NativeMetric do | |
| 13 | + factory :loc, class: KalibroClient::Entities::Miscellaneous::NativeMetric do | |
| 13 | 14 | name "Lines of Code" |
| 14 | 15 | code "loc" |
| 15 | 16 | scope "CLASS" |
| 16 | 17 | description nil |
| 17 | 18 | languages { [:C] } |
| 19 | + metric_collector_name "Analizo" | |
| 18 | 20 | |
| 19 | 21 | initialize_with { new(name, code, scope, description, languages) } |
| 20 | 22 | end |
| 21 | 23 | |
| 22 | - factory :compound_metric, class: KalibroClient::Entities::Processor::CompoundMetric do | |
| 24 | + factory :compound_metric, class: KalibroClient::Entities::Miscellaneous::CompoundMetric do | |
| 23 | 25 | name "Compound" |
| 24 | 26 | code "compound" |
| 25 | 27 | scope "CLASS" |
| 26 | 28 | description nil |
| 27 | 29 | script "" |
| 28 | 30 | |
| 29 | - initialize_with { new(name, code, scope, description, script) } | |
| 31 | + initialize_with { new(name, code, scope, script) } | |
| 30 | 32 | end |
| 31 | 33 | end | ... | ... |
spec/factories/module_results.rb
| 1 | 1 | FactoryGirl.define do |
| 2 | 2 | factory :module_result, class: ModuleResult do |
| 3 | 3 | id 42 |
| 4 | - self.module { FactoryGirl.build(:module) } | |
| 4 | + kalibro_module { FactoryGirl.build(:kalibro_module) } | |
| 5 | 5 | grade 10.0 |
| 6 | 6 | parent_id 21 |
| 7 | 7 | height 6 |
| ... | ... | @@ -9,7 +9,7 @@ FactoryGirl.define do |
| 9 | 9 | |
| 10 | 10 | factory :root_module_result, class: ModuleResult do |
| 11 | 11 | id 21 |
| 12 | - self.module { FactoryGirl.build(:module) } | |
| 12 | + kalibro_module { FactoryGirl.build(:kalibro_module) } | |
| 13 | 13 | grade 6.0 |
| 14 | 14 | parent_id nil |
| 15 | 15 | height 1 | ... | ... |
spec/factories/modules.rb
spec/factories/processings.rb
| ... | ... | @@ -3,8 +3,7 @@ FactoryGirl.define do |
| 3 | 3 | id "31" |
| 4 | 4 | date "2011-10-20T18:26:43.151+00:00" |
| 5 | 5 | state "READY" |
| 6 | - process_time {[FactoryGirl.build(:process_time)]} | |
| 7 | - results_root_id "13" | |
| 6 | + root_module_result_id "13" | |
| 8 | 7 | |
| 9 | 8 | trait :errored do |
| 10 | 9 | state "ERROR" |
| ... | ... | @@ -12,4 +11,4 @@ FactoryGirl.define do |
| 12 | 11 | |
| 13 | 12 | factory :errored_processing, traits: [:errored] |
| 14 | 13 | end |
| 15 | -end | |
| 16 | 14 | \ No newline at end of file |
| 15 | +end | ... | ... |
spec/factories/ranges_snapshot.rb
| ... | ... | @@ -15,7 +15,7 @@ |
| 15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | 16 | |
| 17 | 17 | FactoryGirl.define do |
| 18 | - factory :range_snapshot, class: KalibroClient::Entities::Configurations::KalibroRange do | |
| 18 | + factory :range_snapshot, class: KalibroClient::Entities::Configurations::RangeSnapshot do | |
| 19 | 19 | beginning 1.1 |
| 20 | 20 | self.end 5.1 |
| 21 | 21 | label "Snapshot" | ... | ... |
spec/factories/repositories.rb
| ... | ... | @@ -19,10 +19,10 @@ FactoryGirl.define do |
| 19 | 19 | name "SBKing" |
| 20 | 20 | description "A simple calculator" |
| 21 | 21 | license "GPLv3" |
| 22 | - process_period 1 | |
| 23 | - type "GIT" | |
| 22 | + period 1 | |
| 23 | + scm_type "GIT" | |
| 24 | 24 | address "https://git.gitorious.org/sbking/sbking.git" |
| 25 | - configuration_id 1 | |
| 25 | + kalibro_configuration_id 1 | |
| 26 | 26 | project_id 1 |
| 27 | 27 | send_email "test@test.com" |
| 28 | 28 | end |
| ... | ... | @@ -30,4 +30,4 @@ FactoryGirl.define do |
| 30 | 30 | factory :another_repository, parent: :repository do |
| 31 | 31 | id 2 |
| 32 | 32 | end |
| 33 | -end | |
| 34 | 33 | \ No newline at end of file |
| 34 | +end | ... | ... |
spec/helpers/metric_configurations_helper_spec.rb
| ... | ... | @@ -24,11 +24,11 @@ describe MetricConfigurationsHelper, :type => :helper do |
| 24 | 24 | let! (:metric_configuration) { FactoryGirl.build(:metric_configuration) } |
| 25 | 25 | |
| 26 | 26 | before :each do |
| 27 | - MetricConfiguration.expects(:metric_configurations_of).with(metric_configuration.configuration_id).returns([metric_configuration]) | |
| 27 | + MetricConfiguration.expects(:metric_configurations_of).with(metric_configuration.kalibro_configuration_id).returns([metric_configuration]) | |
| 28 | 28 | end |
| 29 | 29 | |
| 30 | 30 | it 'should return a pair with the metric configuration code and metric name' do |
| 31 | - expect(helper.native_metrics_of(metric_configuration.configuration_id)).to eq [[metric_configuration.code, metric_configuration.metric.name]] | |
| 31 | + expect(helper.native_metrics_of(metric_configuration.kalibro_configuration_id)).to eq [[metric_configuration.metric.code, metric_configuration.metric.name]] | |
| 32 | 32 | end |
| 33 | 33 | end |
| 34 | 34 | end | ... | ... |
spec/helpers/mezuro_configurations_helper_spec.rb
| ... | ... | @@ -45,32 +45,32 @@ describe KalibroConfigurationsHelper, :type => :helper do |
| 45 | 45 | describe 'link to edit form' do |
| 46 | 46 | context 'when the metric is native' do |
| 47 | 47 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } |
| 48 | - let(:response_link) {"<a class=\"btn btn-info\" href=\"/kalibro_configurations/#{metric_configuration.configuration_id}/metric_configurations/#{metric_configuration.id}/edit\">Edit</a>"} | |
| 48 | + let(:response_link) {"<a class=\"btn btn-info\" href=\"/kalibro_configurations/#{metric_configuration.kalibro_configuration_id}/metric_configurations/#{metric_configuration.id}/edit\">Edit</a>"} | |
| 49 | 49 | |
| 50 | - it { expect(helper.link_to_edit_form(metric_configuration, metric_configuration.configuration_id)).to eq(response_link) } | |
| 50 | + it { expect(helper.link_to_edit_form(metric_configuration, metric_configuration.kalibro_configuration_id)).to eq(response_link) } | |
| 51 | 51 | end |
| 52 | 52 | |
| 53 | 53 | context 'when the metric is compound' do |
| 54 | 54 | let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration) } |
| 55 | - let(:response_link) {"<a class=\"btn btn-info\" href=\"/kalibro_configurations/#{compound_metric_configuration.configuration_id}/compound_metric_configurations/#{compound_metric_configuration.id}/edit\">Edit</a>"} | |
| 55 | + let(:response_link) {"<a class=\"btn btn-info\" href=\"/kalibro_configurations/#{compound_metric_configuration.kalibro_configuration_id}/compound_metric_configurations/#{compound_metric_configuration.id}/edit\">Edit</a>"} | |
| 56 | 56 | |
| 57 | - it { expect(helper.link_to_edit_form(compound_metric_configuration, compound_metric_configuration.configuration_id)).to eq(response_link) } | |
| 57 | + it { expect(helper.link_to_edit_form(compound_metric_configuration, compound_metric_configuration.kalibro_configuration_id)).to eq(response_link) } | |
| 58 | 58 | end |
| 59 | 59 | end |
| 60 | 60 | |
| 61 | 61 | describe 'link to show page' do |
| 62 | 62 | context 'when the metric is native' do |
| 63 | 63 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } |
| 64 | - let(:response_link) {"<a class=\"btn btn-info\" href=\"/kalibro_configurations/#{metric_configuration.configuration_id}/metric_configurations/#{metric_configuration.id}\">Show</a>"} | |
| 64 | + let(:response_link) {"<a class=\"btn btn-info\" href=\"/kalibro_configurations/#{metric_configuration.kalibro_configuration_id}/metric_configurations/#{metric_configuration.id}\">Show</a>"} | |
| 65 | 65 | |
| 66 | - it { expect(helper.link_to_show_page(metric_configuration, metric_configuration.configuration_id)).to eq(response_link) } | |
| 66 | + it { expect(helper.link_to_show_page(metric_configuration, metric_configuration.kalibro_configuration_id)).to eq(response_link) } | |
| 67 | 67 | end |
| 68 | 68 | |
| 69 | 69 | context 'when the metric is compound' do |
| 70 | 70 | let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration) } |
| 71 | - let(:response_link) {"<a class=\"btn btn-info\" href=\"/kalibro_configurations/#{compound_metric_configuration.configuration_id}/compound_metric_configurations/#{compound_metric_configuration.id}\">Show</a>"} | |
| 71 | + let(:response_link) {"<a class=\"btn btn-info\" href=\"/kalibro_configurations/#{compound_metric_configuration.kalibro_configuration_id}/compound_metric_configurations/#{compound_metric_configuration.id}\">Show</a>"} | |
| 72 | 72 | |
| 73 | - it { expect(helper.link_to_show_page(compound_metric_configuration, compound_metric_configuration.configuration_id)).to eq(response_link) } | |
| 73 | + it { expect(helper.link_to_show_page(compound_metric_configuration, compound_metric_configuration.kalibro_configuration_id)).to eq(response_link) } | |
| 74 | 74 | end |
| 75 | 75 | end |
| 76 | 76 | end | ... | ... |
spec/helpers/processings_helper_spec.rb
| ... | ... | @@ -14,15 +14,15 @@ describe ProcessingsHelper, :type => :helper do |
| 14 | 14 | end |
| 15 | 15 | |
| 16 | 16 | describe 'find_range_snapshot' do |
| 17 | - let(:metric_configuration_snapshot) { FactoryGirl.build(:metric_configuration_snapshot)} | |
| 18 | - let(:metric_result) { FactoryGirl.build(:metric_result, {value: 6.0, configuration: metric_configuration_snapshot})} | |
| 17 | + let(:metric_configuration) { FactoryGirl.build(:metric_configuration)} | |
| 18 | + let(:metric_result) { FactoryGirl.build(:metric_result, {value: 6.0, metric_configuration: metric_configuration})} | |
| 19 | 19 | let(:range_snapshot_1_to_5) { FactoryGirl.build(:range_snapshot, {beginning: 1.0, end: 5.0}) } |
| 20 | 20 | let(:range_snapshot_5dot1_to_10) { FactoryGirl.build(:range_snapshot, {beginning: 5.1, end: 10.0}) } |
| 21 | 21 | let(:range_snapshot_10dot1_to_15) { FactoryGirl.build(:range_snapshot, {beginning: 10.1, end: 15.0}) } |
| 22 | 22 | |
| 23 | 23 | before :each do |
| 24 | - metric_result.expects(:metric_configuration).returns(metric_result.configuration) | |
| 25 | - metric_configuration_snapshot.expects(:kalibro_ranges). | |
| 24 | + metric_result.expects(:metric_configuration).returns(metric_result.metric_configuration) | |
| 25 | + metric_configuration.expects(:kalibro_ranges). | |
| 26 | 26 | returns([range_snapshot_1_to_5, |
| 27 | 27 | range_snapshot_5dot1_to_10, |
| 28 | 28 | range_snapshot_10dot1_to_15]) | ... | ... |
spec/models/module_result_spec.rb
| ... | ... | @@ -6,20 +6,20 @@ describe ModuleResult, :type => :model do |
| 6 | 6 | |
| 7 | 7 | describe 'metric_history' do |
| 8 | 8 | let(:date_module_result) {FactoryGirl.build(:date_module_result)} |
| 9 | - let(:metric_result) { FactoryGirl.build(:metric_result, configuration: FactoryGirl.build(:metric_configuration_with_snapshot)) } | |
| 9 | + let!(:metric_result) { FactoryGirl.build(:metric_result, metric_configuration: FactoryGirl.build(:another_metric_configuration)) } | |
| 10 | 10 | let(:processing) {FactoryGirl.build(:processing)} |
| 11 | 11 | let(:repository) {FactoryGirl.build(:repository)} |
| 12 | 12 | |
| 13 | 13 | before :each do |
| 14 | 14 | subject.expects(:processing).returns(processing) |
| 15 | - metric_result.expects(:metric_configuration).returns(metric_result.configuration) | |
| 15 | + metric_result.expects(:metric_configuration).returns(metric_result.metric_configuration) | |
| 16 | 16 | processing.expects(:repository).returns(repository) |
| 17 | 17 | repository.expects(:module_result_history_of).with(subject).returns([date_module_result]) |
| 18 | 18 | ModuleResult.any_instance.expects(:metric_results).returns([metric_result]) |
| 19 | 19 | end |
| 20 | 20 | |
| 21 | 21 | it 'should return the history for the given metric name' do |
| 22 | - expect(subject.metric_history(metric_result.configuration.metric_snapshot.name)).to eq({date_module_result.date => metric_result.value}) | |
| 22 | + expect(subject.metric_history(metric_result.metric_configuration.metric.name)).to eq({date_module_result.date => metric_result.value}) | |
| 23 | 23 | end |
| 24 | 24 | end |
| 25 | 25 | end | ... | ... |