WOW! WatchJS became so popular that I've been pushed to migrate it to GitHub
https://github.com/melanke/Watch.JS
Just kidding
| ENV["RAILS_ENV"] = "test" | |
| require File.expand_path('../../config/environment', __FILE__) | |
| require 'rails/test_help' | |
| require 'minitest/autorun' | |
| require 'minitest/pride' | |
| require 'capybara/rails' | |
| class MiniTest::Spec | |
| include ActiveSupport::Testing::SetupAndTeardown |
WOW! WatchJS became so popular that I've been pushed to migrate it to GitHub
https://github.com/melanke/Watch.JS
Just kidding
| javascript:(function(){ | |
| /* Bookmarklet for viewing source in iPad Safari */ | |
| var pageHTML = document.documentElement.innerHTML; | |
| var otherlib = false; | |
| var jQueryLoaded = false; | |
| document.documentElement.innerHTML = '<!DOCTYPE html><html><head><title>Source of ' + location.href + '</title><meta name="viewport" content="width=device-width" /></head><body><div id="editor" style="height:' + window.innerHeight + 'px;width:' + window.innerWidth + 'px;"></div></body></html>'; | |
| /* Load jQuery */ | |
| if(typeof jQuery != 'undefined') { | |
| console.log('This page already using jQuery v' + jQuery.fn.jquery); |
| class CssBlock | |
| attr_reader :selector, :properties | |
| def initialize(selector, properties = {}) | |
| @selector = selector.dup.freeze | |
| @properties = properties.dup.freeze | |
| end | |
| def set(key, value = nil) | |
| new_properties = if key.is_a?(Hash) |
| ENV["RAILS_ENV"] = "test" | |
| require File.expand_path('../../config/environment', __FILE__) | |
| require 'rubygems' | |
| gem 'minitest' | |
| require 'minitest/autorun' | |
| require 'action_controller/test_case' | |
| require 'miniskirt' | |
| require 'capybara/rails' |
For a while, I have felt that the following is the correct way to improve the mass assignment problem without increasing the burden on new users. Now that the problem with the Rails default has been brought up again, it's a good time to revisit it.
When creating a form with form_for, include a signed token including all of the fields that were created at form creation time. Only these fields are allowed.
To allow new known fields to be added via JS, we could add:
| class PostsController < ActionController::Base | |
| def create | |
| Post.create(post_params) | |
| end | |
| def update | |
| Post.find(params[:id]).update_attributes!(post_params) | |
| end | |
| private |
| # account.rb | |
| class Account < ActiveRecord::Base | |
| has_many :users | |
| has_many :services | |
| end | |
| # user.rb | |
| class User < ActiveRecord::Base | |
| belongs_to :account | |
| end |
I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").
Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):
# minitest/spec.rb
module MiniTest::Expectations| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Determine Link Trigger Method With jQuery</title> | |
| </head> | |
| <body> | |
| <h1> | |
| Determine Link Trigger Method With jQuery | |
| </h1> |