Skip to content

Commit

Permalink
kt c8
Browse files Browse the repository at this point in the history
  • Loading branch information
chien-pro committed Jun 22, 2012
1 parent 465babe commit 93445ee
Show file tree
Hide file tree
Showing 66 changed files with 381 additions and 28 deletions.
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ group :test do
gem 'rb-inotify', '0.8.8'
gem 'libnotify', '0.5.9'
gem 'factory_girl_rails', '1.4.0'
gem 'cucumber-rails', '1.2.1', require: false
gem 'database_cleaner', '0.7.0'
end

group :production do
gem 'pg', '0.12.2'
#gem 'pg', '0.12.2'
#thai cho
end
16 changes: 14 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.3.3)
cucumber (1.2.1)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.11.0)
json (>= 1.4.6)
cucumber-rails (1.2.1)
capybara (>= 1.1.2)
cucumber (>= 1.1.3)
nokogiri (>= 1.5.0)
database_cleaner (0.7.0)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.4.0)
Expand All @@ -60,6 +70,8 @@ GEM
factory_girl (~> 2.3.0)
railties (>= 3.0.0)
ffi (1.0.11)
gherkin (2.11.0)
json (>= 1.4.6)
guard (1.1.1)
listen (>= 0.4.2)
thor (>= 0.14.6)
Expand All @@ -86,7 +98,6 @@ GEM
mime-types (1.18)
multi_json (1.3.6)
nokogiri (1.5.4)
pg (0.12.2)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
Expand Down Expand Up @@ -169,11 +180,12 @@ DEPENDENCIES
bootstrap-sass (= 2.0.0)
capybara (= 1.1.2)
coffee-rails (= 3.2.2)
cucumber-rails (= 1.2.1)
database_cleaner (= 0.7.0)
factory_girl_rails (= 1.4.0)
guard-rspec (= 0.5.5)
jquery-rails (= 2.0.0)
libnotify (= 0.5.9)
pg (= 0.12.2)
rails (= 3.2.6)
rb-inotify (= 0.8.8)
rspec-rails (= 2.10.0)
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .
3 changes: 3 additions & 0 deletions app/assets/javascripts/sessions.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sessions.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class ApplicationController < ActionController::Base
protect_from_forgery
include SessionsHelper
end
19 changes: 19 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class SessionsController < ApplicationController
def create
user = User.find_by_email(params[:session][:email])
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_to user
else
flash.now[:error] = 'Invalid email/password combination' # Not quite right!
render 'new'
end
end
def new

end
def destroy
sign_out
redirect_to root_path
end
end
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def show
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
Expand Down
23 changes: 23 additions & 0 deletions app/helpers/sessions_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module SessionsHelper
def sign_in(user)
cookies.permanent[:remember_token] = user.remember_token
self.current_user = user
end

def signed_in?
!current_user.nil?
end

def current_user=(user)
@current_user = user
end

def current_user
@current_user ||= User.find_by_remember_token(cookies[:remember_token])
end

def sign_out
self.current_user = nil
cookies.delete(:remember_token)
end
end
11 changes: 6 additions & 5 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module UsersHelper
def gravatar_for(user)
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
image_tag(gravatar_url, alt: user.name, class: "gravatar")
end
def gravatar_for(user, options = { size: 50 })
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
size = options[:size]
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
image_tag(gravatar_url, alt: user.name, class: "gravatar")
end
end
7 changes: 6 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation
has_secure_password
before_save { |user| user.email = email.downcase }

before_save :create_remember_token
validates :name, presence: true, length: {maximum: 50}
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: {case_sensitive: false}
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
private

def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64
end
end
25 changes: 21 additions & 4 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
<header class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<%= link_to "sample app", '#', id: "logo" %>
<%= link_to "sample app", root_path, id: "logo" %>
<nav>
<ul class="nav pull-right">
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Help", help_path %></li>
<li><%= link_to "Sign in", '#' %></li>
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Help", help_path %></li>
<% if signed_in? %>
<li><%= link_to "Users", '#' %></li>
<li id="fat-menu" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", '#' %></li>
<li class="divider"></li>
<li>
<%= link_to "Sign out", signout_path, method: "delete" %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Sign in", signin_path %></li>
<% end %>
</ul>
</nav>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<%= content_tag(:div, value, class: "alert alert-#{key}") %>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
Expand Down
19 changes: 19 additions & 0 deletions app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% provide(:title, "Sign in") %>
<h1>Sign in</h1>

<div class="row">
<div class="span6 offset3">
<%= form_for(:session, url: sessions_path) do |f| %>

<%= f.label :email %>
<%= f.text_field :email %>

<%= f.label :password %>
<%= f.password_field :password %>

<%= f.submit "Sign in", class: "btn btn-large btn-primary" %>
<% end %>

