Sha256: e5ec40a6f3c8bf0e027cf300d25304557820c5c737f47d7f1c9c5ef10744b566

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

require "spec_helper"

describe JsRoutes, "compatibility with AMD/require.js"  do

  before(:each) do
    evaljs("var global = this;", force: true)
    evaljs("global.GlobalCheck = {};")
    evaljs("global.define = function (requirs, callback) { global.GlobalCheck['js-routes'] = callback.call(this); return global.GlobalCheck['js-routes']; };")
    evaljs("global.define.amd = { jQuery: true };")
    strRequire =<<EOF
    global.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(global.GlobalCheck[i]);
        }
        return _results;
      })();

      return callback.apply(null, allArgs);
    };
EOF
    evaljs(strRequire)
    evaljs(JsRoutes.generate(module_type: 'AMD'))
  end

  it "should working from require" do
    expectjs("require(['js-routes'], function(r){ return r.inboxes_path(); })").to eq(test_routes.inboxes_path())
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
js-routes-2.2.9 spec/js_routes/module_types/amd_spec.rb
js-routes-2.2.8 spec/js_routes/module_types/amd_spec.rb
js-routes-2.2.7 spec/js_routes/module_types/amd_spec.rb
js-routes-2.2.6 spec/js_routes/module_types/amd_spec.rb
js-routes-2.2.5 spec/js_routes/module_types/amd_spec.rb