Drop back to using User#name, and not User#forum_name

master
Zequez 2015-08-06 07:16:09 -03:00
parent 707592b25d
commit 3535575331
14 changed files with 87 additions and 110 deletions

View File

@ -48,7 +48,7 @@ class ApplicationController < ActionController::Base
end
def configure_devise_permitted_parameters
devise_parameter_sanitizer.for(:sign_up).push(:email, :forum_name)
devise_parameter_sanitizer.for(:sign_up).push(:email, :name)
devise_parameter_sanitizer.for(:sign_in).push(:login)
devise_parameter_sanitizer.for(:account_update)
end

View File

@ -40,7 +40,7 @@ class ForumValidationsController < ApplicationController
redirect_to forum_validation_url(current_user.forum_validation)
end
else
@forum_validation.author = Author.find_for_forum_validation(current_user.forum_name)
@forum_validation.author = Author.find_for_forum_validation(current_user.name)
end
end

View File

@ -25,7 +25,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
# end
def after_sign_up_path_for(user)
if user.forum_name.present? and Author.find_for_forum_validation(user.forum_name)
if Author.find_for_forum_validation(user.name)
new_forum_validation_path
else
super(user)

View File

@ -18,6 +18,8 @@ class Author < ActiveRecord::Base
find_by_slug normalize_friendly_id(name)
end
# Since the author was autogenerated by scraping the forum,
# the forum_name == name
def self.find_for_forum_validation(forum_name)
where.not(forum_name: '').find_by_slugged_name(forum_name)
end

View File

@ -10,7 +10,7 @@ class User < ActiveRecord::Base
friendly_id :name, use: [:slugged, :finders]
auto_strip_attributes :forum_name, squish: true, nullify: false
auto_strip_attributes :name, squish: true, nullify: false
has_many :mods, dependent: :nullify, foreign_key: :author_id
has_many :owned_mods, class_name: 'Mod', foreign_key: :author_id, dependent: :nullify # We'll change it to User#owner_id eventually
@ -40,10 +40,10 @@ class User < ActiveRecord::Base
### Validations
#################
# validates :name, presence: true,
# format: { with: /\A[[:alnum:]\-_\. ]+\Z/i },
# uniqueness: { case_sensitive: false },
# length: { minimum: 2, maximum: 50 }
validates :name, presence: true,
format: { with: /\A[[:alnum:]\-_\. ]+\Z/i },
uniqueness: { case_sensitive: false },
length: { minimum: 2, maximum: 50 }
validates :forum_name, allow_blank: true, uniqueness: { case_sensitive: false }

View File

@ -20,7 +20,7 @@
= f.semantic_errors
= f.inputs do
= f.input :email
= f.input :forum_name
= f.input :name
= f.input :password
= f.input :remember_me, as: :boolean, required: false
= redirect_to_input(f)

View File

@ -70,7 +70,6 @@ en:
user:
login: Email
name: Username
forum_name: Factorio Forum account name
hints:
mod:
@ -82,8 +81,8 @@ en:
imgur: "For an individual picture, not and album"
mod_file:
download_url: "Please use this instead of the attachment when possible, specially for large files"
users:
forum_name: If there are any mods associated with the account, we'll transfer them to you
user:
name: Try to use the same as in the forum
placeholders:
mod:

View File

@ -155,7 +155,7 @@ describe ForumValidationsController, type: :controller do
context 'logged in user' do
it 'should just render the new form if it can be validated' do
author = create :author, forum_name: 'Potato', name: 'Potato'
sign_in create(:user, forum_name: 'Potato')
sign_in create(:user, name: 'Potato')
get :new
expect(assigns(:forum_validation).author).to eq author
expect(response).to render_template :new
@ -163,7 +163,7 @@ describe ForumValidationsController, type: :controller do
it 'should redirect to the root if the user is already validated' do
author = create :author, forum_name: 'Potato', name: 'Potato'
user = create :user, forum_name: 'Potato'
user = create :user, name: 'Potato'
create :forum_validation, author: author, user: user, validated: true
sign_in user
get :new
@ -172,7 +172,7 @@ describe ForumValidationsController, type: :controller do
it 'should redirect to the forum_validations#show if the user has a pending validation' do
author = create :author, forum_name: 'Potato', name: 'Potato'
user = create :user, forum_name: 'Potato'
user = create :user, name: 'Potato'
fv = create :forum_validation, author: author, user: user, validated: false
sign_in user
get :new
@ -183,7 +183,7 @@ describe ForumValidationsController, type: :controller do
context 'logged out user' do
it 'should redirect to login form' do
create :author, forum_name: 'Potato', name: 'Potato'
create :user, forum_name: 'Potato'
create :user, name: 'Potato'
get :new
expect(response).to have_http_status :redirect
expect(response.location).to match new_user_session_path

