From: Anders Nguyen Date: 2010-10-12T17:42:27+09:00 Subject: rake aborted! Validation failed: Trying to populate a database with some users using rake db:populate. But im getting this error trace: ** Invoke db:populate (first_time) ** Invoke db:populate:accounts (first_time) ** Invoke db:populate:setup (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:populate:setup ** Execute db:populate:accounts [populate] accounts rake aborted! Validation failed: Logo failed to be processed. /home/andersnguyen/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/validations.rb:1090:in `save_without_dirty!' /home/andersnguyen/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/dirty.rb:87:in `save_without_transactions!' /home/andersnguyen/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:200:in `save!' /home/andersnguyen/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction' /home/andersnguyen/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:182:in `transaction' /home/andersnguyen/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:200:in `save!' /home/andersnguyen/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:208:in `rollback_active_record_state!' /home/andersnguyen/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:200:in `save!' /usr/lib/ruby/gems/1.8/gems/machinist-1.0.6/lib/machinist/active_record.rb:55:in `make' /home/andersnguyen/rubyprojects/mediapilot/lib/tasks/populate.rake:35 /usr/lib/ruby/1.8/rake.rb:636:in `call' /usr/lib/ruby/1.8/rake.rb:636:in `execute' /usr/lib/ruby/1.8/rake.rb:631:in `each' /usr/lib/ruby/1.8/rake.rb:631:in `execute' /usr/lib/ruby/1.8/rake.rb:597:in `invoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' /usr/lib/ruby/1.8/rake.rb:590:in `invoke_with_call_chain' /usr/lib/ruby/1.8/rake.rb:607:in `invoke_prerequisites' /usr/lib/ruby/1.8/rake.rb:604:in `each' /usr/lib/ruby/1.8/rake.rb:604:in `invoke_prerequisites' /usr/lib/ruby/1.8/rake.rb:596:in `invoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' /usr/lib/ruby/1.8/rake.rb:590:in `invoke_with_call_chain' /usr/lib/ruby/1.8/rake.rb:583:in `invoke' /usr/lib/ruby/1.8/rake.rb:2051:in `invoke_task' /usr/lib/ruby/1.8/rake.rb:2029:in `top_level' /usr/lib/ruby/1.8/rake.rb:2029:in `each' /usr/lib/ruby/1.8/rake.rb:2029:in `top_level' /usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling' /usr/lib/ruby/1.8/rake.rb:2023:in `top_level' /usr/lib/ruby/1.8/rake.rb:2001:in `run' /usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling' /usr/lib/ruby/1.8/rake.rb:1998:in `run' /usr/bin/rake:28 here is the populate.db file: # encoding: utf-8 class Range def random rand(last - first + 1) + first end end namespace :db do desc "Erase and fill database" task :populate => [ 'db:populate:accounts', 'db:populate:users', 'db:populate:memberships', 'db:populate:feeds', 'db:populate:events', 'db:populate:sources', 'db:populate:editorials', 'db:populate:social_posts', 'db:populate:variables', 'db:populate:statistics', 'feed:retrieve' ] namespace :populate do task :setup => :environment do require File.join(Rails.root, 'spec', 'blueprints') end task :accounts => 'db:populate:setup' do puts "[populate] accounts" Account.delete_all Account.make(:name => 'SJ', :logo => File.open(Rails.root.join('features/fixtures/logo-sj.png'))) Account.make(:name => 'Telia', :logo => File.open(Rails.root.join('features/fixtures/logo-telia.png'))) Account.make(:name => 'Stena Line', :logo => File.open(Rails.root.join('features/fixtures/logo-stena.png'))) Account.make(:name => 'Max', :logo => File.open(Rails.root.join('features/fixtures/logo-max.png'))) Account.make(:name => 'Coop', :logo => File.open(Rails.root.join('features/fixtures/logo-coop.png'))) end task :users => 'db:populate:setup' do puts "[populate] users" User.delete_all User.make(:password => 'test1234', :email => "admin@elabs.se", :role => 'admin', :locale => "en") User.make(:password => 'test1234', :email => "analyst@elabs.se", :role => 'analyst', :locale => "en") User.make(:password => 'test1234', :email => "customer@elabs.se", :role => 'customer', :locale => "en") User.make(:password => 'test1234', :email => "swedish@elabs.se", :role => 'admin', :locale => "sv") 12.times { User.make(:role => (User::ROLES - ['Admin']).rand) } end task :memberships => 'db:populate:setup' do puts "[populate] memberships" Membership.delete_all User.find(:all, :conditions => "role != 'Admin'").each do | user | if user.customer? user.accounts << Account.random else (1..4).random.times { user.accounts << Account.random } end end end task :sources => 'db:populate:setup' do puts "[populate] sources" Source.delete_all Source.make(:name => 'Aftonbladet', :circulation => 1_232_432, :category => 'popular') Source.make(:name => 'DN', :circulation => 1_632_653, :category => 'large_city') Source.make(:name => 'Expressen', :circulation => 823_583, :category => 'popular') Source.make(:name => 'Göteborgs-Posten', :circulation => 442_556, :category => 'large_city') Source.make(:name => 'Sydsvenska Dagbladet', :circulation => 350_834, :category => 'local') Source.make(:name => 'Dagens Industri', :circulation => 2_342_342, :category => 'trade') Source.make(:name => 'Engadget', :circulation => 7_234_618, :category => 'trade') Source.make(:name => 'Tech Crunch', :circulation => 13_546_245, :category => 'trade') Source.make(:name => 'Wired', :circulation => 1_350_000, :category => 'trade') end task :feeds => 'db:populate:setup' do puts "[populate] feeds" Feed.delete_all Account.all.each do | account | [ ['http://www.dn.se/m/rss/toppnyheter', "DN.se toppnyheter"], ['http://www.gp.se/1.16943', 'Göteborgsposten'], ['http://www.aftonbladet.se/sportbladet/rss.xml', 'Aftonbladet sportnyheter'], ['http://www.sr.se/rssfeed/rssfeed.aspx?rssfeed=83&format=1', 'Sveriges Radio EKOT'] ].each do | url, name | account.feeds.make(:name => name, :url => url, :category => 'editorial') end [ ['http://twitter.com/statuses/user_timeline/17023971.rss', "eLabs on Twitter", false], ['http://twitter.com/statuses/user_timeline/23775395.rss', 'MediaPilot on Twitter', false], ['http://friendfeed.com/cjkihlbom?format=atom', 'CJ Kihlbom on FriendFeed', true], ['http://feeds.digg.com/digg/upcoming.rss', 'Fresh stuff on Digg', true] ].each do | url, name, preview | account.feeds.make(:name => name, :url => url, :category => 'social', :preview => preview) end end end task :events => 'db:populate:setup' do puts "[populate] events" Event.delete_all Account.all.each do | account | (10..15).random.times { Event.make(:account => account) } end end task :editorials => 'db:populate:setup' do puts "[populate] editorials" Editorial.delete_all Account.all.each do | account | (60..100).random.times { Editorial.make(:printed, :account => account, :event => account.events.random, :source => Source.random) } account.editorial_feed_items.each do | item | Editorial.make(:web, :account => account, :feed_item => item, :url => item.url, :headline => item.title, :event => account.events.random, :source => Source.random) if(rand(2).zero?) end end end task :social_posts => 'db:populate:setup' do puts "[populate] social_posts" SocialPost.delete_all Account.all.each do | account | account.social_feed_items.each do | item | SocialPost.make(:account => account, :feed_item => item, :headline => item.title) if(rand(2).zero?) end end end task :variables => 'db:populate:setup' do puts "[populate] custom variables" Variable.delete_all VariableOption.delete_all EditorialVariableOption.delete_all SocialPostVariableOption.delete_all Account.all.each do | account | products = account.variables.make(:name => 'Products', :multiple_choice => true, :category => 'editorial') %w(Fanta Sprite Cola).each do | option_name | products.options.make(:name => option_name) end flavors = account.variables.make(:name => 'Flavors', :multiple_choice => false, :category => 'editorial') %w(Sweet Sour Bitter Salty).each do | option_name | flavors.options.make(:name => option_name) end sugar_content = account.variables.make(:name => 'Sugar Content', :multiple_choice => false, :category => 'social') %w(Diabetes High Medium Low).each do | option_name | sugar_content.options.make(:name => option_name) end product_options = products.options flavor_options = flavors.options account.editorials.each do | editorial | editorial.variable_options.push(*product_options.shuffle[0,rand(4)]) editorial.variable_options.push(flavor_options.rand) end sugar_content_options = sugar_content.options account.social_posts.each do | social_post | social_post.variable_options.push(sugar_content_options.rand) end end end task :statistics => 'db:populate:setup' do puts '[populate] statistics' Statistic.delete_all Account.all.each do | account | account.statistics.make(:pie, :category => 'editorial', :name => 'Favorability Overview', :group_parameter_one_type => 'favorability') account.statistics.make(:bar, :category => 'editorial', :name => 'Media types', :group_parameter_one_type => 'medium', :group_parameter_two_type => nil) sugar_content = account.variables.find_by_name('Sugar Content') account.statistics.make(:bar, :category => 'social', :name => 'Sugar content per favorability', :group_parameter_one_type => "variable_#{sugar_content.id}", :group_parameter_two_type => 'favorability') account.statistics.make(:line, :category => 'social', :name => 'Development of Comments', :group_parameter_one_type => 'time_months', :group_parameter_two_type => 'comments') end end end end -- Posted via http://www.ruby-forum.com/.