Class: Rhino::Blueprint::Generators::TestGenerator
- Inherits:
-
Object
- Object
- Rhino::Blueprint::Generators::TestGenerator
- Defined in:
- lib/rhino/blueprint/generators/test_generator.rb
Overview
Generates RSpec request spec files with per-role contexts and individual action tests.
Constant Summary collapse
- ALL_ACTIONS =
%w[index show store update destroy trashed restore forceDelete].freeze
- ACTION_LABELS =
{ "index" => "list", "show" => "show", "store" => "create", "update" => "update", "destroy" => "delete", "trashed" => "view trashed", "restore" => "restore", "forceDelete" => "force delete" }.freeze
Instance Method Summary collapse
- #actions_to_permissions(actions, slug) ⇒ Object
- #generate(blueprint, is_multi_tenant, org_identifier = "slug") ⇒ Object
Instance Method Details
#actions_to_permissions(actions, slug) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/rhino/blueprint/generators/test_generator.rb', line 40 def (actions, slug) if (ALL_ACTIONS - actions).empty? "['#{slug}.*']" else items = actions.map { |a| "'#{slug}.#{a}'" } "[#{items.join(', ')}]" end end |
#generate(blueprint, is_multi_tenant, org_identifier = "slug") ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rhino/blueprint/generators/test_generator.rb', line 21 def generate(blueprint, is_multi_tenant, org_identifier = "slug") model = blueprint[:model] slug = blueprint[:slug] = blueprint[:permissions] columns = blueprint[:columns] # URL segment attribute for member endpoints: the configured route # key, or the primary key (id) when none is set. route_key = (blueprint[:options] || {})[:route_key] || "id" factory_name = model_to_factory(model) role_contexts = build_role_contexts(slug, factory_name, , columns, is_multi_tenant, org_identifier, route_key) if is_multi_tenant wrap_multi_tenant(model, slug, role_contexts, org_identifier) else wrap_non_tenant(model, slug, role_contexts) end end |