Commit d72126529fee4588742ced1cb42e45e3d3cc9552

Authored by Rafael Manzo
1 parent 503a269d

Added the method last_processing to the model Repository

app/models/processing.rb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +class Processing < KalibroEntities::Entities::Processing
  2 + include KalibroRecord
  3 +end
0 4 \ No newline at end of file
... ...
app/models/repository.rb
1 1 class Repository < KalibroEntities::Entities::Repository
2 2 include KalibroRecord
  3 +
  4 + def last_processing
  5 + Processing.processing_of(@id)
  6 + end
3 7 end
... ...
spec/factories/process_times.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +FactoryGirl.define do
  2 + factory :process_time, class: KalibroEntities::Entities::ProcessTime do
  3 + state "Ready"
  4 + time "3600"
  5 + end
  6 +
  7 + factory :analyzing_process_time, class: KalibroEntities::Entities::ProcessTime do
  8 + state "Analyzing"
  9 + time "12345"
  10 + end
  11 +end
0 12 \ No newline at end of file
... ...
spec/factories/processings.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +FactoryGirl.define do
  2 + factory :processing, class: Processing do
  3 + id "31"
  4 + date "2011-10-20T18:26:43.151+00:00"
  5 + state "READY"
  6 + process_time {[FactoryGirl.build(:process_time)]}
  7 + results_root_id "13"
  8 + end
  9 +end
0 10 \ No newline at end of file
... ...
spec/factories/repositories.rb
1   -# Read about factories at https://github.com/thoughtbot/factory_girl
2   -
3 1 FactoryGirl.define do
4   - factory :repository do
5   - name "MyString"
  2 + factory :repository, class: Repository do
  3 + id 1
  4 + name "QtCalculator"
  5 + description "A simple calculator"
  6 + license "GPLv3"
  7 + process_period 1
  8 + type "SVN"
  9 + address "svn://svn.code.sf.net/p/qt-calculator/code/trunk"
  10 + configuration_id 1
  11 + project_id 1
  12 + send_email "test@test.com"
  13 + end
  14 +
  15 + factory :another_repository, class: KalibroEntities::Entities::Repository, parent: :repository do
  16 + id 2
6 17 end
7 18 -end
  19 +end
8 20 \ No newline at end of file
... ...
spec/models/repository_spec.rb
1 1 require 'spec_helper'
2 2  
3 3 describe Repository do
4   - pending "add some examples to (or delete) #{__FILE__}"
  4 + describe 'methods' do
  5 + describe 'last_processing' do
  6 + subject { FactoryGirl.build(:repository) }
  7 +
  8 + context 'with a ready processing' do
  9 + let(:processing) { FactoryGirl.build(:processing) }
  10 +
  11 + before :each do
  12 + Processing.expects(:has_ready_processing).with(subject.id).returns(true)
  13 + end
  14 +
  15 + it 'should return a ready processing processing' do
  16 + Processing.expects(:last_ready_processing_of).with(subject.id).returns(processing)
  17 +
  18 + subject.last_processing.should eq(processing)
  19 + end
  20 + end
  21 +
  22 + context 'with no ready processing' do
  23 + let(:processing) { FactoryGirl.build(:processing, state: 'COLLECTING') }
  24 +
  25 + before :each do
  26 + Processing.expects(:has_ready_processing).with(subject.id).returns(false)
  27 + end
  28 +
  29 + it 'should return the latest processing' do
  30 + Processing.expects(:last_processing_of).with(subject.id).returns(processing)
  31 +
  32 + subject.last_processing.should eq(processing)
  33 + end
  34 + end
  35 + end
  36 + end
5 37 end
... ...