Skip to content
Browse files

Merge pull request #12 from KentonWhite/rails3

Rails3
  • Loading branch information...
2 parents 63aeed7 + 38417a9 commit a2f669944c86f2bec46bb248360e556a983140d4 @Satish committed Sep 19, 2011
View
6 lib/generators/authenticated/templates/authenticated_system.rb
@@ -81,7 +81,7 @@ def access_denied
#
# We can return to this location by calling #redirect_back_or_default.
def store_location
- session[:return_to] = request.request_uri
+ session[:return_to] = request.fullpath
end
# Redirect to the URI stored by the most recent store_location call or
@@ -122,7 +122,7 @@ def login_from_basic_auth
# Called from #current_<%= file_name %>. Finaly, attempt to login by an expiring token in the cookie.
# for the paranoid: we _should_ be storing <%= file_name %>_token = hash(cookie_token, request IP)
def login_from_cookie
- <%= file_name %> = cookies[:auth_token] && <%= class_name %>.find_by_remember_token(cookies[:auth_token].value)
+ <%= file_name %> = cookies[:auth_token] && <%= class_name %>.find_by_remember_token(cookies[:auth_token])
if <%= file_name %> && <%= file_name %>.remember_token?
self.current_<%= file_name %> = <%= file_name %>
handle_remember_cookie! false # freshen cookie token (keeping date)
@@ -136,7 +136,7 @@ def login_from_cookie
def logout_keeping_session!
# Kill server-side auth cookie
@current_<%= file_name %>.forget_me if @current_<%= file_name %>.is_a? <%= class_name %>
- @current_<%= file_name %> = false # not logged in, and don't do it for me
+# @current_<%= file_name %> = false # not logged in, and don't do it for me
kill_remember_cookie! # Kill client-side auth cookie
session[:<%= file_name %>_id] = nil # keeps the session but kill our variable
# explicitly kill any other session variables you set
View
37 lib/generators/authenticated/templates/spec/controllers/access_control_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '<%= ('/..'*controller_class_nesting_depth) + '/../spec_helper' %>'
+require File.dirname(__FILE__) + '/../spec_helper'
# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead
# Then, you can remove it from this and the units test.
include AuthenticatedTestHelper
@@ -31,9 +31,9 @@ def login_not_required
#
ACCESS_CONTROL_FORMATS = [
- ['', "success"],
+ ['html', "success"],
['xml', "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <success>xml</success>\n</hash>\n"],
- ['json', "{\"success\": \"json\"}"],]
+ ['json', "{\"success\":\"json\"}"],]
ACCESS_CONTROL_AM_I_LOGGED_IN = [
[:i_am_logged_in, :quentin],
[:i_am_not_logged_in, nil],]
@@ -42,38 +42,49 @@ def login_not_required
:login_is_required,]
describe AccessControlTestController do
- fixtures :<%= table_name %>
+ fixtures :users
before do
# is there a better way to do this?
- ActionController::Routing::Routes.add_route '/login_is_required', :controller => 'access_control_test', :action => 'login_is_required'
- ActionController::Routing::Routes.add_route '/login_not_required', :controller => 'access_control_test', :action => 'login_not_required'
+ begin
+ _routes = Rails.application.class.routes
+ _routes.disable_clear_and_finalize = true
+ _routes.clear!
+ Rails.application.class.routes_reloader.paths.each{ |path| load(path) }
+ _routes.draw do
+ match 'login_is_required' => 'access_control_test#login_is_required'
+ match 'login_not_required' => 'access_control_test#login_not_required'
+ end
+ ActiveSupport.on_load(:action_controller) { _routes.finalize! }
+ ensure
+ _routes.disable_clear_and_finalize = false
+ end
end
ACCESS_CONTROL_FORMATS.each do |format, success_text|
- ACCESS_CONTROL_AM_I_LOGGED_IN.each do |logged_in_status, <%= file_name %>_login|
+ ACCESS_CONTROL_AM_I_LOGGED_IN.each do |logged_in_status, user_login|
ACCESS_CONTROL_IS_LOGIN_REQD.each do |login_reqd_status|
describe "requesting #{format.blank? ? 'html' : format}; #{logged_in_status.to_s.humanize} and #{login_reqd_status.to_s.humanize}" do
before do
- logout_keeping_session!
- @<%= file_name %> = format.blank? ? login_as(<%= file_name %>_login) : authorize_as(<%= file_name %>_login)
+ controller.send(:logout_keeping_session!)
+ @user = format.blank? ? login_as(user_login) : authorize_as(user_login)
get login_reqd_status.to_s, :format => format
end
if ((login_reqd_status == :login_not_required) ||
(login_reqd_status == :login_is_required && logged_in_status == :i_am_logged_in))
- it "succeeds" do
- response.should have_text(success_text)
+ it "succeeds" do
+ response.body.should == success_text
response.code.to_s.should == '200'
end
elsif (login_reqd_status == :login_is_required && logged_in_status == :i_am_not_logged_in)
if ['html', ''].include? format
it "redirects me to the log in page" do
- response.should redirect_to('/<%= controller_routing_path %>/new')
+ response.should redirect_to('/session/new')
end
else
it "returns 'Access denied' and a 406 (Access Denied) status code" do
- response.should have_text("HTTP Basic: Access denied.\n")
+ response.should contain("HTTP Basic: Access denied.")
response.code.to_s.should == '401'
end
end
View
44 lib/generators/authenticated/templates/spec/controllers/authenticated_system_spec.rb
@@ -1,16 +1,16 @@
-require File.dirname(__FILE__) + '<%= ('/..'*controller_class_nesting_depth) + '/../spec_helper' %>'
+require File.dirname(__FILE__) + '/../spec_helper'
# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead
# Then, you can remove it from this and the units test.
include AuthenticatedTestHelper
include AuthenticatedSystem
def action_name() end
-describe <%= controller_class_name %>Controller do
- fixtures :<%= table_name %>
+describe SessionsController do
+ fixtures :users
before do
- # FIXME -- <%= controller_file_name %> controller not testing xml logins
+ # FIXME -- sessions controller not testing xml logins
stub!(:authenticate_with_http_basic).and_return nil
end
describe "logout_killing_session!" do
@@ -20,18 +20,18 @@ def action_name() end
end
it 'resets the session' do should_receive(:reset_session); logout_killing_session! end
it 'kills my auth_token cookie' do should_receive(:kill_remember_cookie!); logout_killing_session! end
- it 'nils the current <%= file_name %>' do logout_killing_session!; current_<%= file_name %>.should be_nil end
- it 'kills :<%= file_name %>_id session' do
+ it 'nils the current user' do logout_killing_session!; current_user.should be_nil end
+ it 'kills :user_id session' do
session.stub!(:[]=)
- session.should_receive(:[]=).with(:<%= file_name %>_id, nil).at_least(:once)
+ session.should_receive(:[]=).with(:user_id, nil).at_least(:once)
logout_killing_session!
end
it 'forgets me' do
- current_<%= file_name %>.remember_me
- current_<%= file_name %>.remember_token.should_not be_nil; current_<%= file_name %>.remember_token_expires_at.should_not be_nil
- <%= class_name %>.find(1).remember_token.should_not be_nil; <%= class_name %>.find(1).remember_token_expires_at.should_not be_nil
+ current_user.remember_me
+ current_user.remember_token.should_not be_nil; current_user.remember_token_expires_at.should_not be_nil
+ User.find(1).remember_token.should_not be_nil; User.find(1).remember_token_expires_at.should_not be_nil
logout_killing_session!
- <%= class_name %>.find(1).remember_token.should be_nil; <%= class_name %>.find(1).remember_token_expires_at.should be_nil
+ User.find(1).remember_token.should be_nil; User.find(1).remember_token_expires_at.should be_nil
end
end
@@ -42,18 +42,18 @@ def action_name() end
end
it 'does not reset the session' do should_not_receive(:reset_session); logout_keeping_session! end
it 'kills my auth_token cookie' do should_receive(:kill_remember_cookie!); logout_keeping_session! end
- it 'nils the current <%= file_name %>' do logout_keeping_session!; current_<%= file_name %>.should be_nil end
- it 'kills :<%= file_name %>_id session' do
+ it 'nils the current user' do logout_keeping_session!; current_user.should be_nil end
+ it 'kills :user_id session' do
session.stub!(:[]=)
- session.should_receive(:[]=).with(:<%= file_name %>_id, nil).at_least(:once)
+ session.should_receive(:[]=).with(:user_id, nil).at_least(:once)
logout_keeping_session!
end
it 'forgets me' do
- current_<%= file_name %>.remember_me
- current_<%= file_name %>.remember_token.should_not be_nil; current_<%= file_name %>.remember_token_expires_at.should_not be_nil
- <%= class_name %>.find(1).remember_token.should_not be_nil; <%= class_name %>.find(1).remember_token_expires_at.should_not be_nil
+ current_user.remember_me
+ current_user.remember_token.should_not be_nil; current_user.remember_token_expires_at.should_not be_nil
+ User.find(1).remember_token.should_not be_nil; User.find(1).remember_token_expires_at.should_not be_nil
logout_keeping_session!
- <%= class_name %>.find(1).remember_token.should be_nil; <%= class_name %>.find(1).remember_token_expires_at.should be_nil
+ User.find(1).remember_token.should be_nil; User.find(1).remember_token_expires_at.should be_nil
end
end
@@ -68,12 +68,12 @@ def action_name() end
#
describe "Logging in by cookie" do
def set_remember_token token, time
- @<%= file_name %>[:remember_token] = token;
- @<%= file_name %>[:remember_token_expires_at] = time
- @<%= file_name %>.save!
+ @user[:remember_token] = token;
+ @user[:remember_token_expires_at] = time
+ @user.save!
end
before do
- @<%= file_name %> = <%= class_name %>.find(:first);
+ @user = User.find(:first);
set_remember_token 'hello!', 5.minutes.from_now
end
it 'logs in with cookie' do
View
76 lib/generators/authenticated/templates/spec/controllers/sessions_controller_spec.rb
@@ -1,15 +1,15 @@
-require File.dirname(__FILE__) + '<%= ('/..'*controller_class_nesting_depth) + '/../spec_helper' %>'
+require File.dirname(__FILE__) + '/../spec_helper'
# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead
# Then, you can remove it from this and the units test.
include AuthenticatedTestHelper
-describe <%= controller_class_name %>Controller do
- fixtures :<%= table_name %>
+describe SessionsController do
+ fixtures :users
before do
- @<%= file_name %> = mock_<%= file_name %>
+ @user = mock_user
@login_params = { :login => 'quentin', :password => 'test' }
- <%= class_name %>.stub!(:authenticate).with(@login_params[:login], @login_params[:password]).and_return(@<%= file_name %>)
+ User.stub!(:authenticate).with(@login_params[:login], @login_params[:password]).and_return(@user)
end
def do_create
post :create, @login_params
@@ -29,12 +29,12 @@ def do_create
@ccookies.stub!(:[]).with(:auth_token).and_return(token_value)
@ccookies.stub!(:delete).with(:auth_token)
@ccookies.stub!(:[]=)
- @<%= file_name %>.stub!(:remember_me)
- @<%= file_name %>.stub!(:refresh_token)
- @<%= file_name %>.stub!(:forget_me)
- @<%= file_name %>.stub!(:remember_token).and_return(token_value)
- @<%= file_name %>.stub!(:remember_token_expires_at).and_return(token_expiry)
- @<%= file_name %>.stub!(:remember_token?).and_return(has_request_token == :valid)
+ @user.stub!(:remember_me)
+ @user.stub!(:refresh_token)
+ @user.stub!(:forget_me)
+ @user.stub!(:remember_token).and_return(token_value)
+ @user.stub!(:remember_token_expires_at).and_return(token_expiry)
+ @user.stub!(:remember_token?).and_return(has_request_token == :valid)
if want_remember_me
@login_params[:remember_me] = '1'
else
@@ -44,24 +44,24 @@ def do_create
it "kills existing login" do controller.should_receive(:logout_keeping_session!); do_create; end
it "authorizes me" do do_create; controller.send(:authorized?).should be_true; end
it "logs me in" do do_create; controller.send(:logged_in?).should be_true end
- it "greets me nicely" do do_create; response.flash[:notice].should =~ /success/i end
+ it "greets me nicely" do do_create; flash[:notice].should =~ /success/i end
it "sets/resets/expires cookie" do controller.should_receive(:handle_remember_cookie!).with(want_remember_me); do_create end
it "sends a cookie" do controller.should_receive(:send_remember_cookie!); do_create end
it 'redirects to the home page' do do_create; response.should redirect_to('/') end
it "does not reset my session" do controller.should_not_receive(:reset_session).and_return nil; do_create end # change if you uncomment the reset_session path
if (has_request_token == :valid)
- it 'does not make new token' do @<%= file_name %>.should_not_receive(:remember_me); do_create end
- it 'does refresh token' do @<%= file_name %>.should_receive(:refresh_token); do_create end
+ it 'does not make new token' do @user.should_not_receive(:remember_me); do_create end
+ it 'does refresh token' do @user.should_receive(:refresh_token); do_create end
it "sets an auth cookie" do do_create; end
else
if want_remember_me
- it 'makes a new token' do @<%= file_name %>.should_receive(:remember_me); do_create end
- it "does not refresh token" do @<%= file_name %>.should_not_receive(:refresh_token); do_create end
+ it 'makes a new token' do @user.should_receive(:remember_me); do_create end
+ it "does not refresh token" do @user.should_not_receive(:refresh_token); do_create end
it "sets an auth cookie" do do_create; end
else
- it 'does not make new token' do @<%= file_name %>.should_not_receive(:remember_me); do_create end
- it 'does not refresh token' do @<%= file_name %>.should_not_receive(:refresh_token); do_create end
- it 'kills user token' do @<%= file_name %>.should_receive(:forget_me); do_create end
+ it 'does not make new token' do @user.should_not_receive(:remember_me); do_create end
+ it 'does not refresh token' do @user.should_not_receive(:refresh_token); do_create end
+ it 'kills user token' do @user.should_receive(:forget_me); do_create end
end
end
end # inner describe
@@ -72,7 +72,7 @@ def do_create
describe "on failed login" do
before do
- <%= class_name %>.should_receive(:authenticate).with(anything(), anything()).and_return(nil)
+ User.should_receive(:authenticate).with(anything(), anything()).and_return(nil)
login_as :quentin
end
it 'logs out keeping session' do controller.should_receive(:logout_keeping_session!); do_create end
@@ -82,7 +82,7 @@ def do_create
it "doesn't send password back" do
@login_params[:password] = 'FROBNOZZ'
do_create
- response.should_not have_text(/FROBNOZZ/i)
+ response.should_not contain(/FROBNOZZ/i)
end
end
@@ -99,40 +99,28 @@ def do_destroy
end
-describe <%= controller_class_name %>Controller do
- describe "route generation" do
- it "should route the new <%= controller_controller_name %> action correctly" do
- route_for(:controller => '<%= controller_controller_name %>', :action => 'new').should == "/login"
- end
- it "should route the create <%= controller_controller_name %> correctly" do
- route_for(:controller => '<%= controller_controller_name %>', :action => 'create').should == "/<%= controller_routing_path %>"
- end
- it "should route the destroy <%= controller_controller_name %> action correctly" do
- route_for(:controller => '<%= controller_controller_name %>', :action => 'destroy').should == "/logout"
- end
- end
-
- describe "route recognition" do
+describe SessionsController do
+ describe "route recognition and generation" do
it "should generate params from GET /login correctly" do
- params_from(:get, '/login').should == {:controller => '<%= controller_controller_name %>', :action => 'new'}
+ {:get => '/login'}.should route_to(:controller => 'sessions', :action => 'new')
end
- it "should generate params from POST /<%= controller_routing_path %> correctly" do
- params_from(:post, '/<%= controller_routing_path %>').should == {:controller => '<%= controller_controller_name %>', :action => 'create'}
+ it "should generate params from POST /session correctly" do
+ {:post => '/session'}.should route_to(:controller => 'sessions', :action => 'create')
end
- it "should generate params from DELETE /<%= controller_routing_path %> correctly" do
- params_from(:delete, '/logout').should == {:controller => '<%= controller_controller_name %>', :action => 'destroy'}
+ it "should generate params from DELETE /session correctly" do
+ {:delete => '/logout'}.should route_to(:controller => 'sessions', :action => 'destroy')
end
end
describe "named routing" do
before(:each) do
get :new
end
- it "should route <%= controller_routing_name %>_path() correctly" do
- <%= controller_routing_name %>_path().should == "/<%= controller_routing_path %>"
+ it "should route session_path() correctly" do
+ session_path().should == "/session"
end
- it "should route new_<%= controller_routing_name %>_path() correctly" do
- new_<%= controller_routing_name %>_path().should == "/<%= controller_routing_path %>/new"
+ it "should route new_session_path() correctly" do
+ new_session_path().should == "/session/new"
end
end
View
191 lib/generators/authenticated/templates/spec/controllers/users_controller_spec.rb
@@ -1,169 +1,102 @@
-require File.dirname(__FILE__) + '<%= ('/..'*model_controller_class_nesting_depth) + '/../spec_helper' %>'
+require File.dirname(__FILE__) + '/../spec_helper'
# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead
# Then, you can remove it from this and the units test.
include AuthenticatedTestHelper
-describe <%= model_controller_class_name %>Controller do
- fixtures :<%= table_name %>
+describe UsersController do
+ fixtures :users
it 'allows signup' do
lambda do
- create_<%= file_name %>
+ create_user
response.should be_redirect
- end.should change(<%= class_name %>, :count).by(1)
+ end.should change(User, :count).by(1)
end
- <% if options.stateful? %>
- it 'signs up user in pending state' do
- create_<%= file_name %>
- assigns(:<%= file_name %>).reload
- assigns(:<%= file_name %>).should be_pending
- end<% end %>
+
-<% if options[:include_activation] -%>
- it 'signs up user with activation code' do
- create_<%= file_name %>
- assigns(:<%= file_name %>).reload
- assigns(:<%= file_name %>).activation_code.should_not be_nil
- end<% end -%>
it 'requires login on signup' do
lambda do
- create_<%= file_name %>(:login => nil)
- assigns[:<%= file_name %>].errors.on(:login).should_not be_nil
+ create_user(:login => nil)
+ assigns[:user].errors.get(:login).should_not be_nil
response.should be_success
- end.should_not change(<%= class_name %>, :count)
+ end.should_not change(User, :count)
end
it 'requires password on signup' do
lambda do
- create_<%= file_name %>(:password => nil)
- assigns[:<%= file_name %>].errors.on(:password).should_not be_nil
+ create_user(:password => nil)
+ assigns[:user].errors.get(:password).should_not be_nil
response.should be_success
- end.should_not change(<%= class_name %>, :count)
+ end.should_not change(User, :count)
end
it 'requires password confirmation on signup' do
lambda do
- create_<%= file_name %>(:password_confirmation => nil)
- assigns[:<%= file_name %>].errors.on(:password_confirmation).should_not be_nil
+ create_user(:password_confirmation => nil)
+ assigns[:user].errors.get(:password_confirmation).should_not be_nil
response.should be_success
- end.should_not change(<%= class_name %>, :count)
+ end.should_not change(User, :count)
end
it 'requires email on signup' do
lambda do
- create_<%= file_name %>(:email => nil)
- assigns[:<%= file_name %>].errors.on(:email).should_not be_nil
+ create_user(:email => nil)
+ assigns[:user].errors.get(:email).should_not be_nil
response.should be_success
- end.should_not change(<%= class_name %>, :count)
- end
-
- <% if options.include_activation? %>
- it 'activates user' do
- <%= class_name %>.authenticate('aaron', 'monkey').should be_nil
- get :activate, :activation_code => <%= table_name %>(:aaron).activation_code
- response.should redirect_to('/login')
- flash[:notice].should_not be_nil
- flash[:error ].should be_nil
- <%= class_name %>.authenticate('aaron', 'monkey').should == <%= table_name %>(:aaron)
+ end.should_not change(User, :count)
end
- it 'does not activate user without key' do
- get :activate
- flash[:notice].should be_nil
- flash[:error ].should_not be_nil
- end
-
- it 'does not activate user with blank key' do
- get :activate, :activation_code => ''
- flash[:notice].should be_nil
- flash[:error ].should_not be_nil
- end
- it 'does not activate user with bogus key' do
- get :activate, :activation_code => 'i_haxxor_joo'
- flash[:notice].should be_nil
- flash[:error ].should_not be_nil
- end<% end %>
- def create_<%= file_name %>(options = {})
- post :create, :<%= file_name %> => { :login => 'quire', :email => 'quire@example.com',
+ def create_user(options = {})
+ post :create, :user => { :login => 'quire', :email => 'quire@example.com',
:password => 'quire69', :password_confirmation => 'quire69' }.merge(options)
end
end
-describe <%= model_controller_class_name %>Controller do
- describe "route generation" do
- it "should route <%= model_controller_controller_name %>'s 'index' action correctly" do
- route_for(:controller => '<%= model_controller_controller_name %>', :action => 'index').should == "/<%= model_controller_routing_path %>"
- end
-
- it "should route <%= model_controller_controller_name %>'s 'new' action correctly" do
- route_for(:controller => '<%= model_controller_controller_name %>', :action => 'new').should == "/signup"
- end
-
- it "should route {:controller => '<%= model_controller_controller_name %>', :action => 'create'} correctly" do
- route_for(:controller => '<%= model_controller_controller_name %>', :action => 'create').should == "/register"
- end
-
- it "should route <%= model_controller_controller_name %>'s 'show' action correctly" do
- route_for(:controller => '<%= model_controller_controller_name %>', :action => 'show', :id => '1').should == "/<%= model_controller_routing_path %>/1"
- end
-
- it "should route <%= model_controller_controller_name %>'s 'edit' action correctly" do
- route_for(:controller => '<%= model_controller_controller_name %>', :action => 'edit', :id => '1').should == "/<%= model_controller_routing_path %>/1/edit"
- end
-
- it "should route <%= model_controller_controller_name %>'s 'update' action correctly" do
- route_for(:controller => '<%= model_controller_controller_name %>', :action => 'update', :id => '1').should == "/<%= model_controller_routing_path %>/1"
- end
-
- it "should route <%= model_controller_controller_name %>'s 'destroy' action correctly" do
- route_for(:controller => '<%= model_controller_controller_name %>', :action => 'destroy', :id => '1').should == "/<%= model_controller_routing_path %>/1"
- end
- end
-
- describe "route recognition" do
- it "should generate params for <%= model_controller_controller_name %>'s index action from GET /<%= model_controller_routing_path %>" do
- params_from(:get, '/<%= model_controller_routing_path %>').should == {:controller => '<%= model_controller_controller_name %>', :action => 'index'}
- params_from(:get, '/<%= model_controller_routing_path %>.xml').should == {:controller => '<%= model_controller_controller_name %>', :action => 'index', :format => 'xml'}
- params_from(:get, '/<%= model_controller_routing_path %>.json').should == {:controller => '<%= model_controller_controller_name %>', :action => 'index', :format => 'json'}
+describe UsersController do
+ describe "route recognition and generation" do
+ it "should generate params for users's index action from GET /users" do
+ {:get => '/users'}.should route_to(:controller => 'users', :action => 'index')
+ {:get => '/users.xml'}.should route_to(:controller => 'users', :action => 'index', :format => 'xml')
+ {:get => '/users.json'}.should route_to(:controller => 'users', :action => 'index', :format => 'json')
end
- it "should generate params for <%= model_controller_controller_name %>'s new action from GET /<%= model_controller_routing_path %>" do
- params_from(:get, '/<%= model_controller_routing_path %>/new').should == {:controller => '<%= model_controller_controller_name %>', :action => 'new'}
- params_from(:get, '/<%= model_controller_routing_path %>/new.xml').should == {:controller => '<%= model_controller_controller_name %>', :action => 'new', :format => 'xml'}
- params_from(:get, '/<%= model_controller_routing_path %>/new.json').should == {:controller => '<%= model_controller_controller_name %>', :action => 'new', :format => 'json'}
+ it "should generate params for users's new action from GET /users" do
+ {:get => '/users/new'}.should route_to(:controller => 'users', :action => 'new')
+ {:get => '/users/new.xml'}.should route_to(:controller => 'users', :action => 'new', :format => 'xml')
+ {:get => '/users/new.json'}.should route_to(:controller => 'users', :action => 'new', :format => 'json')
end
- it "should generate params for <%= model_controller_controller_name %>'s create action from POST /<%= model_controller_routing_path %>" do
- params_from(:post, '/<%= model_controller_routing_path %>').should == {:controller => '<%= model_controller_controller_name %>', :action => 'create'}
- params_from(:post, '/<%= model_controller_routing_path %>.xml').should == {:controller => '<%= model_controller_controller_name %>', :action => 'create', :format => 'xml'}
- params_from(:post, '/<%= model_controller_routing_path %>.json').should == {:controller => '<%= model_controller_controller_name %>', :action => 'create', :format => 'json'}
+ it "should generate params for users's create action from POST /users" do
+ {:post => '/users'}.should route_to(:controller => 'users', :action => 'create')
+ {:post => '/users.xml'}.should route_to(:controller => 'users', :action => 'create', :format => 'xml')
+ {:post => '/users.json'}.should route_to(:controller => 'users', :action => 'create', :format => 'json')
end
- it "should generate params for <%= model_controller_controller_name %>'s show action from GET /<%= model_controller_routing_path %>/1" do
- params_from(:get , '/<%= model_controller_routing_path %>/1').should == {:controller => '<%= model_controller_controller_name %>', :action => 'show', :id => '1'}
- params_from(:get , '/<%= model_controller_routing_path %>/1.xml').should == {:controller => '<%= model_controller_controller_name %>', :action => 'show', :id => '1', :format => 'xml'}
- params_from(:get , '/<%= model_controller_routing_path %>/1.json').should == {:controller => '<%= model_controller_controller_name %>', :action => 'show', :id => '1', :format => 'json'}
+ it "should generate params for users's show action from GET /users/1" do
+ {:get => '/users/1'}.should route_to(:controller => 'users', :action => 'show', :id => '1')
+ {:get => '/users/1.xml'}.should route_to(:controller => 'users', :action => 'show', :id => '1', :format => 'xml')
+ {:get => '/users/1.json'}.should route_to(:controller => 'users', :action => 'show', :id => '1', :format => 'json')
end
- it "should generate params for <%= model_controller_controller_name %>'s edit action from GET /<%= model_controller_routing_path %>/1/edit" do
- params_from(:get , '/<%= model_controller_routing_path %>/1/edit').should == {:controller => '<%= model_controller_controller_name %>', :action => 'edit', :id => '1'}
+ it "should generate params for users's edit action from GET /users/1/edit" do
+ {:get => '/users/1/edit'}.should route_to(:controller => 'users', :action => 'edit', :id => '1')
end
- it "should generate params {:controller => '<%= model_controller_controller_name %>', :action => update', :id => '1'} from PUT /<%= model_controller_routing_path %>/1" do
- params_from(:put , '/<%= model_controller_routing_path %>/1').should == {:controller => '<%= model_controller_controller_name %>', :action => 'update', :id => '1'}
- params_from(:put , '/<%= model_controller_routing_path %>/1.xml').should == {:controller => '<%= model_controller_controller_name %>', :action => 'update', :id => '1', :format => 'xml'}
- params_from(:put , '/<%= model_controller_routing_path %>/1.json').should == {:controller => '<%= model_controller_controller_name %>', :action => 'update', :id => '1', :format => 'json'}
+ it "should generate params {:controller => 'users', :action => update', :id => '1'} from PUT /users/1" do
+ {:put => '/users/1'}.should route_to(:controller => 'users', :action => 'update', :id => '1')
+ {:put => '/users/1.xml'}.should route_to(:controller => 'users', :action => 'update', :id => '1', :format => 'xml')
+ {:put => '/users/1.json'}.should route_to(:controller => 'users', :action => 'update', :id => '1', :format => 'json')
end
- it "should generate params for <%= model_controller_controller_name %>'s destroy action from DELETE /<%= model_controller_routing_path %>/1" do
- params_from(:delete, '/<%= model_controller_routing_path %>/1').should == {:controller => '<%= model_controller_controller_name %>', :action => 'destroy', :id => '1'}
- params_from(:delete, '/<%= model_controller_routing_path %>/1.xml').should == {:controller => '<%= model_controller_controller_name %>', :action => 'destroy', :id => '1', :format => 'xml'}
- params_from(:delete, '/<%= model_controller_routing_path %>/1.json').should == {:controller => '<%= model_controller_controller_name %>', :action => 'destroy', :id => '1', :format => 'json'}
+ it "should generate params for users's destroy action from DELETE /users/1" do
+ {:delete => '/users/1'}.should route_to(:controller => 'users', :action => 'destroy', :id => '1')
+ {:delete => '/users/1.xml'}.should route_to(:controller => 'users', :action => 'destroy', :id => '1', :format => 'xml')
+ {:delete => '/users/1.json'}.should route_to(:controller => 'users', :action => 'destroy', :id => '1', :format => 'json')
end
end
@@ -172,26 +105,26 @@ def create_<%= file_name %>(options = {})
get :new
end
- it "should route <%= model_controller_routing_name %>_path() to /<%= model_controller_routing_path %>" do
- <%= model_controller_routing_name %>_path().should == "/<%= model_controller_routing_path %>"
- formatted_<%= model_controller_routing_name %>_path(:format => 'xml').should == "/<%= model_controller_routing_path %>.xml"
- formatted_<%= model_controller_routing_name %>_path(:format => 'json').should == "/<%= model_controller_routing_path %>.json"
+ it "should route users_path() to /users" do
+ users_path().should == "/users"
+ controller.users_path(:format => 'xml').should == "/users.xml"
+ controller.users_path(:format => 'json').should == "/users.json"
end
- it "should route new_<%= model_controller_routing_name.singularize %>_path() to /<%= model_controller_routing_path %>/new" do
- new_<%= model_controller_routing_name.singularize %>_path().should == "/<%= model_controller_routing_path %>/new"
- formatted_new_<%= model_controller_routing_name.singularize %>_path(:format => 'xml').should == "/<%= model_controller_routing_path %>/new.xml"
- formatted_new_<%= model_controller_routing_name.singularize %>_path(:format => 'json').should == "/<%= model_controller_routing_path %>/new.json"
+ it "should route new_user_path() to /users/new" do
+ new_user_path().should == "/users/new"
+ controller.new_user_path(:format => 'xml').should == "/users/new.xml"
+ controller.new_user_path(:format => 'json').should == "/users/new.json"
end
- it "should route <%= model_controller_routing_name.singularize %>_(:id => '1') to /<%= model_controller_routing_path %>/1" do
- <%= model_controller_routing_name.singularize %>_path(:id => '1').should == "/<%= model_controller_routing_path %>/1"
- formatted_<%= model_controller_routing_name.singularize %>_path(:id => '1', :format => 'xml').should == "/<%= model_controller_routing_path %>/1.xml"
- formatted_<%= model_controller_routing_name.singularize %>_path(:id => '1', :format => 'json').should == "/<%= model_controller_routing_path %>/1.json"
+ it "should route user_(:id => '1') to /users/1" do
+ user_path(:id => '1').should == "/users/1"
+ controller.user_path(:id => '1', :format => 'xml').should == "/users/1.xml"
+ controller.user_path(:id => '1', :format => 'json').should == "/users/1.json"
end
- it "should route edit_<%= model_controller_routing_name.singularize %>_path(:id => '1') to /<%= model_controller_routing_path %>/1/edit" do
- edit_<%= model_controller_routing_name.singularize %>_path(:id => '1').should == "/<%= model_controller_routing_path %>/1/edit"
+ it "should route edit_user_path(:id => '1') to /users/1/edit" do
+ controller.edit_user_path(:id => '1').should == "/users/1/edit"
end
end
View
96 lib/generators/authenticated/templates/spec/helpers/users_helper_spec.rb
@@ -1,138 +1,138 @@
-require File.dirname(__FILE__) + '<%= ('/..'*model_controller_class_nesting_depth) + '/../spec_helper' %>'
+require File.dirname(__FILE__) + '/../spec_helper'
include ApplicationHelper
-include <%= model_controller_class_name %>Helper
+include UsersHelper
include AuthenticatedTestHelper
-describe <%= model_controller_class_name %>Helper do
+describe UsersHelper do
before do
- @<%= file_name %> = mock_<%= file_name %>
+ @user = mock_user
end
describe "if_authorized" do
it "yields if authorized" do
- should_receive(:authorized?).with('a','r').and_return(true)
- if_authorized?('a','r'){|action,resource| [action,resource,'hi'] }.should == ['a','r','hi']
+ helper.should_receive(:authorized?).with('a','r').and_return(true)
+ helper.if_authorized?('a','r'){|action,resource| [action,resource,'hi'] }.should == ['a','r','hi']
end
it "does nothing if not authorized" do
- should_receive(:authorized?).with('a','r').and_return(false)
- if_authorized?('a','r'){ 'hi' }.should be_nil
+ helper.should_receive(:authorized?).with('a','r').and_return(false)
+ helper.if_authorized?('a','r'){ 'hi' }.should be_nil
end
end
- describe "link_to_<%= file_name %>" do
- it "should give an error on a nil <%= file_name %>" do
- lambda { link_to_<%= file_name %>(nil) }.should raise_error('Invalid <%= file_name %>')
+ describe "link_to_user" do
+ it "should give an error on a nil user" do
+ lambda { helper.link_to_user(nil) }.should raise_error('Invalid user')
end
- it "should link to the given <%= file_name %>" do
- should_receive(:<%= model_controller_routing_name.singularize %>_path).at_least(:once).and_return('/<%= model_controller_file_path %>/1')
- link_to_<%= file_name %>(@<%= file_name %>).should have_tag("a[href='/<%= model_controller_file_path %>/1']")
+ it "should link to the given user" do
+ helper.should_receive(:user_path).at_least(:once).and_return('/users/1')
+ helper.link_to_user(@user).should have_tag("a[href='/users/1']")
end
it "should use given link text if :content_text is specified" do
- link_to_<%= file_name %>(@<%= file_name %>, :content_text => 'Hello there!').should have_tag("a", 'Hello there!')
+ helper.link_to_user(@user, :content_text => 'Hello there!').should have_tag("a", :text => 'Hello there!')
end
it "should use the login as link text with no :content_method specified" do
- link_to_<%= file_name %>(@<%= file_name %>).should have_tag("a", 'user_name')
+ helper.link_to_user(@user).should have_tag("a", :text => 'user_name')
end
it "should use the name as link text with :content_method => :name" do
- link_to_<%= file_name %>(@<%= file_name %>, :content_method => :name).should have_tag("a", 'U. Surname')
+ helper.link_to_user(@user, :content_method => :name).should have_tag("a", :text => 'U. Surname')
end
it "should use the login as title with no :title_method specified" do
- link_to_<%= file_name %>(@<%= file_name %>).should have_tag("a[title='user_name']")
+ helper.link_to_user(@user).should have_tag("a[title='user_name']")
end
it "should use the name as link title with :content_method => :name" do
- link_to_<%= file_name %>(@<%= file_name %>, :title_method => :name).should have_tag("a[title='U. Surname']")
+ helper.link_to_user(@user, :title_method => :name).should have_tag("a[title='U. Surname']")
end
it "should have nickname as a class by default" do
- link_to_<%= file_name %>(@<%= file_name %>).should have_tag("a.nickname")
+ helper.link_to_user(@user).should have_tag("a.nickname")
end
it "should take other classes and no longer have the nickname class" do
- result = link_to_<%= file_name %>(@<%= file_name %>, :class => 'foo bar')
+ result = helper.link_to_user(@user, :class => 'foo bar')
result.should have_tag("a.foo")
result.should have_tag("a.bar")
end
end
describe "link_to_login_with_IP" do
it "should link to the login_path" do
- link_to_login_with_IP().should have_tag("a[href='/login']")
+ helper.link_to_login_with_IP().should have_tag("a[href='/login']")
end
it "should use given link text if :content_text is specified" do
- link_to_login_with_IP('Hello there!').should have_tag("a", 'Hello there!')
+ helper.link_to_login_with_IP('Hello there!').should have_tag("a", :text => 'Hello there!')
end
it "should use the login as link text with no :content_method specified" do
- link_to_login_with_IP().should have_tag("a", '0.0.0.0')
+ helper.link_to_login_with_IP().should have_tag("a", :text => '0.0.0.0')
end
it "should use the ip address as title" do
- link_to_login_with_IP().should have_tag("a[title='0.0.0.0']")
+ helper.link_to_login_with_IP().should have_tag("a[title='0.0.0.0']")
end
it "should by default be like school in summer and have no class" do
- link_to_login_with_IP().should_not have_tag("a.nickname")
+ helper.link_to_login_with_IP().should_not have_tag("a.nickname")
end
it "should have some class if you tell it to" do
- result = link_to_login_with_IP(nil, :class => 'foo bar')
+ result = helper.link_to_login_with_IP(nil, :class => 'foo bar')
result.should have_tag("a.foo")
result.should have_tag("a.bar")
end
it "should have some class if you tell it to" do
- result = link_to_login_with_IP(nil, :tag => 'abbr')
+ result = helper.link_to_login_with_IP(nil, :tag => 'abbr')
result.should have_tag("abbr[title='0.0.0.0']")
end
end
- describe "link_to_current_<%= file_name %>, When logged in" do
+ describe "link_to_current_user, When logged in" do
before do
- stub!(:current_<%= file_name %>).and_return(@<%= file_name %>)
+ helper.current_user = @user
end
- it "should link to the given <%= file_name %>" do
- should_receive(:<%= model_controller_routing_name.singularize %>_path).at_least(:once).and_return('/<%= model_controller_file_path %>/1')
- link_to_current_<%= file_name %>().should have_tag("a[href='/<%= model_controller_file_path %>/1']")
+ it "should link to the given user" do
+ helper.should_receive(:user_path).at_least(:once).and_return('/users/1')
+ helper.link_to_current_user().should have_tag("a[href='/users/1']")
end
it "should use given link text if :content_text is specified" do
- link_to_current_<%= file_name %>(:content_text => 'Hello there!').should have_tag("a", 'Hello there!')
+ helper.link_to_current_user(:content_text => 'Hello there!').should have_tag("a", :text => 'Hello there!')
end
it "should use the login as link text with no :content_method specified" do
- link_to_current_<%= file_name %>().should have_tag("a", 'user_name')
+ helper.link_to_current_user().should have_tag("a", :text => 'user_name')
end
it "should use the name as link text with :content_method => :name" do
- link_to_current_<%= file_name %>(:content_method => :name).should have_tag("a", 'U. Surname')
+ helper.link_to_current_user(:content_method => :name).should have_tag("a", :text => 'U. Surname')
end
it "should use the login as title with no :title_method specified" do
- link_to_current_<%= file_name %>().should have_tag("a[title='user_name']")
+ helper.link_to_current_user().should have_tag("a[title='user_name']")
end
it "should use the name as link title with :content_method => :name" do
- link_to_current_<%= file_name %>(:title_method => :name).should have_tag("a[title='U. Surname']")
+ helper.link_to_current_user(:title_method => :name).should have_tag("a[title='U. Surname']")
end
it "should have nickname as a class" do
- link_to_current_<%= file_name %>().should have_tag("a.nickname")
+ helper.link_to_current_user().should have_tag("a.nickname")
end
it "should take other classes and no longer have the nickname class" do
- result = link_to_current_<%= file_name %>(:class => 'foo bar')
+ result = helper.link_to_current_user(:class => 'foo bar')
result.should have_tag("a.foo")
result.should have_tag("a.bar")
end
end
- describe "link_to_current_<%= file_name %>, When logged out" do
+ describe "link_to_current_user, When logged out" do
before do
- stub!(:current_<%= file_name %>).and_return(nil)
+ helper.current_user = nil
end
it "should link to the login_path" do
- link_to_current_<%= file_name %>().should have_tag("a[href='/login']")
+ helper.link_to_current_user().should have_tag("a[href='/login']")
end
it "should use given link text if :content_text is specified" do
- link_to_current_<%= file_name %>(:content_text => 'Hello there!').should have_tag("a", 'Hello there!')
+ helper.link_to_current_user(:content_text => 'Hello there!').should have_tag("a", :text => 'Hello there!')
end
it "should use 'not signed in' as link text with no :content_method specified" do
- link_to_current_<%= file_name %>().should have_tag("a", 'not signed in')
+ helper.link_to_current_user().should have_tag("a", :text => 'not signed in')
end
it "should use the ip address as title" do
- link_to_current_<%= file_name %>().should have_tag("a[title='0.0.0.0']")
+ helper.link_to_current_user().should have_tag("a[title='0.0.0.0']")
end
it "should by default be like school in summer and have no class" do
- link_to_current_<%= file_name %>().should_not have_tag("a.nickname")
+ helper.link_to_current_user().should_not have_tag("a.nickname")
end
it "should have some class if you tell it to" do
- result = link_to_current_<%= file_name %>(:class => 'foo bar')
+ result = helper.link_to_current_user(:class => 'foo bar')
result.should have_tag("a.foo")
result.should have_tag("a.bar")
end
View
209 lib/generators/authenticated/templates/spec/models/user_spec.rb
@@ -1,58 +1,46 @@
# -*- coding: utf-8 -*-
-require File.dirname(__FILE__) + '<%= ('/..'*model_controller_class_nesting_depth) + '/../spec_helper' %>'
+require File.dirname(__FILE__) + '/../spec_helper'
# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead.
# Then, you can remove it from this and the functional test.
include AuthenticatedTestHelper
-describe <%= class_name %> do
- fixtures :<%= table_name %>
+describe User do
+ fixtures :users
describe 'being created' do
before do
- @<%= file_name %> = nil
- @creating_<%= file_name %> = lambda do
- @<%= file_name %> = create_<%= file_name %>
- violated "#{@<%= file_name %>.errors.full_messages.to_sentence}" if @<%= file_name %>.new_record?
+ @user = nil
+ @creating_user = lambda do
+ @user = create_user
+ violated "#{@user.errors.full_messages.to_sentence}" if @user.new_record?
end
end
- it 'increments <%= class_name %>#count' do
- @creating_<%= file_name %>.should change(<%= class_name %>, :count).by(1)
+ it 'increments User#count' do
+ @creating_user.should change(User, :count).by(1)
end
-<% if options[:include_activation] %>
- it 'initializes #activation_code' do
- @creating_<%= file_name %>.call
- @<%= file_name %>.reload
- @<%= file_name %>.activation_code.should_not be_nil
- end
-<% end %><% if options[:stateful] %>
- it 'starts in pending state' do
- @creating_<%= file_name %>.call
- @<%= file_name %>.reload
- @<%= file_name %>.should be_pending
- end
-<% end %> end
+ end
#
# Validations
#
it 'requires login' do
lambda do
- u = create_<%= file_name %>(:login => nil)
- u.errors.on(:login).should_not be_nil
- end.should_not change(<%= class_name %>, :count)
+ u = create_user(:login => nil)
+ u.errors.get(:login).should_not be_nil
+ end.should_not change(User, :count)
end
describe 'allows legitimate logins:' do
['123', '1234567890_234567890_234567890_234567890',
'hello.-_there@funnychar.com'].each do |login_str|
it "'#{login_str}'" do
lambda do
- u = create_<%= file_name %>(:login => login_str)
- u.errors.on(:login).should be_nil
- end.should change(<%= class_name %>, :count).by(1)
+ u = create_user(:login => login_str)
+ u.errors.get(:login).should be_nil
+ end.should change(User, :count).by(1)
end
end
end
@@ -62,32 +50,32 @@
'semicolon;', 'quote"', 'tick\'', 'backtick`', 'percent%', 'plus+', 'space '].each do |login_str|
it "'#{login_str}'" do
lambda do
- u = create_<%= file_name %>(:login => login_str)
- u.errors.on(:login).should_not be_nil
- end.should_not change(<%= class_name %>, :count)
+ u = create_user(:login => login_str)
+ u.errors.get(:login).should_not be_nil
+ end.should_not change(User, :count)
end
end
end
it 'requires password' do
lambda do
- u = create_<%= file_name %>(:password => nil)
- u.errors.on(:password).should_not be_nil
- end.should_not change(<%= class_name %>, :count)
+ u = create_user(:password => nil)
+ u.errors.get(:password).should_not be_nil
+ end.should_not change(User, :count)
end
it 'requires password confirmation' do
lambda do
- u = create_<%= file_name %>(:password_confirmation => nil)
- u.errors.on(:password_confirmation).should_not be_nil
- end.should_not change(<%= class_name %>, :count)
+ u = create_user(:password_confirmation => nil)
+ u.errors.get(:password_confirmation).should_not be_nil
+ end.should_not change(User, :count)
end
it 'requires email' do
lambda do
- u = create_<%= file_name %>(:email => nil)
- u.errors.on(:email).should_not be_nil
- end.should_not change(<%= class_name %>, :count)
+ u = create_user(:email => nil)
+ u.errors.get(:email).should_not be_nil
+ end.should_not change(User, :count)
end
describe 'allows legitimate emails:' do
@@ -98,9 +86,9 @@
].each do |email_str|
it "'#{email_str}'" do
lambda do
- u = create_<%= file_name %>(:email => email_str)
- u.errors.on(:email).should be_nil
- end.should change(<%= class_name %>, :count).by(1)
+ u = create_user(:email => email_str)
+ u.errors.get(:email).should be_nil
+ end.should change(User, :count).by(1)
end
end
end
@@ -113,9 +101,9 @@
].each do |email_str|
it "'#{email_str}'" do
lambda do
- u = create_<%= file_name %>(:email => email_str)
- u.errors.on(:email).should_not be_nil
- end.should_not change(<%= class_name %>, :count)
+ u = create_user(:email => email_str)
+ u.errors.get(:email).should_not be_nil
+ end.should_not change(User, :count)
end
end
end
@@ -126,9 +114,9 @@
].each do |name_str|
it "'#{name_str}'" do
lambda do
- u = create_<%= file_name %>(:name => name_str)
- u.errors.on(:name).should be_nil
- end.should change(<%= class_name %>, :count).by(1)
+ u = create_user(:name => name_str)
+ u.errors.get(:name).should be_nil
+ end.should change(User, :count).by(1)
end
end
end
@@ -138,50 +126,50 @@
].each do |name_str|
it "'#{name_str}'" do
lambda do
- u = create_<%= file_name %>(:name => name_str)
- u.errors.on(:name).should_not be_nil
- end.should_not change(<%= class_name %>, :count)
+ u = create_user(:name => name_str)
+ u.errors.get(:name).should_not be_nil
+ end.should_not change(User, :count)
end
end
end
it 'resets password' do
- <%= table_name %>(:quentin).update_attributes(:password => 'new password', :password_confirmation => 'new password')
- <%= class_name %>.authenticate('quentin', 'new password').should == <%= table_name %>(:quentin)
+ users(:quentin).update_attributes(:password => 'new password', :password_confirmation => 'new password')
+ User.authenticate('quentin', 'new password').should == users(:quentin)
end
it 'does not rehash password' do
- <%= table_name %>(:quentin).update_attributes(:login => 'quentin2')
- <%= class_name %>.authenticate('quentin2', 'monkey').should == <%= table_name %>(:quentin)
+ users(:quentin).update_attributes(:login => 'quentin2')
+ User.authenticate('quentin2', 'monkey').should == users(:quentin)
end
#
# Authentication
#
- it 'authenticates <%= file_name %>' do
- <%= class_name %>.authenticate('quentin', 'monkey').should == <%= table_name %>(:quentin)
+ it 'authenticates user' do
+ User.authenticate('quentin', 'monkey').should == users(:quentin)
end
- it "doesn't authenticate <%= file_name %> with bad password" do
- <%= class_name %>.authenticate('quentin', 'invalid_password').should be_nil
+ it "doesn't authenticate user with bad password" do
+ User.authenticate('quentin', 'invalid_password').should be_nil
end
if REST_AUTH_SITE_KEY.blank?
# old-school passwords
it "authenticates a user against a hard-coded old-style password" do
- <%= class_name %>.authenticate('old_password_holder', 'test').should == <%= table_name %>(:old_password_holder)
+ User.authenticate('old_password_holder', 'test').should == users(:old_password_holder)
end
else
it "doesn't authenticate a user against a hard-coded old-style password" do
- <%= class_name %>.authenticate('old_password_holder', 'test').should be_nil
+ User.authenticate('old_password_holder', 'test').should be_nil
end
# New installs should bump this up and set REST_AUTH_DIGEST_STRETCHES to give a 10ms encrypt time or so
desired_encryption_expensiveness_ms = 0.1
it "takes longer than #{desired_encryption_expensiveness_ms}ms to encrypt a password" do
test_reps = 100
- start_time = Time.now; test_reps.times{ <%= class_name %>.authenticate('quentin', 'monkey'+rand.to_s) }; end_time = Time.now
+ start_time = Time.now; test_reps.times{ User.authenticate('quentin', 'monkey'+rand.to_s) }; end_time = Time.now
auth_time_ms = 1000 * (end_time - start_time)/test_reps
auth_time_ms.should > desired_encryption_expensiveness_ms
end
@@ -192,99 +180,48 @@
#
it 'sets remember token' do
- <%= table_name %>(:quentin).remember_me
- <%= table_name %>(:quentin).remember_token.should_not be_nil
- <%= table_name %>(:quentin).remember_token_expires_at.should_not be_nil
+ users(:quentin).remember_me
+ users(:quentin).remember_token.should_not be_nil
+ users(:quentin).remember_token_expires_at.should_not be_nil
end
it 'unsets remember token' do
- <%= table_name %>(:quentin).remember_me
- <%= table_name %>(:quentin).remember_token.should_not be_nil
- <%= table_name %>(:quentin).forget_me
- <%= table_name %>(:quentin).remember_token.should be_nil
+ users(:quentin).remember_me
+ users(:quentin).remember_token.should_not be_nil
+ users(:quentin).forget_me
+ users(:quentin).remember_token.should be_nil
end
it 'remembers me for one week' do
before = 1.week.from_now.utc
- <%= table_name %>(:quentin).remember_me_for 1.week
+ users(:quentin).remember_me_for 1.week
after = 1.week.from_now.utc
- <%= table_name %>(:quentin).remember_token.should_not be_nil
- <%= table_name %>(:quentin).remember_token_expires_at.should_not be_nil
- <%= table_name %>(:quentin).remember_token_expires_at.between?(before, after).should be_true
+ users(:quentin).remember_token.should_not be_nil
+ users(:quentin).remember_token_expires_at.should_not be_nil
+ users(:quentin).remember_token_expires_at.between?(before, after).should be_true
end
it 'remembers me until one week' do
time = 1.week.from_now.utc
- <%= table_name %>(:quentin).remember_me_until time
- <%= table_name %>(:quentin).remember_token.should_not be_nil
- <%= table_name %>(:quentin).remember_token_expires_at.should_not be_nil
- <%= table_name %>(:quentin).remember_token_expires_at.should == time
+ users(:quentin).remember_me_until time
+ users(:quentin).remember_token.should_not be_nil
+ users(:quentin).remember_token_expires_at.should_not be_nil
+ users(:quentin).remember_token_expires_at.should == time
end
it 'remembers me default two weeks' do
before = 2.weeks.from_now.utc
- <%= table_name %>(:quentin).remember_me
+ users(:quentin).remember_me
after = 2.weeks.from_now.utc
- <%= table_name %>(:quentin).remember_token.should_not be_nil
- <%= table_name %>(:quentin).remember_token_expires_at.should_not be_nil
- <%= table_name %>(:quentin).remember_token_expires_at.between?(before, after).should be_true
- end
-<% if options[:stateful] %>
- it 'registers passive <%= file_name %>' do
- <%= file_name %> = create_<%= file_name %>(:password => nil, :password_confirmation => nil)
- <%= file_name %>.should be_passive
- <%= file_name %>.update_attributes(:password => 'new password', :password_confirmation => 'new password')
- <%= file_name %>.register!
- <%= file_name %>.should be_pending
- end
-
- it 'suspends <%= file_name %>' do
- <%= table_name %>(:quentin).suspend!
- <%= table_name %>(:quentin).should be_suspended
- end
-
- it 'does not authenticate suspended <%= file_name %>' do
- <%= table_name %>(:quentin).suspend!
- <%= class_name %>.authenticate('quentin', 'monkey').should_not == <%= table_name %>(:quentin)
- end
-
- it 'deletes <%= file_name %>' do
- <%= table_name %>(:quentin).deleted_at.should be_nil
- <%= table_name %>(:quentin).delete!
- <%= table_name %>(:quentin).deleted_at.should_not be_nil
- <%= table_name %>(:quentin).should be_deleted
+ users(:quentin).remember_token.should_not be_nil
+ users(:quentin).remember_token_expires_at.should_not be_nil
+ users(:quentin).remember_token_expires_at.between?(before, after).should be_true
end
- describe "being unsuspended" do
- fixtures :<%= table_name %>
-
- before do
- @<%= file_name %> = <%= table_name %>(:quentin)
- @<%= file_name %>.suspend!
- end
-
- it 'reverts to active state' do
- @<%= file_name %>.unsuspend!
- @<%= file_name %>.should be_active
- end
-
- it 'reverts to passive state if activation_code and activated_at are nil' do
- <%= class_name %>.update_all :activation_code => nil, :activated_at => nil
- @<%= file_name %>.reload.unsuspend!
- @<%= file_name %>.should be_passive
- end
-
- it 'reverts to pending state if activation_code is set and activated_at is nil' do
- <%= class_name %>.update_all :activation_code => 'foo-bar', :activated_at => nil
- @<%= file_name %>.reload.unsuspend!
- @<%= file_name %>.should be_pending
- end
- end
-<% end %>
protected
- def create_<%= file_name %>(options = {})
- record = <%= class_name %>.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire69', :password_confirmation => 'quire69' }.merge(options))
- record.<% if options[:stateful] %>register! if record.valid?<% else %>save<% end %>
+ def create_user(options = {})
+ record = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire69', :password_confirmation => 'quire69' }.merge(options))
+ record.save
record
end
end

0 comments on commit a2f6699

Please sign in to comment.
Something went wrong with that request. Please try again.