adds tests and fixes some broken code to main language mr

This commit is contained in:
tiagonbotelho 2016-03-01 19:45:55 +00:00 committed by Yorick Peterse
parent c2c5572e22
commit d72e6ad2a1
3 changed files with 17 additions and 3 deletions

View File

@ -89,7 +89,7 @@ class Project < ActiveRecord::Base
# checks if the language main language of the project changed # checks if the language main language of the project changed
before_save :check_main_language before_save :check_main_language
def check_main_language def check_main_language
if commit_count.changed? if self.commit_count_changed?
self.main_language = repository.main_language self.main_language = repository.main_language
end end
end end
@ -955,12 +955,12 @@ class Project < ActiveRecord::Base
end end
def main_language def main_language
language = read_attributes(:main_language) language = read_attribute(:main_language)
return language if language return language if language
update_attributes(main_language: repository.main_language) update_attributes(main_language: repository.main_language)
read_attributes(:main_language) read_attribute(:main_language)
end end
end end

View File

@ -560,6 +560,14 @@ describe Project, models: true do
end end
end end
describe "#main_language" do
let(:project) { create :project }
it 'shows the main language of the project' do
expect(project.main_language).to eq("Ruby")
end
end
describe '#visibility_level_allowed?' do describe '#visibility_level_allowed?' do
let(:project) { create :project, visibility_level: Gitlab::VisibilityLevel::INTERNAL } let(:project) { create :project, visibility_level: Gitlab::VisibilityLevel::INTERNAL }

View File

@ -595,4 +595,10 @@ describe Repository, models: true do
repository.after_remove_branch repository.after_remove_branch
end end
end end
describe "#main_language" do
it 'shows the main language of the project' do
expect(repository.main_language).to eq("Ruby")
end
end
end end