小编Aus*_*tio的帖子

在rails app目录中将文件夹作为模块常量加载的方法

所以有一个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

ruby ruby-on-rails ruby-on-rails-5

9
推荐指数
1
解决办法
2664
查看次数

通过REPL驾驶Nightwatch测试

我目前使用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它让我们非常高兴

selenium nightwatch.js

8
推荐指数
1
解决办法
245
查看次数

Rails Pundit Rspec 测试

我在使用 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)

ruby-on-rails rspec-rails pundit

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