I've just created a directory of very elementary controllers with AS
to act as admin interface.
My app/controllers/admin/admin_controller.rb:

class Admin::AdminController < ApplicationController
  load_and_authorize_resource
  before_filter :ensure_admin
  layout "administrator"

  ActiveScaffold.set_defaults do |config|
    config.ignore_columns.add
[:created_at, :updated_at, :lock_version]
  end

  def ensure_admin
    redirect_to root_url unless current_user.admin?
  end

  def current_ability
    @current_ability ||= AdminAbility.new(current_user,
params[:format])
  end
end

from admin/users_controller.rb:
class Admin::UsersController < Admin::AdminController
  active_scaffold :users do |config|
    config.columns.add :password
  end
end

(password is a virtual field in devise models).

This works great from a browser.  No problems.

require 'spec_helper'

describe Admin::UsersController do
  include Devise::TestHelpers
  fixtures :users

  describe "admin users" do
    it "can create new user without password" do
      @adminuser= users(:admin)
      sign_in(@adminuser)

      post :create, :user => {
        :email => '[email protected]',
        :fullname => 'Frank Jones'
      }
      assert_response 201
    end
  end
end

This blows up with:

marajade-[~/C/hydra/portal] mcr 10043 %bundle exec rspec spec/
controllers/admin/users_controller_spec.rb
F

Failures:

  1) Admin::UsersController admin users can create new user without
password
     Failure/Error: post :create, :user => {
     NoMethodError:
       You have a nil object when you didn't expect it!
       You might have expected an instance of Array.
       The error occurred while evaluating nil.each
     # ./spec/controllers/admin/users_controller_spec.rb:13


Too many layers to debug through, and obviously the error is not at
line 13.  Line 13 is just the post :create line.
If I insert my own "def create" method (rather than let AS provide
it), then I have no problems, but of course, then I have have to
generate out everything including the views, etc. which isn't what I
wanted to do...

Even a clue on how to debug this would be great.

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en.

Reply via email to