fake_api 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 291b0a2acbe638fd0298f165f52361d40ed135aaae8ac5788879071810796573
4
- data.tar.gz: ffd968738a8652262fbeeabc9ffda18c99139989a55ac22f4c7cdb0bdd7db564
3
+ metadata.gz: 47a20671e9ad372adb3792311a170dd58c084b1d27fe224a456dcd9947d7be72
4
+ data.tar.gz: c2dc6f1b9eee009056f60fc9c9b52df906c47d68f432b1ff82646644aa258f09
5
5
  SHA512:
6
- metadata.gz: 32d03d9f654d063f9726cc944ebc4c380e0ddfca498a49a27a295f547c829cb6adfecd6ef92618021f53753dc3e85ba8b947bb31f6eb46a5ad27a52412e622bd
7
- data.tar.gz: c2cac52ff859c0566d60d80ab448d528da024c06801f334dbb152bd225b78a962e731e45e7bb32ac6a4dc01ee19dd531ff5d9bef46008cc4ae9757bcd7573589
6
+ metadata.gz: bf67634e0aab083999f9efd0f6a08c96c535da598bb2943208a3415751da4228febbf0756a3d196ec833a1f439178ccdcb553b9a5742de781839d46c1a99155b
7
+ data.tar.gz: f591bda5399892cd8cb650b1145431c35f586090d5ca0b5103cdb7e07be7c93ac6fd0a7311bc1986fd89bdb36c74f04aab222c086bc9762513da20694689100c
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Fake API
2
2
 
3
+ [![Build Status](https://travis-ci.org/igorkasyanchuk/fake_api.svg?branch=master)](https://travis-ci.org/igorkasyanchuk/fake_api)
4
+
3
5
  The **fastest** way to prototype API with most real dummy data, and provide them to other team members.
4
6
 
5
7
  Instead of creating many new controllers and actions, and sending random data like `"First name #{rand(100)}"` you'll get real data for developing/testing.
@@ -17,6 +19,7 @@ Features:
17
19
  * manage cookies, session, headers with fake response
18
20
  * executes your factories in real-time, so you always get fresh and random data
19
21
  * has generator
22
+ * has standalone mode (see documentation for more details)
20
23
 
21
24
  ## Installation & Usage
22
25
 
@@ -106,12 +109,61 @@ end
106
109
  - `with_session` to list changes in session
107
110
  - `with_headers` to list returned headers
108
111
 
112
+ ## Standalone mode
113
+
114
+ Developing standalone version of the gem:
115
+
116
+ ```bash
117
+ cd test
118
+ rackup -p 3000 -o 0.0.0.0
119
+ ```
120
+
121
+ Edit `config.ru` to change example code.
122
+
123
+ ## Standalone mode
124
+
125
+ This is an example how you can start just fake_api server and define your factories and responses just inside one single file.
126
+
127
+ Please check example below and instructions how to start fakea_api in standalone mode.
128
+
129
+ Since this is a rack app it could be just deployed to the server.
130
+
131
+ ```ruby
132
+ # start it:
133
+ # rackup -p 3000 -o 0.0.0.0
134
+
135
+ # create file
136
+ # config.ru
137
+
138
+ require 'fake_api/standalone'
139
+
140
+ factory(:user) do
141
+ {
142
+ id: rand(100),
143
+ first_name: Faker::Name.first_name,
144
+ last_name: Faker::Name.last_name,
145
+ age: rand(100)
146
+ }
147
+ end
148
+
149
+ get('/users').and_return do
150
+ create_list(:user, 5)
151
+ end
152
+
153
+ get(%r{/users/\d+$}).and_return do
154
+ object(:user)
155
+ end
156
+
157
+ run FakeApi::Standalone.app on: '/api'
158
+ ```
159
+
109
160
  ## TODO
110
161
 
111
- - CI (travis, github actions, etc)
112
162
  - render ERB?
113
163
  - exclude from code converage generator and dummy app
114
164
  - make code coverage 100%
165
+ - access controller in the gem?
166
+ - reload code in standalone app after code changes in dev mode
115
167
 
116
168
  ## Contributing
117
169
 
@@ -1,7 +1,14 @@
1
1
  class FakeController < ApplicationController
2
2
 
3
3
  def data
4
- result = FakeApi::Handler.handle(request.method, path: params[:path], params: params, headers: request.headers)
4
+ result = FakeApi::Handler.handle(
5
+ request.method,
6
+ path: params[:path],
7
+ params: params,
8
+ headers: request.headers,
9
+ cookies: cookies,
10
+ session: session
11
+ )
5
12
 
6
13
  response.status = result.status
7
14
 
@@ -1,6 +1,5 @@
1
1
  require "fake_api/engine"
2
2
  require "faker"
3
- require "pry"
4
3
  require "ostruct"
5
4
 
6
5
  require_relative './fake_api/data.rb'
@@ -8,4 +8,5 @@ module FakeApi
8
8
  end
9
9
  Routing = Base
10
10
  Factoring = Base
11
+ Inline = Base
11
12
  end
@@ -1,7 +1,7 @@
1
1
  module FakeApi
2
2
  class Handler
3
3
 
4
- def Handler.handle(method, path:, params: {}, headers: {})
4
+ def Handler.handle(method, path:, params: {}, headers: {}, session: {}, cookies: {})
5
5
  if route = Handler.resolve(method, path)
6
6
  result(
7
7
  data: route.response.call,
@@ -18,7 +18,7 @@ module FakeApi
18
18
  \n#{available.presence || 'NONE'}
19
19
  }.strip,
20
20
  status: 500,
21
- )
21
+ )
22
22
  end
23
23
  end
24
24
 
@@ -0,0 +1,35 @@
1
+ require "rails"
2
+ require "fake_api"
3
+ require "action_controller/railtie"
4
+ require "active_support/railtie"
5
+
6
+ class FakeApiApp < Rails::Application
7
+ config.session_store :cookie_store, key: '_fake_session'
8
+ config.secret_key_base = SecureRandom.hex(30)
9
+ Rails.logger = Logger.new($stdout)
10
+ config.hosts.clear
11
+ end
12
+
13
+ class ApplicationController < ActionController::Base; end
14
+
15
+ module FakeApi
16
+ class Standalone
17
+ def Standalone.app(on: '/api')
18
+ FakeApiApp.routes.append do
19
+ mount FakeApi::Engine => on
20
+ end
21
+
22
+ FakeApiApp.initialize!
23
+
24
+ FakeApiApp
25
+ end
26
+ end
27
+ end
28
+
29
+ def method_missing(m, *args, &block)
30
+ if FakeApi::FakeApiData.instance.respond_to?(m)
31
+ FakeApi::FakeApiData.instance.send(m, *args, &block)
32
+ else
33
+ super
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module FakeApi
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-13 00:00:00.000000000 Z
11
+ date: 2020-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -102,6 +102,7 @@ files:
102
102
  - lib/fake_api/factory.rb
103
103
  - lib/fake_api/handler.rb
104
104
  - lib/fake_api/route.rb
105
+ - lib/fake_api/standalone.rb
105
106
  - lib/fake_api/version.rb
106
107
  - lib/generators/fake_api_generator.rb
107
108
  - lib/generators/templates/factory.rb