Commit 847f145c by tady

.

parent 5664346c
source 'https://rubygems.org'
ruby '2.0.0'
ruby '2.1.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 4.0.2'
......@@ -72,10 +72,16 @@ end
group :development, :test do
gem 'rspec-rails'
gem 'guard-rspec'
gem 'guard-spring'
gem 'factory_girl_rails'
gem 'spring'
end
group :test do
gem 'email_spec'
end
group :production do
gem 'rails_12factor'
......
......@@ -74,6 +74,9 @@ GEM
thread_safe (~> 0.1)
warden (~> 1.2.3)
diff-lcs (1.2.5)
email_spec (1.5.0)
launchy (~> 2.1)
mail (~> 2.2)
erubis (2.7.0)
eventmachine (1.0.3)
execjs (2.0.2)
......@@ -97,6 +100,9 @@ GEM
guard-rspec (4.0.4)
guard (>= 2.1.1)
rspec (~> 2.14)
guard-spring (0.0.4)
guard
spring
hashie (2.0.5)
hike (1.2.3)
htmlentities (4.3.1)
......@@ -108,6 +114,8 @@ GEM
json (1.8.1)
jwt (0.1.8)
multi_json (>= 1.5)
launchy (2.4.2)
addressable (~> 2.3)
listen (2.2.0)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
......@@ -246,9 +254,11 @@ DEPENDENCIES
coderay
coffee-rails (~> 4.0.0)
devise
email_spec
factory_girl_rails
faraday
guard-rspec
guard-spring
jbuilder (~> 1.2)
mail
nokogiri
......
if window.location.pathname.match /^\/$/
if window.location.pathname.match /^\/posts\/?$/
$ ->
......
.treeview, .treeview ul {
padding: 0;
margin: 0;
list-style: none;
}
.treeview ul {
background-color: white;
margin-top: 4px;
}
.treeview .hitarea {
background: url(images/treeview-default.gif) -64px -25px no-repeat;
height: 16px;
width: 16px;
margin-left: -16px;
float: left;
cursor: pointer;
}
/* fix for IE6 */
* html .hitarea {
display: inline;
float:none;
}
.treeview li {
margin: 0;
padding: 3px 0pt 3px 16px;
}
.treeview a.selected {
background-color: #eee;
}
#treecontrol { margin: 1em 0; display: none; }
.treeview .hover { color: red; cursor: pointer; }
.treeview li { background: url(images/treeview-default-line.gif) 0 0 no-repeat; }
.treeview li.collapsable, .treeview li.expandable { background-position: 0 -176px; }
.treeview .expandable-hitarea { background-position: -80px -3px; }
.treeview li.last { background-position: 0 -1766px }
.treeview li.lastCollapsable, .treeview li.lastExpandable { background-image: url(images/treeview-default.gif); }
.treeview li.lastCollapsable { background-position: 0 -111px }
.treeview li.lastExpandable { background-position: -32px -67px }
.treeview div.lastCollapsable-hitarea, .treeview div.lastExpandable-hitarea { background-position: 0; }
.treeview-red li { background-image: url(images/treeview-red-line.gif); }
.treeview-red .hitarea, .treeview-red li.lastCollapsable, .treeview-red li.lastExpandable { background-image: url(images/treeview-red.gif); }
.treeview-black li { background-image: url(images/treeview-black-line.gif); }
.treeview-black .hitarea, .treeview-black li.lastCollapsable, .treeview-black li.lastExpandable { background-image: url(images/treeview-black.gif); }
.treeview-gray li { background-image: url(images/treeview-gray-line.gif); }
.treeview-gray .hitarea, .treeview-gray li.lastCollapsable, .treeview-gray li.lastExpandable { background-image: url(images/treeview-gray.gif); }
.treeview-famfamfam li { background-image: url(images/treeview-famfamfam-line.gif); }
.treeview-famfamfam .hitarea, .treeview-famfamfam li.lastCollapsable, .treeview-famfamfam li.lastExpandable { background-image: url(images/treeview-famfamfam.gif); }
.treeview .placeholder {
background: url(images/ajax-loader.gif) 0 0 no-repeat;
height: 16px;
width: 16px;
display: block;
}
.filetree li { padding: 3px 0 2px 16px; }
.filetree span.folder, .filetree span.file { padding: 1px 0 1px 16px; display: block; }
.filetree span.folder { background: url(images/folder.gif) 0 0 no-repeat; }
.filetree li.expandable span.folder { background: url(images/folder-closed.gif) 0 0 no-repeat; }
.filetree span.file { background: url(images/file.gif) 0 0 no-repeat; }
......@@ -3,7 +3,6 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
def require_login
unless user_signed_in?
flash[:alert] = 'You need Login!'
......
class HomeController < ApplicationController
def show
skip_before_action :require_login
def top
if user_signed_in?
redirect_to posts_path, status: 301
else
render template: 'home/login'
end
end
......
......@@ -4,7 +4,7 @@ require 'rv/mailer'
class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy]
before_action :require_login, except: [:index]
before_action :require_login
include ApplicationHelper
include RV::Mailer
......@@ -12,17 +12,10 @@ class PostsController < ApplicationController
# GET /posts
# GET /posts.json
def index
if user_signed_in?
if params[:q].present?
@posts = Post.build_query(params).limit(10)
else
@posts = Post.order(updated_at: :desc).limit(10)
end
render
if params[:q].present?
@posts = Post.build_query(params).limit(10)
else
render file: 'home/login'
@posts = Post.order(updated_at: :desc).limit(10)
end
end
......@@ -47,9 +40,7 @@ class PostsController < ApplicationController
end
def fork
@post = set_post.clone
@post.title = @post.title.gsub(/%Name/, current_user.name)
@post.title = Time.now.strftime(@post.title) # TODO
@post = set_post.generate_fork(user: current_user)
render action: 'new'
end
......
......@@ -37,4 +37,14 @@ class Post < ActiveRecord::Base
end
# generate forked post (not saved)
def generate_fork(user: )
forked_post = self.clone
forked_post.title = forked_post.title.gsub(/%Name/, user.name)
forked_post.title = Time.now.strftime(forked_post.title) # TODO
forked_post.author = user
forked_post
end
end
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'spring' 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('spring', 'spring')
......@@ -20,7 +20,7 @@ module Rendezvous
# 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 = :de
config.i18n.default_locale = :ja
# config.action_mailer.delivery_method = :action_gmailer
......
Rendezvous::Application.routes.draw do
root 'posts#index', as: 'root'
root 'home#top', as: 'root'
post 'posts/preview' => 'posts#preview'
get 'posts/show_fragment' => 'posts#show_fragment'
get 'posts/:id/fork' => 'posts#fork', as: 'fork_post'
get 'posts/:id/mail' => 'posts#mail', as: 'mail_post'
resources :posts
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
......
require 'spec_helper'
describe HomeController do
describe "GET 'top'" do
it "should be successful" do
get :top
expect(response).to be_success
expect(response.code).to eq("200")
end
end
describe 'Login' do
before (:each) do
@user = FactoryGirl.create(:login_user_1)
sign_in @user
end
describe "GET 'top'" do
it "should be successful" do
get :top
expect(subject).to redirect_to controller: 'posts',
action: 'index'
end
it "should find the right user" do
get :top
expect(assigns(:current_user)).to eq(@user)
end
end
end
end
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :post do
title 'sample title'
body 'sample body'
after(:create) do |post|
create(:post_tag, post: post, tag: create(:tag_ruby))
end
end
factory :post_tag do
end
end
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :tag_ruby, class: Tag do
name 'ruby'
end
end
FactoryGirl.define do
factory :alice, class: User do
name 'Alice'
email "alice@mail.com"
password Devise.friendly_token[0,20]
google_token_expires_at Time.now + 30.minutes
end
factory :bob, class: User do
name 'Bob'
email "bob@mail.com"
password Devise.friendly_token[0,20]
google_token_expires_at Time.now - 1.hour
end
factory :login_user_1, class: User do
name 'Test User'
email 'example@example.com'
password 'changeme'
password_confirmation 'changeme'
# required if the Devise Confirmable module is used
# confirmed_at Time.now
end
end
# Commonly used email steps
#
# To add your own steps make a custom_email_steps.rb
# The provided methods are:
#
# last_email_address
# reset_mailer
# open_last_email
# visit_in_email
# unread_emails_for
# mailbox_for
# current_email
# open_email
# read_emails_for
# find_email
#
# General form for email scenarios are:
# - clear the email queue (done automatically by email_spec)
# - execute steps that sends an email
# - check the user received an/no/[0-9] emails
# - open the email
# - inspect the email contents
# - interact with the email (e.g. click links)
#
# The Cucumber steps below are setup in this order.
# module EmailHelpers
# def current_email_address
# # Replace with your a way to find your current email. e.g @current_user.email
# # last_email_address will return the last email address used by email spec to find an email.
# # Note that last_email_address will be reset after each Scenario.
# last_email_address || "example@example.com"
# end
# end
# World(EmailHelpers)
# #
# # Reset the e-mail queue within a scenario.
# # This is done automatically before each scenario.
# #
# Given /^(?:a clear email queue|no emails have been sent)$/ do
# reset_mailer
# end
# #
# # Check how many emails have been sent/received
# #
# Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
# unread_emails_for(address).size.should == parse_email_count(amount)
# end
# Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
# mailbox_for(address).size.should == parse_email_count(amount)
# end
# Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject|
# unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.should == parse_email_count(amount)
# end
# Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject \/([^"]*?)\/$/ do |address, amount, subject|
# unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size.should == parse_email_count(amount)
# end
# Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
# open_email(address, :with_text => expected_body)
# end
# #
# # Accessing emails
# #
# # Opens the most recently received email
# When /^(?:I|they|"([^"]*?)") opens? the email$/ do |address|
# open_email(address)
# end
# When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
# open_email(address, :with_subject => subject)
# end
# When /^(?:I|they|"([^"]*?)") opens? the email with subject \/([^"]*?)\/$/ do |address, subject|
# open_email(address, :with_subject => Regexp.new(subject))
# end
# When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
# open_email(address, :with_text => text)
# end
# When /^(?:I|they|"([^"]*?)") opens? the email with text \/([^"]*?)\/$/ do |address, text|
# open_email(address, :with_text => Regexp.new(text))
# end
# #
# # Inspect the Email Contents
# #
# Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text|
# current_email.should have_subject(text)
# end
# Then /^(?:I|they) should see \/([^"]*?)\/ in the email subject$/ do |text|
# current_email.should have_subject(Regexp.new(text))
# end
# Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text|
# current_email.default_part_body.to_s.should include(text)
# end
# Then /^(?:I|they) should see \/([^"]*?)\/ in the email body$/ do |text|
# current_email.default_part_body.to_s.should =~ Regexp.new(text)
# end
# Then /^(?:I|they) should see the email delivered from "([^"]*?)"$/ do |text|
# current_email.should be_delivered_from(text)
# end
# Then /^(?:I|they) should see "([^\"]*)" in the email "([^"]*?)" header$/ do |text, name|
# current_email.should have_header(name, text)
# end
# Then /^(?:I|they) should see \/([^\"]*)\/ in the email "([^"]*?)" header$/ do |text, name|
# current_email.should have_header(name, Regexp.new(text))
# end
# Then /^I should see it is a multi\-part email$/ do
# current_email.should be_multipart
# end
# Then /^(?:I|they) should see "([^"]*?)" in the email html part body$/ do |text|
# current_email.html_part.body.to_s.should include(text)
# end
# Then /^(?:I|they) should see "([^"]*?)" in the email text part body$/ do |text|
# current_email.text_part.body.to_s.should include(text)
# end
# #
# # Inspect the Email Attachments
# #
# Then /^(?:I|they) should see (an|no|\d+) attachments? with the email$/ do |amount|
# current_email_attachments.size.should == parse_email_count(amount)
# end
# Then /^there should be (an|no|\d+) attachments? named "([^"]*?)"$/ do |amount, filename|
# current_email_attachments.select { |a| a.filename == filename }.size.should == parse_email_count(amount)
# end
# Then /^attachment (\d+) should be named "([^"]*?)"$/ do |index, filename|
# current_email_attachments[(index.to_i - 1)].filename.should == filename
# end
# Then /^there should be (an|no|\d+) attachments? of type "([^"]*?)"$/ do |amount, content_type|
# current_email_attachments.select { |a| a.content_type.include?(content_type) }.size.should == parse_email_count(amount)
# end
# Then /^attachment (\d+) should be of type "([^"]*?)"$/ do |index, content_type|
# current_email_attachments[(index.to_i - 1)].content_type.should include(content_type)
# end
# Then /^all attachments should not be blank$/ do
# current_email_attachments.each do |attachment|
# attachment.read.size.should_not == 0
# end
# end
# Then /^show me a list of email attachments$/ do
# EmailSpec::EmailViewer::save_and_open_email_attachments_list(current_email)
# end
# #
# # Interact with Email Contents
# #
# When /^(?:I|they|"([^"]*?)") follows? "([^"]*?)" in the email$/ do |address, link|
# visit_in_email(link, address)
# end
# When /^(?:I|they) click the first link in the email$/ do
# click_first_link_in_email
# end
# #
# # Debugging
# # These only work with Rails and OSx ATM since EmailViewer uses RAILS_ROOT and OSx's 'open' command.
# # Patches accepted. ;)
# #
# Then /^save and open current email$/ do
# EmailSpec::EmailViewer::save_and_open_email(current_email)
# end
# Then /^save and open all text emails$/ do
# EmailSpec::EmailViewer::save_and_open_all_text_emails
# end
# Then /^save and open all html emails$/ do
# EmailSpec::EmailViewer::save_and_open_all_html_emails
# end
# Then /^save and open all raw emails$/ do
# EmailSpec::EmailViewer::save_and_open_all_raw_emails
# end
require 'spec_helper'
describe Post do
describe 'Instance method' do
before :each do
@post = create(:post)
@alice = create(:alice)
end
describe 'Fork' do
subject { @post.generate_fork(user: @alice) }
it 'valid title' do
expect(subject.title).to eq('sample title')
end
it 'valid body' do
expect(subject.body).to eq('sample body')
end
it 'valid user' do
expect(subject.author).to eq(@alice)
end
it 'valid user' do
expect(subject.tags).to include(@post.tags.first)
end
end
end
end
require 'spec_helper'
describe Tag do
pending "add some examples to (or delete) #{__FILE__}"
end
require 'spec_helper'
describe User do
before :each do
@alice = create(:alice)
@bob = create(:bob)
describe 'Instance method' do
before :each do
@alice = create(:alice)
@bob = create(:bob)
end
describe '#google_oauth_token_expired?' do
it 'not expired' do
expect(@alice.google_oauth_token_expired?).to be_false
end
it 'expired' do
expect(@bob.google_oauth_token_expired?).to be_true
end
end
end
describe '#google_oauth_token_expired?' do
describe 'validation' do
before(:each) do
@attr = {
:name => "Example User",
:email => "user@example.com",
:password => "changeme",
:password_confirmation => "changeme"
}
end
it "should create a new instance given a valid attribute" do
User.create!(@attr)
end
it "should require an email address" do
no_email_user = User.new(@attr.merge(:email => ""))
no_email_user.should_not be_valid
end
it "should accept valid email addresses" do
addresses = %w[user@foo.com THE_USER@foo.bar.org first.last@foo.jp]
addresses.each do |address|
valid_email_user = User.new(@attr.merge(:email => address))
valid_email_user.should be_valid
end
end
it "should reject invalid email addresses" do
addresses = %w[user@foo,com user_at_foo.org example.user@foo.]
addresses.each do |address|
invalid_email_user = User.new(@attr.merge(:email => address))
invalid_email_user.should_not be_valid
end
end
it "should reject duplicate email addresses" do
User.create!(@attr)
user_with_duplicate_email = User.new(@attr)
user_with_duplicate_email.should_not be_valid
end
it 'not expired' do
expect(@alice.google_oauth_token_expired?).to be_false
it "should reject email addresses identical up to case" do
upcased_email = @attr[:email].upcase
User.create!(@attr.merge(:email => upcased_email))
user_with_duplicate_email = User.new(@attr)
user_with_duplicate_email.should_not be_valid
end
it 'expired' do
expect(@bob.google_oauth_token_expired?).to be_true
describe "passwords" do
before(:each) do
@user = User.new(@attr)
end
it "should have a password attribute" do
@user.should respond_to(:password)
end
it "should have a password confirmation attribute" do
@user.should respond_to(:password_confirmation)
end
end
describe "password validations" do
it "should require a password" do
User.new(@attr.merge(:password => "", :password_confirmation => "")).
should_not be_valid
end
it "should require a matching password confirmation" do
User.new(@attr.merge(:password_confirmation => "invalid")).
should_not be_valid
end
it "should reject short passwords" do
short = "a" * 5
hash = @attr.merge(:password => short, :password_confirmation => short)
User.new(hash).should_not be_valid
end
end
describe "password encryption" do
before(:each) do
@user = User.create!(@attr)
end
it "should have an encrypted password attribute" do
@user.should respond_to(:encrypted_password)
end
it "should set the encrypted password attribute" do
@user.encrypted_password.should_not be_blank
end
end
end
end
......@@ -3,6 +3,7 @@ ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'email_spec'
require 'factory_girl'
# Requires supporting ruby files with custom matchers and macros, etc,
......@@ -43,6 +44,10 @@ RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.include(EmailSpec::Helpers)
config.include(EmailSpec::Matchers)
config.before(:all) do
FactoryGirl.reload
end
......
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment