Permalink
Browse files

Generate middleware only for ActiveRecord orm. Ref.: #680

  • Loading branch information...
1 parent b6d9ee9 commit e4b9e28e83e24a324fda777d658af298bb845fc4 @DAddYE DAddYE committed Feb 23, 2012
@@ -59,7 +59,7 @@ def create_admin
directory "templates/assets", destination_root("public", "admin")
template "templates/app.rb.tt", destination_root("admin/app.rb")
append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"Admin\").to(\"/admin\")"
- insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement', 'admin'
+ insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement', 'admin' if [:mini_record, :activerecord].include?(orm)
account_params = [
options[:admin_model].underscore, "name:string", "surname:string", "email:string", "crypted_password:string", "role:string",
@@ -25,6 +25,13 @@ def initialize(name, orm, columns=nil, column_fields=nil)
raise OrmError, "Model '#{klass_name}' could not be found!" if @columns.nil? && @klass.nil?
end
+ def activerecord?
+ case orm
+ when :activerecord, :mini_record then true
+ else false
+ end
+ end
+
def field_type(type)
type = :string if type.nil? # couchrest-Hack to avoid the next line to fail
type = type.to_s.demodulize.downcase.to_sym unless type.is_a?(Symbol)
@@ -59,7 +59,6 @@ def teardown
assert_match_in_file 'class Admin < Padrino::Application', "#{@apptmp}/sample_project/admin/app.rb"
assert_match_in_file 'role.project_module :accounts, \'/accounts\'', "#{@apptmp}/sample_project/admin/app.rb"
assert_match_in_file 'button_to pat(:logout)', "#{@apptmp}/sample_project/admin/views/layouts/application.haml"
- assert_match_in_file(/ use ActiveRecord::ConnectionAdapters::ConnectionManagemen/m, "#{@apptmp}/sample_project/admin/app.rb")
end
should 'correctly generate a new padrino admin application with erb renderer' do
@@ -159,6 +158,24 @@ def teardown
assert_match_in_file 'button_to pat(:logout)', "#{@apptmp}/sample_project/admin/views/layouts/application.haml"
end
+ should 'not add activerecord middleware for #datamapper' do
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=datamapper', '-e=haml') }
+ capture_io { generate(:admin_app,"-a=/admin", "--root=#{@apptmp}/sample_project") }
+ assert_no_match_in_file(/ use ActiveRecord::ConnectionAdapters::ConnectionManagemen/m, "#{@apptmp}/sample_project/admin/app.rb")
+ end
+
+ should 'add activerecord middleware for #activerecord' do
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord', '-e=haml') }
+ capture_io { generate(:admin_app,"-a=/admin", "--root=#{@apptmp}/sample_project") }
+ assert_match_in_file(/ use ActiveRecord::ConnectionAdapters::ConnectionManagemen/m, "#{@apptmp}/sample_project/admin/app.rb")
+ end
+
+ should 'add activerecord middleware for #mini_record' do
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=mini_record', '-e=haml') }
+ capture_io { generate(:admin_app,"-a=/admin", "--root=#{@apptmp}/sample_project") }
+ assert_match_in_file(/ use ActiveRecord::ConnectionAdapters::ConnectionManagemen/m, "#{@apptmp}/sample_project/admin/app.rb")
+ end
+
should 'not conflict with existing seeds file' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord', '-e=erb') }

0 comments on commit e4b9e28

Please sign in to comment.