小编jel*_*der的帖子

如何在Rails 4中测试Controller关注点

在Rails 4控制器中使用时,处理问题测试的最佳方法是什么?说我有一个小问题Citations.

module Citations
    extend ActiveSupport::Concern
    def citations ; end
end
Run Code Online (Sandbox Code Playgroud)

测试中的预期行为是包含此关注点的任何控制器都将获得此citations端点.

class ConversationController < ActionController::Base
    include Citations
end
Run Code Online (Sandbox Code Playgroud)

简单.

ConversationController.new.respond_to? :yelling #=> true
Run Code Online (Sandbox Code Playgroud)

但是,孤立地测试这种问题的正确方法是什么?

class CitationConcernController < ActionController::Base
    include Citations
end

describe CitationConcernController, type: :controller do
    it 'should add the citations endpoint' do
        get :citations
        expect(response).to be_successful
    end
end
Run Code Online (Sandbox Code Playgroud)

不幸的是,这失败了.

CitationConcernController
  should add the citations endpoint (FAILED - 1)

Failures:

  1) CitationConcernController should add the citations endpoint
     Failure/Error: get :citations
     ActionController::UrlGenerationError:
       No route matches {:controller=>"citation_concern", …
Run Code Online (Sandbox Code Playgroud)

controller rspec ruby-on-rails activesupport-concern

40
推荐指数
3
解决办法
2万
查看次数

dailyLimitExceeded错误,但API控制台显示21%的配额

使用Ruby API客户端,一个服务帐户,以及每天50k请求的"礼貌限制",我们在发出几百个请求后就开始看到这个错误.

{
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "dailyLimitExceeded",
        "message": "Quota Error: profileId ga:REDACTED has exceeded the daily request limit."
      }
    ],
    "code": 403,
    "message": "Quota Error: profileId ga:REDACTED has exceeded the daily request limit."
  }
}
Run Code Online (Sandbox Code Playgroud)

API控制台显示我们仅占配额的21%.前几天,当我们占配额的51%左右时,错误开始发生.

Google API控制台的屏幕截图,显示了21%的配额

我们的用法从未如此激进:

在此输入图像描述

google-api google-analytics-api

2
推荐指数
1
解决办法
1314
查看次数