Sha256: f133a45e54074af3925ac2ebda5e0a26a52dfaf4a02c281df1a27525103711bb

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Waylon
  module RSpec
    # A test Message class
    class TestMessage
      include Waylon::Message

      attr_reader :id

      # Simple way to list all TestMessages
      # @return [Array<TestMessage>]
      def self.all
        TestSense.message_list.each_index.map { |id| new(id) }
      end

      # @param message_id [Integer] The Message ID for the new TestMessage
      # @param details [Hash] Details hash for the new TestMessage
      def initialize(message_id, details = {})
        @id = message_id.to_i
        @details = details
      end

      # Provides the user that authored the message
      # @return [TestUser]
      def author
        TestUser.new(details[:user_id])
      end

      # Easy access to when the TestMessage was created
      # @return [Time]
      def created_at
        details[:created_at]
      end

      # Is this a private message?
      # @return [Boolean]
      def private_message?
        details[:type] == :private
      end

      # The TestChannel where this TestMessage lives
      # @return [TestChannel]
      def channel
        TestChannel.new(details[:channel_id])
      end

      # The Message content
      # @return [String]
      def text
        details[:text]
      end

      # Lazily provides the details for TestMessages
      # @api private
      # @return [Hash] The details for this TestMessage instance
      def details
        @details = TestSense.message_list[id] if @details.empty?
        @details.dup
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
waylon-core-0.1.1 lib/waylon/rspec/test_message.rb
waylon-core-0.1.0 lib/waylon/rspec/test_message.rb