所以有一个rails 5项目,并希望加载这样的目录
/app
/services
/user
foo.rb
Run Code Online (Sandbox Code Playgroud)
作为constant :: Services :: User :: Foo
有没有人有过使用rails自动加载路径以这种方式加载常量的经验?
foo.rb
module Services
module User
class Foo
end
end
end
Run Code Online (Sandbox Code Playgroud)
解
将其添加到您的application.rb文件中
config.autoload_paths << Rails.root.join('app')
请参阅此处有关自动加载的讨论
https://github.com/rails/rails/issues/14382#issuecomment-37763348 https://github.com/trailblazer/trailblazer/issues/89#issuecomment-149367035
我目前使用vue自动设置进行nightwatch.js设置.该模板位于此处.
https://github.com/vuejs-templates/webpack/tree/master/template/test/e2e
是否可以通过命令行以类似于webdriver.io中提供的REPL方式运行nightwatch声明?以下是对webdriver功能的参考https://twitter.com/webdriverio/status/806911722682544128
更新,我们已经开始使用Cypress.io它让我们非常高兴
我在使用 Rspec 测试 Pundit 策略范围时遇到了障碍。基本上,我试图测试范围内的返回值是否严格限于用户。因此,我循环遍历为用户返回的所有问题,并确保 id 等于用户。
这是绿色的,但是当它是非公民角色时它会失败,因为 Scope 调用仅返回一个 Issue 对象。这不是什么大问题,因为每个角色都有一个 .where() 的范围,但这是一种代码味道,我可能做错了一些事情。
我有一个执行该操作的 IssueController
class IssuePolicy < ApplicationPolicy
class Scope < Struct.new(:user, :scope)
def resolve
if user.role == 'citizen'
scope.where(:user_id => user.id)
else
scope
end
end
end
Run Code Online (Sandbox Code Playgroud)
为了在 rspec 中测试这一点,我必须这样做
require 'spec_helper'
describe IssuePolicy do
before(:each) do
@user = FactoryGirl.create(:user)
@issue = FactoryGirl.create(:issue)
@last_issue = FactoryGirl.create(:issue, user_id: User.last.id + 1)
end
context "for a citizen" do
before(:each) do
@user.update(role: 'citizen')
end
it "should only return their posts on …Run Code Online (Sandbox Code Playgroud)