Getting an error with the default tests
Below is the code that I have in my rails application. I can't figure out why it's causing this error? Any ideas where I should start looking? I don't get where it's getting the DELETE FROM workloads call from.
The AccountsController & WorkloadsController are both empty.
Test
require 'test_helper'
class AccountTest < ActiveSupport::开发者_StackOverflow社区TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
Error
2) Error:
test_the_truth(AccountTest):
ActiveRecord::StatementInvalid: TinyTds::Error: Invalid object name 'workloads'.: DELETE FROM [workloads]
Account Model
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
Workload Model
class Workload < ActiveRecord::Base
set_primary_key "WorkloadID"
set_table_name "Workload"
end
It's behaving like you forgot to update your test schema.
rake db:test:prepare
If that doesn't work, look at test_helper.rb
for any setup / teardown code, and post that if you get stuck.
Also, you're oddly using a table named Workload
(singular / capitalized), implying a legacy db, but the error is referring to workloads
(plural / lowercase). Check any config files you have for references to this table and make sure that it's spelled correctly.
I found the answer... it has to do with fixtures needing to be redefined and reference. Here's the site that gave me the answer.
http://www.missiondata.com/blog/systems-integration/80/rails-fixtures-with-models-using-set_table_name/
精彩评论