Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 4f1e648fe3f259cf3125784cb4b65afb76449e02 1 parent 4957a55
@mkristian authored
View
1  .gitignore
@@ -1,2 +1,3 @@
pkg
+tmp
*~
View
3  Manifest.txt
@@ -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
13 Rakefile
@@ -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
View
52 datamapper_rails_templates.rb
@@ -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  lib/datamapper4rails.rb
@@ -1,4 +1,5 @@
require 'rails_datamapper'
+require 'rack-datamapper'
require 'datamapper4rails/datamapper_store'
# keep this here until rails_datamapper has it included
View
45 lib/datamapper4rails/integration_test.rb
@@ -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
View
14 lib/datamapper4rails/overlay.rb
@@ -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)
View
8 lib/datamapper4rails/rspec.rb
@@ -0,0 +1,8 @@
+module DataMapper
+ module Resource
+
+ def has_attribute?(name)
+ properties[name] != nil
+ end
+ end
+end
View
2  lib/datamapper4rails/version.rb
@@ -1,3 +1,3 @@
class Datamapper4rails
- VERSION = '0.2.0'
+ VERSION = '0.2.0'.freeze
end
View
204 spec/restful_adapter_spec.rb
@@ -1,204 +0,0 @@
-$LOAD_PATH << File.dirname(__FILE__)
-require 'spec_helper'
-require 'datamapper4rails/adapters/restful_adapter'
-require 'slf4r/ruby_logger'
-
-class Item
- include DataMapper::Resource
-
- property :id, Serial
- property :name, String
-
- belongs_to :group
-end
-class User
- include DataMapper::Resource
-
- property :id, Serial
-
- belongs_to :container
- has n, :groups, :through => Resource
-end
-class Group
- include DataMapper::Resource
-
- property :id, Serial
-
- has n, :users, :through => Resource
- has n, :items
-end
-
-class Container
- include DataMapper::Resource
-
- property :id, Serial
-
- has 1, :user
-
- def items
- @items ||= []
- end
-end
-
-def mock_attribute(name)
- attr = Object.new
- def attr.name
- @name
- end
- def attr.name=(name)
- @name = name
- end
- attr.name= name
- attr
-end
-
-def mock_item(stubs={})
- @mock_item ||= mock(Item, stubs)
-end
-
-def mock_query(stubs={})
- @mock_query ||= mock(DataMapper::Query, stubs)
-end
-
-describe DataMapper::Adapters::RestfulAdapter do
-
- before :each do
- @adapter = DataMapper::Adapters::RestfulAdapter.new(:name, "uri://")
-
- def @adapter.key_value_from_query(query)
- 432
- end
- def @adapter.resource_name_from_query(query)
- "item"
- end
- def @adapter.http_put(uri, data)
- @uri = uri
- @data = data
- end
- def @adapter.http_delete(uri)
- @uri = uri
- end
- def @adapter.data
- @data
- end
- def @adapter.uri
- @uri
- end
- def @adapter.body=(b)
- @body = b
- end
- def @adapter.send_request
- res = Object.new
- def res.body=(b)
- @body = b
- end
- def res.body
- @body
- end
- def res.kind_of?(clazz)
- true
- end
- res.body= @body
- res
- end
-
- end
-
- it 'should create an Item' do
- @adapter.body = "<item><id>123</id><name>zappa</name></item>"
-
- item = Item.new
- @adapter.create_resource(item).should == item
- item.id.should == 123
- item.name.should == 'zappa'
- end
-
- it 'should update an Item' do
- mock_item.should_receive(:to_query)
- mock_item.should_receive(:name).and_return("item")
- mock_item.should_receive(:to_xml)
-
- @adapter.update_resource(mock_item, mock_attribute(:name) => "frank zappa")
-
- @adapter.data.should == "<item><name>frank zappa</name></item>"
- end
-
- it 'should update Items' do
- mock_query.should_receive(:limit).and_return(1)
- @adapter.update({mock_attribute(:name) => "frank zappa"}, mock_query)
-
- @adapter.data.should == "<item><name>frank zappa</name></item>"
- end
-
- it 'should delete an Item' do
- mock_item.should_receive(:name).and_return("item")
- mock_item.should_receive(:to_query)
- @adapter.delete_resource(mock_item)
- @adapter.uri.should == "/items/432.xml"
- end
-
- it 'should delete Items' do
- mock_query.should_receive(:limit).and_return(1)
- @adapter.delete(mock_query)
-
- @adapter.uri.should == "/items/432.xml"
- end
-
- it 'should read an Item' do
- @adapter.body = "<item><id>123</id><name>zappa</name></item>"
-
- query = DataMapper::Query.new(Item.new.repository, Item)
- item = @adapter.read_resource(query)
- item.id.should == 123
- item.name.should == 'zappa'
- end
-
- it 'should read Items' do
- @adapter.body = "<items type='array'><item><id>123</id><name>zappa</name></item></items>"
-
- query = DataMapper::Query.new(Item.new.repository, Item)
- items = @adapter.read_resources(query)
- items.size.should == 1
- items[0].id.should == 123
- items[0].name.should == 'zappa'
- end
-#end
-
-
-#describe 'associations of ' + DataMapper::Adapters::RestfulAdapter.to_s do
- it 'should read nested resource (belongs_to)' do
- @adapter.body = "<item><id>123</id><name>zappa</name>" +
- "<group><id>342</id>" + #<items tpye='array'><item><id>1234</id><name>frank zappa</name></item></items>" +
- "</group>" +
- "</item>"
-
- query = DataMapper::Query.new(Item.new.repository, Item)
- item = @adapter.read_resource(query)
- item.id.should == 123
- item.name.should == 'zappa'
- item.group.id.should == 342
- end
-
- it 'should read nested resource manual "has n"' do
- @adapter.body = "<container><id>342</id><items type='array'>" +
- "<item><id>543</id><name>hmm</name></item>" +
- "</items></container>"
-
- query = DataMapper::Query.new(Container.new.repository, Container)
- c = @adapter.read_resource(query)
- c.id.should == 342
- c.items.size.should == 1
- c.items[0].id.should == 543
- c.items[0].name.should == 'hmm'
- end
-
-# it 'should read nested resource (has 1)' do
-# @adapter.body = "<container><id>342</id>" +
-# "<user><id>543</id></user>" +
-# "</container>"
-
-# query = DataMapper::Query.new(Container.new.repository, Container)
-# c = @adapter.read_resource(query)
-# c.id.should == 342
-# end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.