jax 1.0.1 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +3 -0
- data/.travis.yml +32 -0
- data/CHANGELOG +126 -0
- data/README.md +1 -1
- data/Rakefile +125 -19
- data/bin/jax +1 -1
- data/builtin/{shaders → app/shaders}/basic/common.ejs +0 -0
- data/builtin/{shaders → app/shaders}/basic/fragment.ejs +0 -0
- data/builtin/{shaders → app/shaders}/basic/vertex.ejs +0 -0
- data/builtin/{shaders → app/shaders}/depthmap/common.ejs +0 -0
- data/builtin/{shaders → app/shaders}/depthmap/fragment.ejs +0 -0
- data/builtin/{shaders → app/shaders}/depthmap/material.js +0 -0
- data/builtin/{shaders → app/shaders}/depthmap/vertex.ejs +0 -0
- data/builtin/{shaders → app/shaders}/fog/common.ejs +0 -0
- data/builtin/{shaders → app/shaders}/fog/fragment.ejs +0 -0
- data/builtin/{shaders → app/shaders}/fog/manifest.yml +0 -0
- data/builtin/{shaders → app/shaders}/fog/material.js +0 -0
- data/builtin/{shaders → app/shaders}/fog/vertex.ejs +0 -0
- data/builtin/{shaders → app/shaders}/functions/depth_map.ejs +0 -0
- data/builtin/{shaders → app/shaders}/functions/lights.ejs +0 -0
- data/builtin/{shaders → app/shaders}/functions/noise.ejs +0 -0
- data/builtin/{shaders → app/shaders}/lighting/common.ejs +0 -0
- data/builtin/{shaders → app/shaders}/lighting/fragment.ejs +0 -0
- data/builtin/{shaders → app/shaders}/lighting/manifest.yml +0 -0
- data/builtin/{shaders → app/shaders}/lighting/material.js +0 -0
- data/builtin/{shaders → app/shaders}/lighting/vertex.ejs +0 -0
- data/builtin/{shaders → app/shaders}/normal_map/common.ejs +0 -0
- data/builtin/{shaders → app/shaders}/normal_map/fragment.ejs +0 -0
- data/builtin/{shaders → app/shaders}/normal_map/manifest.yml +0 -0
- data/builtin/{shaders → app/shaders}/normal_map/material.js +0 -0
- data/builtin/{shaders → app/shaders}/normal_map/vertex.ejs +0 -0
- data/builtin/{shaders → app/shaders}/paraboloid/common.ejs +0 -0
- data/builtin/{shaders → app/shaders}/paraboloid/fragment.ejs +0 -0
- data/builtin/{shaders → app/shaders}/paraboloid/manifest.yml +0 -0
- data/builtin/{shaders → app/shaders}/paraboloid/material.js +0 -0
- data/builtin/{shaders → app/shaders}/paraboloid/vertex.ejs +0 -0
- data/builtin/{shaders → app/shaders}/picking/common.ejs +0 -0
- data/builtin/{shaders → app/shaders}/picking/fragment.ejs +0 -0
- data/builtin/{shaders → app/shaders}/picking/material.js +0 -0
- data/builtin/{shaders → app/shaders}/picking/vertex.ejs +0 -0
- data/builtin/{shaders → app/shaders}/shadow_map/common.ejs +0 -0
- data/builtin/{shaders → app/shaders}/shadow_map/fragment.ejs +0 -0
- data/builtin/{shaders → app/shaders}/shadow_map/manifest.yml +0 -0
- data/builtin/{shaders → app/shaders}/shadow_map/material.js +0 -0
- data/builtin/{shaders → app/shaders}/shadow_map/vertex.ejs +0 -0
- data/builtin/{shaders → app/shaders}/texture/common.ejs +0 -0
- data/builtin/{shaders → app/shaders}/texture/fragment.ejs +0 -0
- data/builtin/{shaders → app/shaders}/texture/manifest.yml +0 -0
- data/builtin/{shaders → app/shaders}/texture/material.js +0 -0
- data/builtin/{shaders → app/shaders}/texture/vertex.ejs +0 -0
- data/jax.gems +1 -1
- data/jax.gemspec +9 -7
- data/lib/jax.rb +23 -9
- data/lib/jax/application.rb +118 -60
- data/lib/jax/application/builtin.rb +12 -0
- data/lib/jax/application/builtin/configurable.rb +5 -0
- data/lib/jax/application/builtin/configuration.rb +5 -0
- data/lib/jax/application/configurable.rb +19 -0
- data/lib/jax/application/configuration.rb +46 -13
- data/lib/jax/application/railties.rb +26 -0
- data/lib/jax/core_ext/kernel.rb +7 -0
- data/lib/jax/engine.rb +64 -0
- data/lib/jax/engine/configurable.rb +19 -0
- data/lib/jax/engine/configuration.rb +49 -0
- data/lib/jax/generators/app.rb +3 -2
- data/lib/jax/generators/app/app_generator.rb +9 -2
- data/lib/jax/generators/app/templates/config/environment.rb.tt +5 -0
- data/lib/jax/generators/app/templates/public/index.html.tt +26 -0
- data/lib/jax/generators/app/templates/public/javascripts/jax.js +8726 -1
- data/lib/jax/generators/app/templates/public/stylesheets/%file_name%.css.tt +11 -0
- data/lib/jax/generators/app/templates/public/webgl_not_supported.html +1 -1
- data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine.yml +1 -0
- data/lib/jax/generators/app/templates/spec/javascripts/support/spec_helpers/jax_spec_environment_helper.js +13 -5
- data/lib/jax/generators/app/templates/spec/javascripts/support/spec_helpers/jax_spec_helper.js +6 -10
- data/lib/jax/generators/commands.rb +168 -42
- data/lib/jax/generators/controller/controller_generator.rb +9 -2
- data/lib/jax/generators/interactions.rb +56 -0
- data/lib/jax/generators/light_source/light_source_generator.rb +1 -2
- data/lib/jax/generators/material/material_generator.rb +1 -2
- data/lib/jax/generators/model/model_generator.rb +1 -3
- data/lib/jax/generators/packager/package_generator.rb +32 -0
- data/lib/jax/generators/plugin/USAGE +4 -0
- data/lib/jax/generators/plugin/all.rb +113 -0
- data/lib/jax/generators/plugin/credentials.rb +108 -0
- data/lib/jax/generators/plugin/plugin_generator.rb +72 -0
- data/lib/jax/generators/plugin/plugin_manager.rb +254 -0
- data/lib/jax/generators/plugin/templates/new_plugin/app/controllers/.empty_directory +0 -0
- data/lib/jax/generators/plugin/templates/new_plugin/app/helpers/.empty_directory +0 -0
- data/lib/jax/generators/plugin/templates/new_plugin/app/models/.empty_directory +0 -0
- data/lib/jax/generators/plugin/templates/new_plugin/app/resources/.empty_directory +0 -0
- data/lib/jax/generators/plugin/templates/new_plugin/app/views/.empty_directory +0 -0
- data/lib/jax/generators/plugin/templates/new_plugin/config/routes.rb +3 -0
- data/lib/jax/generators/plugin/templates/new_plugin/init.rb +1 -0
- data/lib/jax/generators/plugin/templates/new_plugin/install.rb +2 -0
- data/lib/jax/generators/plugin/templates/new_plugin/public/.empty_directory +0 -0
- data/lib/jax/generators/plugin/templates/new_plugin/spec/.empty_directory +0 -0
- data/lib/jax/generators/plugin/templates/new_plugin/uninstall.rb +2 -0
- data/lib/jax/generators/script_jax_loader.rb +17 -0
- data/lib/jax/generators/shader/shader_generator.rb +2 -3
- data/lib/jax/monkeypatch/jasmine/config.rb +25 -1
- data/lib/jax/monkeypatch/jasmine/server.rb +1 -1
- data/lib/jax/packager.rb +12 -11
- data/lib/jax/packager/sprockets_template.rb +15 -6
- data/lib/jax/plugin.rb +49 -0
- data/lib/jax/plugin/manifest.rb +71 -0
- data/lib/jax/resource_compiler.rb +24 -14
- data/lib/jax/routes.rb +1 -0
- data/lib/jax/shader.rb +16 -1
- data/lib/jax/tasks/rake.rb +1 -1
- data/lib/jax/version.rb +3 -3
- data/spec/benchmark.htm +93 -0
- data/spec/fixtures/web/plugins/404.http +39 -0
- data/spec/fixtures/web/plugins/all.xml +106 -0
- data/spec/fixtures/web/plugins/author/create_account.xml.http +20 -0
- data/spec/fixtures/web/plugins/author/create_new_plugin.xml.http +27 -0
- data/spec/fixtures/web/plugins/author/login_existing_account.xml.http +19 -0
- data/spec/fixtures/web/plugins/author/login_not_found.xml.http +14 -0
- data/spec/fixtures/web/plugins/author/login_password_invalid.xml.http +12 -0
- data/spec/fixtures/web/plugins/clouds.xml +51 -0
- data/spec/fixtures/web/plugins/example.tgz.http +0 -0
- data/spec/fixtures/web/plugins/example.tgz.http.old +0 -0
- data/spec/fixtures/web/plugins/none.http +13 -0
- data/spec/fixtures/web/plugins/vert.xml +68 -0
- data/spec/fixtures/web/plugins/vertex-blob.xml +37 -0
- data/spec/fixtures/web/plugins/vertex-height-map.xml +44 -0
- data/spec/generators/app_generator_test.rb +42 -0
- data/spec/generators/controller_generator_test.rb +47 -0
- data/spec/generators/light_generator_test.rb +37 -0
- data/spec/generators/material_generator_test.rb +22 -0
- data/spec/generators/model_generator_test.rb +26 -0
- data/spec/generators/plugin_generator_test.rb +114 -0
- data/spec/generators/plugin_manager/push_test.rb +59 -0
- data/spec/generators/plugin_manager_test.rb +192 -0
- data/spec/generators/shader_generator_test.rb +38 -0
- data/spec/lib/jax/application_test.rb +18 -0
- data/spec/lib/jax/generators/plugin/credentials_test.rb +72 -0
- data/spec/lib/jax/packager_test.rb +87 -0
- data/spec/lib/jax/plugin_test.rb +27 -0
- data/spec/lib/jax/reloading_test.rb +23 -0
- data/spec/lib/jax/routes_test.rb +28 -0
- data/spec/lib/jax/shader_test.rb +29 -0
- data/spec/lib/jax/tasks/jax_rake_test.rb +85 -0
- data/spec/support/bases/generator_test_case.rb +108 -0
- data/spec/support/bases/isolated_test_case.rb +148 -0
- data/spec/support/fixtures_helper.rb +21 -0
- data/spec/support/spec_shell.rb +14 -1
- data/spec/test_app.rb +3 -0
- data/spec/test_helper.rb +55 -0
- metadata +200 -92
- data/spec/generators/app_generator_spec.rb +0 -47
- data/spec/generators/controller_generator_spec.rb +0 -68
- data/spec/generators/light_generator_spec.rb +0 -51
- data/spec/generators/material_generator_spec.rb +0 -35
- data/spec/generators/model_generator_spec.rb +0 -43
- data/spec/lib/jax/routes_spec.rb +0 -24
- data/spec/lib/jax/shader_spec.rb +0 -57
- data/spec/lib/jax/tasks/jax_rake_spec.rb +0 -92
- data/spec/spec_helper.rb +0 -11
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
# require 'test_app'
|
3
|
+
|
4
|
+
class Jax::Generators::Shader::ShaderGeneratorTest < Jax::Generators::TestCase
|
5
|
+
include TestHelpers::Paths
|
6
|
+
include TestHelpers::Generation
|
7
|
+
|
8
|
+
EXPECTED_FILES = %w(
|
9
|
+
app/shaders/clouds/common.ejs
|
10
|
+
app/shaders/clouds/fragment.ejs
|
11
|
+
app/shaders/clouds/manifest.yml
|
12
|
+
app/shaders/clouds/material.js
|
13
|
+
app/shaders/clouds/vertex.ejs
|
14
|
+
spec/javascripts/shaders/clouds_spec.js
|
15
|
+
)
|
16
|
+
|
17
|
+
test "generator" do
|
18
|
+
build_app
|
19
|
+
boot_app
|
20
|
+
self.class.destination app_path
|
21
|
+
generate 'clouds'
|
22
|
+
|
23
|
+
EXPECTED_FILES.each do |fi|
|
24
|
+
assert_file fi
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test "in plugin" do
|
29
|
+
build_app
|
30
|
+
plugin_generator 'clouds'
|
31
|
+
boot_app
|
32
|
+
|
33
|
+
generate "clouds"
|
34
|
+
EXPECTED_FILES.each do |fi|
|
35
|
+
assert_file File.join("vendor/plugins/clouds", fi)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Jax::ApplicationTest < IsolatedTestCase
|
4
|
+
def setup
|
5
|
+
build_app
|
6
|
+
app_file "app/shaders/clouds/fragment.ejs", "void main(void) { }"
|
7
|
+
boot_app
|
8
|
+
end
|
9
|
+
|
10
|
+
test "shaders" do
|
11
|
+
assert_not_nil Jax.application.shaders.find("clouds")
|
12
|
+
assert_equal abs("app/shaders/clouds"), Jax.application.shaders.find("clouds").path
|
13
|
+
end
|
14
|
+
|
15
|
+
test "paths" do
|
16
|
+
assert_contains Jax.root.to_s, Jax.application.javascript_source_roots
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Jax::Generators::Plugin::CredentialsTest < IsolatedTestCase
|
4
|
+
def shell
|
5
|
+
@shell ||= SpecShell.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def subject
|
9
|
+
@subject ||= Jax::Generators::Plugin::Credentials.new(
|
10
|
+
:home => FIXTURES_PATH,
|
11
|
+
:in => shell.stdin,
|
12
|
+
:out => shell.stdout
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
build_app
|
18
|
+
boot_app
|
19
|
+
FileUtils.rm fixture_path(".jax") if File.exist?(fixture_path(".jax"))
|
20
|
+
end
|
21
|
+
|
22
|
+
test "with new account" do
|
23
|
+
shell.stdin.returns [
|
24
|
+
'missing@gmail.com',
|
25
|
+
'password', 'password'
|
26
|
+
]
|
27
|
+
|
28
|
+
assert_equal "WXTzIXC2ODdbLAyvVL9p", subject.api_key
|
29
|
+
end
|
30
|
+
|
31
|
+
test "with missing config file and valid existing credentials" do
|
32
|
+
shell.stdin.returns [
|
33
|
+
'sinisterchipmunk@gmail.com',
|
34
|
+
'password'
|
35
|
+
]
|
36
|
+
|
37
|
+
assert_equal "WXTzIXC2ODdbLAyvVL9p", subject.api_key
|
38
|
+
end
|
39
|
+
|
40
|
+
test "with missing config file and invalid credentials for an existing account" do
|
41
|
+
shell.stdin.returns [
|
42
|
+
'missing@gmail.com',
|
43
|
+
'invalid'
|
44
|
+
]
|
45
|
+
|
46
|
+
assert_raises(RuntimeError) { subject.api_key }
|
47
|
+
end
|
48
|
+
|
49
|
+
test "with missing api key" do
|
50
|
+
shell.stdin.returns [
|
51
|
+
'missing@gmail.com',
|
52
|
+
'password', 'password'
|
53
|
+
]
|
54
|
+
subject.api_key
|
55
|
+
|
56
|
+
assert_match /email/i, shell.stdout.string
|
57
|
+
end
|
58
|
+
|
59
|
+
test "with api key" do
|
60
|
+
stub_fixture(".jax") { |f| f.print 'api_key: "1234"' }
|
61
|
+
|
62
|
+
assert_equal "1234", subject.api_key
|
63
|
+
end
|
64
|
+
|
65
|
+
test "default home" do
|
66
|
+
assert_equal File.expand_path("~"), Jax::Generators::Plugin::Credentials.new.home
|
67
|
+
end
|
68
|
+
|
69
|
+
test "override home" do
|
70
|
+
assert_equal File.expand_path("."), Jax::Generators::Plugin::Credentials.new(:home => ".").home
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Jax::Generators::Packager::PackageGeneratorTest < Jax::Generators::TestCase
|
4
|
+
include TestHelpers::Paths
|
5
|
+
include TestHelpers::Generation
|
6
|
+
|
7
|
+
setup do
|
8
|
+
build_app
|
9
|
+
app_file "public/asset.txt", 'content'
|
10
|
+
app_file 'app/helpers/my_helper.js', 'var MyHelper = "ONE";'
|
11
|
+
app_file "app/models/my_model.js", "//= require <support.js>\nvar MyModel = 'TWO';"
|
12
|
+
app_file "app/resources/my_models/default.yml", "three: 3"
|
13
|
+
app_file "app/resources/my_models/first.yml", "four: 4"
|
14
|
+
app_file "app/controllers/my_controller.js", "//= require \"application_controller.js\"\nvar MyController = Jax.Controller.create('my', ApplicationController, {});"
|
15
|
+
app_file "lib/support.js", "var SUPPORT = 1.0;"
|
16
|
+
|
17
|
+
plugin "cloud" do |p|
|
18
|
+
p.write "app/shaders/cloud/vertex.ejs", "void main() { }"
|
19
|
+
p.write "public/plugin-asset.txt", 'content'
|
20
|
+
|
21
|
+
p.write 'app/helpers/plugin_helper.js', 'var PluginHelper = "ONE";'
|
22
|
+
p.write "app/models/plugin_model.js", "//= require <plugin/support.js>\nvar PluginModel = 'TWO';"
|
23
|
+
p.write "app/resources/plugin_models/default.yml", "five: 5"
|
24
|
+
p.write "app/resources/plugin_models/second.yml", "six: 6"
|
25
|
+
p.write "app/controllers/plugin_controller.js", "//= require <application_controller.js>\nvar PluginController = Jax.Controller.create('plugin', ApplicationController, {});"
|
26
|
+
p.write "lib/plugin/support.js", "var PLUGIN_SUPPORT = 1.0;"
|
27
|
+
end
|
28
|
+
|
29
|
+
boot_app
|
30
|
+
self.class.destination Jax.root.to_s
|
31
|
+
@result = run_generator([])
|
32
|
+
end
|
33
|
+
|
34
|
+
test "lib" do
|
35
|
+
assert_file "pkg/javascripts/app_template.js" do |content|
|
36
|
+
assert_match /var SUPPORT = 1.0;/, content
|
37
|
+
assert_match /var PLUGIN_SUPPORT = 1.0;/, content
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
test "controllers" do
|
42
|
+
assert_file "pkg/javascripts/app_template.js" do |content|
|
43
|
+
# app and plugin controllers should both exist
|
44
|
+
assert_match /var MyController = Jax.Controller.create\('my', ApplicationController/, content
|
45
|
+
assert_match /var PluginController = Jax.Controller.create\('plugin', ApplicationController/, content
|
46
|
+
|
47
|
+
# application controller should precede both
|
48
|
+
assert_match /ApplicationController\s*=.*?MyController\s*=/m, content
|
49
|
+
assert_match /ApplicationController\s*=.*?PluginController\s*=/m, content
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
test "assets" do
|
54
|
+
assert_file "pkg/asset.txt"
|
55
|
+
assert_file "pkg/plugin-asset.txt"
|
56
|
+
end
|
57
|
+
|
58
|
+
test "models" do
|
59
|
+
assert_file "pkg/javascripts/app_template.js" do |content|
|
60
|
+
assert_match /var MyModel = 'TWO';/, content
|
61
|
+
assert_match /var PluginModel = 'TWO';/, content
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
test "resources" do
|
66
|
+
assert_file "pkg/javascripts/app_template.js" do |content|
|
67
|
+
content =~ /MyModel.addResources\((.*)?\)/
|
68
|
+
assert_not_nil $1, "MyModel has no resources"
|
69
|
+
hash = ActiveSupport::JSON.decode($1)
|
70
|
+
assert_equal 3, hash['default']['three']
|
71
|
+
assert_equal 4, hash['first']['four']
|
72
|
+
|
73
|
+
content =~ /PluginModel.addResources\((.*)?\)/
|
74
|
+
assert_not_nil $1, "PluginModel has no resources"
|
75
|
+
hash = ActiveSupport::JSON.decode($1)
|
76
|
+
assert_equal 5, hash['default']['five']
|
77
|
+
assert_equal 6, hash['second']['six']
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
test "helpers" do
|
82
|
+
assert_file "pkg/javascripts/app_template.js" do |content|
|
83
|
+
assert_match /var MyHelper = "ONE";/, content
|
84
|
+
assert_match /var PluginHelper = "ONE";/, content
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# see also ./packager_test.rb for plugin stuff related to app packaging
|
4
|
+
|
5
|
+
class Jax::PluginTest < IsolatedTestCase
|
6
|
+
def setup
|
7
|
+
build_app
|
8
|
+
plugin "cloud" do |p|
|
9
|
+
p.write "app/shaders/cloud/vertex.ejs", "void main() { }"
|
10
|
+
end
|
11
|
+
|
12
|
+
boot_app
|
13
|
+
end
|
14
|
+
|
15
|
+
test "detecting presence of plugin" do
|
16
|
+
assert_not_empty Jax.application.plugins
|
17
|
+
end
|
18
|
+
|
19
|
+
test "plugin shaders" do
|
20
|
+
assert_not_nil Jax.application.shaders.find("cloud")
|
21
|
+
assert_equal abs("vendor/plugins/cloud/app/shaders/cloud"), Jax.application.shaders.find("cloud").path
|
22
|
+
end
|
23
|
+
|
24
|
+
test "plugin paths" do
|
25
|
+
assert_contains abs("vendor/plugins/cloud"), Jax.application.javascript_source_roots
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Jax::ReloadingTest < IsolatedTestCase
|
4
|
+
def setup
|
5
|
+
build_app
|
6
|
+
app_file "app/shaders/clouds/fragment.ejs", "void main(void) { }"
|
7
|
+
boot_app
|
8
|
+
end
|
9
|
+
|
10
|
+
test "shaders" do
|
11
|
+
assert_match /#{Regexp::escape("void main(void) { }")}/, Jax.application.shaders.find("clouds").fragment
|
12
|
+
|
13
|
+
app_file "app/shaders/clouds/fragment.ejs", "void main(void) { gl_FragColor = vec4(1,1,1,1); }"
|
14
|
+
assert_match /#{Regexp::escape("void main(void) { gl_FragColor = vec4(1,1,1,1); }")}/,
|
15
|
+
Jax.application.shaders.find("clouds").fragment
|
16
|
+
end
|
17
|
+
|
18
|
+
test "resources" do
|
19
|
+
assert_no_match(/#{Regexp::escape "Door"}/, Jax.application.resources.to_s)
|
20
|
+
app_file "app/resources/doors/default.yml", "one: 1"
|
21
|
+
assert_match(/#{Regexp::escape "Door"}/, Jax.application.resources.to_s)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
class Jax::RoutesTest < ActiveSupport::TestCase
|
5
|
+
def subject
|
6
|
+
@subject ||= Jax::Routes.new
|
7
|
+
end
|
8
|
+
|
9
|
+
setup { @out = ""; @io = StringIO.new(@out) }
|
10
|
+
|
11
|
+
test "should map root" do
|
12
|
+
subject.root "welcome"
|
13
|
+
subject.compile(@io)
|
14
|
+
assert_equal 'Jax.routes.root(WelcomeController, "index");', @out.strip
|
15
|
+
end
|
16
|
+
|
17
|
+
test "should map" do
|
18
|
+
subject.map "path/to", "welcome"
|
19
|
+
subject.compile(@io)
|
20
|
+
assert_equal 'Jax.routes.map("path/to", WelcomeController, "index");', @out.strip
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should map with action name" do
|
24
|
+
subject.map "path/to", "welcome", "another"
|
25
|
+
subject.compile(@io)
|
26
|
+
assert_equal 'Jax.routes.map("path/to", WelcomeController, "another");', @out.strip
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Jax::ShaderTest < ActiveSupport::TestCase
|
4
|
+
def subject
|
5
|
+
@subject ||= Jax::Shader.new("path/to/shader")
|
6
|
+
end
|
7
|
+
|
8
|
+
test "subject properties" do
|
9
|
+
assert_equal "shader", subject.name
|
10
|
+
assert_equal "path/to/shader", subject.path
|
11
|
+
end
|
12
|
+
|
13
|
+
test "with an export" do
|
14
|
+
subject.fragment = "void main(void)\n{\n vec4 ambient;\n export(vec4, ambient, ambient);\n}"
|
15
|
+
|
16
|
+
# This has to be done in JS because we can't possibly avoid variable redefinitions at this stage
|
17
|
+
# it's this or have broken shader chains whenever two shaders happen to export the same variable
|
18
|
+
assert_no_match(/vec4 _shader_ambient;/, subject.to_s)
|
19
|
+
assert_match /exports: \{['"]ambient['"]:\s*['"]vec4['"]\},/, subject.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
test "with an import" do
|
23
|
+
subject.fragment = "void main(void)\n{\n vec4 a = import(ambient);\n}"
|
24
|
+
|
25
|
+
# This has to be done in JavaScript because we can't possibly know the exports of other shaders at this stage...
|
26
|
+
# it's this or have broken shader chains whenever they're not used in an expected order
|
27
|
+
assert_no_match(/_shader_ambient/, subject.to_s)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'test_app'
|
3
|
+
|
4
|
+
class Jax::RakeTasksTest < Rails::Generators::TestCase
|
5
|
+
PWD = File.expand_path("../tmp/generator_tests/test_app", Jax.framework_root)
|
6
|
+
self.destination_root = PWD
|
7
|
+
|
8
|
+
def shell
|
9
|
+
@shell ||= SpecShell.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def rake(args)
|
13
|
+
output = `bundle exec rake #{args} 2>&1`
|
14
|
+
if !$?.success?
|
15
|
+
raise output
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# TODO clean this up
|
20
|
+
setup do
|
21
|
+
FileUtils.rm_rf PWD
|
22
|
+
FileUtils.mkdir_p File.dirname(PWD) unless File.exist?(File.dirname(PWD))
|
23
|
+
Dir.chdir File.expand_path('..', PWD)
|
24
|
+
FileUtils.mkdir_p PWD
|
25
|
+
Dir.chdir File.dirname(PWD)
|
26
|
+
Jax::Generators::App::AppGenerator.start(["test_app"], :shell => shell)
|
27
|
+
Dir.chdir PWD
|
28
|
+
File.open("Gemfile", "w") { |f| f.print "gem 'jax', :path => '#{File.expand_path('../../../', PWD)}'"}
|
29
|
+
`bundle install`
|
30
|
+
Jax::Generators::Controller::ControllerGenerator.start(['welcome', 'index'], :shell => shell)
|
31
|
+
File.open("config/routes.rb", "w") do |f|
|
32
|
+
f.puts "TestApp.routes.map do\n root 'welcome'\nmap 'another/index'\nend"
|
33
|
+
end
|
34
|
+
FileUtils.mkdir_p "public/images"
|
35
|
+
FileUtils.touch "public/images/test.png"
|
36
|
+
end
|
37
|
+
|
38
|
+
teardown do
|
39
|
+
FileUtils.rm_rf PWD
|
40
|
+
Dir.chdir File.expand_path('..', PWD)
|
41
|
+
end
|
42
|
+
|
43
|
+
test "jax:generate_files" do
|
44
|
+
rake('jax:generate_files')
|
45
|
+
|
46
|
+
assert_match /jax:update/, File.read(File.expand_path('tmp/version_check.js'))
|
47
|
+
end
|
48
|
+
|
49
|
+
test "jax:generate_files does not duplicate routes" do
|
50
|
+
rake('jax:generate_files')
|
51
|
+
assert_file "tmp/routes.js" do |routes|
|
52
|
+
routes.lines.each do |line|
|
53
|
+
assert routes.split(line.chomp).length < 3
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
test "jax:package" do
|
59
|
+
rake('jax:package')
|
60
|
+
|
61
|
+
subject = File.read(File.expand_path('pkg/javascripts/test_app.js'))
|
62
|
+
|
63
|
+
# should install assets
|
64
|
+
assert_file 'pkg/images/test.png'
|
65
|
+
|
66
|
+
assert_file 'pkg/javascripts/test_app.js' do |app|
|
67
|
+
# should not do a version check
|
68
|
+
assert_no_match /jax:update/, app
|
69
|
+
# should contain views
|
70
|
+
assert_match /Jax.views.push\('welcome\/index'/, app
|
71
|
+
# should contain welcome controller
|
72
|
+
assert_match /var WelcomeController = /, app
|
73
|
+
# should contain application controller
|
74
|
+
assert_match /var ApplicationController = /, app
|
75
|
+
# should contain welcome helper
|
76
|
+
assert_match /var WelcomeHelper = /, app
|
77
|
+
# should contain application helper
|
78
|
+
assert_match /var ApplicationHelper = /, app
|
79
|
+
# should contain routes
|
80
|
+
assert_match /#{Regexp::escape 'Jax.routes.root(WelcomeController, "index")'}/, app
|
81
|
+
# should not contain ruby package names
|
82
|
+
assert_match /#{Regexp::escape 'Jax.routes.map("another/index", AnotherController, "index")'}/, app
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'rails/generators/test_case'
|
2
|
+
require 'active_support/testing/isolation'
|
3
|
+
|
4
|
+
# probably should have one of these in standard jax dist, but not
|
5
|
+
# necessarily *this* class
|
6
|
+
class Jax::Generators::TestCase < Rails::Generators::TestCase
|
7
|
+
include ActiveSupport::Testing::Isolation unless ENV['DO_NOT_ISOLATE']
|
8
|
+
|
9
|
+
def self.inherited(base)
|
10
|
+
super
|
11
|
+
base.class_eval do
|
12
|
+
destination Jax.application ? Jax.root : File.expand_path('../tmp/tmp', Jax.framework_root)
|
13
|
+
setup :prepare_destination
|
14
|
+
teardown :restore_streams
|
15
|
+
|
16
|
+
begin
|
17
|
+
name = base.name.sub(/Test$/, '').split(/::/)
|
18
|
+
konst = (name.first == "Jax") ? Object.class : Jax::Generators
|
19
|
+
while const_name = name.shift
|
20
|
+
konst = konst.const_get(const_name)
|
21
|
+
end
|
22
|
+
base.tests konst
|
23
|
+
rescue
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# call this when you've included both TestHelpers::Paths and TestHelpers::Generation
|
29
|
+
# and want to test Jax generators within plugin directories.
|
30
|
+
def plugin_generator(plugin_name, &block)
|
31
|
+
plugin plugin_name, &block
|
32
|
+
# this happens in bin/jax
|
33
|
+
self.class.destination app_path
|
34
|
+
@jax_cwd = File.join(app_path, "vendor/plugins", plugin_name)
|
35
|
+
File.mkdir_p @jax_cwd unless File.directory?(@jax_cwd)
|
36
|
+
end
|
37
|
+
|
38
|
+
setup do
|
39
|
+
unless Jax.application || self.class.include?(TestHelpers::Generation)
|
40
|
+
require 'test_app'
|
41
|
+
self.class.destination Jax.root
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate(*args)
|
46
|
+
ENV['JAX_CWD'] = @jax_cwd
|
47
|
+
result = run_generator args
|
48
|
+
ENV['JAX_CWD'] = nil
|
49
|
+
result
|
50
|
+
end
|
51
|
+
|
52
|
+
def copy_routes
|
53
|
+
routes = File.expand_path("../../../../lib/jax/generators/app/templates/config/routes.rb.tt", __FILE__)
|
54
|
+
destination = File.join(destination_root, "config")
|
55
|
+
FileUtils.mkdir_p destination
|
56
|
+
FileUtils.cp routes, File.join(destination, "routes.rb")
|
57
|
+
end
|
58
|
+
|
59
|
+
def stub_file(path, content = nil)
|
60
|
+
file = File.expand_path(path, destination_root)
|
61
|
+
FileUtils.mkdir_p File.dirname(file)
|
62
|
+
File.open(file, "w") do |f|
|
63
|
+
f.print content if content
|
64
|
+
yield f if block_given?
|
65
|
+
end
|
66
|
+
File.read(file)
|
67
|
+
end
|
68
|
+
|
69
|
+
def stdin
|
70
|
+
mock_stream :stdin
|
71
|
+
end
|
72
|
+
|
73
|
+
def stdout
|
74
|
+
mock_stream :stdout
|
75
|
+
end
|
76
|
+
|
77
|
+
def stderr
|
78
|
+
mock_stream :stderr
|
79
|
+
end
|
80
|
+
|
81
|
+
def mock_stream(type)
|
82
|
+
@mock_streams ||= {}
|
83
|
+
@mock_streams[type] ||= StringIO.new
|
84
|
+
@mock_streams[type].instance_eval do
|
85
|
+
def returns(str)
|
86
|
+
self.string = str
|
87
|
+
end
|
88
|
+
end
|
89
|
+
prepare_mock_stream type, @mock_streams[type]
|
90
|
+
end
|
91
|
+
|
92
|
+
def real_streams
|
93
|
+
@real_streams ||= {}
|
94
|
+
end
|
95
|
+
|
96
|
+
def prepare_mock_stream(type, stream)
|
97
|
+
real_streams[type] ||= eval("$#{type}")
|
98
|
+
set_stream type, stream
|
99
|
+
end
|
100
|
+
|
101
|
+
def restore_streams
|
102
|
+
real_streams.each { |type, stream| set_stream type, stream }
|
103
|
+
end
|
104
|
+
|
105
|
+
def set_stream(type, stream)
|
106
|
+
eval "$#{type} = stream"
|
107
|
+
end
|
108
|
+
end
|