小编Adr*_*ian的帖子

解决Rails孤立迁移的最佳方法是什么?

我一直在项目中的分支之间切换,每个分支都有不同的迁移...这是场景:

$ rake db:migrate:status

 Status   Migration ID    Migration Name
--------------------------------------------------
   ...
   up     20130307154128  Change columns in traffic capture
   up     20130311155109  Remove log settings
   up     20130311160901  Remove log alarm table
   up     20130320144219  ********** NO FILE **********
   up     20130320161939  ********** NO FILE **********
   up     20130320184628  ********** NO FILE **********
   up     20130322004817  Add replicate to root settings
   up     20130403190042  ********** NO FILE **********
   up     20130403195300  ********** NO FILE **********
   up     20130403214000  ********** NO FILE **********
   up     20130405164752  Fix ap hostnames
   up     20130410194222  ********** …
Run Code Online (Sandbox Code Playgroud)

migration git ruby-on-rails rails-migrations ruby-on-rails-3

34
推荐指数
5
解决办法
1万
查看次数

如何在 Angular 中测试管道中的多个请求?

我想测试在管道内完成的 3 个请求。简化示例:

    httpClient.get<Data[]>(testUrl)
      .pipe(
        mergeMap(() => range(0, 2)),
        mergeMap(() => httpClient.get<Data[]>(testUrl)),
      )
Run Code Online (Sandbox Code Playgroud)

我正在使用官方推荐: HttpTestingController。如果我一个接一个地收到请求,它就可以正常工作httpTestingController.match。然而,我真正的应用程序并不是这样编写的。它使用的是管道。

    let testData: Data[] = [
      { name: 'bob' }, { name: 'carol' },
      { name: 'ted' }, { name: 'alice' }
    ];

    // Make three requests in a row
    httpClient.get<Data[]>(testUrl)
      .subscribe(d => expect(d.length).toEqual(0, 'should have no data'));

    httpClient.get<Data[]>(testUrl)
      .subscribe(d => expect(d).toEqual([testData[0]], 'should be one element array'));

    httpClient.get<Data[]>(testUrl)
      .subscribe(d => expect(d).toEqual(testData, 'should be expected data'));

    // get all pending requests that match …
Run Code Online (Sandbox Code Playgroud)

testing unit-testing angular httptestingcontroller

6
推荐指数
1
解决办法
4730
查看次数

链式承诺和原型`this`

我很难获得承诺this在原型中使用正确的范围.

这是我的代码:

'use strict';

angular.module('testApp').factory('UrlSearchApi',
  function($resource, URL_SEARCH_API, PAGE_SIZE, $q){

  var resource = $resource(URL_SEARCH_API);

  resource.Scroll = function () {
    return this.reset();
  };

  resource.Scroll.prototype.reset = function () {
    this.visibleItems = [];
    this.allItems = [];
    this.busy = null;
    return this;
  };

  resource.Scroll.prototype.fetch = function(query){
    var params = {};
    if(query) { params.q = query; }
    return resource.query(params).$promise;
  };

  resource.Scroll.prototype.loadAllItems = function (results) {
    var d = $q.defer();

    angular.forEach(results, function (result, i) {
      this.allItems.push(result);
      if(i === results.length - 1 ) { d.resolve(); } …
Run Code Online (Sandbox Code Playgroud)

javascript jasmine angularjs karma-jasmine angular-promise

5
推荐指数
1
解决办法
126
查看次数

`value ="{{todo.title}}"`和`[value] ="todo.title"`之间有什么区别?

我一直在Angular 2做一个todo应用程序来掌握概念...... value="{{todo.title}}"和之间的区别是[value]="todo.title"什么?

data-binding angular

5
推荐指数
1
解决办法
678
查看次数

如何从本地目录复制到 docker 命名卷并将其挂载到 NGINX 容器上?

我想将一个public目录复制到命名卷中并将其挂载到所有 Nginx 容器中。

\n\n

这是我的 docker-compose.yml:

\n\n
version: \'3.7\'\nservices:\n  # http://localhost:8187/\n  nginx:\n    # build: .\n    image: nginx\n    # container_name: nginx\n    ports:\n      - "8187:80"\n    networks:\n      - public\n    volumes:\n      - nginx_logs:/var/log/nginx/\n      - nginx_public:/usr/share/nginx/html\n\n      # invalid mount config for type\xe2\x80\xa6\n      # - ./public:/usr/share/nginx/html:cached\n\n      # error: invalid mount config for type "bind": bind source path does not exist: /Users/admejiar/Code/uxer-analytics/events-hub/public"\n      # - type: bind\n      #   source: ./public\n      #   target: /usr/share/nginx/html\n\n\nnetworks:\n  public:\n\nvolumes:\n  nginx_logs:\n  nginx_public:\n    driver: local\n    driver_opts:\n      type: none\n      o: bind\n      device: $PWD/public\n\n
Run Code Online (Sandbox Code Playgroud)\n\n …

nginx docker docker-compose docker-swarm docker-volume

5
推荐指数
0
解决办法
1168
查看次数

为什么多场映射不适用于有弹性搜索的轮胎宝石?

我正在使用弹性搜索来增强我的应用中的搜索功能.搜索工作正常,但排序不适用于包含多个单词的字段.

当我尝试按日志'消息'对搜索进行排序时,我收到错误:

"无法对每个文档具有多个值的字符串类型进行排序,或者每个字段使用多个标记"

我搜索了错误并发现我可以在:message字段上使用多字段映射(一个分析而另一个不分析)来对它们进行排序.所以我这样做了:

class Log < ActiveRecord::Base
  include Tire::Model::Search
  include Tire::Model::Callbacks

  tire.mapping do
    indexes :id, index: :not_analyzed
    indexes :source, type: 'string'
    indexes :level, type: 'string'
    indexes :created_at, :type => 'date', :include_in_all => false
    indexes :updated_at, :type => 'date', :include_in_all => false
    indexes :message, type: 'multi_field', fields: { 
      analyzed: {type: 'string', index: 'analyzed'},
      message: {type: 'string', index: :not_analyzed} 
    }
    indexes :domain, type: 'keyword'
  end
end
Run Code Online (Sandbox Code Playgroud)

但是,由于某种原因,没有将此映射传递给ES.

rails console
Log.index.delete #=> true
Log.index.create #=> 200 : {"ok":true,"acknowledged":true}
Log.index.import Log.all #=> 200 …
Run Code Online (Sandbox Code Playgroud)

ruby mapping ruby-on-rails elasticsearch tire

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

尝试存根 Node 模块中使用的方法

我正在尝试模拟 Node 模块中的一个函数。但它不允许我。有任何想法吗?

// module A

function foo(){
  return 1;
}

function bar(){
   return foo() + 1;
}

module.exports = {foo, bar}
Run Code Online (Sandbox Code Playgroud)

在测试...

const a = require('a');
...
sinon.stub(a, 'foo').callsFake(() => 3);
expect(a.bar()).to.equal(4); // gets 2 instead of 4
Run Code Online (Sandbox Code Playgroud)

stub mocha.js node.js sinon chai

0
推荐指数
1
解决办法
493
查看次数