addPhoneToUser, addcontentToMission, addTest
This commit is contained in:
parent
ba794c7657
commit
f8ad241319
|
@ -42,6 +42,6 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:name, :password, :password_confirmation, :email)
|
||||
params.require(:user).permit(:name, :password, :password_confirmation, :email, :phone)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,4 +10,6 @@ class User < ActiveRecord::Base
|
|||
validates :email, presence: true, uniqueness: true, length: { maximum: 50},
|
||||
format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
|
||||
validates :password, length: { minimum: 6 }
|
||||
validates :phone, presence: true, uniqueness: true, format: { with: /\A[0-9]{11,11}\Z/i },
|
||||
multiline: false
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddPhoneToUser < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :phone, :text
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AddContentToMission < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :missions, :content, :string
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class ChangePhoneToUser < ActiveRecord::Migration
|
||||
def change
|
||||
change_column :users, :phone, :string
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20161211080456) do
|
||||
ActiveRecord::Schema.define(version: 20161226023254) do
|
||||
|
||||
create_table "comments", force: :cascade do |t|
|
||||
t.text "content"
|
||||
|
@ -29,6 +29,7 @@ ActiveRecord::Schema.define(version: 20161211080456) do
|
|||
t.string "status"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "content"
|
||||
end
|
||||
|
||||
create_table "missions_users", id: false, force: :cascade do |t|
|
||||
|
@ -69,6 +70,7 @@ ActiveRecord::Schema.define(version: 20161211080456) do
|
|||
t.string "email"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "phone"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -5,6 +5,7 @@ FactoryGirl.define do
|
|||
email { Faker::Internet.email }
|
||||
password 'secret'
|
||||
password_confirmation 'secret'
|
||||
phone '13712345678'
|
||||
|
||||
factory :user_with_sequence_number do
|
||||
sequence(:email){ |n| "email#{n}@example.com" }
|
||||
|
|
|
@ -71,4 +71,30 @@ RSpec.describe User, type: :model do
|
|||
expect(user.authenticate('654312')).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'phone test' do
|
||||
|
||||
it 'does not allow phone absence' do
|
||||
expect(build(:user, phone: nil)).to_not be_valid
|
||||
end
|
||||
|
||||
it 'does not allow character other than number' do
|
||||
expect(build(:user, phone: '1371234567a')).to_not be_valid
|
||||
end
|
||||
|
||||
it 'does not allow phone longer or shorter than 11' do
|
||||
expect(build(:user, phone: '137123456789')).to_not be_valid
|
||||
expect(build(:user, phone: '1371234567')).to_not be_valid
|
||||
end
|
||||
|
||||
it 'does not allow duplicated phone' do
|
||||
create(:user)
|
||||
expect(build(:user)).to_not be_valid
|
||||
end
|
||||
|
||||
# 防js注入
|
||||
it 'does not allow multiline' do
|
||||
expect(build(:user, phone: '13712345\n78')).to_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue