raygun 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/CHANGES.md +11 -0
  2. data/README.md +14 -9
  3. data/app_prototype/.rbenv-version +1 -0
  4. data/app_prototype/Gemfile +6 -0
  5. data/app_prototype/Guardfile +10 -2
  6. data/app_prototype/README.md +1 -1
  7. data/app_prototype/app/controllers/password_resets_controller.rb +6 -8
  8. data/app_prototype/app/controllers/registrations_controller.rb +1 -1
  9. data/app_prototype/app/mailers/user_mailer.rb +0 -3
  10. data/app_prototype/app/models/user.rb +5 -2
  11. data/app_prototype/app/views/layouts/application.html.slim +1 -1
  12. data/app_prototype/app/views/password_resets/edit.html.slim +2 -3
  13. data/app_prototype/app/views/password_resets/new.html.slim +2 -2
  14. data/app_prototype/app/views/registrations/new.html.slim +1 -2
  15. data/app_prototype/app/views/user_mailer/activation_needed_email.html.erb +2 -2
  16. data/app_prototype/app/views/user_mailer/activation_needed_email.text.erb +2 -2
  17. data/app_prototype/app/views/user_mailer/activation_success_email.html.erb +2 -2
  18. data/app_prototype/app/views/user_mailer/activation_success_email.text.erb +2 -2
  19. data/app_prototype/app/views/user_mailer/reset_password_email.html.erb +2 -2
  20. data/app_prototype/app/views/user_mailer/reset_password_email.text.erb +2 -2
  21. data/app_prototype/app/views/user_sessions/new.html.slim +2 -2
  22. data/app_prototype/app/views/users/show.html.slim +1 -1
  23. data/app_prototype/config/application.rb +2 -2
  24. data/app_prototype/config/environments/acceptance.rb +1 -1
  25. data/app_prototype/config/environments/development.rb +1 -1
  26. data/app_prototype/config/environments/production.rb +1 -1
  27. data/app_prototype/config/environments/test.rb +2 -0
  28. data/app_prototype/config/initializers/email.rb +11 -0
  29. data/app_prototype/config/initializers/secret_token.rb +1 -1
  30. data/app_prototype/config/routes.rb +10 -10
  31. data/app_prototype/config.ru +12 -2
  32. data/app_prototype/db/sample_data.rb +4 -4
  33. data/app_prototype/lib/templates/rspec/scaffold/controller_spec.rb +21 -21
  34. data/app_prototype/public/index.html +3 -3
  35. data/app_prototype/spec/controllers/user_sessions_controller_spec.rb +7 -7
  36. data/app_prototype/spec/controllers/users_controller_spec.rb +22 -22
  37. data/app_prototype/spec/factories/users.rb +2 -0
  38. data/app_prototype/spec/features/activation_spec.rb +18 -0
  39. data/app_prototype/spec/features/password_reset_spec.rb +41 -0
  40. data/app_prototype/spec/features/registration_spec.rb +39 -0
  41. data/app_prototype/spec/features/sign_in_spec.rb +30 -0
  42. data/app_prototype/spec/mailers/user_mailer_spec.rb +16 -16
  43. data/app_prototype/spec/models/user_spec.rb +13 -6
  44. data/app_prototype/spec/spec_helper.rb +8 -12
  45. data/app_prototype/spec/support/user_sessions_feature_helper.rb +2 -2
  46. data/app_prototype/spec/views/users/edit.html.slim_spec.rb +0 -1
  47. data/app_prototype/spec/views/users/index.html.slim_spec.rb +0 -1
  48. data/app_prototype/spec/views/users/new.html.slim_spec.rb +0 -1
  49. data/app_prototype/spec/views/users/show.html.slim_spec.rb +2 -3
  50. data/bin/raygun +8 -1
  51. data/cleanup.sh +8 -0
  52. data/lib/raygun/version.rb +1 -1
  53. data/raygun.gemspec +1 -3
  54. metadata +13 -21
  55. data/app_prototype/spec/features/user_sessions_spec.rb +0 -32
  56. data/app_prototype/spec/helpers/users_helper_spec.rb +0 -15
