DEV: plugin generator support for spec/test/controller/routes (#6344)

This commit is contained in:
Joffrey JAFFEUX 2018-08-30 16:38:25 +02:00 committed by GitHub
parent 1062d45430
commit 2dfb097dd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 0 deletions

View File

@ -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']

View File

@ -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");
});

View 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

View File

@ -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