Ruby – Time.next(:friday)
Thursday, March 31st, 2011This patch adds a method to find the next requested weekday.
This patch adds a method to find the next requested weekday.
I'm building a user model that keeps track of your parents and any children you should have. The acts_as_tree plugin
wouldn't have worked because it wouldn't allow for a parent to have many children. What's needed is a HABTM relationship. It's a quite simple relationship except for the :association_foreign_key option not being listed in the docs. Anyways I found some people discussing it here.
class User < ActiveRecord::Base has_and_belongs_to_many :parents, :class_name => "User", :join_table => "parents_children", :foreign_key => "child_id", :association_foreign_key => "parent_id" has_and_belongs_to_many :children, :class_name => "User", :join_table => "parents_children", :foreign_key => "parent_id" , :association_foreign_key => "child_id" end
describe User do
it "should have 0 children" do
User.new.should have(0).children
end
it "should have 0 parents" do
User.new.should have(0).parents
end
it "should have 1 child" do
parent = User.new
parent.children << User.new
parent.should have(1).children
end
it "should have 0 parents" do
child = User.new
child.parents << User.new
child.should have(1).parents
end
end
Active.com Review
http://techcrunch.com/2010/09/26/techcrunch-disrupt-hackathon-winner/
Video
Our brainstorming kicked off 9 am Saturday morning at the San Diego Airport. Two hours later in San Francisco we had scribbled out an iPhone app, app server and, a client where guest can watch the games.

At 1 pm we arrived at the TechCrunch Distupt Exhibition Center and got a table with the other 450 hackers. Most people came prepared for warfare; 30" monitors, chairs, sleeping bags, food, tablets, keyboards, and laptop stands. I was feeling under gunned and was just hoping I packed an extra pair of socks.
TechCrunch had engineers on site from Facebook, Twitter, CityGrid, and Mashery onsite to give API demos.

12:53 AM ( Taco truck delivered a midnight snack )

I had the iPhone Simulator running the mobile app which connected to my local ruby app in Sinatra. You can see our hacked code on github

3:07:56 AM Some people have retreated but still a large number working and a lot of energy.

7:11:01 AM
So we decided Hackman was finished at 7 am when the sun came up.

11:12:49 AM
The demos started at 11

The presentation

After our presentation we were surprised how many people were tweeting about hacman.




I found the stub_chain method very helpful when stubbing out objects for Rspec controller testing.
My index action is calling 2 named_scopes and then doing a find.
def index @exercise_logs = ExerciseLog.this_user(current_user).past.all end
When testing controllers your just trying to stub out a value for @exercise_logs not simulating an actual call to your model. So we'll use the stub_chain method to stub out our named_scopes like this.
it "assigns all exercise_logs as @exercise_logs" do
ExerciseLog.stub_chain(:this_user,:past).and_return([mock(ExerciseLog),mock(ExerciseLog)])
get :index
response.should be_success
end
It's important to filter out any sensitive data such as passwords from your log files. You can easily filter out data across your while application by calling filter_paramter_logging from your ApplicationController. In the example below I'm passing :password and :password_confirmation to remove their values from being placed in the logs.
class ApplicationController < ActionController::Base filter_parameter_logging :password, :password_confirmation end
You will now see "FILTERED" in place of sensitive data.
Parameters: {"x"=>"37", "y"=>"14", "action"=>"login", "authenticity_token"=>"JRFNcG9chNIpcsHoJzcQRRy1D6lIenjl7cWmvp3UpaI=", "controller"=>"videos", "user_id"=>"7-Jonathan-SpoonerJune", "video"=>{"password"=>"[FILTERED]", "email"=>"june@gmail.com"}}