diff options
-rw-r--r-- | vendor/plugins/rake_tasks/MIT-LICENSE | 20 | ||||
-rw-r--r-- | vendor/plugins/rake_tasks/README | 30 | ||||
-rw-r--r-- | vendor/plugins/rake_tasks/init.rb | 1 | ||||
-rw-r--r-- | vendor/plugins/rake_tasks/lib/convert.rb | 47 | ||||
-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 | ||||
-rw-r--r-- | vendor/plugins/rake_tasks/test/fixtures/views/tests/test.liquid | 0 | ||||
-rw-r--r-- | vendor/plugins/rake_tasks/test/fixtures/views/tests/test.rhtml | 0 | ||||
-rw-r--r-- | vendor/plugins/rake_tasks/test/fixtures/views/tests/test.rjs | 0 | ||||
-rw-r--r-- | vendor/plugins/rake_tasks/test/fixtures/views/tests/test.rxml | 0 | ||||
-rw-r--r-- | vendor/plugins/rake_tasks/test/unit/rhtml_test.rb | 39 |
13 files changed, 337 insertions, 0 deletions
diff --git a/vendor/plugins/rake_tasks/MIT-LICENSE b/vendor/plugins/rake_tasks/MIT-LICENSE new file mode 100644 index 000000000..1aea3fb6b --- /dev/null +++ b/vendor/plugins/rake_tasks/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2007 Integrum Technologies, LLC + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file diff --git a/vendor/plugins/rake_tasks/README b/vendor/plugins/rake_tasks/README new file mode 100644 index 000000000..3d7f74a87 --- /dev/null +++ b/vendor/plugins/rake_tasks/README @@ -0,0 +1,30 @@ +rake_tasks +========== + +Overview +-------- + +Adds the following Rake tasks: + + rake db:create # Creates the databases defined in your config/database.yml (unless they already exist) + rake db:drop # Drops the database for your currenet RAILS_ENV as defined in config/database.yml + rake db:reset # Drops, creates and then migrates the database for your current RAILS_ENV + rake db:shell # Launches the database shell using the values defined in config/database.yml + + rake svn:add # Adds new files to subversion + rake svn:remove # Removes missing files from subversion + rake svn:ignore # Configures svn:ignore properties on log, tmp, db/schema.rb and config/database.yml + rake svn:conflicts # Resolves all svn conflicts by keeping the working file + + rake spec:check # Check files in the app directory for corresponding test files in the spec directory. + rake spec:sync # Check for missing test files in the spec directory and create them if they don't exist. + +Authors +------- + + Josh Knowles joshknowles@gmal.com + Matt Heidemann matthew.heidemann@gmail.com + Matt Aimonetti mattaimonetti@gmail.com + Curtis Miller curtm95@gmail.com + +Copyright (c) 2007 Integrum Technologies, LLC, released under the MIT license
\ No newline at end of file diff --git a/vendor/plugins/rake_tasks/init.rb b/vendor/plugins/rake_tasks/init.rb new file mode 100644 index 000000000..b8faeb6b4 --- /dev/null +++ b/vendor/plugins/rake_tasks/init.rb @@ -0,0 +1 @@ +require 'convert'
\ No newline at end of file diff --git a/vendor/plugins/rake_tasks/lib/convert.rb b/vendor/plugins/rake_tasks/lib/convert.rb new file mode 100644 index 000000000..d74b1be40 --- /dev/null +++ b/vendor/plugins/rake_tasks/lib/convert.rb @@ -0,0 +1,47 @@ +module Convert + # allows different paths for searching to be set + def self.view_path=(path) + @@view_path = path + end + + def self.view_path + @@view_path ||= RAILS_ROOT+'/app/views/' + end + + # Given a file extension will search for all files recursively in a directory + # and move the files using the move command or subversion move command + # + # Example: + # + # Convert::Mover.find(:rhtml).each do |rhtml| + # rhtml.move :erb, :scm => :svn + # end + # + # This will find all .rhtml files within the views directory and move each file + # to a erb extension using subversion + class Mover + + def self.find(file_extension) + files = File.join(Convert::view_path,'**', "*.#{file_extension}") + Dir.glob(files).collect do |path| + self.new(path, file_extension) + end + end + + def initialize(file_path, file_extension) + @file_path = file_path + @file_extension = file_extension + end + + def move_command(move_to_extension, options = {}) + original_path = File.expand_path(@file_path) + new_path = original_path.gsub(".#{@file_extension}", ".#{move_to_extension}") + + "#{options[:scm]} mv #{original_path} #{new_path}".lstrip + end + + def move(move_to_extension, options = {}) + system self.move_command(move_to_extension, options) + end + end +end
\ No newline at end of file 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 diff --git a/vendor/plugins/rake_tasks/test/fixtures/views/tests/test.liquid b/vendor/plugins/rake_tasks/test/fixtures/views/tests/test.liquid new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/vendor/plugins/rake_tasks/test/fixtures/views/tests/test.liquid diff --git a/vendor/plugins/rake_tasks/test/fixtures/views/tests/test.rhtml b/vendor/plugins/rake_tasks/test/fixtures/views/tests/test.rhtml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/vendor/plugins/rake_tasks/test/fixtures/views/tests/test.rhtml diff --git a/vendor/plugins/rake_tasks/test/fixtures/views/tests/test.rjs b/vendor/plugins/rake_tasks/test/fixtures/views/tests/test.rjs new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/vendor/plugins/rake_tasks/test/fixtures/views/tests/test.rjs diff --git a/vendor/plugins/rake_tasks/test/fixtures/views/tests/test.rxml b/vendor/plugins/rake_tasks/test/fixtures/views/tests/test.rxml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/vendor/plugins/rake_tasks/test/fixtures/views/tests/test.rxml diff --git a/vendor/plugins/rake_tasks/test/unit/rhtml_test.rb b/vendor/plugins/rake_tasks/test/unit/rhtml_test.rb new file mode 100644 index 000000000..9597e70c6 --- /dev/null +++ b/vendor/plugins/rake_tasks/test/unit/rhtml_test.rb @@ -0,0 +1,39 @@ +require 'test/unit' +require '../../lib/convert' + +class MoverTest < Test::Unit::TestCase + def setup + Convert.view_path = '../fixtures/views/' + + @rhtml = File.expand_path('../fixtures/views/tests/test.rhtml') + @erb = @rhtml.gsub('.rhtml', '.erb') + end + + def teardown + Dir.glob(File.join(Convert.view_path, '**', '*.erb')) do |file| + mv_file = file.gsub('.erb', '.rhtml') + system "mv #{file} #{mv_file}" + end + end + + def test_should_find_files_with_rhtml_extension + assert_equal 1, Convert::Mover.find(:rhtml).size + end + + def test_should_output_svn_system_call_text + rhtml_files = Convert::Mover.find :rhtml + assert_equal "mv #{@rhtml} #{@erb}", rhtml_files.first.move_command(:erb) + assert_equal "svn mv #{@rhtml} #{@erb}", rhtml_files.first.move_command(:erb, :scm => :svn) + end + + def test_should_move_files_locally + assert File.exist?(@rhtml) + assert !File.exist?(@erb) + + rhtml_files = Convert::Mover.find :rhtml + rhtml_files.first.move(:erb) + + assert !File.exist?(@rhtml) + assert File.exist?(@erb) + end +end
\ No newline at end of file |