View File

@ -7,54 +7,37 @@ describe Users::RegistrationsController, type: :controller do
it 'should create a new user with valid parameters' do
post :create, user: {
email: 'potato@salad.com',
forum_name: 'Potato',
name: 'Potato',
password: '12345678',
password_confirmation: '12345678'
}
user = User.first
expect(user.email).to eq 'potato@salad.com'
expect(user.forum_name).to eq 'Potato'
expect(response).to redirect_to root_path
end
it 'should still create a new user without a forum name' do
post :create, user: {
email: 'potato@salad.com',
forum_name: '',
password: '12345678',
password_confirmation: '12345678'
}
user = User.first
expect(user.email).to eq 'potato@salad.com'
expect(user.forum_name).to eq ''
expect(user.name).to eq 'Potato'
expect(response).to redirect_to root_path
end
it 'should add errors to the user with invalid parameters' do
post :create, user: {
email: 'potatosalad.com',
forum_name: '',
password: '1278',
password_confirmation: '12345678'
name: '',
password: '1278'
}
expect(User.all).to be_empty
user = assigns(:user)
expect(user.errors[:email]).to_not be_empty
expect(user.errors[:forum_name]).to be_empty
expect(user.errors[:password]).to_not be_empty
expect(user.errors[:password_confirmation]).to_not be_empty
expect(response).to render_template :new
end
context 'the user used a forum_name associated with an author' do
context 'the user used a name associated with an author' do
it 'should redirect to forum_validations#new after creating the user' do
create :author, name: 'Potato', forum_name: 'Potato'
post :create, user: {
email: 'potato@salad.com',
forum_name: 'Potato',
password: '12345678',
password_confirmation: '12345678'
name: 'Potato',
password: '12345678'
}
expect(response).to redirect_to new_forum_validation_path
@ -67,9 +50,8 @@ describe Users::RegistrationsController, type: :controller do
post :create, user: {
email: 'potato@salad.com',
forum_name: 'rsarsarsa',
password: '12345678',
password_confirmation: '12345678'
name: 'rsarsarsa',
password: '12345678'
}
expect(response).to redirect_to root_path

View File

@ -3,7 +3,6 @@ feature 'Common sign in and sign up form everywhere' do
visit '/users/login'
expect(page).to have_field 'user_login'
expect(page).to_not have_field 'user_email'
expect(page).to_not have_field 'user_forum_name'
expect(page).to_not have_field 'user_name'
expect(page).to have_field 'user_password'
expect(page).to_not have_field 'user_password_confirmation'
@ -11,8 +10,7 @@ feature 'Common sign in and sign up form everywhere' do
page.find('[for="identify_register"]').click
expect(page).to_not have_field 'user_login'
expect(page).to have_field 'user_email'
expect(page).to have_field 'user_forum_name'
expect(page).to_not have_field 'user_name'
expect(page).to have_field 'user_name'
expect(page).to have_field 'user_password'
expect(page).to_not have_field 'user_password_confirmation'
expect(page).to have_field 'user_remember_me'

View File

@ -10,7 +10,7 @@ feature 'New user forum account validation' do
visit new_user_registration_path
within '#new_registration' do
fill_in 'user_email', with: 'potato@universe.com'
fill_in 'user_forum_name', with: 'FactorioModsBot'
fill_in 'user_name', with: 'FactorioModsBot'
fill_in 'user_password', with: '12345678'
find('#user_submit_action input').click
end
@ -19,7 +19,7 @@ feature 'New user forum account validation' do
user = User.last
expect(user.email).to eq 'potato@universe.com'
expect(user.forum_name).to eq 'FactorioModsBot'
expect(user.name).to eq 'FactorioModsBot'
VCR.use_cassette("features/forum_validation", record: :new_episodes) do
find('#forum_validation_submit_action input').click
@ -49,7 +49,7 @@ feature 'New user forum account validation' do
visit new_user_registration_path
within '#new_registration' do
fill_in 'user_email', with: 'potato@universe.com'
fill_in 'user_forum_name', with: 'FactorioModsBot'
fill_in 'user_name', with: 'FactorioModsBot'
fill_in 'user_password', with: '12345678'
find('#user_submit_action input').click
end

