2011-04-22 50 views

回答

4

我在使用flexmock時遇到同樣的問題。

原因是它沒有使用update_attributes方法來做出路由決定。它檢查resource.errors以查看它是否爲空。

所以爲了讓它正確響應,我們還需要剔除errors方法。

下面是相關代碼@line 248的lib/inherited_resources/base_helpers.rb

def respond_with_dual_blocks(object, options, &block) #:nodoc: 
    args = (with_chain(object) << options) 

    case block.try(:arity) 
     when 2 
     respond_with(*args) do |responder| 
      blank_slate = InheritedResources::BlankSlate.new 
      if object.errors.empty? 
      block.call(responder, blank_slate) 
      else 
      block.call(blank_slate, responder) 
      end 
     end 
     when 1 
     respond_with(*args, &block) 
     else 
     options[:location] = block.call if block 
     respond_with(*args) 
    end 
    end 
+0

它解決了我的問題。非常感謝! ;) – luacassus 2011-04-29 06:41:21

+0

用什麼來模擬出錯誤方法?我遇到了這個完全相同的問題...... – sevenseacat 2011-09-04 14:28:05

+1

啊,對了,我用'team.stub_chain(:errors,:empty?)。和_return(false)'來使用stub_chain,並且它完美地工作。 – sevenseacat 2011-09-04 14:38:46

0

失敗消息是關於無法從控制器內部訪問命名路由,所以我不確定這與mock_model有什麼關係。你是否用真實模型試過相同的例子?

+0

有了真正的機型它的工作沒有任何問題。 – luacassus 2011-04-22 19:47:43