Skip to content

Commit

Permalink
Fix js(false) issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kbparagua committed Mar 24, 2015
1 parent 38adb49 commit 0e33fe9
Show file tree
Hide file tree
Showing 13 changed files with 15,904 additions and 25 deletions.
9 changes: 5 additions & 4 deletions app/views/paloma/_hook.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

var request = <%= request.to_json.html_safe %>;

Paloma.engine.setRequest(
request['resource'],
request['action'],
request['params']);
Paloma.engine.setRequest({
id: "<%= id %>",
resource: request['resource'],
action: request['action'],
params: request['params']});
})();
</script>
</div>
4 changes: 2 additions & 2 deletions test_app/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require turbolinks
//=# require turbolinks
//= require paloma
//= require_tree .

Expand Down Expand Up @@ -51,4 +51,4 @@ Foos.prototype.otherAction = function(){};

var NotFoos = Paloma.controller('NotAdmin/Foos');
NotFoos.prototype.show = function(){};
NotFoos.prototype.otherAction = function(){};
NotFoos.prototype.otherAction = function(){};
38 changes: 21 additions & 17 deletions test_app/spec/integration/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
it 'executes the same controller/action' do
visit main_index_path

expect(request).to eq({
'controller' => 'Main',
'action' => 'index',
'params' => {}})
expect(
request['controller'] == 'Main' &&
request['action'] == 'index' &&
request['params'] == {}
).to be_truthy
end
end

Expand All @@ -31,10 +32,11 @@
it 'executes the specified controller' do
visit main_path(1)

expect(request).to eq({
'controller' => 'OtherMain',
'action' => 'show',
'params' => {'x' => 1}})
expect(
request['controller'] == 'OtherMain' &&
request['action'] == 'show' &&
request['params'] == {'x' => 1}
).to be_truthy
end
end

Expand All @@ -43,10 +45,11 @@
it 'executes the specified action' do
visit new_main_path

expect(request).to eq({
'controller' => 'Main',
'action' => 'otherAction',
'params' => {'x' => 1}})
expect(
request['controller'] == 'Main' &&
request['action'] == 'otherAction' &&
request['params'] == {'x' => 1}
).to be_truthy
end
end

Expand All @@ -55,10 +58,11 @@
it 'executes the specified controller/action' do
visit edit_main_path(1)

expect(request).to eq({
'controller' => 'OtherMain',
'action' => 'otherAction',
'params' => {'x' => 1}})
expect(
request['controller'] == 'OtherMain' &&
request['action'] == 'otherAction' &&
request['params'] == {'x' => 1}
).to be_truthy
end
end

Expand All @@ -83,7 +87,7 @@

shared_examples 'no paloma' do
it 'does not add paloma hook' do
expect(page.has_selector?('.js-paloma-hook')).to be_false
expect(page.has_selector?('.js-paloma-hook')).to be_falsy
end
end

Expand Down
27 changes: 27 additions & 0 deletions test_app/spec/tmp/assets/jasmine-boot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var jsApiReporter;
(function() {
var jasmineEnv = jasmine.getEnv();

jsApiReporter = new jasmine.JsApiReporter();
jasmineEnv.addReporter(jsApiReporter);

var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};

if (jasmine.ConsoleReporter) {
jasmineEnv.addReporter(new jasmine.ConsoleReporter());
}

function execJasmine() {
jasmineEnv.execute();
}

if (window.addEventListener) { // W3C
window.addEventListener('load', execJasmine, false);
} else if (window.attachEvent) { // MSIE
window.attachEvent('onload', execJasmine);
}
})();
111 changes: 111 additions & 0 deletions test_app/spec/tmp/assets/jasmine-console-reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
Jasmine Reporter that outputs test results to the browser console.
Useful for running in a headless environment such as PhantomJs, ZombieJs etc.
Usage:
// From your html file that loads jasmine:
jasmine.getEnv().addReporter(new jasmine.ConsoleReporter());
jasmine.getEnv().execute();
*/


(function(jasmine, console) {
if (!jasmine) {
throw "jasmine library isn't loaded!";
}

var ANSI = {}
ANSI.color_map = {
"green" : 32,
"red" : 31
}

ANSI.colorize_text = function(text, color) {
var color_code = this.color_map[color];
return "\033[" + color_code + "m" + text + "\033[0m";
}

var ConsoleReporter = function() {
if (!console || !console.log) { throw "console isn't present!"; }
this.status = this.statuses.stopped;
};

var proto = ConsoleReporter.prototype;
proto.statuses = {
stopped : "stopped",
running : "running",
fail : "fail",
success : "success"
};

proto.reportRunnerStarting = function(runner) {
this.status = this.statuses.running;
this.start_time = (new Date()).getTime();
this.executed_specs = 0;
this.passed_specs = 0;
this.log("Starting...");
};

proto.reportRunnerResults = function(runner) {
var failed = this.executed_specs - this.passed_specs;
var spec_str = this.executed_specs + (this.executed_specs === 1 ? " spec, " : " specs, ");
var fail_str = failed + (failed === 1 ? " failure in " : " failures in ");
var color = (failed > 0)? "red" : "green";
var dur = (new Date()).getTime() - this.start_time;

this.log("");
this.log("Finished");
this.log("-----------------");
this.log(spec_str + fail_str + (dur/1000) + "s.", color);

this.status = (failed > 0)? this.statuses.fail : this.statuses.success;

/* Print something that signals that testing is over so that headless browsers
like PhantomJs know when to terminate. */
this.log("");
this.log("ConsoleReporter finished");
};


proto.reportSpecStarting = function(spec) {
this.executed_specs++;
};

proto.reportSpecResults = function(spec) {
if (spec.results().skipped) {
return;
}
if (spec.results().passed()) {
this.passed_specs++;
return;
}

var resultText = spec.suite.description + " : " + spec.description;
this.log(resultText, "red");

var items = spec.results().getItems()
for (var i = 0; i < items.length; i++) {
var item = items[i];
var output = ' ' + item.message;
this.log(output, "red");
}
};

proto.reportSuiteResults = function(suite) {
if (suite.parentSuite) { return; }
var results = suite.results();
if (results.totalCount === 0) {
return;
}
var failed = results.totalCount - results.passedCount;
var color = (failed > 0)? "red" : "green";
this.log(suite.description + ": " + results.passedCount + " of " + results.totalCount + " passed.", color);
};

proto.log = function(str, color) {
var text = (color != undefined)? ANSI.colorize_text(str, color) : str;
console.log(text)
};

jasmine.ConsoleReporter = ConsoleReporter;
})(jasmine, console);
31 changes: 31 additions & 0 deletions test_app/spec/tmp/assets/jasmine-console-shims.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(function() {
/**
* Function.bind for ECMAScript 5 Support
*
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
*/

if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}

var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};

fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();

return fBound;
};
}
})();
Loading

0 comments on commit 0e33fe9

Please sign in to comment.