On 11/11/2010 01:25 PM, [email protected] wrote:
> From: Ladislav Martincik<[email protected]>
>
> - Fixing validations for User with maximum allowing blank
> - Merged 2 spec files for registration service to one file
> ---
>   src/app/models/user.rb                         |    5 +-
>   src/spec/models/registration_service_spec.rb   |   64 
> ------------------------
>   src/spec/services/registration_service_spec.rb |   37 ++++++++++++++
>   3 files changed, 39 insertions(+), 67 deletions(-)
>   delete mode 100644 src/spec/models/registration_service_spec.rb
>
> diff --git a/src/app/models/user.rb b/src/app/models/user.rb
> index aed6fe6..7942ae4 100644
> --- a/src/app/models/user.rb
> +++ b/src/app/models/user.rb
> @@ -28,9 +28,8 @@ class User<  ActiveRecord::Base
>     belongs_to :quota, :autosave =>  true
>     accepts_nested_attributes_for :quota
>
> -  validates_length_of   :first_name, :maximum =>  255
> -  validates_length_of   :last_name,  :maximum =>  255
> -
> +  validates_length_of :first_name, :maximum =>  255, :allow_blank =>  true
> +  validates_length_of :last_name,  :maximum =>  255, :allow_blank =>  true
>
>     # authlogic's password confirmation doesn't fire up when we fill in the
>     # confirmation field but leave the password field blank. We have to check
> diff --git a/src/spec/models/registration_service_spec.rb 
> b/src/spec/models/registration_service_spec.rb
> deleted file mode 100644
> index 2a97d11..0000000
> --- a/src/spec/models/registration_service_spec.rb
> +++ /dev/null
> @@ -1,64 +0,0 @@
> -require 'spec_helper'
> -
> -describe RegistrationService do
> -  fixtures :all
> -  before(:each) do
> -    @tuser = Factory :tuser
> -  end
> -
> -  it "should initialize a new instance given valid attributes" do
> -    RegistrationService.new(@tuser)
> -  end
> -
> -  describe "#save" do
> -
> -    context "adding valid user with no errors" do
> -      it "should create user, pool and self-service permission" do
> -        user = User.new({:login =>  'gooduser',
> -                        :email =>  '[email protected]',
> -                        :password =>  'password',
> -                        :password_confirmation =>  'password'})
> -        r = RegistrationService.new(user)
> -      end
> -    end
> -
> -    context "save fails" do
> -      it "should return errors on user when user is missing required field" 
> do
> -        user = User.new(:login =>  'baduser')
> -        r = RegistrationService.new(user)
> -        r.save.should be_false
> -        user.errors.empty?.should be_false
> -        user.errors.find_all {|attr,msg|
> -       ["email", "password",  "password_confirmation"].include?(attr).should 
> be_true
> -     }
> -      end
> -
> -      it "should return pool errors if pool create fails" do
> -        #TODO: implement this test.  We should check this, but not sure of 
> best
> -        # way right now.
> -      end
> -    end
> -  end
> -
> -  it "should register a user with default pool/quota/role when default 
> settings set" do
> -    @user = Factory :user
> -    @pool = Factory(:pool, :name =>  "default_pool")
> -    @role = Role.find_by_name("Instance Creator and User")
> -    @quota = Factory :quota
> -
> -    MetadataObject.set("allow_self_service_logins", "true")
> -    MetadataObject.set("self_service_default_pool", @pool)
> -    MetadataObject.set("self_service_default_role", @role)
> -    MetadataObject.set("self_service_default_quota", @quota)
> -
> -    @registration_service = RegistrationService.new(@user)
> -    @registration_service.save
> -
> -    @pools = Pool.list_for_user(@user, Privilege::INSTANCE_VIEW)
> -    @pools.size.should == 1
> -    @pools[0].name.should == "default_pool"
> -
> -    @user.quota.maximum_running_instances.should == 
> @quota.maximum_running_instances
> -    @user.quota.maximum_total_instances.should == 
> @quota.maximum_total_instances
> -  end
> -end
> diff --git a/src/spec/services/registration_service_spec.rb 
> b/src/spec/services/registration_service_spec.rb
> index 6764715..1d17ba2 100644
> --- a/src/spec/services/registration_service_spec.rb
> +++ b/src/spec/services/registration_service_spec.rb
> @@ -10,6 +10,43 @@ describe RegistrationService do
>       Factory.create(:default_pool_metadata)
>     end
>
> +  describe "with validations" do
> +
> +    it "should return errors on user when user is missing required fields" do
> +      user = User.new(:login =>  'baduser')
> +      r = RegistrationService.new(user)
> +      r.save.should be_false
> +      user.errors.empty?.should be_false
> +      user.errors.find_all do |attr,msg|
> +        ["email","password","password_confirmation"].include?(attr).should 
> be_true
> +      end
> +    end
> +
> +    it "should register a user with default pool/quota/role when default 
> settings set" do
> +      @user = Factory :user
> +      @pool = Factory(:pool, :name =>  "default_pool")
> +      privilege = Privilege.find_by_name('instance_view')
> +      @role = Factory(:role, :privileges =>  [privilege])
> +      @quota = Factory :quota
> +
> +      MetadataObject.set("allow_self_service_logins", "true")
> +      MetadataObject.set("self_service_default_pool", @pool)
> +      MetadataObject.set("self_service_default_role", @role)
> +      MetadataObject.set("self_service_default_quota", @quota)
> +
> +      @registration_service = RegistrationService.new(@user)
> +      @registration_service.save
> +
> +      @pools = Pool.list_for_user(@user, Privilege::INSTANCE_VIEW)
> +      @pools.length.should == 1
> +      @pools[0].name.should == "default_pool"
> +
> +      @user.quota.maximum_running_instances.should == 
> @quota.maximum_running_instances
> +      @user.quota.maximum_total_instances.should == 
> @quota.maximum_total_instances
> +    end
> +
> +  end
> +
>     describe "with quota" do
>
>       it "passed via nested attributes to user model" do

Unfortunately I'm getting this error:
1)
ActiveRecord::AssociationTypeMismatch in 'RegistrationService with 
validations should register a user with default pool/quota/role when 
default settings set'
Privilege(#70205803558460) expected, got NilClass(#70205837380540)
./spec/services/registration_service_spec.rb:27:

I think this problem is caused by changes pushed to next meantime. Also 
rebase is needed because allow_blank is already in next. Could you 
please send this patch again?

Jan
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to