Skip to content

Instantly share code, notes, and snippets.

@shouichi
Last active December 10, 2015 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shouichi/4484039 to your computer and use it in GitHub Desktop.
Save shouichi/4484039 to your computer and use it in GitHub Desktop.
/.bundle
/db/*.sqlite3
/doc
/log
/public/assets
/tmp
/vendor/assets/components
rvm 1.9.3@puriketsu --create

Overview

Development

Environment Variables

TWITTER_KEY=
TWITTER_SECRET=
FACEBOOK_APP_ID=
FACEBOOK_APP_SECRET=
FOURSQUARE_CLIENT_ID=
FOURSQUARE_CLIENT_SECRET=
FOURSQUARE_PUSH_SECRET=

Facebook Permissions

See this.

Realtime Updates

For object 'user', we set following fields birthday, checkins, current_location, events, feed, friends, hometown, hometown_location, interests, likes, link, locale, location, photos, pic, picture, status, statuses, website

Running Tests

% bundle exec spork
% bundle exec guard

External Javascripts and Stylesheets

External dependencies such as js/css are defined in vendor/assets/component.json. To retrieve them run following commands.

% cd vendor/assets
% bower install
= simple_form_for @admin, url: (@admin.new_record? ? admins_admins_path : admins_admin_path(@admin)), html: { class: 'form-horizontal' } do |f|
= f.input :email
= f.input :password
= f.input :password_confirmation
.form-actions
= f.button :submit, class: 'btn-primary'
= link_to t('helpers.links.cancel'), admins_admins_path, class: 'btn'
= simple_form_for(@<%= singular_table_name %>) do |f|
= f.error_notification
.form-inputs
<%- attributes.each do |attribute| -%>
= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>
<%- end -%>
.form-actions
= f.button :submit
!!! 5
%html(lang='ja')
%head
%meta(charset='utf-8')
%meta(http-equiv='X-UA-Compatible' content='IE=Edge,chrome=1')
%meta(name='viewport' content='width=device-width, initial-scale=1.0')
%title= content_for?(:title) ? yield(:title) : t('helpers.titles.application')
= csrf_meta_tags
/[if lt IE 9]
= javascript_include_tag 'http://html5shim.googlecode.com/svn/trunk/html5.js'
= stylesheet_link_tag :admins, media: :all
= favicon_link_tag
%body
.navbar.navbar-fixed-top.navbar-inverse
.navbar-inner
.container
%a.btn.btn-navbar(data-target='.nav-collapse' data-toggle='collapse')
%span.icon-bar
%span.icon-bar
%span.icon-bar
%a.brand(href='#{admins_root_path}')= t 'helpers.titles.application'
.nav-collapse.collapse
%ul.nav
%li
%a(href='#{admins_admins_path}')= Admin.model_name.human
.pull-right
%ul.nav
%li
%a(href='#{admins_admin_path current_admin}')
%i.icon-user
%li
%a(href='#{admins_logout_path}' data-method='post')
%i.icon-off
.container
= yield
%hr
%footer
%p &copy; Lambda Engineering #{Time.now.year}
= javascript_include_tag 'application'
class Admin
include Mongoid::Document
include Mongoid::Timestamps
include Authentication::Model
field :email, type: String
end
FactoryGirl.define do
factory :admin do
sequence(:email) { |n| "admin#{n}@admin.com" }
password 'password'
end
end
require 'spec_helper'
describe Admin do
it 'default factory should be valid' do
admin = FactoryGirl.build :admin
admin.should be_valid
end
describe 'email' do
it 'can not be blank' do
admin = FactoryGirl.build :admin, email: nil
admin.should_not be_valid
admin.should have(2).error_on(:email)
end
it 'can not be invalid format' do
admin = FactoryGirl.build :admin, email: 'foobar'
admin.should_not be_valid
admin.should have(1).error_on(:email)
end
end
describe 'authentication' do
before :each do
@password = 'password'
@admin = FactoryGirl.create :admin, password: @password
end
it 'should return admin instance with valid email/password' do
admin = Admin.authenticate email: @admin.email, password: @password
admin.should == @admin
end
it 'should return nil with invalid email' do
admin = Admin.authenticate email: 'imaginary@imaginary.com', password: @password
admin.should be_nil
end
it 'should return nil with invalid password' do
admin = Admin.authenticate email: @admin.email, password: 'invalid'
admin.should be_nil
end
end
end
/*
*= require_self
*= require ./bootstrap_and_overrides
*= require_tree ./admins
*/
module Admins
class AdminsController < ApplicationController
def index
@admins = Admin.all
end
def show
@admin = Admin.find params[:id]
end
def new
@admin = Admin.new
end
def edit
@admin = Admin.find params[:id]
end
def create
@admin = Admin.new params[:admin]
if @admin.save
redirect_to admins_admin_path(@admin)
else
render :edit
end
end
def update
@admin = Admin.find params[:id]
if @admin.update_attributes params[:admin]
redirect_to admins_admin_path(@admin)
else
render :edit
end
end
def destroy
@admin = Admin.find params[:id]
@admin.destroy
redirect_to admins_admins_path
end
end
end
!!! 5
%html(lang='ja')
%head
%meta(charset='utf-8')
%meta(http-equiv='X-UA-Compatible' content='IE=Edge,chrome=1')
%meta(name='viewport' content='width=device-width, initial-scale=1.0')
%title= content_for?(:title) ? yield(:title) : t('helpers.titles.application')
= csrf_meta_tags
/[if lt IE 9]
= javascript_include_tag 'http://html5shim.googlecode.com/svn/trunk/html5.js'
= stylesheet_link_tag :users, media: :all
= favicon_link_tag
%body
.navbar.navbar-fixed-top
.navbar-inner
.container
%a.btn.btn-navbar(data-target='.nav-collapse' data-toggle='collapse')
%span.icon-bar
%span.icon-bar
%span.icon-bar
%a.brand(href='#{home_path}')= t 'helpers.titles.application'
.nav-collapse.collapse
%ul.nav
%li= link_to t('helpers.titles.home'), home_path
%li= link_to Credential.model_name.human, credentials_path
.pull-right
%ul.nav
%li
%a(href='#{user_path current_user}')
%i.icon-user
%li
%a(href='#{logout_path}' data-method='post')
%i.icon-off
.container
= yield
.navbar.navbar-fixed-bottom
.container
.pull-right
%ul.nav
%li= link_to t('helpers.titles.home'), home_path
%li= link_to Credential.model_name.human, credentials_path
= javascript_include_tag 'application'
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require twitter/bootstrap
//= require_tree .
require File.expand_path('../boot', __FILE__)
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(assets: %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module PuriketsuRails
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W(#{config.root}/lib)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.default_locale = :ja
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
end
module Admins
class ApplicationController < ActionController::Base
include Authentication::Controller::Admin
layout 'admin'
protect_from_forgery
end
end
module Api
module V1
class ApplicationController < ActionController::Base
include Authentication::Controller::User
protect_from_forgery
end
end
end
class ApplicationController < ActionController::Base
include Authentication::Controller::User
protect_from_forgery
end
require 'spec_helper'
describe Admins::ApplicationController do
end
module ApplicationHelper
APPLICATION_NAME = I18n.t 'helpers.titles.application'
# Set page title by concatenating argments by ' | ' with application name prefix.
# Example:
# title 'admins', 'index' #=> 'APPLICATION_NAME | admins | index'
def title(*titles)
content_for :title do
[APPLICATION_NAME, *titles].join(' | ')
end
end
end
module Authentication
module Model
attr_accessor :password
def self.included(base)
base.instance_eval do
attr_protected :encrypted_password, :password_salt
field :email, type: String
field :encrypted_password, type: String
field :password_salt, type: String
validates :email, presence: true, uniqueness: true, format: /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
validates :password, presence: { on: :create }, confirmation: true, length: { minimum: 5, allow_blank: true }
before_save :prepare_password
extend ClassMethods
include InstanceMethods
end
end
module ClassMethods
def authenticate(params)
email, password = params[:email], params[:password]
model = find_by(email: email)
model if model && model.matching_password?(password)
end
end
module InstanceMethods
def matching_password?(password)
self.encrypted_password == encrypt_password(password)
end
private
def prepare_password
if password.present?
self.password_salt = BCrypt::Engine.generate_salt
self.encrypted_password = encrypt_password(password)
end
end
def encrypt_password(password)
BCrypt::Engine.hash_secret(password, password_salt)
end
end
end
module Controller
module Common
def redirect_to_target_or_default(default, options = {})
redirect_to(session[:return_to] || default, options)
session[:return_to] = nil
end
def login_required(redirect_path)
unless logged_in?
flash[:error] = t('flash.error.login_required')
session[:return_to] = request.fullpath
redirect_to redirect_path
end
end
end
module Admin
include ::Authentication::Controller::Common
def self.included(base)
base.instance_eval do
before_filter :login_required
helper_method :current_admin, :logged_in?, :redirect_to_target_or_default
end
end
def login_required
super admins_login_path
end
def current_admin
@current_admin ||= ::Admin.find(session[:admin_id]) if session[:admin_id]
end
def logged_in?
current_admin
end
end
module User
include ::Authentication::Controller::Common
def self.included(base)
base.instance_eval do
before_filter :login_required
helper_method :current_user, :logged_in?, :redirect_to_target_or_default
end
end
def login_required
super login_path
end
def current_user
@current_user ||= ::User.find(session[:user_id]) if session[:user_id]
end
def logged_in?
current_user
end
end
end
end
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
jQuery ->
$("a[rel=popover]").popover()
$(".tooltip").tooltip()
$("a[rel=tooltip]").tooltip()
/*
*= require twitter-bootstrap-static/bootstrap
*= require twitter-bootstrap-static/fontawesome
*/
body {
padding-top: 60px;
}
@media (max-width: 979px) {
body {
padding-top: 0;
}
}
load 'deploy'
load 'deploy/assets'
load 'config/deploy'
{
"dependencies": {
}
}
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run PuriketsuRails::Application
class Credential
include Mongoid::Document
include Mongoid::Timestamps
field :uid, type: Integer
field :nickname, type: String
belongs_to :user
scope :twitter, where(_type: 'TwitterCredential')
scope :facebook, where(_type: 'FacebookCredential')
validates :_type, presence: true, inclusion: { in: %w(TwitterCredential FacebookCredential FoursquareCredential) }
validates :user_id, presence: true
validates :uid, presence: true, uniqueness: { scope: %w(_type user_id) }
validates :nickname, presence: true
end
class CredentialsController < ApplicationController
def index
@credentials = current_user.credentials
end
def create
klass = "#{params[:provider].camelize}Credential".constantize
@credential = klass.build_from_user_and_auth current_user, request.env['omniauth.auth']
@credential.save
redirect_to credentials_path
end
def destroy
@credential = current_user.credentials.find params[:id]
@credential.destroy
redirect_to credentials_path
end
def failure
end
end
require 'spec_helper'
describe CredentialsController do
context 'when not logged-in' do
it 'GET welcome should redirect to login_path' do
get :index
response.should redirect_to(login_path)
end
end
end
require 'capistrano_colors'
require 'bundler/capistrano'
require 'capistrano/ext/multistage'
set :application, 'Puriketsu'
set :deploy_to, '/Users/kamiya/tmp/puriketsu'
set :scm, :git
set :repository, 'git@gist.github.com:32499bae16f6474caf87.git'
set :rails_env, :production
set :bundle_without, %w(development test)
# SSH
set :user, 'kamiya'
set :user_group, 'staff'
set :port, 22
set :use_sudo, false
# RVM
set :rvm_type, :user
set :rvm_ruby_string, '1.9.3@puriketsu'
require 'rvm/capistrano'
before 'deploy:setup', 'rvm:install_rvm'
before 'deploy:setup', 'rvm:install_ruby'
before 'deploy:setup', 'rvm:create_gemset'
# Others
set :normalize_asset_timestamps, false
# Server
require 'capistrano-unicorn'
after 'deploy:restart', 'unicorn:reload'
after 'deploy:restart', 'unicorn:restart'
PuriketsuRails::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload)
end
Admin.create(email: 'shouichi.kamiya@gmail.com', password: 'foobar')
User.create(email: 'shouichi.kamiya@gmail.com', password: 'foobar')
- title t('.title'), @admin.email
.page-header
%h1= t '.title'
= render :partial => 'form'
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
PuriketsuRails::Application.initialize!
module Api
module V1
class FacebookController < ApplicationController
def index
render text: params['hub.challenge']
end
def create
end
end
end
end
class FacebookCredential < Credential
field :token, type: String
validates :token, presence: true
def self.build_from_user_and_auth(user, auth)
find_by(user: user, uid: auth.uid) ||
new(user: user, token: auth.credentials.token, uid: auth.uid, nickname: auth.info.nickname)
end
end
FactoryGirl.define do
factory :facebook_credential do
association :user, factory: :user
sequence(:uid) { |n| n }
nickname 'nickname'
token 'token'
end
end
require 'spec_helper'
describe FacebookCredential do
it 'default factory should be valid' do
facebook_credential = FactoryGirl.build :facebook_credential
facebook_credential.should be_valid
end
it 'user_id cannot be empty' do
facebook_credential = FactoryGirl.build :facebook_credential, user_id: nil
facebook_credential.should_not be_valid
facebook_credential.should have(1).error_on(:user_id)
end
it 'uid cannot be empty' do
facebook_credential = FactoryGirl.build :facebook_credential, uid: nil
facebook_credential.should_not be_valid
facebook_credential.should have(1).error_on(:uid)
end
it 'nickname cannot be empty' do
facebook_credential = FactoryGirl.build :facebook_credential, nickname: nil
facebook_credential.should_not be_valid
facebook_credential.should have(1).error_on(:nickname)
end
it 'token cannot be empty' do
facebook_credential = FactoryGirl.build :facebook_credential, token: nil
facebook_credential.should_not be_valid
facebook_credential.should have(1).error_on(:token)
end
it 'uid should be unique in scope of user' do
facebook_credential = FactoryGirl.create :facebook_credential
facebook_credential = FactoryGirl.build :facebook_credential,
user: facebook_credential.user, uid: facebook_credential.uid
facebook_credential.should have(1).error_on(:uid)
end
it 'uid can be same if user_ids are different' do
facebook_credential = FactoryGirl.create :facebook_credential
facebook_credential = FactoryGirl.create :facebook_credential,
uid: facebook_credential.uid
facebook_credential.should be_valid
end
end
module Api
module V1
class FoursquareController < ApplicationController
def index
end
def create
end
end
end
end
class FoursquareCredential < Credential
field :token, type: String
validates :token, presence: true
def self.build_from_user_and_auth(user, auth)
find_by(user: user, uid: auth.uid) ||
new(user: user, token: auth.credentials.token, uid: auth.uid, nickname: "#{auth.info.first_name} #{auth.info.last_name}")
end
end
FactoryGirl.define do
factory :foursquare_credential do
association :user, factory: :user
sequence(:uid) { |n| n }
nickname 'nickname'
token 'token'
end
end
require 'spec_helper'
describe FoursquareCredential do
it 'default factory should be valid' do
foursquare_credential = FactoryGirl.build :foursquare_credential
foursquare_credential.should be_valid
end
it 'user_id cannot be empty' do
foursquare_credential = FactoryGirl.build :foursquare_credential, user_id: nil
foursquare_credential.should_not be_valid
foursquare_credential.should have(1).error_on(:user_id)
end
it 'uid cannot be empty' do
foursquare_credential = FactoryGirl.build :foursquare_credential, uid: nil
foursquare_credential.should_not be_valid
foursquare_credential.should have(1).error_on(:uid)
end
it 'nickname cannot be empty' do
foursquare_credential = FactoryGirl.build :foursquare_credential, nickname: nil
foursquare_credential.should_not be_valid
foursquare_credential.should have(1).error_on(:nickname)
end
it 'token cannot be empty' do
foursquare_credential = FactoryGirl.build :foursquare_credential, token: nil
foursquare_credential.should_not be_valid
foursquare_credential.should have(1).error_on(:token)
end
it 'uid should be unique in scope of user' do
foursquare_credential = FactoryGirl.create :foursquare_credential
foursquare_credential = FactoryGirl.build :foursquare_credential,
user: foursquare_credential.user, uid: foursquare_credential.uid
foursquare_credential.should have(1).error_on(:uid)
end
it 'uid can be same if user_ids are different' do
foursquare_credential = FactoryGirl.create :foursquare_credential
foursquare_credential = FactoryGirl.create :foursquare_credential,
uid: foursquare_credential.uid
foursquare_credential.should be_valid
end
end
source 'https://rubygems.org'
gem 'rails'
gem 'mongoid'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder'
gem 'haml-rails'
gem 'simple_form'
gem 'foreman'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem 'omniauth-foursquare'
gem 'bcrypt-ruby', require: 'bcrypt'
group :assets do
gem 'sprockets-rails'
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'
gem 'twitter-bootstrap-rails'
end
group :development do
gem 'pry-rails'
gem 'capistrano'
gem 'capistrano-ext'
gem 'capistrano_colors'
gem 'capistrano-unicorn'
gem 'rvm-capistrano'
gem 'thin'
gem 'rack-livereload'
gem 'guard-livereload'
gem 'koala'
gem 'twitter'
gem 'foursquare2'
end
group :test do
gem 'rspec-rails'
gem 'guard-rspec'
gem 'guard-spork'
gem 'rb-fsevent'
gem 'factory_girl'
gem 'database_cleaner'
end
group :production do
gem 'unicorn'
end
GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.9)
actionpack (= 3.2.9)
mail (~> 2.4.4)
actionpack (3.2.9)
activemodel (= 3.2.9)
activesupport (= 3.2.9)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.2.1)
activemodel (3.2.9)
activesupport (= 3.2.9)
builder (~> 3.0.0)
activerecord (3.2.9)
activemodel (= 3.2.9)
activesupport (= 3.2.9)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.9)
activemodel (= 3.2.9)
activesupport (= 3.2.9)
activesupport (3.2.9)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.3.2)
arel (3.0.2)
bcrypt-ruby (3.0.1)
builder (3.0.4)
capistrano (2.13.5)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
capistrano-ext (1.2.1)
capistrano (>= 1.0.0)
capistrano-unicorn (0.1.6)
capistrano
capistrano_colors (0.5.5)
childprocess (0.3.6)
ffi (~> 1.0, >= 1.0.6)
coderay (1.0.8)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.4.0)
daemons (1.1.9)
database_cleaner (0.9.1)
diff-lcs (1.1.3)
em-websocket (0.3.8)
addressable (>= 2.1.1)
eventmachine (>= 0.12.9)
erubis (2.7.0)
eventmachine (1.0.0)
execjs (1.4.0)
multi_json (~> 1.0)
factory_girl (4.1.0)
activesupport (>= 3.0.0)
faraday (0.8.4)
multipart-post (~> 1.1)
faraday_middleware (0.9.0)
faraday (>= 0.7.4, < 0.9)
ffi (1.2.0)
foreman (0.60.2)
thor (>= 0.13.6)
foursquare2 (1.9.1)
faraday (~> 0.8)
faraday_middleware (>= 0.8)
hashie (~> 1.0)
guard (1.6.0)
listen (>= 0.6.0)
lumberjack (>= 1.0.2)
pry (>= 0.9.10)
thor (>= 0.14.6)
guard-livereload (1.1.3)
em-websocket (>= 0.2.0)
guard (>= 1.5.0)
multi_json (~> 1.0)
guard-rspec (2.3.3)
guard (>= 1.1)
rspec (~> 2.11)
guard-spork (1.4.0)
childprocess (>= 0.2.3)
guard (>= 1.1)
spork (>= 0.8.4)
haml (3.1.7)
haml-rails (0.3.5)
actionpack (>= 3.1, < 4.1)
activesupport (>= 3.1, < 4.1)
haml (~> 3.1)
railties (>= 3.1, < 4.1)
hashie (1.2.0)
highline (1.6.15)
hike (1.2.1)
httpauth (0.2.0)
i18n (0.6.1)
jbuilder (0.9.1)
activesupport (>= 3.0.0)
journey (1.0.4)
jquery-rails (2.1.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.7.5)
jwt (0.1.5)
multi_json (>= 1.0)
kgio (2.7.4)
koala (1.6.0)
addressable (~> 2.2)
faraday (~> 0.8)
multi_json (~> 1.3)
listen (0.6.0)
lumberjack (1.0.2)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.8.1)
mime-types (1.19)
mongoid (3.0.15)
activemodel (~> 3.1)
moped (~> 1.1)
origin (~> 1.0)
tzinfo (~> 0.3.22)
moped (1.3.1)
multi_json (1.5.0)
multipart-post (1.1.5)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
net-ssh (>= 2.0.9)
net-ssh (2.6.2)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
oauth (0.4.7)
oauth2 (0.8.0)
faraday (~> 0.8)
httpauth (~> 0.1)
jwt (~> 0.1.4)
multi_json (~> 1.0)
rack (~> 1.2)
omniauth (1.1.1)
hashie (~> 1.2)
rack
omniauth-facebook (1.4.1)
omniauth-oauth2 (~> 1.1.0)
omniauth-foursquare (0.0.8)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.0)
omniauth-oauth (1.0.1)
oauth
omniauth (~> 1.0)
omniauth-oauth2 (1.1.1)
oauth2 (~> 0.8.0)
omniauth (~> 1.0)
omniauth-twitter (0.0.14)
multi_json (~> 1.3)
omniauth-oauth (~> 1.0)
origin (1.0.11)
polyglot (0.3.3)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
pry-rails (0.2.2)
pry (>= 0.9.10)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-livereload (0.3.10)
rack
rack-ssl (1.3.2)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.9)
actionmailer (= 3.2.9)
actionpack (= 3.2.9)
activerecord (= 3.2.9)
activeresource (= 3.2.9)
activesupport (= 3.2.9)
bundler (~> 1.0)
railties (= 3.2.9)
railties (3.2.9)
actionpack (= 3.2.9)
activesupport (= 3.2.9)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
raindrops (0.10.0)
rake (10.0.3)
rb-fsevent (0.9.2)
rdoc (3.12)
json (~> 1.4)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.1)
rspec-rails (2.12.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rvm-capistrano (1.2.7)
capistrano (>= 2.0.0)
sass (3.2.4)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
simple_form (2.0.4)
actionpack (~> 3.0)
activemodel (~> 3.0)
simple_oauth (0.2.0)
slop (3.3.3)
spork (0.9.2)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (0.0.1)
sprockets (>= 1.0.2)
thin (1.5.0)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
turbolinks (0.6.1)
coffee-rails
twitter (4.4.2)
faraday (~> 0.8)
multi_json (~> 1.3)
simple_oauth (~> 0.2)
twitter-bootstrap-rails (2.1.9)
actionpack (>= 3.1)
execjs
railties (>= 3.1)
tzinfo (0.3.35)
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
unicorn (4.5.0)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
PLATFORMS
ruby
DEPENDENCIES
bcrypt-ruby
capistrano
capistrano-ext
capistrano-unicorn
capistrano_colors
coffee-rails
database_cleaner
factory_girl
foreman
foursquare2
guard-livereload
guard-rspec
guard-spork
haml-rails
jbuilder
jquery-rails
koala
mongoid
omniauth-facebook
omniauth-foursquare
omniauth-twitter
pry-rails
rack-livereload
rails
rb-fsevent
rspec-rails
rvm-capistrano
sass-rails
simple_form
sprockets-rails
thin
turbolinks
twitter
twitter-bootstrap-rails
uglifier
unicorn
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
require 'active_support/inflector'
guard 'rspec', cli: '--drb', rspec_env: { RAILS_ENV: 'test' }, all_after_pass: false, all_on_start: false do
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
watch('app/controllers/admins/application_controller.rb') { "spec/controllers/admins" }
watch('app/controllers/api/v1/application_controller.rb') { "spec/controllers/api/v1" }
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^spec/factories/(.+)_factory\.rb$}) { |m| ["app/models/#{m[1].singularize}.rb", "spec/models/#{m[1].singularize}_spec.rb"] }
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)\.haml$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^app/controllers/admins/(.+)_(controller)\.rb$}) { |m| ["spec/routing/admins/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/admins/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^app/controllers/api/v1/(.+)_(controller)\.rb$}) { |m| ["spec/routing/api/v1/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/api/v1/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
end
guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html))).*}) { |m| "/assets/#{m[3]}" }
end
class HomeController < ApplicationController
def index
end
end
- title t('.title')
.page-header
%h1= t '.title'
%table.table.table-striped
%thead
%tr
%th= Admin.human_attribute_name(:email)
%th= t 'helpers.actions'
%tbody
- @admins.each do |admin|
%tr
%td= link_to admin.email, admins_admin_path(admin)
%td
= link_to t('helpers.links.edit'), edit_admins_admin_path(admin), class: 'btn btn-small'
= link_to t('helpers.links.destroy'), admins_admin_path(admin), method: :delete, data: { confirm: t('helpers.links.confirm') }, class: 'btn btn-small btn-danger'
= link_to t('helpers.links.new'), new_admins_admin_path, class: 'btn btn-primary'
%h4 Available Social Medium
%ul(data-no-turbolink)
%li= link_to 'Twitter', auth_twitter_path
%li= link_to 'Facebook', auth_facebook_path
%li= link_to 'Foursquare', auth_foursquare_path
%h4 Linked Social Medium
%ul(data-no-turbolink)
- @credentials.each do |credential|
%li= credential
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
#
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.acronym 'RESTful'
# end
ja:
date:
abbr_day_names:
- 日
- 月
- 火
- 水
- 木
- 金
- 土
abbr_month_names:
-
- 1月
- 2月
- 3月
- 4月
- 5月
- 6月
- 7月
- 8月
- 9月
- 10月
- 11月
- 12月
day_names:
- 日曜日
- 月曜日
- 火曜日
- 水曜日
- 木曜日
- 金曜日
- 土曜日
formats:
default: ! '%Y/%m/%d'
long: ! '%Y年%m月%d日(%a)'
short: ! '%m/%d'
month_names:
-
- 1月
- 2月
- 3月
- 4月
- 5月
- 6月
- 7月
- 8月
- 9月
- 10月
- 11月
- 12月
order:
- :year
- :month
- :day
datetime:
distance_in_words:
about_x_hours:
one: 約1時間
other: 約%{count}時間
about_x_months:
one: 約1ヶ月
other: 約%{count}ヶ月
about_x_years:
one: 約1年
other: 約%{count}年
almost_x_years:
one: 1年弱
other: ! '%{count}年弱'
half_a_minute: 30秒前後
less_than_x_minutes:
one: 1分以内
other: ! '%{count}分以内'
less_than_x_seconds:
one: 1秒以内
other: ! '%{count}秒以内'
over_x_years:
one: 1年以上
other: ! '%{count}年以上'
x_days:
one: 1日
other: ! '%{count}日'
x_minutes:
one: 1分
other: ! '%{count}分'
x_months:
one: 1ヶ月
other: ! '%{count}ヶ月'
x_seconds:
one: 1秒
other: ! '%{count}秒'
prompts:
day: 日
hour: 時
minute: 分
month: 月
second: 秒
year: 年
errors: &errors
format: ! '%{attribute}%{message}'
messages:
accepted: を受諾してください。
blank: を入力してください。
confirmation: と確認の入力が一致しません。
empty: を入力してください。
equal_to: は%{count}にしてください。
even: は偶数にしてください。
exclusion: は予約されています。
greater_than: は%{count}より大きい値にしてください。
greater_than_or_equal_to: は%{count}以上の値にしてください。
inclusion: は一覧にありません。
invalid: は不正な値です。
less_than: は%{count}より小さい値にしてください。
less_than_or_equal_to: は%{count}以下の値にしてください。
not_a_number: は数値で入力してください。
not_an_integer: は整数で入力してください。
odd: は奇数にしてください。
record_invalid: バリデーションに失敗しました。 %{errors}
taken: はすでに存在します。
too_long: は%{count}文字以内で入力してください。
too_short: は%{count}文字以上で入力してください。
wrong_length: は%{count}文字で入力してください。
template:
body: 次の項目を確認してください。
header:
one: ! '%{model}にエラーが発生しました。'
other: ! '%{model}に%{count}個のエラーが発生しました。'
helpers:
actions: 機能
select:
prompt: 選択してください。
submit:
create: 登録する
submit: 保存する
update: 更新する
links:
new: 新規
edit: 編集
back: 戻る
cancel: キャンセル
destroy: 削除
confirm: 本当に良いですか?
titles:
application: ぷりけつ
home: ホーム
new: 新規
edit: 編集
number:
currency:
format:
delimiter: ! ','
format: ! '%n%u'
precision: 0
separator: .
significant: false
strip_insignificant_zeros: false
unit: 円
format:
delimiter: ! ','
precision: 3
separator: .
significant: false
strip_insignificant_zeros: false
human:
decimal_units:
format: ! '%n %u'
units:
billion: 十億
million: 百万
quadrillion: 千兆
thousand: 千
trillion: 兆
unit: ''
format:
delimiter: ''
precision: 3
significant: true
strip_insignificant_zeros: true
storage_units:
format: ! '%n%u'
units:
byte: バイト
gb: ギガバイト
kb: キロバイト
mb: メガバイト
tb: テラバイト
percentage:
format:
delimiter: ''
precision:
format:
delimiter: ''
support:
array:
last_word_connector: と
two_words_connector: と
words_connector: と
time:
am: 午前
formats:
default: ! '%Y/%m/%d %H:%M:%S'
long: ! '%Y年%m月%d日(%a) %H時%M分%S秒 %z'
short: ! '%y/%m/%d %H:%M'
pm: 午後
activemodel:
errors:
<<: *errors
mongoid:
errors:
<<: *errors
models:
admin: 管理者
user: 利用者
credential: 認証
attributes:
admin:
email: メールアドレス
flash:
error:
login_required: ログインして下さい。
notice:
sessions:
error: メールアドレス・パスワードが違います。
sessions:
new:
heading: ようこそ
submit: ログイン
admins:
sessions:
new:
heading: 管理画面
submit: ログイン
admins:
index:
title: 管理者一覧
show:
title: 管理者詳細
new:
title: 管理者新規
edit:
title: 管理者編集
/*
*= require ./bootstrap_and_overrides
*/
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}
.form-login {
max-width: 400px;
padding: 19px 29px 29px;
margin: 0 auto 20px;
background-color: #fff;
border: 1px solid #e5e5e5;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.form-login .form-login-heading,
.form-login .checkbox {
text-align: center;
margin-bottom: 10px;
}
.form-login input[type="email"],
.form-login input[type="password"] {
font-size: 16px;
height: auto;
margin-bottom: 15px;
padding: 7px 9px;
}
.form-login input[type="submit"] {
width: 100%;
}
.footer {
text-align: center;
}
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
Mongoid.raise_not_found_error = false
development:
# Configure available database sessions. (required)
sessions:
# Defines the default session. (required)
default:
# Defines the name of the default database that Mongoid can connect to.
# (required).
database: puriketsu_development
# Provides the hosts the default session can connect to. Must be an array
# of host:port pairs. (required)
hosts:
- localhost:27017
options:
# Change whether the session persists in safe mode by default.
# (default: false)
# safe: false
# Change the default consistency model to :eventual or :strong.
# :eventual will send reads to secondaries, :strong sends everything
# to master. (default: :eventual)
# consistency: :eventual
# How many times Moped should attempt to retry an operation after
# failure. (default: 30)
# max_retries: 30
# The time in seconds that Moped should wait before retrying an
# operation on failure. (default: 1)
# retry_interval: 1
# Configure Mongoid specific options. (optional)
options:
# Configuration for whether or not to allow access to fields that do
# not have a field definition on the model. (default: true)
# allow_dynamic_fields: true
# Enable the identity map, needed for eager loading. (default: false)
# identity_map_enabled: false
# Includes the root model name in json serialization. (default: false)
# include_root_in_json: false
# Include the _type field in serializaion. (default: false)
# include_type_for_serialization: false
# Preload all models in development, needed when models use
# inheritance. (default: false)
# preload_models: false
# Protect id and type from mass assignment. (default: true)
# protect_sensitive_fields: true
# Raise an error when performing a #find and the document is not found.
# (default: true)
# raise_not_found_error: true
# Raise an error when defining a scope with the same name as an
# existing method. (default: false)
# scope_overwrite_exception: false
# Skip the database version check, used when connecting to a db without
# admin access. (default: false)
# skip_version_check: false
# User Active Support's time zone in conversions. (default: true)
# use_activesupport_time_zone: true
# Ensure all times are UTC in the app side. (default: false)
# use_utc: false
test:
sessions:
default:
database: puriketsu_test
hosts:
- localhost:27017
options:
consistency: :strong
# In the test environment we lower the retries and retry interval to
# low amounts for fast failures.
max_retries: 1
retry_interval: 0
production:
sessions:
default:
database: puriketsu_production
hosts:
- localhost:27017
- title t('.title')
.page-header
%h1= t '.title'
= render :partial => "form"
!!! 5
%html(lang='ja')
%head
%meta(charset='utf-8')
%meta(http-equiv='X-UA-Compatible' content='IE=Edge,chrome=1')
%meta(name='viewport' content='width=device-width, initial-scale=1.0')
%title= content_for?(:title) ? yield(:title) : t('helpers.titles.application')
= csrf_meta_tags
/[if lt IE 9]
= javascript_include_tag 'http://html5shim.googlecode.com/svn/trunk/html5.js'
= stylesheet_link_tag :login, media: :all
= favicon_link_tag
%body
.container
= simple_form_for @admin, url: admins_login_path, wrapper: :simplest, html: { class: 'form-login' } do |f|
- if flash[:error]
.alert.alert-error= flash[:error]
%h2.form-login-heading= t '.heading'
= f.input :email, input_html: { class: 'input-block-level', autofocus: true }
= f.input :password, input_html: { class: 'input-block-level' }
= f.button :submit, t('.submit')
%hr
.footer
%p &copy; Lambda Engineering Inc. #{Time.now.year}
!!! 5
%html(lang='ja')
%head
%meta(charset='utf-8')
%meta(http-equiv='X-UA-Compatible' content='IE=Edge,chrome=1')
%meta(name='viewport' content='width=device-width, initial-scale=1.0')
%title= content_for?(:title) ? yield(:title) : t('helpers.titles.application')
= csrf_meta_tags
/[if lt IE 9]
= javascript_include_tag 'http://html5shim.googlecode.com/svn/trunk/html5.js'
= stylesheet_link_tag :login, media: :all
= favicon_link_tag
%body
.container
= simple_form_for @user, url: login_path, wrapper: :simplest, html: { class: 'form-login' } do |f|
- if flash[:error]
.alert.alert-error= flash[:error]
%h2.form-login-heading= t '.heading'
= f.input :email, input_html: { class: 'input-block-level', autofocus: true }
= f.input :password, input_html: { class: 'input-block-level' }
= f.button :submit, t('.submit')
%hr
.footer
%p &copy; Lambda Engineering Inc. #{Time.now.year}
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'],
scope: %w(email
read_friendlists
read_stream publish_stream
user_birthday friends_birthday
user_checkins friends_checkins
user_hometown friends_hometown
user_location friends_location
user_events friends_events
user_likes friends_likes
user_website friends_website
user_photos friends_photos
user_groups friends_groups
user_interests friends_interests
user_status friends_status
user_photo_video_tags friends_photo_video_tags
user_work_history friends_work_history).join(',')
provider :foursquare, ENV['FOURSQUARE_CLIENT_ID'], ENV['FOURSQUARE_CLIENT_SECRET']
end
/*
*= require ./bootstrap_and_overrides
*/
body {
padding-top: 20px;
padding-bottom: 40px;
}
.container-narrow {
margin: 0 auto;
max-width: 700px;
}
.container-narrow > hr {
margin: 30px 0;
}
.jumbotron {
margin: 60px 0;
text-align: center;
}
.jumbotron h1 {
font-size: 72px;
line-height: 1;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
.marketing {
margin: 60px 0;
}
.marketing p + h4 {
margin-top: 28px;
}
!!! 5
%html(lang='ja')
%head
%meta(charset='utf-8')
%meta(http-equiv='X-UA-Compatible' content='IE=Edge,chrome=1')
%meta(name='viewport' content='width=device-width, initial-scale=1.0')
%title= content_for?(:title) ? yield(:title) : t('helpers.titles.application')
= csrf_meta_tags
/[if lt IE 9]
= javascript_include_tag 'http://html5shim.googlecode.com/svn/trunk/html5.js'
= stylesheet_link_tag :pages, media: :all
= favicon_link_tag
%body
.container-narrow
.masthead
%ul.nav.nav-pills.pull-right
%li= link_to 'Welcome', root_path
%li= link_to 'About', about_path
%h3.muted= t 'helpers.titles.application'
= yield
%hr
.footer
%p &copy; Lambda Engineering #{Time.now.year}
= javascript_include_tag 'application'
module Admins
class PagesController < ApplicationController
def welcome
end
end
end
class PagesController < ApplicationController
layout 'pages'
skip_before_filter :login_required
def welcome
redirect_to home_path if logged_in?
end
def faq
end
def about
end
end
require 'spec_helper'
describe Admins::PagesController do
context 'when not logged-in' do
it 'GET welcome should redirect to admins_login_path' do
get :welcome
response.should redirect_to(admins_login_path)
end
end
end
web: bundle exec unicorn -p $PORT
thinkpad = '192.168.0.5'
role :web, thinkpad
role :app, thinkpad
role :db, thinkpad, primary: true
role :db, thinkpad
PuriketsuRails::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
stylesheets = %w(admins users login pages).map { |f| f + '.css' }
config.assets.precompile += stylesheets
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
end
user 'web', 'web'
project_root = File.expand_path '../../../../', __FILE__
pid "#{project_root}/current/tmp/pids/unicorn.pid"
listen "#{project_root}/current/tmp/unicorn.sock", backlog: 64
stderr_path "#{project_root}/current/log/unicorn.stderr.log"
stdout_path "#{project_root}/current/log/unicorn.stdout.log"
working_directory "#{project_root}/current/"
worker_processes 4
preload_app true
timeout 30
before_fork do |server, worker|
old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
signal = (worker.nr + 1) >= server.worker_process ? :QUIT : :TTOU
Process.kill(signal, File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
end
after_fork do |server, worker|
end
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
PuriketsuRails::Application.load_tasks
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
# User-Agent: *
# Disallow: /
PuriketsuRails::Application.routes.draw do
namespace :admins do
get '/login' => 'sessions#new', :as => :login
post '/login' => 'sessions#create', :as => :login
post '/logout' => 'sessions#destroy', :as => :logout
resources :admins
resources :users
root to: 'pages#welcome'
end
namespace :api do
namespace :v1 do
scope '/facebook' do
get '/' => 'facebook#index', :as => :facebook
post '/' => 'facebook#create', :as => :facebook
end
scope '/foursquare' do
get '/' => 'foursquare#index', :as => :foursquare
post '/' => 'foursquare#create', :as => :foursquare
end
end
end
root to: 'pages#welcome'
get '/faq' => 'pages#faq', :as => :faq
get '/about' => 'pages#about', :as => :about
get '/login' => 'sessions#new', :as => :login
post '/login' => 'sessions#create', :as => :login
post '/logout' => 'sessions#destroy', :as => :logout
scope '/auth' do
get '/twitter', :as => :auth_twitter
get '/facebook', :as => :auth_facebook
get '/foursquare', :as => :auth_foursquare
get '/:provider/callback', :to => 'credentials#create', :constraints => { :provider => /twitter|facebook|foursquare/ }
get '/failure', :to => 'credentials#failure'
end
get '/home' => 'home#index', :as => :home
resources :credentials, :only => %w(index destroy)
resources :users, :except => %w(index)
end
require 'spec_helper'
describe 'routes' do
context 'pages' do
it 'GET / should route_to pages#welcome' do
get('/').should route_to 'pages#welcome'
end
end
context 'home' do
it 'GET /home should route_to home#index' do
get('/home').should route_to 'home#index'
end
end
context 'sessions' do
it 'GET /login should route_to sessions#new' do
get('/login').should route_to 'sessions#new'
end
it 'POST /login should route_to sessions#new' do
post('/login').should route_to 'sessions#create'
end
end
context 'credentials' do
it 'GET /credentials should route_to credentials#index' do
get('/credentials').should route_to 'credentials#index'
end
it 'DELETE /credentials/1 should route_to credentials#destroy' do
delete('/credentials/1').should route_to 'credentials#destroy', id: '1'
end
end
end
# Be sure to restart your server when you modify this file.
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
PuriketsuRails::Application.config.secret_token = '6758548b84abeb7ff049d751c5f058c1a4be7f4a14eaa9e32d5a0609225f21e9338281765ea050c57a3e959071e37fe3493296e3b2365c91cefba89aee0cfd83'
seeds = File.expand_path("../seeds/#{Rails.env}.rb", __FILE__)
load(seeds) if File.exist?(seeds)
# Be sure to restart your server when you modify this file.
PuriketsuRails::Application.config.session_store :cookie_store, key: '_puriketsu-rails_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
# PuriketsuRails::Application.config.session_store :active_record_store
module Admins
class SessionsController < ApplicationController
layout false
before_filter :redirect_if_logged_in, only: %w(new create)
skip_before_filter :login_required
def new
@admin = Admin.new
end
def create
if @admin = Admin.authenticate(params[:admin])
session[:admin_id] = @admin.id
redirect_to_target_or_default admins_root_path, notice: t('flash.notice.sessions.created')
else
@admin = Admin.new params[:admin]
flash.now[:error] = t 'flash.notice.sessions.error'
render :new
end
end
def destroy
session[:admin_id] = nil
flash[:notice] = t 'flash.notice.sessions.created'
redirect_to admins_login_path
end
private
def redirect_if_logged_in
if logged_in?
redirect_to admins_root_path
return
end
end
end
end
class SessionsController < ApplicationController
layout false
before_filter :redirect_if_logged_in, only: %w(new create)
skip_before_filter :login_required
def new
@user = User.new
end
def create
if @user = User.authenticate(params[:user])
session[:user_id] = @user.id
redirect_to_target_or_default home_path, notice: t('flash.notice.sessions.created')
else
@user = User.new params[:user]
flash.now[:error] = t 'flash.notice.sessions.error'
render :new
end
end
def destroy
session[:user_id] = nil
flash[:notice] = t('flash.notice.sessions.destroyed')
redirect_to login_path
end
private
def redirect_if_logged_in
if logged_in?
redirect_to home_path
return
end
end
end
require 'spec_helper'
describe SessionsController do
before do
@email, @password = 'user@user.com', 'password'
@user = FactoryGirl.create :user, email: @email, password: @password
end
context 'when not logged-in' do
describe 'new' do
it 'GET should be success' do
get :new
response.should be_success
end
end
describe 'create' do
it 'POST with valid email/password should redirect_to home_path' do
post :create, user: { email: @email, password: @password }
response.should redirect_to(home_path)
end
it 'POST with invalid email/password should render new' do
post :create, user: { email: @email, password: "#{@password}foo" }
response.should render_template(:new)
end
end
describe 'destroy' do
it 'POST should be success' do
post :destroy
response.should redirect_to(login_path)
end
end
end
context 'when logged-in' do
before do
session[:user_id] = @user.id
end
describe 'index' do
it 'GET should redirect_to home_path' do
get :new
response.should redirect_to(home_path)
end
end
describe 'create' do
it 'POST with valid email/password should redirect_to home_path' do
post :create, user: { email: @email, password: @password }
response.should redirect_to(home_path)
end
it 'POST with invalid email/password should redirect_to home_path' do
post :create, user: { email: @email, password: "#{@password}foo" }
response.should redirect_to(home_path)
end
end
describe 'destroy' do
it 'POST should be success' do
post :destroy
response.should redirect_to(login_path)
end
end
end
end
- title t('.title'), @admin.email
.page-header
%h1=t '.title'
%p
%strong= Admin.human_attribute_name(:email) + ':'
%br
= @admin.email
.form-actions
= link_to t('helpers.links.back'), admins_admins_path, class: 'btn'
= link_to t('helpers.links.edit'), edit_admins_admin_path(@admin), class: 'btn'
= link_to t('helpers.links.destroy'), admins_admin_path(@admin), method: 'delete', data: { confirm: t('helpers.links.confirm') }, class: 'btn btn-danger'
ja:
simple_form:
"yes": 'はい'
"no": 'いいえ'
required:
text: '必須'
mark: '*'
# You can uncomment the line below if you need to overwrite the whole required html.
# When using html, text and mark won't be used.
# html: '<abbr title="required">*</abbr>'
error_notification:
default_message: 'Please review the problems below:'
labels:
defaults:
password: 'Password'
user:
new:
email: 'E-mail to sign in.'
edit:
email: 'E-mail.'
hints:
defaults:
placeholders:
admin:
email: 'メールアドレス'
password: '********'
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a
# complete input. You can remove any component from the
# wrapper, change the order or even add your own to the
# stack. The options given below are used to wrap the
# whole input.
config.wrappers :default, :class => :input,
:hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
## Extensions enabled by default
# Any of these extensions can be disabled for a
# given input by passing: `f.input EXTENSION_NAME => false`.
# You can make any of these extensions optional by
# renaming `b.use` to `b.optional`.
# Determines whether to use HTML5 (:email, :url, ...)
# and required attributes
b.use :html5
# Calculates placeholders automatically from I18n
# You can also pass a string as f.input :placeholder => "Placeholder"
b.use :placeholder
## Optional extensions
# They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
# to the input. If so, they will retrieve the values from the model
# if any exists. If you want to enable the lookup for any of those
# extensions by default, you can change `b.optional` to `b.use`.
# Calculates maxlength from length validations for string inputs
b.optional :maxlength
# Calculates pattern from format validations for string inputs
b.optional :pattern
# Calculates min and max from length validations for numeric inputs
b.optional :min_max
# Calculates readonly automatically from readonly attributes
b.optional :readonly
## Inputs
b.use :label_input
b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
b.use :error, :wrap_with => { :tag => :span, :class => :error }
end
# The default wrapper to be used by the FormBuilder.
config.default_wrapper = :default
# Define the way to render check boxes / radio buttons with labels.
# Defaults to :nested for bootstrap config.
# :inline => input + label
# :nested => label > input
config.boolean_style = :nested
# Default class for buttons
config.button_class = 'btn'
# Method used to tidy up errors. Specify any Rails Array method.
# :first lists the first message for each field.
# Use :to_sentence to list all errors for each field.
# config.error_method = :first
# Default tag used for error notification helper.
config.error_notification_tag = :div
# CSS class to add for error notification helper.
config.error_notification_class = 'alert alert-error'
# ID to add for error notification helper.
# config.error_notification_id = nil
# Series of attempts to detect a default label method for collection.
# config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
# Series of attempts to detect a default value method for collection.
# config.collection_value_methods = [ :id, :to_s ]
# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
# config.collection_wrapper_tag = nil
# You can define the class to use on all collection wrappers. Defaulting to none.
# config.collection_wrapper_class = nil
# You can wrap each item in a collection of radio/check boxes with a tag,
# defaulting to :span. Please note that when using :boolean_style = :nested,
# SimpleForm will force this option to be a label.
# config.item_wrapper_tag = :span
# You can define a class to use in all item wrappers. Defaulting to none.
# config.item_wrapper_class = nil
# How the label text should be generated altogether with the required text.
# config.label_text = lambda { |label, required| "#{required} #{label}" }
# You can define the class to use on all labels. Default is nil.
config.label_class = 'control-label'
# You can define the class to use on all forms. Default is simple_form.
# config.form_class = :simple_form
# You can define which elements should obtain additional classes
# config.generate_additional_classes_for = [:wrapper, :label, :input]
# Whether attributes are required by default (or not). Default is true.
# config.required_by_default = true
# Tell browsers whether to use default HTML5 validations (novalidate option).
# Default is enabled.
config.browser_validations = false
# Collection of methods to detect if a file type was given.
# config.file_methods = [ :mounted_as, :file?, :public_filename ]
# Custom mappings for input types. This should be a hash containing a regexp
# to match as key, and the input type that will be used when the field name
# matches the regexp as value.
# config.input_mappings = { /count/ => :integer }
# Custom wrappers for input types. This should be a hash containing an input
# type as key and the wrapper that will be used for all inputs with specified type.
# config.wrapper_mappings = { :string => :prepend }
# Default priority for time_zone inputs.
# config.time_zone_priority = nil
# Default priority for country inputs.
# config.country_priority = nil
# Default size for text inputs.
config.default_input_size = nil
# When false, do not use translations for labels.
# config.translate_labels = true
# Automatically discover new inputs in Rails' autoload path.
# config.inputs_discovery = true
# Cache SimpleForm inputs discovery
# config.cache_discovery = !Rails.env.development?
end
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper :tag => 'div', :class => 'controls' do |ba|
ba.use :input
ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
end
end
config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper :tag => 'div', :class => 'controls' do |input|
input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
prepend.use :input
end
input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
end
end
config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper :tag => 'div', :class => 'controls' do |input|
input.wrapper :tag => 'div', :class => 'input-append' do |append|
append.use :input
end
input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
end
end
# Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
# Check the Bootstrap docs (http://twitter.github.com/bootstrap)
# to learn about the different styles for forms and inputs,
# buttons and other elements.
config.default_wrapper = :bootstrap
end
SimpleForm.setup do |config|
config.wrappers :simplest, tag: false do |b|
b.use :html5
b.use :placeholder
b.use :input
end
end
require 'rubygems'
require 'spork'
Spork.prefork do
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.render_views
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
config.before :suite do
DatabaseCleaner.orm = :mongoid
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean_with :truncation
end
config.before :each do
DatabaseCleaner.start
end
config.after :each do
DatabaseCleaner.clean
end
end
end
Spork.each_run do
FactoryGirl.reload
end
thinkpad = '192.168.0.17'
role :web, thinkpad
role :app, thinkpad
role :db, thinkpad, primary: true
role :db, thinkpad
PuriketsuRails::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
# Log error messages when you accidentally call methods on nil
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
end
class TwitterCredential < Credential
field :token, type: String
field :secret, type: String
validates :token, presence: true
validates :secret, presence: true
def self.build_from_user_and_auth(user, auth)
find_by(user: user, uid: auth.uid) ||
new(user: user, token: auth.credentials.token, secret: auth.credentials.secret, uid: auth.uid, nickname: auth.info.nickname)
end
end
FactoryGirl.define do
factory :twitter_credential do
association :user, factory: :user
sequence(:uid) { |n| n }
nickname 'nickname'
token 'token'
secret 'secret'
end
end
require 'spec_helper'
describe TwitterCredential do
it 'default factory should be valid' do
twitter_credential = FactoryGirl.build :twitter_credential
twitter_credential.should be_valid
end
it 'user_id cannot be empty' do
twitter_credential = FactoryGirl.build :twitter_credential, user_id: nil
twitter_credential.should_not be_valid
twitter_credential.should have(1).error_on(:user_id)
end
it 'uid cannot be empty' do
twitter_credential = FactoryGirl.build :twitter_credential, uid: nil
twitter_credential.should_not be_valid
twitter_credential.should have(1).error_on(:uid)
end
it 'nickname cannot be empty' do
twitter_credential = FactoryGirl.build :twitter_credential, nickname: nil
twitter_credential.should_not be_valid
twitter_credential.should have(1).error_on(:nickname)
end
it 'token cannot be empty' do
twitter_credential = FactoryGirl.build :twitter_credential, token: nil
twitter_credential.should_not be_valid
twitter_credential.should have(1).error_on(:token)
end
it 'secret cannot be empty' do
twitter_credential = FactoryGirl.build :twitter_credential, secret: nil
twitter_credential.should_not be_valid
twitter_credential.should have(1).error_on(:secret)
end
it 'uid should be unique in scope of user' do
twitter_credential = FactoryGirl.create :twitter_credential
twitter_credential = FactoryGirl.build :twitter_credential,
user: twitter_credential.user, uid: twitter_credential.uid
twitter_credential.should have(1).error_on(:uid)
end
it 'uid can be same if user_ids are different' do
twitter_credential = FactoryGirl.create :twitter_credential
twitter_credential = FactoryGirl.create :twitter_credential,
uid: twitter_credential.uid
twitter_credential.should be_valid
end
end
class User
include Mongoid::Document
include Mongoid::Timestamps
include Authentication::Model
has_many :credentials, dependent: :destroy
end
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "user#{n}@user.com" }
password 'password'
end
end
class UserMailer < ActionMailer::Base
default from: 'no-reply@example.com'
end
require 'spec_helper'
describe User do
it 'default factory should be valid' do
user = FactoryGirl.build :user
user.should be_valid
end
describe 'email' do
it 'can not be blank' do
user = FactoryGirl.build :user, email: nil
user.should_not be_valid
user.should have(2).error_on(:email)
end
it 'can not be invalid format' do
user = FactoryGirl.build :user, email: 'foobar'
user.should_not be_valid
user.should have(1).error_on(:email)
end
end
describe 'authentication' do
before :each do
@password = 'password'
@user = FactoryGirl.create :user, password: @password
end
it 'should return user instance with valid email/password' do
user = User.authenticate email: @user.email, password: @password
user.should == @user
end
it 'should return nil with invalid email' do
user = User.authenticate email: 'imaginary@imaginary.com', password: @password
user.should be_nil
end
it 'should return nil with invalid password' do
user = User.authenticate email: @user.email, password: 'invalid'
user.should be_nil
end
end
end
/*
*= require_self
*= require ./bootstrap_and_overrides
*= require_tree ./users
*/
class UsersController < ApplicationController
def show
@user = current_user
end
def new
@user = User.new
end
def edit
@user = current_user
end
def create
@user = User.new params[:user]
if @user.save
redirect_to home_path, notice: t('.created')
else
render :new
end
end
def update
@user = current_user
if @user.update_attributes params[:user]
redirect_to home_path, notice: t('.updated')
else
render :edit
end
end
def destroy
current_user.destroy
session[:user_id] = nil
redirect_to root_path
end
end
%hr
.jumbotron
%h1 Super awesome marketing speak!
%p.lead Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus commodo.
%a.btn.btn-large.btn-success Sign up today
%hr
.row-fluid.marketing
.span6
%h4 Subheading
%p Donec id elit non mi porta gravida at eget metus. Maecenas faucibus mollis interdum.
%h4 Subheading
%p Donec id elit non mi porta gravida at eget metus. Maecenas faucibus mollis interdum.
.span6
%h4 Subheading
%p Donec id elit non mi porta gravida at eget metus. Maecenas faucibus mollis interdum.
%h4 Subheading
%p Donec id elit non mi porta gravida at eget metus. Maecenas faucibus mollis interdum.
# Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
end
# Disable root element in JSON by default.
ActiveSupport.on_load(:active_record) do
self.include_root_in_json = false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment