#757: create "published_container" scope

This commit is contained in:
Vokhmin Alexey V 2013-02-19 18:14:51 +04:00
parent 418a138b37
commit 5234b7cc51
2 changed files with 4 additions and 3 deletions

View File

@ -117,7 +117,7 @@ class Projects::BuildListsController < Projects::BaseController
results = [] results = []
platforms.each{ |p| p.repositories.each{ |r| results << {:id => r.id, :label => "#{p.name}/#{r.name}", :value => "#{p.name}/#{r.name}"} } } platforms.each{ |p| p.repositories.each{ |r| results << {:id => r.id, :label => "#{p.name}/#{r.name}", :value => "#{p.name}/#{r.name}"} } }
bl = BuildList.where(:id => params[:term], :container_status => BuildList::BUILD_PUBLISHED).first bl = BuildList.where(:id => params[:term]).published_container.first
results << {:id => "#{bl.id}-build-list", :value => bl.id, :label => "#{bl.id} (#{bl.project.name} - #{bl.arch.name})"} if bl results << {:id => "#{bl.id}-build-list", :value => bl.id, :label => "#{bl.id} (#{bl.project.name} - #{bl.arch.name})"} if bl
render json: results.to_json render json: results.to_json
end end
@ -125,7 +125,7 @@ class Projects::BuildListsController < Projects::BaseController
def add_extra def add_extra
if params[:extra_id] =~ /-build-list$/ if params[:extra_id] =~ /-build-list$/
id = params[:extra_id].gsub(/-build-list$/, '') id = params[:extra_id].gsub(/-build-list$/, '')
subject = BuildList.where(:id => id, :container_status => BuildList::BUILD_PUBLISHED).first subject = BuildList.where(:id => id).published_container.first
else else
subject = Repository.find params[:extra_id] subject = Repository.find params[:extra_id]
end end

View File

@ -127,6 +127,7 @@ class BuildList < ActiveRecord::Base
scope :scoped_to_project_name, lambda {|project_name| joins(:project).where('projects.name LIKE ?', "%#{project_name}%")} scope :scoped_to_project_name, lambda {|project_name| joins(:project).where('projects.name LIKE ?', "%#{project_name}%")}
scope :scoped_to_new_core, lambda {|new_core| where(:new_core => new_core)} scope :scoped_to_new_core, lambda {|new_core| where(:new_core => new_core)}
scope :outdated, where('created_at < ? AND status <> ? OR created_at < ?', Time.now - LIVE_TIME, BUILD_PUBLISHED, Time.now - MAX_LIVE_TIME) scope :outdated, where('created_at < ? AND status <> ? OR created_at < ?', Time.now - LIVE_TIME, BUILD_PUBLISHED, Time.now - MAX_LIVE_TIME)
scope :published_container, where(:container_status => BUILD_PUBLISHED)
serialize :additional_repos serialize :additional_repos
serialize :include_repos serialize :include_repos
@ -477,7 +478,7 @@ class BuildList < ActiveRecord::Base
end end
def check_extra_containers def check_extra_containers
if extra_containers.present? && BuildList.where(:id => extra_containers, :container_status => BUILD_PUBLISHED).count != extra_containers.count if extra_containers.present? && BuildList.where(:id => extra_containers).published_container.count != extra_containers.count
errors.add(:extra_containers, I18n.t('flash.build_list.wrong_extra_containers')) errors.add(:extra_containers, I18n.t('flash.build_list.wrong_extra_containers'))
end end
end end