使用默认测试获得错误

时间:2011-08-31 01:17:42

标签: ruby-on-rails unit-testing

以下是我在rails应用程序中的代码。我无法弄清楚为什么会导致这个错误?我应该开始寻找什么想法?我没有得到它从DELETE FROM工作负载调用的地方。

AccountsController& WorkloadsController都是空的。

测试

require 'test_helper'

class AccountTest < ActiveSupport::TestCase
  # Replace this with your real tests.
  test "the truth" do
    assert true
  end
end

错误

2) Error:
  test_the_truth(AccountTest):
  ActiveRecord::StatementInvalid: TinyTds::Error: Invalid object name 'workloads'.: DELETE FROM [workloads]

帐户模型

class Account < ActiveRecord::Base
  before_create :set_defaults

  set_table_name "Account"
  set_primary_key "AccountID"

  private
  def set_defaults
    self.UCPIN = UUIDTools::UUID.timestamp_create.to_s
  end
end

工作量模型

class Workload < ActiveRecord::Base
  set_primary_key "WorkloadID"
  set_table_name "Workload"
end

2 个答案:

答案 0 :(得分:1)

它的行为就像您忘记更新测试架构一样。

rake db:test:prepare

如果这不起作用,请查看test_helper.rb以查找任何设置/拆卸代码,如果卡住,请发布。

此外,您奇怪地使用名为Workload(单数/大写)的表,暗示遗留数据库,但错误是指workloads(复数/小写)。检查您对该表的引用所具有的任何配置文件,并确保它拼写正确。

答案 1 :(得分:0)

我找到了答案......它与需要重新定义和引用的灯具有关。这是给我答案的网站。

http://www.missiondata.com/blog/systems-integration/80/rails-fixtures-with-models-using-set_table_name/