Browse Source

git init

denney-disable-on-select
Jason Denney 11 years ago
commit
aa3ed3d43b
  1. 7
      .gitignore
  2. 2
      .rspec
  3. 55
      .rvmrc
  4. 43
      Gemfile
  5. 236
      Gemfile.lock
  6. 37
      Guardfile
  7. 14
      README.md
  8. 27
      Rakefile
  9. BIN
      app/assets/images/rails.png
  10. 16
      app/assets/javascripts/application.js
  11. 4
      app/assets/javascripts/bootstrap.js.coffee
  12. 15
      app/assets/javascripts/examples.js.coffee.sample
  13. 13
      app/assets/stylesheets/application.css
  14. 17
      app/assets/stylesheets/bootstrap_and_overrides.css.less
  15. 3
      app/controllers/application_controller.rb
  16. 3
      app/controllers/authenticated_controller.rb
  17. 9
      app/controllers/site_controller.rb
  18. 36
      app/controllers/team_controller.example
  19. 10
      app/helpers/application_helper.rb
  20. 0
      app/mailers/.gitkeep
  21. 0
      app/models/.gitkeep
  22. 17
      app/models/team.example
  23. 18
      app/models/team_membership.example
  24. 17
      app/models/user.rb
  25. 25
      app/views/devise/_links.erb
  26. 12
      app/views/devise/confirmations/new.html.erb
  27. 5
      app/views/devise/mailer/confirmation_instructions.html.erb
  28. 8
      app/views/devise/mailer/reset_password_instructions.html.erb
  29. 7
      app/views/devise/mailer/unlock_instructions.html.erb
  30. 16
      app/views/devise/passwords/edit.html.erb
  31. 12
      app/views/devise/passwords/new.html.erb
  32. 25
      app/views/devise/registrations/edit.html.erb
  33. 29
      app/views/devise/registrations/new.html.haml
  34. 28
      app/views/devise/sessions/new.html.erb
  35. 12
      app/views/devise/unlocks/new.html.erb
  36. 49
      app/views/layouts/application.html.haml
  37. 1
      app/views/site/index.html.haml
  38. 9
      app/views/teams_examples/index.html.haml
  39. 21
      app/views/teams_examples/new.html.haml
  40. 11
      app/views/teams_examples/show.html.haml
  41. 4
      config.ru
  42. 66
      config/application.rb
  43. 6
      config/boot.rb
  44. 25
      config/database.yml
  45. 5
      config/environment.rb
  46. 44
      config/environments/development.rb
  47. 68
      config/environments/production.rb
  48. 37
      config/environments/test.rb
  49. 7
      config/initializers/backtrace_silencers.rb
  50. 223
      config/initializers/devise.rb
  51. 15
      config/initializers/inflections.rb
  52. 5
      config/initializers/mime_types.rb
  53. 7
      config/initializers/secret_token.rb
  54. 8
      config/initializers/session_store.rb
  55. 9
      config/initializers/setup_mail.rb
  56. 14
      config/initializers/wrap_parameters.rb
  57. 57
      config/locales/devise.en.yml
  58. 5
      config/locales/en.yml
  59. 71
      config/routes.rb
  60. 49
      db/migrate/20120227024410_devise_create_users.rb
  61. 9
      db/migrate/20120227040841_add_lockable_to_user.rb
  62. 7
      db/migrate/20120301124238_add_names_to_user.rb
  63. 17
      db/migrate/20120308031328_create_teams.example
  64. 5
      db/migrate/20120325023452_add_private_team_to_team.example
  65. 17
      db/migrate/20120325031259_create_team_memberships.example
  66. 61
      db/schema.rb
  67. 11
      db/seeds.rb
  68. 1
      doc/README_FOR_APP
  69. 0
      lib/assets/.gitkeep
  70. 0
      lib/tasks/.gitkeep
  71. 0
      log/.gitkeep
  72. 26
      public/404.html
  73. 26
      public/422.html
  74. 25
      public/500.html
  75. 0
      public/favicon.ico
  76. 5
      public/robots.txt
  77. 6
      script/rails
  78. 30
      spec/acceptance/create_a_team.feature.example
  79. 34
      spec/acceptance/list_teams.feature.example
  80. 15
      spec/acceptance/steps/common_steps.rb
  81. 40
      spec/acceptance/steps/factory_girl_steps.rb
  82. 7
      spec/acceptance/steps/login_steps.rb
  83. 3
      spec/acceptance/steps/pagination_steps.rb
  84. 72
      spec/acceptance/steps/team_steps.example
  85. 3
      spec/acceptance/steps/user_steps.rb
  86. 5
      spec/controllers/maps_controller_spec.example
  87. 14
      spec/factories.rb
  88. 10
      spec/factories/maps.example
  89. 24
      spec/models/team_membership_spec.example
  90. 45
      spec/models/team_spec.example
  91. 29
      spec/models/user_spec.rb
  92. 45
      spec/requests/devise/registrations_spec.rb
  93. 119
      spec/spec_helper.rb
  94. 93
      spec/support/factory_girl_step_helpers.rb
  95. 0
      vendor/assets/javascripts/.gitkeep
  96. 0
      vendor/assets/stylesheets/.gitkeep
  97. 0
      vendor/plugins/.gitkeep

7
.gitignore

