users_group_observer_spec.rb 872 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
require 'spec_helper'

describe UsersGroupObserver do
  before(:each) { enable_observers }
  after(:each) { disable_observers }

  subject { UsersGroupObserver.instance }
  before { subject.stub(notification: mock('NotificationService').as_null_object) }

  describe "#after_create" do
    it "should send email to user" do
      subject.should_receive(:notification)
      create(:users_group)
    end
  end

  describe "#after_update" do
    before do
      @membership = create :users_group
    end

    it "should send email to user" do
      subject.should_receive(:notification)
      @membership.update_attribute(:group_access, UsersGroup::MASTER)
    end
26 27 28 29 30

    it "does not send an email when the access level has not changed" do
      subject.should_not_receive(:notification)
      @membership.update_attribute(:group_access, UsersGroup::OWNER)
    end
31 32
  end
end