Commit d0e696d4d24aee488391226d7bc3cbd82722b03f
Exists in
colab
and in
4 other branches
Merge pull request #176 from mezuro/fixing_tests
Fixed compound metric test and added a test for supported_metrics_of
Showing
2 changed files
with
35 additions
and
25 deletions
Show diff stats
spec/controllers/compound_metric_configurations_controller_spec.rb
| @@ -31,40 +31,38 @@ describe CompoundMetricConfigurationsController, :type => :controller do | @@ -31,40 +31,38 @@ describe CompoundMetricConfigurationsController, :type => :controller do | ||
| 31 | end | 31 | end |
| 32 | 32 | ||
| 33 | describe 'create' do | 33 | describe 'create' do |
| 34 | - pending 'waiting for metric on kalibro_client' do | ||
| 35 | - let!(:metric_configuration_params) { Hash[FactoryGirl.attributes_for(:metric_configuration, metric_snapshot_id: 42).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 | ||
| 36 | - 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 | ||
| 37 | - let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration) } | 34 | + let!(:metric_configuration_params) { FactoryGirl.build(:metric_configuration).to_hash } |
| 35 | + let!(:metric_params) { FactoryGirl.build(:metric).to_hash } | ||
| 36 | + let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration) } | ||
| 38 | 37 | ||
| 39 | - before do | ||
| 40 | - sign_in FactoryGirl.create(:user) | ||
| 41 | - metric_configuration_params["metric"] = metric_params | 38 | + before do |
| 39 | + sign_in FactoryGirl.create(:user) | ||
| 40 | + metric_configuration_params["metric"] = metric_params | ||
| 41 | + end | ||
| 42 | + | ||
| 43 | + context 'when the current user owns the reading group' do | ||
| 44 | + before :each do | ||
| 45 | + subject.expects(:kalibro_configuration_owner?).returns true | ||
| 42 | end | 46 | end |
| 43 | 47 | ||
| 44 | - context 'when the current user owns the reading group' do | 48 | + context 'with valid fields' do |
| 45 | before :each do | 49 | before :each do |
| 46 | - subject.expects(:kalibro_configuration_owner?).returns true | ||
| 47 | - end | ||
| 48 | - | ||
| 49 | - context 'with valid fields' do | ||
| 50 | - before :each do | ||
| 51 | - MetricConfiguration.any_instance.expects(:save).returns(true) | 50 | + MetricConfiguration.any_instance.expects(:save).returns(true) |
| 52 | 51 | ||
| 53 | - post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params | ||
| 54 | - end | ||
| 55 | - | ||
| 56 | - it { is_expected.to respond_with(:redirect) } | 52 | + post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params |
| 57 | end | 53 | end |
| 58 | 54 | ||
| 59 | - context 'with invalid fields' do | ||
| 60 | - before :each do | ||
| 61 | - MetricConfiguration.any_instance.expects(:save).returns(false) | ||
| 62 | - MetricConfiguration.expects(:metric_configurations_of).with(kalibro_configuration.id).returns([compound_metric_configuration]) | ||
| 63 | - post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params | ||
| 64 | - end | 55 | + it { is_expected.to respond_with(:redirect) } |
| 56 | + end | ||
| 65 | 57 | ||
| 66 | - it { is_expected.to render_template(:new) } | 58 | + context 'with invalid fields' do |
| 59 | + before :each do | ||
| 60 | + MetricConfiguration.any_instance.expects(:save).returns(false) | ||
| 61 | + MetricConfiguration.expects(:metric_configurations_of).with(kalibro_configuration.id).returns([compound_metric_configuration]) | ||
| 62 | + post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params | ||
| 67 | end | 63 | end |
| 64 | + | ||
| 65 | + it { is_expected.to render_template(:new) } | ||
| 68 | end | 66 | end |
| 69 | end | 67 | end |
| 70 | end | 68 | end |
spec/helpers/metric_configurations_helper_spec.rb
| @@ -31,4 +31,16 @@ describe MetricConfigurationsHelper, :type => :helper do | @@ -31,4 +31,16 @@ describe MetricConfigurationsHelper, :type => :helper do | ||
| 31 | expect(helper.native_metrics_of(metric_configuration.kalibro_configuration_id)).to eq [[metric_configuration.metric.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 | end | 32 | end |
| 33 | end | 33 | end |
| 34 | + | ||
| 35 | + describe 'supported_metrics_of' do | ||
| 36 | + let(:metric_collector_details) { FactoryGirl.build(:metric_collector) } | ||
| 37 | + | ||
| 38 | + before :each do | ||
| 39 | + KalibroClient::Entities::Processor::MetricCollectorDetails.expects(:find_by_name).with(metric_collector_details.name).returns(metric_collector_details) | ||
| 40 | + end | ||
| 41 | + | ||
| 42 | + it 'should return a list of the supported metrics' do | ||
| 43 | + expect(helper.supported_metrics_of(metric_collector_details.name)).to eq(metric_collector_details.supported_metrics) | ||
| 44 | + end | ||
| 45 | + end | ||
| 34 | end | 46 | end |