小编Jos*_*eim的帖子

Shoulda/RSpec:确保验证消息"xxx"已打开:base

我仍然很困惑什么是魔法背后的东西it { should have(1).error_on(:base) },什么是特定的Shoulda匹配器.

我想确保:base包含错误消息"xxx",那么我该怎么做呢?

it "should contain error message 'xxx'" do
  contact.valid?
  contact.errors[:base].should include('xxx')
end
Run Code Online (Sandbox Code Playgroud)

这是"走的路",还是更好的?谢谢.

ruby validation rspec ruby-on-rails shoulda

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

使用RSpec时删除rake测试?

我在我的Rails应用程序中使用RSpec,但在执行时rake -T我仍然获得默认的testrake任务:

rake spec             # Run all specs in spec directory (excluding plugin specs) / Run RSpec cod...
rake spec:controllers # Run the code examples in spec/controllers
rake spec:models      # Run the code examples in spec/models
rake spec:requests    # Run the code examples in spec/requests
rake spec:routing     # Run the code examples in spec/routing
rake stats            # Report code statistics (KLOCs, etc) from the application
rake test             # Runs test:units, test:functionals, test:integration together
rake test:all         # …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails

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

使元素仅对于屏幕阅读器可列表

是否可以仅为屏幕阅读器制作元素?我知道我可以为所有设备制作一个不可列表的元素(tabindex="-1"),但是有类似的东西aria-tabindex吗?所以我可以做以下事情:

<input type="text" tabindex="-1" aria-tabindex="0" />
Run Code Online (Sandbox Code Playgroud)

我需要这个,因为客户想对于一些普通的HTML输入一个奇特的GUI,所以我想使自己的投入非tabbable(视觉用户谁可以使用GUI),而且使tabbable非视觉用户(然后谁可以简单地对HTML输入进行操作,并且可以隐藏GUI aria-hidden="true").

更新

我在这个标题为"可访问,键盘友好的自定义选择菜单 " 博客中找到了解决我的特定问题的解决方案(为视觉键盘和鼠标用户提供了一个精美的GUI,同时又不影响屏幕阅读器用户的体验):

诀窍是将原生select元素放置在花哨的GUI(视觉上隐藏使用opacity: 0)之上,它本身将接收到的点击传播到操纵本机的自定义JS select.这样GUI就不需要是可聚焦的,这解决了我这个特例的问题.即使是文本浏览器也会享受完整的体验.

我不知道这个技巧可以扩展到更复杂的花式GUI多远,但它绝对是个好主意.

html accessibility tabindex wai-aria

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

Rails单表继承:类型coumn未自动填充

我想在Rails 4中使用STI.我已经有了一个模型Boilerplate,现在我想从它继承一个BoilerplateOriginal和一个BoilerplateCopy模型.所以我type在表格中添加了一列:

class AddTypeToBoilerplates < ActiveRecord::Migration
  def up
    add_column :boilerplates, :type, :string
    Boilerplate.update_all type: 'BoilerplateOriginal'
    change_column :boilerplates, :type, :string, null: false
  end

  def down
    remove_column :boilerplates, :type
  end
end
Run Code Online (Sandbox Code Playgroud)

遗憾的是,这个专栏似乎没有被Rails自动填充:

[1] a4aa2 »  x = Boilerplate.new
=> #<Boilerplate:0x00000101609580> {
               :id => nil,
            :title => nil,
             :type => nil
}
[2] a4aa2 »  x.valid?
  Boilerplate Exists (0.4ms)  SELECT  1 AS one FROM "boilerplates" WHERE "boilerplates"."title" IS NULL LIMIT 1
=> false
[3] a4aa2 …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails single-table-inheritance

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