Sha256: 1f2e96ab3a5279508f1b6848ee59bdebea0a35ed7ebaf276fc30012fe7eab512

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

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(test_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(test_routes.inboxes_path())
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
js-routes-1.4.9 spec/js_routes/amd_compatibility_spec.rb
js-routes-1.4.8 spec/js_routes/amd_compatibility_spec.rb
js-routes-1.4.7 spec/js_routes/amd_compatibility_spec.rb
js-routes-1.4.6 spec/js_routes/amd_compatibility_spec.rb
js-routes-1.4.5 spec/js_routes/amd_compatibility_spec.rb
js-routes-1.4.4 spec/js_routes/amd_compatibility_spec.rb
js-routes-1.4.3 spec/js_routes/amd_compatibility_spec.rb
js-routes-1.4.2 spec/js_routes/amd_compatibility_spec.rb
js-routes-1.4.1 spec/js_routes/amd_compatibility_spec.rb
js-routes-1.4.0 spec/js_routes/amd_compatibility_spec.rb