data/CHANGES.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+
3
+ ## 0.0.14 [2012-12-??]
4
+
5
+ * Basic usage information.
6
+ * Added guard-livereload to Guardfile.
7
+ * Better specs for auth flows (register, password reset, sign in) (~98% coverage).
8
+ * Use the new rspec expect(...).to syntax ([more info](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax)).
9
+ * Hardcode 1.9.3-p327 so that app_prototype is executable without futzing.
10
+ * Consistent hostnames across environments.
11
+ * Use mailcatcher when it's running locally ([more info](http://www.mikeperham.com/2012/12/09/12-gems-of-christmas-4-mailcatcher-and-mail_view/)).
data/README.md CHANGED
@@ -2,12 +2,8 @@
2
2
 
3
3
  # Raygun
4
4
 
5
- __NOTE: Currently a work in progress and not yet representative of best practices. Soon the veil will be lifted.__
6
-
7
- Command line Rails application generator that builds a new project skeleton configured with all of the Carbon Five
8
- best practices baked right in.
9
-
10
- Inspired by and code shamelessly lifted from ThoughtBot's Suspenders. Thanks!
5
+ Rails application generator that builds a new project skeleton configured with Carbon Five preferences and
6
+ best practices baked right in. Spend less time configuring stuff and more building cool stuff.
11
7
 
12
8
  Major tools/libraries:
13
9
 
@@ -21,10 +17,12 @@ Major tools/libraries:
21
17
  * RSpec
22
18
  * Factory Girl
23
19
  * Jasmine
24
- * Guard
20
+ * Guard (rspec, jasmine, livereload)
25
21
 
26
22
  And many tweaks, patterns and common recipes.
27
23
 
24
+ Inspired by Xavier Shay and ThoughtBot's Suspenders. Thanks!
25
+
28
26
  ## Projects Goals
29
27
 
30
28
  Raygun...
@@ -41,10 +39,12 @@ Raygun...
41
39
 
42
40
  Be sure you met these requirements before using raygun, otherwise you won't make it very far (misfire!).
43
41
 
44
- * Ruby 1.9.2+ (rvm and rbenv supported)
42
+ * Ruby 1.9.3-p327 (rvm and rbenv supported)
45
43
  * PostgreSQL 9.x with superuser 'postgres' with no password (```createuser -s postgres```)
46
44
  * PhantomJS for JavaScript testing (```brew install phantomjs```)
47
45
 
46
+ If you're using another ruby, just change the Gemfile, .rvmrc and/or .rbenv as necessary before running bundle.
47
+
48
48
  ## Usage
49
49
 
50
50
  $ raygun your-project
@@ -52,6 +52,7 @@ Be sure you met these requirements before using raygun, otherwise you won't make
52
52
  Once your project is baked out, you can easily kick the wheels:
53
53
 
54
54
  $ cd your-project
55
+ $ gem install bundler
55
56
  $ bundle update
56
57
 
57
58
  # Prepare the database: schema and reference / sample data
@@ -74,6 +75,10 @@ Once your project is baked out, you can easily kick the wheels:
74
75
 
75
76
  ### Development
76
77
 
77
- Generate an example app using your local development version of raygun
78
+ Generate an example app using your local development version of raygun:
78
79
 
79
80
  ./bin/raygun tmp/example_app
81
+
82
+ ## Changes
83
+
84
+ [View the Change Log](https://github.com/carbonfive/raygun/tree/master/CHANGES.md)
@@ -0,0 +1 @@
1
+ 1.9.3-p327
@@ -1,5 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ # Heroku uses the ruby version to configure your application's runtime.
4
+ ruby '1.9.3'
5
+
3
6
  gem 'thin'
4
7
  gem 'rails', '~> 3.2.9'
5
8
  gem 'slim-rails'
@@ -23,6 +26,7 @@ end
23
26
  group :test, :development do
24
27
  gem 'rspec-rails', '~> 2.12.0'
25
28
  gem 'capybara', github: 'jnicklas/capybara' # Switch from github once issue #882 is resolved.
29
+ gem 'capybara-email'
26
30
  gem 'factory_girl_rails'
27
31
  gem 'jasminerice'
28
32
  gem 'timecop'
@@ -31,6 +35,8 @@ end
31
35
 
32
36
  group :development do
33
37
  gem 'foreman'
38
+ gem 'launchy'
39
+ gem 'mailcatcher'
34
40
  gem 'guard'
35
41
  gem 'guard-rspec'
36
42
  gem 'guard-jasmine'
@@ -1,7 +1,15 @@
1
- # A sample Guardfile
2
1
  # More info at https://github.com/guard/guard#readme
3
2
 
4
- guard 'rspec' do
3
+ guard :livereload do
4
+ watch(%r{app/views/.+\.slim$})
5
+ watch(%r{app/helpers/.+\.rb})
6
+ watch(%r{public/.+\.(css|js|html)})
7
+ watch(%r{config/locales/.+\.yml})
8
+ # Rails Assets Pipeline
9
+ watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html))).*}) { |m| "/assets/#{m[3]}" }
10
+ end
11
+
12
+ guard :rspec do
5
13
  watch(%r{^spec/.+_spec\.rb$})
6
14
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
15
  watch('spec/spec_helper.rb') { "spec" }
@@ -6,7 +6,7 @@ Overview
6
6
  Requirements
7
7
  ============
8
8
 
9
- * ruby 1.9.?
9
+ * ruby 1.9.3-p327
10
10
  * postgresql 9.? (user 'postgres' with no password)
11
11
 
12
12
  Running the Specs
@@ -1,32 +1,30 @@
1
1
  class PasswordResetsController < ApplicationController
2
2
 
3
3
  skip_before_filter :require_login
4
+ skip_authorization_check
4
5
 
5
6
  def create
6
7
  @user = User.find_by_email(params[:email])
7
-
8
+
8
9
  # Send an email to the user with instructions on how to reset their password.
9
10
  @user.deliver_reset_password_instructions! if @user
10
-
11
+
11
12
  # Tell the user instructions have been sent whether or not email was found.
12
13
  # This is to not leak information to attackers about which emails exist in the system.
13
14
  redirect_to sign_in_path, notice: "Password reset instructions have been sent to your email."
14
15
  end
15
16
 
16
17
  def edit
17
- @user = User.load_from_reset_password_token(params[:id])
18
- @token = params[:id]
18
+ @token = params[:token]
19
+ @user = User.load_from_reset_password_token(@token)
19
20
  not_authenticated if !@user
20
21
  end
21
-
22
+
22
23
  def update
23
24
  @token = params[:token] # needed to render the form again in case of error
24
25
  @user = User.load_from_reset_password_token(@token)
25
26
  not_authenticated if !@user
26
27
 
27
- # Makes the password confirmation validation work.
28
- @user.password_confirmation = params[:user][:password_confirmation]
29
-
30
28
  # Clear the temporary token and update the password.
31
29
  if @user.change_password!(params[:user][:password])
32
30
  redirect_to sign_in_path, notice: "Password was successfully updated."
@@ -7,7 +7,7 @@ class RegistrationsController < ApplicationController
7
7
  end
8
8
 
9
9
  def create
10
- @user = User.new(params[:user])
10
+ @user = User.new(params[:user]) # TODO Safe attributes
11
11
 
12
12
  if @user.save
13
13
  redirect_to sign_in_path, notice: "Thanks for signing up. Please check your email for activation instructions."
@@ -4,19 +4,16 @@ class UserMailer < ActionMailer::Base
4
4
 
5
5
  def activation_needed_email(user)
6
6
  @user = user
7
- @url = "http://0.0.0.0:3000/sign_up/#{user.activation_token}/activate"
8
7
  mail to: user.email, subject: "Welcome to My Awesome Site!"
9
8
  end
10
9
 
11
10
  def activation_success_email(user)
12
11
  @user = user
13
- @url = "http://0.0.0.0:3000/sign_in"
14
12
  mail to: user.email, subject: "Your account has been activated!"
15
13
  end
16
14
 
17
15
  def reset_password_email(user)
18
16
  @user = user
19
- @url = "http://0.0.0.0:3000/password_resets/#{user.reset_password_token}/edit"
20
17
  mail to: user.email, subject: "Password reset requested"
21
18
  end
22
19
  end
@@ -4,14 +4,17 @@ class User < ActiveRecord::Base
4
4
 
5
5
  authenticates_with_sorcery!
6
6
 
7
+ validates :name,
8
+ length: { maximum: 30 }
9
+
7
10
  validates :email,
8
11
  presence: true,
9
- email: true
12
+ email: true,
13
+ uniqueness: true
10
14
 
11
15
  validates :password,
12
16
  presence: true,
13
17
  length: { minimum: 6 },
14
- confirmation: true,
15
18
  if: :password
16
19
 
17
20
  end
@@ -22,7 +22,7 @@ html
22
22
  ul.dropdown-menu
23
23
  li= link_to 'Sign Out', sign_out_path
24
24
  - else
25
- li= link_to 'Sign in', sign_in_path
25
+ li= link_to 'Sign In', sign_in_path
26
26
 
27
27
  - flash.each do |name, msg|
28
28
  = content_tag :div, raw(msg), class: "alert #{alert_class(name)}"
@@ -1,13 +1,12 @@
1
1
  .page-header
2
2
  h1 Reset Your Password
3
3
 
4
- = simple_form_for(@user, url: password_reset_path(@user)) do |f|
4
+ = simple_form_for(@user, url: reset_password_path(@user)) do |f|
5
5
  = f.error_notification
6
6
 
7
7
  .form-inputs
8
8
  = f.input :email, disabled: true
9
- = f.input :password, required: true, autofocus: true
10
- = f.input :password_confirmation, required: true
9
+ = f.input :password, label: 'New Password', required: true, autofocus: true
11
10
  = hidden_field_tag :token, @token
12
11
 
13
12
  .form-actions
@@ -1,11 +1,11 @@
1
1
  .page-header
2
2
  h1 Password Reset
3
3
 
4
- = form_tag(password_resets_path, method: :post) do
4
+ = form_tag(forgotten_password_path, method: :post) do
5
5
  .control-group
6
6
  = label_tag :email, nil, class: 'control-label'
7
7
  .controls
8
8
  = text_field_tag :email, nil, placeholder: 'joe@example.com'
9
9
 
10
10
  .form-actions
11
- = submit_tag "Reset my password!", class: 'btn btn-primary'
11
+ = submit_tag 'Reset My Password', class: 'btn btn-primary'
@@ -8,7 +8,6 @@
8
8
  = f.input :name, autofocus: true
9
9
  = f.input :email
10
10
  = f.input :password
11
- = f.input :password_confirmation
12
11
 
13
12
  .form-actions
14
- = f.button :submit, 'Sign up', class: 'btn btn-primary'
13
+ = f.button :submit, 'Sign Up', class: 'btn btn-primary'
@@ -10,8 +10,8 @@
10
10
  your username is: <%= @user.email %>.<br/>
11
11
  </p>
12
12
  <p>
13
- To login to the site, just follow this link: <%= @url %>.
13
+ To login to the site, just follow this link: <%= link_to activation_url(@user.activation_token), activation_url(@user.activation_token) %>.
14
14
  </p>
