mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
DEV: plugin generator support for spec/test/controller/routes (#6344)
This commit is contained in:
parent
1062d45430
commit
2dfb097dd9
|
@ -7,11 +7,26 @@ class PluginGenerator < Rails::Generators::NamedBase
|
|||
|
||||
source_root File.expand_path('templates', __dir__)
|
||||
|
||||
class_option :controller, type: :boolean, desc: "Generate controller", default: true
|
||||
class_option :spec, type: :boolean, desc: "Generate spec", default: true
|
||||
class_option :acceptance, type: :boolean, desc: "Generate acceptance test", default: true
|
||||
class_option :stylesheet, type: :boolean, desc: "Generate Stylesheet", default: true
|
||||
class_option :javascript, type: :boolean, desc: "Generate Javascript initializer", default: true
|
||||
class_option :scheduled_job, type: :boolean, desc: "Generate scheduled job", default: false
|
||||
class_option :help, type: :boolean, desc: "Adds help comments in generated files", default: true
|
||||
|
||||
def create_acceptance_file
|
||||
return unless @options['acceptance']
|
||||
|
||||
template 'acceptance-test.js.es6.erb', File.join('plugins', dasherized_name, "test/javascripts/acceptance", "#{dasherized_name}-test.js.es6")
|
||||
end
|
||||
|
||||
def create_spec_file
|
||||
return if !@options['spec'] || !@options['controller']
|
||||
|
||||
template 'controller_spec.rb.erb', File.join('plugins', dasherized_name, "spec/requests/actions_controller_spec.rb")
|
||||
end
|
||||
|
||||
def create_scheduled_job_file
|
||||
return unless @options['scheduled_job']
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
|
||||
acceptance("<%= name %>", { loggedIn: true });
|
||||
|
||||
test("<%= name %> works", async assert => {
|
||||
await visit("/admin/plugins/<%= dasherized_name %>");
|
||||
|
||||
assert.ok(false, "it shows the <%= name %> button");
|
||||
});
|
13
lib/generators/plugin/templates/controller_spec.rb.erb
Normal file
13
lib/generators/plugin/templates/controller_spec.rb.erb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe <%= name %>::ActionsController do
|
||||
before do
|
||||
SiteSetting.queue_jobs = false
|
||||
end
|
||||
|
||||
it 'can list' do
|
||||
sign_in(Fabricate(:user))
|
||||
get "/<%= dasherized_name %>/list.json"
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
end
|
|
@ -27,4 +27,25 @@ after_initialize do
|
|||
<% if @options["scheduled_job"] %>
|
||||
require File.expand_path("../jobs/scheduled/check_<%= underscored_name %>.rb", __FILE__)
|
||||
<% end %>
|
||||
|
||||
<% if @options["controller"] %>
|
||||
require_dependency "application_controller"
|
||||
class <%= name %>::ActionsController < ::ApplicationController
|
||||
requires_plugin PLUGIN_NAME
|
||||
|
||||
before_action :ensure_logged_in
|
||||
|
||||
def list
|
||||
render json: success_json
|
||||
end
|
||||
end
|
||||
|
||||
<%= name %>::Engine.routes.draw do
|
||||
get "/list" => "actions#list"
|
||||
end
|
||||
|
||||
Discourse::Application.routes.append do
|
||||
mount ::<%= name %>::Engine, at: "/<%= dasherized_name %>"
|
||||
end
|
||||
<% end %>
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user