Commit 38d8bf14101b6b63bcac121580162047bfa57007
Committed by
Paulo Meireles
1 parent
8bc2bb1b
Exists in
master
and in
29 other branches
[Mezuro] Refactored duplicated code in controllers.
Showing
14 changed files
with
103 additions
and
180 deletions
Show diff stats
plugins/mezuro/controllers/myprofile/mezuro_plugin_metric_configuration_controller.rb
@@ -14,26 +14,34 @@ class MezuroPluginMetricConfigurationController < MezuroPluginMyprofileControlle | @@ -14,26 +14,34 @@ class MezuroPluginMetricConfigurationController < MezuroPluginMyprofileControlle | ||
14 | @reading_group_names_and_ids = reading_group_names_and_ids | 14 | @reading_group_names_and_ids = reading_group_names_and_ids |
15 | end | 15 | end |
16 | 16 | ||
17 | - def create_native | 17 | + def edit_native |
18 | + params_to_edit_view | ||
19 | + end | ||
20 | + | ||
21 | + def new_compound | ||
22 | + @configuration_content = profile.articles.find(params[:id]) | ||
23 | + @metric_configurations = @configuration_content.metric_configurations | ||
24 | + @reading_group_names_and_ids = reading_group_names_and_ids | ||
25 | + if configuration_content_has_errors? | ||
26 | + redirect_to_error_page @configuration_content.errors[:base] | ||
27 | + end | ||
28 | + end | ||
29 | + | ||
30 | + def edit_compound | ||
31 | + params_to_edit_view | ||
32 | + end | ||
33 | + | ||
34 | + def create | ||
18 | configuration_content = profile.articles.find(params[:id]) | 35 | configuration_content = profile.articles.find(params[:id]) |
19 | metric_configuration = Kalibro::MetricConfiguration.create(params[:metric_configuration]) | 36 | metric_configuration = Kalibro::MetricConfiguration.create(params[:metric_configuration]) |
20 | 37 | ||
21 | if metric_configuration_has_errors? metric_configuration | 38 | if metric_configuration_has_errors? metric_configuration |
22 | redirect_to_error_page metric_configuration.errors[0].message | 39 | redirect_to_error_page metric_configuration.errors[0].message |
23 | else | 40 | else |
24 | - redirect_to(metric_configuration_url(configuration_content)) | 41 | + redirect_to(metric_configuration_url(configuration_content)) |
25 | end | 42 | end |
26 | end | 43 | end |
27 | 44 | ||
28 | - def edit_native | ||
29 | - @configuration_content = profile.articles.find(params[:id]) | ||
30 | - metric_configurations = @configuration_content.metric_configurations | ||
31 | - @metric_configuration = find_metric_configuration(metric_configurations, params[:metric_configuration_id].to_i) | ||
32 | - @metric = @metric_configuration.metric | ||
33 | - @reading_group_names_and_ids = reading_group_names_and_ids | ||
34 | - @ranges = Kalibro::Range.ranges_of(@metric_configuration.id) | ||
35 | - end | ||
36 | - | ||
37 | def update | 45 | def update |
38 | @configuration_content = profile.articles.find(params[:id]) | 46 | @configuration_content = profile.articles.find(params[:id]) |
39 | metric_configurations = @configuration_content.metric_configurations | 47 | metric_configurations = @configuration_content.metric_configurations |
@@ -57,51 +65,22 @@ class MezuroPluginMetricConfigurationController < MezuroPluginMyprofileControlle | @@ -57,51 +65,22 @@ class MezuroPluginMetricConfigurationController < MezuroPluginMyprofileControlle | ||
57 | redirect_to configuration_content.view_url | 65 | redirect_to configuration_content.view_url |
58 | end | 66 | end |
59 | end | 67 | end |
60 | - | ||
61 | - def new_compound | ||
62 | - @configuration_content = profile.articles.find(params[:id]) | ||
63 | - @metric_configurations = @configuration_content.metric_configurations | ||
64 | - @reading_group_names_and_ids = reading_group_names_and_ids | ||
65 | - if configuration_content_has_errors? | ||
66 | - redirect_to_error_page @configuration_content.errors[:base] | ||
67 | - end | ||
68 | - end | ||
69 | - | ||
70 | - def create_compound | ||
71 | - configuration_content = profile.articles.find(params[:id]) | ||
72 | - metric_configuration = Kalibro::MetricConfiguration.create(params[:metric_configuration]) | ||
73 | - | ||
74 | - if metric_configuration_has_errors? metric_configuration | ||
75 | - redirect_to_error_page metric_configuration.errors[0].message | ||
76 | - else | ||
77 | - redirect_to(metric_configuration_url(configuration_content)) | ||
78 | - end | ||
79 | - end | ||
80 | - | ||
81 | - def edit_compound | ||
82 | - @configuration_content = profile.articles.find(params[:id]) | ||
83 | - @metric_configurations = @configuration_content.metric_configurations | ||
84 | - @metric_configuration = find_metric_configuration(@metric_configurations, params[:metric_configuration_id].to_i) | ||
85 | - @metric = @metric_configuration.metric | ||
86 | - @reading_group_names_and_ids = reading_group_names_and_ids | ||
87 | - @ranges = Kalibro::Range.ranges_of(@metric_configuration.id) | ||
88 | - end | ||
89 | 68 | ||
90 | private | 69 | private |
91 | - | 70 | + |
92 | def find_metric_configuration (metric_configurations, metric_configuration_id) | 71 | def find_metric_configuration (metric_configurations, metric_configuration_id) |
93 | metric_configurations.select {|metric_configuration| metric_configuration.id == metric_configuration_id }.first | 72 | metric_configurations.select {|metric_configuration| metric_configuration.id == metric_configuration_id }.first |
94 | end | 73 | end |
95 | - | 74 | + |
96 | def reading_group_names_and_ids | 75 | def reading_group_names_and_ids |
97 | array = Kalibro::ReadingGroup.all.map { |reading_group| [reading_group.name, reading_group.id] } | 76 | array = Kalibro::ReadingGroup.all.map { |reading_group| [reading_group.name, reading_group.id] } |
98 | array.sort { |x,y| x.first.downcase <=> y.first.downcase } | 77 | array.sort { |x,y| x.first.downcase <=> y.first.downcase } |
99 | end | 78 | end |
100 | - | 79 | + |
101 | def metric_configuration_has_errors? metric_configuration | 80 | def metric_configuration_has_errors? metric_configuration |
102 | not metric_configuration.errors.empty? | 81 | not metric_configuration.errors.empty? |
103 | end | 82 | end |
104 | - | 83 | + |
105 | def configuration_content_has_errors? | 84 | def configuration_content_has_errors? |
106 | not @configuration_content.errors[:base].nil? | 85 | not @configuration_content.errors[:base].nil? |
107 | end | 86 | end |
@@ -114,5 +93,14 @@ class MezuroPluginMetricConfigurationController < MezuroPluginMyprofileControlle | @@ -114,5 +93,14 @@ class MezuroPluginMetricConfigurationController < MezuroPluginMyprofileControlle | ||
114 | url[:action] = (params[:metric_configuration][:metric][:compound] ? "edit_compound" : "edit_native") | 93 | url[:action] = (params[:metric_configuration][:metric][:compound] ? "edit_compound" : "edit_native") |
115 | url | 94 | url |
116 | end | 95 | end |
117 | -end | ||
118 | 96 | ||
97 | + def params_to_edit_view | ||
98 | + @configuration_content = profile.articles.find(params[:id]) | ||
99 | + @metric_configurations = @configuration_content.metric_configurations | ||
100 | + @metric_configuration = find_metric_configuration(@metric_configurations, params[:metric_configuration_id].to_i) | ||
101 | + @metric = @metric_configuration.metric | ||
102 | + @reading_group_names_and_ids = reading_group_names_and_ids | ||
103 | + @ranges = Kalibro::Range.ranges_of(@metric_configuration.id) | ||
104 | + end | ||
105 | + | ||
106 | +end |
plugins/mezuro/controllers/myprofile/mezuro_plugin_range_controller.rb
@@ -3,44 +3,27 @@ class MezuroPluginRangeController < MezuroPluginMyprofileController | @@ -3,44 +3,27 @@ class MezuroPluginRangeController < MezuroPluginMyprofileController | ||
3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
4 | 4 | ||
5 | def new | 5 | def new |
6 | - @content_id = params[:id].to_i | ||
7 | - @metric_configuration_id = params[:metric_configuration_id].to_i | ||
8 | - @reading_labels_and_ids = reading_labels_and_ids | ||
9 | - @reading_group_id = params[:reading_group_id].to_i | ||
10 | - @compound = params[:compound] | 6 | + params_to_range_form |
7 | + params_to_redirect | ||
11 | end | 8 | end |
12 | 9 | ||
13 | def edit | 10 | def edit |
14 | - @content_id = params[:id].to_i | ||
15 | - @metric_configuration_id = params[:metric_configuration_id].to_i | 11 | + params_to_range_form |
16 | ranges = Kalibro::Range.ranges_of params[:metric_configuration_id].to_i | 12 | ranges = Kalibro::Range.ranges_of params[:metric_configuration_id].to_i |
17 | @range = (ranges.select { |range| range.id == params[:range_id].to_i }).first | 13 | @range = (ranges.select { |range| range.id == params[:range_id].to_i }).first |
18 | - @reading_labels_and_ids = reading_labels_and_ids | ||
19 | end | 14 | end |
20 | 15 | ||
21 | def create | 16 | def create |
22 | - metric_configuration_id = params[:metric_configuration_id].to_i | ||
23 | - @reading_group_id = params[:reading_group_id].to_i | ||
24 | - @compound = params[:compound] | ||
25 | - @range = Kalibro::Range.new params[:range] | ||
26 | - @range.save metric_configuration_id | ||
27 | - if !@range.errors.empty? | ||
28 | - @error = @range.errors[0].message | ||
29 | - end | 17 | + params_to_redirect |
18 | + save_range | ||
30 | end | 19 | end |
31 | 20 | ||
32 | def update | 21 | def update |
33 | - metric_configuration_id = params[:metric_configuration_id].to_i | ||
34 | - @range = Kalibro::Range.new params[:range] | ||
35 | - @range.save metric_configuration_id | ||
36 | - if !@range.errors.empty? | ||
37 | - @error = @range.errors[0].message | ||
38 | - end | 22 | + save_range |
39 | end | 23 | end |
40 | 24 | ||
41 | def remove | 25 | def remove |
42 | configuration_content = profile.articles.find(params[:id]) | 26 | configuration_content = profile.articles.find(params[:id]) |
43 | - | ||
44 | Kalibro::Range.new({:id => params[:range_id].to_i}).destroy | 27 | Kalibro::Range.new({:id => params[:range_id].to_i}).destroy |
45 | redirect_to(metric_configuration_url(configuration_content)) | 28 | redirect_to(metric_configuration_url(configuration_content)) |
46 | end | 29 | end |
@@ -61,4 +44,24 @@ class MezuroPluginRangeController < MezuroPluginMyprofileController | @@ -61,4 +44,24 @@ class MezuroPluginRangeController < MezuroPluginMyprofileController | ||
61 | array.sort { |x,y| x.first.downcase <=> y.first.downcase } | 44 | array.sort { |x,y| x.first.downcase <=> y.first.downcase } |
62 | end | 45 | end |
63 | 46 | ||
47 | + def save_range | ||
48 | + metric_configuration_id = params[:metric_configuration_id].to_i | ||
49 | + @range = Kalibro::Range.new params[:range] | ||
50 | + @range.save metric_configuration_id | ||
51 | + if !@range.errors.empty? | ||
52 | + @error = @range.errors[0].message | ||
53 | + end | ||
54 | + end | ||
55 | + | ||
56 | + def params_to_range_form | ||
57 | + @content_id = params[:id].to_i | ||
58 | + @metric_configuration_id = params[:metric_configuration_id].to_i | ||
59 | + @reading_labels_and_ids = reading_labels_and_ids | ||
60 | + end | ||
61 | + | ||
62 | + def params_to_redirect | ||
63 | + @reading_group_id = params[:reading_group_id].to_i | ||
64 | + @compound = params[:compound] | ||
65 | + end | ||
66 | + | ||
64 | end | 67 | end |
plugins/mezuro/controllers/myprofile/mezuro_plugin_reading_controller.rb
1 | class MezuroPluginReadingController < MezuroPluginMyprofileController | 1 | class MezuroPluginReadingController < MezuroPluginMyprofileController |
2 | 2 | ||
3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
4 | - | 4 | + |
5 | def new | 5 | def new |
6 | @reading_group_content = profile.articles.find(params[:id]) | 6 | @reading_group_content = profile.articles.find(params[:id]) |
7 | end | 7 | end |
8 | - | ||
9 | - def create | 8 | + |
9 | + def save | ||
10 | reading_group_content = profile.articles.find(params[:id]) | 10 | reading_group_content = profile.articles.find(params[:id]) |
11 | reading = Kalibro::Reading.new params[:reading] | 11 | reading = Kalibro::Reading.new params[:reading] |
12 | 12 | ||
@@ -22,17 +22,6 @@ class MezuroPluginReadingController < MezuroPluginMyprofileController | @@ -22,17 +22,6 @@ class MezuroPluginReadingController < MezuroPluginMyprofileController | ||
22 | @reading = Kalibro::Reading.find params[:reading_id] | 22 | @reading = Kalibro::Reading.find params[:reading_id] |
23 | end | 23 | end |
24 | 24 | ||
25 | - def update | ||
26 | - reading_group_content = profile.articles.find(params[:id]) | ||
27 | - reading = Kalibro::Reading.new params[:reading] | ||
28 | - | ||
29 | - if( reading.save(reading_group_content.reading_group_id) ) | ||
30 | - redirect_to reading_group_content.view_url | ||
31 | - else | ||
32 | - redirect_to_error_page reading.errors[0].message | ||
33 | - end | ||
34 | - end | ||
35 | - | ||
36 | def destroy | 25 | def destroy |
37 | reading_group_content = profile.articles.find(params[:id]) | 26 | reading_group_content = profile.articles.find(params[:id]) |
38 | reading = Kalibro::Reading.find params[:reading_id] | 27 | reading = Kalibro::Reading.find params[:reading_id] |
@@ -43,5 +32,5 @@ class MezuroPluginReadingController < MezuroPluginMyprofileController | @@ -43,5 +32,5 @@ class MezuroPluginReadingController < MezuroPluginMyprofileController | ||
43 | redirect_to_error_page reading.errors[0].message | 32 | redirect_to_error_page reading.errors[0].message |
44 | end | 33 | end |
45 | end | 34 | end |
46 | - | 35 | + |
47 | end | 36 | end |
plugins/mezuro/controllers/profile/mezuro_plugin_repository_controller.rb
1 | class MezuroPluginRepositoryController < MezuroPluginProfileController | 1 | class MezuroPluginRepositoryController < MezuroPluginProfileController |
2 | 2 | ||
3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
4 | - | ||
5 | - def new | ||
6 | - @project_content = profile.articles.find(params[:id]) | ||
7 | - | ||
8 | - @repository_types = Kalibro::Repository.repository_types | ||
9 | - | ||
10 | - configurations = Kalibro::Configuration.all | ||
11 | - configurations = [] if (configurations.nil?) | ||
12 | - @configuration_select = configurations.map do |configuration| | ||
13 | - [configuration.name,configuration.id] | ||
14 | - end | ||
15 | - end | ||
16 | - | ||
17 | - def create | ||
18 | - project_content = profile.articles.find(params[:id]) | ||
19 | 4 | ||
20 | - repository = Kalibro::Repository.new( params[:repository] ) | ||
21 | - repository.save(project_content.project_id) | ||
22 | - | ||
23 | - if( repository.errors.empty? ) | ||
24 | - repository.process | ||
25 | - redirect_to(repository_url(project_content)) | ||
26 | - else | ||
27 | - redirect_to_error_page repository.errors[0].message | ||
28 | - end | 5 | + def new |
6 | + params_repository_form | ||
29 | end | 7 | end |
30 | 8 | ||
31 | def edit | 9 | def edit |
32 | - @project_content = profile.articles.find(params[:id]) | ||
33 | - @repository_types = Kalibro::Repository.repository_types | ||
34 | - | ||
35 | - configurations = Kalibro::Configuration.all | ||
36 | - configurations = [] if (configurations.nil?) | ||
37 | - @configuration_select = configurations.map do |configuration| | ||
38 | - [configuration.name,configuration.id] | ||
39 | - end | ||
40 | - | 10 | + params_repository_form |
41 | @repository = @project_content.repositories.select{ |repository| repository.id.to_s == params[:repository_id] }.first | 11 | @repository = @project_content.repositories.select{ |repository| repository.id.to_s == params[:repository_id] }.first |
42 | end | 12 | end |
43 | 13 | ||
44 | - def update | 14 | + def save |
45 | project_content = profile.articles.find(params[:id]) | 15 | project_content = profile.articles.find(params[:id]) |
46 | - | 16 | + |
47 | repository = Kalibro::Repository.new( params[:repository] ) | 17 | repository = Kalibro::Repository.new( params[:repository] ) |
48 | repository.save(project_content.project_id) | 18 | repository.save(project_content.project_id) |
49 | 19 | ||
@@ -71,6 +41,8 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController | @@ -71,6 +41,8 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController | ||
71 | redirect_to_error_page repository.errors[0].message | 41 | redirect_to_error_page repository.errors[0].message |
72 | end | 42 | end |
73 | end | 43 | end |
44 | + | ||
45 | + private | ||
74 | 46 | ||
75 | def repository_url project_content | 47 | def repository_url project_content |
76 | url = project_content.view_url | 48 | url = project_content.view_url |
@@ -80,5 +52,16 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController | @@ -80,5 +52,16 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController | ||
80 | url[:action] = "show" | 52 | url[:action] = "show" |
81 | url | 53 | url |
82 | end | 54 | end |
83 | - | 55 | + |
56 | + def params_repository_form | ||
57 | + @project_content = profile.articles.find(params[:id]) | ||
58 | + @repository_types = Kalibro::Repository.repository_types | ||
59 | + | ||
60 | + configurations = Kalibro::Configuration.all | ||
61 | + configurations = [] if (configurations.nil?) | ||
62 | + @configuration_select = configurations.map do |configuration| | ||
63 | + [configuration.name,configuration.id] | ||
64 | + end | ||
65 | + end | ||
66 | + | ||
84 | end | 67 | end |
plugins/mezuro/test/functional/myprofile/mezuro_plugin_metric_configuration_controller_test.rb
@@ -14,7 +14,7 @@ class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase | @@ -14,7 +14,7 @@ class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase | ||
14 | @controller = MezuroPluginMetricConfigurationController.new | 14 | @controller = MezuroPluginMetricConfigurationController.new |
15 | @request = ActionController::TestRequest.new | 15 | @request = ActionController::TestRequest.new |
16 | @response = ActionController::TestResponse.new | 16 | @response = ActionController::TestResponse.new |
17 | - @profile = fast_create(Community) #FIXME Should be a person, not a community | 17 | + @profile = fast_create(Profile) |
18 | 18 | ||
19 | @configuration = ConfigurationFixtures.configuration | 19 | @configuration = ConfigurationFixtures.configuration |
20 | @created_configuration = ConfigurationFixtures.created_configuration | 20 | @created_configuration = ConfigurationFixtures.created_configuration |
@@ -61,12 +61,6 @@ class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase | @@ -61,12 +61,6 @@ class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase | ||
61 | assert_response :success | 61 | assert_response :success |
62 | end | 62 | end |
63 | 63 | ||
64 | - should 'create native' do | ||
65 | - Kalibro::MetricConfiguration.expects(:create).returns(@native_metric_configuration) #FIXME need .with(some_hash), should it mock the request?. | ||
66 | - get :create_native, :profile => @profile.identifier, :id => @configuration_content.id, :metric_configuration => @native_metric_configuration_hash | ||
67 | - assert_response :redirect | ||
68 | - end | ||
69 | - | ||
70 | should 'edit native' do | 64 | should 'edit native' do |
71 | Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration.id).returns([@native_metric_configuration]) | 65 | Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration.id).returns([@native_metric_configuration]) |
72 | Kalibro::ReadingGroup.expects(:all).returns([@reading_group]) | 66 | Kalibro::ReadingGroup.expects(:all).returns([@reading_group]) |
@@ -91,12 +85,6 @@ class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase | @@ -91,12 +85,6 @@ class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase | ||
91 | assert_response :success | 85 | assert_response :success |
92 | end | 86 | end |
93 | 87 | ||
94 | - should 'create compound' do | ||
95 | - Kalibro::MetricConfiguration.expects(:create).returns(@compound_metric_configuration) #FIXME need .with(some_hash), should it mock the request?. | ||
96 | - get :create_compound, :profile => @profile.identifier, :id => @configuration_content.id, :metric_configuration => @compound_metric_configuration_hash | ||
97 | - assert_response :redirect | ||
98 | - end | ||
99 | - | ||
100 | should 'edit compound' do | 88 | should 'edit compound' do |
101 | Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration.id).returns([@compound_metric_configuration]) | 89 | Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration.id).returns([@compound_metric_configuration]) |
102 | Kalibro::ReadingGroup.expects(:all).returns([@reading_group]) | 90 | Kalibro::ReadingGroup.expects(:all).returns([@reading_group]) |
@@ -112,6 +100,12 @@ class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase | @@ -112,6 +100,12 @@ class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase | ||
112 | assert_response :success | 100 | assert_response :success |
113 | end | 101 | end |
114 | 102 | ||
103 | + should 'create' do | ||
104 | + Kalibro::MetricConfiguration.expects(:create).returns(@compound_metric_configuration) #FIXME need .with(some_hash), should it mock the request?. | ||
105 | + get :create, :profile => @profile.identifier, :id => @configuration_content.id, :metric_configuration => @compound_metric_configuration_hash | ||
106 | + assert_response :redirect | ||
107 | + end | ||
108 | + | ||
115 | should 'update' do | 109 | should 'update' do |
116 | Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration_content.configuration_id).returns([@native_metric_configuration]) | 110 | Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration_content.configuration_id).returns([@native_metric_configuration]) |
117 | @native_metric_configuration.expects(:update_attributes).returns(true) #FIXME need .with(some_hash), should it mock the request?. | 111 | @native_metric_configuration.expects(:update_attributes).returns(true) #FIXME need .with(some_hash), should it mock the request?. |
plugins/mezuro/test/functional/myprofile/mezuro_plugin_range_controller_test.rb
@@ -12,7 +12,7 @@ class MezuroPluginRangeControllerTest < ActionController::TestCase | @@ -12,7 +12,7 @@ class MezuroPluginRangeControllerTest < ActionController::TestCase | ||
12 | @controller = MezuroPluginRangeController.new | 12 | @controller = MezuroPluginRangeController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
14 | @response = ActionController::TestResponse.new | 14 | @response = ActionController::TestResponse.new |
15 | - @profile = fast_create(Community) | 15 | + @profile = fast_create(Profile) |
16 | 16 | ||
17 | @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration | 17 | @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration |
18 | @metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash | 18 | @metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash |
plugins/mezuro/test/functional/myprofile/mezuro_plugin_reading_controller_test.rb
@@ -9,7 +9,7 @@ class MezuroPluginReadingControllerTest < ActionController::TestCase | @@ -9,7 +9,7 @@ class MezuroPluginReadingControllerTest < ActionController::TestCase | ||
9 | @controller = MezuroPluginReadingController.new | 9 | @controller = MezuroPluginReadingController.new |
10 | @request = ActionController::TestRequest.new | 10 | @request = ActionController::TestRequest.new |
11 | @response = ActionController::TestResponse.new | 11 | @response = ActionController::TestResponse.new |
12 | - @profile = fast_create(Community) | 12 | + @profile = fast_create(Profile) |
13 | 13 | ||
14 | @reading = ReadingFixtures.reading | 14 | @reading = ReadingFixtures.reading |
15 | @created_reading = ReadingFixtures.created_reading | 15 | @created_reading = ReadingFixtures.created_reading |
@@ -29,7 +29,7 @@ class MezuroPluginReadingControllerTest < ActionController::TestCase | @@ -29,7 +29,7 @@ class MezuroPluginReadingControllerTest < ActionController::TestCase | ||
29 | should 'create a reading' do | 29 | should 'create a reading' do |
30 | Kalibro::Reading.expects(:new).with(@reading_hash.to_s).returns(@created_reading) | 30 | Kalibro::Reading.expects(:new).with(@reading_hash.to_s).returns(@created_reading) |
31 | @created_reading.expects(:save).with(@content.reading_group_id).returns(true) | 31 | @created_reading.expects(:save).with(@content.reading_group_id).returns(true) |
32 | - get :create, :profile => @profile.identifier, :id => @content.id, :reading => @reading_hash | 32 | + get :save, :profile => @profile.identifier, :id => @content.id, :reading => @reading_hash |
33 | assert @created_reading.errors.empty? | 33 | assert @created_reading.errors.empty? |
34 | assert_response :redirect | 34 | assert_response :redirect |
35 | end | 35 | end |
@@ -38,7 +38,7 @@ class MezuroPluginReadingControllerTest < ActionController::TestCase | @@ -38,7 +38,7 @@ class MezuroPluginReadingControllerTest < ActionController::TestCase | ||
38 | @created_reading.errors = [Exception.new] | 38 | @created_reading.errors = [Exception.new] |
39 | Kalibro::Reading.expects(:new).with(@reading_hash.to_s).returns(@created_reading) | 39 | Kalibro::Reading.expects(:new).with(@reading_hash.to_s).returns(@created_reading) |
40 | @created_reading.expects(:save).with(@content.reading_group_id).returns(false) | 40 | @created_reading.expects(:save).with(@content.reading_group_id).returns(false) |
41 | - get :create, :profile => @profile.identifier, :id => @content.id, :reading => @reading_hash | 41 | + get :save, :profile => @profile.identifier, :id => @content.id, :reading => @reading_hash |
42 | assert !@created_reading.errors.empty? | 42 | assert !@created_reading.errors.empty? |
43 | assert_response :redirect | 43 | assert_response :redirect |
44 | end | 44 | end |
@@ -51,22 +51,6 @@ class MezuroPluginReadingControllerTest < ActionController::TestCase | @@ -51,22 +51,6 @@ class MezuroPluginReadingControllerTest < ActionController::TestCase | ||
51 | assert_response :success | 51 | assert_response :success |
52 | end | 52 | end |
53 | 53 | ||
54 | - should 'update a reading' do | ||
55 | - Kalibro::Reading.expects(:new).with(@reading_hash.to_s).returns(@reading) | ||
56 | - @reading.expects(:save).with(@content.reading_group_id).returns(true) | ||
57 | - get :update, :profile => @profile.identifier, :id => @content.id, :reading => @reading_hash | ||
58 | - assert @reading.errors.empty? | ||
59 | - assert_response :redirect | ||
60 | - end | ||
61 | - | ||
62 | - should 'put an Exception in reading when an error occurs in update action' do | ||
63 | - @reading.errors = [Exception.new] | ||
64 | - Kalibro::Reading.expects(:new).with(@reading_hash.to_s).returns(@reading) | ||
65 | - @reading.expects(:save).with(@content.reading_group_id).returns(false) | ||
66 | - get :update, :profile => @profile.identifier, :id => @content.id, :reading => @reading_hash | ||
67 | - assert_response :redirect | ||
68 | - end | ||
69 | - | ||
70 | should 'destroy a reading' do | 54 | should 'destroy a reading' do |
71 | @reading.expects(:destroy) | 55 | @reading.expects(:destroy) |
72 | Kalibro::Reading.expects(:find).with(@reading.id.to_s).returns(@reading) | 56 | Kalibro::Reading.expects(:find).with(@reading.id.to_s).returns(@reading) |
plugins/mezuro/test/functional/profile/mezuro_plugin_repository_controller_test.rb
@@ -38,20 +38,20 @@ class MezuroPluginRepositoryControllerTest < ActionController::TestCase | @@ -38,20 +38,20 @@ class MezuroPluginRepositoryControllerTest < ActionController::TestCase | ||
38 | assert_response :success | 38 | assert_response :success |
39 | end | 39 | end |
40 | 40 | ||
41 | - should 'create a repository' do | 41 | + should 'save a repository' do |
42 | Kalibro::Repository.expects(:new).returns(@repository) | 42 | Kalibro::Repository.expects(:new).returns(@repository) |
43 | @repository.expects(:save).with(@content.project_id).returns(true) | 43 | @repository.expects(:save).with(@content.project_id).returns(true) |
44 | @repository.expects(:process) | 44 | @repository.expects(:process) |
45 | - get :create, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash | 45 | + get :save, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash |
46 | assert @repository.errors.empty? | 46 | assert @repository.errors.empty? |
47 | assert_response :redirect | 47 | assert_response :redirect |
48 | end | 48 | end |
49 | 49 | ||
50 | - should 'not create a repository' do | 50 | + should 'not save a repository' do |
51 | @repository.errors = [Exception.new] | 51 | @repository.errors = [Exception.new] |
52 | Kalibro::Repository.expects(:new).returns(@repository) | 52 | Kalibro::Repository.expects(:new).returns(@repository) |
53 | @repository.expects(:save).with(@content.project_id).returns(false) | 53 | @repository.expects(:save).with(@content.project_id).returns(false) |
54 | - get :create, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash | 54 | + get :save, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash |
55 | assert !@repository.errors.empty? | 55 | assert !@repository.errors.empty? |
56 | assert_response :redirect | 56 | assert_response :redirect |
57 | end | 57 | end |
@@ -71,24 +71,6 @@ class MezuroPluginRepositoryControllerTest < ActionController::TestCase | @@ -71,24 +71,6 @@ class MezuroPluginRepositoryControllerTest < ActionController::TestCase | ||
71 | assert_response :success | 71 | assert_response :success |
72 | end | 72 | end |
73 | 73 | ||
74 | - should 'update a repository' do | ||
75 | - Kalibro::Repository.expects(:new).returns(@repository) | ||
76 | - @repository.expects(:save).with(@content.project_id).returns(true) | ||
77 | - Kalibro::Repository.expects(:request).with(:process_repository, {:repository_id => @repository.id}) | ||
78 | - get :update, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash | ||
79 | - assert @repository.errors.empty? | ||
80 | - assert_response :redirect | ||
81 | - end | ||
82 | - | ||
83 | - should 'not update a repository' do | ||
84 | - @repository.errors = [Exception.new] | ||
85 | - Kalibro::Repository.expects(:new).returns(@repository) | ||
86 | - @repository.expects(:save).with(@content.project_id).returns(false) | ||
87 | - get :update, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash | ||
88 | - assert !@repository.errors.empty? | ||
89 | - assert_response :redirect | ||
90 | - end | ||
91 | - | ||
92 | should 'set variables to show a repository' do | 74 | should 'set variables to show a repository' do |
93 | Kalibro::Repository.expects(:repositories_of).with(@content.project_id).returns([@repository]) | 75 | Kalibro::Repository.expects(:repositories_of).with(@content.project_id).returns([@repository]) |
94 | Kalibro::Configuration.expects(:configuration_of).with(@repository.id).returns(@configuration) | 76 | Kalibro::Configuration.expects(:configuration_of).with(@repository.id).returns(@configuration) |
plugins/mezuro/views/mezuro_plugin_metric_configuration/new_compound.html.erb
1 | <h2><%= link_to("#{@configuration_content.name} Configuration", @configuration_content.view_url) %></h2> | 1 | <h2><%= link_to("#{@configuration_content.name} Configuration", @configuration_content.view_url) %></h2> |
2 | 2 | ||
3 | -<% form_for :metric_configuration, :url => {:action =>"create_compound", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %> | 3 | +<% form_for :metric_configuration, :url => {:action =>"create", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %> |
4 | <%= hidden_field_tag :id, @configuration_content.id %> | 4 | <%= hidden_field_tag :id, @configuration_content.id %> |
5 | <%= f.hidden_field :configuration_id, :value => @configuration_content.configuration_id %> | 5 | <%= f.hidden_field :configuration_id, :value => @configuration_content.configuration_id %> |
6 | 6 |
plugins/mezuro/views/mezuro_plugin_metric_configuration/new_native.html.erb
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | <h2><%= link_to("#{@configuration_content.name} Configuration", @configuration_content.view_url) %></h2> | 3 | <h2><%= link_to("#{@configuration_content.name} Configuration", @configuration_content.view_url) %></h2> |
4 | <!-- TODO This form should be a partial similar to _native_metric_configuration_form.rhtml --> | 4 | <!-- TODO This form should be a partial similar to _native_metric_configuration_form.rhtml --> |
5 | -<% form_for :metric_configuration, :url => {:action =>"create_native", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %> | 5 | +<% form_for :metric_configuration, :url => {:action =>"create", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %> |
6 | 6 | ||
7 | <%= hidden_field_tag :id, @configuration_content.id %> | 7 | <%= hidden_field_tag :id, @configuration_content.id %> |
8 | <%= f.hidden_field :configuration_id, :value => @configuration_content.configuration_id %> | 8 | <%= f.hidden_field :configuration_id, :value => @configuration_content.configuration_id %> |
plugins/mezuro/views/mezuro_plugin_reading/edit.html.erb
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | <script src="/javascripts/colorpicker-noosfero.js" type="text/javascript"></script> | 2 | <script src="/javascripts/colorpicker-noosfero.js" type="text/javascript"></script> |
3 | <h2><%= link_to("#{@reading_group_content.name} Reading Group", @reading_group_content.view_url) %></h2> | 3 | <h2><%= link_to("#{@reading_group_content.name} Reading Group", @reading_group_content.view_url) %></h2> |
4 | 4 | ||
5 | -<% form_for :reading, :url => {:action =>"update", :controller => "mezuro_plugin_reading"}, :method => :get do |f| %> | 5 | +<% form_for :reading, :url => {:action =>"save", :controller => "mezuro_plugin_reading"}, :method => :get do |f| %> |
6 | <%= hidden_field_tag :id, @reading_group_content.id %> | 6 | <%= hidden_field_tag :id, @reading_group_content.id %> |
7 | 7 | ||
8 | <%= f.hidden_field :id %> | 8 | <%= f.hidden_field :id %> |
plugins/mezuro/views/mezuro_plugin_reading/new.html.erb
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | <script src="/javascripts/colorpicker-noosfero.js" type="text/javascript"></script> | 2 | <script src="/javascripts/colorpicker-noosfero.js" type="text/javascript"></script> |
3 | <h2><%= link_to("#{@reading_group_content.name} Reading Group", @reading_group_content.view_url) %></h2> | 3 | <h2><%= link_to("#{@reading_group_content.name} Reading Group", @reading_group_content.view_url) %></h2> |
4 | 4 | ||
5 | -<% form_for :reading, :url => {:action =>"create", :controller => "mezuro_plugin_reading"}, :method => :get do |f| %> | 5 | +<% form_for :reading, :url => {:action =>"save", :controller => "mezuro_plugin_reading"}, :method => :get do |f| %> |
6 | <%= hidden_field_tag :id, @reading_group_content.id %> | 6 | <%= hidden_field_tag :id, @reading_group_content.id %> |
7 | 7 | ||
8 | <%= required labelled_form_field _('label:'), f.text_field(:label) %> | 8 | <%= required labelled_form_field _('label:'), f.text_field(:label) %> |
plugins/mezuro/views/mezuro_plugin_repository/edit.html.erb
1 | <h2><%= link_to("#{@project_content.name} Project", @project_content.view_url) %></h2> | 1 | <h2><%= link_to("#{@project_content.name} Project", @project_content.view_url) %></h2> |
2 | 2 | ||
3 | -<% form_for :repository, :url => {:action =>"update", :controller => "mezuro_plugin_repository"}, :method => :get do |f| %> | 3 | +<% form_for :repository, :url => {:action =>"save", :controller => "mezuro_plugin_repository"}, :method => :get do |f| %> |
4 | <%= hidden_field_tag :id, @project_content.id %> | 4 | <%= hidden_field_tag :id, @project_content.id %> |
5 | 5 | ||
6 | <%= f.hidden_field :id%> | 6 | <%= f.hidden_field :id%> |
plugins/mezuro/views/mezuro_plugin_repository/new.html.erb
1 | <h2><%= link_to("#{@project_content.name} Project", @project_content.view_url) %></h2> | 1 | <h2><%= link_to("#{@project_content.name} Project", @project_content.view_url) %></h2> |
2 | 2 | ||
3 | -<% form_for :repository, :url => {:action =>"create", :controller => "mezuro_plugin_repository"}, :method => :get do |f| %> | 3 | +<% form_for :repository, :url => {:action =>"save", :controller => "mezuro_plugin_repository"}, :method => :get do |f| %> |
4 | <%= hidden_field_tag :id, @project_content.id %> | 4 | <%= hidden_field_tag :id, @project_content.id %> |
5 | 5 | ||
6 | <%= required labelled_form_field _('Name:'), f.text_field(:name) %> | 6 | <%= required labelled_form_field _('Name:'), f.text_field(:name) %> |