Rails 测试 (minitest) 导致 PostgreSQL 语法错误
Rails tests (minitest) cause PostgreSQL syntax error
因此,每当我 运行 进行测试时,Rails 似乎试图向我的 PostgreSQL 数据库中插入任何内容...导致语法错误。什么可能导致这个?在某些情况下,无论多么简单或复杂,每次测试都会发生这种情况。例如:
class PlayerTest < ActiveSupport::TestCase
test "should not save empty player" do
assert true
end
end
然后我看到以下错误消息:
Error:
PlayerTest#test_should_not_save_empty_player:
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near ")"
LINE 1: INSERT INTO "players_venues" () VALUES ()
此外,players_venues
是 players
和 venues
之间的多对多联接 table。此问题不会在测试之外发生。任何帮助将不胜感激。如果需要更多代码,请随时询问。
所以我最终弄明白了。事实证明 Rails 生成空的固定装置,如下所示:
one: {}
# column: value
#
two: {}
# column: value
当您 运行 测试时,它不会尝试插入任何内容!非常感谢 jdno 给我提示以查看固定装置。热血冠军.
因此,每当我 运行 进行测试时,Rails 似乎试图向我的 PostgreSQL 数据库中插入任何内容...导致语法错误。什么可能导致这个?在某些情况下,无论多么简单或复杂,每次测试都会发生这种情况。例如:
class PlayerTest < ActiveSupport::TestCase
test "should not save empty player" do
assert true
end
end
然后我看到以下错误消息:
Error:
PlayerTest#test_should_not_save_empty_player:
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near ")"
LINE 1: INSERT INTO "players_venues" () VALUES ()
此外,players_venues
是 players
和 venues
之间的多对多联接 table。此问题不会在测试之外发生。任何帮助将不胜感激。如果需要更多代码,请随时询问。
所以我最终弄明白了。事实证明 Rails 生成空的固定装置,如下所示:
one: {}
# column: value
#
two: {}
# column: value
当您 运行 测试时,它不会尝试插入任何内容!非常感谢 jdno 给我提示以查看固定装置。热血冠军.