1 require File.dirname(__FILE__) + "/../../spec_helper"
3 describe Admin::UserController do
9 it "should inherit from the abastract model controller" do
10 Admin::UserController.ancestors.should include(Admin::AbstractModelController)
13 [:index, :new, :edit, :remove, :preferences].each do |action|
14 it "should require you to login in order to access #{action}" do
15 lambda { get action }.should require_login
19 [:index, :new, :edit, :remove].each do |action|
20 it "should allow you to access to #{action} action if you are an admin" do
21 lambda { get action, :id => user_id(:existing) }.should restrict_access(:allow => users(:admin))
24 it "should deny you access to #{action} action if you are not an admin" do
25 lambda { get action, :id => user_id(:existing) }.should restrict_access(:deny => [users(:developer), users(:existing)])
29 it "should not allow you to delete yourself" do
32 get :remove, { :id => user.id }
33 response.should redirect_to(user_index_url)
34 flash[:error].should match(/cannot.*self/i)
35 User.find(user.id).should_not be_nil
38 it "should allow you to view your preferences" do
39 user = login_as(:non_admin)
40 get :preferences, :user => { :email => 'updated@email.com' }
41 response.should be_success
42 assigned_user = assigns(:user)
43 assigned_user.should == user
44 assigned_user.object_id.should_not == user.object_id
45 assigned_user.email.should == 'non_admin@example.com'
47 it "should allow you to save your preferences" do
49 post :preferences, :user => { :password => '', :password_confirmation => '', :email => 'updated@gmail.com' }
50 user = users(:non_admin)
51 response.should redirect_to(page_index_url)
52 flash[:notice].should match(/preferences.*?saved/i)
53 user.email.should == 'updated@gmail.com'
55 it "should not allow you to update your login through the preferences page" do
57 get :preferences, 'user' => { :login => 'superman' }
58 response.should be_success
59 flash[:error].should match(/bad form data/i)
62 it "should allow you to change your password" do
64 post :preferences, { :user => { :password => 'funtimes', :password_confirmation => 'funtimes' } }
65 user = users(:non_admin)
66 user.password.should == User.sha1('funtimes')
68 rails_log.should_not match(/"password"=>"funtimes"/)
69 rails_log.should_not match(/"password_confirmation"=>"funtimes"/)