Commit 6d8f5022b712df7c0050c2de5e038f3ec2fd7e44
Committed by
Paulo Meireles
1 parent
b36660ac
Exists in
master
and in
29 other branches
[Mezuro] Tests for metric configuration.
Showing
2 changed files
with
17 additions
and
17 deletions
Show diff stats
plugins/mezuro/controllers/myprofile/mezuro_plugin_metric_configuration_controller.rb
... | ... | @@ -15,8 +15,7 @@ class MezuroPluginMetricConfigurationController < MezuroPluginMyprofileControlle |
15 | 15 | end |
16 | 16 | |
17 | 17 | def create_native |
18 | - metric_configuration = Kalibro::MetricConfiguration.new(params[:metric_configuration]) | |
19 | - metric_configuration.save | |
18 | + metric_configuration = Kalibro::MetricConfiguration.create(params[:metric_configuration]) | |
20 | 19 | |
21 | 20 | if metric_configuration_has_errors? metric_configuration |
22 | 21 | redirect_to_error_page metric_configuration.errors[0].message | ... | ... |
plugins/mezuro/test/functional/myprofile/mezuro_plugin_metric_configuration_controller_test.rb
... | ... | @@ -5,6 +5,8 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_fixtures" |
5 | 5 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" |
6 | 6 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" |
7 | 7 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_group_fixtures" |
8 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" | |
9 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_fixtures" | |
8 | 10 | |
9 | 11 | class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase |
10 | 12 | |
... | ... | @@ -30,6 +32,8 @@ class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase |
30 | 32 | @metric = MetricFixtures.amloc |
31 | 33 | |
32 | 34 | @reading_group = ReadingGroupFixtures.reading_group |
35 | + @range = RangeFixtures.range | |
36 | + @reading = ReadingFixtures.reading | |
33 | 37 | |
34 | 38 | @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration |
35 | 39 | @metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash |
... | ... | @@ -41,8 +45,8 @@ class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase |
41 | 45 | |
42 | 46 | @native_hash = @metric_configuration.to_hash.merge({:configuration_name => @metric_configuration.configuration_name}) |
43 | 47 | @native_hash.delete :attributes! |
44 | - @compound_hash = @compound_metric_configuration.to_hash.merge({:configuration_name => @compound_metric_configuration.configuration_name}) | |
45 | 48 | @compound_hash.delete :attributes! |
49 | + @compound_hash = @compound_metric_configuration.to_hash.merge({:configuration_name => @compound_metric_configuration.configuration_name}) | |
46 | 50 | =end |
47 | 51 | end |
48 | 52 | |
... | ... | @@ -51,7 +55,7 @@ class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase |
51 | 55 | get :choose_metric, :profile => @profile.identifier, :id => @configuration_content.id |
52 | 56 | assert_equal @configuration_content, assigns(:configuration_content) |
53 | 57 | assert_equal [@base_tool], assigns(:base_tools) |
54 | - assert_response 200 | |
58 | + assert_response :success | |
55 | 59 | end |
56 | 60 | |
57 | 61 | should 'initialize native' do |
... | ... | @@ -62,40 +66,37 @@ class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase |
62 | 66 | assert_equal @metric.name, assigns(:metric).name |
63 | 67 | assert_equal @base_tool.name, assigns(:base_tool_name) |
64 | 68 | assert_equal [[@reading_group.name,@reading_group.id]], assigns(:reading_group_names_and_ids) |
65 | - assert_response 200 | |
69 | + assert_response :success | |
66 | 70 | end |
67 | 71 | |
68 | 72 | should 'create native' do |
69 | - #Kalibro::MetricConfiguration.expects(:new).returns(@created_metric_configuration) #FIXME need .with(some_hash). | |
70 | - #@created_metric_configuration.expects(:save).returns(true) | |
71 | -=begin | |
72 | - #TODO ARRUMAR ESTE TESTE!!! | |
73 | - Kalibro::MetricConfiguration.expects(:request).with(:save_metric_configuration, {:metric_configuration => @metric_configuration.to_hash, :configuration_id => @configuration_content.configuration_id}).returns(@metric_configuration.id) | |
73 | + Kalibro::MetricConfiguration.expects(:create).returns(@created_metric_configuration) #FIXME need .with(some_hash), should it mock the request?. | |
74 | 74 | get :create_native, :profile => @profile.identifier, :id => @configuration_content.id, :metric_configuration => @metric_configuration_hash |
75 | - assert_response 200 | |
76 | -=end | |
75 | + assert_response :redirect | |
77 | 76 | end |
78 | 77 | |
79 | 78 | should 'edit native' do |
80 | 79 | Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration.id).returns([@metric_configuration]) |
81 | 80 | Kalibro::ReadingGroup.expects(:all).returns([@reading_group]) |
81 | + Kalibro::Range.expects(:ranges_of).with(@metric_configuration.id).returns([@range]) | |
82 | + Kalibro::Reading.expects(:find).with(@range.reading_id).returns(@reading) | |
82 | 83 | get :edit_native, :profile => @profile.identifier, :id => @configuration_content.id, :metric_configuration_id => @metric_configuration.id |
83 | 84 | assert_equal @configuration_content, assigns(:configuration_content) |
84 | 85 | assert_equal @metric_configuration.code, assigns(:metric_configuration).code |
85 | 86 | assert_equal @metric_configuration.metric.name, assigns(:metric).name |
86 | 87 | assert_equal [[@reading_group.name,@reading_group.id]], assigns(:reading_group_names_and_ids) |
87 | - assert_response 200 | |
88 | + assert_equal [@range], assigns(:ranges) | |
89 | + assert_response :success | |
88 | 90 | end |
89 | 91 | |
90 | 92 | should 'initialize compound' do |
91 | 93 | Kalibro::ReadingGroup.expects(:all).returns([@reading_group]) |
94 | + Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration_content.configuration_id).returns([@compound_metric_configuration]) | |
92 | 95 | get :new_compound, :profile => @profile.identifier, :id => @configuration_content.id |
93 | 96 | assert_equal @configuration_content, assigns(:configuration_content) |
94 | - #FIXME mock is not working. configuration_id is not being set. | |
95 | - #MezuroPlugin::ConfigurationContent.expects(:metric_configurations).returns([@compound_metric_configuration]) | |
96 | - #assert_equal @compound_metric_configuration.code, assigns(:metric_configurations).first.code | |
97 | + assert_equal @compound_metric_configuration.code, assigns(:metric_configurations).first.code | |
97 | 98 | assert_equal [[@reading_group.name,@reading_group.id]], assigns(:reading_group_names_and_ids) |
98 | - assert_response 200 | |
99 | + assert_response :success | |
99 | 100 | end |
100 | 101 | |
101 | 102 | should 'create compound' do | ... | ... |