Acts As Trackable plugin

Plugin details

This plugin was created with the intention of track state change of models.

Websitehttp://blogs.onrails.com.ar/plugins Repositorysvn://svn.virtualizar.com.ar/projects/plugins/acts_as_trackable/ Author Pedro Visintin Tags track, monitor LicenseUnknown

Documentation

Install the plugin:
ruby script/plugin install svn://svn.virtualizar.com.ar/projects/plugins/acts_as_trackable/

In your model

class Orden < ActiveRecord::Base
  acts_as_trackable, :track_method => :estado
end


describe "Cuando genero una order. When an order is created" do

  before(:each) do
    @order = Order.new(:customer=>"Capitan Piluso",:state=>"created")
  end
  it "Deberia tener un track asociado cuando se graba. Should have a new track associated" do
    @order.should have(0).tracks
    @order.save
    @order.should have(1).tracks
    @order.tracks[0].should be_an_instance_of(Track)
  end
  it "Deberia guardar la instancia serializada en track. Should save the instance serialized" do
    @order.save
    @order.tracks.last.retrieve_old_instance.should be_an_instance_of(Order)
  end

end

describe "Cuando cambia el estado de una order existente. When an order state is changed" do
  before(:each) do
    @order = Order.create(:customer=>"El Manosanta",:state=>"created")
    @order.state = "shipped"
    @order.save
  end
  it "Deberia crear otro track. Should create another track" do
    @order.should have(2).tracks
    @order.current_track.state.should == "shipped"
    @order.tracks.first.state.should == "created"
  end
end

describe "Con varios tracks. With several tracks" do
  fixtures :orders
  it "deberia poder recuperar la instancia de order en otro momento, should retrieve an old instance of order" do
    @order = orders(:created_1)
    @old_order = orders(:created_1)
    @order.customer = "Dentaduras Sonria Ya"
    @order.state = "shipped"
    @order.save
    @order.state = "returned"
    @order.save
    @order.tracks[0].retrieve_old_instance.should eql(@old_order)
    @order.tracks[1].retrieve_old_instance.should !eql(@old_order)
    @order.tracks[1].retrieve_old_instance.should eql(@order)
  end

end

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | Back in time (1 older version) | Last edited by: scott, 9 months ago