Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

new Rails app generated by rails3_devise_wizard

  • Loading branch information...
commit 4de124fdb287d6be90da74eec0aad80b60a7fb84 0 parents
Daniel Kehoe fortuity authored

Showing 62 changed files with 1,737 additions and 0 deletions. Show diff stats Hide diff stats

  1. +65 0 .gitignore
  2. +12 0 Gemfile
  3. +212 0 Gemfile.lock
  4. +8 0 README
  5. +59 0 README.textile
  6. +7 0 Rakefile
  7. +33 0 app/controllers/application_controller.rb
  8. +5 0 app/controllers/home_controller.rb
  9. +30 0 app/controllers/sessions_controller.rb
  10. +24 0 app/controllers/users_controller.rb
  11. +2 0  app/helpers/application_helper.rb
  12. +2 0  app/helpers/home_helper.rb
  13. +2 0  app/helpers/users_helper.rb
  14. +21 0 app/models/user.rb
  15. +4 0 app/views/home/index.html.erb
  16. +20 0 app/views/layouts/application.html.erb
  17. +12 0 app/views/shared/_navigation.html.erb
  18. +6 0 app/views/users/edit.html.erb
  19. +4 0 app/views/users/show.html.erb
  20. +4 0 config.ru
  21. +53 0 config/application.rb
  22. +6 0 config/boot.rb
  23. +8 0 config/cucumber.yml
  24. +5 0 config/environment.rb
  25. +26 0 config/environments/development.rb
  26. +49 0 config/environments/production.rb
  27. +35 0 config/environments/test.rb
  28. +7 0 config/initializers/backtrace_silencers.rb
  29. +2 0  config/initializers/generators.rb
  30. +10 0 config/initializers/inflections.rb
  31. +5 0 config/initializers/mime_types.rb
  32. +7 0 config/initializers/secret_token.rb
  33. +8 0 config/initializers/session_store.rb
  34. +5 0 config/locales/en.yml
  35. +23 0 config/mongoid.yml
  36. +72 0 config/routes.rb
  37. +9 0 db/seeds.rb
  38. +211 0 features/step_definitions/web_steps.rb
  39. +40 0 features/support/env.rb
  40. +33 0 features/support/paths.rb
  41. +39 0 features/support/selectors.rb
  42. 0  lib/tasks/.gitkeep
  43. +57 0 lib/tasks/cucumber.rake
  44. +26 0 public/404.html
  45. +26 0 public/422.html
  46. +26 0 public/500.html
  47. 0  public/favicon.ico
  48. 0  public/javascripts/.gitkeep
  49. 0  public/javascripts/application.js
  50. +16 0 public/javascripts/jquery.js
  51. +289 0 public/javascripts/rails.js
  52. +5 0 public/robots.txt
  53. 0  public/stylesheets/.gitkeep
  54. +20 0 public/stylesheets/application.css
  55. +10 0 script/cucumber
  56. +6 0 script/rails
  57. +12 0 spec/controllers/home_controller_spec.rb
  58. +12 0 spec/controllers/users_controller_spec.rb
  59. +5 0 spec/models/user_spec.rb
  60. +39 0 spec/spec_helper.rb
  61. +3 0  spec/support/mongoid.rb
  62. 0  vendor/plugins/.gitkeep
