-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from le0pard/master
Support AMD
- Loading branch information
Showing
5 changed files
with
98 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,6 @@ pkg | |
.ruby-version | ||
|
||
Gemfile.lock | ||
gemfiles/*.lock | ||
gemfiles/*.lock | ||
|
||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require "spec_helper" | ||
|
||
describe JsRoutes, "compatibility with AMD/require.js" do | ||
|
||
before(:each) do | ||
evaljs("window.GlobalCheck = {};") | ||
evaljs("window.define = function (requirs, callback) { window.GlobalCheck['js-routes'] = callback.call(this); return window.GlobalCheck['js-routes']; };") | ||
evaljs("window.define.amd = { jQuery: true };") | ||
strRequire =<<EOF | ||
window.require = function (r, callback) { | ||
var allArgs, i; | ||
allArgs = (function() { | ||
var _i, _len, _results; | ||
_results = []; | ||
for (_i = 0, _len = r.length; _i < _len; _i++) { | ||
i = r[_i]; | ||
_results.push(window.GlobalCheck[i]); | ||
} | ||
return _results; | ||
})(); | ||
return callback.apply(null, allArgs); | ||
}; | ||
EOF | ||
evaljs(strRequire) | ||
evaljs(JsRoutes.generate({})) | ||
end | ||
|
||
it "should working from global scope" do | ||
expect(evaljs("Routes.inboxes_path()")).to eq(routes.inboxes_path()) | ||
end | ||
|
||
it "should working from define function" do | ||
expect(evaljs("Routes.inboxes_path()")).to eq(evaljs("GlobalCheck['js-routes'].inboxes_path()")) | ||
end | ||
|
||
it "should working from require" do | ||
expect(evaljs("require(['js-routes'], function(r){ return r.inboxes_path(); })")).to eq(routes.inboxes_path()) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters