From 487802dee7e4589c02c171c0b24c795f5a1a71f2 Mon Sep 17 00:00:00 2001 From: jwollert Date: Fri, 15 Mar 2013 14:04:08 +0100 Subject: [PATCH] migrate longer logins plugin to core --- app/models/user.rb | 2 +- ...0130315124655_add_longer_login_to_users.rb | 13 +++++++ spec/models/user_spec.rb | 35 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20130315124655_add_longer_login_to_users.rb diff --git a/app/models/user.rb b/app/models/user.rb index a6a3c2cc8b..312b36e210 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -99,7 +99,7 @@ class User < Principal validates_uniqueness_of :mail, :allow_blank => true, :case_sensitive => false # Login must contain lettres, numbers, underscores only validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i - validates_length_of :login, :maximum => 30 + validates_length_of :login, :maximum => 256 validates_length_of :firstname, :lastname, :maximum => 30 validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_blank => true validates_length_of :mail, :maximum => 60, :allow_nil => true diff --git a/db/migrate/20130315124655_add_longer_login_to_users.rb b/db/migrate/20130315124655_add_longer_login_to_users.rb new file mode 100644 index 0000000000..3477936df1 --- /dev/null +++ b/db/migrate/20130315124655_add_longer_login_to_users.rb @@ -0,0 +1,13 @@ +class AddLongerLoginToUsers < ActiveRecord::Migration + def self.up + change_table :users do |t| + t.change "login", :string, :limit => 256, :default => "", :null => false + end + end + + def self.down + change_table :users do |t| + t.change "login", :string, :limit => 30, :default => "", :null => false + end + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 151a5a7609..4e1509f966 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -13,6 +13,41 @@ describe User do :project => project, :status => issue_status) } + + + describe 'a user with a long login (<= 256 chars)' do + it 'is valid' do + user.login = 'a' * 256 + user.should be_valid + end + + it 'may be stored in the database' do + user.login = 'a' * 256 + user.save.should be_true + end + + it 'may be loaded from the database' do + user.login = 'a' * 256 + user.save + + User.find_by_login('a' * 256).should == user + end + end + + describe 'a user with and overly long login (> 256 chars)' do + it 'is invalid' do + user.login = 'a' * 257 + user.should_not be_valid + end + + it 'may not be stored in the database' do + user.login = 'a' * 257 + user.save.should be_false + end + + end + + describe :assigned_issues do before do user.save!