65 .gitignore
... ... @@ -0,0 +1,65 @@
  1 +#----------------------------------------------------------------------------
  2 +# Ignore these files when commiting to a git repository
  3 +#
  4 +# The original version of this file is found here:
  5 +# https://github.com/fortuity/rails3-gitignore/raw/master/gitignore.txt
  6 +#
  7 +# Corrections? Improvements? Create a GitHub issue:
  8 +# https://github.com/fortuity/rails3-gitignore/issues
  9 +#----------------------------------------------------------------------------
  10 +
  11 +# bundler state
  12 +/.bundle
  13 +/vendor/bundle/
  14 +
  15 +# minimal Rails specific artifacts
  16 +db/*.sqlite3
  17 +/log/*
  18 +tmp/*
  19 +
  20 +# various artifacts
  21 +**.war
  22 +*.rbc
  23 +*.sassc
  24 +.rspec
  25 +.sass-cache
  26 +/config/config.yml
  27 +/config/database.yml
  28 +/coverage.data
  29 +/coverage/
  30 +/db/*.javadb/
  31 +/db/*.sqlite3-journal
  32 +/doc/api/
  33 +/doc/app/
  34 +/doc/features.html
  35 +/doc/specs.html
  36 +/public/cache
  37 +/public/stylesheets/compiled
  38 +/public/system
  39 +/spec/tmp/*
  40 +/cache
  41 +/capybara*
  42 +/capybara-*.html
  43 +/gems
  44 +/rerun.txt
  45 +/spec/requests
  46 +/spec/routing
  47 +/spec/views
  48 +/specifications
  49 +
  50 +# scm revert files
  51 +**.orig
  52 +
  53 +# Mac finder artifacts
  54 +.DS_Store
  55 +
  56 +# Netbeans project directory
  57 +/nbproject/
  58 +
  59 +# Textmate project files
  60 +/*.tmpproj
  61 +
  62 +# vim artifacts
  63 +**.swp
  64 +# keep OmniAuth service provider secrets out of the Git repo
  65 +config/initializers/omniauth.rb
12 Gemfile
... ... @@ -0,0 +1,12 @@
  1 +source 'http://rubygems.org'
  2 +gem 'rails', '3.0.7'
  3 +gem "rspec-rails", ">= 2.5.0", :group => [:development, :test]
  4 +gem "database_cleaner", ">= 0.6.7", :group => :test
  5 +gem "mongoid-rspec", ">= 1.4.2", :group => :test
  6 +gem "factory_girl_rails", ">= 1.1.beta1", :group => :test
  7 +gem "cucumber-rails", ">= 0.4.1", :group => :test
  8 +gem "capybara", ">= 0.4.1.2", :group => :test
  9 +gem "launchy", ">= 0.4.0", :group => :test
  10 +gem "bson_ext", ">= 1.3.0"
  11 +gem "mongoid", ">= 2.0.1"
  12 +gem "omniauth", ">= 0.2.4"
212 Gemfile.lock
... ... @@ -0,0 +1,212 @@
  1 +GEM
  2 + remote: http://rubygems.org/
  3 + specs:
  4 + abstract (1.0.0)
  5 + actionmailer (3.0.7)
  6 + actionpack (= 3.0.7)
  7 + mail (~> 2.2.15)
  8 + actionpack (3.0.7)
  9 + activemodel (= 3.0.7)
  10 + activesupport (= 3.0.7)
  11 + builder (~> 2.1.2)
  12 + erubis (~> 2.6.6)
  13 + i18n (~> 0.5.0)
  14 + rack (~> 1.2.1)
  15 + rack-mount (~> 0.6.14)
  16 + rack-test (~> 0.5.7)
  17 + tzinfo (~> 0.3.23)
  18 + activemodel (3.0.7)
  19 + activesupport (= 3.0.7)
  20 + builder (~> 2.1.2)
  21 + i18n (~> 0.5.0)
  22 + activerecord (3.0.7)
  23 + activemodel (= 3.0.7)
  24 + activesupport (= 3.0.7)
  25 + arel (~> 2.0.2)
  26 + tzinfo (~> 0.3.23)
  27 + activeresource (3.0.7)
  28 + activemodel (= 3.0.7)
  29 + activesupport (= 3.0.7)
  30 + activesupport (3.0.7)
  31 + addressable (2.2.4)
  32 + arel (2.0.9)
  33 + bson (1.3.0)
  34 + bson_ext (1.3.0)
  35 + builder (2.1.2)
  36 + capybara (0.4.1.2)
  37 + celerity (>= 0.7.9)
  38 + culerity (>= 0.2.4)
  39 + mime-types (>= 1.16)
  40 + nokogiri (>= 1.3.3)
  41 + rack (>= 1.0.0)
  42 + rack-test (>= 0.5.4)
  43 + selenium-webdriver (>= 0.0.27)
  44 + xpath (~> 0.1.3)
  45 + celerity (0.8.9)
  46 + childprocess (0.1.8)
  47 + ffi (~> 1.0.6)
  48 + configuration (1.2.0)
  49 + cucumber (0.10.2)
  50 + builder (>= 2.1.2)
  51 + diff-lcs (>= 1.1.2)
  52 + gherkin (>= 2.3.5)
  53 + json (>= 1.4.6)
  54 + term-ansicolor (>= 1.0.5)
  55 + cucumber-rails (0.4.1)
  56 + cucumber (>= 0.10.1)
  57 + nokogiri (>= 1.4.4)
  58 + rack-test (>= 0.5.7)
  59 + culerity (0.2.15)
  60 + database_cleaner (0.6.7)
  61 + diff-lcs (1.1.2)
  62 + erubis (2.6.6)
  63 + abstract (>= 1.0.0)
  64 + factory_girl (2.0.0.beta2)
  65 + factory_girl_rails (1.1.beta1)
  66 + factory_girl (~> 2.0.0.beta)
  67 + rails (>= 3.0.0)
  68 + faraday (0.6.1)
  69 + addressable (~> 2.2.4)
  70 + multipart-post (~> 1.1.0)
  71 + rack (< 2, >= 1.1.0)
  72 + ffi (1.0.7)
  73 + rake (>= 0.8.7)
  74 + gherkin (2.3.7)
  75 + json (>= 1.4.6)
  76 + i18n (0.5.0)
  77 + json (1.5.1)
  78 + json_pure (1.5.1)
  79 + launchy (0.4.0)
  80 + configuration (>= 0.0.5)
  81 + rake (>= 0.8.1)
  82 + mail (2.2.19)
  83 + activesupport (>= 2.3.6)
  84 + i18n (>= 0.4.0)
  85 + mime-types (~> 1.16)
  86 + treetop (~> 1.4.8)
  87 + mime-types (1.16)
  88 + mongo (1.3.0)
  89 + bson (>= 1.3.0)
  90 + mongoid (2.0.1)
  91 + activemodel (~> 3.0)
  92 + mongo (~> 1.3)
  93 + tzinfo (~> 0.3.22)
  94 + will_paginate (~> 3.0.pre)
  95 + mongoid-rspec (1.4.2)
  96 + mongoid (~> 2.0)
  97 + rspec (~> 2)
  98 + multi_json (1.0.1)
  99 + multi_xml (0.2.2)
  100 + multipart-post (1.1.0)
  101 + net-ldap (0.2.2)
  102 + nokogiri (1.4.4)
  103 + oa-basic (0.2.5)
  104 + oa-core (= 0.2.5)
  105 + rest-client (~> 1.6.0)
  106 + oa-core (0.2.5)
  107 + oa-enterprise (0.2.5)
  108 + addressable (= 2.2.4)
  109 + net-ldap (~> 0.2.2)
  110 + nokogiri (~> 1.4.2)
  111 + oa-core (= 0.2.5)
  112 + pyu-ruby-sasl (~> 0.0.3.1)
  113 + rubyntlm (~> 0.1.1)
  114 + oa-more (0.2.5)
  115 + multi_json (~> 1.0.0)
  116 + oa-core (= 0.2.5)
  117 + rest-client (~> 1.6.0)
  118 + oa-oauth (0.2.5)
  119 + faraday (~> 0.6.1)
  120 + multi_json (~> 1.0.0)
  121 + multi_xml (~> 0.2.2)
  122 + oa-core (= 0.2.5)
  123 + oauth (~> 0.4.0)
  124 + oauth2 (~> 0.4.1)
  125 + oa-openid (0.2.5)
  126 + oa-core (= 0.2.5)
  127 + rack-openid (~> 1.3.1)
  128 + ruby-openid-apps-discovery (~> 1.2.0)
  129 + oauth (0.4.4)
  130 + oauth2 (0.4.1)
  131 + faraday (~> 0.6.1)
  132 + multi_json (>= 0.0.5)
  133 + omniauth (0.2.5)
  134 + oa-basic (= 0.2.5)
  135 + oa-core (= 0.2.5)
  136 + oa-enterprise (= 0.2.5)
  137 + oa-more (= 0.2.5)
  138 + oa-oauth (= 0.2.5)
  139 + oa-openid (= 0.2.5)
  140 + polyglot (0.3.1)
  141 + pyu-ruby-sasl (0.0.3.2)
  142 + rack (1.2.2)
  143 + rack-mount (0.6.14)
  144 + rack (>= 1.0.0)
  145 + rack-openid (1.3.1)
  146 + rack (>= 1.1.0)
  147 + ruby-openid (>= 2.1.8)
  148 + rack-test (0.5.7)
  149 + rack (>= 1.0)
  150 + rails (3.0.7)
  151 + actionmailer (= 3.0.7)
  152 + actionpack (= 3.0.7)
  153 + activerecord (= 3.0.7)
  154 + activeresource (= 3.0.7)
  155 + activesupport (= 3.0.7)
  156 + bundler (~> 1.0)
  157 + railties (= 3.0.7)
  158 + railties (3.0.7)
  159 + actionpack (= 3.0.7)
  160 + activesupport (= 3.0.7)
  161 + rake (>= 0.8.7)
  162 + thor (~> 0.14.4)
  163 + rake (0.8.7)
  164 + rest-client (1.6.1)
  165 + mime-types (>= 1.16)
  166 + rspec (2.5.0)
  167 + rspec-core (~> 2.5.0)
  168 + rspec-expectations (~> 2.5.0)
  169 + rspec-mocks (~> 2.5.0)
  170 + rspec-core (2.5.2)
  171 + rspec-expectations (2.5.0)
  172 + diff-lcs (~> 1.1.2)
  173 + rspec-mocks (2.5.0)
  174 + rspec-rails (2.5.0)
  175 + actionpack (~> 3.0)
  176 + activesupport (~> 3.0)
  177 + railties (~> 3.0)
  178 + rspec (~> 2.5.0)
  179 + ruby-openid (2.1.8)
  180 + ruby-openid-apps-discovery (1.2.0)
  181 + ruby-openid (>= 2.1.7)
  182 + rubyntlm (0.1.1)
  183 + rubyzip (0.9.4)
  184 + selenium-webdriver (0.2.0)
  185 + childprocess (>= 0.1.7)
  186 + ffi (>= 1.0.7)
  187 + json_pure
  188 + rubyzip
  189 + term-ansicolor (1.0.5)
  190 + thor (0.14.6)
  191 + treetop (1.4.9)
  192 + polyglot (>= 0.3.1)
  193 + tzinfo (0.3.27)
  194 + will_paginate (3.0.pre2)
  195 + xpath (0.1.4)
  196 + nokogiri (~> 1.3)
  197 +
  198 +PLATFORMS
  199 + ruby
  200 +
  201 +DEPENDENCIES
  202 + bson_ext (>= 1.3.0)
  203 + capybara (>= 0.4.1.2)
  204 + cucumber-rails (>= 0.4.1)
  205 + database_cleaner (>= 0.6.7)
  206 + factory_girl_rails (>= 1.1.beta1)
  207 + launchy (>= 0.4.0)
  208 + mongoid (>= 2.0.1)
  209 + mongoid-rspec (>= 1.4.2)
  210 + omniauth (>= 0.2.4)
  211 + rails (= 3.0.7)
  212 + rspec-rails (>= 2.5.0)
8 README
... ... @@ -0,0 +1,8 @@
  1 +Rails3 Mongoid Omniauth
  2 +========================
  3 +
  4 +
  5 +________________________
  6 +
  7 +License
  8 +
59 README.textile
Source Rendered
... ... @@ -0,0 +1,59 @@
  1 +h1. Rails3 Mongoid Omniauth
  2 +
  3 +Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  4 +
  5 +h2. More Information
  6 +
  7 +Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  8 +
  9 +h2. Required Gems
  10 +
  11 +This application requires this gem:
  12 +
  13 +* "rails":http://rubygems.org/gems/rails
  14 +
  15 +h2. Dependencies
  16 +
  17 +To use this application, you will need:
  18 +
  19 +* The Ruby language (version 1.8.7 or 1.9.2)
  20 +* Rails (version 3.0.4 or newer)
  21 +
  22 +h2. Installing the Application
  23 +
  24 +Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  25 +
  26 +h2. Getting Started
  27 +
  28 +Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  29 +
  30 +h2. Documentation and Support
  31 +
  32 +This is the only documentation.
  33 +
  34 +h4. Issues
  35 +
  36 +Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  37 +
  38 +h2. Similar Projects
  39 +
  40 +Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  41 +
  42 +h2. Contributing
  43 +
  44 +If you make improvements to this application, please share with others.
  45 +
  46 +* Fork the project on GitHub.
  47 +* Make your feature addition or bug fix.
  48 +* Commit with Git.
  49 +* Send the author a pull request.
  50 +
  51 +If you add functionality to this application, create an alternative implementation, or build an application that is similar, please contact me and I'll add a note to the README so that others can find your work.
  52 +
  53 +h2. Credits
  54 +
  55 +Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  56 +
  57 +h2. License
  58 +
  59 +Lorem ipsum dolor sit amet, consectetur adipiscing elit.
7 Rakefile
... ... @@ -0,0 +1,7 @@
  1 +# Add your own tasks in files placed in lib/tasks ending in .rake,
  2 +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
  3 +
  4 +require File.expand_path('../config/application', __FILE__)
  5 +require 'rake'
  6 +
  7 +Rails3MongoidOmniauth::Application.load_tasks
33 app/controllers/application_controller.rb
... ... @@ -0,0 +1,33 @@
  1 +class ApplicationController < ActionController::Base
  2 + protect_from_forgery
  3 + helper_method :current_user
  4 + helper_method :user_signed_in?
  5 + helper_method :correct_user?
  6 +
  7 + private
  8 + def current_user
  9 + begin
  10 + @current_user ||= User.find(session[:user_id]) if session[:user_id]
  11 + rescue Mongoid::Errors::DocumentNotFound
  12 + nil
  13 + end
  14 + end
  15 +
  16 + def user_signed_in?
  17 + return true if current_user
  18 + end
  19 +
  20 + def correct_user?
  21 + @user = User.find(params[:id])
  22 + unless current_user == @user
  23 + redirect_to root_url, :alert => "Access denied."
  24 + end
  25 + end
  26 +
  27 + def authenticate_user!
  28 + if !current_user
  29 + redirect_to root_url, :alert => 'You need to sign in for access to this page.'
  30 + end
  31 + end
  32 +
  33 +end
5 app/controllers/home_controller.rb
... ... @@ -0,0 +1,5 @@
  1 +class HomeController < ApplicationController
  2 + def index
  3 + @users = User.all
  4 + end
  5 +end
30 app/controllers/sessions_controller.rb
... ... @@ -0,0 +1,30 @@
  1 +class SessionsController < ApplicationController
  2 +
  3 + def new
  4 + redirect_to '/auth/twitter'
  5 + end
  6 +
  7 +
  8 + def create
  9 + auth = request.env["omniauth.auth"]
  10 + user = User.where(:provider => auth['provider'],
  11 + :uid => auth['uid']).first || User.create_with_omniauth(auth)
  12 + session[:user_id] = user.id
  13 + if !user.email
  14 + redirect_to edit_user_path(user), :alert => "Please enter your email address."
  15 + else
  16 + redirect_to root_url, :notice => 'Signed in!'
  17 + end
  18 +
  19 + end
  20 +
  21 + def destroy
  22 + session[:user_id] = nil
  23 + redirect_to root_url, :notice => 'Signed out!'
  24 + end
  25 +
  26 + def failure
  27 + redirect_to root_url, :alert => "Authentication error: #{params[:message].humanize}"
  28 + end
  29 +
  30 +end
24 app/controllers/users_controller.rb
... ... @@ -0,0 +1,24 @@
  1 +class UsersController < ApplicationController
  2 + before_filter :authenticate_user!
  3 + before_filter :correct_user?
  4 +
  5 + def edit
  6 + @user = User.find(params[:id])
  7 + end
  8 +
  9 + def update
  10 + @user = User.find(params[:id])
  11 + if @user.update_attributes(params[:user])
  12 + redirect_to @user
  13 + else
  14 + render :edit
  15 + end
  16 + end
  17 +
  18 +
  19 +def show
  20 + @user = User.find(params[:id])
  21 +
  22 + end
  23 +
  24 +end
2  app/helpers/application_helper.rb
... ... @@ -0,0 +1,2 @@
  1 +module ApplicationHelper
  2 +end
2  app/helpers/home_helper.rb
... ... @@ -0,0 +1,2 @@
  1 +module HomeHelper
  2 +end
2  app/helpers/users_helper.rb
... ... @@ -0,0 +1,2 @@
  1 +module UsersHelper
  2 +end
21 app/models/user.rb
... ... @@ -0,0 +1,21 @@
  1 +class User
  2 + include Mongoid::Document
  3 + field :provider, :type => String
  4 + field :uid, :type => String
  5 + field :name, :type => String
  6 + field :email, :type => String
  7 + attr_accessible :provider, :uid, :name, :email
  8 +
  9 + def self.create_with_omniauth(auth)
  10 + create! do |user|
  11 + user.provider = auth['provider']
  12 + user.uid = auth['uid']
  13 + user.name = auth['user_info']['name'] if auth['user_info']['name'] # Twitter, Google, Yahoo, GitHub
  14 + user.email = auth['user_info']['email'] if auth['user_info']['email'] # Google, Yahoo, GitHub
  15 + user.name = auth['extra']['user_hash']['name'] if auth['extra']['user_hash']['name'] # Facebook
  16 + user.email = auth['extra']['user_hash']['email'] if auth['extra']['user_hash']['email'] # Facebook
  17 + end
  18 + end
  19 +
  20 +end
  21 +
4 app/views/home/index.html.erb
... ... @@ -0,0 +1,4 @@
  1 +<h3>Home</h3>
  2 +<% @users.each do |user| %>
  3 + <p>User: <%=link_to user.name, user %></p>
  4 +<% end %>
20 app/views/layouts/application.html.erb
... ... @@ -0,0 +1,20 @@
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <title>Rails3MongoidOmniauth</title>
  5 + <%= stylesheet_link_tag :all %>
  6 + <%= javascript_include_tag :defaults %>
  7 + <%= csrf_meta_tag %>
  8 +</head>
  9 +<body>
  10 + <ul class="hmenu">
  11 + <%= render 'shared/navigation' %>
  12 + </ul>
  13 + <%- flash.each do |name, msg| -%>
  14 + <%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) %>
  15 + <%- end -%>
  16 +
  17 +<%= yield %>
  18 +
  19 +</body>
  20 +</html>
12 app/views/shared/_navigation.html.erb
... ... @@ -0,0 +1,12 @@
  1 +<% if user_signed_in? %>
  2 + <li>
  3 + Logged in as <%= current_user.name %>
  4 + </li>
  5 + <li>
  6 + <%= link_to('Logout', signout_path) %>
  7 + </li>
  8 +<% else %>
  9 + <li>
  10 + <%= link_to('Login', signin_path) %>
  11 + </li>
  12 +<% end %>
6 app/views/users/edit.html.erb
... ... @@ -0,0 +1,6 @@
  1 +<%= form_for(@user) do |f| %>
  2 + <%= f.label :email %>
  3 + <%= f.text_field :email %>
  4 + <br />
  5 + <%= f.submit "Sign in" %>
  6 +<% end %>
4 app/views/users/show.html.erb
... ... @@ -0,0 +1,4 @@
  1 +<h1>Users#show</h1>
  2 +<p>Find me in app/views/users/show.html.erb</p>
  3 +<p>User: <%= @user.name %></p>
  4 +<p>Email: <%= @user.email if @user.email %></p>
4 config.ru
... ... @@ -0,0 +1,4 @@
  1 +# This file is used by Rack-based servers to start the application.
  2 +
  3 +require ::File.expand_path('../config/environment', __FILE__)
  4 +run Rails3MongoidOmniauth::Application
53 config/application.rb
... ... @@ -0,0 +1,53 @@
  1 +require File.expand_path('../boot', __FILE__)
  2 +
  3 +# Pick the frameworks you want:
  4 +# require "active_record/railtie"
  5 +require "action_controller/railtie"
  6 +require "action_mailer/railtie"
  7 +require "active_resource/railtie"
  8 +# require "rails/test_unit/railtie"
  9 +
  10 +# If you have a Gemfile, require the gems listed there, including any gems
  11 +# you've limited to :test, :development, or :production.
  12 +Bundler.require(:default, Rails.env) if defined?(Bundler)
  13 +
  14 +module Rails3MongoidOmniauth
  15 + class Application < Rails::Application
  16 +
  17 + config.generators do |g|
  18 + g.view_specs false
  19 + g.helper_specs false
  20 + end
  21 +
  22 + # Settings in config/environments/* take precedence over those specified here.
  23 + # Application configuration should go into files in config/initializers
  24 + # -- all .rb files in that directory are automatically loaded.
  25 +
  26 + # Custom directories with classes and modules you want to be autoloadable.
  27 + # config.autoload_paths += %W(#{config.root}/extras)
  28 +
  29 + # Only load the plugins named here, in the order given (default is alphabetical).
  30 + # :all can be used as a placeholder for all plugins not explicitly named.
  31 + # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
  32 +
  33 + # Activate observers that should always be running.
  34 + # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
  35 +
  36 + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
  37 + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
  38 + # config.time_zone = 'Central Time (US & Canada)'
  39 +
  40 + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
  41 + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
  42 + # config.i18n.default_locale = :de
  43 +
  44 + # JavaScript files you want as :defaults (application.js is always included).
  45 + config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
  46 +
  47 + # Configure the default encoding used in templates for Ruby 1.9.
  48 + config.encoding = "utf-8"
  49 +
  50 + # Configure sensitive parameters which will be filtered from the log file.
  51 + config.filter_parameters += [:password]
  52 + end
  53 +end
6 config/boot.rb
... ... @@ -0,0 +1,6 @@
  1 +require 'rubygems'
  2 +
  3 +# Set up gems listed in the Gemfile.
  4 +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
  5 +
  6 +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
8 config/cucumber.yml
... ... @@ -0,0 +1,8 @@
  1 +<%
  2 +rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
  3 +rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
  4 +std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
  5 +%>
  6 +default: <%= std_opts %> features
  7 +wip: --tags @wip:3 --wip features
  8 +rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
5 config/environment.rb
... ... @@ -0,0 +1,5 @@
  1 +# Load the rails application
  2 +require File.expand_path('../application', __FILE__)
  3 +
  4 +# Initialize the rails application
  5 +Rails3MongoidOmniauth::Application.initialize!
26 config/environments/development.rb
... ... @@ -0,0 +1,26 @@
  1 +Rails3MongoidOmniauth::Application.configure do
  2 + # Settings specified here will take precedence over those in config/application.rb
  3 +
  4 + # In the development environment your application's code is reloaded on
  5 + # every request. This slows down response time but is perfect for development
  6 + # since you don't have to restart the webserver when you make code changes.
  7 + config.cache_classes = false
  8 +
  9 + # Log error messages when you accidentally call methods on nil.
  10 + config.whiny_nils = true
  11 +
  12 + # Show full error reports and disable caching
  13 + config.consider_all_requests_local = true
  14 + config.action_view.debug_rjs = true
  15 + config.action_controller.perform_caching = false
  16 +
  17 + # Don't care if the mailer can't send
  18 + config.action_mailer.raise_delivery_errors = false
  19 +
  20 + # Print deprecation notices to the Rails logger
  21 + config.active_support.deprecation = :log
  22 +
  23 + # Only use best-standards-support built into browsers
  24 + config.action_dispatch.best_standards_support = :builtin
  25 +end
  26 +
49 config/environments/production.rb
... ... @@ -0,0 +1,49 @@
  1 +Rails3MongoidOmniauth::Application.configure do
  2 + # Settings specified here will take precedence over those in config/application.rb
  3 +
  4 + # The production environment is meant for finished, "live" apps.
  5 + # Code is not reloaded between requests
  6 + config.cache_classes = true
  7 +
  8 + # Full error reports are disabled and caching is turned on
  9 + config.consider_all_requests_local = false
  10 + config.action_controller.perform_caching = true
  11 +
  12 + # Specifies the header that your server uses for sending files
  13 + config.action_dispatch.x_sendfile_header = "X-Sendfile"
  14 +
  15 + # For nginx:
  16 + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
  17 +
  18 + # If you have no front-end server that supports something like X-Sendfile,
  19 + # just comment this out and Rails will serve the files
  20 +
  21 + # See everything in the log (default is :info)
  22 + # config.log_level = :debug
  23 +
  24 + # Use a different logger for distributed setups
  25 + # config.logger = SyslogLogger.new
  26 +
  27 + # Use a different cache store in production
  28 + # config.cache_store = :mem_cache_store
  29 +
  30 + # Disable Rails's static asset server
  31 + # In production, Apache or nginx will already do this
  32 + config.serve_static_assets = false
  33 +
  34 + # Enable serving of images, stylesheets, and javascripts from an asset server
  35 + # config.action_controller.asset_host = "http://assets.example.com"
  36 +
  37 + # Disable delivery errors, bad email addresses will be ignored
  38 + # config.action_mailer.raise_delivery_errors = false
  39 +
  40 + # Enable threaded mode
  41 + # config.threadsafe!
  42 +
  43 + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  44 + # the I18n.default_locale when a translation can not be found)
  45 + config.i18n.fallbacks = true
  46 +
  47 + # Send deprecation notices to registered listeners
  48 + config.active_support.deprecation = :notify
  49 +end
35 config/environments/test.rb
... ... @@ -0,0 +1,35 @@
  1 +Rails3MongoidOmniauth::Application.configure do
  2 + # Settings specified here will take precedence over those in config/application.rb
  3 +
  4 + # The test environment is used exclusively to run your application's
  5 + # test suite. You never need to work with it otherwise. Remember that
  6 + # your test database is "scratch space" for the test suite and is wiped
  7 + # and recreated between test runs. Don't rely on the data there!
  8 + config.cache_classes = true
  9 +
  10 + # Log error messages when you accidentally call methods on nil.
  11 + config.whiny_nils = true
  12 +
  13 + # Show full error reports and disable caching
  14 + config.consider_all_requests_local = true
  15 + config.action_controller.perform_caching = false
  16 +
  17 + # Raise exceptions instead of rendering exception templates
  18 + config.action_dispatch.show_exceptions = false
  19 +
  20 + # Disable request forgery protection in test environment
  21 + config.action_controller.allow_forgery_protection = false
  22 +
  23 + # Tell Action Mailer not to deliver emails to the real world.
  24 + # The :test delivery method accumulates sent emails in the
  25 + # ActionMailer::Base.deliveries array.
  26 + config.action_mailer.delivery_method = :test
  27 +
  28 + # Use SQL instead of Active Record's schema dumper when creating the test database.
  29 + # This is necessary if your schema can't be completely dumped by the schema dumper,
  30 + # like if you have constraints or database-specific column types
  31 + # config.active_record.schema_format = :sql
  32 +
  33 + # Print deprecation notices to the stderr
  34 + config.active_support.deprecation = :stderr
  35 +end
7 config/initializers/backtrace_silencers.rb
... ... @@ -0,0 +1,7 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
  4 +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
  5 +
  6 +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
  7 +# Rails.backtrace_cleaner.remove_silencers!
2  config/initializers/generators.rb
... ... @@ -0,0 +1,2 @@
  1 +Rails.application.config.generators do |g|
  2 +end
10 config/initializers/inflections.rb
... ... @@ -0,0 +1,10 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# Add new inflection rules using the following format
  4 +# (all these examples are active by default):
  5 +# ActiveSupport::Inflector.inflections do |inflect|
  6 +# inflect.plural /^(ox)$/i, '\1en'
  7 +# inflect.singular /^(ox)en/i, '\1'
  8 +# inflect.irregular 'person', 'people'
  9 +# inflect.uncountable %w( fish sheep )
  10 +# end
5 config/initializers/mime_types.rb
... ... @@ -0,0 +1,5 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# Add new mime types for use in respond_to blocks:
  4 +# Mime::Type.register "text/richtext", :rtf
  5 +# Mime::Type.register_alias "text/html", :iphone
7 config/initializers/secret_token.rb
... ... @@ -0,0 +1,7 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# Your secret key for verifying the integrity of signed cookies.
  4 +# If you change this key, all old signed cookies will become invalid!
  5 +# Make sure the secret is at least 30 characters and all random,
  6 +# no regular words or you'll be exposed to dictionary attacks.
  7 +Rails3MongoidOmniauth::Application.config.secret_token = 'ce0c9e90903f6dea6f661a8ee8edbd5f4bee4428a4c9ba10e255efd63846b23908537c1a07903cb11ac8cd1fadaa639141450ae7880b22b9bffbbfeffb514d80'
8 config/initializers/session_store.rb
... ... @@ -0,0 +1,8 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +Rails3MongoidOmniauth::Application.config.session_store :cookie_store, :key => '_rails3-mongoid-omniauth_session'
  4 +
  5 +# Use the database for sessions instead of the cookie-based default,
  6 +# which shouldn't be used to store highly confidential information
  7 +# (create the session table with "rails generate session_migration")
  8 +# Rails3MongoidOmniauth::Application.config.session_store :active_record_store
5 config/locales/en.yml
... ... @@ -0,0 +1,5 @@
  1 +# Sample localization file for English. Add more files in this directory for other locales.
  2 +# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
  3 +
  4 +en:
  5 + hello: "Hello world"
23 config/mongoid.yml
... ... @@ -0,0 +1,23 @@
  1 +defaults: &defaults
  2 + host: localhost
  3 + # slaves:
  4 + # - host: slave1.local
  5 + # port: 27018
  6 + # - host: slave2.local
  7 + # port: 27019
  8 +
  9 +development:
  10 + <<: *defaults
  11 + database: rails3_mongoid_omniauth_development
  12 +
  13 +test:
  14 + <<: *defaults
  15 + database: rails3_mongoid_omniauth_test
  16 +
  17 +# set these environment variables on your prod server
  18 +production:
  19 + host: <%= ENV['MONGOID_HOST'] %>
  20 + port: <%= ENV['MONGOID_PORT'] %>
  21 + username: <%= ENV['MONGOID_USERNAME'] %>
  22 + password: <%= ENV['MONGOID_PASSWORD'] %>
  23 + database: <%= ENV['MONGOID_DATABASE'] %>
72 config/routes.rb
... ... @@ -0,0 +1,72 @@
  1 +Rails3MongoidOmniauth::Application.routes.draw do
  2 + #get \"users\/show\"
  3 +
  4 + root :to => "home#index"
  5 +
  6 + resources :users, :only => [ :show, :edit, :update ]
  7 +
  8 + match '/auth/:provider/callback' => 'sessions#create'
  9 +
  10 + match '/signin' => 'sessions#new', :as => :signin
  11 +
  12 + match '/signout' => 'sessions#destroy', :as => :signout
  13 +
  14 + match '/auth/failure' => 'sessions#failure'
  15 +
  16 + # The priority is based upon order of creation:
  17 + # first created -> highest priority.
  18 +
  19 + # Sample of regular route:
  20 + # match 'products/:id' => 'catalog#view'
  21 + # Keep in mind you can assign values other than :controller and :action
  22 +
  23 + # Sample of named route:
  24 + # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
  25 + # This route can be invoked with purchase_url(:id => product.id)
  26 +
  27 + # Sample resource route (maps HTTP verbs to controller actions automatically):
  28 + # resources :products
  29 +
  30 + # Sample resource route with options:
  31 + # resources :products do
  32 + # member do
  33 + # get 'short'
  34 + # post 'toggle'
  35 + # end
  36 + #
  37 + # collection do
  38 + # get 'sold'
  39 + # end
  40 + # end
  41 +
  42 + # Sample resource route with sub-resources:
  43 + # resources :products do
  44 + # resources :comments, :sales
  45 + # resource :seller
  46 + # end
  47 +
  48 + # Sample resource route with more complex sub-resources
  49 + # resources :products do
  50 + # resources :comments
  51 + # resources :sales do
  52 + # get 'recent', :on => :collection
  53 + # end
  54 + # end
  55 +
  56 + # Sample resource route within a namespace:
  57 + # namespace :admin do
  58 + # # Directs /admin/products/* to Admin::ProductsController
  59 + # # (app/controllers/admin/products_controller.rb)
  60 + # resources :products
  61 + # end
  62 +
  63 + # You can have the root of your site routed with "root"
  64 + # just remember to delete public/index.html.
  65 + # root :to => "welcome#index"
  66 +
  67 + # See how all your routes lay out with "rake routes"
  68 +
  69 + # This is a legacy wild controller route that's not recommended for RESTful applications.
  70 + # Note: This route will make all actions in every controller accessible via GET requests.
  71 + # match ':controller(/:action(/:id(.:format)))'
  72 +end
9 db/seeds.rb
... ... @@ -0,0 +1,9 @@
  1 +# This file should contain all the record creation needed to seed the database with its default values.
  2 +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
  3 +#
  4 +# Examples:
  5 +#
  6 +# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
  7 +# Mayor.create(:name => 'Daley', :city => cities.first)
  8 +puts 'EMPTY THE MONGODB DATABASE'
  9 +Mongoid.master.collections.reject { |c| c.name =~ /^system/}.each(&:drop)
211 features/step_definitions/web_steps.rb
... ... @@ -0,0 +1,211 @@
  1 +# TL;DR: YOU SHOULD DELETE THIS FILE
  2 +#
  3 +# This file was generated by Cucumber-Rails and is only here to get you a head start
  4 +# These step definitions are thin wrappers around the Capybara/Webrat API that lets you
  5 +# visit pages, interact with widgets and make assertions about page content.
  6 +#
  7 +# If you use these step definitions as basis for your features you will quickly end up
  8 +# with features that are:
  9 +#
  10 +# * Hard to maintain
  11 +# * Verbose to read
  12 +#
  13 +# A much better approach is to write your own higher level step definitions, following
  14 +# the advice in the following blog posts:
  15 +#
  16 +# * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
  17 +# * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
  18 +# * http://elabs.se/blog/15-you-re-cuking-it-wrong
  19 +#
  20 +
  21 +
  22 +require 'uri'
  23 +require 'cgi'
  24 +require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
  25 +require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
  26 +
  27 +module WithinHelpers
  28 + def with_scope(locator)
  29 + locator ? within(*selector_for(locator)) { yield } : yield
  30 + end
  31 +end
  32 +World(WithinHelpers)
  33 +
  34 +# Single-line step scoper
  35 +When /^(.*) within ([^:]+)$/ do |step, parent|
  36 + with_scope(parent) { When step }
  37 +end
  38 +
  39 +# Multi-line step scoper
  40 +When /^(.*) within ([^:]+):$/ do |step, parent, table_or_string|
  41 + with_scope(parent) { When "#{step}:", table_or_string }
  42 +end
  43 +
  44 +Given /^(?:|I )am on (.+)$/ do |page_name|
  45 + visit path_to(page_name)
  46 +end
  47 +
  48 +When /^(?:|I )go to (.+)$/ do |page_name|
  49 + visit path_to(page_name)
  50 +end
  51 +
  52 +When /^(?:|I )press "([^"]*)"$/ do |button|
  53 + click_button(button)
  54 +end
  55 +
  56 +When /^(?:|I )follow "([^"]*)"$/ do |link|
  57 + click_link(link)
  58 +end
  59 +
  60 +When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
  61 + fill_in(field, :with => value)
  62 +end
  63 +
  64 +When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
  65 + fill_in(field, :with => value)
  66 +end
  67 +
  68 +# Use this to fill in an entire form with data from a table. Example:
  69 +#
  70 +# When I fill in the following:
  71 +# | Account Number | 5002 |
  72 +# | Expiry date | 2009-11-01 |
  73 +# | Note | Nice guy |
  74 +# | Wants Email? | |
  75 +#
  76 +# TODO: Add support for checkbox, select og option
  77 +# based on naming conventions.
  78 +#
  79 +When /^(?:|I )fill in the following:$/ do |fields|
  80 + fields.rows_hash.each do |name, value|
  81 + When %{I fill in "#{name}" with "#{value}"}
  82 + end
  83 +end
  84 +
  85 +When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
  86 + select(value, :from => field)
  87 +end
  88 +
  89 +When /^(?:|I )check "([^"]*)"$/ do |field|
  90 + check(field)
  91 +end
  92 +
  93 +When /^(?:|I )uncheck "([^"]*)"$/ do |field|
  94 + uncheck(field)
  95 +end
  96 +
  97 +When /^(?:|I )choose "([^"]*)"$/ do |field|
  98 + choose(field)
  99 +end
  100 +
  101 +When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
  102 + attach_file(field, File.expand_path(path))
  103 +end
  104 +
  105 +Then /^(?:|I )should see "([^"]*)"$/ do |text|
  106 + if page.respond_to? :should
  107 + page.should have_content(text)
  108 + else
  109 + assert page.has_content?(text)
  110 + end
  111 +end
  112 +
  113 +Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
  114 + regexp = Regexp.new(regexp)
  115 +
  116 + if page.respond_to? :should
  117 + page.should have_xpath('//*', :text => regexp)
  118 + else
  119 + assert page.has_xpath?('//*', :text => regexp)
  120 + end
  121 +end
  122 +
  123 +Then /^(?:|I )should not see "([^"]*)"$/ do |text|
  124 + if page.respond_to? :should
  125 + page.should have_no_content(text)
  126 + else
  127 + assert page.has_no_content?(text)
  128 + end
  129 +end
  130 +
  131 +Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
  132 + regexp = Regexp.new(regexp)
  133 +
  134 + if page.respond_to? :should
  135 + page.should have_no_xpath('//*', :text => regexp)
  136 + else
  137 + assert page.has_no_xpath?('//*', :text => regexp)
  138 + end
  139 +end
  140 +
  141 +Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
  142 + with_scope(parent) do
  143 + field = find_field(field)
  144 + field_value = (field.tag_name == 'textarea') ? field.text : field.value
  145 + if field_value.respond_to? :should
  146 + field_value.should =~ /#{value}/
  147 + else
  148 + assert_match(/#{value}/, field_value)
  149 + end
  150 + end
  151 +end
  152 +
  153 +Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
  154 + with_scope(parent) do
  155 + field = find_field(field)
  156 + field_value = (field.tag_name == 'textarea') ? field.text : field.value
  157 + if field_value.respond_to? :should_not
  158 + field_value.should_not =~ /#{value}/
  159 + else
  160 + assert_no_match(/#{value}/, field_value)
  161 + end
  162 + end
  163 +end
  164 +
  165 +Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
  166 + with_scope(parent) do
  167 + field_checked = find_field(label)['checked']
  168 + if field_checked.respond_to? :should
  169 + field_checked.should be_true
  170 + else
  171 + assert field_checked
  172 + end
  173 + end
  174 +end
  175 +
  176 +Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
  177 + with_scope(parent) do
  178 + field_checked = find_field(label)['checked']
  179 + if field_checked.respond_to? :should
  180 + field_checked.should be_false
  181 + else
  182 + assert !field_checked
  183 + end
  184 + end
  185 +end
  186 +
  187 +Then /^(?:|I )should be on (.+)$/ do |page_name|
  188 + current_path = URI.parse(current_url).path
  189 + if current_path.respond_to? :should
  190 + current_path.should == path_to(page_name)
  191 + else
  192 + assert_equal path_to(page_name), current_path
  193 + end
  194 +end
  195 +
  196 +Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
  197 + query = URI.parse(current_url).query
  198 + actual_params = query ? CGI.parse(query) : {}
  199 + expected_params = {}
  200 + expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
  201 +
  202 + if actual_params.respond_to? :should
  203 + actual_params.should == expected_params
  204 + else
  205 + assert_equal expected_params, actual_params
  206 + end
  207 +end
  208 +
  209 +Then /^show me the page$/ do
  210 + save_and_open_page