Attr-accessible on aspects, check whether built user is persisted

This commit is contained in:
Raphael 2010-10-21 12:49:50 -07:00
parent 705cef3696
commit fe1a6bce20
5 changed files with 14 additions and 13 deletions

View file

@ -73,8 +73,7 @@ class AspectsController < ApplicationController
def update
@aspect = current_user.aspect_by_id(params[:id])
data = clean_hash(params[:aspect])
@aspect.update_attributes( data )
@aspect.update_attributes( params[:aspect] )
flash[:notice] = I18n.t 'aspects.update.success',:name => @aspect.name
respond_with @aspect
end

View file

@ -18,6 +18,7 @@ class Aspect
validates_presence_of :name
validates_uniqueness_of :name, :scope => :user_id
attr_accessible :name
timestamps!

View file

@ -92,8 +92,10 @@ class User
######### Aspects ######################
def aspect(opts = {})
opts[:user] = self
Aspect.create(opts)
aspect = Aspect.new(opts)
aspect.user = self
aspect.save
aspect
end
def drop_aspect(aspect)

View file

@ -18,29 +18,27 @@ describe Aspect do
let(:aspect3) {user3.aspect(:name => "lala")}
describe 'creation' do
let(:aspect){user.aspect(:name => 'losers')}
it 'should have a name' do
aspect = user.aspect(:name => 'losers')
aspect.name.should == "losers"
end
it 'should be creatable with people' do
it 'should not be creatable with people' do
aspect = user.aspect(:name => 'losers', :people => [friend, friend_2])
aspect.people.size.should == 2
aspect.people.size.should == 0
end
it 'should be able to have other users' do
aspect = user.aspect(:name => 'losers', :people => [user2.person])
aspect.people << user2.person
aspect.people.include?(user.person).should be false
aspect.people.include?(user2.person).should be true
aspect.people.size.should == 1
end
it 'should be able to have users and people' do
aspect = user.aspect(:name => 'losers', :people => [user2.person, friend_2])
aspect.people.include?(user.person).should be false
aspect.people.include?(user2.person).should be true
aspect.people.include?(friend_2).should be true
aspect.people.size.should == 2
aspect.people << user2.person
aspect.people << friend_2
aspect.save.should be_true
end
end

View file

@ -103,6 +103,7 @@ describe User do
end
it "makes a valid user" do
@user.should be_valid
@user.persisted?.should be_false
User.find_by_username("ohai").should be_nil
end
it 'saves successfully' do