Skip to content

Instantly share code, notes, and snippets.

@harlow
Created December 20, 2013 19:42
Show Gist options
  • Select an option

  • Save harlow/8060235 to your computer and use it in GitHub Desktop.

Select an option

Save harlow/8060235 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe UsersController, '#create' do
let(:group_id) { double(:group_id) }
let(:group) { double(:group) }
let(:user) { double(:user) }
before do
Group.should_receive(:find).with(group_id).and_return(group)
group.should_receive(:create_user).with(attributes).and_return(users)
end
context ‘when attributes are valid’ do
it ‘saves the user and redirects to the index page’ do
user.should_receive(:persisted?).and_return(true)
post :create, group_id: group_id, user: attributes
expect(subject).to redirect_to(:users)
end
end
context ‘when attributes are not valid’ do
it ‘renders the new template’ do
user.should_receive(:persisted?).and_return(false)
post :create, group_id: group_id, user: attributes
expect(subject).to render_template(:new)
end
end
context ‘when group is not found’ do
it 'renders the not_found template' do
Group.should_receive(:find).with(group_id).and_raise(ActiveRecord::RecordNotFound)
expect(subject).to render_template(:not_found)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment