Skip to content

Instantly share code, notes, and snippets.

View takuyan's full-sized avatar
🎯
Focusing

Takuya Kato / katton takuyan

🎯
Focusing
View GitHub Profile
# spec/factories/users.rb
include ActionDispatch::TestProcess # 追加
FactoryGirl.define do
factory :user do
name 'Takuya Kato'
avatar { fixture_file_upload("#{Rails.root}/spec/files/rails.png", "image/png") }
end
end
describe User do
it { should have_attached_file(:avatar) }
it { should validate_attachment_presence(:avatar) }
it { should validate_attachment_content_type(:avatar).
allowing('image/png', 'image/gif').
rejecting('text/plain', 'text/xml') }
it { should validate_attachment_size(:avatar).
less_than(2.megabytes) }
end
# spec/spec_helper.rb
require "paperclip/matchers"
RSpec.configure do |config|
#
# etc...
#
# 追加
config.include Paperclip::Shoulda::Matchers
# This will guess the User class
FactoryGirl.define do
factory :user do
first_name "John"
last_name "Doe"
admin false
end
# This will use the User class (Admin would have been guessed)
factory :admin, class: User do
# app/models/user.rb
class User < ActiveRecord::Base
attr_accessible :avatar
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }
end
# Create a root node:
science = Category.create!(name: 'Science')
# Put a new thing inside this root node:
physics = Category.create!(name: 'Physics')
physics.move_to_child_of(science)
# Put another thing inside the "physics" node:
gravity = Category.create!(name: 'Gravity')
gravity.move_to_child_of(physics)
sudo apt-get update
sudo apt-get install git
mkdir -p ~/tmp
cd ~/tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
tar -zxf ruby-1.9.3-p327.tar.gz
cd ruby-1.9.3-p327
./configure
make
sudo make install
@takuyan
takuyan / chef_solo_bootstrap.sh
Created November 12, 2012 02:17 — forked from ryanb/chef_solo_bootstrap.sh
Bootstrap Chef Solo
#!/usr/bin/env bash
sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
tar -xvzf ruby-1.9.3-p327.tar.gz
cd ruby-1.9.3-p327/
./configure --prefix=/usr/local
make
sudo make install
@takuyan
takuyan / partial_deploy.rb
Created November 1, 2012 11:13
partial deploy.rb for using rbenv with capistrano
require "bundler/capistrano"
set :default_environment, {
'RBENV_ROOT' => '$HOME/.rbenv',
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
set :bundle_flags, "--quiet --binstubs --shebang ruby-local-exec"
# ==== Examples
#
# Let's say you have an User model configured to use authenticatable,
# confirmable and recoverable modules. After creating this inside your routes:
#
devise_for :users
#
# This method is going to look inside your User model and create the
# needed routes: