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,7 +31,7 @@ class RepositoriesController < ApplicationController | ||
31 | # POST /projects/1/repositories.json | 31 | # POST /projects/1/repositories.json |
32 | def create | 32 | def create |
33 | @repository = Repository.new(repository_params) | 33 | @repository = Repository.new(repository_params) |
34 | - @repository.project_id = params[:project_id] | 34 | + @repository.project_id = params[:project_id] |
35 | 35 | ||
36 | respond_to do |format| | 36 | respond_to do |format| |
37 | create_and_redir(format) | 37 | create_and_redir(format) |
@@ -62,12 +62,14 @@ class RepositoriesController < ApplicationController | @@ -62,12 +62,14 @@ class RepositoriesController < ApplicationController | ||
62 | end | 62 | end |
63 | 63 | ||
64 | # POST /projects/1/repositories/1/state | 64 | # POST /projects/1/repositories/1/state |
65 | - def state | 65 | + def state |
66 | if params[:last_state] != 'READY' | 66 | if params[:last_state] != 'READY' |
67 | @processing = @repository.last_processing | 67 | @processing = @repository.last_processing |
68 | 68 | ||
69 | respond_to do |format| | 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 | format.js { render action: 'load_ready_processing' } | 73 | format.js { render action: 'load_ready_processing' } |
72 | else | 74 | else |
73 | format.js { render action: 'reload_processing' } | 75 | format.js { render action: 'reload_processing' } |
@@ -83,7 +85,7 @@ private | @@ -83,7 +85,7 @@ private | ||
83 | def failed_action(format, destiny_action) | 85 | def failed_action(format, destiny_action) |
84 | @project_id = params[:project_id] | 86 | @project_id = params[:project_id] |
85 | @repository_types = Repository.repository_types | 87 | @repository_types = Repository.repository_types |
86 | - | 88 | + |
87 | format.html { render action: destiny_action } | 89 | format.html { render action: destiny_action } |
88 | format.json { render json: @repository.errors, status: :unprocessable_entity } | 90 | format.json { render json: @repository.errors, status: :unprocessable_entity } |
89 | end | 91 | end |
app/models/repository.rb
@@ -5,6 +5,10 @@ class Repository < KalibroGem::Entities::Repository | @@ -5,6 +5,10 @@ class Repository < KalibroGem::Entities::Repository | ||
5 | validates :address, presence: true | 5 | validates :address, presence: true |
6 | 6 | ||
7 | def last_processing | 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 | end | 13 | end |
10 | end | 14 | end |
@@ -0,0 +1,3 @@ | @@ -0,0 +1,3 @@ | ||
1 | +<p>This repository has no processings yet. Please hold tight that as soon as possible we'll start it!</p> | ||
2 | + | ||
3 | +<div id="processing_information"><%= image_tag 'loader.gif' %> Loading data. Please, wait.</div> | ||
0 | \ No newline at end of file | 4 | \ No newline at end of file |
@@ -0,0 +1,3 @@ | @@ -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 | \ No newline at end of file | 4 | \ No newline at end of file |
spec/controllers/repositories_controller_spec.rb
@@ -255,6 +255,19 @@ describe RepositoriesController do | @@ -255,6 +255,19 @@ describe RepositoriesController do | ||
255 | describe 'state' do | 255 | describe 'state' do |
256 | let(:repository) { FactoryGirl.build(:repository) } | 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 | context 'with a READY state' do | 271 | context 'with a READY state' do |
259 | let(:ready_processing) { FactoryGirl.build(:processing) } | 272 | let(:ready_processing) { FactoryGirl.build(:processing) } |
260 | 273 |
spec/models/repository_spec.rb
@@ -5,10 +5,21 @@ describe Repository do | @@ -5,10 +5,21 @@ describe Repository do | ||
5 | describe 'last_processing' do | 5 | describe 'last_processing' do |
6 | subject { FactoryGirl.build(:repository) } | 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 | context 'with a ready processing' do | 18 | context 'with a ready processing' do |
9 | let(:processing) { FactoryGirl.build(:processing) } | 19 | let(:processing) { FactoryGirl.build(:processing) } |
10 | 20 | ||
11 | before :each do | 21 | before :each do |
22 | + Processing.expects(:has_processing).with(subject.id).returns(true) | ||
12 | Processing.expects(:has_ready_processing).with(subject.id).returns(true) | 23 | Processing.expects(:has_ready_processing).with(subject.id).returns(true) |
13 | end | 24 | end |
14 | 25 | ||
@@ -23,6 +34,7 @@ describe Repository do | @@ -23,6 +34,7 @@ describe Repository do | ||
23 | let(:processing) { FactoryGirl.build(:processing, state: 'COLLECTING') } | 34 | let(:processing) { FactoryGirl.build(:processing, state: 'COLLECTING') } |
24 | 35 | ||
25 | before :each do | 36 | before :each do |
37 | + Processing.expects(:has_processing).with(subject.id).returns(true) | ||
26 | Processing.expects(:has_ready_processing).with(subject.id).returns(false) | 38 | Processing.expects(:has_ready_processing).with(subject.id).returns(false) |
27 | end | 39 | end |
28 | 40 | ||
@@ -37,8 +49,8 @@ describe Repository do | @@ -37,8 +49,8 @@ describe Repository do | ||
37 | 49 | ||
38 | describe 'validations' do | 50 | describe 'validations' do |
39 | subject {FactoryGirl.build(:repository)} | 51 | subject {FactoryGirl.build(:repository)} |
40 | - | ||
41 | - context 'active model validations' do | 52 | + |
53 | + context 'active model validations' do | ||
42 | before :each do | 54 | before :each do |
43 | Repository.expects(:all).at_least_once.returns([]) | 55 | Repository.expects(:all).at_least_once.returns([]) |
44 | end | 56 | end |