Sha256: 24a4982feba63b8d640c6afda76e61c9e738b47c305e19f9ab51c28872192491

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'active_record'
require 'hashie'
require 'facemock/config'
require 'facemock/fb_graph/application/user'
require 'facemock/fb_graph/application/test_users'

module Facemock
  module FbGraph
    class Application < ActiveRecord::Base
      alias_attribute  :identifier, :id
      has_many :users, :dependent => :destroy

      def initialize(identifier, options={})
        opts = Hashie::Mash.new(options)
        if (identifier == :app && opts.access_token)
          identifier = (0..9).to_a.shuffle[0..15].join
          secret = opts.access_token
        else
          identifer = identifier.to_s
          secret = opts.secret || rand(36**32).to_s(36)
        end
        
        super(secret: secret)
        self.identifier = identifier
        save! unless Application.find_by_id_and_secret(identifier, secret)
      end

      def fetch
        self
      end

      def test_user!(options={})
        user = User.new(options)
        user.application_id = self.identifier
        user.save!
        user
      end

      def test_users(options={})
        TestUsers.new(self.identifier, options)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facemock-0.0.2 lib/facemock/fb_graph/application.rb