From 44a0f294490bdceb73688b2eb9475a29b4ecba7d Mon Sep 17 00:00:00 2001 From: Brian Hogan Date: Wed, 7 Jan 2009 23:18:27 -0600 Subject: [PATCH] Removed gem stuff, changed db:import to db:from_yaml and db:export to db:to_yaml, moved tasks around, updated SVN tasks, started something for git that will probably go nowhere. --- README | 109 -------------------------------- README.rdoc | 36 ++++------- tasks/db_translate.rake | 16 ++--- tasks/git.rake | 32 ++++++++-- tasks/lazy_developer_tasks.rake | 54 ++-------------- tasks/svn.rake | 75 ++++++++++++---------- tasks/test_unit.rake | 38 +++++++++++ 7 files changed, 132 insertions(+), 228 deletions(-) delete mode 100644 README create mode 100644 tasks/test_unit.rake diff --git a/README b/README deleted file mode 100644 index 04b4c7b..0000000 --- a/README +++ /dev/null @@ -1,109 +0,0 @@ -=LazyDeveloper - - -Developers are lazy. I know I am. If I have to do things over and over, I want -them to be automated. Maybe that's efficent and not lazy. However, lazy is a -shorter word and it's funnier to call this plugin LazyDeveloper. - -This plugin provides some useful Rake tasks that will make your life a little -eaiser. I use them in many of my projects and I invite you to do the same. - - -= Usage -== Databases - -=== rake db:migrate - -The db:migrate task has been modified slightly. Running this task now clones your -test database, which is really useful if you run tests individually via TextMate -or through the commandline. - -=== rake db:remigrate - -Sometimes you just need to wipe out your database tables and start over. This -task drops your tables and starts over. - -=== rake db:export - -Dump your database to fixtures. Stores them in /test/fixtures/live. You can then use this to load the data -back into another database, even one of a different type - -=== rake db:import -Load fixtures from test/fixures/live into your database. Loads fixtures dumped by using rake db:export - -== Subversion - -=== rake svn:root -Displays the root of your repository - -=== rake svn:tags -Displays all the tags. Assumes you use a tags/ folder and a /trunk folder - -=== rake svn:tags:last -Displays the last tag. - -=== rake svn:tag TAG=rel_1-0-0 -Creates a new tag from the trunk. - -== Rcov -Thanks to Kevin Gisi for these tasks that make running RCov a bit easier. -Requires the RCov gem and the rails_rcov plugin - -=== rake rcov:models -Runs coverage on your models -=== rake rcov:controllers -Runs coverage on your controllers -=== rake rcov:full -Runs coverage on models and controllers - - -== Tests -Based on an idea from Geoffrey Grosenbach, you can run all tests in units\user_test.rb by doing - - rake test:units:user:all - -Or run a specific test by speficying all or part of a name. For example, if I -wanted to run the "test_create" test case, I would use - - rake test:units:user:create - -The same rules apply to functional tests - - rake test:functionals:users:list - -== Gems - -Place a file called .gems in the root of your Rails project. The file should -contain all of the gems you want to install. - - tz_info - rcov - fastercsv - redcloth - -You can install all of these gems easily with - - rake rails:install:gems - -== Plugins - -Create a file in your Home folder called .plugins and you can have all of your -favorite plugins easily installed by doing - - rake rails:install:plugins - -Just put each plugin name or repository on its own line. - -Windows users need to set the HOME environment variable. - -== Cleaning Up - -Run - - rake rails:clear - -to clean up tmp, logs, and docs in one easy command. - - - -Copyright (c) 2007-2008 Brian Hogan except where noted. Released under the MIT license diff --git a/README.rdoc b/README.rdoc index 2507abe..554ccae 100644 --- a/README.rdoc +++ b/README.rdoc @@ -2,35 +2,35 @@ Copyright (C) 2007-2008 Brian P. Hogan and Kevin Gisi Developers are lazy. I know I am. If I have to do things over and over, I want -them to be automated. Maybe that's efficent and not lazy. However, lazy is a +them to be automated. Maybe that's efficient and not lazy. However, lazy is a shorter word and it's funnier to call this plugin LazyDeveloper. This plugin provides some useful Rake tasks that will make your life a little -eaiser. I use them in many of my projects and I invite you to do the same. +easier. I use them in many of my projects and I invite you to do the same. = Usage == Databases === rake db:migrate -The db:migrate task has been modified slightly. Running this task now clones your +Everyone forgets to clone the test database when you make changes, so I decided to override rake:db:migrate. Running this task now clones your test database, which is really useful if you run tests individually via TextMate -or through the commandline. +or through the command line. === rake db:remigrate Sometimes you just need to wipe out your database tables and start over. This task drops your tables and starts over by dropping the tables directly and then re-running your migrations. This provides a great way to test to make sure you -haven't broken migrations at some point. +haven't broken migrations at some point, which *will* happen to you at some point. -=== rake db:export +=== rake db:to_yaml (formerly rake:db:import) -Dump your database to fixtures. Stores them in /test/fixtures/live. You can then use this to load the data -back into another database, even one of a different type +Dump your database to fixtures. Stores them in RAILS_ROOT/production_data. You can then use this to load the data back into another database, even one of a different type. We've used this to move +data from SQL Server to MySQL and back again. -=== rake db:import -Load fixtures from test/fixures/live into your database. Loads fixtures dumped by using rake db:export +=== rake db:from_yaml (formerly rake:db:export) +Load fixtures from RAILS_ROOT/production_data into your database. Loads fixtures dumped by using rake db:export == Subversion @@ -68,7 +68,7 @@ Based on an idea from Geoffrey Grosenbach, you can run all tests in units\user_t rake test:units:user:all -Or run a specific test by speficying all or part of a name. For example, if I +Or run a specific test by specifying all or part of a name. For example, if I wanted to run the "test_create" test case, I would use rake test:units:user:create @@ -95,20 +95,6 @@ some of the built-in specs. rake spec:model:user rake spec:controller:sessions -== Gems (Deprecated - will be removed very, very soon) - -Place a file called .gems in the root of your Rails project. The file should -contain all of the gems you want to install. - - tz_info - rcov - fastercsv - redcloth - -You can install all of these gems easily with - - rake rails:install:gems - == Plugins Create a file in your Home folder called .plugins and you can have all of your diff --git a/tasks/db_translate.rake b/tasks/db_translate.rake index b2bc64e..89cbd46 100644 --- a/tasks/db_translate.rake +++ b/tasks/db_translate.rake @@ -24,7 +24,7 @@ def write_file(filename, contents) end def habtm_fixtures(object) - path = RAILS_ROOT + "/test/fixtures/live" + path = RAILS_ROOT + "/production_data" hatbms = object.reflect_on_all_associations.collect{|i| i if i.macro == :has_and_belongs_to_many}.compact h = Hash.new @@ -56,18 +56,17 @@ end namespace :db do desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y" - task :import => :environment do + task :from_yaml => :environment do require 'active_record/fixtures' ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) - (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures/live', '*.{yml,csv}'))).each do |fixture_file| - Fixtures.create_fixtures('test/fixtures/live', File.basename(fixture_file, '.*')) + (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'production_data', '*.{yml,csv}'))).each do |fixture_file| + Fixtures.create_fixtures('production_data', File.basename(fixture_file, '.*')) end end - desc "Dump all data to fixtures/live folder" - task :export => :environment do - path = RAILS_ROOT + "/test/fixtures/live" - #models = %W{Account Profile Portfolio Item Presentation Publication Experience Proficiency Skill Role} + desc "Dump all data to the production_data folder" + task :to_yaml => :environment do + path = RAILS_ROOT + "/production_data" models= Dir.glob("#{RAILS_ROOT}/app/models/*.rb").collect{|c| c.gsub("#{RAILS_ROOT}/app/models/", "").gsub(".rb", "").camelize} FileUtils.mkdir_p path rescue nil @@ -78,6 +77,7 @@ namespace :db do str = object.to_yaml write_file "#{path}/#{object.table_name}.yml", str + # get the association data for has_and_belongs_to_many habtm_fixtures(object) rescue "skipping - not a model" diff --git a/tasks/git.rake b/tasks/git.rake index bfc12dd..f4e53b4 100644 --- a/tasks/git.rake +++ b/tasks/git.rake @@ -1,10 +1,35 @@ namespace :git do + namespace :stats do + + desc "Show untracked files" + task :untracked do + `git status --untracked` + end + + desc "show number of changes" + task :changes do + `git diff --shortstat` + end + + desc "see the number of commits" + task :commits do + `git log | grep ^commit | wc -l` + end + + end + desc "Commit all modified files and pull" - task :cpush do + task :cpull do `git commit -a -m #{ENV["M"]}` `git pull origin master` end + + desc "Commit all modified files and push" + task :commit do + `git commit -a -m "#{ENV["M"]}"` + `git pull origin master` + end @@ -30,9 +55,6 @@ namespace :git do end - desc "see the number of commits" - task :commits do - `git log | grep ^commit | wc -l` - end + end \ No newline at end of file diff --git a/tasks/lazy_developer_tasks.rake b/tasks/lazy_developer_tasks.rake index 98efdd4..86e7ec7 100644 --- a/tasks/lazy_developer_tasks.rake +++ b/tasks/lazy_developer_tasks.rake @@ -1,44 +1,14 @@ +VERSION=1.1.0 -namespace :test do - - rule /^test/ do |t| - root = t.name.gsub("test:","").split(/:/) - if root.length >= 3 - flag = root[0] - file_name = root[1] - test_name = root[2] - test_name = "" if test_name == "all" - - - functional = (flag == "functionals" || flag == "f") - unit = (flag == "units" || flag == "u") - - - if (unit) - file_path = "unit/#{file_name}_test.rb" - end - - if (functional) - file_path = "functional/#{file_name}_controller_test.rb" - end - - if (!File.exist?("test/#{file_path}")) - raise "No file found for #{file_path}" - end - - sh "ruby test/#{file_path} -n /^test_#{test_name}/" - else - puts "invalid arguments. Specify the type of test, filename, and test name" - end +namespace :lazy do + desc "Shows the version of Lazy Developer this app uses" + task :version do + puts "LazyDeveloper v#{VERSION}" end - - - end - namespace :db do # Override the original Rake task to clone the test database too @@ -86,19 +56,7 @@ namespace :rails do end end - desc "installs the required gems for this project" - task :gems do - sudo = PLATFORM.include?("win32") ? "" : "sudo" - File.open("./.gems", "r") do |f| - while (line = f.gets) - begin - sh "#{sudo} gem install #{line}" - rescue - puts "Couldn't install #{line}" - end - end - - end + end #install diff --git a/tasks/svn.rake b/tasks/svn.rake index eafbbe6..3536038 100644 --- a/tasks/svn.rake +++ b/tasks/svn.rake @@ -1,11 +1,18 @@ def get_svn_root - `svn info | grep URL`.gsub("URL: ", "").gsub("/trunk", "").chop! + `svn info`.grep(/URL/).to_s.gsub("URL: ", "").gsub("/trunk", "").chop! end def get_svn_tags - cmd = "svn ls #{get_svn_root}/tags" - `#{cmd}`.chop! + cmd = "svn ls -v #{get_svn_root}/tags" + # get a full list, sort on date. + tags = `#{cmd}`.to_a.sort! + output = "" + tags.each do |tag| + tmp =tag.split(" ") + output << tmp[5..-1].to_s + "\n" + end + output end @@ -17,17 +24,46 @@ namespace :svn do puts get_svn_root end - desc "create tag - expects TAG='tag_name" + desc "create tag" task :tag do raise "You have to pass a tag name - rake svn:tag TAG=rel_1-0-0" if ENV["TAG"].nil? tagname = ENV["TAG"] - `svn cp #{get_svn_root}/trunk #{get_svn_root}/tags/#{tagname} -m "tag created by Lazy Developer"` + `svn cp #{get_svn_root}/trunk #{get_svn_root}/tags/#{tagname} -m "Created tag #{tagname}"` end + desc "create branch" + task :branch do + raise "You have to pass a tag name - rake svn:tag TAG=rel_1-0-0" if ENV["TAG"].nil? + branch = ENV["branch"] + `svn cp #{get_svn_root}/trunk #{get_svn_root}/branches/#{branch} -m "Created tag #{branch}"` + end + + + namespace :log do + def get_log(limit) + l = limit || 25 + result = `svn log --limit #{l}` + + end + + desc "Fetches the last 25 log entries - override limit wit LIMIT=x" + task :latest do + s = get_log(ENV["LIMIT"]) + puts s + end + + desc "get last log entry" + task :last do + s = get_log(1) + end + + desc "" + + end namespace :tags do - desc "show the last tag, assuming you've used some sort of naming scheme that uses ascending order" + desc "show the last tag" task :last do puts get_svn_tags.split("\n").last @@ -39,31 +75,4 @@ namespace :svn do puts get_svn_tags end - desc "Fix your app for use with Subversion by removing files you might not need." - task :configure_for_svn do - system "svn remove log/*" - system "svn commit -m 'removing all log files from subversion'" - system 'svn propset svn:ignore "*.log" log/' - system "svn update log/" - system "svn commit -m 'Ignoring all files in /log/ ending in .log'" - system 'svn propset svn:ignore "*.db" db/' - system "svn update db/" - system "svn commit -m 'Ignoring all files in /db/ ending in .db'" - system 'svn propset svn:ignore "*.sqlite3" db/' - system "svn update db/" - system "svn commit -m 'Ignoring all files in /db/ ending in .sqlite3'" - system "svn move config/database.yml config/database.example" - system "svn commit -m 'Moving database.yml to database.example to provide a template for anyone who checks out the code'" - system 'svn propset svn:ignore "database.yml" config/' - system "svn update config/" - system "svn commit -m 'Ignoring database.yml'" - system "svn remove tmp/*" - system "svn commit -m 'Removing /tmp/ folder'" - system 'svn propset svn:ignore "*" tmp/' - end - - - - - end \ No newline at end of file diff --git a/tasks/test_unit.rake b/tasks/test_unit.rake new file mode 100644 index 0000000..0a2b019 --- /dev/null +++ b/tasks/test_unit.rake @@ -0,0 +1,38 @@ + +namespace :test do + + rule /^test/ do |t| + root = t.name.gsub("test:","").split(/:/) + if root.length >= 3 + flag = root[0] + file_name = root[1] + test_name = root[2] + test_name = "" if test_name == "all" + + + functional = (flag == "functionals" || flag == "f") + unit = (flag == "units" || flag == "u") + + + if (unit) + file_path = "unit/#{file_name}_test.rb" + end + + if (functional) + file_path = "functional/#{file_name}_controller_test.rb" + end + + if (!File.exist?("test/#{file_path}")) + raise "No file found for #{file_path}" + end + + sh "ruby test/#{file_path} -n /^test_#{test_name}/" + else + puts "invalid arguments. Specify the type of test, filename, and test name" + end + end + + + + +end