15
15
  <p>Thanks for joining and have a great day!</p>
16
16
  </body>
17
- </html>
17
+ </html>
@@ -4,6 +4,6 @@ Welcome to example.com, <%= @user.email %>
4
4
  You have successfully signed up to example.com,
5
5
  your username is: <%= @user.email %>.
6
6
 
7
- To login to the site, just follow this link: <%= @url %>.
7
+ To login to the site, just follow this link: <%= activation_url(@user.activation_token) %>
8
8
 
9
- Thanks for joining and have a great day!
9
+ Thanks for joining and have a great day!
@@ -10,8 +10,8 @@
10
10
  your username is: <%= @user.email %>.<br/>
11
11
  </p>
12
12
  <p>
13
- To login to the site, just follow this link: <%= @url %>.
13
+ To login to the site, just follow this link: <%= link_to sign_in_url, sign_in_url %>.
14
14
  </p>
15
15
  <p>Thanks for joining and have a great day!</p>
16
16
  </body>
17
- </html>
17
+ </html>
@@ -4,6 +4,6 @@ Congratz, <%= @user.email %>
4
4
  You have successfully activated your example.com account,
5
5
  your username is: <%= @user.email %>.
6
6
 
7
- To login to the site, just follow this link: <%= @url %>.
7
+ To login to the site, just follow this link: <%= sign_in_url %>
8
8
 
9
- Thanks for joining and have a great day!
9
+ Thanks for joining and have a great day!
@@ -9,8 +9,8 @@
9
9
  You have requested to reset your password.
10
10
  </p>
11
11
  <p>
12
- To choose a new password, just follow this link: <%= @url %>.
12
+ To choose a new password, just follow this link: <%= link_to reset_password_url(@user.reset_password_token), reset_password_url(@user.reset_password_token) %>.
13
13
  </p>
14
14
  <p>Have a great day!</p>
15
15
  </body>
16
- </html>
16
+ </html>
@@ -3,6 +3,6 @@ Hello, <%= @user.email %>
3
3
 
4
4
  You have requested to reset your password.
5
5
 
6
- To choose a new password, just follow this link: <%= @url %>.
6
+ To choose a new password, just follow this link: <%= reset_password_url(@user.reset_password_token) %>
7
7
 
8
- Have a great day!
8
+ Have a great day!
@@ -6,8 +6,8 @@
6
6
  = f.input :password
7
7
 
8
8
  ul.unstyled
9
- li= link_to 'Sign up', sign_up_path
10
- li= link_to 'Reset forgotten password', new_password_reset_path
9
+ li= link_to 'Sign Up', sign_up_path
10
+ li= link_to 'Reset Password', forgotten_password_path
11
11
 
12
12
  .form-actions
13
13
  = f.button :submit, 'Sign In', class: 'btn btn-primary'
@@ -14,4 +14,4 @@ dl
14
14
 
15
15
  - if can?(:destroy, @user)
16
16
  '
17
- = link_to'Destroy', user_path(@user), method: :delete, data: { confirm: "Are you sure?" }, class: 'btn btn-danger'
17
+ = link_to 'Destroy', user_path(@user), method: :delete, data: { confirm: "Are you sure?" }, class: 'btn btn-danger'
@@ -4,9 +4,8 @@ require File.expand_path('../boot', __FILE__)
4
4
  require "active_record/railtie"
5
5
  require "action_controller/railtie"
6
6
  require "action_mailer/railtie"
7
- require "active_resource/railtie"
7
+ #require "active_resource/railtie"
8
8
  require "sprockets/railtie"
9
- # require "rails/test_unit/railtie"
10
9
 
11
10
  if defined?(Bundler)
12
11
  # If you precompile assets before deploying to production, use this line
@@ -23,6 +22,7 @@ module AppPrototype
23
22
  #generate.helper false
24
23
  generate.routing_specs false
25
24
  #generate.view_specs false
