#321: small fixes, added specs

This commit is contained in:
Vokhmin Alexey V 2013-11-15 23:02:19 +04:00
parent 17e143e011
commit 77b23780be
5 changed files with 25 additions and 7 deletions

View File

@ -19,7 +19,7 @@ class KeyPair < ActiveRecord::Base
protected protected
def check_keys def check_keys
dir = Dir.mktmpdir('keys-', '/tmp') dir = Dir.mktmpdir 'keys-', APP_CONFIG['tmpfs_path']
begin begin
%w(pubring secring).each do |kind| %w(pubring secring).each do |kind|
filename = "#{dir}/#{kind}" filename = "#{dir}/#{kind}"

View File

@ -117,13 +117,14 @@ class Project < ActiveRecord::Base
repository = Repository.find add_to_repository_id repository = Repository.find add_to_repository_id
platform = repository.platform platform = repository.platform
dir = Dir.mktmpdir('mass-import-', '/dev/shm') dir = Dir.mktmpdir 'mass-import-', APP_CONFIG['tmpfs_path']
links.each do |link| links.each do |link|
begin begin
package = link.attributes['href'].value package = link.attributes['href'].value
package.chomp!; package.strip! package.chomp!; package.strip!
next if package.size == 0 || package !~ /^[\w\.\-]+$/ next if package.size == 0 || package !~ /^[\w\.\-]+$/
next if filter.present? && !filter.include?(package)
uri = URI "#{url}/#{package}" uri = URI "#{url}/#{package}"
srpm_file = "#{dir}/#{package}" srpm_file = "#{dir}/#{package}"
@ -137,7 +138,7 @@ class Project < ActiveRecord::Base
end end
end end
if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present?
next if owner.projects.exists?(:name => name) || (filter.present? && !filter.include?(name)) next if owner.projects.exists?(:name => name)
description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`) description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`)
project = owner.projects.build( project = owner.projects.build(
:name => name, :name => name,
@ -156,11 +157,11 @@ class Project < ActiveRecord::Base
f.close if defined?(f) f.close if defined?(f)
Airbrake.notify_or_ignore(e, :link => link.to_s, :url => url, :owner => owner) Airbrake.notify_or_ignore(e, :link => link.to_s, :url => url, :owner => owner)
ensure ensure
File.delete srpm_file if defined?(srpm_file) File.delete srpm_file if srpm_file
end end
end end
ensure ensure
FileUtils.remove_entry_secure dir if defined?(dir) FileUtils.remove_entry_secure dir if dir
end end
end end

View File

@ -57,6 +57,7 @@ development:
<<: *common <<: *common
root_path: /var/rosa root_path: /var/rosa
git_path: /var/rosa git_path: /var/rosa
tmpfs_path: /dev/shm
do-not-reply-email: do-not-reply@localhost do-not-reply-email: do-not-reply@localhost
github_services: github_services:
ip: 127.0.0.1 ip: 127.0.0.1
@ -66,6 +67,7 @@ production:
<<: *common <<: *common
root_path: /share root_path: /share
git_path: /mnt/gitstore git_path: /mnt/gitstore
tmpfs_path: /dev/shm
do-not-reply-email: do-not-reply@abf.rosalinux.ru do-not-reply-email: do-not-reply@abf.rosalinux.ru
mailer_https_url: false mailer_https_url: false
github_services: github_services:
@ -74,6 +76,7 @@ production:
test: test:
<<: *common <<: *common
tmpfs_path: "use Rails.root/tmp/test_root in spec"
root_path: "use Rails.root/tmp/test_root in spec" root_path: "use Rails.root/tmp/test_root in spec"
git_path: "use Rails.root/tmp/test_root in spec" git_path: "use Rails.root/tmp/test_root in spec"
do-not-reply-email: do-not-reply@localhost do-not-reply-email: do-not-reply@localhost

View File

@ -169,4 +169,17 @@ describe Project do
end end
end end
it '#run_mass_import' do
owner = FactoryGirl.create(:user)
repository = FactoryGirl.create(:repository)
url = 'http://abf-downloads.rosalinux.ru/abf_personal/repository/test-mass-import'
visibility = 'open'
Project.run_mass_import(url, "abf-worker-service-1-3.src.rpm\nredir-2.2.1-7.res6.src.rpm\n", visibility, owner, repository.id)
Project.count.should == 2
repository.projects.should have(2).items
owner.projects.should have(2).items
end
end end

View File

@ -52,6 +52,7 @@ end
Resque.inline = true Resque.inline = true
APP_CONFIG['root_path'] = "#{Rails.root}/tmp/test_root" APP_CONFIG['root_path'] = "#{Rails.root}/tmp/test_root"
APP_CONFIG['git_path'] = "#{Rails.root}/tmp/test_root" APP_CONFIG['git_path'] = "#{Rails.root}/tmp/test_root"
APP_CONFIG['tmpfs_path'] = "#{Rails.root}/tmp/test_root"
def init_test_root def init_test_root
clear_test_root clear_test_root