Skip to content
Extraits de code Groupes Projets
users_controller_spec.rb 3,95 ko
Newer Older
  • Learn to ignore specific revisions
  • #   Copyright (c) 2010, Diaspora Inc.  This file is
    
    Raphael's avatar
    Raphael a validé
    #   licensed under the Affero General Public License version 3 or later.  See
    
    #   the COPYRIGHT file.
    
    require 'spec_helper'
    
    describe UsersController do
      before do
    
        @user = alice
        @aspect = @user.aspects.first
    
        @aspect1 = @user.aspects.create(:name => "super!!")
    
        sign_in :user, @user
    
      describe '#export' do
    
        it 'returns an xml file'  do
    
          get :export
          response.header["Content-Type"].should include "application/xml"
        end
      end
    
    
      describe '#export_photos' do
        it 'returns a tar file'  do
          get :export_photos
          response.header["Content-Type"].should include "application/octet-stream"
        end
      end
    
    
        it 'renders xml if atom is requested' do
    
          sm = Factory(:status_message, :public => true, :author => @user.person)
    
          get :public, :username => @user.username, :format => :atom
    
    Raphael Sofaer's avatar
    Raphael Sofaer a validé
          response.body.should include(sm.text)
    
    
        it 'redirects to a profile page if html is requested' do
    
          get :public, :username => @user.username
          response.should be_redirect
        end
    
        before do
          @params  = { :id => @user.id,
    
                      :user => { :diaspora_handle => "notreal@stuff.com" } }
    
        it "doesn't overwrite random attributes" do
    
          }.should_not change(@user, :diaspora_handle)
    
        it 'redirects to the user edit page' do
          put :update, @params
    
          response.should redirect_to edit_user_path
    
    Raphael Sofaer's avatar
    Raphael Sofaer a validé
        it 'responds with a 204 on a js request' do
    
          put :update, @params.merge(:format => :js)
    
    Raphael Sofaer's avatar
    Raphael Sofaer a validé
          response.status.should == 204
    
        context 'password updates' do
    
          before do
            @password_params = {:current_password => 'bluepin7',
                                :password => "foobaz",
                                :password_confirmation => "foobaz"}
    
          it "uses devise's update with password" do
            @user.should_receive(:update_with_password).with(hash_including(@password_params))
            @controller.stub!(:current_user).and_return(@user)
            put :update, :id => @user.id, :user => @password_params
    
          it 'allow the user to change his language' do
            old_language = 'en'
    
            @user.language = old_language
            @user.save
            put(:update, :id => @user.id, :user =>
    
                { :language => "fr"}
               )
    
            @user.reload
            @user.language.should_not == old_language
    
    
        describe 'email settings' do
          it 'lets the user turn off mail' do
            par = {:id => @user.id, :user => {:email_preferences => {'mentioned' => 'true'}}}
            proc{
              put :update, par
            }.should change(@user.user_preferences, :count).by(1)
          end
    
          it 'lets the user get mail again' do
            @user.user_preferences.create(:email_type => 'mentioned')
            par = {:id => @user.id, :user => {:email_preferences => {'mentioned' => 'false'}}}
            proc{
              put :update, par
            }.should change(@user.user_preferences, :count).by(-1)
          end
        end
    
    
      describe '#edit' do
        it "returns a 200" do
    
          get 'edit', :id => @user.id
    
          response.status.should == 200
    
    maxwell's avatar
    maxwell a validé
    
        it 'set @email_pref to false when there is a user pref' do
          @user.user_preferences.create(:email_type => 'mentioned')
          get 'edit', :id => @user.id
          assigns[:email_prefs]['mentioned'].should be_false
        end
    
    
        it 'does not allow token auth' do
          sign_out :user
          bob.reset_authentication_token!
          get :edit, :auth_token => bob.authentication_token
          response.should redirect_to new_user_session_path
        end
    
    
      describe '#destroy' do
        it 'enqueues a delete job' do
          Resque.should_receive(:enqueue).with(Job::DeleteAccount, alice.id)
          delete :destroy
        end
        it 'locks the user out' do
          delete :destroy
          alice.reload.access_locked?.should be_true
        end
      end