Skip to content

Instantly share code, notes, and snippets.

@waseem
Created May 30, 2011 10:43
Show Gist options
  • Save waseem/998711 to your computer and use it in GitHub Desktop.
Save waseem/998711 to your computer and use it in GitHub Desktop.
class SmsNoticesController < ApplicationController
def create
listing = Listing.find(params[:listing_id])
sms = Sms.new(listing.name, params[:phone_number])
if sms.deliver
flash[:notice] = "SMS sent successfully."
else
flash[:alert] = "Something went wrong. Please try sending SMS again."
end
respond_to do |format|
format.html { redirect_to(listing_url(listing)) }
end
end
end
require 'spec_helper'
describe SmsNoticesController do
describe "SMS sending" do
before(:each) do
@listing = mock_model(Listing, :name => "Google")
end
describe "#create" do
before(:each) do
Listing.stub!(:find).with(@listing.id).and_return(@listing)
@sms = mock(Sms) # non databse backed model
end
it 'should send sms and inform user' do
controller.should_receive(:simple_captcha_valid?).and_return(true)
@sms.should_receive(:deliver).and_return(true)
post :create, :listing_id => @listing.id
flash[:notice].should == "SMS sent successfully."
response.should redirect_to(listing_url(@listing))
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment