Commit fbc36e89eb9b3642fe1dd4e053f90229e443d821
Committed by
Rafael Manzo
1 parent
3ed1197f
Exists in
colab
and in
4 other branches
Implemented last_processing_of for Repository
Showing
2 changed files
with
18 additions
and
65 deletions
Show diff stats
app/models/repository.rb
| 1 | -class Repository < KalibroGatekeeperClient::Entities::Repository | ||
| 2 | - include KalibroRecord | ||
| 3 | - | ||
| 4 | - validates :name, presence: true, kalibro_uniqueness: true | ||
| 5 | - validates :address, presence: true | ||
| 6 | - | ||
| 7 | - def last_processing | ||
| 8 | - if Processing.has_processing(@id) | ||
| 9 | - Processing.processing_of(@id) | 1 | +class Repository < KalibroClient::Processor::Repository |
| 2 | + def last_processing_of | ||
| 3 | + if has_processing | ||
| 4 | + last_processing | ||
| 10 | else | 5 | else |
| 11 | nil | 6 | nil |
| 12 | end | 7 | end |
spec/models/repository_spec.rb
| 1 | require 'rails_helper' | 1 | require 'rails_helper' |
| 2 | 2 | ||
| 3 | describe Repository, :type => :model do | 3 | describe Repository, :type => :model do |
| 4 | - pending 'waiting for kalibro configurations integration' do | ||
| 5 | - describe 'methods' do | ||
| 6 | - describe 'last_processing' do | ||
| 7 | - subject { FactoryGirl.build(:repository) } | 4 | + describe 'methods' do |
| 5 | + describe 'last_processing_of' do | ||
| 6 | + subject { FactoryGirl.build(:repository) } | ||
| 8 | 7 | ||
| 9 | - context 'with no processing at all' do | ||
| 10 | - before :each do | ||
| 11 | - Processing.expects(:has_processing).with(subject.id).returns(false) | ||
| 12 | - end | ||
| 13 | - | ||
| 14 | - it 'should return nil' do | ||
| 15 | - expect(subject.last_processing).to be_nil | ||
| 16 | - end | 8 | + context 'with no processing at all' do |
| 9 | + before :each do | ||
| 10 | + subject.expects(:has_processing).returns(false) | ||
| 17 | end | 11 | end |
| 18 | 12 | ||
| 19 | - context 'with a ready processing' do | ||
| 20 | - let(:processing) { FactoryGirl.build(:processing) } | ||
| 21 | - | ||
| 22 | - before :each do | ||
| 23 | - Processing.expects(:has_processing).with(subject.id).returns(true) | ||
| 24 | - Processing.expects(:has_ready_processing).with(subject.id).returns(true) | ||
| 25 | - end | ||
| 26 | - | ||
| 27 | - it 'should return a ready processing processing' do | ||
| 28 | - Processing.expects(:last_ready_processing_of).with(subject.id).returns(processing) | ||
| 29 | - | ||
| 30 | - expect(subject.last_processing).to eq(processing) | ||
| 31 | - end | ||
| 32 | - end | ||
| 33 | - | ||
| 34 | - context 'with no ready processing' do | ||
| 35 | - let(:processing) { FactoryGirl.build(:processing, state: 'COLLECTING') } | ||
| 36 | - | ||
| 37 | - before :each do | ||
| 38 | - Processing.expects(:has_processing).with(subject.id).returns(true) | ||
| 39 | - Processing.expects(:has_ready_processing).with(subject.id).returns(false) | ||
| 40 | - end | ||
| 41 | - | ||
| 42 | - it 'should return the latest processing' do | ||
| 43 | - Processing.expects(:last_processing_of).with(subject.id).returns(processing) | ||
| 44 | - | ||
| 45 | - expect(subject.last_processing).to eq(processing) | ||
| 46 | - end | 13 | + it 'should return nil' do |
| 14 | + expect(subject.last_processing_of).to be_nil | ||
| 47 | end | 15 | end |
| 48 | end | 16 | end |
| 49 | - end | ||
| 50 | 17 | ||
| 51 | - describe 'validations' do | ||
| 52 | - subject {FactoryGirl.build(:repository)} | 18 | + context 'with a processing' do |
| 19 | + let(:processing) { FactoryGirl.build(:processing) } | ||
| 53 | 20 | ||
| 54 | - context 'active model validations' do | ||
| 55 | before :each do | 21 | before :each do |
| 56 | - Repository.expects(:all).at_least_once.returns([]) | 22 | + subject.expects(:has_processing).returns(true) |
| 57 | end | 23 | end |
| 58 | 24 | ||
| 59 | - it { is_expected.to validate_presence_of(:name) } | ||
| 60 | - it { is_expected.to validate_presence_of(:address) } | ||
| 61 | - end | ||
| 62 | - | ||
| 63 | - context 'kalibro validations' do | ||
| 64 | - before :each do | ||
| 65 | - Repository.expects(:request).returns(42) | ||
| 66 | - end | 25 | + it 'should return a ready processing processing' do |
| 26 | + subject.expects(:last_processing).returns(processing) | ||
| 67 | 27 | ||
| 68 | - it 'should validate uniqueness' do | ||
| 69 | - KalibroUniquenessValidator.any_instance.expects(:validate_each).with(subject, :name, subject.name) | ||
| 70 | - subject.save | 28 | + expect(subject.last_processing_of).to eq(processing) |
| 71 | end | 29 | end |
| 72 | end | 30 | end |
| 73 | end | 31 | end |