View File

@ -42,6 +42,7 @@ feature 'Redirect to the previous page the user was after login' do
expect(current_path).to eq '/users/register'
within('#new_registration') do
fill_in 'user_email', with: 'banana@split.com'
fill_in 'user_name', with: 'Potato'
fill_in 'user_password', with: 'rsarsarsa'
click_button 'Register'
end
@ -55,12 +56,14 @@ feature 'Redirect to the previous page the user was after login' do
expect(current_path).to eq '/users/register'
within('#new_registration') do
fill_in 'user_email', with: 'bansplit.com'
fill_in 'user_name', with: '----'
fill_in 'user_password', with: 'rsarsarsa'
click_button 'Register'
end
expect(current_path).to eq '/users'
within('#new_registration') do
fill_in 'user_email', with: 'banana@split.com'
fill_in 'user_name', with: 'Potato'
fill_in 'user_password', with: 'rsarsarsa'
click_button 'Register'
end

View File

@ -55,11 +55,11 @@ describe ForumValidation, type: :model do
@u = create :user, name: 'Potato'
@a = create :author, name: 'Salatto', forum_name: 'Salatto' # Italian salad
@fv = create :forum_validation, user: @u, author: @a
@m1 = create :mod, authors: [@a], owner: nil, name: 'lalalalalalalala'
@m2 = create :mod, authors: [@a], owner: nil, name: 'lelelelelelelele'
@m1 = create :mod, authors: [@a], owner: nil, name: 'lalala'
@m2 = create :mod, authors: [@a], owner: nil, name: 'lelele'
end
it 'should create a new forum bot if not logged in' do
it 'should create a new forum bot if not authenticated' do
bot = double('ForumBot')
expect(ForumBot).to receive(:new).once.and_return(bot)
@ -67,7 +67,7 @@ describe ForumValidation, type: :model do
expect(bot).to receive(:authenticate).with(ENV['FORUM_BOT_ACCOUNT'], ENV['FORUM_BOT_PASSWORD']).and_return true
expect(bot).to receive(:get_user_id).with('Salatto').and_return(1234)
expect(bot).to receive(:send_pm)
.with(1234, /validation/, %r{/forum-validations/#{@fv.id}/validate\?vid=#{@fv.vid}.*lelelelelelelele.*lalalalalalalala}m)
.with(1234, /validation/, %r{/forum-validations/#{@fv.id}/validate\?vid=#{@fv.vid}.*(lalala.*lelele|lelele.*lalala)}m)
.and_return(true)
expect(@fv.send_pm).to eq true
@ -82,7 +82,7 @@ describe ForumValidation, type: :model do
expect(bot).to receive(:authenticate).with(ENV['FORUM_BOT_ACCOUNT'], ENV['FORUM_BOT_PASSWORD']).and_return true
expect(bot).to receive(:get_user_id).twice.with('Salatto').and_return(1234)
expect(bot).to receive(:send_pm).twice
.with(1234, /validation/, %r{/forum-validations/#{@fv.id}/validate\?vid=#{@fv.vid}.*lelelelelelelele.*lalalalalalalala}m)
.with(1234, /validation/, %r{/forum-validations/#{@fv.id}/validate\?vid=#{@fv.vid}.*(lalala.*lelele|lelele.*lalala)}m)
.and_return(true)
expect(@fv.send_pm).to eq true
@ -113,7 +113,7 @@ describe ForumValidation, type: :model do
expect(bot).to receive(:authenticate).with(ENV['FORUM_BOT_ACCOUNT'], ENV['FORUM_BOT_PASSWORD']).and_return true
expect(bot).to receive(:get_user_id).with('Salatto').and_return(1234)
expect(bot).to receive(:send_pm)
.with(1234, /validation/, %r{/forum-validations/#{@fv.id}/validate\?vid=#{@fv.vid}.*lelelelelelelele.*lalalalalalalala}m)
.with(1234, /validation/, %r{/forum-validations/#{@fv.id}/validate\?vid=#{@fv.vid}.*(lalala.*lelele|lelele.*lalala)}m)
.and_return(false)
expect(@fv.send_pm).to eq false
@ -126,7 +126,7 @@ describe ForumValidation, type: :model do
expect(bot).to receive(:authenticated?).and_return true
expect(bot).to receive(:get_user_id).with('Salatto').and_return(1234)
expect(bot).to receive(:send_pm)
.with(1234, /validation/, %r{/forum-validations/#{@fv.id}/validate\?vid=#{@fv.vid}.*lelelelelelelele.*lalalalalalalala}m)
.with(1234, /validation/, %r{/forum-validations/#{@fv.id}/validate\?vid=#{@fv.vid}.*(lalala.*lelele|lelele.*lalala)}m)
.and_return(true)
expect(@fv.send_pm).to eq true

View File

@ -9,7 +9,6 @@ describe User, :type => :model do
it { is_expected.to respond_to :slug }
it { is_expected.to respond_to :autogenerated }
it { is_expected.to respond_to :login }
it { is_expected.to respond_to :forum_name }
it { is_expected.to respond_to :owned_mods }
it { is_expected.to respond_to :bookmarks }
@ -24,10 +23,10 @@ describe User, :type => :model do
its('build_forum_validation'){ is_expected.to be_kind_of ForumValidation }
describe 'validations' do
# it 'should not allow user without name' do
# user = build :user, name: ''
# expect(user).to be_invalid
# end
it 'should not allow user without name' do
user = build :user, name: ''
expect(user).to be_invalid
end
it 'should not allow user without email' do
user = build :user, email: ''
@ -44,58 +43,52 @@ describe User, :type => :model do
expect(user).to be_invalid
end
it 'should not allow 2 users with the same #forum_name' do
create :user, forum_name: 'HeyHeyNanana'
user2 = build :user, forum_name: 'HeyHeyNanana'
it 'should allow spaces in the name' do
user = build :user, name: 'Potato Head'
expect(user).to be_valid
end
it 'should strip extra spaces and sqeeze them automatically' do
user = build :user, name: ' Potato Head '
expect(user).to be_valid
expect(user.name).to eq 'Potato Head'
end
it 'should not allow users with the same name' do
create :user, name: 'HeyHeyNanana'
user2 = build :user, name: 'HeyHeyNanana'
expect(user2).to be_invalid
end
# it 'should allow spaces in the name' do
# user = build :user, name: 'Potato Head'
# expect(user).to be_valid
# end
#
# it 'should strip extra spaces and sqeeze them automatically' do
# user = build :user, name: ' Potato Head '
# expect(user).to be_valid
# expect(user.name).to eq 'Potato Head'
# end
#
# it 'should not allow users with the same name' do
# create :user, name: 'HeyHeyNanana'
# user2 = build :user, name: 'HeyHeyNanana'
# expect(user2).to be_invalid
# end
#
# it 'should not allow users with the same name with different cases' do
# create :user, name: 'HeyHeyNanana'
# user2 = build :user, name: 'heyheynanana'
# expect(user2).to be_invalid
# end
#
# it 'should not allow names shorter than 2 characters' do
# user = build :user, name: 'a'
# expect(user).to be_invalid
# end
#
# it 'should allow names of 2 characters' do
# user = build :user, name: '22'
# expect(user).to be_valid
# end
#
# it 'should not allow names longer than 50 characters' do
# user = build :user, name: 'a'*51
# expect(user).to be_invalid
# end
#
# it 'should allow names of 50 characters' do
# user = build :user, name: 'a'*50
# expect(user).to be_valid
# end
#
# it 'should be valid with alphanumeric characters, spaces, dashes, underscores, dots or spaces' do
# expect(build(:user, name: 'Zeq.mán123- _Potatoí')).to be_valid
# end
it 'should not allow users with the same name with different cases' do
create :user, name: 'HeyHeyNanana'
user2 = build :user, name: 'heyheynanana'
expect(user2).to be_invalid
end
it 'should not allow names shorter than 2 characters' do
user = build :user, name: 'a'
expect(user).to be_invalid
end
it 'should allow names of 2 characters' do
user = build :user, name: '22'
expect(user).to be_valid
end
it 'should not allow names longer than 50 characters' do
user = build :user, name: 'a'*51
expect(user).to be_invalid
end
it 'should allow names of 50 characters' do
user = build :user, name: 'a'*50
expect(user).to be_valid
end
it 'should be valid with alphanumeric characters, spaces, dashes, underscores, dots or spaces' do
expect(build(:user, name: 'Zeq.mán123- _Potatoí')).to be_valid
end
end
describe 'attributes' do