25
+ generate.request_specs false
26
26
  end
27
27
 
28
28
  # Settings in config/environments/* take precedence over those specified here.
@@ -65,5 +65,5 @@ AppPrototype::Application.configure do
65
65
  # with SQLite, MySQL, and PostgreSQL)
66
66
  # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
67
 
68
- config.action_mailer.default_url_options = { host: 'acceptance.app_prototype.com' }
68
+ config.action_mailer.default_url_options = { host: 'app_prototype-acceptance.herokuapp.com' }
69
69
  end
@@ -35,5 +35,5 @@ AppPrototype::Application.configure do
35
35
  # Expands the lines which load the assets
36
36
  config.assets.debug = true
37
37
 
38
- config.action_mailer.default_url_options = { host: 'app_prototype.local' }
38
+ config.action_mailer.default_url_options = { host: '0.0.0.0:3000' }
39
39
  end
@@ -65,5 +65,5 @@ AppPrototype::Application.configure do
65
65
  # with SQLite, MySQL, and PostgreSQL)
66
66
  # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
67
 
68
- config.action_mailer.default_url_options = { host: 'app_prototype.com' }
68
+ config.action_mailer.default_url_options = { host: 'app_prototype.herokuapp.com' }
69
69
  end
@@ -37,4 +37,6 @@ AppPrototype::Application.configure do
37
37
 
38
38
  config.action_mailer.default_url_options = { host: 'example.com' }
39
39
  end
40
+
41
+ # Turn down the cost so that specs run quickly.
40
42
  Sorcery::CryptoProviders::BCrypt.cost = 1
@@ -0,0 +1,11 @@
1
+ # http://www.mikeperham.com/2012/12/09/12-gems-of-christmas-4-mailcatcher-and-mail_view/
2
+
3
+ begin
4
+ sock = TCPSocket.new('localhost', 1025)
5
+ sock.close
6
+ catcher = true
7
+ rescue
8
+ catcher = false
9
+ end
10
+
11
+ ActionMailer::Base.smtp_settings = (Rails.env.development? && catcher) ? { host: 'localhost', port: '1025', } : {}
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- AppPrototype::Application.config.secret_token = 'SECRET_TOKEN_REPLACE_ME_TODO'
7
+ AppPrototype::Application.config.secret_token = 'SUPER_SECRET_TOKEN_REPLACE_ME_TODO'
@@ -1,21 +1,21 @@
1
1
  AppPrototype::Application.routes.draw do
2
- match 'sign_in' => 'user_sessions#new', as: :sign_in
3
2
 
3
+ match 'sign_in' => 'user_sessions#new', as: :sign_in
4
4
  match 'sign_out' => 'user_sessions#destroy', as: :sign_out
5
5
 
6
6
  resources :user_sessions, only: [:new, :create, :destroy]
7
7
 
8
- resources :registrations, only: [:new, :create, :activate]
9
-
10
- match 'sign_up' => 'registrations#new', via: :get
8
+ #resources :registrations, only: [:new, :create, :activate]
9
+ match 'sign_up' => 'registrations#new', via: :get, as: :sign_up
10
+ match 'sign_up' => 'registrations#create', via: :post, as: :sign_up
11
+ match 'activate/:token' => 'registrations#activate', via: :get, as: :activation
11
12
 
12
- match 'sign_up' => 'registrations#create', via: :post
13
-
14
- match 'sign_up/:token/activate' => 'registrations#activate', via: :get
15
-
16
- resources :password_resets, only: [:new, :create, :edit, :update]
13
+ #resources :password_resets, only: [:new, :create, :edit, :update]
14
+ match 'forgotten_password' => 'password_resets#new', via: :get, as: :forgotten_password
15
+ match 'forgotten_password' => 'password_resets#create', via: :post, as: :forgotten_password
16
+ match 'reset_password/:token' => 'password_resets#edit', via: :get, as: :reset_password
17
+ match 'reset_password/:id' => 'password_resets#update', via: :put
17
18
 
18
19
  resources :users
19
20
 
20
-
21
21
  end
@@ -1,8 +1,18 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
4
 
5
- # Disable buffering for real time logging (foreman and heroku).
5
+ # Disable buffering for real time logging, see: https://devcenter.heroku.com/articles/logging#writing-to-your-log
6
6
  $stdout.sync = true
7
7
 
8
+ # Optional Basic Auth - Enabled if BASIC_AUTH_PASSWORD is set. User is optional (any value will be accepted).
9
+ BASIC_AUTH_USER = ENV['BASIC_AUTH_USER']
10
+ BASIC_AUTH_PASSWORD = ENV['BASIC_AUTH_PASSWORD']
11
+
12
+ if BASIC_AUTH_PASSWORD
13
+ use Rack::Auth::Basic do |username, password|
14
+ password == BASIC_AUTH_PASSWORD && (BASIC_AUTH_USER.blank? || username == BASIC_AUTH_USER)
15
+ end
16
+ end
17
+
8
18
  run AppPrototype::Application
@@ -10,14 +10,14 @@
10
10
  # Data that is required by the application across all environments (i.e. reference data) should _not_ be included here.
11
11
  # That belongs in seeds.rb instead.
12
12
 
13
- User.create! do |u|
14
- u.email = 'user@example.com'
13
+ # TODO Disable sending emails, no need for seed data.
14
+
15
+ User.find_or_create_by_email('user@example.com') do |u|
15
16
  u.name = 'Ustead User'
16
17
  u.password = 'password'
17
18
  end.activate!
18
19
 
19
- User.create! do |u|
20
- u.email = 'admin@example.com'
20
+ User.find_or_create_by_email('admin@example.com') do |u|
21
21
  u.name = 'Adam Admin'
22
22
  u.password = 'password'
23
23
  u.admin = true
@@ -22,39 +22,39 @@ describe <%= controller_class_name %>Controller do
22
22
  end
23
23
 
24
24
  <% unless options[:singleton] -%>
25
- describe "GET index" do
25
+ describe "#index" do
26
26
  it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
27
27
  <%= file_name %> = <%= class_name %>.create! valid_attributes
28
28
  get :index, {}, valid_session
29
- assigns(:<%= table_name %>).should eq([<%= file_name %>])
29
+ expect(assigns(:<%= table_name %>)).to eq([<%= file_name %>])
30
30
  end
31
31
  end
32
32
 
33
33
  <% end -%>
34
- describe "GET show" do
34
+ describe "#show" do
35
35
  it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
36
36
  <%= file_name %> = <%= class_name %>.create! valid_attributes
37
37
  get :show, { :id => <%= file_name %>.to_param }, valid_session
38
- assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
38
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
39
39
  end
40
40
  end
41
41
 
42
- describe "GET new" do
42
+ describe "#new" do
43
43
  it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
44
44
  get :new, {}, valid_session
45
- assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
45
+ expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
46
46
  end
47
47
  end
48
48
 
49
- describe "GET edit" do
49
+ describe "#edit" do
50
50
  it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
51
51
  <%= file_name %> = <%= class_name %>.create! valid_attributes
52
52
  get :edit, { :id => <%= file_name %>.to_param }, valid_session
53
- assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
53
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
54
54
  end
55
55
  end
56
56
 
57
- describe "POST create" do
57
+ describe "#create" do
58
58
  describe "with valid params" do
59
59
  it "creates a new <%= class_name %>" do
