範圍的關係,我在Rails的兩種型號:創建與軌道4
class User < ActiveRecord::Base
enum user_type: [:admin, :normal]
end
和
class Department < ActiveRecord::Base
end
包容我寫了下面Rspec的測試:
require 'rails_helper'
RSpec.describe User, :type => :model do
it { should belong_to(:department).conditions(user_type: :admin)}
end
我需要什麼,我不知道如何實現這一點。我如何根據其類型創建兩個模型之間的關係?
換句話說,如何才能使這種關係只與類型爲「管理員」的用戶?
鏈接或我看到了類似的問題,並沒有爲我工作,測試仍然失敗
或者'user_type'是'normal'呢? –