diff --git a/app/controllers/platforms/mass_builds_controller.rb b/app/controllers/platforms/mass_builds_controller.rb index a0ab0bd76..ecea50458 100644 --- a/app/controllers/platforms/mass_builds_controller.rb +++ b/app/controllers/platforms/mass_builds_controller.rb @@ -10,13 +10,10 @@ class Platforms::MassBuildsController < Platforms::BaseController skip_authorize_resource :platform, :only => [:create, :index] def create - mass_build = MassBuild.new( - :platform_id => @platform.id, - :user_id => current_user.id, - :repositories => params[:repositories], + mass_build = @platform.mass_builds.new(:repositories => params[:repositories], :arches => params[:arches], - :auto_publish => params[:auto_publish] || false - ) + :auto_publish => params[:auto_publish] || false) + mass_build.user = current_user authorize! :create, mass_build if mass_build.save diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 4fb14758e..70804f2ac 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -12,6 +12,7 @@ class MassBuild < ActiveRecord::Base validates_inclusion_of :auto_publish, :in => [true, false] after_create :build_all + before_validation :set_data COUNT_STATUSES = [ :build_lists, @@ -22,16 +23,6 @@ class MassBuild < ActiveRecord::Base :build_error ] - def initialize(args = nil) - super - - if new_record? - self.rep_names = Repository.where(:id => self.repositories).map(&:name).join(", ") - self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}" - self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ") - end - end - # ATTENTION: repositories and arches must be set before calling this method! def build_all platform.build_all( @@ -59,4 +50,15 @@ class MassBuild < ActiveRecord::Base end end later :cancel_all, :queue => :clone_build + + private + + def set_data + if new_record? + self.rep_names = Repository.where(:id => self.repositories).map(&:name).join(", ") + self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}" + self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ") + end + end + end