<p>New user? <%= link_to "Sign up now!", signup_path %></p>
</div>
</div>
Empty file modified bin/annotate
100755 → 100644
Empty file.
Empty file modified bin/autospec
100755 → 100644
Empty file.
16 changes: 16 additions & 0 deletions bin/cucumber
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'cucumber' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('cucumber', 'cucumber')
Empty file modified bin/erubis
100755 → 100644
Empty file.
Empty file modified bin/guard
100755 → 100644
Empty file.
Empty file modified bin/htmldiff
100755 → 100644
Empty file.
Empty file modified bin/ldiff
100755 → 100644
Empty file.
Empty file modified bin/nokogiri
100755 → 100644
Empty file.
Empty file modified bin/rackup
100755 → 100644
Empty file.
Empty file modified bin/rails
100755 → 100644
Empty file.
Empty file modified bin/rake
100755 → 100644
Empty file.
Empty file modified bin/rake2thor
100755 → 100644
Empty file.
Empty file modified bin/rdoc
100755 → 100644
Empty file.
Empty file modified bin/ri
100755 → 100644
Empty file.
Empty file modified bin/rspec
100755 → 100644
Empty file.
Empty file modified bin/sass
100755 → 100644
Empty file.
Empty file modified bin/sass-convert
100755 → 100644
Empty file.
Empty file modified bin/scss
100755 → 100644
Empty file.
Empty file modified bin/thor
100755 → 100644
Empty file.
Empty file modified bin/tilt
100755 → 100644
Empty file.
Empty file modified bin/tt
100755 → 100644
Empty file.
Empty file modified bundler_stubs/autospec
100755 → 100644
Empty file.
Empty file modified bundler_stubs/erubis
100755 → 100644
Empty file.
Empty file modified bundler_stubs/htmldiff
100755 → 100644
Empty file.
Empty file modified bundler_stubs/ldiff
100755 → 100644
Empty file.
Empty file modified bundler_stubs/nokogiri
100755 → 100644
Empty file.
Empty file modified bundler_stubs/rackup
100755 → 100644
Empty file.
Empty file modified bundler_stubs/rails
100755 → 100644
Empty file.
Empty file modified bundler_stubs/rake
100755 → 100644
Empty file.
Empty file modified bundler_stubs/rake2thor
100755 → 100644
Empty file.
Empty file modified bundler_stubs/rdoc
100755 → 100644
Empty file.
Empty file modified bundler_stubs/ri
100755 → 100644
Empty file.
Empty file modified bundler_stubs/rspec
100755 → 100644
Empty file.
Empty file modified bundler_stubs/sass
100755 → 100644
Empty file.
Empty file modified bundler_stubs/sass-convert
100755 → 100644
Empty file.
Empty file modified bundler_stubs/scss
100755 → 100644
Empty file.
Empty file modified bundler_stubs/thor
100755 → 100644
Empty file.
Empty file modified bundler_stubs/tilt
100755 → 100644
Empty file.
Empty file modified bundler_stubs/tt
100755 → 100644
Empty file.
8 changes: 8 additions & 0 deletions config/cucumber.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
5 changes: 4 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ development:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
test: &test
adapter: sqlite3
database: db/test.sqlite3
pool: 5
Expand All @@ -23,3 +23,6 @@ production:
database: db/production.sqlite3
pool: 5
timeout: 5000

cucumber:
<<: *test
8 changes: 4 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.

en:
hello: "Hello world"
activerecord:
attributes:
user:
password_digest: "Password"
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
SecondApp::Application.routes.draw do

resources :users
resources :sessions, only: [:new, :create, :destroy]

get "users/show"
get "users/new"
get "sessions/new"

get "static_pages/home"
get "home/index"

match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20120622024227_add_remember_token_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddRememberTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :remember_token, :string
add_index :users, :remember_token
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120621043335) do
ActiveRecord::Schema.define(:version => 20120622024227) do

create_table "users", :force => true do |t|
t.string "name"
Expand All @@ -21,8 +21,10 @@
t.string "password_digest"
t.string "password_confirmation"
t.string "password"
t.string "remember_token"
end

add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["remember_token"], :name => "index_users_on_remember_token"

end
56 changes: 56 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.

require 'cucumber/rails'

# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
# order to ease the transition to Capybara we set the default here. If you'd
# prefer to use XPath just remove this line and adjust any selectors in your
# steps to use the XPath syntax.
Capybara.default_selector = :css

# By default, any exception happening in your Rails application will bubble up
# to Cucumber so that your scenario will fail. This is a different from how
# your application behaves in the production environment, where an error page will
# be rendered instead.
#
# Sometimes we want to override this default behaviour and allow Rails to rescue
# exceptions and display an error page (just like when the app is running in production).
# Typical scenarios where you want to do this is when you test your error pages.
# There are two ways to allow Rails to rescue exceptions:
#
# 1) Tag your scenario (or feature) with @allow-rescue
#
# 2) Set the value below to true. Beware that doing this globally is not
# recommended as it will mask a lot of errors for you!
#
ActionController::Base.allow_rescue = false

# Remove/comment out the lines below if your app doesn't have a database.
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
# See the DatabaseCleaner documentation for details. Example:
#
# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
# DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
# end
#
# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
# DatabaseCleaner.strategy = :transaction
# end
#

# Possible values are :truncation and :transaction
# The :transaction strategy is faster, but might give you threading problems.
# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
Cucumber::Rails::Database.javascript_strategy = :truncation

Loading

0 comments on commit 93445ee

Please sign in to comment.