Commit 32fd0fb0191071d29f3a84d70d9620004d24f8e0
Committed by
Paulo Meireles
1 parent
329cd2d3
Exists in
colab
and in
4 other branches
Dealt with the caser where there is no processing for a given repository
Showing
6 changed files
with
44 additions
and
7 deletions
Show diff stats
app/controllers/repositories_controller.rb
... | ... | @@ -31,7 +31,7 @@ class RepositoriesController < ApplicationController |
31 | 31 | # POST /projects/1/repositories.json |
32 | 32 | def create |
33 | 33 | @repository = Repository.new(repository_params) |
34 | - @repository.project_id = params[:project_id] | |
34 | + @repository.project_id = params[:project_id] | |
35 | 35 | |
36 | 36 | respond_to do |format| |
37 | 37 | create_and_redir(format) |
... | ... | @@ -62,12 +62,14 @@ class RepositoriesController < ApplicationController |
62 | 62 | end |
63 | 63 | |
64 | 64 | # POST /projects/1/repositories/1/state |
65 | - def state | |
65 | + def state | |
66 | 66 | if params[:last_state] != 'READY' |
67 | 67 | @processing = @repository.last_processing |
68 | 68 | |
69 | 69 | respond_to do |format| |
70 | - if @processing.state == 'READY' | |
70 | + if @processing.nil? | |
71 | + format.js { render action: 'unprocessed' } | |
72 | + elsif @processing.state == 'READY' | |
71 | 73 | format.js { render action: 'load_ready_processing' } |
72 | 74 | else |
73 | 75 | format.js { render action: 'reload_processing' } |
... | ... | @@ -83,7 +85,7 @@ private |
83 | 85 | def failed_action(format, destiny_action) |
84 | 86 | @project_id = params[:project_id] |
85 | 87 | @repository_types = Repository.repository_types |
86 | - | |
88 | + | |
87 | 89 | format.html { render action: destiny_action } |
88 | 90 | format.json { render json: @repository.errors, status: :unprocessable_entity } |
89 | 91 | end | ... | ... |
app/models/repository.rb
... | ... | @@ -5,6 +5,10 @@ class Repository < KalibroGem::Entities::Repository |
5 | 5 | validates :address, presence: true |
6 | 6 | |
7 | 7 | def last_processing |
8 | - Processing.processing_of(@id) | |
8 | + if Processing.has_processing(@id) | |
9 | + Processing.processing_of(@id) | |
10 | + else | |
11 | + nil | |
12 | + end | |
9 | 13 | end |
10 | 14 | end | ... | ... |
... | ... | @@ -0,0 +1,3 @@ |
1 | +$('div#processing_information').html('<%= escape_javascript(render partial: "unstarted_processing") %>'); | |
2 | +repository = new Module.Repository(<%= @repository.project_id %>, <%= @repository.id %>) | |
3 | +repository.schedule_poll_state('') | |
0 | 4 | \ No newline at end of file | ... | ... |
spec/controllers/repositories_controller_spec.rb
... | ... | @@ -255,6 +255,19 @@ describe RepositoriesController do |
255 | 255 | describe 'state' do |
256 | 256 | let(:repository) { FactoryGirl.build(:repository) } |
257 | 257 | |
258 | + context 'with no processing at all' do | |
259 | + before :each do | |
260 | + repository.expects(:last_processing).returns(nil) | |
261 | + Repository.expects(:find).at_least_once.with(repository.id).returns(repository) | |
262 | + | |
263 | + request.env["HTTP_ACCEPT"] = 'application/javascript' # FIXME: there should be a better way to force JS | |
264 | + get :state, project_id: project.id.to_s, id: repository.id, last_state: '' | |
265 | + end | |
266 | + | |
267 | + it { should respond_with(:success) } | |
268 | + it { should render_template(:unprocessed) } | |
269 | + end | |
270 | + | |
258 | 271 | context 'with a READY state' do |
259 | 272 | let(:ready_processing) { FactoryGirl.build(:processing) } |
260 | 273 | ... | ... |
spec/models/repository_spec.rb
... | ... | @@ -5,10 +5,21 @@ describe Repository do |
5 | 5 | describe 'last_processing' do |
6 | 6 | subject { FactoryGirl.build(:repository) } |
7 | 7 | |
8 | + context 'with no processing at all' do | |
9 | + before :each do | |
10 | + Processing.expects(:has_processing).with(subject.id).returns(false) | |
11 | + end | |
12 | + | |
13 | + it 'should return nil' do | |
14 | + subject.last_processing.should be_nil | |
15 | + end | |
16 | + end | |
17 | + | |
8 | 18 | context 'with a ready processing' do |
9 | 19 | let(:processing) { FactoryGirl.build(:processing) } |
10 | 20 | |
11 | 21 | before :each do |
22 | + Processing.expects(:has_processing).with(subject.id).returns(true) | |
12 | 23 | Processing.expects(:has_ready_processing).with(subject.id).returns(true) |
13 | 24 | end |
14 | 25 | |
... | ... | @@ -23,6 +34,7 @@ describe Repository do |
23 | 34 | let(:processing) { FactoryGirl.build(:processing, state: 'COLLECTING') } |
24 | 35 | |
25 | 36 | before :each do |
37 | + Processing.expects(:has_processing).with(subject.id).returns(true) | |
26 | 38 | Processing.expects(:has_ready_processing).with(subject.id).returns(false) |
27 | 39 | end |
28 | 40 | |
... | ... | @@ -37,8 +49,8 @@ describe Repository do |
37 | 49 | |
38 | 50 | describe 'validations' do |
39 | 51 | subject {FactoryGirl.build(:repository)} |
40 | - | |
41 | - context 'active model validations' do | |
52 | + | |
53 | + context 'active model validations' do | |
42 | 54 | before :each do |
43 | 55 | Repository.expects(:all).at_least_once.returns([]) |
44 | 56 | end | ... | ... |