-
-
Save fronx/982618 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Beautiful, thanks for teaching me!