salex/rails3-Devise-BCSD-Can-Invite — Issue #10: Is the if !Account::CAN_SIGN_UP on create_account method in user.rb correct?
Author: cathalcurtis
Created: 2011-10-21 22:56:22+00:00
State: open

I'm a relatively new RoR developer so forgive me if I get this wrong.
I've been trying to create some RSpec test cases and I've an RSpec test that looks like this:

it "should allow minimum attr set" do
#create an account
account1 = Factory.create(:account)
user = User.new(:name => "name1",
:account_name => account1.name,
:email => "name1@example.com",
:password => "secret1")
user.account = account1
user.save
puts user.errors.full_messages.to_s if user.errors.any?

user.should be_valid
end

Note: Account::CAN_SIGN_UP equates to false (users must be invited to join an account)
So essentially, I've created an account using FactoryGirl, and I allocate a new User with the attributes above,
I hook up the account to the user and then save the user. No Problem it saves ok.
But the 'user.should be_valid' step fails when 'create_account' in user.rb contains:
self.account_name = "" if !Account::CAN_SIGN_UP
and the step passes when I change it to:
self.account_name = "" if Account::CAN_SIGN_UP

I can't follow the code well enough to be able to make a statement as to whether it should be
Account::CAN_SIGN_UP or !Account::CAN_SIGN_UP

I'd be grateful to know if this is an issue or not and if I do remove the '!' will I break other functionality?

Regards,
Cathal.