开发者

RSpec controller test: How do I check @organization.destroy is being called?

开发者 https://www.devze.com 2023-03-16 18:40 出处:网络
I thought it might be like:开发者_高级运维 let(:organization) { mock_model(Organization).as_null_object }

I thought it might be like:

开发者_高级运维
let(:organization) { mock_model(Organization).as_null_object }

before(:each) do
  Organization.stub(:find).and_return(organization)
end

it "calls the destroy action on @organization" do
  assigns[:organization].should_receive("destroy")
  post :destroy, :id => organization.id
end

..but I get a "can't modify frozen object" error.


Here's how I would write that spec:

describe 'Oragnization#destroy' do
  let(:organization) { mock_model(Organization, :id => 1, :destroy => true) }

  subject { post :destroy, :id => organization.id }

  it { should be_successful }
end
0

精彩评论

暂无评论...
验证码 换一张
取 消