Commit b6f01b8f71a9b54e1ec9da169bdcba7e668ad590
Committed by
Gabriela Navarro
1 parent
0687ee4f
Exists in
master
and in
5 other branches
Add rake to create sample softwares
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
2 changed files
with
72 additions
and
1 deletions
Show diff stats
lib/software_info.rb
| @@ -49,7 +49,7 @@ class SoftwareInfo < ActiveRecord::Base | @@ -49,7 +49,7 @@ class SoftwareInfo < ActiveRecord::Base | ||
| 49 | has_many :programming_languages, :through => :software_languages | 49 | has_many :programming_languages, :through => :software_languages |
| 50 | has_many :operating_system_names, :through => :operating_systems | 50 | has_many :operating_system_names, :through => :operating_systems |
| 51 | 51 | ||
| 52 | - belongs_to :community | 52 | + belongs_to :community, :dependent => :destroy |
| 53 | belongs_to :license_info | 53 | belongs_to :license_info |
| 54 | 54 | ||
| 55 | has_one :software_categories | 55 | has_one :software_categories |
| @@ -0,0 +1,71 @@ | @@ -0,0 +1,71 @@ | ||
| 1 | +NUMBER_OF_SOFTWARES = 10 | ||
| 2 | + | ||
| 3 | +namespace :software do | ||
| 4 | + desc "Create sample softwares" | ||
| 5 | + task :create_sample_softwares => :environment do | ||
| 6 | + Environment.all.each do |env| | ||
| 7 | + if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin") | ||
| 8 | + | ||
| 9 | + print "Creating softwares: " | ||
| 10 | + | ||
| 11 | + NUMBER_OF_SOFTWARES.times do |i| | ||
| 12 | + number = i < 10 ? "0#{i}" : "#{i}" | ||
| 13 | + software_name = "Software #{number}" | ||
| 14 | + create_software_info(software_name) | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + create_software_info("Ubuntu") | ||
| 18 | + create_software_info("Debian") | ||
| 19 | + create_software_info("Windows XP") | ||
| 20 | + create_software_info("Windows Vista") | ||
| 21 | + create_software_info("Windows 7") | ||
| 22 | + create_software_info("Windows 8") | ||
| 23 | + create_software_info("Disk Operating System", "DOS") | ||
| 24 | + create_software_info("Sublime") | ||
| 25 | + create_software_info("Vi IMproved", "Vim") | ||
| 26 | + create_software_info("Nano") | ||
| 27 | + create_software_info("Gedit") | ||
| 28 | + create_software_info("Firefox") | ||
| 29 | + create_software_info("InkScape") | ||
| 30 | + create_software_info("Eclipse") | ||
| 31 | + create_software_info("LibreOffice") | ||
| 32 | + create_software_info("Tetris") | ||
| 33 | + create_software_info("Mario") | ||
| 34 | + create_software_info("Pong") | ||
| 35 | + create_software_info("Sonic") | ||
| 36 | + create_software_info("Astah") | ||
| 37 | + create_software_info("Pokemom Red") | ||
| 38 | + create_software_info("Mass Effect") | ||
| 39 | + create_software_info("Deus EX") | ||
| 40 | + create_software_info("Dragon Age") | ||
| 41 | + | ||
| 42 | + puts "" | ||
| 43 | + end | ||
| 44 | + end | ||
| 45 | + end | ||
| 46 | +end | ||
| 47 | + | ||
| 48 | +def create_community(name) | ||
| 49 | + community = Community.new | ||
| 50 | + community.name = name | ||
| 51 | + community.save | ||
| 52 | + community | ||
| 53 | +end | ||
| 54 | + | ||
| 55 | +def create_software_info(name, acronym = "") | ||
| 56 | + community = create_community(name) | ||
| 57 | + software_info = SoftwareInfo.new | ||
| 58 | + software_info.community = community | ||
| 59 | + software_info.public_software = true | ||
| 60 | + software_info.acronym = acronym | ||
| 61 | + software_info.license_info = LicenseInfo.first | ||
| 62 | + | ||
| 63 | + if software_info.community.valid? && software_info.valid? | ||
| 64 | + print "." | ||
| 65 | + software_info.save | ||
| 66 | + software_info | ||
| 67 | + else | ||
| 68 | + print "F" | ||
| 69 | + nil | ||
| 70 | + end | ||
| 71 | +end | ||
| 0 | \ No newline at end of file | 72 | \ No newline at end of file |