我在mysql下通过了以下测试(使用FactoryGirl):
test "order by title" do
@library = create(:drawing_library, title: 'Accessories')
@drawing = create(:drawing, drawing_library: @library, title: 'Test Drawing')
create(:drawing, drawing_library: @library, title: 'z')
create(:drawing, drawing_library: @library, title: 'm')
create(:drawing, drawing_library: @library, title: 'b')
str = ''
@library.drawings.each do |dwg|
str += dwg.title
end
assert_equal 'bmTest Drawingz', str
end
绘图模型为:
class Drawing < ActiveRecord::Base
belongs_to :drawing_library
default_scope order: :title
..
end
在 postgresql 下,这个测试现在失败了:
<"bmTest Drawingz"> expected but was
<"Test Drawingbmz">.
这似乎是因为“测试绘图”中的 T 是大写的。如果我将其更改为“测试绘图”,则测试通过。
有没有办法让default_scope order
大小写不敏感?