Skip to content

Instantly share code, notes, and snippets.

@sclinede
Last active August 29, 2015 14:25
Show Gist options
  • Save sclinede/1a40327b65cbe4467287 to your computer and use it in GitHub Desktop.
Save sclinede/1a40327b65cbe4467287 to your computer and use it in GitHub Desktop.
Fill Apress::Deals::Offers
# Run in console
100.times do |i|
r = RubricsDenormalizationTree.order('RANDOM()').first.rubric;
c = Company.includes(:company_logo).where('company_logos.id is not null').order('RANDOM()').first;
s = [Date.yesterday, 15.days.from_now].sample
e = [20.days.from_now, 25.days.from_now, 30.days.from_now].sample
o = Apress::Deals::Offers::Custom.new(
title: "Акция ##{i}",
start_date: s,
end_date: e,
profit: 'Rocket launcher',
company: c,
description: 'Deals deals deal',
creator: User.order('RANDOM()').first,
type: 'Apress::Deals::Offers::Custom'
);
o.offer_regions.build(region_id: c.main_region_id);
o.save!;
o.build_offer_rubric(rubric: r).save!;
o.moderation.accept!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment