fake_api 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +53 -1
- data/app/controllers/fake_controller.rb +8 -1
- data/lib/fake_api.rb +0 -1
- data/lib/fake_api/base.rb +1 -0
- data/lib/fake_api/handler.rb +2 -2
- data/lib/fake_api/standalone.rb +35 -0
- data/lib/fake_api/version.rb +1 -1
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 47a20671e9ad372adb3792311a170dd58c084b1d27fe224a456dcd9947d7be72
         | 
| 4 | 
            +
              data.tar.gz: c2dc6f1b9eee009056f60fc9c9b52df906c47d68f432b1ff82646644aa258f09
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: bf67634e0aab083999f9efd0f6a08c96c535da598bb2943208a3415751da4228febbf0756a3d196ec833a1f439178ccdcb553b9a5742de781839d46c1a99155b
         | 
| 7 | 
            +
              data.tar.gz: f591bda5399892cd8cb650b1145431c35f586090d5ca0b5103cdb7e07be7c93ac6fd0a7311bc1986fd89bdb36c74f04aab222c086bc9762513da20694689100c
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,5 +1,7 @@ | |
| 1 1 | 
             
            # Fake API
         | 
| 2 2 |  | 
| 3 | 
            +
            [](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( | 
| 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 |  | 
    
        data/lib/fake_api.rb
    CHANGED
    
    
    
        data/lib/fake_api/base.rb
    CHANGED
    
    
    
        data/lib/fake_api/handler.rb
    CHANGED
    
    | @@ -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
         | 
    
        data/lib/fake_api/version.rb
    CHANGED
    
    
    
        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. | 
| 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- | 
| 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
         |