Commit f6b35fcc283b812923fdcaae11092d0b4ce626ce
1 parent
80156114
Exists in
colab
and in
2 other branches
Add Repository#attributes method
Showing
2 changed files
with
34 additions
and
0 deletions
Show diff stats
app/models/repository.rb
| 1 | 1 | class Repository < KalibroClient::Entities::Processor::Repository |
| 2 | 2 | include KalibroRecord |
| 3 | 3 | |
| 4 | + attr_writer :attributes | |
| 5 | + | |
| 4 | 6 | def self.public_or_owned_by_user(user = nil) |
| 5 | 7 | repository_attributes = RepositoryAttributes.where(public: true) |
| 6 | 8 | repository_attributes += RepositoryAttributes.where(user_id: user.id, public: false) if user |
| ... | ... | @@ -17,4 +19,8 @@ class Repository < KalibroClient::Entities::Processor::Repository |
| 17 | 19 | def self.latest(count=1) |
| 18 | 20 | all.sort { |one, another| another.id <=> one.id }.first(count) |
| 19 | 21 | end |
| 22 | + | |
| 23 | + def attributes | |
| 24 | + @attributes ||= RepositoryAttributes.find_by_repository_id(@id) | |
| 25 | + end | |
| 20 | 26 | end | ... | ... |
spec/models/repository_spec.rb
| 1 | 1 | require 'rails_helper' |
| 2 | 2 | |
| 3 | 3 | describe Repository do |
| 4 | + describe 'methods' do | |
| 5 | + describe 'attributes' do | |
| 6 | + subject { FactoryGirl.build(:repository) } | |
| 7 | + | |
| 8 | + context 'when there are attributes' do | |
| 9 | + let!(:repository_attributes) { FactoryGirl.build(:repository_attributes) } | |
| 10 | + | |
| 11 | + before :each do | |
| 12 | + RepositoryAttributes.expects(:find_by_repository_id).returns(repository_attributes) | |
| 13 | + end | |
| 14 | + | |
| 15 | + it 'is expected to return the repository attributes' do | |
| 16 | + expect(subject.attributes).to eq(repository_attributes) | |
| 17 | + end | |
| 18 | + end | |
| 19 | + | |
| 20 | + context 'when there are no attributes' do | |
| 21 | + before :each do | |
| 22 | + RepositoryAttributes.expects(:find_by_repository_id).returns(nil) | |
| 23 | + end | |
| 24 | + | |
| 25 | + it 'is expected to return the repository attributes' do | |
| 26 | + expect(subject.attributes).to be_nil | |
| 27 | + end | |
| 28 | + end | |
| 29 | + end | |
| 30 | + end | |
| 31 | + | |
| 4 | 32 | describe 'class method' do |
| 5 | 33 | describe 'latest' do |
| 6 | 34 | let!(:repository) { FactoryGirl.build(:repository, id: 1) } | ... | ... |