mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 07:38:45 -05:00
Scaffold for new Wizard - Rails / Ember / Tests
This commit is contained in:
parent
6070939daa
commit
0471ad393c
23 changed files with 247 additions and 6 deletions
2
app/assets/javascripts/discourse-objects.js
Normal file
2
app/assets/javascripts/discourse-objects.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
window.Discourse = {};
|
||||
Discourse.SiteSettings = {};
|
|
@ -1,8 +1,3 @@
|
|||
window.ENV = { };
|
||||
|
||||
window.Discourse = {};
|
||||
Discourse.SiteSettings = {};
|
||||
|
||||
window.EmberENV = window.EmberENV || {};
|
||||
window.EmberENV['FORCE_JQUERY'] = true;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
//= require logster
|
||||
//= require ./env
|
||||
//= require ./discourse-objects
|
||||
//= require probes.js
|
||||
|
||||
//= require template_include.js
|
||||
|
|
6
app/assets/javascripts/wizard-application.js
Normal file
6
app/assets/javascripts/wizard-application.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
//= require wizard/resolver
|
||||
//= require wizard/router
|
||||
//= require wizard/wizard
|
||||
//= require_tree ./wizard/templates
|
||||
//= require_tree ./wizard/routes
|
||||
//= require_tree ./wizard/controllers
|
2
app/assets/javascripts/wizard-vendor.js
Normal file
2
app/assets/javascripts/wizard-vendor.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
//= require env
|
||||
//= require template_include.js
|
3
app/assets/javascripts/wizard/controllers/step.js.es6
Normal file
3
app/assets/javascripts/wizard/controllers/step.js.es6
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default Ember.Controller.extend({
|
||||
step: null,
|
||||
});
|
26
app/assets/javascripts/wizard/resolver.js.es6
Normal file
26
app/assets/javascripts/wizard/resolver.js.es6
Normal file
|
@ -0,0 +1,26 @@
|
|||
function resolveType(parsedName) {
|
||||
const entries = requirejs.entries;
|
||||
|
||||
const named = `wizard/${parsedName.type}s/${parsedName.fullNameWithoutType}`;
|
||||
if (entries[named]) {
|
||||
const module = require(named, null, null, true /* force sync */);
|
||||
return module.default;
|
||||
}
|
||||
}
|
||||
|
||||
export default Ember.DefaultResolver.extend({
|
||||
|
||||
resolveRoute(parsedName) {
|
||||
return resolveType(parsedName) || this._super(parsedName);
|
||||
},
|
||||
|
||||
resolveController(parsedName) {
|
||||
return resolveType(parsedName) || this._super(parsedName);
|
||||
},
|
||||
|
||||
resolveTemplate(parsedName) {
|
||||
const templates = Ember.TEMPLATES;
|
||||
const withoutType = parsedName.fullNameWithoutType;
|
||||
return templates[`wizard/templates/${withoutType}`] || this._super(parsedName);
|
||||
}
|
||||
});
|
7
app/assets/javascripts/wizard/router.js.es6
Normal file
7
app/assets/javascripts/wizard/router.js.es6
Normal file
|
@ -0,0 +1,7 @@
|
|||
const Router = Ember.Router.extend();
|
||||
|
||||
Router.map(function () {
|
||||
this.route('step', { path: '/step/:step_id' });
|
||||
});
|
||||
|
||||
export default Router;
|
5
app/assets/javascripts/wizard/routes/index.js.es6
Normal file
5
app/assets/javascripts/wizard/routes/index.js.es6
Normal file
|
@ -0,0 +1,5 @@
|
|||
export default Ember.Route.extend({
|
||||
beforeModel() {
|
||||
this.replaceWith('step', 'welcome');
|
||||
}
|
||||
});
|
12
app/assets/javascripts/wizard/routes/step.js.es6
Normal file
12
app/assets/javascripts/wizard/routes/step.js.es6
Normal file
|
@ -0,0 +1,12 @@
|
|||
export default Ember.Route.extend({
|
||||
model(params) {
|
||||
return {
|
||||
id: params.step_id,
|
||||
title: "You're a wizard harry!"
|
||||
};
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
controller.set('step', model);
|
||||
}
|
||||
});
|
7
app/assets/javascripts/wizard/templates/application.hbs
Normal file
7
app/assets/javascripts/wizard/templates/application.hbs
Normal file
|
@ -0,0 +1,7 @@
|
|||
<div class='wizard-column'>
|
||||
<div class='wizard-column-contents'>
|
||||
Discourse!
|
||||
|
||||
{{outlet}}
|
||||
</div>
|
||||
</div>
|
3
app/assets/javascripts/wizard/templates/step.hbs
Normal file
3
app/assets/javascripts/wizard/templates/step.hbs
Normal file
|
@ -0,0 +1,3 @@
|
|||
<div class='wizard-step'>
|
||||
{{step.title}}
|
||||
</div>
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
module("Acceptance: wizard");
|
||||
|
||||
test("Wizard loads", assert => {
|
||||
visit("/");
|
||||
andThen(() => {
|
||||
assert.ok(exists('.wizard-column-contents'));
|
||||
assert.equal(currentPath(), 'steps');
|
||||
});
|
||||
});
|
40
app/assets/javascripts/wizard/test/test_helper.js
Normal file
40
app/assets/javascripts/wizard/test/test_helper.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*global document, sinon, QUnit, Logster */
|
||||
|
||||
//= require env
|
||||
//= require jquery.debug
|
||||
//= require loader
|
||||
//= require jquery.debug
|
||||
//= require handlebars
|
||||
//= require ember.debug
|
||||
//= require ember-template-compiler
|
||||
//= require ember-qunit
|
||||
//= require wizard-application
|
||||
//= require helpers/assertions
|
||||
//= require_tree ./acceptance
|
||||
|
||||
// Trick JSHint into allow document.write
|
||||
var d = document;
|
||||
d.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>');
|
||||
d.write('<style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>');
|
||||
|
||||
if (window.Logster) {
|
||||
Logster.enabled = false;
|
||||
} else {
|
||||
window.Logster = { enabled: false };
|
||||
}
|
||||
|
||||
var wizard = require('wizard/wizard').default.create({
|
||||
rootElement: '#ember-testing'
|
||||
});
|
||||
wizard.setupForTesting();
|
||||
wizard.injectTestHelpers();
|
||||
|
||||
QUnit.testDone(function() {
|
||||
wizard.reset();
|
||||
});
|
||||
|
||||
Object.keys(requirejs.entries).forEach(function(entry) {
|
||||
if ((/\-test/).test(entry)) {
|
||||
require(entry, null, null, true);
|
||||
}
|
||||
});
|
8
app/assets/javascripts/wizard/wizard.js.es6
Normal file
8
app/assets/javascripts/wizard/wizard.js.es6
Normal file
|
@ -0,0 +1,8 @@
|
|||
import Resolver from 'wizard/resolver';
|
||||
import Router from 'wizard/router';
|
||||
|
||||
export default Ember.Application.extend({
|
||||
rootElement: '#wizard-main',
|
||||
Resolver,
|
||||
Router
|
||||
});
|
31
app/assets/stylesheets/wizard.scss
Normal file
31
app/assets/stylesheets/wizard.scss
Normal file
|
@ -0,0 +1,31 @@
|
|||
@import "vendor/normalize";
|
||||
@import "vendor/font_awesome/font-awesome";
|
||||
|
||||
body {
|
||||
background-color: rgb(231,238,247);
|
||||
background-image: url('/images/wizard/bubbles.png');
|
||||
background-repeat: repeat;
|
||||
background-position: left top;
|
||||
}
|
||||
|
||||
.wizard-column {
|
||||
background-color: white;
|
||||
border-radius: 2px;
|
||||
box-shadow: 0 5px 10px rgba(0,0,0,0.2);
|
||||
box-sizing: border-box;
|
||||
margin: 0.75rem auto;
|
||||
padding: 0;
|
||||
max-width: 700px;
|
||||
min-width: 280px;
|
||||
width: 100%;
|
||||
border: 1px solid #ccc;
|
||||
|
||||
.wizard-column-contents {
|
||||
padding: 1em;
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
app/controllers/wizard/wizard_controller.rb
Normal file
16
app/controllers/wizard/wizard_controller.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
class Wizard::WizardController < ApplicationController
|
||||
|
||||
before_filter :ensure_logged_in
|
||||
before_filter :ensure_staff
|
||||
|
||||
skip_before_filter :check_xhr, :preload_json
|
||||
|
||||
layout false
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def qunit
|
||||
end
|
||||
|
||||
end
|
21
app/views/wizard/wizard/index.html.erb
Normal file
21
app/views/wizard/wizard/index.html.erb
Normal file
|
@ -0,0 +1,21 @@
|
|||
<html>
|
||||
<head>
|
||||
<%= stylesheet_link_tag 'wizard' %>
|
||||
<%= javascript_include_tag 'wizard-vendor' %>
|
||||
<%= javascript_include_tag 'ember_jquery' %>
|
||||
<%= javascript_include_tag 'wizard-application' %>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id='wizard-main'>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
require('wizard/wizard').default.create();
|
||||
})();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
15
app/views/wizard/wizard/qunit.html.erb
Normal file
15
app/views/wizard/wizard/qunit.html.erb
Normal file
|
@ -0,0 +1,15 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>QUnit Test Runner</title>
|
||||
<%= stylesheet_link_tag "qunit" %>
|
||||
<%= stylesheet_link_tag "test_helper" %>
|
||||
<%= javascript_include_tag "qunit" %>
|
||||
<%= javascript_include_tag "wizard/test/test_helper" %>
|
||||
<%= csrf_meta_tags %>
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -72,7 +72,8 @@ module Discourse
|
|||
config.assets.precompile += ['vendor.js', 'common.css', 'desktop.css', 'mobile.css',
|
||||
'admin.js', 'admin.css', 'shiny/shiny.css', 'preload-store.js.es6',
|
||||
'browser-update.js', 'embed.css', 'break_string.js', 'ember_jquery.js',
|
||||
'pretty-text-bundle.js']
|
||||
'pretty-text-bundle.js', 'wizard.css', 'wizard-application.js',
|
||||
'wizard-vendor.js']
|
||||
|
||||
# Precompile all available locales
|
||||
Dir.glob("#{config.root}/app/assets/javascripts/locales/*.js.erb").each do |file|
|
||||
|
|
|
@ -53,6 +53,11 @@ Discourse::Application.routes.draw do
|
|||
resources :forums
|
||||
get "srv/status" => "forums#status"
|
||||
|
||||
namespace :wizard, constraints: StaffConstraint.new do
|
||||
get "" => "wizard#index"
|
||||
get "qunit" => "wizard#qunit"
|
||||
end
|
||||
|
||||
namespace :admin, constraints: StaffConstraint.new do
|
||||
get "" => "admin#index"
|
||||
|
||||
|
|
BIN
public/images/wizard/bubbles.png
Normal file
BIN
public/images/wizard/bubbles.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
25
spec/controllers/wizard/wizard_controller_spec.rb
Normal file
25
spec/controllers/wizard/wizard_controller_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Wizard::WizardController do
|
||||
|
||||
context 'index' do
|
||||
render_views
|
||||
|
||||
it 'needs you to be logged in' do
|
||||
expect { xhr :get, :index }.to raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
|
||||
it "raises an error if you aren't an admin" do
|
||||
log_in
|
||||
xhr :get, :index
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "renders the wizard if you are an admin" do
|
||||
log_in(:admin)
|
||||
xhr :get, :index
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue