是否可以使用我的Rails应用程序启动AMQP订阅者?可能通过初始化器或其他东西.
我想让它同时运行,也可以与Rails模型交互.下面是我的意思的伪代码示例.
queue.subscribe do |msg,body|
Foo.create(....)
end
Run Code Online (Sandbox Code Playgroud) 我想我有一点鸡蛋和鸡蛋的问题.我想设置通过Paperclip上传的文件的content_type.问题是默认的content_type只基于扩展,但我想将它建立在另一个模块上.
我似乎能够使用before_post_process设置content_type
class Upload < ActiveRecord::Base
has_attached_file :upload
before_post_process :foo
def foo
logger.debug "Changing content_type"
#This works
self.upload.instance_write(:content_type,"foobar")
# This fails because the file does not actually exist yet
self.upload.instance_write(:content_type,file_type(self.upload.path)
end
# Returns the filetype based on file command (assume it works)
def file_type(path)
return `file -ib '#{path}'`.split(/;/)[0]
end
end
Run Code Online (Sandbox Code Playgroud)
但是......我不能将内容类型基于文件,因为Paperclip直到after_create才写入文件.
并且我似乎无法在保存后使用content_type或使用after_create回调(甚至回到控制器中)
所以我想知道在保存之前我是否可以以某种方式访问实际的文件对象(假设没有处理器对原始文件做任何事情),这样我就可以在其上运行file_type命令.或者有一种方法可以在创建对象后修改content_type.
我有一个身份验证中间件,需要调用外部服务并提供回调URL.例如:
var express = require('express');
var app = express();
// This will work just fine
app.use('/', getAuthRouter());
// The redirects here will end up going to /oauth/callback
// instead of /admin/oauth/callback
app.use('/admin', getAuthRouter());
function getAuthRouter() {
var authRouter = express.Router();
// Setup auth routes
var callbackUrl = '/oauth/callback';
var loginUrl = '/login';
authRouter.get(callbackUrl, .... });
authRouter.get(loginUrl, function(req, res, next){
// Make call to OAuth server
res.redirect("http://authserver/?callback=" + callbackUrl);
});
return authRouter;
}
Run Code Online (Sandbox Code Playgroud)
问题是,authRouter
它不知道它实际上是在下面安装的,/admin
所以它无法将它添加到callback
参数中.
有什么方法可以让我在 …
我想模拟super
调用,特别是一些ES6类中的构造函数.例如
import Bar from 'bar';
class Foo extends Bar {
constructor(opts) {
...
super(opts);
}
someFunc() {
super.someFunc('asdf');
}
}
Run Code Online (Sandbox Code Playgroud)
然后在我的测试中,我想做类似的事情
import Foo from '../lib/foo';
import Bar from 'bar';
describe('constructor', function() {
it('should call super', function() {
let opts = Symbol('opts');
let constructorStub = sinon.stub(Bar, 'constructor');
new Foo(opts);
sinon.assert.calledWith(constructorStub, opts);
});
})
describe('someFunc', function() {
it('should call super', function() {
let funcStub = sinon.stub(Bar, 'someFunc');
let foo = new Foo(opts);
foo.someFunc();
sinon.assert.calledWith(funcStub, 'asdf');
});
})
Run Code Online (Sandbox Code Playgroud) amqp ×1
content-type ×1
ecmascript-6 ×1
express ×1
javascript ×1
mocha.js ×1
node.js ×1
paperclip ×1
rabbitmq ×1
sinon ×1
unit-testing ×1