rails-js-routes 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.travis.yml +3 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +127 -0
- data/MIT-LICENSE +20 -0
- data/README.md +161 -0
- data/Rakefile +25 -0
- data/app/assets/javascripts/routes.js +327 -0
- data/lib/rails/js/routes.rb +10 -0
- data/lib/rails/js/routes/engine.rb +12 -0
- data/lib/rails/js/routes/version.rb +7 -0
- data/lib/rails/js/routes/view_helpers.rb +25 -0
- data/rails-js-routes.gemspec +24 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +14 -0
- data/test/dummy/app/assets/javascripts/testing.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/controllers/testing_controller.rb +6 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/testing_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +15 -0
- data/test/dummy/app/views/testing/index.html.erb +0 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +22 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +83 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +3 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/spec/javascripts/route_dispatch_spec.js +165 -0
- data/test/dummy/spec/javascripts/spec_helper.js +31 -0
- data/test/dummy/spec/teaspoon_env.rb +13 -0
- data/test/dummy/test/helpers/testing_helper_test.rb +4 -0
- data/test/teaspoon_env.rb +24 -0
- data/test/test_helper.rb +18 -0
- data/test/testing_controller_test.rb +12 -0
- metadata +178 -0
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format. Inflections
|
4
|
+
# are locale specific, and you may define rules for as many different
|
5
|
+
# locales as you wish. All of these examples are active by default:
|
6
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
7
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
8
|
+
# inflect.singular /^(ox)en/i, '\1'
|
9
|
+
# inflect.irregular 'person', 'people'
|
10
|
+
# inflect.uncountable %w( fish sheep )
|
11
|
+
# end
|
12
|
+
|
13
|
+
# These inflection rules are supported but not enabled by default:
|
14
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
15
|
+
# inflect.acronym 'RESTful'
|
16
|
+
# end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
|
9
|
+
end
|
10
|
+
|
11
|
+
# To enable root element in JSON for ActiveRecord objects.
|
12
|
+
# ActiveSupport.on_load(:active_record) do
|
13
|
+
# self.include_root_in_json = true
|
14
|
+
# end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
+
# than English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t 'hello'
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t('hello') %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# To learn more, please read the Rails Internationalization guide
|
20
|
+
# available at http://guides.rubyonrails.org/i18n.html.
|
21
|
+
|
22
|
+
en:
|
23
|
+
hello: "Hello world"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rake secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure the secrets in this file are kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
|
13
|
+
development:
|
14
|
+
secret_key_base: 78846b64c741c1343375f567793baea08b47c4cc383fca18e7ea3de893e44e13650dc2fc41cbe49b84ea49cb6fb3b208bd0dd205cb9310a0bb00057a49756e8f
|
15
|
+
|
16
|
+
test:
|
17
|
+
secret_key_base: 122cf3ea286d1336eca8ff19eccdeee09a5b10b3118f9fe236557aa4595a820313bc5dc7f1796c377fd22f685306c9a17a2c06488d946f93152000aa03f669ff
|
18
|
+
|
19
|
+
# Do not keep production secrets in the repository,
|
20
|
+
# instead read values from the environment.
|
21
|
+
production:
|
22
|
+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
File without changes
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,165 @@
|
|
1
|
+
|
2
|
+
/*
|
3
|
+
* Test for rails.js
|
4
|
+
*
|
5
|
+
* For more information see rails.js itself
|
6
|
+
*/
|
7
|
+
|
8
|
+
(function() {
|
9
|
+
describe('rails-js_route_dispatch', function() {
|
10
|
+
|
11
|
+
/*
|
12
|
+
* define all functions spied on
|
13
|
+
*/
|
14
|
+
var spies = { beforeAll: function() {},
|
15
|
+
namespaceHook: function() {},
|
16
|
+
usersIndex: function() {},
|
17
|
+
entitiesNew: function() {},
|
18
|
+
adminUsersIndex: function() {},
|
19
|
+
aHelper: function() {}
|
20
|
+
};
|
21
|
+
|
22
|
+
beforeEach(function() {
|
23
|
+
|
24
|
+
// Set config normally set by view_helper
|
25
|
+
Rails.config = {
|
26
|
+
controller: 'users',
|
27
|
+
action: 'index'
|
28
|
+
};
|
29
|
+
|
30
|
+
|
31
|
+
/*
|
32
|
+
* Clean up
|
33
|
+
*/
|
34
|
+
Rails.clear();
|
35
|
+
|
36
|
+
spyOn(spies, 'beforeAll');
|
37
|
+
spyOn(spies, 'namespaceHook');
|
38
|
+
spyOn(spies, 'usersIndex');
|
39
|
+
spyOn(spies, 'entitiesNew');
|
40
|
+
spyOn(spies, 'adminUsersIndex');
|
41
|
+
spyOn(spies, 'aHelper');
|
42
|
+
|
43
|
+
/*
|
44
|
+
* Create an app
|
45
|
+
*/
|
46
|
+
Rails.app({
|
47
|
+
// global helpers
|
48
|
+
answer: function() {
|
49
|
+
return 42
|
50
|
+
}
|
51
|
+
}, {
|
52
|
+
// initial data
|
53
|
+
foo: 'bar'
|
54
|
+
}, spies.beforeAll);
|
55
|
+
|
56
|
+
/*
|
57
|
+
* Create a controller
|
58
|
+
*/
|
59
|
+
Rails.controller('users', {
|
60
|
+
index: spies.usersIndex,
|
61
|
+
new: function(h) {
|
62
|
+
// execute helper
|
63
|
+
h.aHelper();
|
64
|
+
}
|
65
|
+
}, {
|
66
|
+
aHelper: spies.aHelper
|
67
|
+
});
|
68
|
+
});
|
69
|
+
|
70
|
+
it('must be defined', function() {
|
71
|
+
expect(Rails).toBeDefined();
|
72
|
+
expect(R).toBeDefined();
|
73
|
+
});
|
74
|
+
|
75
|
+
it('must handle global variables', function() {
|
76
|
+
R('a.global.variable', 'foo');
|
77
|
+
|
78
|
+
expect(R('a')).toBeDefined();
|
79
|
+
expect(R('a.global')).toBeDefined();
|
80
|
+
expect(R('a.global.variable')).toBe('foo');
|
81
|
+
});
|
82
|
+
|
83
|
+
it('must be able to execute global helpers', function() {
|
84
|
+
expect(R.global('answer')).toBe(42);
|
85
|
+
});
|
86
|
+
|
87
|
+
it('must be able to read initial data', function() {
|
88
|
+
expect(R('foo')).toBe('bar');
|
89
|
+
});
|
90
|
+
|
91
|
+
it('must execute beforeAll hook', function() {
|
92
|
+
Rails.execute();
|
93
|
+
expect(spies.beforeAll).toHaveBeenCalled();
|
94
|
+
});
|
95
|
+
|
96
|
+
it('must execute right controller action', function() {
|
97
|
+
Rails.execute();
|
98
|
+
expect(spies.usersIndex).toHaveBeenCalled();
|
99
|
+
|
100
|
+
// Change action to users#new
|
101
|
+
Rails.config.action = 'new';
|
102
|
+
|
103
|
+
// A helper must be called from within users#new
|
104
|
+
Rails.execute();
|
105
|
+
expect(spies.aHelper).toHaveBeenCalled();
|
106
|
+
|
107
|
+
// Create entities controller
|
108
|
+
Rails.controller('entities', { new: spies.entitiesNew });
|
109
|
+
// Change controller to entities#new
|
110
|
+
Rails.config.controller = 'entities';
|
111
|
+
|
112
|
+
Rails.execute();
|
113
|
+
expect(spies.entitiesNew).toHaveBeenCalled();
|
114
|
+
});
|
115
|
+
|
116
|
+
it('must handle controller with same name but different namespace', function() {
|
117
|
+
Rails.controller('admin/users', {
|
118
|
+
index: spies.adminUsersIndex
|
119
|
+
});
|
120
|
+
|
121
|
+
Rails.config.namespace = 'admin';
|
122
|
+
Rails.execute();
|
123
|
+
expect(spies.adminUsersIndex).toHaveBeenCalled();
|
124
|
+
expect(spies.usersIndex).not.toHaveBeenCalled();
|
125
|
+
});
|
126
|
+
|
127
|
+
it('must execute foreign helper', function() {
|
128
|
+
Rails.controller('admin/users', {
|
129
|
+
index: function() {
|
130
|
+
R.helper('users', 'aHelper');
|
131
|
+
}
|
132
|
+
});
|
133
|
+
|
134
|
+
Rails.config.namespace = 'admin';
|
135
|
+
Rails.execute();
|
136
|
+
expect(spies.aHelper).toHaveBeenCalled();
|
137
|
+
});
|
138
|
+
|
139
|
+
it('must execute foreign action', function() {
|
140
|
+
Rails.controller('admin/users', {
|
141
|
+
index: function() {
|
142
|
+
R.action('users#index');
|
143
|
+
}
|
144
|
+
});
|
145
|
+
|
146
|
+
Rails.config.namespace = 'admin';
|
147
|
+
Rails.execute();
|
148
|
+
expect(spies.usersIndex).toHaveBeenCalled();
|
149
|
+
});
|
150
|
+
|
151
|
+
it('must execute namespace hook when in namespace', function() {
|
152
|
+
// Define namespace with hook
|
153
|
+
Rails.namespace('admin', spies.namespaceHook);
|
154
|
+
|
155
|
+
// First without namespace
|
156
|
+
Rails.execute();
|
157
|
+
expect(spies.namespaceHook).not.toHaveBeenCalled();
|
158
|
+
|
159
|
+
// Now with namespace
|
160
|
+
Rails.config.namespace = 'admin';
|
161
|
+
Rails.execute();
|
162
|
+
expect(spies.namespaceHook).toHaveBeenCalled();
|
163
|
+
});
|
164
|
+
});
|
165
|
+
})();
|