@ -0,0 +1,7 @@
.bundle
db/*.sqlite3
log/*.log
tmp/
*.swp
.powrc
.rbenv-version

2
.rspec

@ -0,0 +1,2 @@
--colour
-rturnip

55
.rvmrc

@ -0,0 +1,55 @@
#!/usr/bin/env bash
# This is an RVM Project .rvmrc file, used to automatically load the ruby
# development environment upon cd'ing into the directory
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
environment_id="ruby-1.9.3-p0@velocipede"
#
# Uncomment following line if you want options to be set only for given project.
#
# PROJECT_JRUBY_OPTS=( --1.9 )
#
# First we attempt to load the desired environment directly from the environment
# file. This is very fast and efficient compared to running through the entire
# CLI and selector. If you want feedback on which environment was used then
# insert the word 'use' after --create as this triggers verbose mode.
#
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
then
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
fi
else
# If the environment file has not yet been created, use the RVM CLI to select.
if ! rvm --create use "$environment_id"
then
echo "Failed to create RVM environment '${environment_id}'."
return 1
fi
fi
#
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
# it be automatically loaded. Uncomment the following and adjust the filename if
# necessary.
#
# filename=".gems"
# if [[ -s "$filename" ]]
# then
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
# fi
# If you use bundler, this might be useful to you:
# if command -v bundle && [[ -s Gemfile ]]
# then
# bundle install
# fi

43
Gemfile

@ -0,0 +1,43 @@
source 'https://rubygems.org'
gem 'rails', '3.2.1'
gem 'sqlite3', '~> 1.3.5'
gem 'devise', '~> 2.0.4'
gem 'haml-rails', '~> 0.3.4'
gem 'jquery-rails', '~> 2.0'
gem 'decent_exposure', '~> 1.0.1'
gem 'will_paginate', '~> 3.0.3'
gem 'bootstrap-will_paginate', '~> 0.0.6'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem "twitter-bootstrap-rails", "~> 2.0.3"
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer'
gem 'uglifier', '>= 1.0.3'
end
group :development, :test do
gem 'rspec-rails', '~> 2.8.1'
gem 'factory_girl_rails', '~> 1.2'
gem 'pry', '~> 0.9.8'
end
group :test do
gem 'shoulda-matchers', '~> 1.0.0'
gem 'capybara', '~> 1.1.2'
gem 'turnip', '~> 0.3.0'
gem 'database_cleaner'
gem 'launchy'
gem 'spork'
#guard dependency for Mac OS 10
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
gem 'guard-spork'
gem 'guard-rspec'
end

236
Gemfile.lock

@ -0,0 +1,236 @@
GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.1)
actionpack (= 3.2.1)
mail (~> 2.4.0)
actionpack (3.2.1)
activemodel (= 3.2.1)
activesupport (= 3.2.1)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.1)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
activemodel (3.2.1)
activesupport (= 3.2.1)
builder (~> 3.0.0)
activerecord (3.2.1)
activemodel (= 3.2.1)
activesupport (= 3.2.1)
arel (~> 3.0.0)
tzinfo (~> 0.3.29)
activeresource (3.2.1)
activemodel (= 3.2.1)
activesupport (= 3.2.1)
activesupport (3.2.1)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.3.2)
arel (3.0.2)
bcrypt-ruby (3.0.1)
bootstrap-will_paginate (0.0.9)
will_paginate
builder (3.0.4)
capybara (1.1.3)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
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)
commonjs (0.2.6)
database_cleaner (0.9.1)
decent_exposure (1.0.2)
devise (2.0.4)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
railties (~> 3.1)
warden (~> 1.1.1)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
factory_girl (2.6.4)
activesupport (>= 2.3.9)
factory_girl_rails (1.7.0)
factory_girl (~> 2.6.0)
railties (>= 3.0.0)
ffi (1.1.5)
gherkin (2.11.5)
json (>= 1.4.6)
guard (1.5.4)
listen (>= 0.4.2)
lumberjack (>= 1.0.2)
pry (>= 0.9.10)
thor (>= 0.14.6)
guard-rspec (1.2.1)
guard (>= 1.1)
guard-spork (1.2.3)
childprocess (>= 0.2.3)
guard (>= 1.1)
spork (>= 0.8.4)
sys-proctable
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)
hike (1.2.1)
i18n (0.6.1)
journey (1.0.4)
jquery-rails (2.1.3)
railties (>= 3.1.0, < 5.0)
thor (~> 0.14)
json (1.7.5)
launchy (2.1.2)
addressable (~> 2.3)
less (2.2.2)
commonjs (~> 0.2.6)
less-rails (2.2.6)
actionpack (>= 3.1)
less (~> 2.2.0)
libv8 (3.3.10.4)
libwebsocket (0.1.5)
addressable
listen (0.5.3)
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)
multi_json (1.3.7)
nokogiri (1.5.5)
orm_adapter (0.0.7)
polyglot (0.3.3)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.1)
actionmailer (= 3.2.1)
actionpack (= 3.2.1)
activerecord (= 3.2.1)
activeresource (= 3.2.1)
activesupport (= 3.2.1)
bundler (~> 1.0)
railties (= 3.2.1)
railties (3.2.1)
actionpack (= 3.2.1)
activesupport (= 3.2.1)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rb-fsevent (0.9.2)
rdoc (3.12)
json (~> 1.4)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
rspec-mocks (~> 2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
rspec-rails (2.8.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.8.0)
rubyzip (0.9.9)
sass (3.2.3)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
selenium-webdriver (2.26.0)
childprocess (>= 0.2.5)
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
shoulda-matchers (1.0.0)
slop (3.3.3)
spork (0.9.2)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.6)
sys-proctable (0.9.2)
therubyracer (0.10.2)
libv8 (~> 3.3.10)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
turnip (0.3.1)
gherkin (>= 2.5)
rspec (~> 2.0)
twitter-bootstrap-rails (2.0.9)
actionpack (>= 3.1)
less-rails (~> 2.2.2)
railties (>= 3.1)
therubyracer (~> 0.10.1)
tzinfo (0.3.35)
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
warden (1.1.1)
rack (>= 1.0)
will_paginate (3.0.3)
xpath (0.1.4)
nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
bootstrap-will_paginate (~> 0.0.6)
capybara (~> 1.1.2)
coffee-rails (~> 3.2.1)
database_cleaner
decent_exposure (~> 1.0.1)
devise (~> 2.0.4)
factory_girl_rails (~> 1.2)
guard-rspec
guard-spork
haml-rails (~> 0.3.4)
jquery-rails (~> 2.0)
launchy
pry (~> 0.9.8)
rails (= 3.2.1)
rb-fsevent
rspec-rails (~> 2.8.1)
sass-rails (~> 3.2.3)
shoulda-matchers (~> 1.0.0)
spork
sqlite3 (~> 1.3.5)
turnip (~> 0.3.0)
twitter-bootstrap-rails (~> 2.0.3)
uglifier (>= 1.0.3)
will_paginate (~> 3.0.3)

37
Guardfile

@ -0,0 +1,37 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch('config/environments/test.rb')
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb') { :rspec }
watch('test/test_helper.rb') { :test_unit }
watch(%r{features/support/}) { :cucumber }
watch(%r{^spec/support/.+\.rb$})
end
guard 'rspec', :version => 2, :cli => "--drb", :all_on_start => false, :all_after_pass => false do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_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{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end

14
README.md

@ -0,0 +1,14 @@
# Developer Setup
1. use rvm
1. allow the .rvmrc file
1. `gem install bundler`
1. `bundle`
1. `rake db:create db:migrate db:seed`
1. `rake`
1. `rails s`
## Mailcatcher
Use mailcatcher to see what emails look like in development.
Follow the instructions from http://mailcatcher.me/ to create an rvm wrapper so you don't install it all over your gemsets

27
Rakefile

@ -0,0 +1,27 @@
#!/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.
Rake::TaskManager.class_eval do
def remove_task(task_name)
@tasks.delete(task_name.to_s)
end
end
require File.expand_path('../config/application', __FILE__)
Velocipede::Application.load_tasks
namespace :spec do
desc 'Run all acceptance specs'
RSpec::Core::RakeTask.new(:acceptance => 'db:test:prepare') do |t|
t.pattern = '**/*.feature'
end
end
Rake.application.remove_task 'spec'
desc 'Run all specs'
RSpec::Core::RakeTask.new(:spec => 'db:test:prepare') do |t|
t.pattern = '**/*{_spec.rb,.feature}'
end

BIN
app/assets/images/rails.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

16
app/assets/javascripts/application.js

@ -0,0 +1,16 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require_tree .

4
app/assets/javascripts/bootstrap.js.coffee

@ -0,0 +1,4 @@
jQuery ->
$("a[rel=popover]").popover()
$(".tooltip").tooltip()
$("a[rel=tooltip]").tooltip()

15
app/assets/javascripts/examples.js.coffee.sample

@ -0,0 +1,15 @@
# 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/
jQuery ->
$('form').on 'click', '.remove_fields', (event) ->
$(this).prev('input[type=hidden]').val('1')
$(this).closest('fieldset').hide()
event.preventDefault()
$('form').on 'click', '.add_fields', (event) ->
time = new Date().getTime()
regexp = new RegExp($(this).data('id'), 'g')
$(this).before($(this).data('fields').replace(regexp, time))
event.preventDefault()

13
app/assets/stylesheets/application.css

@ -0,0 +1,13 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/

17
app/assets/stylesheets/bootstrap_and_overrides.css.less

@ -0,0 +1,17 @@
@import "twitter/bootstrap/bootstrap";
@import "twitter/bootstrap/responsive";
// Set the correct sprite paths
@iconSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings.png');
@iconWhiteSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings-white.png');
// Your custom LESS stylesheets goes here
//
// Since bootstrap was imported above you have access to its mixins which
// you may use and inherit here
//
// If you'd like to override bootstrap's own variables, you can do so here as well
// See http://twitter.github.com/bootstrap/less.html for their names and documentation
//
// Example:
// @linkColor: #ff0000;

3
app/controllers/application_controller.rb

@ -0,0 +1,3 @@
class ApplicationController < ActionController::Base
protect_from_forgery
end

3
app/controllers/authenticated_controller.rb

@ -0,0 +1,3 @@
class AuthenticatedController < ApplicationController
before_filter :authenticate_user!
end

9
app/controllers/site_controller.rb

@ -0,0 +1,9 @@
class SiteController < ApplicationController
def index
respond_to do |format|
format.html
end
end
end

36
app/controllers/team_controller.example

@ -0,0 +1,36 @@
class TeamsController < AuthenticatedController
expose(:team) do
if params[:id]
Team.find(params[:id])
elsif params[:team]
Team.new(params[:team])
else
Team.new(:max_members => 16)
end
end
expose(:teams) { Team.order('lower(name)').paginate(:page => params[:page]) }
def index
end
def show
end
def new
end
def create
team.captain = current_user
if team.save
redirect_to teams_url
else
render :new
end
end
def join
current_user.teams << team
redirect_to team
end
end

10
app/helpers/application_helper.rb

