Skip to content

Instantly share code, notes, and snippets.

@fronx
Forked from manuelkiessling/gist:982566
Created May 20, 2011 09:28
Show Gist options
  • Save fronx/982618 to your computer and use it in GitHub Desktop.
Save fronx/982618 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe SharesController do
render_views
describe '#create' do
let(:share_params) { :facebook_id => 'abc', :address_id => 7 }
it "redirects to login" do
post :create, :share => share_params
response.should redirect_to login_path
end
context "if the user is logged in" do
before { @user = login_user }
context "and the parameters are valid" do
it "creates a new Share" do
share = mock_model(Share)
share.should_receive(:save).and_return(true)
Share.should_receive(:new).
with(share_params.merge(:user_id => @user.id)).
and_return(share)
post :create, :format => :json, :share => share_params
end
it "responds with success" do
Share.stub_chain(:new, :save).and_return(true)
post :create, :format => :json, :share => share_params
response.should be_success
end
end
context "and the parameters are invalid" do
# ...
end
end
end
end
@manuelkiessling
Copy link

Beautiful, thanks for teaching me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment