Sha256: a40a975a3e516679339d77e3c2944082b70d75d5cfe4278fbd589fd9e738edd6

Contents?: true

Size: 769 Bytes

Versions: 2

Compression:

Stored size: 769 Bytes

Contents

class Double < ActiveRecord::Base
  attr_accessible :fullpath, :content, :description, :method

  METHODS = %w{GET POST PUT DELETE}

  validates_presence_of :fullpath, :content
  validates_inclusion_of :method, :in => METHODS

  before_save :toggle_active
  before_validation :set_method
  after_destroy :set_active

  private
    def toggle_active
      if active && Double.where(:fullpath => fullpath, :active => true, :id.ne => id).exists?
        Double.where(:fullpath => fullpath, :id.ne => id).update_all :active => false
      end
    end

    def set_method
      self.method = 'GET' unless method.present?
    end

    def set_active
      if active && f = Double.where(:fullpath => fullpath).last
        f.active = true
        f.save
      end
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rest-assured-0.1.1 lib/rest-assured/models/double.rb
rest-assured-0.1.0 lib/rest-assured/models/double.rb