@ -0,0 +1,10 @@
module ApplicationHelper
def link_to_add_fields(name, f, association)
new_object = f.object.send(association).klass.new
id = new_object.object_id
fields = f.fields_for(association, new_object, child_index: id) do |builder|
render(association.to_s.singularize + "_fields", f: builder)
end
link_to(name, '#', id: "add_#{association.to_s.singularize}" , class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")})
end
end

0
app/mailers/.gitkeep

0
app/models/.gitkeep

17
app/models/team.example

@ -0,0 +1,17 @@
class Team < ActiveRecord::Base
attr_accessible :name, :max_members, :private_team
belongs_to :captain, :class_name => 'User'
has_many :team_memberships
has_many :members, :through => :team_memberships, :source => :user
validates :name, :presence => true, :uniqueness => true, :length => { :minimum => 3 }
validates :max_members, :presence => true, :numericality => { :only_integer => true, :greater_than => 0 }
validates :captain, :presence => true
self.per_page = 15
def to_s
"#{name}#{private_team? ? '*' : ''}"
end
end

18
app/models/team_membership.example

@ -0,0 +1,18 @@
class TeamMembership < ActiveRecord::Base
belongs_to :team
belongs_to :user
validates :user, :presence => true
validates :team, :presence => true
validates :user_id, :uniqueness => { :scope => :team_id }
validate :no_captains_allowed
private
def no_captains_allowed
if user.present? && team.present? && team.captain == user
errors.add(:user, "Captain is already a member.")
end
end
end

17
app/models/user.rb

@ -0,0 +1,17 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :lockable #TODO ,:confirmable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me,
:first_name, :last_name, :nickname
validates :first_name, :presence => true
validates :last_name, :presence => true
def to_s
"#{first_name} #{last_name}"
end
end

25
app/views/devise/_links.erb

@ -0,0 +1,25 @@
<%- if controller_name != 'sessions' %>
<%= link_to "Sign in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>

12
app/views/devise/confirmations/new.html.erb

@ -0,0 +1,12 @@
<h2>Resend confirmation instructions</h2>
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.submit "Resend confirmation instructions" %></div>
<% end %>
<%= render "links" %>

5
app/views/devise/mailer/confirmation_instructions.html.erb

@ -0,0 +1,5 @@
<p>Welcome <%= @resource.email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>

8
app/views/devise/mailer/reset_password_instructions.html.erb

@ -0,0 +1,8 @@
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

7
app/views/devise/mailer/unlock_instructions.html.erb

@ -0,0 +1,7 @@
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>

16
app/views/devise/passwords/edit.html.erb

@ -0,0 +1,16 @@
<h2>Change your password</h2>
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
<div><%= f.label :password, "New password" %><br />
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.submit "Change my password" %></div>
<% end %>
<%= render "links" %>

12
app/views/devise/passwords/new.html.erb

@ -0,0 +1,12 @@
<h2>Forgot your password?</h2>
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.submit "Send me reset password instructions" %></div>
<% end %>
<%= render "links" %>

25
app/views/devise/registrations/edit.html.erb

@ -0,0 +1,25 @@
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, :autocomplete => "off" %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password %></div>
<div><%= f.submit "Update" %></div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
<%= link_to "Back", :back %>

29
app/views/devise/registrations/new.html.haml

@ -0,0 +1,29 @@
%h2 Sign up
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= devise_error_messages!
%div
= f.label :first_name
%br/
= f.text_field :first_name
%div
= f.label :last_name
%br/
= f.text_field :last_name
%div
= f.label :nickname
%br/
= f.text_field :nickname
%div
= f.label :email
%br/
= f.email_field :email
%div
= f.label :password
%br/
= f.password_field :password
%div
= f.label :password_confirmation
%br/
= f.password_field :password_confirmation
%div= f.submit "Sign up"
= render "links"

28
app/views/devise/sessions/new.html.erb

@ -0,0 +1,28 @@
<h2>Sign in</h2>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<% if devise_mapping.rememberable? -%>
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
<% end -%>
<div><%= f.submit "Sign in" %></div>
<% end %>
<%= render "links" %>
<% if Rails.env.development? %>
<% User.all.each do |user| %>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<%= f.hidden_field :email, :value => user.email %></div>
<%= f.hidden_field :password, :value => 'password' %></div>
<div><%= f.submit "Sign in as #{user.email}" %></div>
<% end %>
<% end %>
<% end %>

12
app/views/devise/unlocks/new.html.erb

@ -0,0 +1,12 @@
<h2>Resend unlock instructions</h2>
<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.submit "Resend unlock instructions" %></div>
<% end %>
<%= render "links" %>

49
app/views/layouts/application.html.haml

@ -0,0 +1,49 @@
!!! 5
%html{:lang => "en"}
%head
%meta{:charset => "utf-8"}/
%title= content_for?(:title) ? yield(:title) : "Mash"
= csrf_meta_tags
/[if lt IE 9]
= javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js"
:css
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
= stylesheet_link_tag "application", :media => "all"
%body
.navbar.navbar-fixed-top
.navbar-inner
.container
= link_to 'Mash', root_path, :class => 'brand'
.container.nav-collapse
%ul.nav
%li= link_to "Home", root_path
%ul.nav.pull-right
- if user_signed_in?
%li#logged_in_as
= link_to "Hello #{current_user.first_name} #{current_user.last_name}", edit_user_registration_path
%li#logout
= link_to 'Logout', destroy_user_session_path, :method => :delete
- else
%li#login
= link_to 'Login', new_user_session_path
%li#register
= link_to 'Register', new_user_registration_path
.container
.content
- if flash[:notice]
%p{:class => 'notice'}= flash[:notice]
- if flash[:alert]
%p{:class => 'alert'}= flash[:alert]
.row
.span13
= yield
%footer
%p &copy; Rails App Template 2012
= javascript_include_tag "application"

1
app/views/site/index.html.haml

@ -0,0 +1 @@
Do the monster mash!

9
app/views/teams_examples/index.html.haml

@ -0,0 +1,9 @@
%p
= link_to 'Create a Team', new_team_path, :class => 'btn btn-large btn-primary'
.teams
- teams.each do |team|
%h3.team= link_to team, team
= will_paginate teams

21
app/views/teams_examples/new.html.haml

@ -0,0 +1,21 @@
= form_for team, :html => { :class => 'form-horizontal' } do |f|
.control-group{:class => team.errors[:name].present? ? 'error' : ''}
= f.label :name, 'Name', :class => 'control-label'
.controls
= f.text_field :name
- if team.errors[:name].present?
.help-inline= team.errors[:name].join(', ')
.control-group{:class => team.errors[:max_members].present? ? 'error' : ''}
= f.label :max_members, 'Max members', :class => 'control-label'
.controls
= f.text_field :max_members
- if team.errors[:max_members].present?
.help-inline= team.errors[:max_members].join(', ')
.control-group{:class => team.errors[:private_team].present? ? 'error' : ''}
= f.label :private_team, 'Private team?', :class => 'control-label'
.controls
= f.check_box :private_team
- if team.errors[:private_team].present?
.help-inline= team.errors[:private_team].join(', ')
.form-actions
= f.submit 'Create Team', :class => 'btn btn-primary'

11
app/views/teams_examples/show.html.haml

@ -0,0 +1,11 @@
%h3= team
%ul.members
%li= team.captain
- team.members.each do |member|
%li= member
- unless current_user.is_a_member_of?(team)
= form_tag join_team_path(team) do
= submit_tag 'Join team', :class => 'btn'

4
config.ru

@ -0,0 +1,4 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Velocipede::Application

66
config/application.rb

@ -0,0 +1,66 @@
require File.expand_path('../boot', __FILE__)
require 'rails/all'
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 Velocipede
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}/extras)
# 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 ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# 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 = :de
# 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]
config.generators do |g|
g.helper false
g.test_framework :rspec,
:view_specs => false,
:routing_specs => false
end
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
# config.active_record.whitelist_attributes = 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

6
config/boot.rb

@ -0,0 +1,6 @@
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'])

25
config/database.yml

@ -0,0 +1,25 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# 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:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000

5
config/environment.rb

@ -0,0 +1,5 @@
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Velocipede::Application.initialize!

44
config/environments/development.rb

@ -0,0 +1,44 @@
Velocipede::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
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# 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
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
#Devise gem uses mailer
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
# use mailcatcher (http://mailcatcher.me/) to test emails in development
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
end

68
config/environments/production.rb

@ -0,0 +1,68 @@
Velocipede::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 Rails.root.join("public/assets")
# 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)
# config.assets.precompile += %w( search.js )
# TODO set to host
# 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

37
config/environments/test.rb

@ -0,0 +1,37 @@
Velocipede::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
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
end

7
config/initializers/backtrace_silencers.rb

@ -0,0 +1,7 @@
# 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!

223
config/initializers/devise.rb

