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
# 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 |
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
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 |
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
# spec/spec_helper.rb | |
require "paperclip/matchers" | |
RSpec.configure do |config| | |
# | |
# etc... | |
# | |
# 追加 | |
config.include Paperclip::Shoulda::Matchers |
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
# 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 |
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
# app/models/user.rb | |
class User < ActiveRecord::Base | |
attr_accessible :avatar | |
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" } | |
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
# 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) |
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
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 |
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
#!/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 |
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 "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" |
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
# ==== 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: |