Sha256: 65fa855ae6ed328d5f791de861d51c060a96a1479b2dbba22fd0218bc0644f30

Contents?: true

Size: 1.69 KB

Versions: 5

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

describe "custom require" do
  before(:each) do
    # Use clean version of Message class
    ActsAsMessageable.instance_eval { remove_const "Message" }
    load "acts-as-messageable/message.rb"
  end

  it "should work with non-array require" do
    User.acts_as_messageable :required => :body
    ActsAsMessageable::Message.required.should == ([:body])
  end

  it "should work with array require" do
    User.acts_as_messageable :required => [:body, :topic]
    ActsAsMessageable::Message.required.should == ([:body, :topic])
  end

  context "only body" do
    before(:each) do
      User.acts_as_messageable :required => :body
    end

    it "alice should able to send message to bob only with body" do
      @alice.send_message(@bob, "Hello bob!")
      @alice.messages.first.body.should == "Hello bob!"
      @bob.received_messages.first.body.should == "Hello bob!"
    end

    it "alice should able to send message to bob with hash" do
      @alice.send_message(@bob, :body => "Hi Bob! I'm hash master")
      @alice.messages.first.body.should == "Hi Bob! I'm hash master"
    end

    it "alice send message to bob with body and bob reply to alice" do
      @alice.send_message(@bob, "Hi Bob!")
      @message_from_alice = @bob.received_messages.first
      @message_from_alice.body.should == "Hi Bob!"
      @bob.reply_to(@message_from_alice, "Hi Alice!")
      @alice.received_messages.first.body.should == "Hi Alice!"
    end

    it "alice send message to bob and bob reply with hash" do
      @message_from_alice = @alice.send_message(@bob, "Hi Bob!")
      @bob.reply_to(@message_from_alice, :body => "Hi Alice!")
      @alice.received_messages.first.body.should == "Hi Alice!"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
acts-as-messageable-0.4.10 spec/custom-required_spec.rb
acts-as-messageable-0.4.9 spec/custom-required_spec.rb
acts-as-messageable-0.4.8 spec/custom-required_spec.rb
acts-as-messageable-0.4.7 spec/custom-required_spec.rb
acts-as-messageable-0.4.6 spec/custom-required_spec.rb