@ -0,0 +1,223 @@
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "velocipede@gmail.com"
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
# Automatically apply schema changes in tableless databases
config.apply_schema = false
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
require 'devise/orm/active_record'
# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating a user. The default is
# just :email. You can configure it to use [:username, :subdomain], so for
# authenticating a user, both parameters are required. Remember that those
# parameters are used only when authenticating and not when retrieving from
# session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present.
# config.authentication_keys = [ :email ]
# Configure parameters from the request object used for authentication. Each entry
# given should be a request method and it will automatically be passed to the
# find_for_authentication method and considered in your model lookup. For instance,
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
# The same considerations mentioned for authentication_keys also apply to request_keys.
# config.request_keys = []
# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [ :email ]
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [ :email ]
# Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the
# given strategies, for example, `config.params_authenticatable = [:database]` will
# enable it only for database (email + password) authentication.
# config.params_authenticatable = true
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
# It can be set to an array that will enable http authentication only for the
# given strategies, for example, `config.http_authenticatable = [:token]` will
# enable it only for token authentication.
# config.http_authenticatable = false
# If http headers should be returned for AJAX requests. True by default.
# config.http_authenticatable_on_xhr = true
# The realm used in Http Basic Authentication. "Application" by default.
# config.http_authentication_realm = "Application"
# It will change confirmation, password recovery and other workflows
# to behave the same regardless if the e-mail provided was right or wrong.
# Does not affect registerable.
# config.paranoid = true
# By default Devise will store the user in session. You can skip storage for
# :http_auth and :token_auth by adding those symbols to the array below.
# Notice that if you are skipping storage for all authentication paths, you
# may want to disable generating routes to Devise's sessions controller by
# passing :skip => :sessions to `devise_for` in your config/routes.rb
config.skip_session_storage = [:http_auth]
# ==> Configuration for :database_authenticatable
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
# using other encryptors, it sets how many times you want the password re-encrypted.
#
# Limiting the stretches to just one in testing will increase the performance of
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
# a value less than 10 in other environments.
config.stretches = Rails.env.test? ? 1 : 10
# Setup a pepper to generate the encrypted password.
# config.pepper = "bb93785f2f4fa5d751943024b63e63ec239e2de6b975d14c919083a3ef922f0c5eced07e17291ca08225c212a9fbd4738dfe4bc76daa1bc70bc950e526d2fea5"
# ==> Configuration for :confirmable
# A period that the user is allowed to access the website even without
# confirming his account. For instance, if set to 2.days, the user will be
# able to access the website for two days without confirming his account,
# access will be blocked just in the third day. Default is 0.days, meaning
# the user cannot access the website without confirming his account.
# config.allow_unconfirmed_access_for = 2.days
# If true, requires any email changes to be confirmed (exctly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed new email is stored in
# unconfirmed email column, and copied to email column on successful confirmation.
config.reconfirmable = true
# Defines which key will be used when confirming an account
# config.confirmation_keys = [ :email ]
# ==> Configuration for :rememberable
# The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks
# If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false
# If true, uses the password salt as remember token. This should be turned
# to false if you are not using database authenticatable.
config.use_salt_as_remember_token = true
# Options to be passed to the created cookie. For instance, you can set
# :secure => true in order to force SSL only cookies.
# config.cookie_options = {}
# ==> Configuration for :validatable
# Range for password length. Default is 6..128.
# config.password_length = 6..128
# Email regex used to validate email formats. It simply asserts that
# an one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
# config.email_regexp = /\A[^@]+@[^@]+\z/
# ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this
# time the user will be asked for credentials again. Default is 30 minutes.
# config.timeout_in = 30.minutes
# ==> Configuration for :lockable
# Defines which strategy will be used to lock an account.
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
# :none = No lock strategy. You should handle locking by yourself.
# config.lock_strategy = :failed_attempts
# Defines which key will be used when locking and unlocking an account
# config.unlock_keys = [ :email ]
# Defines which strategy will be used to unlock an account.
# :email = Sends an unlock link to the user email
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
# :both = Enables both strategies
# :none = No unlock strategy. You should handle unlocking by yourself.
# config.unlock_strategy = :both
# Number of authentication tries before locking an account if lock_strategy
# is failed attempts.
# config.maximum_attempts = 20
# Time interval to unlock the account if :time is enabled as unlock_strategy.
# config.unlock_in = 1.hour
# ==> Configuration for :recoverable
#
# Defines which key will be used when recovering the password for an account
# config.reset_password_keys = [ :email ]
# Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to
# change their passwords.
config.reset_password_within = 6.hours
# ==> Configuration for :encryptable
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
# REST_AUTH_SITE_KEY to pepper)
# config.encryptor = :sha512
# ==> Configuration for :token_authenticatable
# Defines name of the authentication token params key
# config.token_authentication_key = :auth_token
# ==> Scopes configuration
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "users/sessions/new". It's turned off by default because it's slower if you
# are using only default views.
# config.scoped_views = false
# Configure the default scope given to Warden. By default it's the first
# devise role declared in your routes (usually :user).
# config.default_scope = :user
# Configure sign_out behavior.
# Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
# The default is true, which means any logout action will sign out all active scopes.
# config.sign_out_all_scopes = true
# ==> Navigation configuration
# Lists the formats that should be treated as navigational. Formats like
# :html, should redirect to the sign in page when the user does not have
# access, but formats like :xml or :json, should return 401.
#
# If you have any extra navigational formats, like :iphone or :mobile, you
# should add them to the navigational formats lists.
#
# The "*/*" below is required to match Internet Explorer requests.
# config.navigational_formats = ["*/*", :html]
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or
# change the failure app, you can configure them inside the config.warden block.
#
# config.warden do |manager|
# manager.intercept_401 = false
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
# end
end

15
config/initializers/inflections.rb

@ -0,0 +1,15 @@
# 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

5
config/initializers/mime_types.rb

@ -0,0 +1,5 @@
# 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

7
config/initializers/secret_token.rb

@ -0,0 +1,7 @@
# 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.
Velocipede::Application.config.secret_token = 'cd4ae1e008bba64bfe79f64167e769534386892a48163ecfb114ee65ef7e5d2548ba1194b5ee08f52998622b6aad39390db2029fdf3143bdea3bb59bf23f97be'

8
config/initializers/session_store.rb

@ -0,0 +1,8 @@
# Be sure to restart your server when you modify this file.
Velocipede::Application.config.session_store :cookie_store, key: '_mash_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")
# Velocipede::Application.config.session_store :active_record_store

9
config/initializers/setup_mail.rb

@ -0,0 +1,9 @@
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "velocipede",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}

14
config/initializers/wrap_parameters.rb

@ -0,0 +1,14 @@
# 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

57
config/locales/devise.en.yml

@ -0,0 +1,57 @@
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
en:
errors:
messages:
expired: "has expired, please request a new one"
not_found: "not found"
already_confirmed: "was already confirmed, please try signing in"
not_locked: "was not locked"
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"
devise:
failure:
already_authenticated: 'You are already signed in.'
unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.'
invalid: 'Invalid email or password.'
invalid_token: 'Invalid authentication token.'
timeout: 'Your session expired, please sign in again to continue.'
inactive: 'Your account was not activated yet.'
sessions:
signed_in: 'Signed in successfully.'
signed_out: 'Signed out successfully.'
passwords:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
updated: 'Your password was changed successfully. You are now signed in.'
updated_not_active: 'Your password was changed successfully.'
send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
confirmations:
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
confirmed: 'Your account was successfully confirmed. You are now signed in.'
registrations:
signed_up: 'Welcome! You have signed up successfully.'
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
updated: 'You updated your account successfully.'
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
unlocks:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
omniauth_callbacks:
success: 'Successfully authorized from %{kind} account.'
failure: 'Could not authorize you from %{kind} because "%{reason}".'
mailer:
confirmation_instructions:
subject: 'Confirmation instructions'
reset_password_instructions:
subject: 'Reset password instructions'
unlock_instructions:
subject: 'Unlock Instructions'

