add validation which prevent user for signing up with dead username. fix cucumber features

This commit is contained in:
Maxwell Salzberg 2011-10-20 15:56:44 -07:00
parent 34816f3a7f
commit 484f46d70f
6 changed files with 44 additions and 30 deletions

View file

@ -28,6 +28,7 @@ class User < ActiveRecord::Base
validates_presence_of :person, :unless => proc {|user| user.invitation_token.present?}
validates_associated :person
validate :no_person_with_same_username
has_one :person, :foreign_key => :owner_id
delegate :public_key, :posts, :photos, :owns?, :diaspora_handle, :name, :public_url, :profile, :first_name, :last_name, :to => :person
@ -471,4 +472,11 @@ class User < ActiveRecord::Base
self.email = self.invitation_identifier if self.invitation_service == 'email'
self
end
def no_person_with_same_username
diaspora_id = "#{self.username}@#{AppConfig[:pod_uri].host}"
if self.username_changed? && Person.exists?(:diaspora_handle => diaspora_id)
errors[:base] << 'That username has already been taken'
end
end
end

View file

@ -1,11 +1,12 @@
%form{:action => "https://www.paypal.com/cgi-bin/webscr", :method => "post"}
%input{:name => "cmd", :type => "hidden", :value => "_s-xclick"}
%input{:name => "hosted_button_id", :type => "hidden", :value => AppConfig[:paypal_hosted_button_id]}
%input{:name => "on0", :type => "hidden", :value => "Type"}
%input{:name => "modify", :type => "hidden", :value => "2"}
%select{:name => "os0"}
%option{:value => "Mocha"} Mocha : $3.00USD
%option{:value => "Americano"} Americano : $5.00USD
%option{:value => "Box o' Joe"} Box o' Joe : $20.00USD
%input{:name => "currency_code", :type => "hidden", :value => "USD"}
-# %form{:action => "https://www.paypal.com/cgi-bin/webscr", :method => "post"}
%form{:action => "https://www.diasporafoundation.org/donate", :method => "get"}
-# %input{:name => "cmd", :type => "hidden", :value => "_s-xclick"}
-# %input{:name => "hosted_button_id", :type => "hidden", :value => AppConfig[:paypal_hosted_button_id]}
-# %input{:name => "on0", :type => "hidden", :value => "Type"}
-# %input{:name => "modify", :type => "hidden", :value => "2"}
%select{:name => "monthly_amount"}
%option{:value => "1"} Supporter : $5.00USD
%option{:value => "2"} Member : $10.00USD
%option{:value => "3"} Freedom Fighter : $20.00USD
-# %input{:name => "currency_code", :type => "hidden", :value => "USD"}
%input{:name => "submit", :type => "submit", :value => t('aspects.index.donate')}

View file

@ -77,15 +77,13 @@
.content#community_spotlight
= link_to t('aspects.index.see_more_from_us'), spotlight_path, :id => 'view_all_contacts_link'
- unless AppConfig[:paypal_hosted_button_id].blank?
.section
.title
= image_tag('/images/icons/coffee.png')
%h5
= t('aspects.index.donate')
.content
= t('aspects.index.keep_us_running', :pod => URI.parse(AppConfig[:pod_url]).host)
%br
= render 'shared/donate'
.section
.title
= image_tag('/images/icons/coffee.png')
%h5
= t('aspects.index.donate')
.content
= t('aspects.index.keep_us_running', :pod => URI.parse(AppConfig[:pod_url]).host)
%br
= render 'shared/donate'

View file

@ -4,10 +4,10 @@ Feature: invitation acceptance
Given I have been invited by an admin
And I am on my acceptance form page
And I fill in the following:
| Username | ohai |
| Email | woot@sweet.com |
| user_username | ohai |
| user_email | woot@sweet.com |
| user_password | secret |
| Password confirmation | secret |
| user_password_confirmation | secret |
And I press "Create my account"
Then I should be on the getting started page
And I should see "Welcome"
@ -28,10 +28,10 @@ Feature: invitation acceptance
Given I have been invited by a user
And I am on my acceptance form page
And I fill in the following:
| Username | ohai |
| Email | woot@sweet.com |
| user_username | ohai |
| user_email | woot@sweet.com |
| user_password | secret |
| Password confirmation | secret |
| user_password_confirmation | secret |
And I press "Create my account"
Then I should be on the getting started page
And I should see "Welcome"

View file

@ -3,10 +3,10 @@ Feature: new user registration
Background:
When I go to the new user registration page
And I fill in "Username" with "ohai"
And I fill in "Email" with "ohai@example.com"
And I fill in "user_username" with "ohai"
And I fill in "user_email" with "ohai@example.com"
And I fill in "user_password" with "secret"
And I fill in "Password confirmation" with "secret"
And I fill in "user_password_confirmation" with "secret"
And I press "Create my account"
Then I should be on the getting started page
And I should see "Welcome"

View file

@ -110,6 +110,13 @@ describe User do
alice.should_not be_valid
end
it 'requires uniqueness also amount Person objects with diaspora handle' do
p = Factory(:person, :diaspora_handle => "jimmy@#{AppConfig[:pod_uri].host}")
alice.username = 'jimmy'
alice.should_not be_valid
end
it "downcases username" do
user = Factory.build(:user, :username => "WeIrDcAsE")
user.should be_valid