[rspec-users] Example for attr_accessible?

Pat Maddox pergesu at gmail.com
Tue Oct 16 14:40:35 EDT 2007

On 10/16/07, Steve <vertebrate at gmail.com> wrote:
> >
> > You could expect a call to attr_accessible and then load your model file.
> >
> > Or, loop through all the column names in your model, and make sure
> > that only the ones that are supposed to be accessible get set.
> >
> > Pat
> Expecting the call is what I had originally thought of, but couldn't
> figure out how to write that test. Isn't attr_accessible called when you
> create a new instance, so there wouldn't be time to setup an expectation
> for the call?

describe Chicken do
  it "should make only :name and :age attr_accessible" do
    Chicken.should_receive(:attr_accessible).with(:name, :age)
    load "#{RAILS_ROOT}/app/models/chicken.rb"

I first saw this technique described by David Chelimsky at


More information about the rspec-users mailing list