├── .gitignore ├── .rspec ├── .ruby-gemset ├── .ruby-version ├── Gemfile ├── Gemfile.lock ├── README ├── README.textile ├── Rakefile ├── app ├── assets │ ├── javascripts │ │ ├── application.js │ │ └── home.js.coffee │ └── stylesheets │ │ ├── application.css.scss │ │ └── home.css.scss ├── controllers │ ├── application_controller.rb │ ├── home_controller.rb │ └── users_controller.rb ├── helpers │ ├── application_helper.rb │ └── home_helper.rb ├── mailers │ └── .gitkeep ├── models │ ├── .gitkeep │ └── user.rb └── views │ ├── devise │ ├── registrations │ │ ├── edit.html.erb │ │ └── new.html.erb │ └── shared │ │ └── _links.html.erb │ ├── home │ └── index.html.erb │ ├── layouts │ ├── _messages.html.erb │ ├── _navigation.html.erb │ └── application.html.erb │ └── users │ ├── index.html.erb │ └── show.html.erb ├── config.ru ├── config ├── application.example.yml ├── application.rb ├── application.yml ├── boot.rb ├── cucumber.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── backtrace_silencers.rb │ ├── devise.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── secret_token.rb │ ├── session_store.rb │ └── wrap_parameters.rb ├── locales │ ├── devise.en.yml │ └── en.yml ├── mongoid.yml └── routes.rb ├── db └── seeds.rb ├── features ├── step_definitions │ ├── email_steps.rb │ └── user_steps.rb ├── support │ ├── email_spec.rb │ ├── env.rb │ └── paths.rb └── users │ ├── sign_in.feature │ ├── sign_out.feature │ ├── sign_up.feature │ ├── user_edit.feature │ └── user_show.feature ├── lib ├── assets │ └── .gitkeep └── tasks │ ├── .gitkeep │ └── cucumber.rake ├── public ├── 404.html ├── 422.html ├── 500.html ├── favicon.ico ├── humans.txt └── robots.txt ├── script ├── cucumber └── rails ├── spec ├── controllers │ ├── home_controller_spec.rb │ └── users_controller_spec.rb ├── factories │ └── users.rb ├── models │ └── user_spec.rb ├── spec_helper.rb └── support │ ├── devise.rb │ └── mongoid.rb └── vendor └── plugins └── .gitkeep /.gitignore: -------------------------------------------------------------------------------- 1 | #---------------------------------------------------------------------------- 2 | # Ignore these files when commiting to a git repository. 3 | # 4 | # See http://help.github.com/ignore-files/ for more about ignoring files. 5 | # 6 | # The original version of this file is found here: 7 | # https://github.com/RailsApps/rails-composer/blob/master/files/gitignore.txt 8 | # 9 | # Corrections? Improvements? Create a GitHub issue: 10 | # http://github.com/RailsApps/rails-composer/issues 11 | #---------------------------------------------------------------------------- 12 | 13 | # bundler state 14 | /.bundle 15 | /vendor/bundle/ 16 | /vendor/ruby/ 17 | 18 | # minimal Rails specific artifacts 19 | db/*.sqlite3 20 | /log/* 21 | /tmp/* 22 | 23 | # various artifacts 24 | **.war 25 | *.rbc 26 | *.sassc 27 | .rspec 28 | .redcar/ 29 | .sass-cache 30 | /config/config.yml 31 | /config/database.yml 32 | /coverage.data 33 | /coverage/ 34 | /db/*.javadb/ 35 | /db/*.sqlite3 36 | /doc/api/ 37 | /doc/app/ 38 | /doc/features.html 39 | /doc/specs.html 40 | /public/cache 41 | /public/stylesheets/compiled 42 | /public/system/* 43 | /spec/tmp/* 44 | /cache 45 | /capybara* 46 | /capybara-*.html 47 | /gems 48 | /specifications 49 | rerun.txt 50 | pickle-email-*.html 51 | 52 | # If you find yourself ignoring temporary files generated by your text editor 53 | # or operating system, you probably want to add a global ignore instead: 54 | # git config --global core.excludesfile ~/.gitignore_global 55 | # 56 | # Here are some files you may want to ignore globally: 57 | 58 | # scm revert files 59 | **.orig 60 | 61 | # Mac finder artifacts 62 | .DS_Store 63 | 64 | # Netbeans project directory 65 | /nbproject/ 66 | 67 | # RubyMine project files 68 | .idea 69 | 70 | # Textmate project files 71 | /*.tmproj 72 | 73 | # vim artifacts 74 | **.swp 75 | 76 | # Ignore application configuration 77 | /config/application.yml 78 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | -------------------------------------------------------------------------------- /.ruby-gemset: -------------------------------------------------------------------------------- 1 | rails3-mongoid-devise 2 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.0.0 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | ruby '2.0.0' 3 | gem 'rails', '3.2.14' 4 | group :assets do 5 | gem 'sass-rails', '~> 3.2.3' 6 | gem 'coffee-rails', '~> 3.2.1' 7 | gem 'uglifier', '>= 1.0.3' 8 | end 9 | gem 'jquery-rails' 10 | gem 'devise' 11 | gem 'figaro' 12 | gem 'mongoid' 13 | group :development do 14 | gem 'better_errors' 15 | gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx] 16 | gem 'quiet_assets' 17 | end 18 | group :development, :test do 19 | gem 'factory_girl_rails' 20 | gem 'rspec-rails' 21 | end 22 | group :test do 23 | gem 'capybara' 24 | gem 'cucumber-rails', :require=>false 25 | gem 'database_cleaner', '1.0.1' 26 | gem 'email_spec' 27 | gem 'launchy' 28 | gem 'mongoid-rspec' 29 | end 30 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actionmailer (3.2.14) 5 | actionpack (= 3.2.14) 6 | mail (~> 2.5.4) 7 | actionpack (3.2.14) 8 | activemodel (= 3.2.14) 9 | activesupport (= 3.2.14) 10 | builder (~> 3.0.0) 11 | erubis (~> 2.7.0) 12 | journey (~> 1.0.4) 13 | rack (~> 1.4.5) 14 | rack-cache (~> 1.2) 15 | rack-test (~> 0.6.1) 16 | sprockets (~> 2.2.1) 17 | activemodel (3.2.14) 18 | activesupport (= 3.2.14) 19 | builder (~> 3.0.0) 20 | activerecord (3.2.14) 21 | activemodel (= 3.2.14) 22 | activesupport (= 3.2.14) 23 | arel (~> 3.0.2) 24 | tzinfo (~> 0.3.29) 25 | activeresource (3.2.14) 26 | activemodel (= 3.2.14) 27 | activesupport (= 3.2.14) 28 | activesupport (3.2.14) 29 | i18n (~> 0.6, >= 0.6.4) 30 | multi_json (~> 1.0) 31 | addressable (2.3.5) 32 | arel (3.0.2) 33 | bcrypt-ruby (3.1.1) 34 | better_errors (0.9.0) 35 | coderay (>= 1.0.0) 36 | erubis (>= 2.6.6) 37 | binding_of_caller (0.7.2) 38 | debug_inspector (>= 0.0.1) 39 | builder (3.0.4) 40 | capybara (2.1.0) 41 | mime-types (>= 1.16) 42 | nokogiri (>= 1.3.3) 43 | rack (>= 1.0.0) 44 | rack-test (>= 0.5.4) 45 | xpath (~> 2.0) 46 | coderay (1.0.9) 47 | coffee-rails (3.2.2) 48 | coffee-script (>= 2.2.0) 49 | railties (~> 3.2.0) 50 | coffee-script (2.2.0) 51 | coffee-script-source 52 | execjs 53 | coffee-script-source (1.6.3) 54 | cucumber (1.3.6) 55 | builder (>= 2.1.2) 56 | diff-lcs (>= 1.1.3) 57 | gherkin (~> 2.12.0) 58 | multi_json (~> 1.7.5) 59 | multi_test (>= 0.0.2) 60 | cucumber-rails (1.4.0) 61 | capybara (>= 1.1.2) 62 | cucumber (>= 1.2.0) 63 | nokogiri (>= 1.5.0) 64 | rails (>= 3.0.0) 65 | database_cleaner (1.0.1) 66 | debug_inspector (0.0.2) 67 | devise (3.0.3) 68 | bcrypt-ruby (~> 3.0) 69 | orm_adapter (~> 0.1) 70 | railties (>= 3.2.6, < 5) 71 | warden (~> 1.2.3) 72 | diff-lcs (1.2.4) 73 | email_spec (1.5.0) 74 | launchy (~> 2.1) 75 | mail (~> 2.2) 76 | erubis (2.7.0) 77 | execjs (2.0.0) 78 | factory_girl (4.2.0) 79 | activesupport (>= 3.0.0) 80 | factory_girl_rails (4.2.1) 81 | factory_girl (~> 4.2.0) 82 | railties (>= 3.0.0) 83 | figaro (0.7.0) 84 | bundler (~> 1.0) 85 | rails (>= 3, < 5) 86 | gherkin (2.12.1) 87 | multi_json (~> 1.3) 88 | hike (1.2.3) 89 | i18n (0.6.5) 90 | journey (1.0.4) 91 | jquery-rails (3.0.4) 92 | railties (>= 3.0, < 5.0) 93 | thor (>= 0.14, < 2.0) 94 | json (1.8.0) 95 | launchy (2.3.0) 96 | addressable (~> 2.3) 97 | mail (2.5.4) 98 | mime-types (~> 1.16) 99 | treetop (~> 1.4.8) 100 | mime-types (1.24) 101 | mini_portile (0.5.1) 102 | mongoid (3.1.4) 103 | activemodel (~> 3.2) 104 | moped (~> 1.4) 105 | origin (~> 1.0) 106 | tzinfo (~> 0.3.22) 107 | mongoid-rspec (1.9.0) 108 | mongoid (>= 3.0.1) 109 | rake 110 | rspec (>= 2.14) 111 | moped (1.5.1) 112 | multi_json (1.7.9) 113 | multi_test (0.0.2) 114 | nokogiri (1.6.0) 115 | mini_portile (~> 0.5.0) 116 | origin (1.1.0) 117 | orm_adapter (0.4.0) 118 | polyglot (0.3.3) 119 | quiet_assets (1.0.2) 120 | railties (>= 3.1, < 5.0) 121 | rack (1.4.5) 122 | rack-cache (1.2) 123 | rack (>= 0.4) 124 | rack-ssl (1.3.3) 125 | rack 126 | rack-test (0.6.2) 127 | rack (>= 1.0) 128 | rails (3.2.14) 129 | actionmailer (= 3.2.14) 130 | actionpack (= 3.2.14) 131 | activerecord (= 3.2.14) 132 | activeresource (= 3.2.14) 133 | activesupport (= 3.2.14) 134 | bundler (~> 1.0) 135 | railties (= 3.2.14) 136 | railties (3.2.14) 137 | actionpack (= 3.2.14) 138 | activesupport (= 3.2.14) 139 | rack-ssl (~> 1.3.2) 140 | rake (>= 0.8.7) 141 | rdoc (~> 3.4) 142 | thor (>= 0.14.6, < 2.0) 143 | rake (10.1.0) 144 | rdoc (3.12.2) 145 | json (~> 1.4) 146 | rspec (2.14.1) 147 | rspec-core (~> 2.14.0) 148 | rspec-expectations (~> 2.14.0) 149 | rspec-mocks (~> 2.14.0) 150 | rspec-core (2.14.5) 151 | rspec-expectations (2.14.2) 152 | diff-lcs (>= 1.1.3, < 2.0) 153 | rspec-mocks (2.14.3) 154 | rspec-rails (2.14.0) 155 | actionpack (>= 3.0) 156 | activesupport (>= 3.0) 157 | railties (>= 3.0) 158 | rspec-core (~> 2.14.0) 159 | rspec-expectations (~> 2.14.0) 160 | rspec-mocks (~> 2.14.0) 161 | sass (3.2.10) 162 | sass-rails (3.2.6) 163 | railties (~> 3.2.0) 164 | sass (>= 3.1.10) 165 | tilt (~> 1.3) 166 | sprockets (2.2.2) 167 | hike (~> 1.2) 168 | multi_json (~> 1.0) 169 | rack (~> 1.0) 170 | tilt (~> 1.1, != 1.3.0) 171 | thor (0.18.1) 172 | tilt (1.4.1) 173 | treetop (1.4.15) 174 | polyglot 175 | polyglot (>= 0.3.1) 176 | tzinfo (0.3.37) 177 | uglifier (2.2.0) 178 | execjs (>= 0.3.0) 179 | multi_json (~> 1.0, >= 1.0.2) 180 | warden (1.2.3) 181 | rack (>= 1.0) 182 | xpath (2.0.0) 183 | nokogiri (~> 1.3) 184 | 185 | PLATFORMS 186 | ruby 187 | 188 | DEPENDENCIES 189 | better_errors 190 | binding_of_caller 191 | capybara 192 | coffee-rails (~> 3.2.1) 193 | cucumber-rails 194 | database_cleaner (= 1.0.1) 195 | devise 196 | email_spec 197 | factory_girl_rails 198 | figaro 199 | jquery-rails 200 | launchy 201 | mongoid 202 | mongoid-rspec 203 | quiet_assets 204 | rails (= 3.2.14) 205 | rspec-rails 206 | sass-rails (~> 3.2.3) 207 | uglifier (>= 1.0.3) 208 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Rails3-Mongoid-Devise 2 | ======================== 3 | 4 | You can use this project as a starting point for a Rails web application. It requires Rails 3 and uses Mongoid http://mongoid.org/ for data storage and Devise http://github.com/plataformatec/devise for user management and authentication. 5 | ________________________ 6 | 7 | See the README file on GitHub 8 | 9 | For more information, please see the updated README file on GitHub: 10 | 11 | http://github.com/railsapps/rails3-mongoid-devise 12 | 13 | ________________________ 14 | 15 | MIT License 16 | 17 | http://www.opensource.org/licenses/mit-license -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h1. !http://railsapps.github.io/images/rails-36x36.jpg(Rails Application)! Rails 4.1 2 | 3 | For a Rails 4.1 example application for Devise, see: 4 | 5 | * "rails-devise":https://github.com/RailsApps/rails-devise 6 | 7 | A tutorial is available for Devise: 8 | 9 | "Rails Devise Tutorial":http://railsapps.github.io/rails-devise/ 10 | 11 | h4. Similar Examples and Tutorials 12 | 13 | This is one in a series of Rails example apps and tutorials from the "RailsApps Project":http://railsapps.github.io/. See a list of additional "Rails examples, tutorials, and starter apps":http://railsapps.github.io/rails-examples-tutorials.html. Related example applications may be useful: 14 | 15 | * "Learn Rails":https://github.com/RailsApps/learn-rails companion to the book "Learn Ruby on Rails":http://learn-rails.com/learn-ruby-on-rails.html 16 | * "Foundation and Rails":http://railsapps.github.io/rails-foundation/ shows how to integrate Foundation 17 | * "Bootstrap and Rails":http://railsapps.github.io/rails-bootstrap/ shows to integrate Bootstrap 18 | * "OmniAuth and Rails":https://github.com/RailsApps/rails-omniauth uses OmniAuth for authentication 19 | * "Devise and Rails":https://github.com/RailsApps/rails-devise uses Devise for authentication 20 | 21 | h1. !http://railsapps.github.io/images/rails-36x36.jpg(Rails Application for Devise with RSpec and Cucumber)! Rails 3.2 22 | 23 | Rails 3.2 example application shows how to use Devise with Mongoid. 24 | 25 | * "Devise":http://github.com/plataformatec/devise gives you ready-made authentication and user management. 26 | * MongoDB is used as a datastore with the "Mongoid":http://mongoid.org/ gem for quick development without schemas or migrations. 27 | 28 | You really should use the "rails-devise":https://github.com/RailsApps/rails-devise newer version. 29 | 30 | h2. What Is Implemented -- and What Is Not 31 | 32 | This is a demonstration application that allows you to visit a home page and see a list of users. With the default user's email and password (supplied below), you can log in and view details for each user. You can customize this app as you need. 33 | 34 | h2. Dependencies 35 | 36 | Before generating your application, you will need: 37 | 38 | * The Ruby language (version 1.9.3 or 2.0.0) 39 | * The Rails gem (version 3.2.14) 40 | * A working installation of "MongoDB":http://www.mongodb.org/ (version 1.6.0 or newer) 41 | 42 | See the article "Installing Rails":http://railsapps.github.io/installing-rails.html for advice about updating Rails and your development environment. 43 | 44 | h4. Installing MongoDB 45 | 46 | If you don't have MongoDB installed on your computer, you'll need to install it and set it up to be always running on your computer (run at launch). 47 | 48 | On Mac OS X, the easiest way to install MongoDB is to install "Homebrew":http://mxcl.github.com/homebrew/ and then run the following: 49 | 50 |
51 | brew install mongodb 52 |53 | 54 | Homebrew will provide post-installation instructions to get MongoDB running. The last line of the installation output shows you the MongoDB install location (for example, */usr/local/Cellar/mongodb/1.8.0-x86_64*). You'll find the MongoDB configuration file there. After an installation using Homebrew, the default data directory will be */usr/local/var/mongodb*. 55 | 56 | On the Debian GNU/Linux operating system, as of March 2013, the latest stable version is MongoDB 2.0.0. With MongoDB 2.0.0, the Mongoid gem must be version 3.0.x. See the "Mongoid installation instructions":http://mongoid.org/en/mongoid/docs/installation.html#installation. Change your Gemfile to use an earlier Mongoid version: 57 | 58 |
59 | gem 'mongoid', '~> 3.0.1' 60 |61 | 62 | h2. Getting the Application 63 | 64 | You have several options for getting the code. 65 | 66 | h3. Fork 67 | 68 | If you'd like to add features (or bug fixes) to improve the example application, you can fork the GitHub repo and "make pull requests":http://help.github.com/send-pull-requests/. Your code contributions are welcome! 69 | 70 | h3. Clone 71 | 72 | If you want to copy and customize the app with changes that are only useful for your own project, you can clone the GitHub repo. You'll need to search-and-replace the project name throughout the application. You probably should generate the app instead (see below). To clone: 73 | 74 |
75 | $ git clone git://github.com/RailsApps/rails3-mongoid-devise.git 76 |77 | 78 | You'll need "git":http://git-scm.com/ on your machine. See "Rails and Git":http://railsapps.github.io/rails-git.html. 79 | 80 | h3. Generate 81 | 82 | If you want to use the project as a starter app, use the "Rails Composer":http://railsapps.github.io/rails-composer/ tool to generate a new version of the example app. You'll be able to give it your own project name when you generate the app. Generating the application gives you many additional options. 83 | 84 | To build the example application, run the command: 85 | 86 |
87 | $ rails new rails3-mongoid-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer-Rails3_2.rb -T -O 88 |89 | 90 | Use the @-T -O@ flags to skip Test::Unit files and Active Record files. 91 | 92 | The @$@ character indicates a shell prompt; don't include it when you run the command. 93 | 94 | This creates a new Rails app named @rails3-mongoid-devise@ on your computer. 95 | 96 | You'll see a prompt: 97 | 98 |
99 | question Install an example application? 100 | 1) I want to build my own application 101 | 2) membership/subscription/saas 102 | 3) rails-prelaunch-signup 103 | 4) rails3-bootstrap-devise-cancan 104 | 5) rails3-devise-rspec-cucumber 105 | 6) rails3-mongoid-devise 106 | 7) rails3-mongoid-omniauth 107 | 8) rails3-subdomains 108 |109 | 110 | Choose *rails3-mongoid-devise*. The Rails Composer tool may give you other options (other choices may have been added since these notes were written). 111 | 112 | The application generator template will ask you for additional preferences: 113 | 114 |
115 | question Web server for development? 116 | 1) WEBrick (default) 117 | 2) Thin 118 | 3) Unicorn 119 | 4) Puma 120 | question Web server for production? 121 | 1) Same as development 122 | 2) Thin 123 | 3) Unicorn 124 | 4) Puma 125 | question Template engine? 126 | 1) ERB 127 | 2) Haml 128 | 3) Slim 129 | extras Set a robots.txt file to ban spiders? (y/n) 130 | extras Use or create a project-specific rvm gemset? (y/n) 131 | extras Create a GitHub repository? (y/n) 132 |133 | 134 | h4. Web Servers 135 | 136 | Use the default WEBrick server for convenience. If you plan to deploy to Heroku, select "thin" as your production webserver. 137 | 138 | h4. Template Engine 139 | 140 | The example application uses the default "ERB" Rails template engine. Optionally, you can use another template engine, such as Haml or Slim. See instructions for "Haml and Rails":http://railsapps.github.io/rails-haml.html. 141 | 142 | h4. Other Choices 143 | 144 | Set a robots.txt file to ban spiders if you want to keep your new site out of Google search results. 145 | 146 | It is a good idea to use "rvm":https://rvm.io/, the Ruby Version Manager, and create a project-specific rvm gemset (not available on Windows). See "Installing Rails":http://railsapps.github.io/installing-rails.html. 147 | 148 | If you choose to create a GitHub repository, the generator will prompt you for a GitHub username and password. 149 | 150 | h4. Troubleshooting 151 | 152 | If you get an error "OpenSSL certificate verify failed" or "Gem::RemoteFetcher::FetchError: SSL_connect" see the article "OpenSSL errors and Rails":http://railsapps.github.io/openssl-certificate-verify-failed.html. 153 | 154 | If you get an error like this: 155 | 156 |
157 | Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. 158 | composer Running 'after bundler' callbacks. 159 | The template [...] could not be loaded. 160 | Error: You have already activated ..., but your Gemfile requires .... 161 | Using bundle exec may solve this. 162 |163 | 164 | It's due to conflicting gem versions. See the article "Rails Error: “You have already activated (…)”":http://railsapps.github.io/rails-error-you-have-already-activated.html. 165 | 166 | Other problems? Check the "issues":https://github.com/RailsApps/rails3-mongoid-devise/issues. 167 | 168 | h3. Edit the README 169 | 170 | If you're storing the app in a GitHub repository, please edit the README files to add a description of the app and your contact info. If you don't change the README, people will think I am the author of your version of the application. 171 | 172 | h2. Getting Started 173 | 174 | h3. Install the Required Gems 175 | 176 | Check the Gemfile to see which gems are used by this application. 177 | 178 | If you used the "Rails Composer":http://railsapps.github.io/rails-composer/ tool to generate the example app, the application template script has already run the @bundle install@ command. 179 | 180 | If not, you should run the @bundle install@ command to install the required gems on your computer: 181 | 182 |
183 | $ bundle install 184 |185 | 186 | You can check which gems are installed on your computer with: 187 | 188 |
189 | $ gem list 190 |191 | 192 | Keep in mind that you have installed these gems locally. When you deploy the app to another server, the same gems (and versions) must be available. 193 | 194 | I recommend using "rvm":https://rvm.io/, the Ruby Version Manager, to create a project-specific gemset for the application. See the article "Installing Rails":http://railsapps.github.io/installing-rails.html. 195 | 196 | h3. Configure Mongoid 197 | 198 | Mongoid provides access to the MongoDB database from Rails. 199 | 200 | You can use the default configuration found in the file *config/mongoid.yml*. 201 | 202 | If you want to see what's in your MongoDB databases, I recommend using the "MongoHub":http://mongohub.todayclose.com/ app (for Mac OS X). 203 | 204 | h3. Configure Email 205 | 206 | This example application doesn't send email messages. However, if you want your application to send email messages (for example, if you plan to install the Devise @:confirmable@ module) you must configure the application for your email account. See the article "Send Email with Rails":http://railsapps.github.io/rails-send-email.html. 207 | 208 | h3. Configure Devise 209 | 210 | You can modify the configuration file for Devise if you want to use something other than the defaults: 211 | 212 | * *config/initializers/devise.rb* 213 | 214 | h3. Configuration File 215 | 216 | The application uses the "figaro gem":https://github.com/laserlemon/figaro to set environment variables. Credentials for your administrator account and email account are set in the *config/application.yml* file. The *.gitignore* file prevents the *config/application.yml* file from being saved in the git repository so your credentials are kept private. See the article "Rails Environment Variables":http://railsapps.github.io/rails-environment-variables.html for more information. 217 | 218 | Modify the file *config/application.yml*: 219 | 220 |
221 | # Add account credentials and API keys here. 222 | # See http://railsapps.github.io/rails-environment-variables.html 223 | # This file should be listed in .gitignore to keep your settings secret! 224 | # Each entry sets a local environment variable and overrides ENV variables in the Unix shell. 225 | # For example, setting: 226 | # GMAIL_USERNAME: Your_Gmail_Username 227 | # makes 'Your_Gmail_Username' available as ENV["GMAIL_USERNAME"] 228 | # Add application configuration variables here, as shown below. 229 | # 230 | GMAIL_USERNAME: Your_Username 231 | GMAIL_PASSWORD: Your_Password 232 | ADMIN_NAME: First User 233 | ADMIN_EMAIL: user@example.com 234 | ADMIN_PASSWORD: changeme 235 |236 | 237 | If you are planning to customize the application to send email using a Gmail account, you can add the user name and password needed for the application to send email. See the article "Send Email with Rails":http://railsapps.github.io/rails-send-email.html. 238 | 239 | If you wish, set your name, email address, and password for the first user's account. If you prefer, you can use the default to sign in to the application and edit the account after deployment. It is always a good idea to change the password after the application is deployed. 240 | 241 | All configuration values in the *config/application.yml* file are available anywhere in the application as environment variables. For example, @ENV["GMAIL_USERNAME"]@ will return the string "Your_Username". 242 | 243 | If you prefer, you can delete the *config/application.yml* file and set each value as an environment variable in the Unix shell. 244 | 245 | h3. Set Up a Database Seed File 246 | 247 | The *db/seeds.rb* file initializes the database with default values. To keep some data private, and consolidate configuration settings in a single location, we use the *config/application.yml* file to set environment variables and then use the environment variables in the *db/seeds.rb* file. 248 | 249 |
250 | puts 'DEFAULT USERS' 251 | user = User.create! :name => ENV['ADMIN_NAME'].dup, :email => ENV['ADMIN_EMAIL'].dup, :password => ENV['ADMIN_PASSWORD'].dup, :password_confirmation => ENV['ADMIN_PASSWORD'].dup 252 | puts 'user: ' << user.name 253 |254 | 255 | You can change the first user's name, email, and password in this file but it is better to make the changes in the *config/application.yml* file to keep the credentials private. If you decide to include your private password in the *db/seeds.rb* file, be sure to add the filename to your *.gitignore* file so that your password doesn't become available in your public GitHub repository. 256 | 257 | Note that it's not necessary to personalize the *db/seeds.rb* file before you deploy your app. You can deploy the app with an example user and then use the application's "Edit Account" feature to change name, email address, and password after you log in. Use this feature to log in as the first user and change the user name and password to your own. 258 | 259 | You may wish to include additional sample users: 260 | 261 |
262 | user2 = User.create! :name => 'Second User', :email => 'user2@example.com', :password => 'changeme', :password_confirmation => 'changeme' 263 | puts 'user: ' << user2.name 264 |265 | 266 | This will add a second user to the database. 267 | 268 | h3. Set the Database 269 | 270 | Prepare the database and add the default user to the database by running the commands: 271 | 272 |
273 | $ rake db:seed 274 |275 | 276 | Use @rake db:reseed@ if you want to empty and reseed the database. Or you can use @rake db:drop@ and @rake db:setup@. The equivalent task for Rails with ActiveRecord is @rake db:reset@ which will be available in Mongoid 4.0. 277 | 278 | Set the database for running tests: 279 | 280 |
281 | $ rake db:test:prepare 282 |283 | 284 | If you’re not using "rvm":https://rvm.io/, the Ruby Version Manager, you should preface each rake command with @bundle exec@. You don’t need to use @bundle exec@ if you are using rvm version 1.11.0 or newer. 285 | 286 | h3. Change your Application's Secret Token 287 | 288 | If you've used the Rails Composer tool to generate the application, the application's secret token will be unique, just as with any Rails application generated with the @rails new@ command. 289 | 290 | However, if you've cloned the application directly from GitHub, it is crucial that you change the application's secret token before deploying your application in production mode. Otherwise, people could change their session information, and potentially access your site without your permission. Your secret token should be at least 30 characters long and completely random. 291 | 292 | Get a unique secret token: 293 | 294 |
295 | rake secret 296 |297 | 298 | Edit your *config/initializers/secret_token.rb* file to add the secret token: 299 | 300 |
301 | Rails3MongoidDevise::Application.config.secret_token = '...some really long, random string...' 302 |303 | 304 | h2. Test the App 305 | 306 | You can check that your app runs properly by entering the command 307 | 308 | @$ rails server@ 309 | 310 | To see your application in action, open a browser window and navigate to "http://localhost:3000/":http://localhost:3000. You should see the default user listed on the home page. When you click on the user's name, you should be required to log in before seeing the user's detail page. 311 | 312 | To sign in as the default user, (unless you've changed it) use 313 | 314 | * email: user@example.com 315 | * password: changeme 316 | 317 | You should delete or change the pre-configured logins before you deploy your application. 318 | 319 | If you test the app by starting the web server and then leave the server running while you install new gems, you’ll have to restart the server to see any changes. The same is true for changes to configuration files in the config folder. This can be confusing to new Rails developers because you can change files in the app folders without restarting the server. Stop the server each time after testing and you will avoid this issue. 320 | 321 | h2. Deploy to Heroku 322 | 323 | For your convenience, here are "instructions for deploying your app to Heroku":http://railsapps.github.io/rails-heroku-tutorial.html. Heroku provides low cost, easily configured Rails application hosting. 324 | 325 | h2. Customizing 326 | 327 | "Devise":http://github.com/plataformatec/devise provides a variety of features for implementing authentication. See the Devise documentation for options. 328 | 329 | This example application and tutorial demonstrates Devise and Mongoid working together on Rails 3. Add any models, controllers, and views that you need. 330 | 331 | h2. Testing 332 | 333 | The example application contains a suite of RSpec unit tests and Cucumber scenarios and step definitions. 334 | 335 | After installing the application, run @rake -T@ to check that rake tasks for RSpec and Cucumber are available. 336 | 337 | Run @rake spec@ to run RSpec tests. 338 | 339 | Run @rake cucumber@ (or more simply, @cucumber@) to run Cucumber scenarios. 340 | 341 | Please send the author a message, create an issue, or submit a pull request if you can contribute improved RSpec or Cucumber files. 342 | 343 | h2. Troubleshooting 344 | 345 | Problems? Check the "issues":https://github.com/RailsApps/rails3-mongoid-devise/issues. 346 | 347 | h4. Problems with "Certificate Verify Failed" 348 | 349 | Are you getting an error "OpenSSL certificate verify failed" when you try to generate a new Rails app from an application template? See suggestions to resolve the error "Certificate Verify Failed":http://railsapps.github.io/openssl-certificate-verify-failed.html. 350 | 351 | h2. Documentation and Support 352 | 353 | The "tutorial":http://railsapps.github.io/tutorial-rails-mongoid-devise.html provides additional documentation. 354 | 355 | For a Mongoid introduction, Ryan Bates offers a "Railscast on Mongoid":http://railscasts.com/episodes/238-mongoid. You can find documentation for "Mongoid":http://mongoid.org/ at "http://mongoid.org/":http://mongoid.org/ There is an active "Mongoid mailing list":http://groups.google.com/group/mongoid and you can submit "Mongoid issues":http://github.com/durran/mongoid/issues at GitHub. 356 | 357 | For a Devise introduction, Ryan Bates offers a "Railscast on Devise":http://railscasts.com/episodes/209-introducing-devise. You can find documentation for "Devise":http://github.com/plataformatec/devise at "http://github.com/plataformatec/devise":http://github.com/plataformatec/devise. There is an active "Devise mailing list":http://groups.google.com/group/plataformatec-devise and you can submit "Devise issues":http://github.com/plataformatec/devise/issues at GitHub. 358 | 359 | h4. Issues 360 | 361 | Please create an "issue on GitHub":http://github.com/RailsApps/rails3-mongoid-devise/issues if you identify any problems or have suggestions for improvements. 362 | 363 | h4. Where to Get Help 364 | 365 | Your best source for help with problems is "Stack Overflow":http://stackoverflow.com/questions/tagged/ruby-on-rails-3. Your issue may have been encountered and addressed by others. 366 | 367 | You can also try "Rails Hotline":http://www.railshotline.com/, a free telephone hotline for Rails help staffed by volunteers. 368 | 369 | h2. Contributing 370 | 371 | If you make improvements to this application, please share with others. 372 | 373 | Send the author a message, create an "issue":http://github.com/RailsApps/rails3-mongoid-devise/issues, or fork the project and submit a pull request. 374 | 375 | 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. 376 | 377 | h2. Credits 378 | 379 | Daniel Kehoe implemented the application and wrote the tutorial. 380 | 381 | Is the app useful to you? Follow the project on Twitter: "@rails_apps":http://twitter.com/rails_apps 382 | and tweet some praise. I'd love to know you were helped out by what I've put together. 383 | 384 | h4. Contributors 385 | 386 | Thank you for improvements to the tutorial by contributors: 387 | 388 | * "Cory Foy":https://github.com/CoryFoy 389 | * "Luca G. Soave":https://github.com/lgs 390 | * "Bob Clewell":https://github.com/bobclewell 391 | * "Justin Workman":https://github.com/xtagon 392 | * "Tom von Schwerdtner":https://github.com/tvon 393 | 394 | h2. MIT License 395 | 396 | "MIT License":http://www.opensource.org/licenses/mit-license 397 | 398 | Copyright © 2012 Daniel Kehoe 399 | 400 | h2. Useful Links 401 | 402 | |_. Getting Started |_. Articles |_. Tutorials | 403 | | "Ruby on Rails":http://railsapps.github.io/ruby-and-rails.html | "Analytics for Rails":http://railsapps.github.io/rails-google-analytics.html | "Rails Bootstrap":http://railsapps.github.io/twitter-bootstrap-rails.html | 404 | | "What is Ruby on Rails?":http://railsapps.github.io/what-is-ruby-rails.html | "Heroku and Rails":http://railsapps.github.io/rails-heroku-tutorial.html | "Rails Foundation":http://railsapps.github.io/rails-foundation.html | 405 | | "Learn Ruby on Rails":http://learn-rails.com/learn-ruby-on-rails.html | "JavaScript and Rails":http://railsapps.github.io/rails-javascript-include-external.html | "RSpec Tutorial":http://railsapps.github.io/rspec.html | 406 | | "Rails Tutorial":https://tutorials.railsapps.org/rails-tutorial | "Rails Environment Variables":http://railsapps.github.io/rails-environment-variables.html | "Rails Devise Tutorial":http://railsapps.github.io/tutorial-rails-devise.html | 407 | | "Ruby on Rails Tutorial for Beginners":http://learn-rails.com/ruby-on-rails-tutorial-for-beginners | "Git and GitHub with Rails":http://railsapps.github.io/rails-git.html | "Devise RSpec":http://railsapps.github.io/tutorial-rails-devise-rspec-cucumber.html | 408 | | "Install Ruby on Rails":http://railsapps.github.io/installing-rails.html | "Send Email with Rails":http://railsapps.github.io/rails-send-email.html | "Devise Bootstrap":http://railsapps.github.io/tutorial-rails-bootstrap-devise-cancan.html | 409 | | "Install Ruby on Rails - Mac OS X":http://railsapps.github.io/installrubyonrails-mac.html | "Haml and Rails":http://railsapps.github.io/rails-haml.html | "Rails Membership Site with Stripe":https://tutorials.railsapps.org/rails-stripe-membership-saas | 410 | | "Install Ruby on Rails - Ubuntu":http://railsapps.github.io/installrubyonrails-ubuntu.html | "Rails Application Layout":http://railsapps.github.io/rails-default-application-layout.html | "Rails Subscription Site with Recurly":https://tutorials.railsapps.org/rails-recurly-subscription-saas | 411 | | "Ruby on Rails - Nitrous.io":http://railsapps.github.io/rubyonrails-nitrous-io.html | "HTML5 Boilerplate for Rails":http://railsapps.github.io/rails-html5-boilerplate.html | "Startup Prelaunch Signup Application":https://tutorials.railsapps.org/rails-prelaunch-signup | 412 | | "Update Rails":http://railsapps.github.io/updating-rails.html | "Example Gemfiles for Rails":http://railsapps.github.io/rails-3-2-example-gemfile.html | 413 | | "Rails Composer":http://railsapps.github.io/rails-composer/ | "Rails Application Templates":http://railsapps.github.io/rails-application-templates.html | 414 | | "Rails Examples":http://railsapps.github.io/ | "Rails Product Planning":http://railsapps.github.io/rails-product-planning.html | 415 | | "Rails Starter Apps":http://railsapps.github.io/rails-examples-tutorials.html | "Rails Project Management":http://railsapps.github.io/rails-project-management.html | 416 | 417 | !https://cruel-carlota.pagodabox.com/71628a7b3fd9644aaf6b5bd279dac05d(githalytics.com alpha)! 418 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | # Add your own tasks in files placed in lib/tasks ending in .rake, 3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 4 | 5 | require File.expand_path('../config/application', __FILE__) 6 | 7 | Rails3MongoidDevise::Application.load_tasks 8 | -------------------------------------------------------------------------------- /app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // the compiled file. 9 | // 10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD 11 | // GO AFTER THE REQUIRES BELOW. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require_tree . 16 | -------------------------------------------------------------------------------- /app/assets/javascripts/home.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css.scss: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the top of the 9 | * compiled file, but it's generally better to create a new file per style scope. 10 | * 11 | *= require_self 12 | *= require_tree . 13 | */ 14 | .brand { 15 | float: left; 16 | padding-right: 8px; 17 | } 18 | ul.nav { 19 | list-style: none; 20 | margin: 0 0 2em; 21 | padding: 0; 22 | } 23 | ul.nav li { 24 | display: inline; 25 | } 26 | #flash_notice, #flash_alert { 27 | padding: 5px 8px; 28 | margin: 10px 0; 29 | } 30 | #flash_notice { 31 | background-color: #CFC; 32 | border: solid 1px #6C6; 33 | } 34 | #flash_alert { 35 | background-color: #FCC; 36 | border: solid 1px #C66; 37 | } 38 | -------------------------------------------------------------------------------- /app/assets/stylesheets/home.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the home controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery 3 | end 4 | -------------------------------------------------------------------------------- /app/controllers/home_controller.rb: -------------------------------------------------------------------------------- 1 | class HomeController < ApplicationController 2 | def index 3 | @users = User.all 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /app/controllers/users_controller.rb: -------------------------------------------------------------------------------- 1 | class UsersController < ApplicationController 2 | before_filter :authenticate_user! 3 | 4 | def index 5 | @users = User.all 6 | end 7 | 8 | def show 9 | @user = User.find(params[:id]) 10 | end 11 | 12 | end 13 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/home_helper.rb: -------------------------------------------------------------------------------- 1 | module HomeHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/mailers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RailsApps/rails3-mongoid-devise/be1e4b9e111fbfe73905c47d09464843b71e019c/app/mailers/.gitkeep -------------------------------------------------------------------------------- /app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RailsApps/rails3-mongoid-devise/be1e4b9e111fbfe73905c47d09464843b71e019c/app/models/.gitkeep -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User 2 | include Mongoid::Document 3 | include Mongoid::Timestamps 4 | 5 | # Include default devise modules. Others available are: 6 | # :token_authenticatable, :confirmable, 7 | # :lockable, :timeoutable and :omniauthable 8 | devise :database_authenticatable, :registerable, 9 | :recoverable, :rememberable, :trackable, :validatable 10 | 11 | ## Database authenticatable 12 | field :email, :type => String, :default => "" 13 | field :encrypted_password, :type => String, :default => "" 14 | 15 | validates_presence_of :email 16 | validates_presence_of :encrypted_password 17 | 18 | ## Recoverable 19 | field :reset_password_token, :type => String 20 | field :reset_password_sent_at, :type => Time 21 | 22 | ## Rememberable 23 | field :remember_created_at, :type => Time 24 | 25 | ## Trackable 26 | field :sign_in_count, :type => Integer, :default => 0 27 | field :current_sign_in_at, :type => Time 28 | field :last_sign_in_at, :type => Time 29 | field :current_sign_in_ip, :type => String 30 | field :last_sign_in_ip, :type => String 31 | 32 | ## Confirmable 33 | # field :confirmation_token, :type => String 34 | # field :confirmed_at, :type => Time 35 | # field :confirmation_sent_at, :type => Time 36 | # field :unconfirmed_email, :type => String # Only if using reconfirmable 37 | 38 | ## Lockable 39 | # field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts 40 | # field :unlock_token, :type => String # Only if unlock strategy is :email or :both 41 | # field :locked_at, :type => Time 42 | 43 | ## Token authenticatable 44 | # field :authentication_token, :type => String 45 | # run 'rake db:mongoid:create_indexes' to create indexes 46 | index({ email: 1 }, { unique: true, background: true }) 47 | field :name, :type => String 48 | validates_presence_of :name 49 | attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :created_at, :updated_at 50 | end 51 | -------------------------------------------------------------------------------- /app/views/devise/registrations/edit.html.erb: -------------------------------------------------------------------------------- 1 |
<%= f.label :name %>
6 | <%= f.text_field :name %>
Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>.
26 | 27 | <%= link_to "Back", :back %> 28 | -------------------------------------------------------------------------------- /app/views/devise/registrations/new.html.erb: -------------------------------------------------------------------------------- 1 |<%= f.label :name %>
6 | <%= f.text_field :name %>
User: <%=link_to user.name, user %>
4 | <% end %> 5 | -------------------------------------------------------------------------------- /app/views/layouts/_messages.html.erb: -------------------------------------------------------------------------------- 1 | <% flash.each do |name, msg| %> 2 | <% if msg.is_a?(String) %> 3 | <%= content_tag :div, msg, :id => "flash_#{name}" %> 4 | <% end %> 5 | <% end %> 6 | -------------------------------------------------------------------------------- /app/views/layouts/_navigation.html.erb: -------------------------------------------------------------------------------- 1 | <%= link_to "Rails3 Mongoid Devise", root_path, :class => 'brand' %> 2 | 22 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |User: <%= @user.name %>
3 |Email: <%= @user.email if @user.email %>
4 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails3MongoidDevise::Application 5 | -------------------------------------------------------------------------------- /config/application.example.yml: -------------------------------------------------------------------------------- 1 | # Add account credentials and API keys here. 2 | # See http://railsapps.github.io/rails-environment-variables.html 3 | # This file should be listed in .gitignore to keep your settings secret! 4 | # Each entry sets a local environment variable and overrides ENV variables in the Unix shell. 5 | # For example, setting: 6 | # GMAIL_USERNAME: Your_Gmail_Username 7 | # makes 'Your_Gmail_Username' available as ENV["GMAIL_USERNAME"] 8 | # Add application configuration variables here, as shown below. 9 | # 10 | GMAIL_USERNAME: Your_Username 11 | GMAIL_PASSWORD: Your_Password 12 | ADMIN_NAME: First User 13 | ADMIN_EMAIL: user@example.com 14 | ADMIN_PASSWORD: changeme 15 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 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 "sprockets/railtie" 9 | # # require "rails/test_unit/railtie" 10 | 11 | if defined?(Bundler) 12 | # If you precompile assets before deploying to production, use this line 13 | Bundler.require(*Rails.groups(:assets => %w(development test))) 14 | # If you want your assets lazily compiled in production, use this line 15 | # Bundler.require(:default, :assets, Rails.env) 16 | end 17 | 18 | module Rails3MongoidDevise 19 | class Application < Rails::Application 20 | 21 | # don't generate RSpec tests for views and helpers 22 | config.generators do |g| 23 | 24 | g.test_framework :rspec, fixture: true 25 | g.fixture_replacement :factory_girl, dir: 'spec/factories' 26 | 27 | 28 | g.view_specs false 29 | g.helper_specs false 30 | end 31 | 32 | # Settings in config/environments/* take precedence over those specified here. 33 | # Application configuration should go into files in config/initializers 34 | # -- all .rb files in that directory are automatically loaded. 35 | 36 | # Custom directories with classes and modules you want to be autoloadable. 37 | # config.autoload_paths += %W(#{config.root}/extras) 38 | config.autoload_paths += %W(#{config.root}/lib) 39 | 40 | 41 | # Only load the plugins named here, in the order given (default is alphabetical). 42 | # :all can be used as a placeholder for all plugins not explicitly named. 43 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 44 | 45 | # Activate observers that should always be running. 46 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 47 | 48 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 49 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 50 | # config.time_zone = 'Central Time (US & Canada)' 51 | 52 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 53 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 54 | # config.i18n.default_locale = :de 55 | 56 | # Configure the default encoding used in templates for Ruby 1.9. 57 | config.encoding = "utf-8" 58 | 59 | # Configure sensitive parameters which will be filtered from the log file. 60 | config.filter_parameters += [:password, :password_confirmation] 61 | 62 | # Enable escaping HTML in JSON. 63 | config.active_support.escape_html_entities_in_json = true 64 | 65 | # Use SQL instead of Active Record's schema dumper when creating the database. 66 | # This is necessary if your schema can't be completely dumped by the schema dumper, 67 | # like if you have constraints or database-specific column types 68 | # config.active_record.schema_format = :sql 69 | 70 | # Enforce whitelist mode for mass assignment. 71 | # This will create an empty whitelist of attributes available for mass-assignment for all models 72 | # in your app. As such, your models will need to explicitly whitelist or blacklist accessible 73 | # parameters by using an attr_accessible or attr_protected declaration. 74 | # config.active_record.whitelist_attributes = true 75 | 76 | # Enable the asset pipeline 77 | config.assets.enabled = true 78 | 79 | # Version of your assets, change this if you want to expire all your assets 80 | config.assets.version = '1.0' 81 | end 82 | end 83 | -------------------------------------------------------------------------------- /config/application.yml: -------------------------------------------------------------------------------- 1 | # Add account credentials and API keys here. 2 | # See http://railsapps.github.io/rails-environment-variables.html 3 | # This file should be listed in .gitignore to keep your settings secret! 4 | # Each entry sets a local environment variable and overrides ENV variables in the Unix shell. 5 | # For example, setting: 6 | # GMAIL_USERNAME: Your_Gmail_Username 7 | # makes 'Your_Gmail_Username' available as ENV["GMAIL_USERNAME"] 8 | # Add application configuration variables here, as shown below. 9 | # 10 | GMAIL_USERNAME: Your_Username 11 | GMAIL_PASSWORD: Your_Password 12 | ADMIN_NAME: First User 13 | ADMIN_EMAIL: user@example.com 14 | ADMIN_PASSWORD: changeme 15 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 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']) 7 | -------------------------------------------------------------------------------- /config/cucumber.yml: -------------------------------------------------------------------------------- 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 = "-r features/support/ -r features/step_definitions --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 9 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | Rails3MongoidDevise::Application.initialize! 6 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails3MongoidDevise::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 web server 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_controller.perform_caching = false 15 | 16 | # ActionMailer Config 17 | config.action_mailer.default_url_options = { :host => 'localhost:3000' } 18 | config.action_mailer.delivery_method = :smtp 19 | # change to true to allow email to be sent during development 20 | config.action_mailer.perform_deliveries = false 21 | config.action_mailer.raise_delivery_errors = true 22 | config.action_mailer.default :charset => "utf-8" 23 | 24 | 25 | # Print deprecation notices to the Rails logger 26 | config.active_support.deprecation = :log 27 | 28 | # Only use best-standards-support built into browsers 29 | config.action_dispatch.best_standards_support = :builtin 30 | 31 | 32 | # Do not compress assets 33 | config.assets.compress = false 34 | 35 | # Expands the lines which load the assets 36 | config.assets.debug = true 37 | 38 | config.action_mailer.smtp_settings = { 39 | address: "smtp.gmail.com", 40 | port: 587, 41 | domain: ENV["DOMAIN_NAME"], 42 | authentication: "plain", 43 | enable_starttls_auto: true, 44 | user_name: ENV["GMAIL_USERNAME"], 45 | password: ENV["GMAIL_PASSWORD"] 46 | } 47 | 48 | end 49 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails3MongoidDevise::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # Code is not reloaded between requests 5 | config.cache_classes = true 6 | 7 | # Full error reports are disabled and caching is turned on 8 | config.consider_all_requests_local = false 9 | config.action_controller.perform_caching = true 10 | 11 | # Disable Rails's static asset server (Apache or nginx will already do this) 12 | config.serve_static_assets = false 13 | 14 | # Compress JavaScripts and CSS 15 | config.assets.compress = true 16 | 17 | # Don't fallback to assets pipeline if a precompiled asset is missed 18 | config.assets.compile = false 19 | 20 | # Generate digests for assets URLs 21 | config.assets.digest = true 22 | 23 | # Defaults to nil and saved in location specified by config.assets.prefix 24 | # config.assets.manifest = YOUR_PATH 25 | 26 | # Specifies the header that your server uses for sending files 27 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 28 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 29 | 30 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 31 | # config.force_ssl = true 32 | 33 | # See everything in the log (default is :info) 34 | # config.log_level = :debug 35 | 36 | # Prepend all log lines with the following tags 37 | # config.log_tags = [ :subdomain, :uuid ] 38 | 39 | # Use a different logger for distributed setups 40 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 41 | 42 | # Use a different cache store in production 43 | # config.cache_store = :mem_cache_store 44 | 45 | # Enable serving of images, stylesheets, and JavaScripts from an asset server 46 | # config.action_controller.asset_host = "http://assets.example.com" 47 | 48 | # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 49 | # config.assets.precompile += %w( search.js ) 50 | 51 | # Disable delivery errors, bad email addresses will be ignored 52 | # config.action_mailer.raise_delivery_errors = false 53 | 54 | # Enable threaded mode 55 | # config.threadsafe! 56 | 57 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 58 | # the I18n.default_locale when a translation can not be found) 59 | config.i18n.fallbacks = true 60 | 61 | # Send deprecation notices to registered listeners 62 | config.active_support.deprecation = :notify 63 | 64 | config.action_mailer.smtp_settings = { 65 | address: "smtp.gmail.com", 66 | port: 587, 67 | domain: ENV["DOMAIN_NAME"], 68 | authentication: "plain", 69 | enable_starttls_auto: true, 70 | user_name: ENV["GMAIL_USERNAME"], 71 | password: ENV["GMAIL_PASSWORD"] 72 | } 73 | 74 | 75 | config.action_mailer.default_url_options = { :host => 'example.com' } 76 | # ActionMailer Config 77 | # Setup for production - deliveries, no errors raised 78 | config.action_mailer.delivery_method = :smtp 79 | config.action_mailer.perform_deliveries = true 80 | config.action_mailer.raise_delivery_errors = false 81 | config.action_mailer.default :charset => "utf-8" 82 | 83 | 84 | end 85 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails3MongoidDevise::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 | # Configure static asset server for tests with Cache-Control for performance 11 | config.serve_static_assets = true 12 | config.static_cache_control = "public, max-age=3600" 13 | 14 | # Log error messages when you accidentally call methods on nil 15 | config.whiny_nils = true 16 | 17 | # Show full error reports and disable caching 18 | config.consider_all_requests_local = true 19 | config.action_controller.perform_caching = false 20 | 21 | # Raise exceptions instead of rendering exception templates 22 | config.action_dispatch.show_exceptions = false 23 | 24 | # Disable request forgery protection in test environment 25 | config.action_controller.allow_forgery_protection = false 26 | 27 | # Tell Action Mailer not to deliver emails to the real world. 28 | # The :test delivery method accumulates sent emails in the 29 | # ActionMailer::Base.deliveries array. 30 | config.action_mailer.delivery_method = :test 31 | 32 | 33 | # Print deprecation notices to the stderr 34 | config.active_support.deprecation = :stderr 35 | 36 | # ActionMailer Config 37 | config.action_mailer.default_url_options = { :host => 'example.com' } 38 | 39 | end 40 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 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! 8 | -------------------------------------------------------------------------------- /config/initializers/devise.rb: -------------------------------------------------------------------------------- 1 | # Use this hook to configure devise mailer, warden hooks and so forth. 2 | # Many of these configuration options can be set straight in your model. 3 | Devise.setup do |config| 4 | # ==> Mailer Configuration 5 | # Configure the e-mail address which will be shown in Devise::Mailer, 6 | # note that it will be overwritten if you use your own mailer class with default "from" parameter. 7 | config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" 8 | 9 | # Configure the class responsible to send e-mails. 10 | # config.mailer = "Devise::Mailer" 11 | 12 | # ==> ORM configuration 13 | # Load and configure the ORM. Supports :active_record (default) and 14 | # :mongoid (bson_ext recommended) by default. Other ORMs may be 15 | # available as additional gems. 16 | require 'devise/orm/mongoid' 17 | 18 | # ==> Configuration for any authentication mechanism 19 | # Configure which keys are used when authenticating a user. The default is 20 | # just :email. You can configure it to use [:username, :subdomain], so for 21 | # authenticating a user, both parameters are required. Remember that those 22 | # parameters are used only when authenticating and not when retrieving from 23 | # session. If you need permissions, you should implement that in a before filter. 24 | # You can also supply a hash where the value is a boolean determining whether 25 | # or not authentication should be aborted when the value is not present. 26 | # config.authentication_keys = [ :email ] 27 | 28 | # Configure parameters from the request object used for authentication. Each entry 29 | # given should be a request method and it will automatically be passed to the 30 | # find_for_authentication method and considered in your model lookup. For instance, 31 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. 32 | # The same considerations mentioned for authentication_keys also apply to request_keys. 33 | # config.request_keys = [] 34 | 35 | # Configure which authentication keys should be case-insensitive. 36 | # These keys will be downcased upon creating or modifying a user and when used 37 | # to authenticate or find a user. Default is :email. 38 | config.case_insensitive_keys = [ :email ] 39 | 40 | # Configure which authentication keys should have whitespace stripped. 41 | # These keys will have whitespace before and after removed upon creating or 42 | # modifying a user and when used to authenticate or find a user. Default is :email. 43 | config.strip_whitespace_keys = [ :email ] 44 | 45 | # Tell if authentication through request.params is enabled. True by default. 46 | # It can be set to an array that will enable params authentication only for the 47 | # given strategies, for example, `config.params_authenticatable = [:database]` will 48 | # enable it only for database (email + password) authentication. 49 | # config.params_authenticatable = true 50 | 51 | # Tell if authentication through HTTP Auth is enabled. False by default. 52 | # It can be set to an array that will enable http authentication only for the 53 | # given strategies, for example, `config.http_authenticatable = [:token]` will 54 | # enable it only for token authentication. The supported strategies are: 55 | # :database = Support basic authentication with authentication key + password 56 | # :token = Support basic authentication with token authentication key 57 | # :token_options = Support token authentication with options as defined in 58 | # http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Token.html 59 | # config.http_authenticatable = false 60 | 61 | # If http headers should be returned for AJAX requests. True by default. 62 | # config.http_authenticatable_on_xhr = true 63 | 64 | # The realm used in Http Basic Authentication. "Application" by default. 65 | # config.http_authentication_realm = "Application" 66 | 67 | # It will change confirmation, password recovery and other workflows 68 | # to behave the same regardless if the e-mail provided was right or wrong. 69 | # Does not affect registerable. 70 | # config.paranoid = true 71 | 72 | # By default Devise will store the user in session. You can skip storage for 73 | # :http_auth and :token_auth by adding those symbols to the array below. 74 | # Notice that if you are skipping storage for all authentication paths, you 75 | # may want to disable generating routes to Devise's sessions controller by 76 | # passing :skip => :sessions to `devise_for` in your config/routes.rb 77 | config.skip_session_storage = [:http_auth] 78 | 79 | # By default, Devise cleans up the CSRF token on authentication to 80 | # avoid CSRF token fixation attacks. This means that, when using AJAX 81 | # requests for sign in and sign up, you need to get a new CSRF token 82 | # from the server. You can disable this option at your own risk. 83 | # config.clean_up_csrf_token_on_authentication = true 84 | 85 | # ==> Configuration for :database_authenticatable 86 | # For bcrypt, this is the cost for hashing the password and defaults to 10. If 87 | # using other encryptors, it sets how many times you want the password re-encrypted. 88 | # 89 | # Limiting the stretches to just one in testing will increase the performance of 90 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use 91 | # a value less than 10 in other environments. 92 | config.stretches = Rails.env.test? ? 1 : 10 93 | 94 | # Setup a pepper to generate the encrypted password. 95 | # config.pepper = "aa8c9e6e4405808e756a15e7ace3d7f3d620bf7d4179196e9e5a08538ead06588d9278ae2deb9e57ef892084fed9c292b10ac13a18f928c892a758404cab0572" 96 | 97 | # ==> Configuration for :confirmable 98 | # A period that the user is allowed to access the website even without 99 | # confirming his account. For instance, if set to 2.days, the user will be 100 | # able to access the website for two days without confirming his account, 101 | # access will be blocked just in the third day. Default is 0.days, meaning 102 | # the user cannot access the website without confirming his account. 103 | # config.allow_unconfirmed_access_for = 2.days 104 | 105 | # A period that the user is allowed to confirm their account before their 106 | # token becomes invalid. For example, if set to 3.days, the user can confirm 107 | # their account within 3 days after the mail was sent, but on the fourth day 108 | # their account can't be confirmed with the token any more. 109 | # Default is nil, meaning there is no restriction on how long a user can take 110 | # before confirming their account. 111 | # config.confirm_within = 3.days 112 | 113 | # If true, requires any email changes to be confirmed (exactly the same way as 114 | # initial account confirmation) to be applied. Requires additional unconfirmed_email 115 | # db field (see migrations). Until confirmed new email is stored in 116 | # unconfirmed email column, and copied to email column on successful confirmation. 117 | config.reconfirmable = true 118 | 119 | # Defines which key will be used when confirming an account 120 | # config.confirmation_keys = [ :email ] 121 | 122 | # ==> Configuration for :rememberable 123 | # The time the user will be remembered without asking for credentials again. 124 | # config.remember_for = 2.weeks 125 | 126 | # If true, extends the user's remember period when remembered via cookie. 127 | # config.extend_remember_period = false 128 | 129 | # Options to be passed to the created cookie. For instance, you can set 130 | # :secure => true in order to force SSL only cookies. 131 | # config.rememberable_options = {} 132 | 133 | # ==> Configuration for :validatable 134 | # Range for password length. Default is 8..128. 135 | config.password_length = 8..128 136 | 137 | # Email regex used to validate email formats. It simply asserts that 138 | # one (and only one) @ exists in the given string. This is mainly 139 | # to give user feedback and not to assert the e-mail validity. 140 | # config.email_regexp = /\A[^@]+@[^@]+\z/ 141 | 142 | # ==> Configuration for :timeoutable 143 | # The time you want to timeout the user session without activity. After this 144 | # time the user will be asked for credentials again. Default is 30 minutes. 145 | # config.timeout_in = 30.minutes 146 | 147 | # If true, expires auth token on session timeout. 148 | # config.expire_auth_token_on_timeout = false 149 | 150 | # ==> Configuration for :lockable 151 | # Defines which strategy will be used to lock an account. 152 | # :failed_attempts = Locks an account after a number of failed attempts to sign in. 153 | # :none = No lock strategy. You should handle locking by yourself. 154 | # config.lock_strategy = :failed_attempts 155 | 156 | # Defines which key will be used when locking and unlocking an account 157 | # config.unlock_keys = [ :email ] 158 | 159 | # Defines which strategy will be used to unlock an account. 160 | # :email = Sends an unlock link to the user email 161 | # :time = Re-enables login after a certain amount of time (see :unlock_in below) 162 | # :both = Enables both strategies 163 | # :none = No unlock strategy. You should handle unlocking by yourself. 164 | # config.unlock_strategy = :both 165 | 166 | # Number of authentication tries before locking an account if lock_strategy 167 | # is failed attempts. 168 | # config.maximum_attempts = 20 169 | 170 | # Time interval to unlock the account if :time is enabled as unlock_strategy. 171 | # config.unlock_in = 1.hour 172 | 173 | # ==> Configuration for :recoverable 174 | # 175 | # Defines which key will be used when recovering the password for an account 176 | # config.reset_password_keys = [ :email ] 177 | 178 | # Time interval you can reset your password with a reset password key. 179 | # Don't put a too small interval or your users won't have the time to 180 | # change their passwords. 181 | config.reset_password_within = 6.hours 182 | 183 | # ==> Configuration for :encryptable 184 | # Allow you to use another encryption algorithm besides bcrypt (default). You can use 185 | # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, 186 | # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) 187 | # and :restful_authentication_sha1 (then you should set stretches to 10, and copy 188 | # REST_AUTH_SITE_KEY to pepper). 189 | # 190 | # Require the `devise-encryptable` gem when using anything other than bcrypt 191 | # config.encryptor = :sha512 192 | 193 | # ==> Configuration for :token_authenticatable 194 | # Defines name of the authentication token params key 195 | # config.token_authentication_key = :auth_token 196 | 197 | # ==> Scopes configuration 198 | # Turn scoped views on. Before rendering "sessions/new", it will first check for 199 | # "users/sessions/new". It's turned off by default because it's slower if you 200 | # are using only default views. 201 | # config.scoped_views = false 202 | 203 | # Configure the default scope given to Warden. By default it's the first 204 | # devise role declared in your routes (usually :user). 205 | # config.default_scope = :user 206 | 207 | # Set this configuration to false if you want /users/sign_out to sign out 208 | # only the current scope. By default, Devise signs out all scopes. 209 | # config.sign_out_all_scopes = true 210 | 211 | # ==> Navigation configuration 212 | # Lists the formats that should be treated as navigational. Formats like 213 | # :html, should redirect to the sign in page when the user does not have 214 | # access, but formats like :xml or :json, should return 401. 215 | # 216 | # If you have any extra navigational formats, like :iphone or :mobile, you 217 | # should add them to the navigational formats lists. 218 | # 219 | # The "*/*" below is required to match Internet Explorer requests. 220 | # config.navigational_formats = ["*/*", :html] 221 | 222 | # The default HTTP method used to sign out a resource. Default is :delete. 223 | config.sign_out_via = Rails.env.test? ? :get : :delete 224 | 225 | # ==> OmniAuth 226 | # Add a new OmniAuth provider. Check the wiki for more information on setting 227 | # up on your models and hooks. 228 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' 229 | 230 | # ==> Warden configuration 231 | # If you want to use other strategies, that are not supported by Devise, or 232 | # change the failure app, you can configure them inside the config.warden block. 233 | # 234 | # config.warden do |manager| 235 | # manager.intercept_401 = false 236 | # manager.default_strategies(:scope => :user).unshift :some_external_strategy 237 | # end 238 | 239 | # ==> Mountable engine configurations 240 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine 241 | # is mountable, there are some extra configurations to be taken into account. 242 | # The following options are available, assuming the engine is mounted as: 243 | # 244 | # mount MyEngine, at: "/my_engine" 245 | # 246 | # The router that invoked `devise_for`, in the example above, would be: 247 | # config.router_name = :my_engine 248 | # 249 | # When using omniauth, Devise cannot automatically set Omniauth path, 250 | # so you need to do it manually. For the users scope, it would be: 251 | # config.omniauth_path_prefix = "/my_engine/users/auth" 252 | end 253 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 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 11 | # 12 | # These inflection rules are supported but not enabled by default: 13 | # ActiveSupport::Inflector.inflections do |inflect| 14 | # inflect.acronym 'RESTful' 15 | # end 16 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 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 6 | -------------------------------------------------------------------------------- /config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 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 | Rails3MongoidDevise::Application.config.secret_token = '2e16658ee1ca9825515d39fe72725ee4588555485984f7b668c423b16bf5ee9788ee134c715638238f49ae0638c942652e6b624544771d817e81f7810848fd12' 8 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails3MongoidDevise::Application.config.session_store :cookie_store, key: '_rails3-mongoid-devise_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 | # Rails3MongoidDevise::Application.config.session_store :active_record_store 9 | -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | -------------------------------------------------------------------------------- /config/locales/devise.en.yml: -------------------------------------------------------------------------------- 1 | # Additional translations at https://github.com/plataformatec/devise/wiki/I18n 2 | 3 | en: 4 | devise: 5 | confirmations: 6 | confirmed: "Your account was successfully confirmed. You are now signed in." 7 | send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes." 8 | send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes." 9 | failure: 10 | already_authenticated: "You are already signed in." 11 | inactive: "Your account was not activated yet." 12 | invalid: "Invalid email or password." 13 | invalid_token: "Invalid authentication token." 14 | locked: "Your account is locked." 15 | not_found_in_database: "Invalid email or password." 16 | timeout: "Your session expired, please sign in again to continue." 17 | unauthenticated: "You need to sign in or sign up before continuing." 18 | unconfirmed: "You have to confirm your account before continuing." 19 | mailer: 20 | confirmation_instructions: 21 | subject: "Confirmation instructions" 22 | reset_password_instructions: 23 | subject: "Reset password instructions" 24 | unlock_instructions: 25 | subject: "Unlock Instructions" 26 | omniauth_callbacks: 27 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"." 28 | success: "Successfully authenticated from %{kind} account." 29 | passwords: 30 | no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." 31 | send_instructions: "You will receive an email with instructions about how to reset your password in a few minutes." 32 | send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." 33 | updated: "Your password was changed successfully. You are now signed in." 34 | updated_not_active: "Your password was changed successfully." 35 | registrations: 36 | destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon." 37 | signed_up: "Welcome! You have signed up successfully." 38 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." 39 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." 40 | 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." 41 | 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." 42 | updated: "You updated your account successfully." 43 | sessions: 44 | signed_in: "Signed in successfully." 45 | signed_out: "Signed out successfully." 46 | unlocks: 47 | send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes." 48 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes." 49 | unlocked: "Your account has been unlocked successfully. Please sign in to continue." 50 | errors: 51 | messages: 52 | already_confirmed: "was already confirmed, please try signing in" 53 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" 54 | expired: "has expired, please request a new one" 55 | not_found: "not found" 56 | not_locked: "was not locked" 57 | not_saved: 58 | one: "1 error prohibited this %{resource} from being saved:" 59 | other: "%{count} errors prohibited this %{resource} from being saved:" 60 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Sample localization file for English. Add more files in this directory for other locales. 2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 3 | 4 | en: 5 | hello: "Hello world" 6 | -------------------------------------------------------------------------------- /config/mongoid.yml: -------------------------------------------------------------------------------- 1 | development: 2 | # Configure available database sessions. (required) 3 | sessions: 4 | # Defines the default session. (required) 5 | default: 6 | # Defines the name of the default database that Mongoid can connect to. 7 | # (required). 8 | database: rails3_mongoid_devise_development 9 | # Provides the hosts the default session can connect to. Must be an array 10 | # of host:port pairs. (required) 11 | hosts: 12 | - localhost:27017 13 | options: 14 | # Change whether the session persists in safe mode by default. 15 | # (default: false) 16 | # safe: false 17 | 18 | # Change the default consistency model to :eventual or :strong. 19 | # :eventual will send reads to secondaries, :strong sends everything 20 | # to master. (default: :eventual) 21 | # consistency: :eventual 22 | 23 | # How many times Moped should attempt to retry an operation after 24 | # failure. (default: 30) 25 | # max_retries: 30 26 | 27 | # The time in seconds that Moped should wait before retrying an 28 | # operation on failure. (default: 1) 29 | # retry_interval: 1 30 | # Configure Mongoid specific options. (optional) 31 | options: 32 | # Configuration for whether or not to allow access to fields that do 33 | # not have a field definition on the model. (default: true) 34 | # allow_dynamic_fields: true 35 | 36 | # Enable the identity map, needed for eager loading. (default: false) 37 | # identity_map_enabled: false 38 | 39 | # Includes the root model name in json serialization. (default: false) 40 | # include_root_in_json: false 41 | 42 | # Include the _type field in serializaion. (default: false) 43 | # include_type_for_serialization: false 44 | 45 | # Preload all models in development, needed when models use 46 | # inheritance. (default: false) 47 | # preload_models: false 48 | 49 | # Protect id and type from mass assignment. (default: true) 50 | # protect_sensitive_fields: true 51 | 52 | # Raise an error when performing a #find and the document is not found. 53 | # (default: true) 54 | # raise_not_found_error: true 55 | 56 | # Raise an error when defining a scope with the same name as an 57 | # existing method. (default: false) 58 | # scope_overwrite_exception: false 59 | 60 | # Skip the database version check, used when connecting to a db without 61 | # admin access. (default: false) 62 | # skip_version_check: false 63 | 64 | # User Active Support's time zone in conversions. (default: true) 65 | # use_activesupport_time_zone: true 66 | 67 | # Ensure all times are UTC in the app side. (default: false) 68 | # use_utc: false 69 | test: 70 | sessions: 71 | default: 72 | database: rails3_mongoid_devise_test 73 | hosts: 74 | - localhost:27017 75 | options: 76 | consistency: :strong 77 | # In the test environment we lower the retries and retry interval to 78 | # low amounts for fast failures. 79 | max_retries: 1 80 | retry_interval: 0 81 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails3MongoidDevise::Application.routes.draw do 2 | authenticated :user do 3 | root :to => 'home#index' 4 | end 5 | root :to => "home#index" 6 | devise_for :users 7 | resources :users 8 | end -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 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: 'Emanuel', city: cities.first) 8 | # Environment variables (ENV['...']) can be set in the file config/application.yml. 9 | # See http://railsapps.github.io/rails-environment-variables.html 10 | puts 'DEFAULT USERS' 11 | user = User.create! :name => ENV['ADMIN_NAME'].dup, :email => ENV['ADMIN_EMAIL'].dup, :password => ENV['ADMIN_PASSWORD'].dup, :password_confirmation => ENV['ADMIN_PASSWORD'].dup 12 | puts 'user: ' << user.name 13 | -------------------------------------------------------------------------------- /features/step_definitions/email_steps.rb: -------------------------------------------------------------------------------- 1 | # Commonly used email steps 2 | # 3 | # To add your own steps make a custom_email_steps.rb 4 | # The provided methods are: 5 | # 6 | # last_email_address 7 | # reset_mailer 8 | # open_last_email 9 | # visit_in_email 10 | # unread_emails_for 11 | # mailbox_for 12 | # current_email 13 | # open_email 14 | # read_emails_for 15 | # find_email 16 | # 17 | # General form for email scenarios are: 18 | # - clear the email queue (done automatically by email_spec) 19 | # - execute steps that sends an email 20 | # - check the user received an/no/[0-9] emails 21 | # - open the email 22 | # - inspect the email contents 23 | # - interact with the email (e.g. click links) 24 | # 25 | # The Cucumber steps below are setup in this order. 26 | 27 | module EmailHelpers 28 | def current_email_address 29 | # Replace with your a way to find your current email. e.g @current_user.email 30 | # last_email_address will return the last email address used by email spec to find an email. 31 | # Note that last_email_address will be reset after each Scenario. 32 | last_email_address || "example@example.com" 33 | end 34 | end 35 | 36 | World(EmailHelpers) 37 | 38 | # 39 | # Reset the e-mail queue within a scenario. 40 | # This is done automatically before each scenario. 41 | # 42 | 43 | Given /^(?:a clear email queue|no emails have been sent)$/ do 44 | reset_mailer 45 | end 46 | 47 | # 48 | # Check how many emails have been sent/received 49 | # 50 | 51 | Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount| 52 | unread_emails_for(address).size.should == parse_email_count(amount) 53 | end 54 | 55 | Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount| 56 | mailbox_for(address).size.should == parse_email_count(amount) 57 | end 58 | 59 | Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject| 60 | unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.should == parse_email_count(amount) 61 | end 62 | 63 | Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject \/([^"]*?)\/$/ do |address, amount, subject| 64 | unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size.should == parse_email_count(amount) 65 | end 66 | 67 | Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body| 68 | open_email(address, :with_text => expected_body) 69 | end 70 | 71 | # 72 | # Accessing emails 73 | # 74 | 75 | # Opens the most recently received email 76 | When /^(?:I|they|"([^"]*?)") opens? the email$/ do |address| 77 | open_email(address) 78 | end 79 | 80 | When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject| 81 | open_email(address, :with_subject => subject) 82 | end 83 | 84 | When /^(?:I|they|"([^"]*?)") opens? the email with subject \/([^"]*?)\/$/ do |address, subject| 85 | open_email(address, :with_subject => Regexp.new(subject)) 86 | end 87 | 88 | When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text| 89 | open_email(address, :with_text => text) 90 | end 91 | 92 | When /^(?:I|they|"([^"]*?)") opens? the email with text \/([^"]*?)\/$/ do |address, text| 93 | open_email(address, :with_text => Regexp.new(text)) 94 | end 95 | 96 | # 97 | # Inspect the Email Contents 98 | # 99 | 100 | Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text| 101 | current_email.should have_subject(text) 102 | end 103 | 104 | Then /^(?:I|they) should see \/([^"]*?)\/ in the email subject$/ do |text| 105 | current_email.should have_subject(Regexp.new(text)) 106 | end 107 | 108 | Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text| 109 | current_email.default_part_body.to_s.should include(text) 110 | end 111 | 112 | Then /^(?:I|they) should see \/([^"]*?)\/ in the email body$/ do |text| 113 | current_email.default_part_body.to_s.should =~ Regexp.new(text) 114 | end 115 | 116 | Then /^(?:I|they) should see the email delivered from "([^"]*?)"$/ do |text| 117 | current_email.should be_delivered_from(text) 118 | end 119 | 120 | Then /^(?:I|they) should see "([^\"]*)" in the email "([^"]*?)" header$/ do |text, name| 121 | current_email.should have_header(name, text) 122 | end 123 | 124 | Then /^(?:I|they) should see \/([^\"]*)\/ in the email "([^"]*?)" header$/ do |text, name| 125 | current_email.should have_header(name, Regexp.new(text)) 126 | end 127 | 128 | Then /^I should see it is a multi\-part email$/ do 129 | current_email.should be_multipart 130 | end 131 | 132 | Then /^(?:I|they) should see "([^"]*?)" in the email html part body$/ do |text| 133 | current_email.html_part.body.to_s.should include(text) 134 | end 135 | 136 | Then /^(?:I|they) should see "([^"]*?)" in the email text part body$/ do |text| 137 | current_email.text_part.body.to_s.should include(text) 138 | end 139 | 140 | # 141 | # Inspect the Email Attachments 142 | # 143 | 144 | Then /^(?:I|they) should see (an|no|\d+) attachments? with the email$/ do |amount| 145 | current_email_attachments.size.should == parse_email_count(amount) 146 | end 147 | 148 | Then /^there should be (an|no|\d+) attachments? named "([^"]*?)"$/ do |amount, filename| 149 | current_email_attachments.select { |a| a.filename == filename }.size.should == parse_email_count(amount) 150 | end 151 | 152 | Then /^attachment (\d+) should be named "([^"]*?)"$/ do |index, filename| 153 | current_email_attachments[(index.to_i - 1)].filename.should == filename 154 | end 155 | 156 | Then /^there should be (an|no|\d+) attachments? of type "([^"]*?)"$/ do |amount, content_type| 157 | current_email_attachments.select { |a| a.content_type.include?(content_type) }.size.should == parse_email_count(amount) 158 | end 159 | 160 | Then /^attachment (\d+) should be of type "([^"]*?)"$/ do |index, content_type| 161 | current_email_attachments[(index.to_i - 1)].content_type.should include(content_type) 162 | end 163 | 164 | Then /^all attachments should not be blank$/ do 165 | current_email_attachments.each do |attachment| 166 | attachment.read.size.should_not == 0 167 | end 168 | end 169 | 170 | Then /^show me a list of email attachments$/ do 171 | EmailSpec::EmailViewer::save_and_open_email_attachments_list(current_email) 172 | end 173 | 174 | # 175 | # Interact with Email Contents 176 | # 177 | 178 | When /^(?:I|they|"([^"]*?)") follows? "([^"]*?)" in the email$/ do |address, link| 179 | visit_in_email(link, address) 180 | end 181 | 182 | When /^(?:I|they) click the first link in the email$/ do 183 | click_first_link_in_email 184 | end 185 | 186 | # 187 | # Debugging 188 | # These only work with Rails and OSx ATM since EmailViewer uses RAILS_ROOT and OSx's 'open' command. 189 | # Patches accepted. ;) 190 | # 191 | 192 | Then /^save and open current email$/ do 193 | EmailSpec::EmailViewer::save_and_open_email(current_email) 194 | end 195 | 196 | Then /^save and open all text emails$/ do 197 | EmailSpec::EmailViewer::save_and_open_all_text_emails 198 | end 199 | 200 | Then /^save and open all html emails$/ do 201 | EmailSpec::EmailViewer::save_and_open_all_html_emails 202 | end 203 | 204 | Then /^save and open all raw emails$/ do 205 | EmailSpec::EmailViewer::save_and_open_all_raw_emails 206 | end 207 | -------------------------------------------------------------------------------- /features/step_definitions/user_steps.rb: -------------------------------------------------------------------------------- 1 | ### UTILITY METHODS ### 2 | 3 | def create_visitor 4 | @visitor ||= { :name => "Testy McUserton", :email => "example@example.com", 5 | :password => "changeme", :password_confirmation => "changeme" } 6 | end 7 | 8 | def find_user 9 | @user ||= User.where(:email => @visitor[:email]).first 10 | end 11 | 12 | def create_unconfirmed_user 13 | create_visitor 14 | delete_user 15 | sign_up 16 | visit '/users/sign_out' 17 | end 18 | 19 | def create_user 20 | create_visitor 21 | delete_user 22 | @user = FactoryGirl.create(:user, @visitor) 23 | end 24 | 25 | def delete_user 26 | @user ||= User.where(:email => @visitor[:email]).first 27 | @user.destroy unless @user.nil? 28 | end 29 | 30 | def sign_up 31 | delete_user 32 | visit '/users/sign_up' 33 | fill_in "user_name", :with => @visitor[:name] 34 | fill_in "user_email", :with => @visitor[:email] 35 | fill_in "user_password", :with => @visitor[:password] 36 | fill_in "user_password_confirmation", :with => @visitor[:password_confirmation] 37 | click_button "Sign up" 38 | find_user 39 | end 40 | 41 | def sign_in 42 | visit '/users/sign_in' 43 | fill_in "user_email", :with => @visitor[:email] 44 | fill_in "user_password", :with => @visitor[:password] 45 | click_button "Sign in" 46 | end 47 | 48 | ### GIVEN ### 49 | Given /^I am not logged in$/ do 50 | visit '/users/sign_out' 51 | end 52 | 53 | Given /^I am logged in$/ do 54 | create_user 55 | sign_in 56 | end 57 | 58 | Given /^I exist as a user$/ do 59 | create_user 60 | end 61 | 62 | Given /^I do not exist as a user$/ do 63 | create_visitor 64 | delete_user 65 | end 66 | 67 | Given /^I exist as an unconfirmed user$/ do 68 | create_unconfirmed_user 69 | end 70 | 71 | ### WHEN ### 72 | When /^I sign in with valid credentials$/ do 73 | create_visitor 74 | sign_in 75 | end 76 | 77 | When /^I sign out$/ do 78 | visit '/users/sign_out' 79 | end 80 | 81 | When /^I sign up with valid user data$/ do 82 | create_visitor 83 | sign_up 84 | end 85 | 86 | When /^I sign up with an invalid email$/ do 87 | create_visitor 88 | @visitor = @visitor.merge(:email => "notanemail") 89 | sign_up 90 | end 91 | 92 | When /^I sign up without a password confirmation$/ do 93 | create_visitor 94 | @visitor = @visitor.merge(:password_confirmation => "") 95 | sign_up 96 | end 97 | 98 | When /^I sign up without a password$/ do 99 | create_visitor 100 | @visitor = @visitor.merge(:password => "") 101 | sign_up 102 | end 103 | 104 | When /^I sign up with a mismatched password confirmation$/ do 105 | create_visitor 106 | @visitor = @visitor.merge(:password_confirmation => "changeme123") 107 | sign_up 108 | end 109 | 110 | When /^I return to the site$/ do 111 | visit '/' 112 | end 113 | 114 | When /^I sign in with a wrong email$/ do 115 | @visitor = @visitor.merge(:email => "wrong@example.com") 116 | sign_in 117 | end 118 | 119 | When /^I sign in with a wrong password$/ do 120 | @visitor = @visitor.merge(:password => "wrongpass") 121 | sign_in 122 | end 123 | 124 | When /^I edit my account details$/ do 125 | click_link "Edit account" 126 | fill_in "user_name", :with => "newname" 127 | fill_in "user_current_password", :with => @visitor[:password] 128 | click_button "Update" 129 | end 130 | 131 | When /^I look at the list of users$/ do 132 | visit '/' 133 | end 134 | 135 | ### THEN ### 136 | Then /^I should be signed in$/ do 137 | page.should have_content "Logout" 138 | page.should_not have_content "Sign up" 139 | page.should_not have_content "Login" 140 | end 141 | 142 | Then /^I should be signed out$/ do 143 | page.should have_content "Sign up" 144 | page.should have_content "Login" 145 | page.should_not have_content "Logout" 146 | end 147 | 148 | Then /^I see an unconfirmed account message$/ do 149 | page.should have_content "You have to confirm your account before continuing." 150 | end 151 | 152 | Then /^I see a successful sign in message$/ do 153 | page.should have_content "Signed in successfully." 154 | end 155 | 156 | Then /^I should see a successful sign up message$/ do 157 | page.should have_content "Welcome! You have signed up successfully." 158 | end 159 | 160 | Then /^I should see an invalid email message$/ do 161 | page.should have_content "Email is invalid" 162 | end 163 | 164 | Then /^I should see a missing password message$/ do 165 | page.should have_content "Password can't be blank" 166 | end 167 | 168 | Then /^I should see a missing password confirmation message$/ do 169 | page.should have_content "Password doesn't match confirmation" 170 | end 171 | 172 | Then /^I should see a mismatched password message$/ do 173 | page.should have_content "Password doesn't match confirmation" 174 | end 175 | 176 | Then /^I should see a signed out message$/ do 177 | page.should have_content "Signed out successfully." 178 | end 179 | 180 | Then /^I see an invalid login message$/ do 181 | page.should have_content "Invalid email or password." 182 | end 183 | 184 | Then /^I should see an account edited message$/ do 185 | page.should have_content "You updated your account successfully." 186 | end 187 | 188 | Then /^I should see my name$/ do 189 | create_user 190 | page.should have_content @user[:name] 191 | end 192 | -------------------------------------------------------------------------------- /features/support/email_spec.rb: -------------------------------------------------------------------------------- 1 | require 'email_spec/cucumber' 2 | -------------------------------------------------------------------------------- /features/support/env.rb: -------------------------------------------------------------------------------- 1 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. 2 | # It is recommended to regenerate this file in the future when you upgrade to a 3 | # newer version of cucumber-rails. Consider adding your own code to a new file 4 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb 5 | # files. 6 | 7 | require 'cucumber/rails' 8 | 9 | # Capybara defaults to CSS3 selectors rather than XPath. 10 | # If you'd prefer to use XPath, just uncomment this line and adjust any 11 | # selectors in your step definitions to use the XPath syntax. 12 | # Capybara.default_selector = :xpath 13 | 14 | # By default, any exception happening in your Rails application will bubble up 15 | # to Cucumber so that your scenario will fail. This is a different from how 16 | # your application behaves in the production environment, where an error page will 17 | # be rendered instead. 18 | # 19 | # Sometimes we want to override this default behaviour and allow Rails to rescue 20 | # exceptions and display an error page (just like when the app is running in production). 21 | # Typical scenarios where you want to do this is when you test your error pages. 22 | # There are two ways to allow Rails to rescue exceptions: 23 | # 24 | # 1) Tag your scenario (or feature) with @allow-rescue 25 | # 26 | # 2) Set the value below to true. Beware that doing this globally is not 27 | # recommended as it will mask a lot of errors for you! 28 | # 29 | ActionController::Base.allow_rescue = false 30 | 31 | # Remove/comment out the lines below if your app doesn't have a database. 32 | # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead. 33 | begin 34 | DatabaseCleaner.orm = 'mongoid' 35 | DatabaseCleaner.strategy = :truncation 36 | rescue NameError 37 | raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it." 38 | end 39 | 40 | # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios. 41 | # See the DatabaseCleaner documentation for details. Example: 42 | # 43 | # Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do 44 | # # { :except => [:widgets] } may not do what you expect here 45 | # # as Cucumber::Rails::Database.javascript_strategy overrides 46 | # # this setting. 47 | # DatabaseCleaner.strategy = :truncation 48 | # end 49 | # 50 | # Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do 51 | # DatabaseCleaner.strategy = :truncation 52 | # end 53 | # 54 | 55 | # Possible values are :truncation and :truncation 56 | # The :truncation strategy is faster, but might give you threading problems. 57 | # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature 58 | Cucumber::Rails::Database.javascript_strategy = :truncation 59 | 60 | -------------------------------------------------------------------------------- /features/support/paths.rb: -------------------------------------------------------------------------------- 1 | module NavigationHelpers 2 | # Maps a name to a path. Used by the 3 | # 4 | # When /^I go to (.+)$/ do |page_name| 5 | # 6 | # step definition in web_steps.rb 7 | # 8 | def path_to(page_name) 9 | case page_name 10 | 11 | when /the home\s?page/ 12 | '/' 13 | 14 | when /the sign up page/ 15 | '/users/sign_up' 16 | 17 | when /the sign in page/ 18 | '/users/sign_in' 19 | 20 | # Add more mappings here. 21 | # Here is an example that pulls values out of the Regexp: 22 | # 23 | # when /^(.*)'s profile page$/i 24 | # user_profile_path(User.find_by_login($1)) 25 | 26 | else 27 | begin 28 | page_name =~ /the (.*) page/ 29 | path_components = $1.split(/\s+/) 30 | self.send(path_components.push('path').join('_').to_sym) 31 | rescue Object => e 32 | raise "Can't find mapping from \"#{page_name}\" to a path.\n" + 33 | "Now, go and add a mapping in #{__FILE__}" 34 | end 35 | end 36 | end 37 | end 38 | 39 | World(NavigationHelpers) 40 | -------------------------------------------------------------------------------- /features/users/sign_in.feature: -------------------------------------------------------------------------------- 1 | Feature: Sign in 2 | In order to get access to protected sections of the site 3 | A user 4 | Should be able to sign in 5 | 6 | Scenario: User is not signed up 7 | Given I do not exist as a user 8 | When I sign in with valid credentials 9 | Then I see an invalid login message 10 | And I should be signed out 11 | 12 | Scenario: User signs in successfully 13 | Given I exist as a user 14 | And I am not logged in 15 | When I sign in with valid credentials 16 | Then I see a successful sign in message 17 | When I return to the site 18 | Then I should be signed in 19 | 20 | Scenario: User enters wrong email 21 | Given I exist as a user 22 | And I am not logged in 23 | When I sign in with a wrong email 24 | Then I see an invalid login message 25 | And I should be signed out 26 | 27 | Scenario: User enters wrong password 28 | Given I exist as a user 29 | And I am not logged in 30 | When I sign in with a wrong password 31 | Then I see an invalid login message 32 | And I should be signed out 33 | 34 | -------------------------------------------------------------------------------- /features/users/sign_out.feature: -------------------------------------------------------------------------------- 1 | Feature: Sign out 2 | To protect my account from unauthorized access 3 | A signed in user 4 | Should be able to sign out 5 | 6 | Scenario: User signs out 7 | Given I am logged in 8 | When I sign out 9 | Then I should see a signed out message 10 | When I return to the site 11 | Then I should be signed out 12 | -------------------------------------------------------------------------------- /features/users/sign_up.feature: -------------------------------------------------------------------------------- 1 | Feature: Sign up 2 | In order to get access to protected sections of the site 3 | As a user 4 | I want to be able to sign up 5 | 6 | Background: 7 | Given I am not logged in 8 | 9 | Scenario: User signs up with valid data 10 | When I sign up with valid user data 11 | Then I should see a successful sign up message 12 | 13 | Scenario: User signs up with invalid email 14 | When I sign up with an invalid email 15 | Then I should see an invalid email message 16 | 17 | Scenario: User signs up without password 18 | When I sign up without a password 19 | Then I should see a missing password message 20 | 21 | Scenario: User signs up without password confirmation 22 | When I sign up without a password confirmation 23 | Then I should see a missing password confirmation message 24 | 25 | Scenario: User signs up with mismatched password and confirmation 26 | When I sign up with a mismatched password confirmation 27 | Then I should see a mismatched password message 28 | -------------------------------------------------------------------------------- /features/users/user_edit.feature: -------------------------------------------------------------------------------- 1 | Feature: Edit User 2 | As a registered user of the website 3 | I want to edit my user profile 4 | so I can change my username 5 | 6 | Scenario: I sign in and edit my account 7 | Given I am logged in 8 | When I edit my account details 9 | Then I should see an account edited message 10 | -------------------------------------------------------------------------------- /features/users/user_show.feature: -------------------------------------------------------------------------------- 1 | Feature: Show Users 2 | As a visitor to the website 3 | I want to see registered users listed on the homepage 4 | so I can know if the site has users 5 | 6 | Scenario: Viewing users 7 | Given I exist as a user 8 | When I look at the list of users 9 | Then I should see my name 10 | -------------------------------------------------------------------------------- /lib/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RailsApps/rails3-mongoid-devise/be1e4b9e111fbfe73905c47d09464843b71e019c/lib/assets/.gitkeep -------------------------------------------------------------------------------- /lib/tasks/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RailsApps/rails3-mongoid-devise/be1e4b9e111fbfe73905c47d09464843b71e019c/lib/tasks/.gitkeep -------------------------------------------------------------------------------- /lib/tasks/cucumber.rake: -------------------------------------------------------------------------------- 1 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. 2 | # It is recommended to regenerate this file in the future when you upgrade to a 3 | # newer version of cucumber-rails. Consider adding your own code to a new file 4 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb 5 | # files. 6 | 7 | 8 | unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks 9 | 10 | vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first 11 | $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil? 12 | 13 | begin 14 | require 'cucumber/rake/task' 15 | 16 | namespace :cucumber do 17 | Cucumber::Rake::Task.new({:ok => 'test:prepare'}, 'Run features that should pass') do |t| 18 | t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. 19 | t.fork = true # You may get faster startup if you set this to false 20 | t.profile = 'default' 21 | end 22 | 23 | Cucumber::Rake::Task.new({:wip => 'test:prepare'}, 'Run features that are being worked on') do |t| 24 | t.binary = vendored_cucumber_bin 25 | t.fork = true # You may get faster startup if you set this to false 26 | t.profile = 'wip' 27 | end 28 | 29 | Cucumber::Rake::Task.new({:rerun => 'test:prepare'}, 'Record failing features and run only them if any exist') do |t| 30 | t.binary = vendored_cucumber_bin 31 | t.fork = true # You may get faster startup if you set this to false 32 | t.profile = 'rerun' 33 | end 34 | 35 | desc 'Run all features' 36 | task :all => [:ok, :wip] 37 | 38 | task :statsetup do 39 | require 'rails/code_statistics' 40 | ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features') 41 | ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features') 42 | end 43 | end 44 | desc 'Alias for cucumber:ok' 45 | task :cucumber => 'cucumber:ok' 46 | 47 | task :default => :cucumber 48 | 49 | task :features => :cucumber do 50 | STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" 51 | end 52 | 53 | # In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon. 54 | task 'test:prepare' do 55 | end 56 | 57 | task :stats => 'cucumber:statsetup' 58 | rescue LoadError 59 | desc 'cucumber rake task not available (cucumber not installed)' 60 | task :cucumber do 61 | abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin' 62 | end 63 | end 64 | 65 | end 66 | -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |You may have mistyped the address or the page may have moved.
24 |Maybe you tried to change something you didn't have access to.
24 |