60
60
  expect {
@@ -64,13 +64,13 @@ describe <%= controller_class_name %>Controller do
64
64
 
65
65
  it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
66
66
  post :create, {:<%= ns_file_name %> => valid_attributes }, valid_session
67
- assigns(:<%= ns_file_name %>).should be_a(<%= class_name %>)
68
- assigns(:<%= ns_file_name %>).should be_persisted
67
+ expect(assigns(:<%= ns_file_name %>)).to be_a(<%= class_name %>)
68
+ expect(assigns(:<%= ns_file_name %>)).to be_persisted
69
69
  end
70
70
 
71
71
  it "redirects to the created <%= ns_file_name %>" do
72
72
  post :create, { :<%= ns_file_name %> => valid_attributes }, valid_session
73
- response.should redirect_to(<%= class_name %>.last)
73
+ expect(response).to redirect_to(<%= class_name %>.last)
74
74
  end
75
75
  end
76
76
 
@@ -79,19 +79,19 @@ describe <%= controller_class_name %>Controller do
79
79
  # Trigger the behavior that occurs when invalid params are submitted
80
80
  <%= class_name %>.any_instance.stub(:save).and_return(false)
81
81
  post :create, { :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %> }, valid_session
82
- assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
82
+ expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
83
83
  end
84
84
 
85
85
  it "re-renders the 'new' template" do
86
86
  # Trigger the behavior that occurs when invalid params are submitted
87
87
  <%= class_name %>.any_instance.stub(:save).and_return(false)
88
88
  post :create, { :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %> }, valid_session
89
- response.should render_template("new")
89
+ expect(response).to render_template("new")
90
90
  end
91
91
  end
92
92
  end
93
93
 
94
- describe "PUT update" do
94
+ describe "#update" do
95
95
  describe "with valid params" do
96
96
  it "updates the requested <%= ns_file_name %>" do
97
97
  <%= file_name %> = <%= class_name %>.create! valid_attributes
@@ -106,13 +106,13 @@ describe <%= controller_class_name %>Controller do
106
106
  it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
107
107
  <%= file_name %> = <%= class_name %>.create! valid_attributes
108
108
  put :update, { :id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes }, valid_session
109
- assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
109
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
110
110
  end
111
111
 
112
112
  it "redirects to the <%= ns_file_name %>" do
113
113
  <%= file_name %> = <%= class_name %>.create! valid_attributes
114
114
  put :update, { :id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes }, valid_session
115
- response.should redirect_to(<%= file_name %>)
115
+ expect(response).to redirect_to(<%= file_name %>)
116
116
  end
117
117
  end
118
118
 
@@ -122,7 +122,7 @@ describe <%= controller_class_name %>Controller do
122
122
  # Trigger the behavior that occurs when invalid params are submitted
123
123
  <%= class_name %>.any_instance.stub(:save).and_return(false)
124
124
  put :update, { :id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %> }, valid_session
125
- assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
125
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
126
126
  end
127
127
 
128
128
  it "re-renders the 'edit' template" do
@@ -130,12 +130,12 @@ describe <%= controller_class_name %>Controller do
130
130
  # Trigger the behavior that occurs when invalid params are submitted
131
131
  <%= class_name %>.any_instance.stub(:save).and_return(false)
132
132
  put :update, { :id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %> }, valid_session
133
- response.should render_template("edit")
133
+ expect(response).to render_template("edit")
134
134
  end
135
135
  end
136
136
  end
137
137
 
138
- describe "DELETE destroy" do
138
+ describe "#destroy" do
139
139
  it "destroys the requested <%= ns_file_name %>" do
140
140
  <%= file_name %> = <%= class_name %>.create! valid_attributes
141
141
  expect {
@@ -146,7 +146,7 @@ describe <%= controller_class_name %>Controller do
146
146
  it "redirects to the <%= table_name %> list" do
147
147
  <%= file_name %> = <%= class_name %>.create! valid_attributes
148
148
  delete :destroy, { :id => <%= file_name %>.to_param }, valid_session
149
- response.should redirect_to(<%= index_helper %>_url)
149
+ expect(response).to redirect_to(<%= index_helper %>_url)
150
150
  end
151
151
  end
152
152