diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index f935d78..a2b5f9e 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -57,7 +57,6 @@ class AccountController < ApplicationController @terms_of_use = environment.terms_of_use @user.person_data = params[:profile_data] @person = Person.new(params[:profile_data]) - @person.name = @user.login @person.environment = @user.environment if request.post? && params[self.icaptcha_field].blank? @user.signup! diff --git a/app/models/person.rb b/app/models/person.rb index 02fc976..5d5a197 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -184,14 +184,6 @@ class Person < Profile ] end - def name - if !self[:name].blank? - self[:name] - else - self.user ? self.user.login : nil - end - end - has_and_belongs_to_many :favorite_enterprises, :class_name => 'Enterprise', :join_table => 'favorite_enteprises_people' def email_domain diff --git a/app/views/profile_editor/_person_form.rhtml b/app/views/profile_editor/_person_form.rhtml index b178e0c..0821c40 100644 --- a/app/views/profile_editor/_person_form.rhtml +++ b/app/views/profile_editor/_person_form.rhtml @@ -1,6 +1,6 @@ <% @person ||= @profile %> -<%= required labelled_form_field(_('Full name'), text_field(:profile_data, :name)) %> +<%= required f.text_field(:name) %> <% optional_field(@person, 'nickname') do %> <%= f.text_field(:nickname, :maxlength => 16, :size => 30) %> diff --git a/db/migrate/079_fix_people_without_names.rb b/db/migrate/079_fix_people_without_names.rb new file mode 100644 index 0000000..e1f4f18 --- /dev/null +++ b/db/migrate/079_fix_people_without_names.rb @@ -0,0 +1,11 @@ +class FixPeopleWithoutNames < ActiveRecord::Migration + def self.up + select_all("SELECT name, identifier FROM profiles WHERE name = '' or name IS NULL").each do |profile| + update("UPDATE profiles SET name = '%s' WHERE identifier = '%s'" % [profile['identifier'], profile['identifier']]) + end + end + + def self.down + say("Nothing to undo (cannot recover the data)") + end +end diff --git a/db/schema.rb b/db/schema.rb index bf6c347..6202cf8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 78) do +ActiveRecord::Schema.define(:version => 79) do create_table "article_versions", :force => true do |t| t.integer "article_id" diff --git a/features/join_community.feature b/features/join_community.feature index 8c3e35d..7687292 100644 --- a/features/join_community.feature +++ b/features/join_community.feature @@ -53,7 +53,7 @@ Feature: join a community | Username | joseoliveira | | Password | 123456 | | Password confirmation | 123456 | - | Full name | Jose Oliveira | + | Name | Jose Oliveira | And I press "Sign up" And I should see "Are you sure you want to join Sample Community?" When I press "Yes, I want to join" diff --git a/features/signup.feature b/features/signup.feature index bf28017..9bac886 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -11,7 +11,7 @@ Feature: signup And I fill in "Username" with "josesilva" And I fill in "Password" with "secret" And I fill in "Password confirmation" with "secret" - And I fill in "Full name" with "José da Silva" + And I fill in "Name" with "José da Silva" And I press "Sign up" Then I should see "Thanks for signing up!" @@ -22,3 +22,25 @@ Feature: signup Given I am logged in as "joaosilva" And I go to signup page Then I should be on Joao Silva's control panel + + Scenario: user cannot register without a name + Given I am on the homepage + And I follow "Login" + And I follow "I want to participate" + And I fill in "e-Mail" with "josesilva@example.com" + And I fill in "Username" with "josesilva" + And I fill in "Password" with "secret" + And I fill in "Password confirmation" with "secret" + And I press "Sign up" + Then I should see "Name can't be blank" + + Scenario: user cannot change his name to empty string + Given the following users + | login | name | + | joaosilva | Joao Silva | + Given I am logged in as "joaosilva" + And I am on Joao Silva's control panel + And I follow "Profile Info and settings" + And I fill in "Name" with "" + When I press "Save" + Then I should see "Name can't be blank" diff --git a/test/factories.rb b/test/factories.rb index 39be342..b67b52a 100644 --- a/test/factories.rb +++ b/test/factories.rb @@ -94,7 +94,7 @@ module Noosfero::Factory :environment_id => environment_id, }.merge(options) user = fast_insert_with_timestamps(User, data) - person = fast_insert_with_timestamps(Person, { :type => 'Person', :identifier => name, :user_id => user.id, :environment_id => environment_id }.merge(person_options)) + person = fast_insert_with_timestamps(Person, { :type => 'Person', :identifier => name, :name => name, :user_id => user.id, :environment_id => environment_id }.merge(person_options)) homepage = fast_insert_with_timestamps(TextileArticle, { :type => 'TextileArticle', :name => 'homepage', :slug => 'homepage', :path => 'homepage', :profile_id => person.id }) fast_update(person, {:home_page_id => homepage.id}) box = fast_insert(Box, { :owner_type => "Profile", :owner_id => person.id, :position => 1}) diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 91e030b..00b8c1a 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -270,18 +270,6 @@ class PersonTest < Test::Unit::TestCase assert_equal 'José', p.name end - should 'fallback to login when person_info is not present' do - p = create_user('randomhacker').person - p.name = nil - assert_equal 'randomhacker', p.name - end - - should 'fallback to login when name is blank' do - p = create_user('randomhacker').person - p.name = '' - assert_equal 'randomhacker', p.name - end - should 'have favorite enterprises' do p = create_user('test_person').person e = Enterprise.create!(:name => 'test_ent', :identifier => 'test_ent') -- libgit2 0.21.2