Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* cleaned up the generators

* simplified the overlay api

* moved overlay and default values to lib so other generators can use them too
  • Loading branch information...
commit 27e855f0a6b4e5d223c66949c3b78e4ad4e10730 1 parent a49a4c3
@mkristian authored
Showing with 294 additions and 419 deletions.
  1. +17 −15 Manifest.txt
  2. +2 −2 Rakefile
  3. +0 −12 generators/datamapper_controller/datamapper_controller_generator.rb
  4. +12 −0 generators/datamapper_install/datamapper_install_generator.rb
  5. +42 −0 generators/datamapper_install/templates/datamapper.rake
  6. +8 −4 generators/datamapper_model/datamapper_model_generator.rb
  7. +2 −1  generators/datamapper_model/templates/model.rb
  8. +0 −8 generators/datamapper_model/templates/unit_test.rb
  9. +18 −0 generators/datamapper_rspec_model/datamapper_rspec_model_generator.rb
  10. +1 −1  generators/{rspec_datamapper_model → datamapper_rspec_model}/templates/model_spec.rb
  11. +20 −0 generators/datamapper_rspec_scaffold/datamapper_rspec_scaffold_generator.rb
  12. +1 −4 generators/{rspec_datamapper_scaffold → datamapper_rspec_scaffold}/templates/controller_spec.rb
  13. +31 −0 generators/datamapper_scaffold/datamapper_scaffold_generator.rb
  14. +1 −1  generators/{rspec_datamapper_scaffold → datamapper_scaffold}/templates/controller.rb
  15. +49 −0 generators/datamapper_scaffold/templates/functional_test.rb
  16. +18 −0 generators/datamapper_scaffold/templates/view_edit.html.erb
  17. +24 −0 generators/datamapper_scaffold/templates/view_index.html.erb
  18. +17 −0 generators/datamapper_scaffold/templates/view_new.html.erb
  19. +10 −0 generators/datamapper_scaffold/templates/view_show.html.erb
  20. +0 −8 generators/rspec_datamapper_controller/rspec_datamapper_controller_generator.rb
  21. +0 −111 generators/rspec_datamapper_controller/templates/controller.rb
  22. +0 −189 generators/rspec_datamapper_controller/templates/controller_spec.rb
  23. +0 −2  generators/rspec_datamapper_controller/templates/helper.rb
  24. +0 −11 generators/rspec_datamapper_controller/templates/helper_spec.rb
  25. +0 −13 generators/rspec_datamapper_model/rspec_datamapper_model_generator.rb
  26. +0 −18 generators/rspec_datamapper_model/templates/model.rb
  27. +0 −16 generators/rspec_datamapper_scaffold/rspec_datamapper_scaffold_generator.rb
  28. +1 −1  lib/datamapper4rails.rb
  29. +20 −2 {generators → lib/datamapper4rails}/overlay.rb
  30. 0  {generators → lib/datamapper4rails}/rspec_default_values.rb
