Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / radiant_specs / spec / controllers / admin / .svn / text-base / user_controller_spec.rb.svn-base
blob53f8ebd23ceb60646502f7e4d9f441f65b37a49b
1 require File.dirname(__FILE__) + "/../../spec_helper"
3 describe Admin::UserController do
4   scenario :users
5   test_helper :logging
6   
7   integrate_views
8   
9   it "should inherit from the abastract model controller" do
10     Admin::UserController.ancestors.should include(Admin::AbstractModelController)
11   end
12   
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
16     end
17   end
18   
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))
22     end
23     
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)])
26     end
27   end
28   
29   it "should not allow you to delete yourself" do
30     user = users(:admin)
31     login_as user
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
36   end
37   
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'
46   end
47   it "should allow you to save your preferences" do
48     login_as :non_admin
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'
54   end
55   it "should not allow you to update your login through the preferences page" do
56     login_as :non_admin
57     get :preferences, 'user' => { :login => 'superman' }
58     response.should be_success
59     flash[:error].should match(/bad form data/i)
60   end
61   
62   it "should allow you to change your password" do
63     login_as :non_admin
64     post :preferences, { :user => { :password => 'funtimes', :password_confirmation => 'funtimes' } }
65     user = users(:non_admin)
66     user.password.should == User.sha1('funtimes')
67     
68     rails_log.should_not match(/"password"=>"funtimes"/)
69     rails_log.should_not match(/"password_confirmation"=>"funtimes"/)
70   end
71   
72 end