This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
require 'mocha' | |
class StatTest < ActiveSupport::TestCase | |
test "should belong to user" do | |
assert_kind_of User, stats(:one).user | |
end | |
test "should add error on user when validating with nil user" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WeblogController < ActionController::Base | |
# will render weblog/index.html.erb | |
# note for older versions it will be index.rhtml, but it's still erb | |
def index | |
# more code here | |
end | |
end | |
class AuthorsController < ActionController::Base | |
# will render authors.index.html.erb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'> | |
<head> | |
<title>Firsthand Web Design</title> | |
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' /> | |
<style type="text/css"> | |
div { | |
float: left | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CheckoutController | |
def new | |
checkout = ChecktoutContext.new | |
@order = checkout.order | |
end | |
end | |
class CheckoutContext | |
def initialize | |
@order = Order.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sandi Metz - Less - The Path to Better Design | |
# http://vimeo.com/26330100 | |
# http://less-goruco.heroku.com/ | |
# | |
# Abstractions are more stable than concretions. | |
class Trip | |
attr_reader :bicycles, :customers, :vehicle | |
def prepare(preparers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://tech.groups.yahoo.com/group/domaindrivendesign/message/6654 | |
class Target { | |
public void strike(missile) { | |
missile.setCoordinates(self.coordinates); | |
missile.launch(); | |
markDestroyed(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# Collaboration Rules | |
def can_like?(like) | |
user.plugins.include?(:page_like) | |
end | |
# Business Service | |
def like(page) | |
Like.create!(:page => page, :user => self) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SQL Antipatterns: http://pragprog.com/book/bksqla/sql-antipatterns | |
# A relationship between a model and a DAO like ActiveRecord should be HAS-A | |
# (aggregation) instead of (inheritance). Most frameworks that rely on | |
# ActiveRecord assume the IS-A solution. If you model uses DAOs instead of | |
# inheriting from the DAO class, then you can design the model to contain all | |
# data and code for the domain it's supposed to model--even if it takes | |
# multiple database tables to represent it. | |
# BugReport is a domain object encapsulating: | |
# * Bugs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## PayRoll gem | |
# lib/pay_roll.rb | |
module PayRoll | |
class << self | |
attr_accessor :employee_directory | |
def config | |
yield self | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RecycleApp | |
module RecycleApp | |
class << self | |
attr_accessor :can_repository | |
def config | |
yield self | |
end | |
end | |
end |
OlderNewer