0
我有一個Rails 4測試版應用程序(在Ruby 2上),並且出現了一個我無法理解的錯誤。'創建'的ActiveRecord模型子類NoMethodError
我有一些規格失敗,因爲我的模型類沒有創建方法,即使我從ActiveRecord :: Base繼承。該錯誤消息是呼叫我的班級模塊(undefined method 'create' for Topic:Module
),這似乎很奇怪。
規格/模型/ topic_spec.rb:
require "spec_helper"
describe Topic do
it "should create a new topic given valid attributes" do
Topic.create!({:created_by_id => 1, :title => "Test" })
end
end
應用/模型/ topic.rb
class Topic < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
validates :title => :presence => ture
validates :created_by_id => :presence => true
end
錯誤消息:
$ rspec spec/models/topic_spec.rb
F
Failures:
1) Topic should create a new topic given valid attributes
Failure/Error: Topic.create!({:created_by_id => 1, :title => "Test" })
NoMethodError:
undefined method `create' for Topic:Module
# ./spec/models/topic_spec.rrc:15:in `block (2 levels) in <top (required)>'
正確的金錢。該應用程序被稱爲「主題」。非常感謝! –