-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tammer Saleh
committed
Oct 15, 2009
1 parent
d73c4b4
commit 8e46aaa
Showing
292 changed files
with
35,216 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test-app |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
desc "Run all tests" | ||
task :default => [:test, "test:javascripts"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
include HoptoadNotifier::Catcher | ||
|
||
filter_parameter_logging :password, :password_confirmation | ||
helper_method :current_user_session, :current_user | ||
|
||
private | ||
|
||
def current_user_session | ||
return @current_user_session if defined?(@current_user_session) | ||
@current_user_session = UserSession.find | ||
end | ||
|
||
def current_user | ||
return @current_user if defined?(@current_user) | ||
@current_user = current_user_session && current_user_session.user | ||
end | ||
|
||
def require_user | ||
deny_access unless current_user | ||
end | ||
|
||
def require_no_user | ||
if current_user | ||
deny_access :redirect_to => root_url, | ||
:flash => "You must be logged out to access this page." | ||
end | ||
end | ||
|
||
def deny_access(opts = {}) | ||
opts[:flash] ||= "You must be logged in to access this page." | ||
opts[:redirect_to] ||= new_user_session_url | ||
|
||
store_location | ||
flash[:notice] = opts[:flash] | ||
redirect_to opts[:redirect_to] | ||
end | ||
|
||
def store_location | ||
session[:return_to] = request.request_uri | ||
end | ||
|
||
def redirect_back_or(url) | ||
redirect_to(session[:return_to] || url) | ||
session[:return_to] = nil | ||
end | ||
|
||
def interpolation_options | ||
{ :resource_name => resource.to_s } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class UserSessionsController < ApplicationController | ||
skip_before_filter :require_user, :only => [:new, :create] | ||
before_filter :require_no_user, :only => [:new, :create] | ||
|
||
def new | ||
@user = User.new | ||
@user_session = UserSession.new | ||
end | ||
|
||
def create | ||
@user_session = UserSession.new(params[:user_session]) | ||
if @user_session.save | ||
flash[:notice] = "Welcome, #{@user_session.user}" | ||
redirect_back_or root_url | ||
else | ||
@user = User.new | ||
render :action => "new" | ||
end | ||
end | ||
|
||
def destroy | ||
current_user_session.destroy | ||
flash[:notice] = "Good bye, #{current_user}." | ||
redirect_back_or new_user_session_url | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class UsersController < InheritedResources::Base | ||
skip_before_filter :require_user, :only => [:new, :create] | ||
before_filter :require_self, :except => [:new, :create, :show] | ||
|
||
actions :new, :create, :show, :edit, :update | ||
|
||
private | ||
|
||
def require_self | ||
unless current_user.id == params[:id].to_i | ||
deny_access(:flash => "You cannot access this page.", :redirect_to => root_url) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
def body_class | ||
"#{controller.controller_name} #{controller.controller_name}-#{controller.action_name}" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class User < ActiveRecord::Base | ||
acts_as_authentic do |config| | ||
config.validate_password_field = false | ||
config.validate_email_field = false | ||
end | ||
|
||
has_attached_file :photo, | ||
:storage => :s3, | ||
:bucket => "test-app", | ||
:path => ":class/:id/:attachment/:style.:extension", | ||
:default_url => "/images/default_:style_avatar.jpg", | ||
:default_style => :small, | ||
:styles => { :small => "64x64#", :medium => "128x128#" }, | ||
:s3_credentials => { :access_key_id => S3_KEY, | ||
:secret_access_key => S3_SECRET } | ||
|
||
validates_presence_of :password, :on => :create | ||
validates_confirmation_of :password, :if => :require_password? | ||
validates_presence_of :email | ||
validates_presence_of :name | ||
|
||
def to_s | ||
name | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class UserSession < Authlogic::Session::Base | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div id='flash'> | ||
<% flash.each do |key, value| %> | ||
<div id=<%= "flash_#{key}" %> class=<%="flash #{key}"%> > | ||
<%= h value %> | ||
</div> | ||
<% end %> | ||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<%= javascript_include_tag "jquery-1.3.2", "application", :cache => true %> | ||
<%= yield :javascript %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<% semantic_form_for @user_session, :url => user_session_path do |form| %> | ||
<% form.inputs :name => "Sign in!" do %> | ||
<%= form.input :email %> | ||
<%= form.input :password %> | ||
<%= form.input :remember_me, :as => :boolean %> | ||
<% end %> | ||
<% form.buttons do %> | ||
<%= form.commit_button "Login" %> | ||
<% end %> | ||
<% end %> | ||
|
||
<h2> | ||
Or <%= link_to "sign up for an account.", new_user_path %> | ||
</h2> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<% semantic_form_for @user, :html => {:multipart => true} do |form| %> | ||
<% form.inputs :name => "Credentials" do %> | ||
<%= form.input :name %> | ||
<%= form.input :email %> | ||
<%= form.input :password %> | ||
<%= form.input :password_confirmation %> | ||
<% end %> | ||
<% form.inputs :name => "Profile photo" do %> | ||
<%= form.input :photo, :type => "file" %> | ||
<% end %> | ||
<% form.buttons do %> | ||
<%= form.commit_button %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<% content_tag_for(:div, user) do %> | ||
<div class="user_name"> | ||
<%= h user.name %> | ||
</div> | ||
|
||
<div class='user_photo'> | ||
<%= image_tag(user.photo.url) %> | ||
</div> | ||
|
||
<% if user == current_user %> | ||
<div class='edit_profile_link'> | ||
<%= link_to "Edit profile", edit_user_path(user) %> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render :partial => 'form' %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render :partial => 'form' %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render :partial => @user %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Settings specified here will take precedence over those in config/environment.rb | ||
|
||
# We'd like to stay as close to prod as possible | ||
# Code is not reloaded between requests | ||
config.cache_classes = true | ||
|
||
# Full error reports are disabled and caching is turned on | ||
config.action_controller.consider_all_requests_local = false | ||
config.action_controller.perform_caching = true | ||
|
||
# Disable delivery errors if you bad email addresses should just be ignored | ||
config.action_mailer.raise_delivery_errors = false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ActionMailer::Base.smtp_settings = { | ||
:address => "smtp.thoughtbot.com", | ||
:port => 25, | ||
:domain => "thoughtbot.com" | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright (c) 2009 Michael Koziarski <michael@koziarski.com> | ||
# | ||
# Permission to use, copy, modify, and/or distribute this software for any | ||
# purpose with or without fee is hereby granted, provided that the above | ||
# copyright notice and this permission notice appear in all copies. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
||
require 'bigdecimal' | ||
|
||
alias BigDecimalUnsafe BigDecimal | ||
|
||
|
||
# This fixes CVE-2009-1904 however it removes legitimate functionality that your | ||
# application may depend on. You are *strongly* advised to upgrade your ruby | ||
# rather than relying on this fix for an extended period of time. | ||
|
||
def BigDecimal(initial, digits=0) | ||
if initial.size > 255 || initial =~ /e/i | ||
raise "Invalid big Decimal Value" | ||
end | ||
BigDecimalUnsafe(initial, digits) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'net/smtp' | ||
# Example: | ||
# begin | ||
# some http call | ||
# rescue *HTTP_ERRORS => error | ||
# notify_hoptoad error | ||
# end | ||
|
||
HTTP_ERRORS = [Timeout::Error, | ||
Errno::EINVAL, | ||
Errno::ECONNRESET, | ||
EOFError, | ||
Net::HTTPBadResponse, | ||
Net::HTTPHeaderSyntaxError, | ||
Net::ProtocolError] | ||
|
||
SMTP_SERVER_ERRORS = [TimeoutError, | ||
IOError, | ||
Net::SMTPUnknownError, | ||
Net::SMTPServerBusy, | ||
Net::SMTPAuthenticationError] | ||
|
||
SMTP_CLIENT_ERRORS = [Net::SMTPFatalError, | ||
Net::SMTPSyntaxError] | ||
|
||
SMTP_ERRORS = SMTP_SERVER_ERRORS + SMTP_CLIENT_ERRORS | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Set the default text field size when input is a string. Default is 50 | ||
Formtastic::SemanticFormBuilder.default_text_field_size = 20 | ||
|
||
# Should all fields be considered "required" by default | ||
# Defaults to true, see ValidationReflection notes below | ||
Formtastic::SemanticFormBuilder.all_fields_required_by_default = false | ||
|
||
# Set the string that will be appended to the labels/fieldsets which are required | ||
# It accepts string or procs and the default is a localized version of | ||
# '<abbr title="required">*</abbr>'. In other words, if you configure formtastic.required | ||
# in your locale, it will replace the abbr title properly. But if you don't want to use | ||
# abbr tag, you can simply give a string as below | ||
# Formtastic::SemanticFormBuilder.required_string = "(required)" | ||
|
||
# Set the string that will be appended to the labels/fieldsets which are optional | ||
# Defaults to an empty string ("") and also accepts procs (see required_string above) | ||
# Formtastic::SemanticFormBuilder.optional_string = "(optional)" | ||
|
||
# Set the way inline errors will be displayed. | ||
# Defaults to :sentence, valid options are :sentence, :list and :none | ||
# Formtastic::SemanticFormBuilder.inline_errors = :list | ||
|
||
# Set the method to call on label text to transform or format it for human-friendly | ||
# reading when formtastic is user without object. Defaults to :humanize. | ||
Formtastic::SemanticFormBuilder.label_str_method = :titleize | ||
|
||
# Set the array of methods to try calling on parent objects in :select and :radio inputs | ||
# for the text inside each @<option>@ tag or alongside each radio @<input>@. The first method | ||
# that is found on the object will be used. | ||
# Defaults to ["to_label", "display_name", "full_name", "name", "title", "username", "login", "value", "to_s"] | ||
Formtastic::SemanticFormBuilder.collection_label_methods = ["to_s"] | ||
|
||
# Formtastic by default renders inside li tags the input, hints and then | ||
# errors messages. Sometimes you want the hints to be rendered first than | ||
# the input, in the following order: hints, input and errors. You can | ||
# customize it doing just as below: | ||
# Formtastic::SemanticFormBuilder.inline_order = [:hints, :input, :errors] | ||
|
||
# Set the default "priority countries" to suit your user base when using :as => :country | ||
# Formtastic::SemanticFormBuilder.priority_countries = ["Australia", "New Zealand"] | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Rails 2 doesn't like mocks | ||
|
||
# This callback will run before every request to a mock in development mode, | ||
# or before the first server request in production. | ||
|
||
Rails.configuration.to_prepare do | ||
Dir[File.join(RAILS_ROOT, 'test', 'mocks', RAILS_ENV, '*.rb')].each do |f| | ||
load f | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ActiveRecord::Base.class_eval do | ||
def log_protected_attribute_removal(*attributes) | ||
raise "Can't mass-assign these protected attributes: #{attributes.join(', ')}" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Paperclip.options[:swallow_stderr] = false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'redcloth' | ||
|
||
Dir[File.join(RAILS_ROOT, 'lib', 'extensions', '*.rb')].each do |f| | ||
require f | ||
end | ||
|
||
Dir[File.join(RAILS_ROOT, 'lib', '*.rb')].each do |f| | ||
require f | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ :short_date => "%x", # 04/13/10 | ||
:long_date => "%a, %b %d, %Y" # Tue, Apr 13, 2010 | ||
}.each do |k, v| | ||
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(k => v) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ActionController::Routing::Routes.draw do |map| | ||
map.resource :user_session | ||
map.resources :users | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class CreateUsers < ActiveRecord::Migration | ||
def self.up | ||
create_table :users do |t| | ||
t.string :name | ||
t.string :email | ||
t.string :crypted_password | ||
t.string :password_salt | ||
t.string :persistence_token | ||
t.boolean :active, :default => true, :null => false | ||
t.timestamps | ||
end | ||
|
||
add_index :users, :active | ||
end | ||
|
||
def self.down | ||
drop_table :users | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
log/* | ||
tmp/**/* | ||
db/schema.rb | ||
db/*.sqlite3 | ||
public/system | ||
*.DS_Store | ||
coverage* | ||
*.swp | ||
tmp/restart.txt | ||
public/system | ||
|
||
!.keep |
Oops, something went wrong.