Sha256: 03bee1b9d913725d8598187ce5fff5c05637ccf56a650940c9dc7a6ed8198353

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

describe ActiveUrl do
  before(:each) do
    ActiveUrl::Config.stub!(:secret).and_return("secret")
  end

  context "instance with callbacks" do
    before(:all) do
      class ::Registration < ActiveUrl::Base  
        attribute :email
        after_save :send_registration_email
      end
    end
    
    after(:all) do
      Object.send(:remove_const, "Registration")
    end
    
    before(:each) do
      @registration = Registration.new(:email => "email@example.com")
      @registration.stub!(:valid?).and_return(true)
    end
    
    it "should not run the callback when saved if the instance is invalid" do
      @registration.stub!(:valid?).and_return(false)
      @registration.should_not_receive(:send_registration_email)
      @registration.save
    end
    
    it "should run the callback when saved if the instance is valid" do
      @registration.should_receive(:send_registration_email)
      @registration.save
    end
    
    it "should not run the callback when found from its ID" do
      @registration.stub!(:send_registration_email).and_return(true)
      @registration.save
      @found = Registration.new
      Registration.should_receive(:new).and_return(@found)
      @found.should_not_receive(:send_registration_email)
      Registration.find(@registration.id)
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
mholling-active_url-0.1.4 spec/callbacks_spec.rb
active_url-0.1.4 spec/callbacks_spec.rb