2012-08-03 10 views
6

मैं इस आसान सत्यापन पर अपना सिर तोड़ रहा हूं और मैं इसे सत्यापित करने के लिए नहीं मिल सकता।रुपये और फैक्ट्रीगर्ल स्वीकृति सत्यापन

describe "event has many attendances" do 
    it "should have attendances" do 
     event = FactoryGirl.create(:event) 
     user1 = FactoryGirl.create(:user, firstname: "user1", email: "[email protected]") 
     user2 = FactoryGirl.create(:user, firstname: "user2", email: "[email protected]") 

     attendance1 = FactoryGirl.create(:attendance, event: event, user: user1, terms_of_service: true)  
    end 
    end 

यह किसी भी त्रुटि को लाने नहीं करना चाहिए लेकिन यह करता है:

factory :attendance do 
    user 
    event 
    terms_of_service true 
    end 

यह मेरी परीक्षा है:

class Attendance < ActiveRecord::Base 
    belongs_to :user, counter_cache: true 
    belongs_to :event, counter_cache: true 

    validates :terms_of_service, :acceptance => true 
end 

यह मेरा फैक्टरी है: मैं निम्नलिखित मॉडल मिल गया है ।

Running spec/models/workshop_spec.rb 
.............F 

Failures: 

    1) Event event has many attendances should have attendances 
    Failure/Error: attendance1 = FactoryGirl.create(:attendance, event: event, user: user1, terms_of_service: true) 
    ActiveRecord::RecordInvalid: 
     Validation failed: Terms of service must be accepted 
    # ./spec/models/event_spec.rb:33:in `block (3 levels) in <top (required)>' 

जब मैं अपने ब्राउज़र में ये क्रिया करता हूं और मैं स्वीकार करता हूं कि सभी अच्छी तरह से चलते हैं। मुझे यहां क्या समझ नहीं आ रहा है?!

उत्तर

9

:terms_of_service डीबी कॉलम में मैप किया गया है? validates :acceptance के लिए डिफ़ॉल्ट मान स्ट्रिंग "1" है, true नहीं है। यह स्तंभ db से मैप किया गया है, तो सत्यापन के लिए :accept => true जोड़ने का प्रयास:

validates :terms_of_service, :acceptance => {:accept => true} 

क्षेत्र मैप नहीं है, तो या डीबी स्तंभ बूलियन नहीं है, परीक्षण और कारखानों में सच की "1" का उपयोग करने के बजाय कोशिश ।

+0

धन्यवाद, वह था! मैंने सब कुछ एक स्ट्रिंग के अलावा कोशिश की। धन्यवाद, रिकॉर्ड के लिए यह एक आभासी विशेषता थी! –

+0

@dimuch क्या आप कभी जानते थे कि तुम मेरे नायक हो? धन्यवाद। – Jeff

संबंधित मुद्दे