轨道 Arel 单元测试错误



我有以下错误:

ERROR["test_character_should_be_valid", CharacterTest, 0.214787]
test_character_should_be_valid#CharacterTest (0.21s)
NoMethodError:         NoMethodError: undefined method `val' for "$1":Arel::Nodes::BindParam
app/models/user.rb:11:in `block in <class:User>'
test/models/character_test.rb:8:in `setup'

来自以下测试:test/models/character_test.rb:

    require 'test_helper'
    class CharacterTest < ActiveSupport::TestCase
      def setup
        @user = User.new(name: "Example User", email: "user@example.com", callsign: "example",
                         password: "foobar", password_confirmation: "foobar")
        @user.save
        @character = @user.character
      end
      test "character should be valid" do
        assert @character.valid?
      end
    end # CharacterTest

在宝石文件中:

gem 'arel', '6.0.0.beta2'

字符.rb:

class Character < ActiveRecord::Base
  belongs_to :sociable, polymorphic: true
end

用户.rb:

class User < ActiveRecord::Base
  has_one  :character, as: :sociable
  before_validation do
    self.create_character unless character # line 11
  end
  .
  .
end

我找不到有关此特定 arel 错误的任何信息。我的 arel gem 是 6.0.0.beta2,它似乎解决了其他问题(如此处)。以前有人见过这样的事情吗?

事实证明这不是

Arel 错误 - 这是因为列sociable_id和sociable_type未在架构中定义。我愚蠢的错误。Arel 引发了异常,因为缺少外键。但是,此处的 Arel 有一个改进的错误消息:https://github.com/rails/rails/commit/78bd18a90992e3da767cfe492f1bc5d63077da8a

相关内容

  • 没有找到相关文章

最新更新