diff options
Diffstat (limited to 'vendor/plugins/rake_tasks/tasks')
-rw-r--r-- | vendor/plugins/rake_tasks/tasks/deprecated.rake | 10 | ||||
-rw-r--r-- | vendor/plugins/rake_tasks/tasks/environment.rake | 9 | ||||
-rw-r--r-- | vendor/plugins/rake_tasks/tasks/spec.rake | 122 | ||||
-rw-r--r-- | vendor/plugins/rake_tasks/tasks/svn.rake | 59 |
4 files changed, 200 insertions, 0 deletions
diff --git a/vendor/plugins/rake_tasks/tasks/deprecated.rake b/vendor/plugins/rake_tasks/tasks/deprecated.rake new file mode 100644 index 000000000..4311c3bd1 --- /dev/null +++ b/vendor/plugins/rake_tasks/tasks/deprecated.rake @@ -0,0 +1,10 @@ +namespace :deprecated do + namespace :convert do + desc 'Moves .rhtml files to a file with .erb extension for subversion' + task :erb => :environment do + Convert::Mover.find(:rhtml).each do |rhtml| + rhtml.move :erb, :scm => :svn + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rake_tasks/tasks/environment.rake b/vendor/plugins/rake_tasks/tasks/environment.rake new file mode 100644 index 000000000..223bba3e5 --- /dev/null +++ b/vendor/plugins/rake_tasks/tasks/environment.rake @@ -0,0 +1,9 @@ +# +# Thanks to Chris for this handy task (http://errtheblog.com/post/33) +# +%w[development test production].each do |env| + desc "Runs the following task in the #{env} environment" + task env do + RAILS_ENV = ENV['RAILS_ENV'] = env + end +end
\ No newline at end of file diff --git a/vendor/plugins/rake_tasks/tasks/spec.rake b/vendor/plugins/rake_tasks/tasks/spec.rake new file mode 100644 index 000000000..9f07b0100 --- /dev/null +++ b/vendor/plugins/rake_tasks/tasks/spec.rake @@ -0,0 +1,122 @@ +namespace :spec do + unless defined?(RAILS_ROOT) + root_path = File.join(File.dirname(__FILE__), '..') + unless RUBY_PLATFORM =~ /mswin32/ + require 'pathname' + root_path = Pathname.new(root_path).cleanpath(true).to_s + end + RAILS_ROOT = root_path + end + + require "#{RAILS_ROOT}/config/environment" + + PROJ_DIR = "#{RAILS_ROOT}/app/" + + def view_ext + if ActionView::Base.const_defined?('DEFAULT_TEMPLATE_HANDLER_PREFERENCE') && + ActionView::Base::DEFAULT_TEMPLATE_HANDLER_PREFERENCE.include?(:erb) then + return ".html.erb" + else + return ".rhtml" + end + end + + def find_untested_ruby_files + files = {} + `find #{PROJ_DIR} -name '*.rb'`.split(/\n/).each do |file| + spec_file = file.sub('/app/', '/spec/').sub('.rb', '_spec.rb') + type = (File.dirname(file).split("/").last == "models" ? "model" : "controller") + File.exists?(spec_file) ? next : files[spec_file] = type + end + files + end + + def find_untested_view_files + files = {} + `find #{PROJ_DIR} -name '*#{view_ext}'`.split(/\n/).each do |file| + spec_file = file.sub('/app/', '/spec/').sub(view_ext, "#{view_ext}_spec.rb") + type = File.dirname(file).split("/").last + File.exists?(spec_file) ? next : files[spec_file] = type + end + files + end + + desc "Check files in the app directory for corresponding test files in the spec directory." + task :check do + files = find_untested_ruby_files.merge(find_untested_view_files) + unless files.empty? + puts "Missing test files:" + files.each {|file, type| puts " #{file}"} + puts + puts "Run the following command(s) to create the missing files:" + puts " rake spec:sync" + end + end + + desc "Check for missing test files in the spec directory and create them if they don't exist." + task :sync do + # Check if an application_controller file exists... hopefully it does not. + has_application_controller = File.exists?("#{PROJ_DIR}/controllers/application_controller.rb") + + files = find_untested_ruby_files + unless files.empty? + files.each do |file, type| + # Get rid of the _spec and file extension + name = File.basename(file).sub("_spec.rb", "").sub(/(_controller|_helper)/, "") + + has_controller = has_helper = false + if type == "controller" + has_controller = File.exists?("#{PROJ_DIR}/controllers/#{name}_controller.rb") + has_helper = File.exists?("#{PROJ_DIR}/helpers/#{name}_helper.rb") + end + + options = "--skip" + options += " --skip-migration" if type == "model" + puts `script/generate rspec_#{type} #{options} #{name} | grep create` + + unless has_controller + FileUtils.rm "#{PROJ_DIR}/controllers/#{name}_controller.rb" if File.exists?("#{PROJ_DIR}/controllers/#{name}_controller.rb") + FileUtils.rm "#{PROJ_DIR}/../spec/controllers/#{name}_controller_spec.rb" if File.exists?("#{PROJ_DIR}/../spec/controllers/#{name}_controller_spec.rb") + end + + unless has_helper + FileUtils.rm "#{PROJ_DIR}/helpers/#{name}_helper.rb" if File.exists?("#{PROJ_DIR}/helpers/#{name}_helper.rb") + FileUtils.rm "#{PROJ_DIR}/../spec/helpers/#{name}_helper_spec.rb" if File.exists?("#{PROJ_DIR}/../spec/helpers/#{name}_helper_spec.rb") + end + end + end + + files = find_untested_view_files + unless files.empty? + action_list = {} + files.each do |file, controller| + action = File.basename(file)[0..-9].sub(view_ext, "") + + if action_list[controller].blank? + action_list[controller] = action + else + action_list[controller] = "#{action_list[controller]} #{action}" + end + end + + action_list.each do |controller, actions| + next if actions.blank? + + has_controller = File.exists?("#{PROJ_DIR}/controllers/#{controller}_controller.rb") + has_helper = File.exists?("#{PROJ_DIR}/helpers/#{controller}_helper.rb") + + puts `script/generate rspec_controller --skip #{controller} #{actions} | grep create` + + unless has_controller + FileUtils.rm "#{PROJ_DIR}/controllers/#{controller}_controller.rb" + FileUtils.rm "#{PROJ_DIR}/../spec/controllers/#{controller}_controller_spec.rb" + end + + unless has_helper + FileUtils.rm "#{PROJ_DIR}/helpers/#{controller}_helper.rb" + FileUtils.rm "#{PROJ_DIR}/../spec/helpers/#{controller}_helper_spec.rb" + end + end + end + end +end diff --git a/vendor/plugins/rake_tasks/tasks/svn.rake b/vendor/plugins/rake_tasks/tasks/svn.rake new file mode 100644 index 000000000..5da3cab56 --- /dev/null +++ b/vendor/plugins/rake_tasks/tasks/svn.rake @@ -0,0 +1,59 @@ +namespace :svn do + desc 'Adds new files to subversion' + task :add do + `svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add` + end + + desc 'Removes missing files from subversion' + task :remove do + `svn status | grep '^\!' | sed -e 's/! *//' | sed -e 's/ /\ /g' | xargs svn remove` + end + + desc 'Deletes unknown files' + task :delete do + `svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs rm -Rf` + end + + desc 'Configures svn:ignore properties on log, tmp, db/schema.rb and config/database.yml' + task :ignore => :environment do + ignore :log => '*' + ignore :tmp => '*' + ignore :db => ['schema.rb', '*.sqlite3'] + ignore :config => 'database.yml' + end + + desc 'Resolves all svn conflicts by keeping the working file' + task :conflicts do + `svn status | grep '^C' | sed -e 's/C *//' | sed -e 's/ /\ /g'`.split("\n").each do |conflict| + `mv #{conflict}.working #{conflict}` + `rm #{conflict}.merge-*` + end + end +end + +private + +def ignore(files) + files.each_pair do |location, pattern| + case pattern + when Array + pattern.each { |p| ignore(location => p) } + when String + remove_versioned_files(location, pattern) + update_ignore_property(location, pattern) + end + end +end + +def remove_versioned_files(location, pattern) + path = File.join(location.to_s, pattern) + FileUtils.mv(path, "#{path}.tmp") if File.exists? path + `svn remove '#{path}' --force` + FileUtils.mv("#{path}.tmp", path) if File.exists? "#{path}.tmp" +end + +def update_ignore_property(location, pattern) + ignored_patterns = `svn propget svn:ignore #{location}`.split(/\s/) + ignored_patterns << pattern unless ignored_patterns.include? pattern + `svn propset svn:ignore '#{ignored_patterns.join("\n")}' #{location}` +end
\ No newline at end of file |