5
config/locales/en.yml

@ -0,0 +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"

71
config/routes.rb

@ -0,0 +1,71 @@
Velocipede::Application.routes.draw do
devise_for :users
# The priority is based upon order of creation:
# first created -> highest priority.
match 'site/index' => 'site#index'
resources :teams, :except => [:edit, :delete] do
member do
post :join
end
end
resources :clues
resources :maps
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
root :to => 'site#index'
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
end

49
db/migrate/20120227024410_devise_create_users.rb

@ -0,0 +1,49 @@
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Encryptable
# t.string :password_salt
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
## Token authenticatable
# t.string :authentication_token
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
end

9
db/migrate/20120227040841_add_lockable_to_user.rb

@ -0,0 +1,9 @@
class AddLockableToUser < ActiveRecord::Migration
def change
change_table :users do |t|
t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
t.string :unlock_token # Only if unlock strategy is :email or :both
t.datetime :locked_at
end
end
end

7
db/migrate/20120301124238_add_names_to_user.rb

@ -0,0 +1,7 @@
class AddNamesToUser < ActiveRecord::Migration
def change
add_column :users, :first_name, :string, :null => false, :default => ''
add_column :users, :last_name, :string, :null => false, :default => ''
add_column :users, :nickname, :string
end
end

17
db/migrate/20120308031328_create_teams.example

@ -0,0 +1,17 @@
class CreateTeams < ActiveRecord::Migration
def up
create_table :teams do |t|
t.string :name, :null => false, :default => ''
t.integer :max_members, :null => false, :default => 16
t.integer :captain_id, :null => false
end
add_index :teams, :name, :unique => true
add_index :teams, :captain_id
end
def down
remove_index :teams, :column => :captain_id
remove_index :teams, :column => :name
drop_table :teams
end
end

5
db/migrate/20120325023452_add_private_team_to_team.example

@ -0,0 +1,5 @@
class AddPrivateTeamToTeam < ActiveRecord::Migration
def change
add_column :teams, :private_team, :boolean, :default => false, :null => false
end
end

17
db/migrate/20120325031259_create_team_memberships.example

@ -0,0 +1,17 @@
class CreateTeamMemberships < ActiveRecord::Migration
def up
create_table :team_memberships do |t|
t.references :user, :null => false
t.references :team, :null => false
t.timestamps
end
add_index :team_memberships, :user_id
add_index :team_memberships, :team_id
end
def down
remove_index :team_memberships, :column => :team_id
remove_index :team_memberships, :column => :user_id
drop_table :team_memberships
end
end

61
db/schema.rb

@ -0,0 +1,61 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20121104211300) do
# create_table "team_memberships", :force => true do |t|
# t.integer "user_id", :null => false
# t.integer "team_id", :null => false
# t.datetime "created_at", :null => false
# t.datetime "updated_at", :null => false
# end
# add_index "team_memberships", ["team_id"], :name => "index_team_memberships_on_team_id"
# add_index "team_memberships", ["user_id"], :name => "index_team_memberships_on_user_id"
# create_table "teams", :force => true do |t|
# t.string "name", :default => "", :null => false
# t.integer "max_members", :default => 16, :null => false
# t.integer "captain_id", :null => false
# t.boolean "private_team", :default => false, :null => false
# end
# add_index "teams", ["captain_id"], :name => "index_teams_on_captain_id"
# add_index "teams", ["name"], :name => "index_teams_on_name", :unique => true
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "failed_attempts", :default => 0
t.string "unlock_token"
t.datetime "locked_at"
t.string "first_name", :default => "", :null => false
t.string "last_name", :default => "", :null => false
t.string "nickname"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
end

11
db/seeds.rb

@ -0,0 +1,11 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
if Rails.env.development?
FactoryGirl.create(:user)
end

1
doc/README_FOR_APP

@ -0,0 +1 @@
# No API yet

0
lib/assets/.gitkeep

0
lib/tasks/.gitkeep

0
log/.gitkeep

26
public/404.html

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>The page you were looking for doesn't exist (404)</title>
<style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog {
width: 25em;
padding: 0 4em;
margin: 4em auto 0 auto;
border: 1px solid #ccc;
border-right-color: #999;
border-bottom-color: #999;
}
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
</style>
</head>
<body>
<!-- This file lives in public/404.html -->
<div class="dialog">
<h1>The page you were looking for doesn't exist.</h1>
<p>You may have mistyped the address or the page may have moved.</p>
</div>
</body>
</html>

26
public/422.html

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>The change you wanted was rejected (422)</title>
<style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog {
width: 25em;
padding: 0 4em;
margin: 4em auto 0 auto;
border: 1px solid #ccc;
border-right-color: #999;
border-bottom-color: #999;
}
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
</style>
</head>
<body>
<!-- This file lives in public/422.html -->
<div class="dialog">
<h1>The change you wanted was rejected.</h1>
<p>Maybe you tried to change something you didn't have access to.</p>
</div>
</body>
</html>

25
public/500.html

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>We're sorry, but something went wrong (500)</title>
<style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog {
width: 25em;
padding: 0 4em;
margin: 4em auto 0 auto;
border: 1px solid #ccc;
border-right-color: #999;
border-bottom-color: #999;
}
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
</style>
</head>
<body>
<!-- This file lives in public/500.html -->
<div class="dialog">
<h1>We're sorry, but something went wrong.</h1>
</div>
</body>
</html>

0
public/favicon.ico

5
public/robots.txt

@ -0,0 +1,5 @@
# 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: /

6
script/rails

@ -0,0 +1,6 @@
#!/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'

30
spec/acceptance/create_a_team.feature.example

@ -0,0 +1,30 @@
Feature: Create a team
In order to gather my friends to participate in a hunt
As a user
I want to create a team
Background:
Given a user "test@example.com" with password "password"
When I login with email "test@example.com" and password "password"
And I go to create a new team
Scenario: View the create a team form
Then I should see the create a team form
Scenario: Errors on form are displayed
When I submit the new team form
Then I should see an error message about the team name
Scenario: Created team is in list
When I fill out the team form with team name "Happy Trackers"
And I submit the new team form
And I go to the team list
Then I should see "Happy Trackers" in the team list
Scenario: Create a private team
When I fill out the team form with team name "Happy Trackers"
And I check the box to make my team private
And I submit the new team form
And I go to the team list
Then the team list should be:
| Happy Trackers* |

34
spec/acceptance/list_teams.feature.example

