spec/models/user_invitation_spec.rb in iugusdk-1.0.0.alpha.1 vs spec/models/user_invitation_spec.rb in iugusdk-1.0.0.alpha.2

- old
+ new

@@ -2,12 +2,20 @@ describe UserInvitation do it { should belong_to :account } - context "before save" do + it 'should not accept an email already used by an account user' do + @account = Fabricate(:account) + @user = Fabricate(:user, :email => "invited@test.test") + @account.users << @user + @user_invitation = UserInvitation.new(:email => "invited@test.test", :account_id => @account.id) + @user_invitation.should_not be_valid + end + context "before save" do + context "if has no token" do it 'should generate one' do @user_invitation = UserInvitation.new(:email => "test@test.test", :roles => "user") @user_invitation.save @user_invitation.token.should_not be_nil @@ -79,9 +87,23 @@ @user_invitation.roles =(["user", "guest"].join(',')) @user_invitation.save @user_invitation.accept(@user) AccountUser.last.is?('user').should be_true end + + it 'should return true if successfull' do + @user_invitation.account = @account + @user_invitation.save + @user_invitation.accept(@user).should be_true + end + + it 'should return false if user is already member of the account' do + @user_invitation.account = @account + @user_invitation.save + @account.users << @user + @user_invitation.accept(@user).should be_false + end + end end