Commit 29bc97929fba74c161b11c39ede61abd85b68f3c
Committed by
Diego Martinez
1 parent
1cdaecd5
Exists in
master
and in
29 other branches
[Mezuro] Refactored and tested repository controller.
Showing
2 changed files
with
29 additions
and
8 deletions
Show diff stats
plugins/mezuro/controllers/profile/mezuro_plugin_repository_controller.rb
... | ... | @@ -55,18 +55,18 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController |
55 | 55 | end |
56 | 56 | end |
57 | 57 | |
58 | - def show #TODO verificar data_content e data_profile | |
58 | + def show | |
59 | 59 | project_content = profile.articles.find(params[:id]) |
60 | 60 | @project_name = project_content.name |
61 | - @repository = project_content.repositories.select{ |repository| repository.id == params[:repository_id].to_s }.first | |
61 | + @repository = project_content.repositories.select{ |repository| repository.id.to_s == params[:repository_id] }.first | |
62 | 62 | @configuration_name = Kalibro::Configuration.configuration_of(@repository.id).name |
63 | 63 | @data_profile = project_content.profile.identifier |
64 | 64 | @data_content = project_content.id |
65 | 65 | end |
66 | 66 | |
67 | - def destroy #TODO verificar se está correto | |
67 | + def destroy | |
68 | 68 | project_content = profile.articles.find(params[:id]) |
69 | - repository = project_content.repositories.select{ |repository| repository.id == params[:repository_id].to_s }.first | |
69 | + repository = project_content.repositories.select{ |repository| repository.id.to_s == params[:repository_id] }.first | |
70 | 70 | repository.destroy |
71 | 71 | if( repository.errors.empty? ) |
72 | 72 | redirect_to "/#{profile.identifier}/#{project_content.name.downcase.gsub(/\s/, '-')}" | ... | ... |
plugins/mezuro/test/functional/profile/mezuro_plugin_repository_controller_test.rb
... | ... | @@ -6,7 +6,6 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures" |
6 | 6 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_content_fixtures" |
7 | 7 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" |
8 | 8 | |
9 | -#TODO terminar os testes | |
10 | 9 | class MezuroPluginRepositoryControllerTest < ActionController::TestCase |
11 | 10 | |
12 | 11 | def setup |
... | ... | @@ -87,14 +86,36 @@ class MezuroPluginRepositoryControllerTest < ActionController::TestCase |
87 | 86 | assert_response :redirect |
88 | 87 | end |
89 | 88 | |
90 | - should 'set variables to show a repository' do #TODO Terminar esse teste | |
89 | + should 'set variables to show a repository' do | |
91 | 90 | Kalibro::Repository.expects(:repositories_of).with(@content.project_id).returns([@repository]) |
92 | 91 | Kalibro::Configuration.expects(:configuration_of).with(@repository.id).returns(@configuration) |
93 | 92 | |
93 | + get :show, :profile => @profile.identifier, :id => @content.id, :repository_id => @repository.id | |
94 | 94 | assert_equal @content.name, assigns(:project_name) |
95 | 95 | assert_equal @repository, assigns(:repository) |
96 | -# @configuration_name = Kalibro::Configuration.find(@repository.configuration_id).name | |
97 | -# @processing = processing(@repository.id) | |
96 | + assert_equal @configuration.name, assigns(:configuration_name) | |
97 | + assert_equal @content.profile.identifier, assigns(:data_profile) | |
98 | + assert_equal @content.id, assigns(:data_content) | |
98 | 99 | end |
99 | 100 | |
101 | + should 'destroy a repository' do | |
102 | + @repository.expects(:destroy) | |
103 | + Kalibro::Repository.expects(:repositories_of).with(@content.project_id).returns([@repository]) | |
104 | + | |
105 | + get :destroy, :profile => @profile.identifier, :id => @content.id, :repository_id => @repository.id | |
106 | + | |
107 | + assert @repository.errors.empty? | |
108 | + assert_response :redirect | |
109 | + end | |
110 | + | |
111 | + should 'not destroy a repository' do | |
112 | + @repository.errors = [Exception.new] | |
113 | + @repository.expects(:destroy) | |
114 | + Kalibro::Repository.expects(:repositories_of).with(@content.project_id).returns([@repository]) | |
115 | + | |
116 | + get :destroy, :profile => @profile.identifier, :id => @content.id, :repository_id => @repository.id | |
117 | + | |
118 | + assert !@repository.errors.empty? | |
119 | + assert_response :redirect | |
120 | + end | |
100 | 121 | end | ... | ... |