Skip to content

Instantly share code, notes, and snippets.

@raphaelcm
Created October 3, 2012 21:22

Revisions

  1. raphaelcm created this gist Oct 3, 2012.
    40 changes: 40 additions & 0 deletions persistence_test.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    class PersistenceTest
    include Mongoid::Document
    include Mongoid::Timestamps

    BRAINTREE_SYNC_STATUSES = %w(new synced changed)

    #
    # Top-level Fields
    #
    field :terms_accepted_at, :type => DateTime
    field :first_billing_date, :type => Date
    field :next_billing_date, :type => Date
    field :trial_duration, :type => Integer, :default => 0
    field :charge_attempts, :type => Integer, :default => 0
    field :migrated_pmt, :type => String
    field :pre_coins_hub, :type => Boolean, :default => false
    field :braintree_billing, :type => Boolean, :default => true
    field :sync_status, :type => String, :default => "new"
    field :reminder_sent, :type => Boolean, :default => false
    field :override_amount, :type => Integer
    field :terms_accepted_at, :type => DateTime
    field :activated_at, :type => DateTime

    #
    # Validations
    #
    validates_inclusion_of :sync_status, :in => BRAINTREE_SYNC_STATUSES

    def created_in_braintree?
    self.sync_status != "new"
    end

    def synced?
    self.sync_status == "synced"
    end

    def changed?
    self.sync_status == "changed"
    end
    end