Project

fakesite

0.0
No commit activity in last 3 years
No release in over 3 years
An rails plugin that provides a fake framework to stub 3-party redirect page such as payment or oauth login.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0

Runtime

>= 4.0.0
 Project Readme

Fakesite

Build Status Coverage Status

A rails plugin that provides a fake framework to stub 3-party redirect page such as payment or oauth login.
image

Installation

Add this line to your application's Gemfile:

gem 'fakesite', group: :development

And then execute:

bundle

Route

Add fakesite route in your config/route.rb

mount Fakesite::Engine => "/fakesite" if Rails.env.development?

Usage

Create Your Fakesite

Inherit Fakesite::Base class and implement methods:

class TestFakesite < Fakesite::Base
  # specify what the parameters will return to your site
  def parameters
    {:test_key1 => :value1, :test_key2 => :value2}
  end

  # overwrite where to return, default using return_url in external_uri query string if exsit
  def return_url
    external_params["custom_url"]
  end

  # overwrite the parameters that will pass to return_url. default is params, you can do something here
  # def return_parameters
  #   params
  # end

  # implement the rule to stub external page by redirect url
  def self.match(external_uri)
    external_uri.host == "test.com"
  end

  # after register event
  # def self.after_register
  # end
end

Class Members

You can use following properties and methods in instance of Fakesite::Base class:

options

The options that you registered.

external_uri

The original uri of external third-party.

external_params

The parameters of external_uri in query string.

params

The post parameters in the fakesite page.

user

current_user instance from devise if exists.

Register Fakesite

You can register your fakesites when rails initialize.

if Rails.env.development?
  Fakesite.register :test, TestFakesite
  # You can also pass some options if needs, and using by options in your class
  # Fakesite.register :test, TestFakesite, {:your => :option}
end

You can put the registration in config/initializers/fakesite.rb

Plugins

fakesite-alipay
fakesite-wechat

License

The gem is available as open source under the terms of the MIT License.

Contact

The project's website is located at https://github.com/emn178/fakesite
Author: emn178@gmail.com