Understanding Procs, mock_model and ids

3 views
Skip to first unread message

Colin Ramsay

unread,
May 10, 2010, 12:58:48 PM5/10/10
to Remarkable
Hi there,

I have something like this:

describe StockItemsController do
mock_models :stock_item, :account

describe :post => :create do
expects :current_account, :on => proc { @controller }, :returns =>
account_proc
expects :new, :on => StockItem, :with => { "account_id" =>
account_proc.id }, :returns => stock_item_proc
should_redirect_to { stock_items_url }
end
end

And the controller action:

def create
@stock_item = StockItem.new({ "account_id" => current_account.id })
@stock_item.save!
redirect_to stock_items_url
end

I get:

<StockItem(id: integer, account_id: integer) (class)> received :new
with unexpected arguments
expected: ({"account_id"=>2173769420})
got: ({"account_id"=>1001})

I'm guessing this is something to do with the evaluation of the
account_proc but I'm missing what the exact problem is. Does anyone
have any advice?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Remarkable" group.
To post to this group, send email to remarka...@googlegroups.com.
To unsubscribe from this group, send email to remarkable-co...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/remarkable-core?hl=en.

Sébastien Nicouleaud

unread,
May 11, 2010, 2:40:09 AM5/11/10
to remarka...@googlegroups.com
The following may work:

expects :new, :on => StockItem, :with => proc {{ "account_id" =>
mock_account.id }}, :returns => stock_item_proc


Seb
Reply all
Reply to author
Forward
0 new messages