Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Problem
- @draft_entry.state.should eql('draft') is failing - expected "draft", got "passive" (using .eql?)
- due to the has_permalink Proc - any idea?
- ## entry
- # == Schema Information
- # Schema version: 20080509164356
- #
- # Table name: entries
- #
- # id :integer(11) not null, primary key
- # permalink :string(255)
- # title :string(255)
- # excerpt :text
- # body :text
- # state :string(255) default("passive")
- # published_at :datetime
- # user_id :integer(11)
- # created_at :datetime
- # updated_at :datetime
- # type :string(255)
- #
- class Entry < ActiveRecord::Base
- belongs_to :user
- validates_presence_of :title, :body, :permalink
- validates_uniqueness_of :permalink
- has_permalink :title, :if => Proc.new { |entry| entry.recently_published? }
- # named_scope :drafts, :conditions => { :state => "draft" }
- # named_scope :private, :conditions => { :state => "private" }
- # named_scope :published, :conditions => { :state => "published" }
- #
- acts_as_state_machine :initial => :draft
- state :draft
- state :private
- state :published, :enter => :do_publish
- event :publish do
- transitions :from => :draft, :to => :published
- transitions :from => :private, :to => :published
- end
- def recently_published?
- @recently_published == true
- end
- def do_publish
- @recently_published = true
- # self.published_at = Time.now
- end
- end
Add Comment
Please, Sign In to add comment