Guest User

Untitled

a guest
Apr 26th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. ## Problem
  2. @draft_entry.state.should eql('draft') is failing - expected "draft", got "passive" (using .eql?)
  3. due to the has_permalink Proc - any idea?
  4.  
  5. ## entry
  6.  
  7. # == Schema Information
  8. # Schema version: 20080509164356
  9. #
  10. # Table name: entries
  11. #
  12. # id :integer(11) not null, primary key
  13. # permalink :string(255)
  14. # title :string(255)
  15. # excerpt :text
  16. # body :text
  17. # state :string(255) default("passive")
  18. # published_at :datetime
  19. # user_id :integer(11)
  20. # created_at :datetime
  21. # updated_at :datetime
  22. # type :string(255)
  23. #
  24.  
  25. class Entry < ActiveRecord::Base
  26. belongs_to :user
  27.  
  28. validates_presence_of :title, :body, :permalink
  29. validates_uniqueness_of :permalink
  30.  
  31. has_permalink :title, :if => Proc.new { |entry| entry.recently_published? }
  32.  
  33. # named_scope :drafts, :conditions => { :state => "draft" }
  34. # named_scope :private, :conditions => { :state => "private" }
  35. # named_scope :published, :conditions => { :state => "published" }
  36. #
  37. acts_as_state_machine :initial => :draft
  38. state :draft
  39. state :private
  40. state :published, :enter => :do_publish
  41.  
  42. event :publish do
  43. transitions :from => :draft, :to => :published
  44. transitions :from => :private, :to => :published
  45. end
  46.  
  47. def recently_published?
  48. @recently_published == true
  49. end
  50.  
  51. def do_publish
  52. @recently_published = true
  53. # self.published_at = Time.now
  54. end
  55. end
Add Comment
Please, Sign In to add comment