इस प्रकार मैं एक रेल 3.0 अनुप्रयोग में एक गुंजाइश spec'ing हूँ के लिए Timecop मणि का उपयोग करना:कार्यक्षेत्र
before do
@list = DrawingList.create #things that include begin and end dates
end
it "doesn't find an active drawing if they are out of range" do
pending "really need to figure out how to work timecop in the presence of scopes"
Timecop.travel(2.days)
puts Date.today.to_s
DrawingList.active_drawings.first.should be_nil
end
आप हो सकता है के रूप में:
class DrawingList < ActiveRecord::Base
scope :active_drawings, where('start_date <= ? AND end_date >= ?', Date.today, Date.today)
end
मेरी कल्पना में, मैं क्या करना चाहते हैं कल्पना करें, रखता है वास्तव में दिखाता है कि तिथि। आज दो दिन है। हालांकि, दायरे का मूल्यांकन एक अलग संदर्भ में किया जाता है, इसलिए यह पुराने "आज" का उपयोग करता है। आज एक संदर्भ में मूल्यांकन कैसे किया जाता है कि टाइमकॉप प्रभावित हो सकता है।
धन्यवाद!
एक अच्छे प्रश्न का अच्छा जवाब। –
पकड़ने के लिए यह एक मुश्किल मुद्दा है! धन्यवाद। मैं बहुत खुश हूं अब मैं इस व्यवहार से अवगत हूं। –