diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index f990507..17eb969 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -31,7 +31,7 @@ class RepositoriesController < ApplicationController
# POST /projects/1/repositories.json
def create
@repository = Repository.new(repository_params)
- @repository.project_id = params[:project_id]
+ @repository.project_id = params[:project_id]
respond_to do |format|
create_and_redir(format)
@@ -62,12 +62,14 @@ class RepositoriesController < ApplicationController
end
# POST /projects/1/repositories/1/state
- def state
+ def state
if params[:last_state] != 'READY'
@processing = @repository.last_processing
respond_to do |format|
- if @processing.state == 'READY'
+ if @processing.nil?
+ format.js { render action: 'unprocessed' }
+ elsif @processing.state == 'READY'
format.js { render action: 'load_ready_processing' }
else
format.js { render action: 'reload_processing' }
@@ -83,7 +85,7 @@ private
def failed_action(format, destiny_action)
@project_id = params[:project_id]
@repository_types = Repository.repository_types
-
+
format.html { render action: destiny_action }
format.json { render json: @repository.errors, status: :unprocessable_entity }
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 2f3e5f1..71ae666 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -5,6 +5,10 @@ class Repository < KalibroGem::Entities::Repository
validates :address, presence: true
def last_processing
- Processing.processing_of(@id)
+ if Processing.has_processing(@id)
+ Processing.processing_of(@id)
+ else
+ nil
+ end
end
end
diff --git a/app/views/repositories/_unstarted_processing.html.erb b/app/views/repositories/_unstarted_processing.html.erb
new file mode 100644
index 0000000..a1ca425
--- /dev/null
+++ b/app/views/repositories/_unstarted_processing.html.erb
@@ -0,0 +1,3 @@
+
This repository has no processings yet. Please hold tight that as soon as possible we'll start it!
+
+<%= image_tag 'loader.gif' %> Loading data. Please, wait.
\ No newline at end of file
diff --git a/app/views/repositories/unprocessed.js.erb b/app/views/repositories/unprocessed.js.erb
new file mode 100644
index 0000000..f3f9f91
--- /dev/null
+++ b/app/views/repositories/unprocessed.js.erb
@@ -0,0 +1,3 @@
+$('div#processing_information').html('<%= escape_javascript(render partial: "unstarted_processing") %>');
+repository = new Module.Repository(<%= @repository.project_id %>, <%= @repository.id %>)
+repository.schedule_poll_state('')
\ No newline at end of file
diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb
index a6aa6c4..d820c85 100644
--- a/spec/controllers/repositories_controller_spec.rb
+++ b/spec/controllers/repositories_controller_spec.rb
@@ -255,6 +255,19 @@ describe RepositoriesController do
describe 'state' do
let(:repository) { FactoryGirl.build(:repository) }
+ context 'with no processing at all' do
+ before :each do
+ repository.expects(:last_processing).returns(nil)
+ Repository.expects(:find).at_least_once.with(repository.id).returns(repository)
+
+ request.env["HTTP_ACCEPT"] = 'application/javascript' # FIXME: there should be a better way to force JS
+ get :state, project_id: project.id.to_s, id: repository.id, last_state: ''
+ end
+
+ it { should respond_with(:success) }
+ it { should render_template(:unprocessed) }
+ end
+
context 'with a READY state' do
let(:ready_processing) { FactoryGirl.build(:processing) }
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 96b19b9..0c7b43c 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -5,10 +5,21 @@ describe Repository do
describe 'last_processing' do
subject { FactoryGirl.build(:repository) }
+ context 'with no processing at all' do
+ before :each do
+ Processing.expects(:has_processing).with(subject.id).returns(false)
+ end
+
+ it 'should return nil' do
+ subject.last_processing.should be_nil
+ end
+ end
+
context 'with a ready processing' do
let(:processing) { FactoryGirl.build(:processing) }
before :each do
+ Processing.expects(:has_processing).with(subject.id).returns(true)
Processing.expects(:has_ready_processing).with(subject.id).returns(true)
end
@@ -23,6 +34,7 @@ describe Repository do
let(:processing) { FactoryGirl.build(:processing, state: 'COLLECTING') }
before :each do
+ Processing.expects(:has_processing).with(subject.id).returns(true)
Processing.expects(:has_ready_processing).with(subject.id).returns(false)
end
@@ -37,8 +49,8 @@ describe Repository do
describe 'validations' do
subject {FactoryGirl.build(:repository)}
-
- context 'active model validations' do
+
+ context 'active model validations' do
before :each do
Repository.expects(:all).at_least_once.returns([])
end
--
libgit2 0.21.2