From 47ed190b73c687b7a37ef11b378c18f2fb145b53 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 21 Jun 2013 14:39:03 +0400 Subject: [PATCH 1/2] #195: updated MassBuild model, added specs --- app/models/mass_build.rb | 17 +++++++++++---- spec/factories/mass_build.rb | 4 ++-- spec/models/mass_build_spec.rb | 38 +++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index f174d1501..d7e18fea8 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -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 diff --git a/spec/factories/mass_build.rb b/spec/factories/mass_build.rb index c97bf517e..7ea9ff64f 100644 --- a/spec/factories/mass_build.rb +++ b/spec/factories/mass_build.rb @@ -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 diff --git a/spec/models/mass_build_spec.rb b/spec/models/mass_build_spec.rb index e7bb6c4d2..3e213af38 100644 --- a/spec/models/mass_build_spec.rb +++ b/spec/models/mass_build_spec.rb @@ -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 From 329de6bd2d0b8d003b6d3cc7cb7822536b1df8f3 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 21 Jun 2013 14:41:57 +0400 Subject: [PATCH 2/2] #195: removed empty lines --- app/models/mass_build.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index d7e18fea8..c40715ca3 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -15,8 +15,6 @@ 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, :presence => true validates :projects_list, :length => {:maximum => 500_000}, :presence => true validates_inclusion_of :auto_publish, :in => [true, false]