Created
May 30, 2011 10:43
-
-
Save waseem/998711 to your computer and use it in GitHub Desktop.
This file contains 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
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 |
This file contains 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 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