Skip to content

Commit

Permalink
added some more test, and removed some extra devise stuff not needed …
Browse files Browse the repository at this point in the history
…for bootstrapping
  • Loading branch information
Graeme Nelson committed Aug 28, 2010
1 parent d509dec commit fe601ea
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 69 deletions.
2 changes: 2 additions & 0 deletions bootstrap/setup/setup_generator.rb
Expand Up @@ -75,6 +75,8 @@ def setup_initial_tests
# setups the initial application, this includes moving over default
# views and support classes.
def setup_initial_application
remove_file "#{Rails.root}/app/controllers/application_controller.rb"
template "app/controllers/application_controller.rb", "app/controllers/application_controller.rb"
remove_file "#{Rails.root}/app/helpers/application_helper.rb"
template "app/helpers/application_helper.rb", "app/helpers/application_helper.rb"

Expand Down
@@ -0,0 +1,23 @@
class ApplicationController < ActionController::Base

layout proc{ |controller| controller.devise_controller? ? devise_layout : "application" }

protect_from_forgery

private

def devise_layout
devise_layout = "public"
devise_layout = "application" if devise_actions_for_application_layout.include?( "#{controller_path}##{action_name}" )
devise_layout
end

def devise_actions_for_application_layout
@_devise_actions_for_application_layout ||=
[ "devise/registrations#edit",
"devise/registrations#update",
"devise/passwords#edit",
"devise/passwords#update" ]
end

end
@@ -1,9 +1,10 @@
<% singular = @resource.singularize -%>
%p
Thanks for Joining #{@site_name}!
%br
Your account login is: #{@email}
%br
You can access your account at: #{link_to(account_root_url,account_root_url)}
You can access your account at: #{link_to(<%= singular %>_root_url,<%= singular %>_root_url)}
%br
If the above URL does not work try copying and pasting it into your browser. If you continue to have problem please feel free to contact us.
%br
Expand Down
10 changes: 10 additions & 0 deletions bootstrap/setup/templates/config/locales/views/passwords/en.yml
@@ -0,0 +1,10 @@
en:
passwords:
new:
header: "Reset Your Password"
buttons:
commit: "Reset"
edit:
header: "Update Your Password"
buttons:
commit: "Update Password"
@@ -0,0 +1,6 @@
en:
sessions:
new:
header: "Sign Into Your Account"
buttons:
commit: "Sign In"
2 changes: 1 addition & 1 deletion bootstrap/setup/templates/config/routes.rb
Expand Up @@ -10,7 +10,7 @@
end

# the default <%= @resource.singularize %> root path used by devise.
match '/account', :to => "<%= @resource %>#show", :as => "<%= @resource.singularize %>_root"
match '/<%= @resource.singularize %>', :to => "<%= @resource %>#show", :as => "<%= @resource.singularize %>_root"

# makes the / path redirect to devise signin page
root :to => 'devise/sessions#new'
Expand Down
@@ -1,12 +1,162 @@
require 'test_helper'
<% singular = @resource.singularize -%>
class Devise::PasswordsControllerTest < ActionController::TestCase
context "routes" do
context "new" do
context "without an authenticated <%= singular %>" do
setup do
get :new
end
should render_template(:new)
should render_with_layout(:public)
should "render appropriate view elements" do
assert_select "body#passwords.new" do
assert_select "h2", :text => I18n.t('passwords.new.header')
assert_select "form[action='#{<%= singular %>_password_path}']" do
assert_select "fieldset.inputs" do
assert_select "ol" do
assert_select "li#<%= singular %>_email_input" do
assert_select "label[for='<%= singular %>_email']", :text => "#{I18n.t('activerecord.attributes.<%= singular %>.email')}*"
assert_select "input[type='text'][name='<%= singular %>[email]']"
end
end
end
assert_select "fieldset.buttons" do
assert_select "ol" do
assert_select "li.commit" do
assert_select "input[type='submit'][value='#{I18n.t('passwords.new.buttons.commit')}']"
end
end
end
end
end
end

end

should "/<%= @resource %>/password/new should route to {:controller => 'devise/passwords', :action => 'new'}" do
assert_routing( "/<%= @resource %>/password/new", {:controller => 'devise/passwords', :action => 'new'})
end

end
context "with an authenticated <%= singular %>" do

setup do
sign_in( Factory.create(:<%= singular %>) )
get :new
end

should redirect_to("<%= singular %> path") { <%= singular %>_root_path }
end
end
context "create" do
context "with valid email address" do
setup do
@<%= singular %> = Factory.create(:<%= singular %>)
ActionMailer::Base.deliveries.clear
post :create, :<%= singular %> => {:email => @<%= singular %>.email}
end

should "send reset password email" do
assert_equal 1, ActionMailer::Base.deliveries.size
end

should "set reset password token" do
assert_not_nil @<%= singular %>.reload.reset_password_token
end

end

context "without a valid email address" do

setup do
@<%= singular %> = Factory.create(:<%= singular %>)
ActionMailer::Base.deliveries.clear
post :create, :<%= singular %> => {:email => ""}
end

should render_template(:new)

end

end

context "edit" do

context "with token" do

setup do
reset_password_token = "myspecialtoken"
@<%= singular %> = Factory.create(:<%= singular %>)
@<%= singular %>.update_attribute(:reset_password_token, reset_password_token)
get :edit, :reset_password_token => reset_password_token
end

should render_template(:edit)
should render_with_layout(:application)

should "render appropriate view elements" do
assert_select "body#passwords.edit" do
assert_select "h2", :text => I18n.t('passwords.edit.header')
assert_select "form[action='#{<%= singular %>_password_path}']" do
assert_select "fieldset.inputs" do
assert_select "ol" do
assert_select "li#<%= singular %>_reset_password_token_input.hidden" do
assert_select "input[type='hidden'][name='<%= singular %>[reset_password_token]']"
end
assert_select "li#<%= singular %>_password_input.required" do
assert_select "label[for='<%= singular %>_password']", :text => "#{I18n.t('activerecord.attributes.<%= singular %>.password')}*"
assert_select "input[type='password'][name='<%= singular %>[password]']"
end
assert_select "li#<%= singular %>_password_confirmation_input.optional" do
assert_select "label[for='<%= singular %>_password_confirmation']", :text => "#{I18n.t('activerecord.attributes.<%= singular %>.password_confirmation')}"
assert_select "input[type='password'][name='<%= singular %>[password_confirmation]']"
end
end
end
assert_select "fieldset.buttons" do
assert_select "ol" do
assert_select "li.commit" do
assert_select "input[type='submit'][value='#{I18n.t('passwords.edit.buttons.commit')}']"
end
end
end
end
end
end

end

end

context "update" do

context "with authenticated account" do

context "with valid password and password confirmation" do

should "change password"

end

context "with invalid password and password confirmation" do

should "edit template with errors"

end

context "with invalid reset password token" do

should "render update template with errors"

end

end

end

end
Expand Up @@ -5,12 +5,6 @@ class Devise::RegistrationsControllerTest < ActionController::TestCase
setup :fix_devise_registrations_authenticate_scope
context "routes" do
should route(:get, '/<%= @resource %>/signup').to(:controller => 'devise/registrations', :action => 'new')
end
context "new" do
context "without an authenticated <%= singular %>" do
Expand All @@ -19,7 +13,8 @@ class Devise::RegistrationsControllerTest < ActionController::TestCase
get :new
end
should render_template(:new)
should render_template(:new)
should render_with_layout(:public)
should "render appropriate view elements" do
assert_select "body#registrations.new" do
Expand All @@ -44,7 +39,7 @@ class Devise::RegistrationsControllerTest < ActionController::TestCase
assert_select "fieldset.buttons" do
assert_select "ol" do
assert_select "li.commit" do
assert_select "input[type='submit'][value='Create #{<%= singular.titleize %>}']"
assert_select "input[type='submit'][value='Create <%= singular.titleize %>']"
end
end
end
Expand All @@ -60,6 +55,17 @@ class Devise::RegistrationsControllerTest < ActionController::TestCase
end
end
end

context "with an authenticated <%= singular %>" do

setup do
sign_in( Factory.create(:<%= singular %>) )
get :new
end

should redirect_to("<%= singular %> path") { <%= singular %>_root_path }
end
end
Expand All @@ -83,6 +89,7 @@ class Devise::RegistrationsControllerTest < ActionController::TestCase
end

should render_template(:new)
should render_with_layout(:public)

should "render appropriate view elements" do
assert_select "body#registrations.create" do
Expand Down Expand Up @@ -110,7 +117,7 @@ class Devise::RegistrationsControllerTest < ActionController::TestCase
assert_select "fieldset.buttons" do
assert_select "ol" do
assert_select "li.commit" do
assert_select "input[type='submit'][value='Create #{<%= singular.titleize %>}']"
assert_select "input[type='submit'][value='Create <%= singular.titleize %>']"
end
end
end
Expand Down Expand Up @@ -179,7 +186,7 @@ class Devise::RegistrationsControllerTest < ActionController::TestCase
assert_select "fieldset.buttons" do
assert_select "ol" do
assert_select "li.commit" do
assert_select "input[type='submit'][value='Update #{<%= singular.titleize %>}']"
assert_select "input[type='submit'][value='Update <%= singular.titleize %>']"
end
end
end
Expand Down

0 comments on commit fe601ea

Please sign in to comment.