#195: updated MassBuild model, added specs

This commit is contained in:
Vokhmin Alexey V 2013-06-21 14:39:03 +04:00
parent 563f983e60
commit 47ed190b73
3 changed files with 52 additions and 7 deletions

View File

@ -15,7 +15,10 @@ class MassBuild < ActiveRecord::Base
attr_accessible :arches, :auto_publish, :projects_list, :build_for_platform_id,
:extra_repositories, :extra_build_lists
validates :save_to_platform_id, :build_for_platform_id, :arch_names, :name, :user_id, :projects_list, :presence => true
validates :save_to_platform_id, :build_for_platform_id, :arch_names, :name, :user_id, :presence => true
validates :projects_list, :length => {:maximum => 500_000}, :presence => true
validates_inclusion_of :auto_publish, :in => [true, false]
after_commit :build_all, :on => :create
@ -104,8 +107,14 @@ class MassBuild < ActiveRecord::Base
end
def set_data
self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{save_to_platform.name}"
self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ")
self.build_for_platform = save_to_platform if save_to_platform && save_to_platform.main?
if save_to_platform
self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{save_to_platform.name}"
self.build_for_platform = save_to_platform if save_to_platform.main?
end
self.arch_names = Arch.where(:id => arches).map(&:name).join(", ")
self.projects_list = projects_list.lines.map do |name|
name.chomp.strip if name.present?
end.compact.uniq.join("\r\n") if projects_list.present?
end
end

View File

@ -1,10 +1,10 @@
# -*- encoding : utf-8 -*-
FactoryGirl.define do
factory :mass_build do
association :save_to_platform
association :save_to_platform, :factory => :platform
association :user
projects_list "first"
arches { [ Arch.first.id ] }
arches { [ Arch.find_or_create_by_name('x86_64').id ] }
auto_publish true
stop_build false
end

View File

@ -1,5 +1,41 @@
require 'spec_helper'
describe MassBuild do
pending "add some examples to (or delete) #{__FILE__}"
before { stub_symlink_methods }
context 'ensures that validations and associations exist' do
before do
# Need for validate_uniqueness_of check
FactoryGirl.create(:mass_build)
end
it { should belong_to(:build_for_platform) }
it { should belong_to(:save_to_platform) }
it { should belong_to(:user) }
it { should have_many(:build_lists)}
it { should validate_presence_of(:save_to_platform_id)}
it { should validate_presence_of(:build_for_platform_id)}
it { should validate_presence_of(:user_id)}
it { should validate_presence_of(:arch_names)}
it { should validate_presence_of(:name)}
it { should validate_presence_of(:projects_list)}
it { should ensure_length_of(:projects_list).is_at_most(500_000) }
it { should_not allow_mass_assignment_of(:name) }
it { should_not allow_mass_assignment_of(:arch_names) }
end
it 'ensures that projects_list contains unique projects' do
projects_list = %(at
at
ab
)
mass_build = FactoryGirl.create(:mass_build, :projects_list => projects_list)
list = mass_build.projects_list.split(/[\r]*\n/)
list.should have(2).items
list.should include('at', 'ab')
end
end