小编din*_*jas的帖子

Rspec send_data测试未通过

我似乎无法通过这个测试,我不明白为什么.

controller_spec.rb:

require 'rails_helper'

RSpec.describe QuotationRequestsController, type: :controller do

  describe "GET download" do    
    it "streams the sample text as a text file" do
      #setup
      quotation_request = create(:quotation_request)
      file_options = {filename: "#{quotation_request.id}-#{quotation_request.client.name.parameterize}.txt", type: 'plain/text', disposition: 'attachment'}

      #exercise
      get :download, id: quotation_request

      #verification
      expect(@controller).to receive(:send_data).with(file_options) {@controller.render nothing: true}      
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

控制器:

def download
  @quotation_request = QuotationRequest.find(params[:id])
  send_data @quotation_request.sample_text, {
    filename: @quotation_request.sample_text_file, 
    type: "text/plain",
    disposition: "attachment"
  }
end
Run Code Online (Sandbox Code Playgroud)

输出测试:

1) QuotationRequestsController GET download streams the sample text as a text file
  Failure/Error: …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails

7
推荐指数
1
解决办法
1152
查看次数

Mongodb $ inc嵌入值语法

我正在尝试使用$ inc运算符在我的mongodb文档中增加一个字段.我想要增加的字段是我的文档计数字段的子属性,例如:

mydoc: {
    count: {
        schedules: 0
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试这个:

> db.mydocs.update({ _id: new ObjectId('4db5c2f3dc73c5afdaffd636') }, { $inc: { count.schedules: 1 } }, { upsert: true, safe: true }, null);
Run Code Online (Sandbox Code Playgroud)

从我的mongo shell,我收到此错误消息:

Mon Apr 25 11:59:05 SyntaxError: missing : after property id (shell):1
Run Code Online (Sandbox Code Playgroud)

我尝试了几种类似结果的语法变体.我需要采取不同的方法吗?我已经验证了我的文档存在并且有一个count.schedules字段设置为0.

我可以使用如下命令直接设置值:

 db.mydocs.update({ _id: new ObjectId('4db5c2f3dc73c5afdaffd636') }, { $set: { count: {  schedules:1 } } }, null, null);
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试$ inc操作的语法,我会收到此错误:

Modifier $inc allowed for numbers only
Run Code Online (Sandbox Code Playgroud)

谢谢

javascript database mongodb node.js

3
推荐指数
1
解决办法
4996
查看次数

没有'to_s'的Ruby对象

红宝石中是否有任何不响应的物体to_s

问题并不是要问是否有可能创建一个,我知道可以做到undef_method.随意解释细节,包括取消定义的警告.

ruby

3
推荐指数
1
解决办法
136
查看次数

标签 统计

database ×1

javascript ×1

mongodb ×1

node.js ×1

rspec ×1

ruby ×1

ruby-on-rails ×1