raygun 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/.gitignore +17 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +63 -0
  6. data/Rakefile +1 -0
  7. data/TODO.md +24 -0
  8. data/bin/raygun +11 -0
  9. data/lib/raygun/actions.rb +26 -0
  10. data/lib/raygun/app_builder.rb +283 -0
  11. data/lib/raygun/generators/app_generator.rb +182 -0
  12. data/lib/raygun/version.rb +3 -0
  13. data/marvin.jpg +0 -0
  14. data/raygun.gemspec +25 -0
  15. data/templates/Gemfile_customized +32 -0
  16. data/templates/README.md.erb +31 -0
  17. data/templates/_app/assets/stylesheets/_footer.less +30 -0
  18. data/templates/_app/assets/stylesheets/application.css.less +8 -0
  19. data/templates/_app/controllers/application_controller.rb +14 -0
  20. data/templates/_app/controllers/password_resets_controller.rb +38 -0
  21. data/templates/_app/controllers/registrations_controller.rb +27 -0
  22. data/templates/_app/controllers/user_sessions_controller.rb +25 -0
  23. data/templates/_app/helpers/application_helper.rb +11 -0
  24. data/templates/_app/mailers/user_mailer.rb +22 -0
  25. data/templates/_app/models/user.rb +17 -0
  26. data/templates/_app/models/user_session.rb +6 -0
  27. data/templates/_app/views/layouts/application.html.slim.erb +36 -0
  28. data/templates/_app/views/password_resets/edit.html.slim +16 -0
  29. data/templates/_app/views/password_resets/new.html.slim +11 -0
  30. data/templates/_app/views/registrations/new.html.slim +14 -0
  31. data/templates/_app/views/user_mailer/activation_needed_email.html.erb +17 -0
  32. data/templates/_app/views/user_mailer/activation_needed_email.text.erb +9 -0
  33. data/templates/_app/views/user_mailer/activation_success_email.html.erb +17 -0
  34. data/templates/_app/views/user_mailer/activation_success_email.text.erb +9 -0
  35. data/templates/_app/views/user_mailer/reset_password_email.html.erb +16 -0
  36. data/templates/_app/views/user_mailer/reset_password_email.text.erb +8 -0
  37. data/templates/_app/views/user_sessions/new.html.slim +13 -0
  38. data/templates/_config/database.yml.erb +13 -0
  39. data/templates/_db/sample_data.rb +17 -0
  40. data/templates/_lib/email_validator.rb +9 -0
  41. data/templates/_lib/tasks/db.rake +7 -0
  42. data/templates/_lib/templates/rspec/scaffold/controller_spec.rb +152 -0
  43. data/templates/_lib/templates/slim/scaffold/_form.html.slim +13 -0
  44. data/templates/_lib/templates/slim/scaffold/edit.html.slim +5 -0
  45. data/templates/_lib/templates/slim/scaffold/index.html.slim +27 -0
  46. data/templates/_lib/templates/slim/scaffold/new.html.slim +4 -0
  47. data/templates/_lib/templates/slim/scaffold/show.html.slim +15 -0
  48. data/templates/_public/index.html.erb +41 -0
  49. data/templates/_spec/factories/users.rb +7 -0
  50. data/templates/_spec/mailers/user_mailer_spec.rb +48 -0
  51. data/templates/_spec/models/user_spec.rb +29 -0
  52. data/templates/_spec/requests/user_sessions_spec.rb +29 -0
  53. data/templates/_spec/support/accept_values.rb +55 -0
  54. data/templates/_spec/support/factory_girl.rb +3 -0
  55. data/templates/_spec/support/sorcery.rb +3 -0
  56. data/templates/_spec/support/user_sessions_request_helper.rb +21 -0
  57. data/templates/rvmrc.erb +1 -0
  58. metadata +168 -0
@@ -0,0 +1,32 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'thin'
4
+ gem 'rails', '~> 3.2.8'
5
+ gem 'slim-rails'
6
+ gem 'jquery-rails'
7
+ gem 'sorcery'
8
+ gem 'simple_form'
9
+ gem 'active_attr'
10
+ gem 'pg'
11
+ gem 'awesome_print'
12
+
13
+ group :assets do
14
+ gem 'less-rails'
15
+ gem 'less-rails-bootstrap'
16
+ gem 'coffee-rails'
17
+ gem 'uglifier'
18
+ gem 'therubyracer', platforms: :ruby
19
+ end
20
+
21
+ group :test, :development do
22
+ gem 'rspec-rails'
23
+ gem 'capybara', github: 'jnicklas/capybara' # TODO Change when 2.0 is released.
24
+ gem 'factory_girl_rails'
25
+ gem 'timecop'
26
+ end
27
+
28
+ group :development do
29
+ gem 'guard'
30
+ gem 'guard-rspec'
31
+ gem 'guard-livereload'
32
+ end
@@ -0,0 +1,31 @@
1
+ Overview
2
+ ========
3
+
4
+ ...
5
+
6
+ Requirements
7
+ ============
8
+
9
+ * ruby 1.9.?
10
+ * postgresql 9.?
11
+
12
+ Running the Specs
13
+ =================
14
+
15
+ $ rake db:setup db:test:prepare
16
+ $ rake
17
+
18
+ Running the Application
19
+ =======================
20
+
21
+ $ rails s
22
+
23
+ Using Guard
24
+ ===========
25
+
26
+ $ guard -c
27
+
28
+ Considerations
29
+ ==============
30
+
31
+ ...
@@ -0,0 +1,30 @@
1
+ @footerHeight: 30px;
2
+
3
+ html, body {
4
+ height: 100%;
5
+ }
6
+
7
+ .wrapper {
8
+ min-height: 100%;
9
+ height: auto !important;
10
+ height: 100%;
11
+ margin: 0 auto -(@footerHeight + 1);
12
+ }
13
+
14
+ .push {
15
+ height: @footerHeight + 20px; // The extra prevents content from bumping right into our footer.
16
+ }
17
+
18
+ footer {
19
+ height: @footerHeight;
20
+ line-height: @footerHeight;
21
+
22
+ .container {
23
+ border-top: 1px solid @grayLighter;
24
+ }
25
+
26
+ p {
27
+ margin: 0;
28
+ color: @grayLight;
29
+ }
30
+ }
@@ -0,0 +1,8 @@
1
+ @import 'twitter/bootstrap';
2
+ @import '_footer';
3
+
4
+ // Navbar
5
+
6
+ .wrapper > .container {
7
+ padding-top: 60px; // Push the content down so that it's below our pinned navbar.
8
+ }
@@ -0,0 +1,14 @@
1
+ class ApplicationController < ActionController::Base
2
+
3
+ # Uncomment to require auth on all actions (and opt-out when necessary).
4
+ # before_filter :require_login, except: [:not_authenticated]
5
+
6
+ protect_from_forgery
7
+
8
+ protected
9
+
10
+ def not_authenticated
11
+ redirect_to sign_in_path, alert: "Please sign in first."
12
+ end
13
+
14
+ end
@@ -0,0 +1,38 @@
1
+ class PasswordResetsController < ApplicationController
2
+
3
+ skip_before_filter :require_login
4
+
5
+ def create
6
+ @user = User.find_by_email(params[:email])
7
+
8
+ # Send an email to the user with instructions on how to reset their password.
9
+ @user.deliver_reset_password_instructions! if @user
10
+
11
+ # Tell the user instructions have been sent whether or not email was found.
12
+ # This is to not leak information to attackers about which emails exist in the system.
13
+ redirect_to sign_in_path, notice: "Password reset instructions have been sent to your email."
14
+ end
15
+
16
+ def edit
17
+ @user = User.load_from_reset_password_token(params[:id])
18
+ @token = params[:id]
19
+ not_authenticated if !@user
20
+ end
21
+
22
+ def update
23
+ @token = params[:token] # needed to render the form again in case of error
24
+ @user = User.load_from_reset_password_token(@token)
25
+ not_authenticated if !@user
26
+
27
+ # Makes the password confirmation validation work.
28
+ @user.password_confirmation = params[:user][:password_confirmation]
29
+
30
+ # Clear the temporary token and update the password.
31
+ if @user.change_password!(params[:user][:password])
32
+ redirect_to sign_in_path, notice: "Password was successfully updated."
33
+ else
34
+ render action: 'edit'
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,27 @@
1
+ class RegistrationsController < ApplicationController
2
+
3
+ def new
4
+ @user = User.new
5
+ end
6
+
7
+ def create
8
+ @user = User.new(params[:user])
9
+
10
+ if @user.save
11
+ redirect_to sign_in_path, notice: "Thanks for signing up. Please check your email for activation instructions."
12
+ else
13
+ render action: 'new'
14
+ end
15
+ end
16
+
17
+ def activate
18
+ if @user = User.load_from_activation_token(params[:token])
19
+ @user.activate!
20
+ auto_login @user
21
+ redirect_to sign_in_path, notice: "Your account has been activated and you're now signed in. Enjoy!"
22
+ else
23
+ not_authenticated
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,25 @@
1
+ class UserSessionsController < ApplicationController
2
+
3
+ skip_before_filter :require_login, except: [:destroy]
4
+
5
+ def new
6
+ @user_session = UserSession.new
7
+ end
8
+
9
+ def create
10
+ @user_session = UserSession.new(params[:user_session])
11
+
12
+ if @user = login(@user_session.email, @user_session.password, @user_session.remember_me)
13
+ redirect_back_or_to :users, notice: "Successfully signed in."
14
+ else
15
+ flash.now[:alert] = "Sign in failed."
16
+ render action: 'new'
17
+ end
18
+ end
19
+
20
+ def destroy
21
+ logout
22
+ redirect_to :users, notice: "Signed out!"
23
+ end
24
+
25
+ end
@@ -0,0 +1,11 @@
1
+ module ApplicationHelper
2
+
3
+ def alert_class(alert_type)
4
+ alert_type = {
5
+ alert: 'error',
6
+ notice: 'info'
7
+ }.fetch(alert_type, alert_type.to_s)
8
+ "alert-#{alert_type}"
9
+ end
10
+
11
+ end
@@ -0,0 +1,22 @@
1
+ class UserMailer < ActionMailer::Base
2
+
3
+ default from: 'notifications@example.com'
4
+
5
+ def activation_needed_email(user)
6
+ @user = user
7
+ @url = "http://0.0.0.0:3000/sign_up/#{user.activation_token}/activate"
8
+ mail to: user.email, subject: "Welcome to My Awesome Site!"
9
+ end
10
+
11
+ def activation_success_email(user)
12
+ @user = user
13
+ @url = "http://0.0.0.0:3000/sign_in"
14
+ mail to: user.email, subject: "Your account has been activated!"
15
+ end
16
+
17
+ def reset_password_email(user)
18
+ @user = user
19
+ @url = "http://0.0.0.0:3000/password_resets/#{user.reset_password_token}/edit"
20
+ mail to: user.email, subject: "Password reset requested"
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ class User < ActiveRecord::Base
2
+
3
+ attr_accessible :name, :email, :password, :password_confirmation
4
+
5
+ authenticates_with_sorcery!
6
+
7
+ validates :email,
8
+ presence: true,
9
+ email: true
10
+
11
+ validates :password,
12
+ presence: true,
13
+ length: { minimum: 3},
14
+ confirmation: true,
15
+ if: :password
16
+
17
+ end
@@ -0,0 +1,6 @@
1
+ class UserSession
2
+ include ActiveAttr::BasicModel
3
+ include ActiveAttr::MassAssignment
4
+
5
+ attr_accessor :email, :password, :remember_me
6
+ end
@@ -0,0 +1,36 @@
1
+ doctype 5
2
+ html
3
+ head
4
+ title <%= app_name.capitalize %>
5
+ = stylesheet_link_tag 'application', media: 'all'
6
+ = javascript_include_tag 'application'
7
+ = csrf_meta_tag
8
+
9
+ body id=(controller.controller_name) class=(controller.action_name)
10
+ .wrapper
11
+ .container
12
+ header.navbar.navbar-fixed-top
13
+ nav.navbar-inner
14
+ .container
15
+ .brand <%= app_name.capitalize %>
16
+ ul.nav.pull-right
17
+ - if current_user
18
+ li.dropdown
19
+ a.dropdown-toggle href='#' data-toggle='dropdown'
20
+ = current_user.email
21
+ b.caret
22
+ ul.dropdown-menu
23
+ li= link_to 'Sign Out', sign_out_path
24
+ - else
25
+ li= link_to 'Sign in', sign_in_path
26
+
27
+ - flash.each do |name, msg|
28
+ = content_tag :div, raw(msg), class: "alert #{alert_class(name)}"
29
+
30
+ = yield
31
+
32
+ .push
33
+
34
+ footer
35
+ .container
36
+ p &copy; 2012 All rights reserved.
@@ -0,0 +1,16 @@
1
+ .page-header
2
+ h1 Reset Your Password
3
+
4
+ = simple_form_for(@user, url: password_reset_path(@user)) do |f|
5
+ = f.error_notification
6
+
7
+ .form-inputs
8
+ = f.input :email, disabled: true
9
+ = f.input :password, required: true, autofocus: true
10
+ = f.input :password_confirmation, required: true
11
+ = hidden_field_tag :token, @token
12
+
13
+ .form-actions
14
+ = f.button :submit, 'Reset Password', class: 'btn btn-primary'
15
+ '
16
+ = link_to 'Cancel', sign_in_path, class: 'btn'
@@ -0,0 +1,11 @@
1
+ .page-header
2
+ h1 Password Reset
3
+
4
+ = form_tag(password_resets_path, method: :post) do
5
+ .control-group
6
+ = label_tag :email, nil, class: 'control-label'
7
+ .controls
8
+ = text_field_tag :email, nil, placeholder: 'joe@example.com'
9
+
10
+ .form-actions
11
+ = submit_tag "Reset my password!", class: 'btn btn-primary'
@@ -0,0 +1,14 @@
1
+ .page-header
2
+ h1 Sign up for an Account
3
+
4
+ = simple_form_for(@user, url: sign_up_path) do |f|
5
+ = f.error_notification
6
+
7
+ .form-inputs
8
+ = f.input :name, autofocus: true
9
+ = f.input :email
10
+ = f.input :password
11
+ = f.input :password_confirmation
12
+
13
+ .form-actions
14
+ = f.button :submit, 'Sign up', class: 'btn btn-primary'
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
5
+ </head>
6
+ <body>
7
+ <h1>Welcome to example.com, <%= @user.email %></h1>
8
+ <p>
9
+ You have successfully signed up to example.com,
10
+ your username is: <%= @user.email %>.<br/>
11
+ </p>
12
+ <p>
13
+ To login to the site, just follow this link: <%= @url %>.
14
+ </p>
15
+ <p>Thanks for joining and have a great day!</p>
16
+ </body>
17
+ </html>
@@ -0,0 +1,9 @@
1
+ Welcome to example.com, <%= @user.email %>
2
+ ===============================================
3
+
4
+ You have successfully signed up to example.com,
5
+ your username is: <%= @user.email %>.
6
+
7
+ To login to the site, just follow this link: <%= @url %>.
8
+
9
+ Thanks for joining and have a great day!
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
5
+ </head>
6
+ <body>
7
+ <h1>Congratz, <%= @user.email %></h1>
8
+ <p>
9
+ You have successfully activated your example.com account,
10
+ your username is: <%= @user.email %>.<br/>
11
+ </p>
12
+ <p>
13
+ To login to the site, just follow this link: <%= @url %>.
14
+ </p>
15
+ <p>Thanks for joining and have a great day!</p>
16
+ </body>
17
+ </html>
@@ -0,0 +1,9 @@
1
+ Congratz, <%= @user.email %>
2
+ ===============================================
3
+
4
+ You have successfully activated your example.com account,
5
+ your username is: <%= @user.email %>.
6
+
7
+ To login to the site, just follow this link: <%= @url %>.
8
+
9
+ Thanks for joining and have a great day!
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
5
+ </head>
6
+ <body>
7
+ <h1>Hello, <%= @user.email %></h1>
8
+ <p>
9
+ You have requested to reset your password.
10
+ </p>
11
+ <p>
12
+ To choose a new password, just follow this link: <%= @url %>.
13
+ </p>
14
+ <p>Have a great day!</p>
15
+ </body>
16
+ </html>
@@ -0,0 +1,8 @@
1
+ Hello, <%= @user.email %>
2
+ ===============================================
3
+
4
+ You have requested to reset your password.
5
+
6
+ To choose a new password, just follow this link: <%= @url %>.
7
+
8
+ Have a great day!
@@ -0,0 +1,13 @@
1
+ = simple_form_for(@user_session) do |f|
2
+ = f.error_notification
3
+
4
+ .form-inputs
5
+ = f.input :email, placeholder: 'jdoe@example.com', autofocus: true
6
+ = f.input :password
7
+
8
+ ul.unstyled
9
+ li= link_to 'Sign up', sign_up_path
10
+ li= link_to 'Reset forgotten password', new_password_reset_path
11
+
12
+ .form-actions
13
+ = f.button :submit, 'Sign In', class: 'btn btn-primary'
@@ -0,0 +1,13 @@
1
+ # Use 'createuser -s postgres' to create a general purpose db (super)user.
2
+
3
+ development: &default
4
+ adapter: postgresql
5
+ database: <%= app_name %>_development
6
+ username: postgres
7
+ pool: 5
8
+ timeout: 5000
9
+
10
+ test: &TEST
11
+ <<: *default
12
+ database: <%= app_name %>_test
13
+ min_messages: warning
@@ -0,0 +1,17 @@
1
+ # Populate the database with a small set of realistic sample data so that as a developer/designer, you can use the
2
+ # application without having to create a bunch of stuff or pull down production data.
3
+ #
4
+ # After running db:sample_data, a developer/designer should be able to fire up the app, sign in, browse data and see
5
+ # examples of practically anything (interesting) that can happen in the system.
6
+ #
7
+ # It's a good idea to build this up along with the features; when you build a feature, make sure you can easily demo it
8
+ # after running db:sample_data.
9
+ #
10
+ # Data that is required by the application across all environments (i.e. reference data) should _not_ be included here.
11
+ # That belongs in seeds.rb instead.
12
+
13
+ User.create! do |u|
14
+ u.email = 'user@example.com'
15
+ u.name = 'John Smith'
16
+ u.password = 'password'
17
+ end.activate!
@@ -0,0 +1,9 @@
1
+ class EmailValidator < ActiveModel::EachValidator
2
+
3
+ def validate_each(record, attribute, value)
4
+ unless value =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
5
+ record.errors[attribute] << (options[:message] || "is not an email")
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ namespace :db do
2
+ desc "Load a small, representative set of data so that the application can start in an use state (for development)."
3
+ task :sample_data => :environment do
4
+ sample_data = File.join(Rails.root, 'db', 'sample_data.rb')
5
+ load(sample_data) if sample_data
6
+ end
7
+ end
@@ -0,0 +1,152 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= controller_class_name %>Controller do
4
+
5
+ # This should return the minimal set of attributes required to create a valid
6
+ # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
7
+ # update the return value of this method accordingly.
8
+ def valid_attributes
9
+ attributes_for :<%= file_name %>
10
+ end
11
+
12
+ # This should return the minimal set of values that should be in the session
13
+ # in order to pass any filters (e.g. authentication) defined in
14
+ # <%= controller_class_name %>Controller. Be sure to keep this updated too.
15
+ def valid_session
16
+ {}
17
+ end
18
+
19
+ before do
20
+ login_user build :user
21
+ end
22
+
23
+ <% unless options[:singleton] -%>
24
+ describe "GET index" do
25
+ it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
26
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
27
+ get :index, {}, valid_session
28
+ assigns(:<%= table_name %>).should eq([<%= file_name %>])
29
+ end
30
+ end
31
+
32
+ <% end -%>
33
+ describe "GET show" do
34
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
35
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
36
+ get :show, {:id => <%= file_name %>.to_param}, valid_session
37
+ assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
38
+ end
39
+ end
40
+
41
+ describe "GET new" do
42
+ it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
43
+ get :new, {}, valid_session
44
+ assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
45
+ end
46
+ end
47
+
48
+ describe "GET edit" do
49
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
50
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
51
+ get :edit, {:id => <%= file_name %>.to_param}, valid_session
52
+ assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
53
+ end
54
+ end
55
+
56
+ describe "POST create" do
57
+ describe "with valid params" do
58
+ it "creates a new <%= class_name %>" do
59
+ expect {
60
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
61
+ }.to change(<%= class_name %>, :count).by(1)
62
+ end
63
+
64
+ it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
65
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
66
+ assigns(:<%= ns_file_name %>).should be_a(<%= class_name %>)
67
+ assigns(:<%= ns_file_name %>).should be_persisted
68
+ end
69
+
70
+ it "redirects to the created <%= ns_file_name %>" do
71
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
72
+ response.should redirect_to(<%= class_name %>.last)
73
+ end
74
+ end
75
+
76
+ describe "with invalid params" do
77
+ it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
78
+ # Trigger the behavior that occurs when invalid params are submitted
79
+ <%= class_name %>.any_instance.stub(:save).and_return(false)
80
+ post :create, {:<%= ns_file_name %> => {}}, valid_session
81
+ assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
82
+ end
83
+
84
+ it "re-renders the 'new' template" do
85
+ # Trigger the behavior that occurs when invalid params are submitted
86
+ <%= class_name %>.any_instance.stub(:save).and_return(false)
87
+ post :create, {:<%= ns_file_name %> => {}}, valid_session
88
+ response.should render_template("new")
89
+ end
90
+ end
91
+ end
92
+
93
+ describe "PUT update" do
94
+ describe "with valid params" do
95
+ it "updates the requested <%= ns_file_name %>" do
96
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
97
+ # Assuming there are no other <%= table_name %> in the database, this
98
+ # specifies that the <%= class_name %> created on the previous line
99
+ # receives the :update_attributes message with whatever params are
100
+ # submitted in the request.
101
+ <%= class_name %>.any_instance.should_receive(:update_attributes).with(<%= params %>)
102
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= params %>}, valid_session
103
+ end
104
+
105
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
106
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
107
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
108
+ assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
109
+ end
110
+
111
+ it "redirects to the <%= ns_file_name %>" do
112
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
113
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
114
+ response.should redirect_to(<%= file_name %>)
115
+ end
116
+ end
117
+
118
+ describe "with invalid params" do
119
+ it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
120
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
121
+ # Trigger the behavior that occurs when invalid params are submitted
122
+ <%= class_name %>.any_instance.stub(:save).and_return(false)
123
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => {}}, valid_session
124
+ assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
125
+ end
126
+
127
+ it "re-renders the 'edit' template" do
128
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
129
+ # Trigger the behavior that occurs when invalid params are submitted
130
+ <%= class_name %>.any_instance.stub(:save).and_return(false)
131
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => {}}, valid_session
132
+ response.should render_template("edit")
133
+ end
134
+ end
135
+ end
136
+
137
+ describe "DELETE destroy" do
138
+ it "destroys the requested <%= ns_file_name %>" do
139
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
140
+ expect {
141
+ delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
142
+ }.to change(<%= class_name %>, :count).by(-1)
143
+ end
144
+
145
+ it "redirects to the <%= table_name %> list" do
146
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
147
+ delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
148
+ response.should redirect_to(<%= index_helper %>_url)
149
+ end
150
+ end
151
+
152
+ end