photomix/test/blueprints.rb

96 lines
2.4 KiB
Ruby
Raw Normal View History

2012-07-24 23:26:16 +02:00
#coding: utf-8
require 'machinist/active_record'
require 'open-uri'
def random_str
(0...8).map { 65.+(rand(25)).chr }.join
end
Role.blueprint {
name { 'user' }
}
User.blueprint {
rand(2) == 0 ? sex = :female : sex = :male
email { "#{random_str}@example.com" }
password { 'password' }
password_confirmation { 'password' }
first_name { Faker::NameRU.first_name(sex) }
second_name { Faker::NameRU.patronymic(sex) }
surname { Faker::NameRU.last_name(sex) }
confirmed_at { Time.now + rand(1..4) }
confirmation_sent_at { Time.now + rand(5..9) }
userpic {
file_name = ::SecureRandom.hex(8)
file = open("http://lorempixel.com/800/500/abstract/")
if file.kind_of? Tempfile
name = File.basename(file.path)
FileUtils.move(file.path, "#{Rails.root}/tmp/attachments/#{name}.jpeg")
file = File.open("#{Rails.root}/tmp/attachments/#{name}.jpeg")
end
file.original_filename = "#{file_name}.jpeg" if file.kind_of? StringIO
file
}
}
Album.blueprint {
title { Faker::Lorem.sentence(rand(3)) }
description { Faker::Lorem.sentence }
path { "my_album_#{sn}" }
2012-07-26 22:26:23 +02:00
rating_average { rand(1..5) }
public { true }
2012-07-24 23:26:16 +02:00
}
Collection.blueprint {
title { Faker::Lorem.sentence(rand(3)) }
description { Faker::Lorem.sentence }
2012-07-26 22:26:23 +02:00
rating_average { rand(1..5) }
public { true }
2012-07-24 23:26:16 +02:00
}
CollectionAlbum.blueprint {
2012-07-29 00:33:03 +02:00
album { Album.find(rand(1..60)) }
collection { Collection.find(rand(1..60)) }
2012-07-24 23:26:16 +02:00
}
Photo.blueprint {
title { Faker::Lorem.sentence(rand(3)) }
description { Faker::Lorem.sentence }
2012-07-29 00:33:03 +02:00
album { Album.find(rand(1..60)) }
2012-07-26 22:26:23 +02:00
rating_average { rand(1..5) }
public { true }
2012-07-24 23:26:16 +02:00
attachment {
file_name = ::SecureRandom.hex(8)
2012-07-27 01:08:25 +02:00
file = open("http://lorempixel.com/1170/600/people/")
2012-07-24 23:26:16 +02:00
if file.kind_of? Tempfile
name = File.basename(file.path)
FileUtils.move(file.path, "#{Rails.root}/tmp/attachments/#{name}.jpeg")
file = File.open("#{Rails.root}/tmp/attachments/#{name}.jpeg")
end
file.original_filename = "#{file_name}.jpeg" if file.kind_of? StringIO
file
}
}
2012-07-26 22:26:23 +02:00
Rate.blueprint(:collections) {
2012-07-29 00:33:03 +02:00
rateable { Collection.find(rand(1..60)) }
2012-07-26 22:26:23 +02:00
rater { User.find(rand(1..20)) }
stars { rand(1..5) }
}
Rate.blueprint(:albums) {
2012-07-29 00:33:03 +02:00
rateable { Album.find(rand(1..60)) }
2012-07-26 22:26:23 +02:00
rater { User.find(rand(1..20)) }
stars { rand(1..5) }
}
Rate.blueprint(:photos) {
2012-07-29 00:33:03 +02:00
rateable { Photo.find(rand(1..60)) }
2012-07-26 22:26:23 +02:00
rater { User.find(rand(1..20)) }
stars { rand(1..5) }
}