0

我正在使用带有 rails 的 Ajax 调用来调用控制器中的方法。我的问题是代码本身工作正常,我看不到任何错误。当我去测试我得到的代码时

ActionView::MissingTemplate: Missing template branch/call_s ml], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "C:/home/Ruby/rails/showrooms/texting/app/views" * "C:/home/Ruby/rails/showrooms/texting/app/views/shared" * "C:/home/Ruby/rails/showrooms/texting/app/views"

这是我的控制器方法。

  # Sends a SMS message to selected phone number. 
  # 
  def call_sms
    if current_associate    
      @text_number    = params[:phone_number]
      @text_message   = params[:text_message].to_s
      if !@text_number.empty? && !@text_message.empty?

        @sms = ShortMessagingService.new  
        if @sms.send(@text_number, @text_message)       
          @sms_message = "Status: #{@sms.sent?}"
        end
      else
       @sms_message = 'Phone number and text field cannot be blank.'
     end
   else
     @sms_message = 'You do not have perission for this feature.'
   end
 end

这是路线

# Small Messaging Service rout. 
post 'call_sms' => 'branch#call_sms'
match 'call_sms' => 'branch#call_sms'

这是表格:

<%= form_for :call_sms, url: {action: "call_sms"},  
    :method => :post, :remote => true, 
    :html => {:id => 'sms_form'} do |f| 
%> 
.
.
.
<% end %>

这是我的测试

  test "Can send sms messages." do
    phone_number  = '18006388875'
    text_message  = "Hey this is a test. Don't text and drive."
    post :call_sms
    assert_response :ok
  end
4

1 回答 1

1

您的表单正在执行 ajax 请求,但您的测试用例不是。

而不是post :call_sms,试试这个:

xhr :post, :call_sms

这告诉测试用例发送 ajax 帖子而不是常规帖子。

于 2013-09-27T19:39:44.657 回答