Class: DataMapperMatchers::HasTimestamps
- Inherits:
-
Object
- Object
- DataMapperMatchers::HasTimestamps
- Defined in:
- lib/spec/matchers/dm/has_timestamps.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #has_timestamps ⇒ Object
- #included ⇒ Object
-
#initialize(*expected) ⇒ HasTimestamps
constructor
A new instance of HasTimestamps.
- #loaded ⇒ Object
-
#matches?(model) ⇒ Boolean
Category.should has_timestamps(:id).
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(*expected) ⇒ HasTimestamps
Returns a new instance of HasTimestamps.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 8 def initialize(*expected) # Post.should has_timestamps => :created_at, :updated_at expected.push(:at) if expected.empty? if [:at, :on].include?(expected.first) # Post.should has_timestamps(:at) @expected = ["created_#{expected}", "updated_#{expected}"] else # Post.should has_timestamps(:created_at) @expected = expected end end |
Instance Method Details
#description ⇒ Object
38 39 40 |
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 38 def description "has timestamps" end |
#failure_message ⇒ Object
42 43 44 45 |
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 42 def properties = @model.properties.entries.map { || .name } "expected to has timestamps #@expected, but has just the following properties: #{properties}" end |
#has_timestamps ⇒ Object
34 35 36 |
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 34 def @expected.all { |method| model.new.respond_to?(method) } end |
#included ⇒ Object
30 31 32 |
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 30 def included @model.respond_to?(:timestamps) # DataMapper::Timestamp model is included end |
#loaded ⇒ Object
26 27 28 |
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 26 def loaded $LOADED_FEATURES.any? { |file| File.basename(file).eql?("dm-timestamps.rb") } end |
#matches?(model) ⇒ Boolean
Category.should has_timestamps(:id)
21 22 23 24 |
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 21 def matches?(model) @model = model loaded && included && end |
#negative_failure_message ⇒ Object
47 48 49 |
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 47 def "expected not to not timestamps #@expected, but had" end |