Commit 0390bbde authored by Raphael Sofaer's avatar Raphael Sofaer
Browse files

Activerecord this time\!

parents
document.observe("dom:loaded", function() {
function handleRemote(element) {
var method, url, params;
if (element.tagName.toLowerCase() === 'form') {
method = element.readAttribute('method') || 'post';
url = element.readAttribute('action');
params = element.serialize(true);
} else {
method = element.readAttribute('data-method') || 'get';
url = element.readAttribute('href');
params = {};
}
var event = element.fire("ajax:before");
if (event.stopped) return false;
new Ajax.Request(url, {
method: method,
parameters: params,
asynchronous: true,
evalScripts: true,
onLoading: function(request) { element.fire("ajax:loading", {request: request}); },
onLoaded: function(request) { element.fire("ajax:loaded", {request: request}); },
onInteractive: function(request) { element.fire("ajax:interactive", {request: request}); },
onComplete: function(request) { element.fire("ajax:complete", {request: request}); },
onSuccess: function(request) { element.fire("ajax:success", {request: request}); },
onFailure: function(request) { element.fire("ajax:failure", {request: request}); }
});
element.fire("ajax:after");
}
function handleMethod(element) {
var method, url, token_name, token;
method = element.readAttribute('data-method');
url = element.readAttribute('href');
csrf_param = $$('meta[name=csrf-param]').first();
csrf_token = $$('meta[name=csrf-token]').first();
var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
element.parentNode.appendChild(form);
if (method != 'post') {
var field = new Element('input', { type: 'hidden', name: '_method', value: method });
form.appendChild(field);
}
if (csrf_param) {
var param = csrf_param.readAttribute('content');
var token = csrf_token.readAttribute('content');
var field = new Element('input', { type: 'hidden', name: param, value: token });
form.appendChild(field);
}
form.submit();
}
$(document.body).observe("click", function(event) {
var message = event.findElement().readAttribute('data-confirm');
if (message && !confirm(message)) {
event.stop();
return false;
}
var element = event.findElement("a[data-remote]");
if (element) {
handleRemote(element);
event.stop();
return true;
}
var element = event.findElement("a[data-method]");
if (element) {
handleMethod(element);
event.stop();
return true;
}
});
// TODO: I don't think submit bubbles in IE
$(document.body).observe("submit", function(event) {
var element = event.findElement(),
message = element.readAttribute('data-confirm');
if (message && !confirm(message)) {
event.stop();
return false;
}
var inputs = element.select("input[type=submit][data-disable-with]");
inputs.each(function(input) {
input.disabled = true;
input.writeAttribute('data-original-value', input.value);
input.value = input.readAttribute('data-disable-with');
});
var element = event.findElement("form[data-remote]");
if (element) {
handleRemote(element);
event.stop();
}
});
$(document.body).observe("ajax:after", function(event) {
var element = event.findElement();
if (element.tagName.toLowerCase() === 'form') {
var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
inputs.each(function(input) {
input.value = input.readAttribute('data-original-value');
input.writeAttribute('data-original-value', null);
input.disabled = false;
});
}
});
});
\ No newline at end of file
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
# User-Agent: *
# Disallow: /
#!/usr/bin/env ruby1.8
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails)
require 'rspec/rails'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
Rspec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, comment the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end
require 'test_helper'
require 'rails/performance_test_help'
# Profiling results for each test method are written to tmp/performance.
class BrowsingTest < ActionDispatch::PerformanceTest
def test_homepage
get '/'
end
end
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
# Add more helper methods to be used by all tests here...
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment