小编sha*_*ott的帖子

在redis-rb中删除多个键

在Rails应用程序中使用redis-rb,以下内容不起作用:

irb> keys = $redis.keys("autocomplete*")
=> ["autocomplete_foo", "autocomplete_bar", "autocomplete_bat"]
irb> $redis.del(keys)
=> 0
Run Code Online (Sandbox Code Playgroud)

这很好用:

irb> $redis.del("autocomplete_foo", "autocomplete_bar")
=> 2
Run Code Online (Sandbox Code Playgroud)

我错过了一些明显的东西吗 来源只是:

# Delete a key.
def del(*keys)
  synchronize do
    @client.call [:del, *keys]
  end
end
Run Code Online (Sandbox Code Playgroud)

看起来像我应该工作传递一个数组...?

ruby redis

16
推荐指数
3
解决办法
2万
查看次数

当多个相似字段出现在表单中时,选择更好的黄瓜(基于Capybara)

(有些背景如果有帮助:我们的Rails应用程序有一堆使用双嵌套字段的可能重复的动态生成表单,模式中的id为foo_attributes_0_bar_attributes_0_bat_12,其中前两个数字基本上是根据嵌套表单的重复次数而增加的是,并且最后一个数字是特定"bat"对象的id.这使得在Cucumber中进行选择以进行测试很困难!)

我想写一些像这样的步骤:

When I check the 1st checkbox with the value "Bat 12"
Run Code Online (Sandbox Code Playgroud)

要么

When I check the 3rd checkbox with id matching "bar_attributes_bat"
Run Code Online (Sandbox Code Playgroud)

我有以下工作,但我找到复选框(或字段)的方法对我来说似乎非常糟糕和低效:

When /^I check the (\d+)(st|nd|rd|th) checkbox with the value "([^"]*)"$/ do |number, junk, value|
  check(page.all("input").select {|el| el.node['value'] == value}[(number.to_i-1)].node['id'])
end

When /^I check the (\d+)(st|nd|rd|th) checkbox with id matching "([^"]*)"$/ do |number, junk, id_string|
  check(page.all("input").select {|el| el.node['id'] && el.node['id'].match(/#{id_string}/)}[(number.to_i-1)].node['id'])
end
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来选择这些输入元素?

checkbox cucumber capybara

4
推荐指数
1
解决办法
2247
查看次数

标签 统计

capybara ×1

checkbox ×1

cucumber ×1

redis ×1

ruby ×1