Permalink
Browse files

* fixed the rack_datamapper naming problem

* added integration test

* added monkey patch to let generated views spec work with datamapper
  • Loading branch information...
mkristian committed Oct 6, 2009
1 parent 4957a55 commit 4f1e648fe3f259cf3125784cb4b65afb76449e02
View
@@ -1,2 +1,3 @@
pkg
+tmp
*~
View
@@ -25,13 +25,14 @@ lib/datamapper4rails.rb
lib/datamapper4rails/adapters/base_adapter.rb
lib/datamapper4rails/adapters/restful_adapter.rb
lib/datamapper4rails/datamapper_store.rb
+lib/datamapper4rails/integration_test.rb
lib/datamapper4rails/identity_maps.rb
lib/datamapper4rails/overlay.rb
lib/datamapper4rails/preload_models.rb
lib/datamapper4rails/restful_transactions.rb
lib/datamapper4rails/rspec_default_values.rb
+lib/datamapper4rails/rspec.rb
lib/datamapper4rails/version.rb
spec/datamapper_store_spec.rb
-spec/restful_adapter_spec.rb
spec/spec.opts
spec/spec_helper.rb
View
@@ -12,7 +12,7 @@ require './lib/datamapper4rails/version.rb'
Hoe.new('datamapper4rails', Datamapper4rails::VERSION) do |p|
p.rubyforge_name = 'datamapper4rail'
p.developer('mkristian', 'm.kristian@web.de')
- p.extra_deps = ['rack_datamapper', 'rails_datamapper']
+ p.extra_deps = [['rack-datamapper', '~>0.2'], 'rails_datamapper']
p.remote_rdoc_dir = '' # Release to root
end
@@ -30,6 +30,17 @@ Spec::Rake::SpecTask.new(:spec) do |t|
t.spec_files = Pathname.glob('./spec/**/*_spec.rb')
end
+desc 'generate rails using all generators and run the specs'
+task :integration_tests => [:install] do
+ require 'datamapper4rails/integration_test'
+ Datamapper4Rails::IntegrationTest.new do |t|
+ t.generate "datamapper_model role name:string"
+ t.generate "datamapper_scaffold domain name:string"
+ t.generate "datamapper_rspec_model user name:string"
+ t.generate "datamapper_rspec_scaffold group name:string"
+ end
+end
+
require 'yard'
YARD::Rake::YardocTask.new
@@ -23,7 +23,7 @@
rake "gems:install"
# install specs rake tasks
-generate("rspec")
+generate("rspec", "-f")
# install datamapper rake tasks
generate("datamapper_install")
@@ -35,6 +35,10 @@
gsub_file 'spec/spec_helper.rb', /^\s*config[.]/, ' #\0'
gsub_file 'test/test_helper.rb', /^[^#]*fixtures/, ' #\0'
+file 'spec/support/datamapper.rb', <<-CODE
+require 'datamapper4rails/rspec'
+CODE
+
# add middleware
def middleware(name)
log "middleware", name
@@ -60,4 +64,50 @@ def middleware(name)
}
CODE
+# gzip fix for jruby
+initializer 'monkey_patches.rb', <<-CODE
+if RUBY_PLATFORM =~ /java/
+ require 'zlib'
+ class Zlib::GzipWriter
+ def <<(arg)
+ write(arg)
+ end
+ end
+end
+CODE
+
+file 'prepare_jruby.sh', <<-CODE
+#!/bin/bash
+
+echo
+echo "shall freeze rails and fix a bug which prevents rails to use certain"
+echo "java gems like the dataobjects drivers !!"
+echo
+
+mvn --version
+if [ $? -ne 0 ] ; then
+
+ echo "please install maven >= 2.0.9 from maven.apache.org"
+ exit -1
+fi
+
+mvn de.saumya.mojo:rails-maven-plugin:rails-freeze-gems de.saumya.mojo:rails-maven-plugin:gems-install
+
+echo
+echo "you can run rails with (no need to install jruby !!)"
+echo
+echo "\tmvn de.saumya.mojo:rails-maven-plugin:server"
+echo
+echo "more info on"
+echo "\tgithub.org/mkristian/rails-maven-plugin"
+echo
+CODE
+
rake 'db:sessions:create'
+
+logger.info
+logger.info
+logger.info "info mavenized rails application"
+logger.info "\tgithub.org/mkristian/rails-maven-plugin"
+logger.info
+logger.info
View
@@ -1,4 +1,5 @@
require 'rails_datamapper'
+require 'rack-datamapper'
require 'datamapper4rails/datamapper_store'
# keep this here until rails_datamapper has it included
@@ -0,0 +1,45 @@
+module Datamapper4Rails
+ class IntegrationTest
+
+ attr_accessor :generator_args
+
+ attr_accessor :rails_template
+
+ attr_accessor :directory
+
+ def initialize
+ @ruby = RUBY_PLATFORM =~ /java/ ? 'jruby' : 'ruby'
+ @directory = 'tmp'
+ @generator_args = []
+ @rails_template = 'datamapper_rails_templates.rb'
+ yield self if block_given?
+ execute
+ end
+
+ def generate(*args)
+ @generator_args << args.map(&:to_s).join(" ")
+ end
+
+ def execute
+ FileUtils.rm_rf(@directory)
+ run("-S rails -fm #{rails_template} #{directory}")
+ FileUtils.cd(@directory) do
+ @generator_args.each do |arg|
+ run("script/generate #{arg}")
+ end
+ run("-S rake spec")
+ #run("-S rake test:units")
+ end
+
+ end
+
+ def run(command)
+ unless system("#{@ruby} #{command}")
+ puts
+ puts "error in: #{@ruby} #{command}"
+ exit 1
+ end
+ end
+
+ end
+end
@@ -13,9 +13,11 @@ def a.lookup(clazz)
@clazz = clazz
end
a.lookup(self.class)
- def a.add_generator(generator_name, prepend = false)
- path = File.join(@clazz.lookup(generator_name).path, 'templates')
- push(path) unless member? path
+ def a.add_generator(generator_name)
+ unless frozen?
+ path = File.join(@clazz.lookup(generator_name).path, 'templates')
+ push(path) unless member? path
+ end
end
a
end
@@ -40,8 +42,10 @@ def source_path(relative_source)
# first check if the template can be found with in any of the overlay directories
if dirs = options[:overlay_dirs]
generator_name = self.class.name.underscore.sub(/_generator/, '')
- dirs.insert(0, File.join(self.class.lookup(generator_name).path, 'templates'))
-
+ unless dirs.frozen?
+ dirs.insert(0, File.join(self.class.lookup(generator_name).path, 'templates'))
+ dirs.freeze
+ end
file = path.nil? ? name : path
dirs.each do |dir|
if (f = File.join(dir, file)) and File.exists?(f)
@@ -0,0 +1,8 @@
+module DataMapper
+ module Resource
+
+ def has_attribute?(name)
+ properties[name] != nil
+ end
+ end
+end
@@ -1,3 +1,3 @@
class Datamapper4rails
- VERSION = '0.2.0'
+ VERSION = '0.2.0'.freeze
end
Oops, something went wrong.

0 comments on commit 4f1e648

Please sign in to comment.