Class: Waylon::RSpec::TestMessage

Inherits:
Object
  • Object
show all
Includes:
Message
Defined in:
lib/waylon/rspec/test_message.rb

Overview

A test Message class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Message

#mentions_bot?, #private?, #to_bot?

Constructor Details

#initialize(message_id, details = {}) ⇒ TestMessage

Returns a new instance of TestMessage.

Parameters:

  • message_id (Integer)

    The Message ID for the new TestMessage

  • details (Hash) (defaults to: {})

    Details hash for the new TestMessage



19
20
21
22
# File 'lib/waylon/rspec/test_message.rb', line 19

def initialize(message_id, details = {})
  @id = message_id.to_i
  @details = details
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/waylon/rspec/test_message.rb', line 9

def id
  @id
end

Class Method Details

.allArray<TestMessage>

Simple way to list all TestMessages

Returns:



13
14
15
# File 'lib/waylon/rspec/test_message.rb', line 13

def self.all
  TestSense.message_list.each_index.map { |id| new(id) }
end

Instance Method Details

#authorTestUser

Provides the user that authored the message

Returns:



26
27
28
# File 'lib/waylon/rspec/test_message.rb', line 26

def author
  TestUser.new(details[:user_id])
end

#channelTestChannel

The TestChannel where this TestMessage lives

Returns:



44
45
46
# File 'lib/waylon/rspec/test_message.rb', line 44

def channel
  TestChannel.new(details[:channel_id])
end

#created_atTime

Easy access to when the TestMessage was created

Returns:

  • (Time)


32
33
34
# File 'lib/waylon/rspec/test_message.rb', line 32

def created_at
  details[:created_at]
end

#detailsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Lazily provides the details for TestMessages

Returns:

  • (Hash)

    The details for this TestMessage instance



59
60
61
62
# File 'lib/waylon/rspec/test_message.rb', line 59

def details
  @details = TestSense.message_list[id] if @details.empty?
  @details.dup
end

#private_message?Boolean

Is this a private message?

Returns:

  • (Boolean)


38
39
40
# File 'lib/waylon/rspec/test_message.rb', line 38

def private_message?
  details[:type] == :private
end

#textString Also known as: body

The Message content

Returns:

  • (String)


50
51
52
# File 'lib/waylon/rspec/test_message.rb', line 50

def text
  details[:text]
end