lib/tasks/zena.rake in zena-0.16.9 vs lib/tasks/zena.rake in zena-1.0.0.beta1

- old
+ new

@@ -6,11 +6,11 @@ RAILS_ENV = 'test' if ARGV.join(' ') =~ /zena:test/ require File.join(File.dirname(__FILE__), '..', 'zena', 'info') # to have Zena::ROOT require File.join(File.dirname(__FILE__), '..', 'bricks') # to have Bricks -Bricks.load_misc('tasks') +Bricks.load_filename('tasks') def symlink_assets(from, to) from = File.expand_path(from) to = File.expand_path(to) return if from == to @@ -252,11 +252,11 @@ # migrate specific bricks only if ENV['BRICK'] == 'zena' # migrate 'db/migrate' Zena::Migrator.migrate("#{Zena::ROOT}/db/migrate", ENV["BRICK"], ENV["VERSION"] ? ENV["VERSION"].to_i : nil) else - mig_path = "#{Zena::ROOT}/bricks/#{ENV['BRICK']}/migrate" + mig_path = Bricks.migrations_for(ENV['BRICK']) if File.exist?(mig_path) && File.directory?(mig_path) Zena::Migrator.migrate(mig_path, ENV["BRICK"], ENV["VERSION"] ? ENV["VERSION"].to_i : nil) else puts "Could not find migrations for brick '#{ENV['BRICK']}' ('#{mig_path}' not found)." end @@ -264,13 +264,12 @@ else # migrate all to latest paths = {'zena' => "#{RAILS_ROOT}/db/migrate"} bricks = ['zena'] - Bricks.foreach_brick do |brick_path| - brick_name = brick_path.split('/').last - migration_path = File.join(brick_path, 'migrate') + Bricks.foreach_brick do |brick_name| + migration_path = Bricks.migrations_for(brick_name) next unless File.exist?(migration_path) && File.directory?(migration_path) paths[brick_name] = migration_path bricks << brick_name end @@ -280,41 +279,79 @@ #ActiveRecord::Migrator.migrate("db/migrate/", nil) end Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby end + desc 'Reset development environment (drop database, migrate, rebuild and load fixtures, clone to test)' + task :reset => :environment do + if RAILS_ENV == 'production' + puts "You cannot reset database in production !" + else + %w{db:drop db:create zena:migrate zena:build_fixtures db:test:clone}.each do |task| + puts "******************************* #{task}" + Rake::Task[task].invoke + end + end + end + desc 'Rebuild foxy fixtures for all sites' task :build_fixtures => :environment do + Dir["#{RAILS_ROOT}/test/fixtures/*.yml"].each do |f| + FileUtils.rm f + end + tables = Node.connection.tables - # 0. # 1. # need vc # vers. # nodes # need vc. # need nodes - ordered_tables = ['virtual_classes', 'versions', 'nodes', 'zips', 'relations', 'links'] + ordered_tables = %w{roles versions nodes attachments zips relations links} + tables -= ordered_tables tables += ordered_tables - virtual_classes, versions, nodes = nil, nil, nil + roles, versions, nodes = nil, nil, nil tables.each do |table| case table - when 'virtual_classes' - virtual_classes = Zena::FoxyParser.new(table) - virtual_classes.run + when 'roles' + roles = Zena::FoxyParser.new(table) + roles.run when 'versions' versions = Zena::FoxyParser.new(table) versions.run when 'nodes' - nodes = Zena::FoxyParser.new(table, :versions => versions, :virtual_classes => virtual_classes) + nodes = Zena::FoxyParser.new(table, :versions => versions, :roles => roles) nodes.run when 'zips' Zena::FoxyParser.new(table, :nodes => nodes).run when 'relations' - Zena::FoxyParser.new(table, :virtual_classes => virtual_classes).run + Zena::FoxyParser.new(table, :roles => roles).run when 'links' Zena::FoxyParser.new(table, :nodes => nodes).run else Zena::FoxyParser.new(table).run end end + + %w{db:fixtures:load zena:rebuild_index}.each do |task| + puts "******************************* #{task}" + Rake::Task[task].invoke + end + + index_tables = Node.connection.tables.select {|t| t =~ /^idx_/ } + Zena::FoxyParser.dump_fixtures(index_tables) end + desc 'Rebuild index for all sites (without SiteWorker)' + task :rebuild_index => :environment do + include Zena::Acts::Secure + + Site.all.each do |site| + # We avoid SiteWorker because it's async. + Thread.current[:visitor] = User.find_by_login_and_site_id(nil, site.id) + nodes = Node.find(:all, + :conditions => ['site_id = ?', site.id] + ) + site.rebuild_index(secure_result(nodes)) + end + end + Rake::RDocTask.new do |rdoc| files = ['README', 'doc/README_FOR_APP', 'CREDITS', 'MIT-LICENSE', 'app/**/*.rb', 'lib/**/*.rb'] rdoc.rdoc_files.add(files) rdoc.main = "doc/README_FOR_APP" # page to start on @@ -332,17 +369,14 @@ FileUtils::rmtree(path) if File.exist?(path) end end end - # do not change the order in which these elements are loaded (adding 'lib/**/test/*_test.rb' fails) - tests = ['test/helpers/**/*_test.rb', 'test/unit/**/*_test.rb', - 'lib/parser/test/*_test.rb', 'lib/query_builder/test/*_test.rb', - 'test/functional/*_test.rb', #'test/integration/*_test.rb', - 'bricks/**/test/unit/*_test.rb', 'bricks/**/test/functional/*_test.rb', - 'bricks/**/test/integration/*_test.rb'].map {|p| "#{Zena::ROOT}/#{p}"} + tests = ['test/unit/**/*_test.rb', 'test/functional/*_test.rb', 'test/integration/*_test.rb'].map {|p| "#{Zena::ROOT}/#{p}"} + tests += Bricks.test_files + Rake::TestTask.new(:test => ["zena:test:prepare", "zena:build_fixtures"]) do |t| t.libs << "test" t.pattern = tests t.verbose = true end @@ -426,10 +460,11 @@ desc "Create the database, migrate, create 'localhost' site and start application (in production environment by default)" task :init do # FIXME: how to run sub-task ENV['RAILS_ENV'] = RAILS_ENV || 'production' ENV['HOST'] ||= 'localhost' - ENV['LANG'] ||= 'en' + ENV['LANG'] = ENV['LANG'].to_s + ENV['LANG'] = 'en' if ENV['LANG'].empty? ENV['PASSWORD'] ||= 'admin' Rake::Task["db:create"].invoke Rake::Task["zena:migrate"].invoke