Class: FactoryBot::Instrumentation::RootController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- FactoryBot::Instrumentation::RootController
- Includes:
- ActionView::Layouts
- Defined in:
- app/controllers/factory_bot/instrumentation/root_controller.rb
Overview
The Instrumentation engine controller with frontend and API actions.
Instance Method Summary collapse
-
#create ⇒ Object
Create a new entity with the given factory settings to create on demand dependencies for your testing needs.
-
#index ⇒ Object
Show the instrumentation frontend which features the output of configured dynamic seeds scenarios.
Instance Method Details
#create ⇒ Object
Create a new entity with the given factory settings to create on demand dependencies for your testing needs. You can pass in requests without authentication in the following JSON format:
{
"factory": "user",
"traits": ["confirmed"],
"overwrite": {
"first_name": "Bernd",
"last_name": "Müller",
"email": "[email protected]",
"password": "secret"
}
}
The result is the API v1 representation of the created entity.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/factory_bot/instrumentation/root_controller.rb', line 38 def create # Reload the factories to improve the test development experience FactoryBot.reload # Call the factory construction with the user given parameters entity = FactoryBot.create(*factory_params) # Render the resulting entity as an API v1 representation render plain: entity.to_json, content_type: 'application/json' rescue StandardError => err # Log for local factory debugging and re-raise for canary onwards Rails.logger.error("#{err}\n#{err.backtrace.join("\n")}") raise err end |
#index ⇒ Object
Show the instrumentation frontend which features the output of configured dynamic seeds scenarios. The frontend allows humans to generate new seed data on the fly.
15 16 17 18 19 20 |
# File 'app/controllers/factory_bot/instrumentation/root_controller.rb', line 15 def index @instrumentation = instrumentation @scenarios = scenarios @config = FactoryBot::Instrumentation.configuration render :index, layout: true end |