7 | Site:
8 | Twitter:
9 | Location:
10 |
11 | /* THANKS */
12 | Daniel Kehoe (@rails_apps) for the RailsApps project
13 |
14 | /* SITE */
15 | Standards: HTML5, CSS3
16 | Components: jQuery
17 | Software: Ruby on Rails
18 |
19 | /* GENERATED BY */
20 | RailsApps application template: http://railsapps.github.io/
21 |
--------------------------------------------------------------------------------
/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails3Subdomains::Application.config.session_store :cookie_store, key: '_rails3-subdomains_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 | # Rails3Subdomains::Application.config.session_store :active_record_store
9 |
--------------------------------------------------------------------------------
/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/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 | Rails3Subdomains::Application.config.secret_token = '8d27e8e5598ed4b3e303b88713b206f96b3dc07958497d7bd6164616f343764fc6b26adc6c40fcf855ca3e32dd4c1bfb33e89e9ee12f5e404dbd593b1eaef639'
8 |
--------------------------------------------------------------------------------
/spec/controllers/users_controller_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe UsersController do
4 |
5 | before (:each) do
6 | @user = FactoryGirl.create(:user)
7 | sign_in @user
8 | end
9 |
10 | describe "GET 'show'" do
11 |
12 | it "should be successful" do
13 | get :show, :id => @user.id
14 | response.should be_success
15 | end
16 |
17 | it "should find the right user" do
18 | get :show, :id => @user.id
19 | assigns(:user).should == @user
20 | end
21 |
22 | end
23 |
24 | end
25 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/views/devise/registrations/new.html.erb:
--------------------------------------------------------------------------------
1 | Sign up
2 |
3 | <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
4 | <%= devise_error_messages! %>
5 | <%= f.label :name %>
6 | <%= f.text_field :name %>
7 |
8 | <%= f.label :email %>
9 | <%= f.email_field :email %>
10 |
11 | <%= f.label :password %>
12 | <%= f.password_field :password %>
13 |
14 | <%= f.label :password_confirmation %>
15 | <%= f.password_field :password_confirmation %>
16 |
17 | <%= f.submit "Sign up" %>
18 | <% end %>
19 |
20 | <%= render "devise/shared/links" %>
21 |
--------------------------------------------------------------------------------
/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: user1
13 | ADMIN_EMAIL: user@example.com
14 | ADMIN_PASSWORD: changeme
15 |
--------------------------------------------------------------------------------
/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: user1
13 | ADMIN_EMAIL: user@example.com
14 | ADMIN_PASSWORD: changeme
15 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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['...']) are 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 |
--------------------------------------------------------------------------------
/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
We're sorry, but something went wrong.
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The change you wanted was rejected.
23 |
Maybe you tried to change something you didn't have access to.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The page you were looking for doesn't exist.
23 |
You may have mistyped the address or the page may have moved.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Rails3 Subdomains
2 | ========================
3 |
4 | Rails example application shows how to use subdomains with Devise for authentication.
5 |
6 | ________________________
7 |
8 | See the README file on GitHub
9 |
10 | For more information, please see the updated README file on GitHub:
11 |
12 | https://github.com/RailsApps/rails3-subdomains
13 |
14 | ________________________
15 |
16 | Public Domain Dedication
17 |
18 | This work is a compilation and derivation from other previously released works. With the exception of various included works, which may be restricted by other licenses, the author or authors of this code dedicate any and all copyright interest in this code to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this code under copyright law.
19 |
--------------------------------------------------------------------------------
/app/views/layouts/_navigation.html.erb:
--------------------------------------------------------------------------------
1 | <%= link_to "Rails3 Subdomains", root_path, :class => 'brand' %>
2 |
3 | -
4 | <%= link_to 'Main', root_url(:host => request.domain) %>
5 |
6 | <% if request.subdomain.present? && request.subdomain != "www" %>
7 | <% if user_signed_in? %>
8 | -
9 | <%= link_to 'Edit account', edit_user_registration_url %>
10 |
11 | -
12 | <%= link_to 'Logout', destroy_user_session_url, :method=>'delete' %>
13 |
14 | <% else %>
15 | -
16 | <%= link_to 'Login', new_user_session_url %>
17 |
18 | <% end %>
19 | <% else %>
20 | -
21 | <%= link_to 'Sign up', new_user_registration_url(:host => request.domain) %>
22 |
23 | <% if user_signed_in? %>
24 | -
25 | <%= link_to 'Logout', destroy_user_session_url, :method=>'delete' %>
26 |
27 | <% end %>
28 | <% end %>
29 |
30 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 | gem 'rails', '3.2.13'
3 | group :assets do
4 | gem 'sass-rails', '~> 3.2.3'
5 | gem 'coffee-rails', '~> 3.2.1'
6 | gem 'uglifier', '>= 1.0.3'
7 | end
8 | gem 'jquery-rails'
9 | gem "mongoid", ">= 3.1.2"
10 | gem "rspec-rails", ">= 2.12.2", :group => [:development, :test]
11 | gem "database_cleaner", ">= 1.0.0.RC1", :group => :test
12 | gem "mongoid-rspec", ">= 1.7.0", :group => :test
13 | gem "email_spec", ">= 1.4.0", :group => :test
14 | gem "cucumber-rails", ">= 1.3.1", :group => :test, :require => false
15 | gem "launchy", ">= 2.2.0", :group => :test
16 | gem "capybara", ">= 2.0.3", :group => :test
17 | gem "factory_girl_rails", ">= 4.2.0", :group => [:development, :test]
18 | gem "devise", ">= 2.2.3"
19 | gem "quiet_assets", ">= 1.0.2", :group => :development
20 | gem "figaro", ">= 0.6.3"
21 | gem "better_errors", ">= 0.7.2", :group => :development
22 | gem "binding_of_caller", ">= 0.7.1", :group => :development, :platforms => [:mri_19, :rbx]
--------------------------------------------------------------------------------
/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | <%= content_for?(:title) ? yield(:title) : "Rails3 Subdomains" %>
6 | ">
7 | <%= stylesheet_link_tag "application", :media => "all" %>
8 | <%= javascript_include_tag "application" %>
9 | <%= csrf_meta_tags %>
10 | <%= yield(:head) %>
11 |
12 |
13 |
14 |
15 | <%= render 'layouts/navigation' %>
16 | <%= render 'layouts/messages' %>
17 |
18 |
19 | <%= yield %>
20 |
21 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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/views/devise/registrations/edit.html.erb:
--------------------------------------------------------------------------------
1 | Edit <%= resource_name.to_s.humanize %>
2 |
3 | <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
4 | <%= devise_error_messages! %>
5 | <%= f.label :name %>
6 | <%= f.text_field :name %>
7 |
8 | <%= f.label :email %>
9 | <%= f.email_field :email %>
10 |
11 | <%= f.label :password %> (leave blank if you don't want to change it)
12 | <%= f.password_field :password, :autocomplete => "off" %>
13 |
14 | <%= f.label :password_confirmation %>
15 | <%= f.password_field :password_confirmation %>
16 |
17 | <%= f.label :current_password %> (we need your current password to confirm your changes)
18 | <%= f.password_field :current_password %>
19 |
20 | <%= f.submit "Update" %>
21 | <% end %>
22 |
23 | Cancel my account
24 |
25 | Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>.
26 |
27 | <%= link_to "Back", :back %>
28 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/views/devise/shared/_links.html.erb:
--------------------------------------------------------------------------------
1 | <%- if controller_name != 'sessions' %>
2 | <%= link_to "Sign in", new_session_path(resource_name) %>
3 | <% end -%>
4 |
5 | <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
6 | <%= link_to "Sign up", new_registration_path(resource_name) %>
7 | <% end -%>
8 |
9 | <%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
10 | <%= link_to "Forgot your password?", new_password_path(resource_name) %>
11 | <% end -%>
12 |
13 | <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
14 | <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
15 | <% end -%>
16 |
17 | <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
18 | <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
19 | <% end -%>
20 |
21 | <%- if devise_mapping.omniauthable? %>
22 | <%- resource_class.omniauth_providers.each do |provider| %>
23 | <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %>
24 | <% end -%>
25 | <% end -%>
26 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Rails3Subdomains::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/environments/development.rb:
--------------------------------------------------------------------------------
1 | Rails3Subdomains::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 | config.action_mailer.smtp_settings = {
25 | address: "smtp.gmail.com",
26 | port: 587,
27 | domain: "example.com",
28 | authentication: "plain",
29 | enable_starttls_auto: true,
30 | user_name: ENV["GMAIL_USERNAME"],
31 | password: ENV["GMAIL_PASSWORD"]
32 | }
33 |
34 |
35 |
36 | # Print deprecation notices to the Rails logger
37 | config.active_support.deprecation = :log
38 |
39 | # Only use best-standards-support built into browsers
40 | config.action_dispatch.best_standards_support = :builtin
41 |
42 |
43 | # Do not compress assets
44 | config.assets.compress = false
45 |
46 | # Expands the lines which load the assets
47 | config.assets.debug = true
48 | end
49 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | # This file is copied to spec/ when you run 'rails generate rspec:install'
2 | ENV["RAILS_ENV"] ||= 'test'
3 | require File.expand_path("../../config/environment", __FILE__)
4 | require 'rspec/rails'
5 | require 'email_spec'
6 | require 'rspec/autorun'
7 |
8 | # Requires supporting ruby files with custom matchers and macros, etc,
9 | # in spec/support/ and its subdirectories.
10 | Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
11 |
12 | RSpec.configure do |config|
13 | config.include(EmailSpec::Helpers)
14 | config.include(EmailSpec::Matchers)
15 | # ## Mock Framework
16 | #
17 | # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
18 | #
19 | # config.mock_with :mocha
20 | # config.mock_with :flexmock
21 | # config.mock_with :rr
22 |
23 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
24 | # config.fixture_path = "#{::Rails.root}/spec/fixtures"
25 |
26 | # If you're not using ActiveRecord, or you'd prefer not to run each of your
27 | # examples within a transaction, remove the following line or assign false
28 | # instead of true.
29 | # config.use_transactional_fixtures = true
30 |
31 | # If true, the base class of anonymous controllers will be inferred
32 | # automatically. This will be the default behavior in future versions of
33 | # rspec-rails.
34 | config.infer_base_class_for_anonymous_controllers = false
35 |
36 | # Run specs in random order to surface order dependencies. If you find an
37 | # order dependency and want to debug it, you can fix the order by providing
38 | # the seed, which is printed after each run.
39 | # --seed 1234
40 | config.order = "random"
41 |
42 | config.before(:suite) do
43 | DatabaseCleaner.strategy = :truncation
44 | end
45 | config.before(:each) do
46 | DatabaseCleaner.start
47 | end
48 | config.after(:each) do
49 | DatabaseCleaner.clean
50 | end
51 | end
52 |
--------------------------------------------------------------------------------
/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 | validates_format_of :name, with: /^[a-z0-9_]+$/, message: 'must be lowercase alphanumerics only'
50 | validates_length_of :name, maximum: 32, message: 'exceeds maximum of 32 characters'
51 | validates_exclusion_of :name, in: ['www', 'mail', 'ftp'], message: 'is not available'
52 |
53 | attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :created_at, :updated_at
54 | end
55 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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_subdomains_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_subdomains_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 |
--------------------------------------------------------------------------------
/spec/models/user_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe User do
4 |
5 | before(:each) do
6 | @attr = {
7 | :name => "exampleuser",
8 | :email => "user@example.com",
9 | :password => "changeme",
10 | :password_confirmation => "changeme"
11 | }
12 | end
13 |
14 | it "should create a new instance given a valid attribute" do
15 | User.create!(@attr)
16 | end
17 |
18 | it "should require an email address" do
19 | no_email_user = User.new(@attr.merge(:email => ""))
20 | no_email_user.should_not be_valid
21 | end
22 |
23 | it "should accept valid email addresses" do
24 | addresses = %w[user@foo.com THE_USER@foo.bar.org first.last@foo.jp]
25 | addresses.each do |address|
26 | valid_email_user = User.new(@attr.merge(:email => address))
27 | valid_email_user.should be_valid
28 | end
29 | end
30 |
31 | it "should reject invalid email addresses" do
32 | addresses = %w[user@foo,com user_at_foo.org example.user@foo.]
33 | addresses.each do |address|
34 | invalid_email_user = User.new(@attr.merge(:email => address))
35 | invalid_email_user.should_not be_valid
36 | end
37 | end
38 |
39 | it "should reject duplicate email addresses" do
40 | User.create!(@attr)
41 | user_with_duplicate_email = User.new(@attr)
42 | user_with_duplicate_email.should_not be_valid
43 | end
44 |
45 | it "should reject email addresses identical up to case" do
46 | upcased_email = @attr[:email].upcase
47 | User.create!(@attr.merge(:email => upcased_email))
48 | user_with_duplicate_email = User.new(@attr)
49 | user_with_duplicate_email.should_not be_valid
50 | end
51 |
52 | describe "passwords" do
53 |
54 | before(:each) do
55 | @user = User.new(@attr)
56 | end
57 |
58 | it "should have a password attribute" do
59 | @user.should respond_to(:password)
60 | end
61 |
62 | it "should have a password confirmation attribute" do
63 | @user.should respond_to(:password_confirmation)
64 | end
65 | end
66 |
67 | describe "password validations" do
68 |
69 | it "should require a password" do
70 | User.new(@attr.merge(:password => "", :password_confirmation => "")).
71 | should_not be_valid
72 | end
73 |
74 | it "should require a matching password confirmation" do
75 | User.new(@attr.merge(:password_confirmation => "invalid")).
76 | should_not be_valid
77 | end
78 |
79 | it "should reject short passwords" do
80 | short = "a" * 5
81 | hash = @attr.merge(:password => short, :password_confirmation => short)
82 | User.new(hash).should_not be_valid
83 | end
84 |
85 | end
86 |
87 | describe "password encryption" do
88 |
89 | before(:each) do
90 | @user = User.create!(@attr)
91 | end
92 |
93 | it "should have an encrypted password attribute" do
94 | @user.should respond_to(:encrypted_password)
95 | end
96 |
97 | it "should set the encrypted password attribute" do
98 | @user.encrypted_password.should_not be_blank
99 | end
100 |
101 | end
102 |
103 | end
104 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Rails3Subdomains::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.default_url_options = { :host => 'example.com' }
65 | # ActionMailer Config
66 | # Setup for production - deliveries, no errors raised
67 | config.action_mailer.delivery_method = :smtp
68 | config.action_mailer.perform_deliveries = true
69 | config.action_mailer.raise_delivery_errors = false
70 | config.action_mailer.default :charset => "utf-8"
71 |
72 | config.action_mailer.smtp_settings = {
73 | address: "smtp.gmail.com",
74 | port: 587,
75 | domain: "example.com",
76 | authentication: "plain",
77 | enable_starttls_auto: true,
78 | user_name: ENV["GMAIL_USERNAME"],
79 | password: ENV["GMAIL_PASSWORD"]
80 | }
81 |
82 |
83 |
84 | end
85 |
--------------------------------------------------------------------------------
/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 Rails3Subdomains
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/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 |
--------------------------------------------------------------------------------
/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.first conditions: {:email => @visitor[:email]}
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, email: @visitor[:email])
23 | end
24 |
25 | def delete_user
26 | @user ||= User.first conditions: {:email => @visitor[:email]}
27 | @user.destroy unless @user.nil?
28 | end
29 |
30 | def sign_up
31 | delete_user
32 | visit '/users/sign_up'
33 | fill_in "Name", :with => @visitor[:name]
34 | fill_in "Email", :with => @visitor[:email]
35 | fill_in "Password", :with => @visitor[:password]
36 | fill_in "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 "Email", :with => @visitor[:email]
44 | fill_in "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 "Name", :with => "newname"
127 | fill_in "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 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | actionmailer (3.2.13)
5 | actionpack (= 3.2.13)
6 | mail (~> 2.5.3)
7 | actionpack (3.2.13)
8 | activemodel (= 3.2.13)
9 | activesupport (= 3.2.13)
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.13)
18 | activesupport (= 3.2.13)
19 | builder (~> 3.0.0)
20 | activerecord (3.2.13)
21 | activemodel (= 3.2.13)
22 | activesupport (= 3.2.13)
23 | arel (~> 3.0.2)
24 | tzinfo (~> 0.3.29)
25 | activeresource (3.2.13)
26 | activemodel (= 3.2.13)
27 | activesupport (= 3.2.13)
28 | activesupport (3.2.13)
29 | i18n (= 0.6.1)
30 | multi_json (~> 1.0)
31 | addressable (2.3.3)
32 | arel (3.0.2)
33 | bcrypt-ruby (3.0.1)
34 | better_errors (0.8.0)
35 | coderay (>= 1.0.0)
36 | erubis (>= 2.6.6)
37 | binding_of_caller (0.7.1)
38 | debug_inspector (>= 0.0.1)
39 | builder (3.0.4)
40 | capybara (2.0.3)
41 | mime-types (>= 1.16)
42 | nokogiri (>= 1.3.3)
43 | rack (>= 1.0.0)
44 | rack-test (>= 0.5.4)
45 | selenium-webdriver (~> 2.0)
46 | xpath (~> 1.0.0)
47 | childprocess (0.3.9)
48 | ffi (~> 1.0, >= 1.0.11)
49 | coderay (1.0.9)
50 | coffee-rails (3.2.2)
51 | coffee-script (>= 2.2.0)
52 | railties (~> 3.2.0)
53 | coffee-script (2.2.0)
54 | coffee-script-source
55 | execjs
56 | coffee-script-source (1.6.2)
57 | cucumber (1.2.3)
58 | builder (>= 2.1.2)
59 | diff-lcs (>= 1.1.3)
60 | gherkin (~> 2.11.6)
61 | multi_json (~> 1.3)
62 | cucumber-rails (1.3.1)
63 | capybara (>= 1.1.2)
64 | cucumber (>= 1.2.0)
65 | nokogiri (>= 1.5.0)
66 | rails (~> 3.0)
67 | database_cleaner (1.0.0.RC1)
68 | debug_inspector (0.0.2)
69 | devise (2.2.3)
70 | bcrypt-ruby (~> 3.0)
71 | orm_adapter (~> 0.1)
72 | railties (~> 3.1)
73 | warden (~> 1.2.1)
74 | diff-lcs (1.2.2)
75 | email_spec (1.4.0)
76 | launchy (~> 2.1)
77 | mail (~> 2.2)
78 | erubis (2.7.0)
79 | execjs (1.4.0)
80 | multi_json (~> 1.0)
81 | factory_girl (4.2.0)
82 | activesupport (>= 3.0.0)
83 | factory_girl_rails (4.2.1)
84 | factory_girl (~> 4.2.0)
85 | railties (>= 3.0.0)
86 | ffi (1.6.0)
87 | figaro (0.6.3)
88 | bundler (~> 1.0)
89 | rails (>= 3, < 5)
90 | gherkin (2.11.6)
91 | json (>= 1.7.6)
92 | hike (1.2.1)
93 | i18n (0.6.1)
94 | journey (1.0.4)
95 | jquery-rails (2.2.1)
96 | railties (>= 3.0, < 5.0)
97 | thor (>= 0.14, < 2.0)
98 | json (1.7.7)
99 | launchy (2.2.0)
100 | addressable (~> 2.3)
101 | mail (2.5.3)
102 | i18n (>= 0.4.0)
103 | mime-types (~> 1.16)
104 | treetop (~> 1.4.8)
105 | mime-types (1.22)
106 | mongoid (3.1.2)
107 | activemodel (~> 3.2)
108 | moped (~> 1.4.2)
109 | origin (~> 1.0)
110 | tzinfo (~> 0.3.22)
111 | mongoid-rspec (1.7.0)
112 | mongoid (>= 3.0.1)
113 | rake
114 | rspec (>= 2.9)
115 | moped (1.4.5)
116 | multi_json (1.7.2)
117 | nokogiri (1.5.9)
118 | origin (1.0.11)
119 | orm_adapter (0.4.0)
120 | polyglot (0.3.3)
121 | quiet_assets (1.0.2)
122 | railties (>= 3.1, < 5.0)
123 | rack (1.4.5)
124 | rack-cache (1.2)
125 | rack (>= 0.4)
126 | rack-ssl (1.3.3)
127 | rack
128 | rack-test (0.6.2)
129 | rack (>= 1.0)
130 | rails (3.2.13)
131 | actionmailer (= 3.2.13)
132 | actionpack (= 3.2.13)
133 | activerecord (= 3.2.13)
134 | activeresource (= 3.2.13)
135 | activesupport (= 3.2.13)
136 | bundler (~> 1.0)
137 | railties (= 3.2.13)
138 | railties (3.2.13)
139 | actionpack (= 3.2.13)
140 | activesupport (= 3.2.13)
141 | rack-ssl (~> 1.3.2)
142 | rake (>= 0.8.7)
143 | rdoc (~> 3.4)
144 | thor (>= 0.14.6, < 2.0)
145 | rake (10.0.4)
146 | rdoc (3.12.2)
147 | json (~> 1.4)
148 | rspec (2.13.0)
149 | rspec-core (~> 2.13.0)
150 | rspec-expectations (~> 2.13.0)
151 | rspec-mocks (~> 2.13.0)
152 | rspec-core (2.13.1)
153 | rspec-expectations (2.13.0)
154 | diff-lcs (>= 1.1.3, < 2.0)
155 | rspec-mocks (2.13.0)
156 | rspec-rails (2.13.0)
157 | actionpack (>= 3.0)
158 | activesupport (>= 3.0)
159 | railties (>= 3.0)
160 | rspec-core (~> 2.13.0)
161 | rspec-expectations (~> 2.13.0)
162 | rspec-mocks (~> 2.13.0)
163 | rubyzip (0.9.9)
164 | sass (3.2.7)
165 | sass-rails (3.2.6)
166 | railties (~> 3.2.0)
167 | sass (>= 3.1.10)
168 | tilt (~> 1.3)
169 | selenium-webdriver (2.31.0)
170 | childprocess (>= 0.2.5)
171 | multi_json (~> 1.0)
172 | rubyzip
173 | websocket (~> 1.0.4)
174 | sprockets (2.2.2)
175 | hike (~> 1.2)
176 | multi_json (~> 1.0)
177 | rack (~> 1.0)
178 | tilt (~> 1.1, != 1.3.0)
179 | thor (0.18.1)
180 | tilt (1.3.6)
181 | treetop (1.4.12)
182 | polyglot
183 | polyglot (>= 0.3.1)
184 | tzinfo (0.3.37)
185 | uglifier (1.3.0)
186 | execjs (>= 0.3.0)
187 | multi_json (~> 1.0, >= 1.0.2)
188 | warden (1.2.1)
189 | rack (>= 1.0)
190 | websocket (1.0.7)
191 | xpath (1.0.0)
192 | nokogiri (~> 1.3)
193 |
194 | PLATFORMS
195 | ruby
196 |
197 | DEPENDENCIES
198 | better_errors (>= 0.7.2)
199 | binding_of_caller (>= 0.7.1)
200 | capybara (>= 2.0.3)
201 | coffee-rails (~> 3.2.1)
202 | cucumber-rails (>= 1.3.1)
203 | database_cleaner (>= 1.0.0.RC1)
204 | devise (>= 2.2.3)
205 | email_spec (>= 1.4.0)
206 | factory_girl_rails (>= 4.2.0)
207 | figaro (>= 0.6.3)
208 | jquery-rails
209 | launchy (>= 2.2.0)
210 | mongoid (>= 3.1.2)
211 | mongoid-rspec (>= 1.7.0)
212 | quiet_assets (>= 1.0.2)
213 | rails (= 3.2.13)
214 | rspec-rails (>= 2.12.2)
215 | sass-rails (~> 3.2.3)
216 | uglifier (>= 1.0.3)
217 |
--------------------------------------------------------------------------------
/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) follow "([^"]*?)" in the email$/ do |link|
179 | visit_in_email(link)
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 |
--------------------------------------------------------------------------------
/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 Basic 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.
55 | # config.http_authenticatable = false
56 |
57 | # If http headers should be returned for AJAX requests. True by default.
58 | # config.http_authenticatable_on_xhr = true
59 |
60 | # The realm used in Http Basic Authentication. "Application" by default.
61 | # config.http_authentication_realm = "Application"
62 |
63 | # It will change confirmation, password recovery and other workflows
64 | # to behave the same regardless if the e-mail provided was right or wrong.
65 | # Does not affect registerable.
66 | # config.paranoid = true
67 |
68 | # By default Devise will store the user in session. You can skip storage for
69 | # :http_auth and :token_auth by adding those symbols to the array below.
70 | # Notice that if you are skipping storage for all authentication paths, you
71 | # may want to disable generating routes to Devise's sessions controller by
72 | # passing :skip => :sessions to `devise_for` in your config/routes.rb
73 | config.skip_session_storage = [:http_auth]
74 |
75 | # ==> Configuration for :database_authenticatable
76 | # For bcrypt, this is the cost for hashing the password and defaults to 10. If
77 | # using other encryptors, it sets how many times you want the password re-encrypted.
78 | #
79 | # Limiting the stretches to just one in testing will increase the performance of
80 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
81 | # a value less than 10 in other environments.
82 | config.stretches = Rails.env.test? ? 1 : 10
83 |
84 | # Setup a pepper to generate the encrypted password.
85 | # config.pepper = "0f9d3ea0260178132c6936217e9072627258f6863ad42f60b48dd8f92308eb001826307e2a1782f7a692dd4b0fa54a0084cc45b9ce0a66fc704a01a3a3dc6461"
86 |
87 | # ==> Configuration for :confirmable
88 | # A period that the user is allowed to access the website even without
89 | # confirming his account. For instance, if set to 2.days, the user will be
90 | # able to access the website for two days without confirming his account,
91 | # access will be blocked just in the third day. Default is 0.days, meaning
92 | # the user cannot access the website without confirming his account.
93 | # config.allow_unconfirmed_access_for = 2.days
94 |
95 | # A period that the user is allowed to confirm their account before their
96 | # token becomes invalid. For example, if set to 3.days, the user can confirm
97 | # their account within 3 days after the mail was sent, but on the fourth day
98 | # their account can't be confirmed with the token any more.
99 | # Default is nil, meaning there is no restriction on how long a user can take
100 | # before confirming their account.
101 | # config.confirm_within = 3.days
102 |
103 | # If true, requires any email changes to be confirmed (exactly the same way as
104 | # initial account confirmation) to be applied. Requires additional unconfirmed_email
105 | # db field (see migrations). Until confirmed new email is stored in
106 | # unconfirmed email column, and copied to email column on successful confirmation.
107 | config.reconfirmable = true
108 |
109 | # Defines which key will be used when confirming an account
110 | # config.confirmation_keys = [ :email ]
111 |
112 | # ==> Configuration for :rememberable
113 | # The time the user will be remembered without asking for credentials again.
114 | # config.remember_for = 2.weeks
115 |
116 | # If true, extends the user's remember period when remembered via cookie.
117 | # config.extend_remember_period = false
118 |
119 | # Options to be passed to the created cookie. For instance, you can set
120 | # :secure => true in order to force SSL only cookies.
121 | # config.rememberable_options = {}
122 |
123 | # ==> Configuration for :validatable
124 | # Range for password length. Default is 8..128.
125 | config.password_length = 8..128
126 |
127 | # Email regex used to validate email formats. It simply asserts that
128 | # an one (and only one) @ exists in the given string. This is mainly
129 | # to give user feedback and not to assert the e-mail validity.
130 | # config.email_regexp = /\A[^@]+@[^@]+\z/
131 |
132 | # ==> Configuration for :timeoutable
133 | # The time you want to timeout the user session without activity. After this
134 | # time the user will be asked for credentials again. Default is 30 minutes.
135 | # config.timeout_in = 30.minutes
136 |
137 | # If true, expires auth token on session timeout.
138 | # config.expire_auth_token_on_timeout = false
139 |
140 | # ==> Configuration for :lockable
141 | # Defines which strategy will be used to lock an account.
142 | # :failed_attempts = Locks an account after a number of failed attempts to sign in.
143 | # :none = No lock strategy. You should handle locking by yourself.
144 | # config.lock_strategy = :failed_attempts
145 |
146 | # Defines which key will be used when locking and unlocking an account
147 | # config.unlock_keys = [ :email ]
148 |
149 | # Defines which strategy will be used to unlock an account.
150 | # :email = Sends an unlock link to the user email
151 | # :time = Re-enables login after a certain amount of time (see :unlock_in below)
152 | # :both = Enables both strategies
153 | # :none = No unlock strategy. You should handle unlocking by yourself.
154 | # config.unlock_strategy = :both
155 |
156 | # Number of authentication tries before locking an account if lock_strategy
157 | # is failed attempts.
158 | # config.maximum_attempts = 20
159 |
160 | # Time interval to unlock the account if :time is enabled as unlock_strategy.
161 | # config.unlock_in = 1.hour
162 |
163 | # ==> Configuration for :recoverable
164 | #
165 | # Defines which key will be used when recovering the password for an account
166 | # config.reset_password_keys = [ :email ]
167 |
168 | # Time interval you can reset your password with a reset password key.
169 | # Don't put a too small interval or your users won't have the time to
170 | # change their passwords.
171 | config.reset_password_within = 6.hours
172 |
173 | # ==> Configuration for :encryptable
174 | # Allow you to use another encryption algorithm besides bcrypt (default). You can use
175 | # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
176 | # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
177 | # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
178 | # REST_AUTH_SITE_KEY to pepper)
179 | # config.encryptor = :sha512
180 |
181 | # ==> Configuration for :token_authenticatable
182 | # Defines name of the authentication token params key
183 | # config.token_authentication_key = :auth_token
184 |
185 | # ==> Scopes configuration
186 | # Turn scoped views on. Before rendering "sessions/new", it will first check for
187 | # "users/sessions/new". It's turned off by default because it's slower if you
188 | # are using only default views.
189 | # config.scoped_views = false
190 |
191 | # Configure the default scope given to Warden. By default it's the first
192 | # devise role declared in your routes (usually :user).
193 | # config.default_scope = :user
194 |
195 | # Set this configuration to false if you want /users/sign_out to sign out
196 | # only the current scope. By default, Devise signs out all scopes.
197 | # config.sign_out_all_scopes = true
198 |
199 | # ==> Navigation configuration
200 | # Lists the formats that should be treated as navigational. Formats like
201 | # :html, should redirect to the sign in page when the user does not have
202 | # access, but formats like :xml or :json, should return 401.
203 | #
204 | # If you have any extra navigational formats, like :iphone or :mobile, you
205 | # should add them to the navigational formats lists.
206 | #
207 | # The "*/*" below is required to match Internet Explorer requests.
208 | # config.navigational_formats = ["*/*", :html]
209 |
210 | # The default HTTP method used to sign out a resource. Default is :delete.
211 | config.sign_out_via = Rails.env.test? ? :get : :delete
212 |
213 | # ==> OmniAuth
214 | # Add a new OmniAuth provider. Check the wiki for more information on setting
215 | # up on your models and hooks.
216 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
217 |
218 | # ==> Warden configuration
219 | # If you want to use other strategies, that are not supported by Devise, or
220 | # change the failure app, you can configure them inside the config.warden block.
221 | #
222 | # config.warden do |manager|
223 | # manager.intercept_401 = false
224 | # manager.default_strategies(:scope => :user).unshift :some_external_strategy
225 | # end
226 |
227 | # ==> Mountable engine configurations
228 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine
229 | # is mountable, there are some extra configurations to be taken into account.
230 | # The following options are available, assuming the engine is mounted as:
231 | #
232 | # mount MyEngine, at: "/my_engine"
233 | #
234 | # The router that invoked `devise_for`, in the example above, would be:
235 | # config.router_name = :my_engine
236 | #
237 | # When using omniauth, Devise cannot automatically set Omniauth path,
238 | # so you need to do it manually. For the users scope, it would be:
239 | # config.omniauth_path_prefix = "/my_engine/users/auth"
240 | end
241 |
--------------------------------------------------------------------------------
/README.textile:
--------------------------------------------------------------------------------
1 | h1. !http://railsapps.github.io/images/rails-36x36.jpg(Rails Application for Subdomains with Devise)! Rails App for Subdomains with Devise
2 |
3 | Rails 3.2 example application shows how to use subdomains with Devise for authentication.
4 |
5 | * "Devise":http://github.com/plataformatec/devise gives you ready-made authentication and user management.
6 | * MongoDB is used as a datastore with the "Mongoid":http://mongoid.org/ gem for quick development without schemas or migrations.
7 |
8 | Best of all, there's a "detailed tutorial":http://railsapps.github.io/tutorial-rails-subdomains.html to show how it's built.
9 |
10 | You can build this application in only a few minutes using the "Rails Composer":http://railsapps.github.io/rails-composer/ tool.
11 |
12 | h2. !http://twitter-badges.s3.amazonaws.com/t_logo-a.png(Follow on Twitter)!:http://www.twitter.com/rails_apps Follow on Twitter
13 |
14 | Follow the project on Twitter: "@rails_apps":http://twitter.com/rails_apps. Please tweet some praise if you like what you've found.
15 |
16 | h2. Tutorial
17 |
18 | A complete walkthrough tutorial is available on the GitHub wiki:
19 |
20 | h4. "View the Tutorial":http://railsapps.github.io/tutorial-rails-subdomains.html
21 |
22 | The tutorial documents each step to follow to create the application. Every step is documented concisely, so a complete beginner can create this application without any additional knowledge. However, no explanation is offered for any of the steps, so if you are a beginner, you’re advised to look for an introduction to Rails elsewhere. See a list of recommended resources for "Rails":http://railsapps.github.io/rails.html.
23 |
24 | h2. What Is Implemented -- and What Is Not
25 |
26 | The example app implements a common use of subdomains, often called "Basecamp-style subdomains in Rails." Visitors to the main site create a user account which is hosted at a subdomain that matches their user name. Each user has only one subdomain and when they log in, all their activity is confined to their subdomain.
27 |
28 | Another common use of subdomains can be called "blog-style subdomains." This approach is familiar to users of sites such as wordpress.com where each user can create multiple blogs and each is hosted on its own subdomain. For example, a user with the email address "user@example.com@" can own more than one blog, for example, "puppyphotos.wordpress.com" and "kittenphotos.wordpress.com". The "blog-style subdomains" approach is not implemented in this example application.
29 |
30 | h4. RailsApps Examples and Tutorials
31 |
32 | 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.
33 |
34 | h2. Dependencies
35 |
36 | Before running this app, you will need:
37 |
38 | * The Ruby language (version 1.9.3 or 2.0.0)
39 | * The Rails gem (version 3.2.13)
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). On Mac OS X, the easiest way to install MongoDB is to install "Homebrew":http://mxcl.github.com/homebrew/ and then run the following:
47 |
48 |
49 | brew install mongodb
50 |
51 |
52 | 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*.
53 |
54 | h2. Getting the Application
55 |
56 | You have several options for getting the code.
57 |
58 | h3. Fork
59 |
60 | 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!
61 |
62 | h3. Clone
63 |
64 | 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:
65 |
66 |
67 | $ git clone git://github.com/RailsApps/rails3-subdomains.git
68 |
69 |
70 | You'll need "git":http://git-scm.com/ on your machine. See "Rails and Git":http://railsapps.github.io/rails-git.html.
71 |
72 | h3. Generate
73 |
74 | 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.
75 |
76 | To build the example application, run the command:
77 |
78 |
79 | $ rails new rails3-subdomains -m https://raw.github.com/RailsApps/rails-composer/master/composer-Rails3_2.rb -T -O
80 |
81 |
82 | Use the @-T -O@ flags to skip Test::Unit files and Active Record files.
83 |
84 | The @$@ character indicates a shell prompt; don't include it when you run the command.
85 |
86 | This creates a new Rails app named @rails3-subdomains@ on your computer.
87 |
88 | You'll see a prompt:
89 |
90 |
91 | question Install an example application?
92 | 1) I want to build my own application
93 | 2) membership/subscription/saas
94 | 3) rails-prelaunch-signup
95 | 4) rails3-bootstrap-devise-cancan
96 | 5) rails3-devise-rspec-cucumber
97 | 6) rails3-mongoid-devise
98 | 7) rails3-mongoid-omniauth
99 | 8) rails3-subdomains
100 |
101 |
102 | Choose *rails3-subdomains*. The Rails Composer tool may give you other options (other choices may have been added since these notes were written).
103 |
104 | The application generator template will ask you for additional preferences:
105 |
106 |
107 | question Web server for development?
108 | 1) WEBrick (default)
109 | 2) Thin
110 | 3) Unicorn
111 | 4) Puma
112 | question Web server for production?
113 | 1) Same as development
114 | 2) Thin
115 | 3) Unicorn
116 | 4) Puma
117 | question Template engine?
118 | 1) ERB
119 | 2) Haml
120 | 3) Slim
121 | extras Set a robots.txt file to ban spiders? (y/n)
122 | extras Use or create a project-specific rvm gemset? (y/n)
123 | extras Create a GitHub repository? (y/n)
124 |
125 |
126 | h4. Web Servers
127 |
128 | Use the default WEBrick server for convenience. If you plan to deploy to Heroku, select "thin" as your production webserver.
129 |
130 | h4. Template Engine
131 |
132 | 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.
133 |
134 | h4. Other Choices
135 |
136 | Set a robots.txt file to ban spiders if you want to keep your new site out of Google search results.
137 |
138 | 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.
139 |
140 | If you choose to create a GitHub repository, the generator will prompt you for a GitHub username and password.
141 |
142 | h4. Troubleshooting
143 |
144 | 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.
145 |
146 | If you get an error like this:
147 |
148 |
149 | Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
150 | composer Running 'after bundler' callbacks.
151 | The template [...] could not be loaded.
152 | Error: You have already activated ..., but your Gemfile requires ....
153 | Using bundle exec may solve this.
154 |
155 |
156 | 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.
157 |
158 | Other problems? Check the "issues":https://github.com/RailsApps/rails3-subdomains/issues.
159 |
160 | h3. Edit the README
161 |
162 | 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.
163 |
164 | h2. Getting Started
165 |
166 | h3. Install the Required Gems
167 |
168 | Check the Gemfile to see which gems are used by this application.
169 |
170 | 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.
171 |
172 | If not, you should run the @bundle install@ command to install the required gems on your computer:
173 |
174 |
175 | $ bundle install
176 |
177 |
178 | You can check which gems are installed on your computer with:
179 |
180 |
181 | $ gem list
182 |
183 |
184 | 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.
185 |
186 | 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.
187 |
188 | h3. Configure Mongoid
189 |
190 | Mongoid provides access to the MongoDB database from Rails.
191 |
192 | You can use the default configuration found in the file *config/mongoid.yml*.
193 |
194 | 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).
195 |
196 | h3. Configure Email
197 |
198 | 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.
199 |
200 | h3. Configure Devise
201 |
202 | You can modify the configuration file for Devise if you want to use something other than the defaults:
203 |
204 | * *config/initializers/devise.rb*
205 |
206 | h3. Configuration File
207 |
208 | 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.
209 |
210 | Modify the file *config/application.yml*:
211 |
212 |
213 | # Add account credentials and API keys here.
214 | # See http://railsapps.github.io/rails-environment-variables.html
215 | # This file should be listed in .gitignore to keep your settings secret!
216 | # Each entry sets a local environment variable and overrides ENV variables in the Unix shell.
217 | # For example, setting:
218 | # GMAIL_USERNAME: Your_Gmail_Username
219 | # makes 'Your_Gmail_Username' available as ENV["GMAIL_USERNAME"]
220 | # Add application configuration variables here, as shown below.
221 | #
222 | GMAIL_USERNAME: Your_Username
223 | GMAIL_PASSWORD: Your_Password
224 | ADMIN_NAME: user1
225 | ADMIN_EMAIL: user@example.com
226 | ADMIN_PASSWORD: changeme
227 |
228 |
229 | 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.
230 |
231 | 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.
232 |
233 | 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".
234 |
235 | If you prefer, you can delete the *config/application.yml* file and set each value as an environment variable in the Unix shell.
236 |
237 | h3. Set Up a Database Seed File
238 |
239 | 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.
240 |
241 |
242 | puts 'DEFAULT USERS'
243 | user = User.create! :name => ENV['ADMIN_NAME'].dup, :email => ENV['ADMIN_EMAIL'].dup, :password => ENV['ADMIN_PASSWORD'].dup, :password_confirmation => ENV['ADMIN_PASSWORD'].dup
244 | puts 'user: ' << user.name
245 |
246 |
247 | 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.
248 |
249 | 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.
250 |
251 | You may wish to include additional sample users:
252 |
253 |
254 | user2 = User.create! :name => 'user2', :email => 'user2@example.com', :password => 'changeme', :password_confirmation => 'changeme'
255 | puts 'user: ' << user2.name
256 |
257 |
258 | This will add a second user to the database.
259 |
260 | h3. Set the Database
261 |
262 | Prepare the database and add the default user to the database by running the commands:
263 |
264 |
265 | $ rake db:seed
266 |
267 |
268 | 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.
269 |
270 | Set the database for running tests:
271 |
272 |
273 | $ rake db:test:prepare
274 |
275 |
276 | 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.
277 |
278 | h3. Change your Application's Secret Token
279 |
280 | 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.
281 |
282 | 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.
283 |
284 | Get a unique secret token:
285 |
286 |
287 | rake secret
288 |
289 |
290 | Edit your *config/initializers/secret_token.rb* file to add the secret token:
291 |
292 |
293 | Rails3Subdomains::Application.config.secret_token = '...some really long, random string...'
294 |
295 |
296 |
297 | h2. Test the Application With Subdomains
298 |
299 | If you launch the application, it will be running at "http://localhost:3000/":http://localhost:3000/ or "http://0.0.0.0:3000/":http://0.0.0.0:3000/. However, unless you've made some configuration changes to your computer, you won't be able to resolve an address that uses a subdomain, such as "http://foo.localhost:3000/":http://foo.localhost:3000/. There are several complex solutions to this problem. You could set up your own domain name server on your localhost and create an A entry to catch all subdomains. You could modify your */etc/hosts* file (but it won't accommodate dynamically created subdomains). You can create a "proxy auto-config (PAC)":http://en.wikipedia.org/wiki/Proxy_auto-config file and set it up as the proxy in your web browser preferences.There's a far simpler solution that does not require reconfiguring your computer or web browser preferences. The developer Levi Cook registered a domain, "lvh.me":http://lvh.me:3000/ (short for: local virtual host me), that resolves to the localhost IP address 127.0.0.1 and supports wildcards (accommodating dynamically created subdomains).
300 |
301 | To test the application, visit "http://lvh.me:3000/":http://lvh.me:3000/. You should see a list of registered users with links to their profile pages.
302 |
303 | Try "http://user1.lvh.me:3000/":http://user1.lvh.me:3000/. You should see the profile page for the default user "user1."
304 |
305 | Try "http://foo.lvh.me:3000/":http://foo.lvh.me:3000/. You should see the "user not found" error message.
306 |
307 | Try "http://www.lvh.me:3000/":http://www.lvh.me:3000/. You should be redirected to the application home page at "http://lvh.me:3000/":http://lvh.me:3000/.
308 |
309 | To sign in as the default user, (unless you've changed it) use
310 |
311 | * email: user@example.com
312 | * password: changeme
313 |
314 | You should delete or change the pre-configured logins before you deploy your application.
315 |
316 | h2. Deploy to Heroku
317 |
318 | 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.
319 |
320 | h2. Customizing
321 |
322 | "Devise":http://github.com/plataformatec/devise provides a variety of features for implementing authentication. See the Devise documentation for options.
323 |
324 | This example application and tutorial demonstrates Devise and Mongoid working together on Rails 3. Add any models, controllers, and views that you need.
325 |
326 | h2. Testing
327 |
328 | The application is set up for RSpec unit tests and Cucumber scenarios and steps. No tests and scenarios are implemented for this version of the example application. Please send the author a message, create an issue, or submit a pull request if you can contribute RSpec or Cucumber tests and scenarios.
329 |
330 | After installing the application, run @rake -T@ to check that rake tasks for RSpec and Cucumber are available.
331 |
332 | Run @rake spec@ to run RSpec tests.
333 |
334 | Run @rake cucumber@ (or more simply, @cucumber@) to run Cucumber scenarios and steps.
335 |
336 | h2. Troubleshooting
337 |
338 | Problems? Check the "issues":https://github.com/RailsApps/rails3-subdomains/issues.
339 |
340 | h4. Problems with "Certificate Verify Failed"
341 |
342 | 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.
343 |
344 | h2. Documentation and Support
345 |
346 | The "tutorial":http://railsapps.github.io/tutorial-rails-subdomains.html provides additional documentation.
347 |
348 | 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.
349 |
350 | 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.
351 |
352 | h4. Issues
353 |
354 | Please create an "issue on GitHub":http://github.com/RailsApps/rails3-subdomains/issues if you identify any problems or have suggestions for improvements.
355 |
356 | h4. Where to Get Help
357 |
358 | 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.
359 |
360 | You can also try "Rails Hotline":http://www.railshotline.com/, a free telephone hotline for Rails help staffed by volunteers.
361 |
362 | h2. Contributing
363 |
364 | If you make improvements to this application, please share with others.
365 |
366 | Send the author a message, create an "issue":http://github.com/RailsApps/rails3-subdomains/issues, or fork the project and submit a pull request.
367 |
368 | 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.
369 |
370 | h2. Credits
371 |
372 | Thank you to "Brian Cardarella":http://bcardarella.com/ for a helpful blog post on "Custom Subdomains in Rails 3":http://bcardarella.com/post/716951242/custom-subdomains-in-rails-3.
373 |
374 | Daniel Kehoe implemented the application and wrote the tutorial.
375 |
376 | Is the app useful to you? Follow the project on Twitter: "@rails_apps":http://twitter.com/rails_apps
377 | and tweet some praise. I'd love to know you were helped out by what I've put together.
378 |
379 | h2. MIT License
380 |
381 | "MIT License":http://www.opensource.org/licenses/mit-license
382 |
383 | Copyright © 2012 Daniel Kehoe
384 |
385 | h2. Useful Links
386 |
387 | |_. Getting Started |_. Articles |_. Tutorials |
388 | | "Learn Rails":http://learn-rails.com/ | "Twitter Bootstrap and Rails":http://railsapps.github.io/twitter-bootstrap-rails.html | "Rails and Bootstrap":http://railsapps.github.io/rails-bootstrap/ |
389 | | "Ruby and Rails":http://railsapps.github.io/ruby-and-rails.html | "Analytics for Rails":http://railsapps.github.io/rails-google-analytics.html | |
390 | | "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 | "Devise with CanCan and Twitter Bootstrap":https://tutorials.railsapps.org/rails3-bootstrap-devise-cancan |
391 | | "Rails Tutorial":https://tutorials.railsapps.org/rails-tutorial | "JavaScript and Rails":http://railsapps.github.io/rails-javascript-include-external.html | "Rails Membership Site with Stripe":https://tutorials.railsapps.org/rails-stripe-membership-saas |
392 | | "Installing Rails":http://railsapps.github.io/installing-rails.html | "Rails Environment Variables":http://railsapps.github.io/rails-environment-variables.html | "Rails Subscription Site with Recurly":https://tutorials.railsapps.org/rails-recurly-subscription-saas |
393 | | "Updating Rails":http://railsapps.github.io/updating-rails.html | "Git and Rails":http://railsapps.github.io/rails-git.html | "Startup Prelaunch Signup Application":http://railsapps.github.io/tutorial-rails-prelaunch-signup.html |
394 | | "Rails Composer":http://railsapps.github.io/rails-composer/ | "Email and Rails":http://railsapps.github.io/rails-send-email.html | "Devise with RSpec and Cucumber":http://railsapps.github.io/tutorial-rails-devise-rspec-cucumber.html |
395 | | "Rails Examples":http://railsapps.github.io/ | "Haml and Rails":http://railsapps.github.io/rails-haml.html | "Devise with Mongoid":http://railsapps.github.io/tutorial-rails-mongoid-devise.html |
396 | | "Rails Starter Apps":http://railsapps.github.io/rails-examples-tutorials.html | "Rails Application Layout":http://railsapps.github.io/rails-default-application-layout.html | "OmniAuth with Mongoid":http://railsapps.github.io/tutorial-rails-mongoid-omniauth.html |
397 | | | "HTML5 Boilerplate for Rails":http://railsapps.github.io/rails-html5-boilerplate.html | "Subdomains with Devise":http://railsapps.github.io/tutorial-rails-subdomains.html |
398 | | | "Example Gemfiles for Rails":http://railsapps.github.io/rails-3-2-example-gemfile.html | |
399 | | | "Rails Application Templates":http://railsapps.github.io/rails-application-templates.html | |
400 |
401 | !https://cruel-carlota.pagodabox.com/8f9093c277a7a135ad14ae2fb3df4d97(githalytics.com alpha)!
402 |
--------------------------------------------------------------------------------