@ -0,0 +1,34 @@
Feature: List teams
In order to see the teams
As a user
I want to see them sorted by name and paginated
Background:
Given a user "test@example.com" with password "password"
When I login with email "test@example.com" and password "password"
Scenario: Team list paginated to 15
Given 20 teams exist
And I go to the team list
Then I should see 15 teams in the team list
When I go to the next page
Then I should see 5 teams in the team list
Scenario: Team list should be alphabetical by name
Given the following teams exist:
| name |
| Bad |
| Car |
| Art |
| Door |
| ear |
| apple |
And I go to the team list
Then the team list should be:
| apple |
| Art |
| Bad |
| Car |
| Door |
| ear |

15
spec/acceptance/steps/common_steps.rb

@ -0,0 +1,15 @@
step "show me the page" do
save_and_open_page
end
step "I click the link :link_text" do |link_text|
page.click_link link_text
end
step "I click the button :button_text" do |button_text|
page.click_button button_text
end
step "I fill out the form with :model :field_name :field_value" do |model, field_name, field_value|
page.fill_in "#{model}_#{field_name}", :with => field_value
end

40
spec/acceptance/steps/factory_girl_steps.rb

@ -0,0 +1,40 @@
FactoryGirl.factories.each do |factory|
factory.compile
factory.human_names.each do |human_name|
step "the following #{human_name} exists:" do |table|
table.hashes.each do |human_hash|
attributes = convert_human_hash_to_attribute_hash(human_hash, factory.associations)
FactoryGirl.create(factory.name, attributes)
end
end
step "the following #{human_name.pluralize} exist:" do |table|
table.hashes.each do |human_hash|
attributes = convert_human_hash_to_attribute_hash(human_hash, factory.associations)
FactoryGirl.create(factory.name, attributes)
end
end
step "a(n) #{human_name} exists" do
FactoryGirl.create(factory.name)
end
step ":count #{human_name.pluralize} exist" do |count|
FactoryGirl.create_list(factory.name, count.to_i)
end
if factory.build_class.respond_to?(:columns)
factory.build_class.columns.each do |column|
name = column.respond_to?(:name) ? column.name : column.to_s
human_column_name = name.downcase.gsub('_', ' ')
step "a(n) #{human_name} exists with a(n) #{human_column_name} of :value" do |value|
FactoryGirl.create(factory.name, name => value)
end
step ":count #{human_name.pluralize} exist with a(n) #{human_column_name} of :value" do |count, value|
FactoryGirl.create_list(factory.name, count.to_i, name => value)
end
end
end
end
end

7
spec/acceptance/steps/login_steps.rb

@ -0,0 +1,7 @@
step "I login with email :email and password :password" do |email, password|
visit new_user_session_path
fill_in 'Email', :with => email
fill_in 'Password', :with => password
click_button 'Sign in'
page.should have_content("Signed in successfully.")
end

3
spec/acceptance/steps/pagination_steps.rb

@ -0,0 +1,3 @@
step "I go to the next page" do
page.find('.pagination li.next a').click
end

72
spec/acceptance/steps/team_steps.example

@ -0,0 +1,72 @@
step "I go to create a new team" do
visit new_team_path
end
step 'I go to the team list' do
visit teams_path
end
step "I should see the create a team form" do
page.should have_field 'Name'
page.should have_field 'Max members', :with => '16'
end
step "I submit the new team form" do
page.find('form#new_team').find('input[type=submit]').click
end
step "I fill out the team form with team name :team_name" do |team_name|
page.fill_in 'Name', :with => team_name
end
step "I check the box to make my team private" do
page.check "Private team?"
end
step 'I should see an error message about the team name' do
within 'form#new_team' do
page.should have_content "can't be blank"
end
end
step 'I should see :team_name in the team list' do |team_name|
within '.teams' do
page.should have_content(team_name)
end
end
step 'I should see :count teams in the team list' do |count|
within '.teams' do
page.all('h3.team').count.should == count.to_i
end
end
step 'the team list should be:' do |table|
within '.teams' do
actual = page.all('h3.team').collect { |h3| [h3.text] }
table.raw.should == actual
end
end
step 'I should have the option of joining the team' do
page.should have_button 'Join team'
end
step 'I should not have the option of joining the team' do
page.should have_no_button 'Join team'
end
step ':user_email should be in the team member list' do |user_email|
user = User.find_by_email(user_email)
assert user, "Could not find user by email: #{user_email}"
within '.members' do
page.should have_content user.to_s
end
end
step ':user_email captains the team :team_name' do |user_email, team_name|
user = User.find_by_email(user_email)
assert user, "Could not find user by email: #{user_email}"
FactoryGirl.create(:team, :name => team_name, :captain => user)
end

3
spec/acceptance/steps/user_steps.rb

@ -0,0 +1,3 @@
step "a user :email with password :password" do |email, password|
FactoryGirl.create(:user, :email => email, :password => password)
end

5
spec/controllers/maps_controller_spec.example

@ -0,0 +1,5 @@
require 'spec_helper'
describe MapsController do
end

14
spec/factories.rb

@ -0,0 +1,14 @@
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "user_#{n}@example.com" }
password 'password'
password_confirmation { password }
first_name 'Michael'
last_name 'Scott'
end
# factory :team do
# sequence(:name) { |n| "mash it #{n} times" }
# association :captain, :factory => :user
# end
end

10
spec/factories/maps.example

@ -0,0 +1,10 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :map do
name "MyString"
creator_id ""
max_teams ""
max_members ""
end
end

24
spec/models/team_membership_spec.example

@ -0,0 +1,24 @@
require 'spec_helper'
describe TeamMembership do
describe 'membership validations' do
let(:team) { create(:team) }
let(:user) { create(:user) }
describe 'should require user and team' do
it { should have(1).error_on(:user) }
it { should have(1).error_on(:team) }
end
it 'should only allow a user to be a member once' do
TeamMembership.create(:user => user, :team => team)
second = TeamMembership.create(:user => user, :team => team)
second.should be_invalid
end
it 'should not allow a captain to become a member' do
membership = TeamMembership.create(:user => team.captain, :team => team)
membership.should be_invalid
end
end
end

45
spec/models/team_spec.example

@ -0,0 +1,45 @@
require 'spec_helper'
describe Team do
it 'should have a size of 16 by default' do
subject.max_members.should == 16
end
describe 'validations' do
it { should have(2).error_on(:name) }
context 'name' do
it 'should require atleast 3 characters' do
subject.name = 'hi'
subject.should have(1).error_on(:name)
end
it 'should not allow blank' do
subject.name = ''
subject.should have(2).error_on(:name)
end
it 'should not allow duplicated' do
team = FactoryGirl.create(:team)
subject.name = team.name
subject.should have(1).error_on(:name)
end
end
context 'max_members' do
it 'should not let it be 0' do
subject.max_members = 0
subject.should have(1).error_on(:max_members)
end
it 'should not let it be left empty' do
subject.max_members = ''
subject.should have(2).error_on(:max_members)
end
end
context 'captain' do
it 'should require a captain' do
subject.should have(1).error_on(:captain)
end
end
end
end

