Sha256: 0cc2a5134112e0ea6a550633b386c7db7dff6b801a2c8255be94e502655c5dc1

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

#Additional security to be sure to never, ever run in production ... ever
if FacebookRails.app_env != 'production'

  #require 'koala_rails.rb'

  class FacebookApiMock

    def initialize(open_graph_data)
      @open_graph_data = open_graph_data
    end

    def get_object(object_id, options = {})
      @open_graph_data[:objects][object_id]
    end

    def get_connections(object_id, connection_name, options = {})
      @open_graph_data[:connections][object_id][connection_name]
    end

  end

  FacebookRailsController.module_eval do

    def use_as_f8user(name)
      if name.nil?
        @test_user_data = nil
      else
        @test_user_data = YAML.load_file(FacebookRails.app_root.join("spec/f8_user_mocks/#{name}.yml"))
      end
    end

    def facebook_api
      @facebook_api ||= FacebookApiMock.new(@test_user_data)
    end

    def authenticated_by_facebook?
      !@test_user_data.nil?
    end

    #Will only try to collect facebook credentials but it will let the user in even there aren't any
    def try_facebook_authentication
      return true
    end

    #Will force user to authorize the application to access the current url
    def ensure_authenticated_to_facebook
      if @test_user_data.nil?
        raise "Expected authorized facebook user but none was set, set one in spec using controller.use_as_f8user(name)!"
      else
        return true
      end
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
facebook_rails-0.2.1 lib/facebook_rails/test.rb
facebook_rails-0.2.0 lib/facebook_rails/test.rb
facebook_rails-0.1.2 lib/facebook_rails/test.rb
facebook_rails-0.1.1 lib/facebook_rails/test.rb