Sha256: 2c3924144081fa1d403e2d3e754c2b198d6d0f9430207ed0a4a13bf85ee1f53f

Contents?: true

Size: 959 Bytes

Versions: 6

Compression:

Stored size: 959 Bytes

Contents

require 'spec_helper'

module MongoModel
  if ActiveModel::VERSION::STRING < '4.0' || Gem.loaded_specs['rails-observers']
    specs_for(Document) do
      describe "observing" do
        define_class(:TestDocument, described_class)
        define_class(:TestObserver, Observer) do
          observe :test_document
        
          attr_accessor :callback

          def after_save(model)
            @callback.call(model) unless @callback.nil?
          end
        end

        subject { TestDocument.new }

        it "has an #instance method to access the observer singleton" do
          TestObserver.instance.should eq(TestObserver.instance)
        end
      
        it "invokes the TestObserver singleton's after_save method after saving" do
          callback = double
          callback.should_receive(:call).with(subject)
        
          TestObserver.instance.callback = callback
          subject.save
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mongomodel-0.5.5 spec/mongomodel/concerns/observing_spec.rb
mongomodel-0.5.4 spec/mongomodel/concerns/observing_spec.rb
mongomodel-0.5.3 spec/mongomodel/concerns/observing_spec.rb
mongomodel-0.5.2 spec/mongomodel/concerns/observing_spec.rb
mongomodel-0.5.1 spec/mongomodel/concerns/observing_spec.rb
mongomodel-0.5.0 spec/mongomodel/concerns/observing_spec.rb