Skip to content
Extraits de code Groupes Projets
users_controller_spec.rb 2,92 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 = Factory.create(:user)
        sign_in :user, @user
        @user.aspect(:name => "lame-os")
      end
    
    
      describe '#export' do
        it 'should return an xml file'  do
          get :export
          response.header["Content-Type"].should include "application/xml"
        end
      end
    
    
    
      describe '#update' do
        context 'with a profile photo set' do
          before do
            @user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg"
            @user.person.profile.save
    
            
            @params = {"profile"=>
              {"image_url"   => "",
                "last_name"  => @user.person.profile.last_name,
                "first_name" => @user.person.profile.first_name}}
    
          end
    
          it "doesn't overwrite the profile photo when an empty string is passed in" do
            image_url = @user.person.profile.image_url
    
            put("update", :id => @user.id, "user" => @params)
    
    Raphael's avatar
    Raphael a validé
    
    
            @user.person.profile.image_url.should == image_url
          end
    
          it "doesn't overwrite random attributes" do
            new_user = Factory.create(:user)
            @params[:owner_id] = new_user.id
            person = @user.person
            put('update', :id => @user.id, "user" => @params)
            Person.find(person.id).owner_id.should == @user.id
          end
    
        end
    
        context 'should allow the user to update their password' do
          it 'should change a users password ' do
            old_password = @user.encrypted_password
    
    
    Raphael's avatar
    Raphael a validé
            put("update", :id => @user.id, "user"=> {"password" => "foobaz", 'password_confirmation' => "foobaz","profile"=>
    
                {"image_url"   => "",
                "last_name"  => @user.person.profile.last_name,
    
    Raphael's avatar
    Raphael a validé
                "first_name" => @user.person.profile.first_name}})
    
    
            @user.reload
            @user.encrypted_password.should_not == old_password
          end
    
    Raphael's avatar
    Raphael a validé
          it 'should not change a password if they do not match' do
            old_password = @user.encrypted_password
            put("update", :id => @user.id, "user"=> {"password" => "foobarz", 'password_confirmation' => "not_the_same","profile"=>
    
                {"image_url"   => "",
                "last_name"  => @user.person.profile.last_name,
    
    Raphael's avatar
    Raphael a validé
                "first_name" => @user.person.profile.first_name}})
    
              @user.reload
              @user.encrypted_password.should == old_password
          end
    
    
    Raphael's avatar
    Raphael a validé
    
          it 'should not update if the password fields are left blank' do
    
              old_password = @user.encrypted_password
              put("update", :id => @user.id, "user"=> {"password" => "", 'password_confirmation' => "","profile"=>
    
                  {"image_url"   => "",
                  "last_name"  => @user.person.profile.last_name,
    
    Raphael's avatar
    Raphael a validé
                  "first_name" => @user.person.profile.first_name}})
    
                @user.reload
                @user.encrypted_password.should == old_password
          end