Class: DataMapperMatchers::HasTimestamps

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/matchers/dm/has_timestamps.rb

Instance Method Summary collapse

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

#descriptionObject



38
39
40
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 38

def description
  "has timestamps"
end

#failure_messageObject



42
43
44
45
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 42

def failure_message
  properties = @model.properties.entries.map { |timestamps| timestamps.name }
  "expected to has timestamps #@expected, but has just the following properties: #{properties}"
end

#has_timestampsObject



34
35
36
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 34

def has_timestamps
  @expected.all { |method| model.new.respond_to?(method) }
end

#includedObject



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

#loadedObject



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)

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 21

def matches?(model)
  @model = model
  loaded && included && has_timestamps
end

#negative_failure_messageObject



47
48
49
# File 'lib/spec/matchers/dm/has_timestamps.rb', line 47

def negative_failure_message
  "expected not to not timestamps #@expected, but had"
end