Generating a resource with invalid data type will still create the model
Reported by Peter | April 1st, 2008 @ 06:03 AM | in 1.0
When generating an invalid data type ex:
merb-gen resource article title:string content:*test* created_at:datetime
dependency model
exists app
create app/models
create app/models/article.rb
dependency merb_model_test
exists spec
create spec/models
create spec/models/article_spec.rb
dependency resource_controller
/usr/local/lib/ruby/gems/1.8/gems/datamapper-0.3.0/lib/data_mapper/property.rb:173:in `validate_type!': :test is not a supported type in the database adapter. Valid types are: (ArgumentError)
it will still create the Model with the invalid type:
class Article < DataMapper::Base
property :title, :string
property :content, :*test*
property :created_at, :datetime
end
and require you to manually fix it because if you run the generator again it will break
/usr/local/lib/ruby/gems/1.8/gems/datamapper-0.3.0/lib/data_mapper/property.rb:173:in `validate_type!': :test is not a supported type in the database adapter. Valid types are: (ArgumentError)
Comments and changes to this ticket
-
Michael Klishin (antares) May 11th, 2008 @ 03:22 PM
- → Milestone changed from to 1.0
-

Martin Frost June 2nd, 2008 @ 11:00 PM
that error with your merb-gen line doesn't appear with datamapper 0.9.1.
It still creates the model though, and if you try to run any merb or merb-gen command in the same app, things (of course) blows up with a NameError ('uninitialized constant'), like the following:
{{{
frost Mercury >> merb-gen resource aoeu waka:string lalala:weeeeeeee
dependency model
exists app
create app/models
create app/models/aoeu.rb
dependency merb_model_test
exists spec
create spec/models
create spec/models/aoeu_spec.rb
dependency resource_controller
exists app
exists app/controllers
exists app/helpers
exists app/views
create app/views/aoeus
create app/controllers/aoeus.rb
create app/helpers/aoeus_helper.rb
create app/views/aoeus/edit.html.erb
create app/views/aoeus/index.html.erb
create app/views/aoeus/new.html.erb
create app/views/aoeus/show.html.erb
dependency merb_resource_controller_test
create spec/controllers/
create spec/helpers/
exists spec
exists spec/controllers
exists spec/helpers
create spec/views
create spec/views/aoeus
create spec/controllers/aoeus_spec.rb
create spec/helpers/aoeus_helpers.rb
create spec/views/aoeus/delete.html.erb_spec.rb
create spec/views/aoeus/edit.html.erb_spec.rb
create spec/views/aoeus/index.html.erb_spec.rb
create spec/views/aoeus/new.html.erb_spec.rb
create spec/views/aoeus/show.html.erb_spec.rb
frost Mercury >> merb
~ Loaded DEVELOPMENT Environment...
~ Connecting to database...
~ loading gem 'merb_datamapper' ...
~ Please upgrade your Rubygems to the latest version
~ Could not load /Users/frost/Projects/merb-test/app/models/aoeu.rb:
uninitialized constant Aoeu::Weeeeeeee - (NameError)
/Users/frost/Projects/merb-test/app/models/aoeu.rb:5
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:332:in `load'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:332:in `load_file'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:421:in `load_classes_with_requirements'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:418:in `each'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:418:in `load_classes_with_requirements'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:352:in `load_classes'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:322:in `run'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/vendor/facets/dictionary.rb:268:in `each'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/vendor/facets/dictionary.rb:268:in `each'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:320:in `run'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:67:in `run'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/server.rb:51:in `start'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core.rb:87:in `start'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/bin/merb:12
/usr/bin/merb:19:in `load'
/usr/bin/merb:19
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:437:in `load_classes_with_requirements': Could not load ["/Users/frost/Projects/merb-test/app/models/aoeu.rb"] (see log for details). (LoadError)
from /Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:352:in `load_classes'
from /Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:322:in `run'
from /Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/vendor/facets/dictionary.rb:268:in `each'
from /Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/vendor/facets/dictionary.rb:268:in `each'
from /Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:320:in `run'
from /Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:67:in `run'
from /Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/server.rb:51:in `start'
from /Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core.rb:87:in `start'
from /Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/bin/merb:12
from /usr/bin/merb:19:in `load'
from /usr/bin/merb:19
}}}
I guess the best idea is to check the validity of all propertys in a resource before starting to create all the files and directories, and if it breaks, just not create anything and respond with a propriate error message.
It would probably also be a good idea to check how this works with other ORMs...
-
Michael Klishin (antares) June 3rd, 2008 @ 07:22 AM
- → State changed from new to open
This would require making merb-gen quite intelligent. Want to make a contribution?
-
Michael Klishin (antares) September 6th, 2008 @ 01:00 PM
- → Tag changed from to generator merb-gen
- → State changed from open to invalid
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
