public
Created

Adding SMS capabilities to your Rails Application

  • Download Gist
users_controller_test.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
require 'test_helper'
 
class MockedTwilioClient
def method_missing(*args)
self
end
end
 
class UsersControllerTest < ActionController::TestCase
 
test "#new" do
get :new
assert_response :success
assert_template :new
end
 
test "#create succeeds" do
mock(Twilio::REST::Client).new('',''){ MockedTwilioClient.new }
assert_difference 'User.count' do
post :create, user: {name: 'John Doe', email: 'john@doe.com', phone: '555-444-3434'}
assert_response :ok
end
end
 
test "#create fails on validation" do
assert_no_difference 'User.count' do
post :create, user: {name: 'Joe'}
assert_response :ok
assert_template :new
assert !assigns(:user).valid?
end
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.