Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

Commit

Permalink
Removed gem stuff, changed db:import to db:from_yaml and db:export to…
Browse files Browse the repository at this point in the history
… db:to_yaml, moved tasks around, updated SVN tasks, started something for git that will probably go nowhere.
  • Loading branch information
napcs committed Jan 8, 2009
1 parent eca1415 commit 44a0f29
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 228 deletions.
109 changes: 0 additions & 109 deletions README

This file was deleted.

36 changes: 11 additions & 25 deletions README.rdoc
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tasks/db_translate.rake
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down
32 changes: 27 additions & 5 deletions 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



Expand All @@ -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
54 changes: 6 additions & 48 deletions 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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 44a0f29

Please sign in to comment.