29
spec/models/user_spec.rb

@ -0,0 +1,29 @@
require 'spec_helper'
describe User do
describe 'validations' do
it { should have(1).error_on(:first_name) }
it { should have(1).error_on(:last_name) }
end
# describe 'is a member of team' do
# let(:user) { create(:user) }
# let(:team) { create(:team) }
# subject { user.is_a_member_of?(team) }
# context 'it not a member of the team' do
# it { should be_false }
# end
# context 'is a member of the team already' do
# before { user.teams << team }
# it { should be_true }
# end
# context 'is the captain of the team' do
# let(:team) { create(:team, :captain => user) }
# it { should be_true }
# end
# end
end

45
spec/requests/devise/registrations_spec.rb

@ -0,0 +1,45 @@
require 'spec_helper'
describe "New User Registrations" do
it 'should have a link to sign up on the homepage' do
visit root_path
page.should have_link 'Register'
click_link 'Register'
current_path.should == new_user_registration_path
end
context 'registration page' do
before do
visit new_user_registration_path
end
it 'should have the additional user fields on the registration page' do
page.should have_field 'First name'
page.should have_field 'Last name'
page.should have_field 'Nickname'
page.should have_field 'Email'
page.should have_field 'Password'
page.should have_field 'Password confirmation'
page.should have_button 'Sign up'
end
context 'required non-devise fields' do
before do
fill_in 'Email', :with => 'FF@example.com'
fill_in 'Password', :with => 'password'
fill_in 'Password confirmation', :with => 'password'
end
it 'should require first name' do
fill_in 'Last name', :with => 'Footer'
click_button 'Sign up'
page.should have_content "First name can't be blank"
end
it 'should require last name' do
fill_in 'First name', :with => 'Frank'
click_button 'Sign up'
page.should have_content "Last name can't be blank"
end
end
end
end

119
spec/spec_helper.rb

@ -0,0 +1,119 @@
require 'rubygems'
require 'spork'
require 'rails'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
#Needed for Devise gem. Delay loading of loading of User model in routes.rb
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
# 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'
require 'capybara/rspec'
require 'turnip/capybara'
# 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
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with :truncation
end
config.before(:each) do
if Capybara.current_driver == Capybara.javascript_driver
DatabaseCleaner.strategy = :truncation
else
DatabaseCleaner.strategy = :transaction
end
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
# 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
config.include FactoryGirlStepHelpers
config.include FactoryGirl::Syntax::Methods
#allows :focus tag to only run specific tests
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end
end
Spork.each_run do
# This code will be run each time you run your specs.
#Reload Factories
#FYI make sure that Factories use strings instead of class constants
FactoryGirl.reload
end
# --- Instructions ---
# Sort the contents of this file into a Spork.prefork and a Spork.each_run
# block.
#
# The Spork.prefork block is run only once when the spork server is started.
# You typically want to place most of your (slow) initializer code in here, in
# particular, require'ing any 3rd-party gems that you don't normally modify
# during development.
#
# The Spork.each_run block is run each time you run your specs. In case you
# need to load files that tend to change during development, require them here.
# With Rails, your application modules are loaded automatically, so sometimes
# this block can remain empty.
#
# Note: You can modify files loaded *from* the Spork.each_run block without
# restarting the spork server. However, this file itself will not be reloaded,
# so if you change any of the code inside the each_run block, you still need to
# restart the server. In general, if you have non-trivial code in this file,
# it's advisable to move it into a separate file so you can easily edit it
# without restarting spork. (For example, with RSpec, you could move
# non-trivial code into a file spec/support/my_helper.rb, making sure that the
# spec/support/* files are require'd from inside the each_run block.)
#
# Any code that is left outside the two blocks will be run during preforking
# *and* during each_run -- that's probably not what you want.
#
# These instructions should self-destruct in 10 seconds. If they don't, feel
# free to delete them.

93
spec/support/factory_girl_step_helpers.rb

@ -0,0 +1,93 @@
module FactoryGirlStepHelpers
def convert_human_hash_to_attribute_hash(human_hash, associations = [])
HumanHashToAttributeHash.new(human_hash, associations).attributes
end
class HumanHashToAttributeHash
attr_reader :associations
def initialize(human_hash, associations)
@human_hash = human_hash
@associations = associations
end
def attributes(strategy = CreateAttributes)
@human_hash.inject({}) do |attribute_hash, (human_key, value)|
attributes = strategy.new(self, *process_key_value(human_key, value))
attribute_hash.merge({ attributes.key => attributes.value })
end
end
private
def process_key_value(key, value)
value = value.strip if value.is_a?(String)
[key.downcase.gsub(' ', '_').to_sym, value]
end
class AssociationManager
def initialize(human_hash_to_attributes_hash, key, value)
@human_hash_to_attributes_hash = human_hash_to_attributes_hash
@key = key
@value = value
end
def association
@human_hash_to_attributes_hash.associations.detect {|association| association.name == @key }
end
def association_instance
return unless association
if attributes_hash = nested_attribute_hash
factory.build_class.first(:conditions => attributes_hash.attributes(FindAttributes)) or
FactoryGirl.create(association.factory, attributes_hash.attributes)
end
end
private
def factory
FactoryGirl.factory_by_name(association.factory)
end
def nested_attribute_hash
attribute, value = @value.split(':', 2)
return if value.blank?
HumanHashToAttributeHash.new({ attribute => value }, factory.associations)
end
end
class AttributeStrategy
attr_reader :key, :value, :association_manager
def initialize(human_hash_to_attributes_hash, key, value)
@association_manager = AssociationManager.new(human_hash_to_attributes_hash, key, value)
@key = key
@value = value
end
end
class FindAttributes < AttributeStrategy
def initialize(human_hash_to_attributes_hash, key, value)
super
if association_manager.association
@key = "#{@key}_id"
@value = association_manager.association_instance.try(:id)
end
end
end
class CreateAttributes < AttributeStrategy
def initialize(human_hash_to_attributes_hash, key, value)
super
if association_manager.association
@value = association_manager.association_instance
end
end
end
end
end

0
vendor/assets/javascripts/.gitkeep

0
vendor/assets/stylesheets/.gitkeep

0
vendor/plugins/.gitkeep

Loading…
Cancel
Save