View
32 Manifest.txt
@@ -3,31 +3,33 @@ Manifest.txt
README.txt
Rakefile
generate.sh
-generators/datamapper_controller/datamapper_controller_generator.rb
+generators/datamapper_install/datamapper_install_generator.rb
+generators/datamapper_install/templates/datamapper.rake
generators/datamapper_model/datamapper_model_generator.rb
generators/datamapper_model/templates/model.rb
-generators/datamapper_model/templates/unit_test.rb
-generators/overlay.rb
-generators/rspec_datamapper_controller/rspec_datamapper_controller_generator.rb
-generators/rspec_datamapper_controller/templates/controller.rb
-generators/rspec_datamapper_controller/templates/controller_spec.rb
-generators/rspec_datamapper_controller/templates/helper.rb
-generators/rspec_datamapper_controller/templates/helper_spec.rb
-generators/rspec_datamapper_model/rspec_datamapper_model_generator.rb
-generators/rspec_datamapper_model/templates/model.rb
-generators/rspec_datamapper_model/templates/model_spec.rb
-generators/rspec_datamapper_scaffold/rspec_datamapper_scaffold_generator.rb
-generators/rspec_datamapper_scaffold/templates/controller.rb
-generators/rspec_datamapper_scaffold/templates/controller_spec.rb
-generators/rspec_default_values.rb
+generators/datamapper_rspec_model/datamapper_rspec_model_generator.rb
+generators/datamapper_rspec_model/templates/model_spec.rb
+generators/datamapper_rspec_scaffold/datamapper_rspec_scaffold_generator.rb
+generators/datamapper_rspec_scaffold/templates/controller_spec.rb
+generators/datamapper_scaffold/datamapper_scaffold_generator.rb
+generators/datamapper_scaffold/templates/controller.rb
+generators/datamapper_scaffold/templates/functional_test.rb
+generators/datamapper_scaffold/templates/view_edit.html.erb
+generators/datamapper_scaffold/templates/view_index.html.erb
+generators/datamapper_scaffold/templates/view_new.html.erb
+generators/datamapper_scaffold/templates/view_show.html.erb
lib/datamapper4rails.rb
lib/datamapper4rails/adapters/base_adapter.rb
lib/datamapper4rails/adapters/restful_adapter.rb
+lib/datamapper4rails/database_config.rb-
lib/datamapper4rails/datamapper_store.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/version.rb
+lib/datamapper_rails_templates.rb
spec/datamapper_store_spec.rb
spec/restful_adapter_spec.rb
spec/spec.opts
View
4 Rakefile
@@ -9,10 +9,10 @@ require 'pathname'
require './lib/datamapper4rails/version.rb'
-Hoe.new('datamapper4rail', Datamapper4rails::VERSION) do |p|
+Hoe.new('datamapper4rails', Datamapper4rails::VERSION) do |p|
p.rubyforge_name = 'datamapper4rail'
p.developer('mkristian', 'm.kristian@web.de')
- p.extra_deps = ['slf4r', 'rack_datamapper', 'rails_datamapper']
+ p.extra_deps = ['rack_datamapper', 'rails_datamapper']
p.remote_rdoc_dir = '' # Release to root
end
View
12 generators/datamapper_controller/datamapper_controller_generator.rb
@@ -1,12 +0,0 @@
-require File.dirname(__FILE__) + '/../overlay'
-
-# this controller is just for completeness but does not offer
-# any further functionality to the underlying controller
-class DatamapperControllerGenerator < ControllerGenerator
-
- def manifest
- overlay_dirs << File.join(self.class.lookup("controller").path, 'templates')
- super
- end
-
-end
View
12 generators/datamapper_install/datamapper_install_generator.rb
@@ -0,0 +1,12 @@
+require 'rails_generator/base'
+
+class DatamapperInstallGenerator < Rails::Generator::Base
+
+ def manifest
+ record do |m|
+ m.directory 'lib/tasks'
+ m.template 'datamapper.rake', 'lib/tasks/datamapper.rake'
+ end
+ end
+
+end
View
42 generators/datamapper_install/templates/datamapper.rake
@@ -0,0 +1,42 @@
+namespace :dm do
+
+ desc 'Perform automigration'
+ task :automigrate => :environment do
+ FileList['app/models/**/*.rb'].each do |model|
+ load model
+ end
+ ::DataMapper.auto_migrate!
+ end
+
+ desc 'Perform non destructive automigration'
+ task :autoupgrade => :environment do
+ FileList['app/models/**/*.rb'].each do |model|
+ load model
+ end
+ ::DataMapper.auto_upgrade!
+ end
+
+ namespace :migrate do
+ task :load => :environment do
+ require 'dm-migrations/migration_runner'
+ FileList['db/migrate/*.rb'].each do |migration|
+ load migration
+ end
+ end
+
+ desc 'Migrate up using migrations'
+ task :up, :version, :needs => :load do |t, args|
+ version = args[:version]
+ migrate_up!(version)
+ end
+
+ desc 'Migrate down using migrations'
+ task :down, :version, :needs => :load do |t, args|
+ version = args[:version]
+ migrate_down!(version)
+ end
+ end
+
+ desc 'Migrate the database to the latest version'
+ task :migrate => 'dm:migrate:up'
+end
View
12 generators/datamapper_model/datamapper_model_generator.rb
@@ -1,14 +1,18 @@
require 'rails_generator/generators/components/model/model_generator'
require 'active_record'
-require File.dirname(__FILE__) + '/../overlay'
+require 'datamapper4rails/overlay'
-class DatamapperModelGenerator <ModelGenerator
+class DatamapperModelGenerator < ModelGenerator
def manifest
- overlay_dirs << File.join(self.class.lookup("model").path, 'templates')
- overlay_dirs << source_root
+ overlay_dirs.add_generator("model")
super
end
+ def add_options!(opt)
+ super
+ opt.on("--skip-timestamps",
+ "Don't add timestamps for this model") { |v| options[:skip_timestamps] = v }
+ end
end
View
3  generators/datamapper_model/templates/model.rb
@@ -2,8 +2,9 @@ class <%= class_name %>
include DataMapper::Resource
property :id, Serial
+
<% Array(attributes).each do |attribute| -%>
- property :<%= attribute.name %>, <%= attribute.type.to_s.capitalize %>, :nullable => false <% if attribute.type == :string or attribute.type == :text or attribute.type == :slug -%>, :format => /^[^<'&">]*$/<% if attribute.type == :string or attribute.type == :slug %>, :length => 255<% end -%><% end -%>
+ property :<%= attribute.name %>, <%= attribute.type.to_s.capitalize %>, :nullable => false <% if attribute.type == :string or attribute.type == :text or attribute.type == :slug -%>, :format => /^[^<'&">]*$/<% if attribute.type == :string or attribute.type == :slug %>, :length => 255<% end -%><% end %>
<% end -%>
<% unless options[:skip_timestamps] -%>
View
8 generators/datamapper_model/templates/unit_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class <%= class_name %>Test < ActiveSupport::TestCase
- # Replace this with your real tests.
- def test_truth
- assert true
- end
-end
View
18 generators/datamapper_rspec_model/datamapper_rspec_model_generator.rb
@@ -0,0 +1,18 @@
+require 'rails_generator/generators/components/model/model_generator'
+require 'active_record'
+require 'datamapper4rails/overlay'
+
+class DatamapperRspecModelGenerator < RspecModelGenerator
+
+ def manifest
+ overlay_dirs.add_generator("datamapper_model")
+ overlay_dirs.add_generator("rspec_model")
+ super
+ end
+
+ def add_options!(opt)
+ super
+ opt.on("--skip-timestamps",
+ "Don't add timestamps for this model") { |v| options[:skip_timestamps] = v }
+ end
+end
View
2  ...rs/rspec_datamapper_model/templates/model_spec.rb → ...rs/datamapper_rspec_model/templates/model_spec.rb
@@ -18,7 +18,7 @@
<%= singular_name %>.errors.on(:<%= attribute.name %>).should_not == nil
end
-<% if attribute.type == :string or attribute.type == :text or attribute.type == :slug -%>
+<% if [:string, :text, :slug].member? attribute.type -%>
it 'should not match <%= attribute.name %>' do
<%= singular_name %> = <%= class_name %>.create(@valid_attributes.merge(:<%= attribute.name %> => "<script" ))
<%= singular_name %>.errors.on(:<%= attribute.name %>).should_not == nil
View
20 generators/datamapper_rspec_scaffold/datamapper_rspec_scaffold_generator.rb
@@ -0,0 +1,20 @@
+require 'datamapper4rails/overlay'
+require 'datamapper4rails/rspec_default_values'
+
+class DatamapperRspecScaffoldGenerator < RspecScaffoldGenerator
+
+ def manifest
+ overlay_dirs.add_generator("datamapper_rspec_model")
+ overlay_dirs.add_generator("datamapper_model")
+ overlay_dirs.add_generator("datamapper_scaffold")
+ overlay_dirs.add_generator("rspec_scaffold")
+ overlay_dirs.add_generator("scaffold")
+ super
+ end
+
+ def add_options!(opt)
+ super
+ opt.on("--skip-timestamps",
+ "Don't add timestamps for this model") { |v| options[:skip_timestamps] = v }
+ end
+end
View
5 ..._datamapper_scaffold/templates/controller_spec.rb → ...apper_rspec_scaffold/templates/controller_spec.rb
@@ -111,7 +111,6 @@ def mock_<%= file_name %>(stubs={})
it "updates the requested <%= file_name %>" do
<%= class_name %>.should_receive(:get!).with("37").and_return(mock_<%= file_name %>)
mock_<%= file_name %>.should_receive(:update).with({'these' => 'params'})
- mock_<%= file_name %>.should_receive(:dirty?)
put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
end
@@ -134,19 +133,17 @@ def mock_<%= file_name %>(stubs={})
it "updates the requested <%= file_name %>" do
<%= class_name %>.should_receive(:get!).with("37").and_return(mock_<%= file_name %>)
mock_<%= file_name %>.should_receive(:update).with({'these' => 'params'})
- mock_<%= file_name %>.should_receive(:dirty?)
put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
end
it "exposes the <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.stub!(:get!).and_return(mock_<%= file_name %>(:update => false))
- mock_<%= file_name %>.should_receive(:dirty?)
put :update, :id => "1"
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
end
it "re-renders the 'edit' template" do
- <%= class_name %>.stub!(:get!).and_return(mock_<%= file_name %>(:update => false, :dirty? => true))
+ <%= class_name %>.stub!(:get!).and_return(mock_<%= file_name %>(:update => false))
put :update, :id => "1"
response.should render_template('edit')
end
View
31 generators/datamapper_scaffold/datamapper_scaffold_generator.rb
@@ -0,0 +1,31 @@
+require 'datamapper4rails/overlay'
+require 'datamapper4rails/rspec_default_values'
+
+class DatamapperScaffoldGenerator < ScaffoldGenerator
+
+ def manifest
+ overlay_dirs.add_generator("datamapper_model")
+ overlay_dirs.add_generator("scaffold")
+
+ logger.warn
+ logger.warn
+ logger.warn
+ logger.warn
+ logger.warn " WARNING"
+ logger.warn
+ logger.warn "fixtures with datamapper do not work"
+ logger.warn "and so functional tests do not work"
+ logger.warn
+ logger.warn
+ logger.warn
+ logger.warn
+
+ super
+ end
+
+ def add_options!(opt)
+ super
+ opt.on("--skip-timestamps",
+ "Don't add timestamps for this model") { |v| options[:skip_timestamps] = v }
+ end
+end
View
2  ...rspec_datamapper_scaffold/templates/controller.rb → ...ators/datamapper_scaffold/templates/controller.rb
@@ -62,7 +62,7 @@ def update
@<%= file_name %> = <%= class_name %>.get!(params[:id])
respond_to do |format|
- if @<%= file_name %>.update(params[:<%= file_name %>]) or not @<%= file_name %>.dirty?
+ if @<%= file_name %>.update(params[:<%= file_name %>])
flash[:notice] = <% if options[:i18n] -%>t('<%= plural_name %>.<%= singular_name %>_updated')<% else -%>'<%= class_name %> was successfully updated.'<% end -%>
format.html { redirect_to(<%= file_name %>_url(@<%= file_name %>.id)) }
View
49 generators/datamapper_scaffold/templates/functional_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class <%= controller_class_name %>ControllerTest < ActionController::TestCase
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:<%= table_name %>)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create <%= file_name %>" do
+ assert_difference('<%= class_name %>.all.size') do
+ post :create, :<%= file_name %> => {
+<% attributes.each_with_index do |attribute, attribute_index| -%>
+ :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == attributes.length - 1 ? '' : ','%>
+<% end -%>
+ }
+ end
+
+ assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>).key)
+ end
+
+ test "should show <%= file_name %>" do
+ get :show, :id => <%= table_name %>(:one).to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, :id => <%= table_name %>(:one).to_param
+ assert_response :success
+ end
+
+ test "should update <%= file_name %>" do
+ put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
+ assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>).key)
+ end
+
+ test "should destroy <%= file_name %>" do
+ assert_difference('<%= class_name %>.all.size', -1) do
+ delete :destroy, :id => <%= table_name %>(:one).to_param
+ end
+
+ assert_redirected_to <%= table_name %>_path
+ end
+end
View
18 generators/datamapper_scaffold/templates/view_edit.html.erb
@@ -0,0 +1,18 @@
+<h1>Editing <%= singular_name %></h1>
+
+<%% form_for(:<%= singular_name %>, :url => <%= singular_name %>_path(@<%= singular_name %>.key), :html => {:method => :put}) do |f| %>
+ <%%= f.error_messages %>
+
+<% for attribute in attributes -%>
+ <p>
+ <%%= f.label :<%= attribute.name %> %><br />
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
+ </p>
+<% end -%>
+ <p>
+ <%%= f.submit 'Update' %>
+ </p>
+<%% end %>
+
+<%%= link_to 'Show', <%= singular_name %>_path(@<%= singular_name %>.key) %> |
+<%%= link_to 'Back', <%= plural_name %>_path %>
View
24 generators/datamapper_scaffold/templates/view_index.html.erb
@@ -0,0 +1,24 @@
+<h1>Listing <%= plural_name %></h1>
+
+<table>
+ <tr>
+<% for attribute in attributes -%>
+ <th><%= attribute.column.human_name %></th>
+<% end -%>
+ </tr>
+
+<%% @<%= plural_name %>.each do |<%= singular_name %>| %>
+ <tr>
+<% for attribute in attributes -%>
+ <td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
+<% end -%>
+ <td><%%= link_to 'Show', <%= singular_name %>_path(<%= singular_name %>.key) %></td>
+ <td><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>.key) %></td>
+ <td><%%= link_to 'Destroy', <%= singular_name %>_path(<%= singular_name %>.key), :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<%% end %>
+</table>
+
+<br />
+
+<%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %>
View
17 generators/datamapper_scaffold/templates/view_new.html.erb
@@ -0,0 +1,17 @@
+<h1>New <%= singular_name %></h1>
+
+<%% form_for(@<%= singular_name %>) do |f| %>
+ <%%= f.error_messages %>
+
+<% for attribute in attributes -%>
+ <p>
+ <%%= f.label :<%= attribute.name %> %><br />
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
+ </p>
+<% end -%>
+ <p>
+ <%%= f.submit 'Create' %>
+ </p>
+<%% end %>
+
+<%%= link_to 'Back', <%= plural_name %>_path %>
View
10 generators/datamapper_scaffold/templates/view_show.html.erb
@@ -0,0 +1,10 @@
+<% for attribute in attributes -%>
+<p>
+ <b><%= attribute.column.human_name %>:</b>
+ <%%=h @<%= singular_name %>.<%= attribute.name %> %>
+</p>
+
+<% end -%>
+
+<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>.key) %> |
+<%%= link_to 'Back', <%= plural_name %>_path %>
View
8 generators/rspec_datamapper_controller/rspec_datamapper_controller_generator.rb
@@ -1,8 +0,0 @@
-require File.dirname(__FILE__) + '/../overlay'
-
-class RspecDatamapperControllerGenerator < RspecControllerGenerator
- def manifest
- overlay_dirs << File.join(self.class.lookup("rspec_controller").path, 'templates')
- super
- end
-end
View
111 generators/rspec_datamapper_controller/templates/controller.rb
@@ -1,111 +0,0 @@
-class <%= controller_class_name %>Controller < ApplicationController
- # GET /<%= table_name %>
- # GET /<%= table_name %>.xml
- def index
-<% if options[:ixtlan] -%>
- @<%= table_name %> = <%= class_name %>.all(@find_all_args)
-<% else -%>
- @<%= table_name %> = <%= class_name %>.all()
-<% end -%>
-
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @<%= table_name %> }
- end
- end
-
- # GET /<%= table_name %>/1
- # GET /<%= table_name %>/1.xml
- def show
- @<%= file_name %> = <%= class_name %>.get!(params[:id])
-
- respond_to do |format|
- format.html # show.html.erb
- format.xml { render :xml => @<%= file_name %> }
- end
- end
-
- # GET /<%= table_name %>/new
- # GET /<%= table_name %>/new.xml
- def new
- @<%= file_name %> = <%= class_name %>.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.xml { render :xml => @<%= file_name %> }
- end
- end
-
- # GET /<%= table_name %>/1/edit
- def edit
- @<%= file_name %> = <%= class_name %>.get!(params[:id])
- end
-
- # POST /<%= table_name %>
- # POST /<%= table_name %>.xml
- def create
- @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
-
- respond_to do |format|
- if @<%= file_name %>.save
- flash[:notice] = <% if options[:i18n] -%>t('<%= plural_name %>.<%= singular_name %>_created')<% else -%>'<%= class_name %> was successfully created.'<% end -%>
-
- format.html { redirect_to(<%= file_name %>_url(@<%= file_name %>.id)) }
- format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
- end
- end
- end
-
- # PUT /<%= table_name %>/1
- # PUT /<%= table_name %>/1.xml
- def update
- @<%= file_name %> = <%= class_name %>.get!(params[:id])
-
- respond_to do |format|
- if @<%= file_name %>.update_attributes(params[:<%= file_name %>]) or not @<%= file_name %>.dirty?
- flash[:notice] = <% if options[:i18n] -%>t('<%= plural_name %>.<%= singular_name %>_updated')<% else -%>'<%= class_name %> was successfully updated.'<% end -%>
-
- format.html { redirect_to(<%= file_name %>_url(@<%= file_name %>.id)) }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
- end
- end
- end
-
- # DELETE /<%= table_name %>/1
- # DELETE /<%= table_name %>/1.xml
- def destroy
- @<%= file_name %> = <%= class_name %>.get(params[:id])
- @<%= file_name %>.destroy if @<%= file_name %>
-
- respond_to do |format|
- flash[:notice] = <% if options[:i18n] -%>t('<%= plural_name %>.<%= singular_name %>_deleted')<% else -%>'<%= class_name %> was successfully deleted.'<% end -%>
-
- format.html { redirect_to(<%= table_name %>_url) }
- format.xml { head :ok }
- end
- end
-
-<% if options[:ixtlan] -%>
- private
-
- def audit
- if @<%= file_name %>
- @<%= file_name %>.to_s
- elsif @<%= table_name %>
-<% if options[:ixtlan] -%>
- "<%= controller_class_name %>[#{@<%= table_name %>.size};#{@field}:#{@direction}]"
-<% else -%>
- "<%= controller_class_name %>[#{@<%= table_name %>.size}]"
-<% end -%>
- else
- ""
- end
- end
-<% end -%>
-end
View
189 generators/rspec_datamapper_controller/templates/controller_spec.rb
@@ -1,189 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
-
-describe <%= controller_class_name %>Controller do
-
- def mock_<%= file_name %>(stubs={})
- @mock_<%= file_name %> ||= mock_model(<%= class_name %>, stubs)
- end
-
-<% if options[:add_guard] -%>
- before(:each) do
- user = User.new(:id => 1)
- def user.groups
- [Group.new(:name => "root")]
- end
- controller.send(:current_user=, user)
-<% if options[:ixtlan] -%>
- mock_configuration = mock_model(Configuration,{})
- Configuration.should_receive(:instance).any_number_of_times.and_return(mock_configuration)
- mock_configuration.should_receive(:session_idle_timeout).any_number_of_times.and_return(1)
-<% end -%>
- end
-<% end -%>
-
- describe "GET index" do
-
- it "exposes all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
- <%= class_name %>.should_receive(:all).and_return([mock_<%= file_name %>])
- get :index
- assigns[:<%= table_name %>].should == [mock_<%= file_name %>]
- end
-
- describe "with mime type of xml" do
-
- it "renders all <%= table_name.pluralize %> as xml" do
- <%= class_name %>.should_receive(:all).and_return(<%= file_name.pluralize %> = mock("Array of <%= class_name.pluralize %>"))
- <%= file_name.pluralize %>.should_receive(:to_xml).and_return("generated XML")
- get :index, :format => 'xml'
- response.body.should == "generated XML"
- end
-
- end
-
- end
-
- describe "GET show" do
-
- it "exposes the requested <%= file_name %> as @<%= file_name %>" do
- <%= class_name %>.should_receive(:get!).with("37").and_return(mock_<%= file_name %>)
- get :show, :id => "37"
- assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
- end
-
- describe "with mime type of xml" do
-
- it "renders the requested <%= file_name %> as xml" do
- <%= class_name %>.should_receive(:get!).with("37").and_return(mock_<%= file_name %>)
- mock_<%= file_name %>.should_receive(:to_xml).and_return("generated XML")
- get :show, :id => "37", :format => 'xml'
- response.body.should == "generated XML"
- end
-
- end
-
- end
-
- describe "GET new" do
-
- it "exposes a new <%= file_name %> as @<%= file_name %>" do
- <%= class_name %>.should_receive(:new).and_return(mock_<%= file_name %>)
- get :new
- assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
- end
-
- end
-
- describe "GET edit" do
-
- it "exposes the requested <%= file_name %> as @<%= file_name %>" do
- <%= class_name %>.should_receive(:get!).with("37").and_return(mock_<%= file_name %>)
- get :edit, :id => "37"
- assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
- end
-
- end
-
- describe "POST create" do
-
- describe "with valid params" do
-
- it "exposes a newly created <%= file_name %> as @<%= file_name %>" do
- <%= class_name %>.should_receive(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => true))
- post :create, :<%= file_name %> => {:these => 'params'}
- assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
- end
-
- it "redirects to the created <%= file_name %>" do
- <%= class_name %>.stub!(:new).and_return(mock_<%= file_name %>(:save => true))
- post :create, :<%= file_name %> => {}
- response.should redirect_to(<%= table_name.singularize %>_url(mock_<%= file_name %>))
- end
-
- end
-
- describe "with invalid params" do
-
- it "exposes a newly created but unsaved <%= file_name %> as @<%= file_name %>" do
- <%= class_name %>.stub!(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => false))
- post :create, :<%= file_name %> => {:these => 'params'}
- assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
- end
-
- it "re-renders the 'new' template" do
- <%= class_name %>.stub!(:new).and_return(mock_<%= file_name %>(:save => false))
- post :create, :<%= file_name %> => {}
- response.should render_template('new')
- end
-
- end
-
- end
-
- describe "PUT udpate" do
-
- describe "with valid params" do
-
- it "updates the requested <%= file_name %>" do
- <%= class_name %>.should_receive(:get!).with("37").and_return(mock_<%= file_name %>)
- mock_<%= file_name %>.should_receive(:update).with({'these' => 'params'})
- mock_<%= file_name %>.should_receive(:dirty?)
- put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
- end
-
- it "exposes the requested <%= file_name %> as @<%= file_name %>" do
- <%= class_name %>.stub!(:get!).and_return(mock_<%= file_name %>(:update => true))
- put :update, :id => "1"
- assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
- end
-
- it "redirects to the <%= file_name %>" do
- <%= class_name %>.stub!(:get!).and_return(mock_<%= file_name %>(:update => true))
- put :update, :id => "1"
- response.should redirect_to(<%= table_name.singularize %>_url(mock_<%= file_name %>))
- end
-
- end
-
- describe "with invalid params" do
-
- it "updates the requested <%= file_name %>" do
- <%= class_name %>.should_receive(:get!).with("37").and_return(mock_<%= file_name %>)
- mock_<%= file_name %>.should_receive(:update).with({'these' => 'params'})
- mock_<%= file_name %>.should_receive(:dirty?)
- put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
- end
-
- it "exposes the <%= file_name %> as @<%= file_name %>" do
- <%= class_name %>.stub!(:get!).and_return(mock_<%= file_name %>(:update => false))
- mock_<%= file_name %>.should_receive(:dirty?)
- put :update, :id => "1"
- assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
- end
-
- it "re-renders the 'edit' template" do
- <%= class_name %>.stub!(:get!).and_return(mock_<%= file_name %>(:update => false, :dirty? => true))
- put :update, :id => "1"
- response.should render_template('edit')
- end
-
- end
-
- end
-
- describe "DELETE destroy" do
-
- it "destroys the requested <%= file_name %>" do
- <%= class_name %>.should_receive(:get).with("37").and_return(mock_<%= file_name %>)
- mock_<%= file_name %>.should_receive(:destroy)
- delete :destroy, :id => "37"
- end
-
- it "redirects to the <%= table_name %> list" do
- <%= class_name %>.should_receive(:get).with("1").and_return(mock_<%= file_name %>(:destroy => true))
- delete :destroy, :id => "1"
- response.should redirect_to(<%= table_name %>_url)
- end
-
- end
-
-end
View
2  generators/rspec_datamapper_controller/templates/helper.rb
@@ -1,2 +0,0 @@
-module <%= controller_class_name %>Helper
-end
View
11 generators/rspec_datamapper_controller/templates/helper_spec.rb
@@ -1,11 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
-require 'active_record'
-
-describe <%= controller_class_name %>Helper do
- before(:each) do
- include <%= controller_class_name %>Helper
- end
-
- it "should be valid" do
- end
-end
View
13 generators/rspec_datamapper_model/rspec_datamapper_model_generator.rb
@@ -1,13 +0,0 @@
-require 'rails_generator/generators/components/model/model_generator'
-require 'active_record'
-require File.dirname(__FILE__) + '/../overlay'
-
-class RspecDatamapperModelGenerator < RspecModelGenerator
-
- def manifest
- overlay_dirs << File.join(self.class.lookup("datamapper_model").path, 'templates')
- overlay_dirs << File.join(self.class.lookup("rspec_model").path, 'templates')
- super
- end
-
-end
View
18 generators/rspec_datamapper_model/templates/model.rb
@@ -1,18 +0,0 @@
-class <%= class_name %>
- include DataMapper::Resource
-<% if options[:add_constraints] -%>
- include DataMapper::Constraints
-<% end -%>
-
- property :id, Serial
-
-<% for attribute in attributes -%>
- property :<%= attribute.name %>, <%= attribute.type.to_s.camelize %>, :nullable => false <% if attribute.type == :string or attribute.type == :text or attribute.type == :slug -%>, :format => /^[^<'&">]*$/<% if attribute.type == :string or attribute.type == :slug %>, :length => 255<% end -%><% end -%>
-
-<% end -%>
-<% unless options[:skip_timestamps] %>
- timestamps :at
-
-<% end -%>
-
-end
View
16 generators/rspec_datamapper_scaffold/rspec_datamapper_scaffold_generator.rb
@@ -1,16 +0,0 @@
-require File.dirname(__FILE__) + '/../overlay'
-require File.dirname(__FILE__) + '/../rspec_default_values'
-
-class RspecDatamapperScaffoldGenerator < RspecScaffoldGenerator
-
- def manifest
- overlay_dirs << File.join(self.class.lookup("scaffold").path, 'templates')
- overlay_dirs << File.join(self.class.lookup("rspec_scaffold").path, 'templates')
- overlay_dirs << File.join(self.class.lookup("datamapper_model").path, 'templates')
- overlay_dirs << File.join(self.class.lookup("rspec_model").path, 'templates')
- overlay_dirs << source_root
-
- super
- end
-
-end
View
2  lib/datamapper4rails.rb
@@ -1,5 +1,5 @@
-#require 'datamapper4rails/database_config'
require 'rails_datamapper'
+require 'datamapper4rails/datamapper_store'
# keep this here until rails_datamapper has it included
module DataMapper
View
22 generators/overlay.rb → lib/datamapper4rails/overlay.rb
@@ -7,11 +7,25 @@
Rails::Generator::NamedBase.class_eval do
+ def overlay_array
+ a = []
+ 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
+ end
+ a
+ end
+
def overlay_dirs
- options[:overlay_dirs] ||= []
+ options[:overlay_dirs] ||= overlay_array
end
def add_options!(opt)
+ # TODO this seems not to work anymore !!
super
opt.on("--overlay-dir DIR",
"overlay") do |v|
@@ -25,9 +39,13 @@ 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'))
+
file = path.nil? ? name : path
- dirs.reverse.each do |dir|
+ dirs.each do |dir|
if (f = File.join(dir, file)) and File.exists?(f)
+ logger.overlay f
return f
end
end
View
0  generators/rspec_default_values.rb → lib/datamapper4rails/rspec_default_values.rb
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.