Skip to content
Extraits de code Groupes Projets
aspects_controller_spec.rb 1,81 ko
Newer Older
Raphael's avatar
Raphael a validé
#   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
Raphael's avatar
Raphael a validé
#   the COPYRIGHT file.
require 'spec_helper'
Raphael's avatar
Raphael a validé
describe AspectsController do
    @user    = Factory.create(:user)
    @aspect  = @user.aspect(:name => "lame-os")
    @person  = Factory.create(:person)
Jamie Wilkinson's avatar
Jamie Wilkinson a validé
    sign_in :user, @user
  describe "#index" do
    it "assigns @friends to all the user's friends" do
      Factory.create :person
      get :index
      assigns[:friends].should == @user.friends
    end
  describe "#create" do
    describe "with valid params" do
      it "creates an aspect" do
        @user.aspects.count.should == 1
        post :create, "aspect" => {"name" => "new aspect"}
        @user.reload.aspects.count.should == 2
      end
      it "redirects to the aspect page" do
        post :create, "aspect" => {"name" => "new aspect"}
        response.should redirect_to(aspect_path(Aspect.find_by_name("new aspect")))
      end
    end
    describe "with invalid params" do
      it "does not create an aspect" do
        @user.aspects.count.should == 1
        post :create, "aspect" => {"name" => ""}
        @user.reload.aspects.count.should == 1
      end
      it "goes back to manage aspects" do
        post :create, "aspect" => {"name" => ""}
        response.should redirect_to(aspects_manage_path)
      end
    end
  end

  describe "#move_friend" do
    let(:opts) { {:friend_id => "person_id", :from => "from_aspect_id", :to => {:to => "to_aspect_id"}}}
    it 'calls the move_friend_method' do
      pending "need to figure out how to stub current_user to return our test @user"
      @user.should_receive(:move_friend).with( :friend_id => "person_id", :from => "from_aspect_id", :to => "to_aspect_id")
      post :move_friend, opts
    end
  end