Commit 922a3b8e9d1ad46c23f31a44e7521d6a136a7313
Committed by
Diego Martinez
1 parent
998035d2
Exists in
master
and in
29 other branches
Ignore this commit
Showing
3 changed files
with
104 additions
and
60 deletions
Show diff stats
plugins/mezuro/controllers/profile/mezuro_plugin_repository_controller.rb
... | ... | @@ -37,7 +37,7 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController |
37 | 37 | @configuration_select = configurations.map do |configuration| |
38 | 38 | [configuration.name,configuration.id] |
39 | 39 | end |
40 | - @repository = @project_content.repositories.select{ |repository| repository.id == params[:repository_id].to_s }.first | |
40 | + @repository = @project_content.repositories.select{ |repository| repository.id.to_s == params[:repository_id] }.first | |
41 | 41 | end |
42 | 42 | |
43 | 43 | def update |
... | ... | @@ -57,7 +57,7 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController |
57 | 57 | project_content = profile.articles.find(params[:id]) |
58 | 58 | @project_name = project_content.name |
59 | 59 | @repository = project_content.repositories.select{ |repository| repository.id == params[:repository_id].to_s }.first |
60 | - @configuration_name = Kalibro::Configuration.find(@repository.configuration_id).name | |
60 | + @configuration_name = Kalibro::Configuration.configuration_of(@repository.id).name | |
61 | 61 | @processing = processing(@repository.id) |
62 | 62 | end |
63 | 63 | |
... | ... | @@ -74,32 +74,6 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController |
74 | 74 | |
75 | 75 | private |
76 | 76 | |
77 | - def processing(repository_id) | |
78 | - begin | |
79 | - if Kalibro::Processing.has_ready_processing(repository_id) | |
80 | - @processing ||= Kalibro::Processing.last_ready_processing_of(repository_id) | |
81 | - else | |
82 | - @processing = Kalibro::Processing.last_processing_of(repository_id) | |
83 | - end | |
84 | - rescue Exception => error | |
85 | - errors.add_to_base(error.message) | |
86 | - end | |
87 | - @processing | |
88 | - end | |
89 | - | |
90 | - def processing_with_date(repository_id, date) | |
91 | - begin | |
92 | - if Kalibro::Processing.has_processing_after(repository_id, date) | |
93 | - @processing ||= Kalibro::Processing.first_processing_after(repository_id, date) | |
94 | - elsif Kalibro::Processing.has_processing_before(repository_id, date) | |
95 | - @processing ||= Kalibro::Processing.last_processing_before(repository_id, date) | |
96 | - end | |
97 | - rescue Exception => error | |
98 | - errors.add_to_base(error.message) | |
99 | - end | |
100 | - @processing | |
101 | - end | |
102 | - | |
103 | 77 | def module_result(repository_id, date = nil) |
104 | 78 | @processing ||= date.nil? ? processing(repository_id) : processing_with_date(repository_id, date) |
105 | 79 | begin | ... | ... |
plugins/mezuro/lib/kalibro/processing.rb
... | ... | @@ -2,6 +2,42 @@ class Kalibro::Processing < Kalibro::Model |
2 | 2 | |
3 | 3 | attr_accessor :id, :date, :state, :error, :process_time, :results_root_id |
4 | 4 | |
5 | + def self.processing_of(repository_id) | |
6 | + if has_ready_processing(repository_id) | |
7 | + last_ready_processing_of(repository_id) | |
8 | + else | |
9 | + last_processing_of(repository_id) | |
10 | + end | |
11 | + end | |
12 | + | |
13 | + def self.processing_with_date_of(repository_id, date) | |
14 | + if has_processing_after(repository_id, date) | |
15 | + first_processing_after(repository_id, date) | |
16 | + elsif has_processing_before(repository_id, date) | |
17 | + last_processing_before(repository_id, date) | |
18 | + else | |
19 | + last_processing_of(repository_id) | |
20 | + end | |
21 | + end | |
22 | + | |
23 | + def date=(value) | |
24 | + @date = value.is_a?(String) ? DateTime.parse(value) : value | |
25 | + end | |
26 | + | |
27 | + def process_times=(value) | |
28 | + process_time=value | |
29 | + end | |
30 | + | |
31 | + def process_time=(value) | |
32 | + @process_time = Kalibro::ProcessTime.to_objects_array value | |
33 | + end | |
34 | + | |
35 | + def process_times | |
36 | + process_time | |
37 | + end | |
38 | + | |
39 | + private | |
40 | + | |
5 | 41 | def self.has_processing(repository_id) |
6 | 42 | request(:has_processing, {:repository_id => repository_id})[:exists] |
7 | 43 | end |
... | ... | @@ -42,20 +78,4 @@ class Kalibro::Processing < Kalibro::Model |
42 | 78 | new request(:last_processing_before, {:repository_id => repository_id, :date => date})[:processing] |
43 | 79 | end |
44 | 80 | |
45 | - def date=(value) | |
46 | - @date = value.is_a?(String) ? DateTime.parse(value) : value | |
47 | - end | |
48 | - | |
49 | - def process_times=(value) | |
50 | - process_time=value | |
51 | - end | |
52 | - | |
53 | - def process_time=(value) | |
54 | - @process_time = Kalibro::ProcessTime.to_objects_array value | |
55 | - end | |
56 | - | |
57 | - def process_times | |
58 | - process_time | |
59 | - end | |
60 | - | |
61 | 81 | end | ... | ... |
plugins/mezuro/test/functional/profile/mezuro_plugin_repository_controller_test.rb
... | ... | @@ -14,6 +14,9 @@ class MezuroPluginRepositoryControllerTest < ActionController::TestCase |
14 | 14 | @response = ActionController::TestResponse.new |
15 | 15 | @profile = fast_create(Community) |
16 | 16 | |
17 | + @configuration = ConfigurationFixtures.configuration | |
18 | + @repository_types = RepositoryFixtures.types | |
19 | + @all_configurations = ConfigurationFixtures.all | |
17 | 20 | @repository = RepositoryFixtures.repository |
18 | 21 | @repository_hash = RepositoryFixtures.hash |
19 | 22 | @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => name) |
... | ... | @@ -22,28 +25,75 @@ class MezuroPluginRepositoryControllerTest < ActionController::TestCase |
22 | 25 | @content.save |
23 | 26 | end |
24 | 27 | |
25 | - should 'provide the correct variables to the "new" view' do | |
26 | - repository_types = RepositoryFixtures.types | |
27 | - all_configurations = ConfigurationFixtures.all | |
28 | - Kalibro::Repository.expects(:repository_types).returns(repository_types) | |
29 | - Kalibro::Configuration.expects(:all).returns(all_configurations) | |
28 | + should 'set variables to create a new repository' do | |
29 | + Kalibro::Repository.expects(:repository_types).returns(@repository_types) | |
30 | + Kalibro::Configuration.expects(:all).returns(@all_configurations) | |
30 | 31 | |
31 | 32 | get :new, :profile => @profile.identifier, :id => @content.id |
32 | 33 | |
33 | - #assert_equal @content, assigns(:project_content) | |
34 | - assert_equal repository_types, assigns(:repository_types) | |
35 | - assert_equal all_configurations.first.name, assigns(:configuration_select).first.first | |
36 | - assert_equal all_configurations.first.id, assigns(:configuration_select).first.last | |
34 | + assert_equal @content, assigns(:project_content) | |
35 | + assert_equal @repository_types, assigns(:repository_types) | |
36 | + assert_equal @all_configurations.first.name, assigns(:configuration_select).first.first | |
37 | + assert_equal @all_configurations.first.id, assigns(:configuration_select).first.last | |
37 | 38 | end |
38 | 39 | |
39 | - should 'create a repository and redirect correctly' do | |
40 | - Kalibro::Repository.expects(:new).returns(@repository) | |
41 | - @repository.expects(:save).with(@content.project_id).returns(true) | |
42 | - get :create, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash | |
43 | - assert @repository.errors.empty? | |
44 | - assert_response :redirect | |
45 | - assert_select('h5', 'Repositories') | |
40 | + should 'create a repository' do | |
41 | + Kalibro::Repository.expects(:new).returns(@repository) | |
42 | + @repository.expects(:save).with(@content.project_id).returns(true) | |
43 | + get :create, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash | |
44 | + assert @repository.errors.empty? | |
45 | + assert_response :redirect | |
46 | 46 | end |
47 | 47 | |
48 | + should 'not create a repository' do | |
49 | + @repository.errors = [Exception.new] | |
50 | + Kalibro::Repository.expects(:new).returns(@repository) | |
51 | + @repository.expects(:save).with(@content.project_id).returns(false) | |
52 | + get :create, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash | |
53 | + assert !@repository.errors.empty? | |
54 | + assert_response :redirect | |
55 | + end | |
56 | + | |
57 | + should 'set variables to edit a repository' do | |
58 | + articles = mock | |
59 | + Kalibro::Repository.expects(:repository_types).returns(@repository_types) | |
60 | + Kalibro::Configuration.expects(:all).returns(@all_configurations) | |
61 | + Kalibro::Repository.expects(:repositories_of).with(@content.project_id).returns([@repository]) | |
62 | + | |
63 | + get :edit, :profile => @profile.identifier, :id => @content.id, :repository_id => @repository.id | |
64 | + | |
65 | + assert_equal @content, assigns(:project_content) | |
66 | + assert_equal @repository_types, assigns(:repository_types) | |
67 | + assert_equal @all_configurations.first.name, assigns(:configuration_select).first.first | |
68 | + assert_equal @all_configurations.first.id, assigns(:configuration_select).first.last | |
69 | + assert_equal @repository, assigns(:repository) | |
70 | + end | |
71 | + | |
72 | + should 'update a repository' do | |
73 | + Kalibro::Repository.expects(:new).returns(@repository) | |
74 | + @repository.expects(:save).with(@content.project_id).returns(true) | |
75 | + get :update, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash | |
76 | + assert @repository.errors.empty? | |
77 | + assert_response :redirect | |
78 | + end | |
79 | + | |
80 | + should 'not update a repository' do | |
81 | + @repository.errors = [Exception.new] | |
82 | + Kalibro::Repository.expects(:new).returns(@repository) | |
83 | + @repository.expects(:save).with(@content.project_id).returns(false) | |
84 | + get :update, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash | |
85 | + assert !@repository.errors.empty? | |
86 | + assert_response :redirect | |
87 | + end | |
88 | + | |
89 | + should 'show a repository' do | |
90 | + Kalibro::Repository.expects(:repositories_of).with(@content.project_id).returns([@repository]) | |
91 | + Kalibro::Configuration.expects(:configuration_of).with(@repository.id).returns(@configuration) | |
92 | + | |
93 | + assert_equal @content.name, assigns(:project_name) | |
94 | + assert_equal @repository, assigns(:repository) | |
95 | + @configuration_name = Kalibro::Configuration.find(@repository.configuration_id).name | |
96 | + @processing = processing(@repository.id) | |
97 | + end | |
48 | 98 | |
49 | 99 | end | ... | ... |