move address to user
Migration to add fields to User, change factory accordingly profile view to edit new fields remove fields from resume
This commit is contained in:
parent
58ba745a7e
commit
674298ba13
|
@ -11,10 +11,12 @@ class RegistrationsController < Devise::RegistrationsController
|
|||
|
||||
private
|
||||
def sign_up_params
|
||||
params.require(:user).permit(:name, :email, :password, :password_confirmation)
|
||||
params.require(:user).permit(:name, :email,:street,:city,
|
||||
:country , :password, :password_confirmation)
|
||||
end
|
||||
|
||||
def account_update_params
|
||||
params.require(:user).permit(:name, :email, :password, :password_confirmation, :current_password)
|
||||
params.require(:user).permit(:name, :email,:street,:city,:country,
|
||||
:password, :password_confirmation, :current_password)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ class ResumesController < ApplicationController
|
|||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def resume_params
|
||||
params.require(:resume).permit(:street, :city, :country, :user_id , :finance ,
|
||||
params.require(:resume).permit(:user_id , :finance ,
|
||||
:school, :uni, :internship, :work, :tech_skills,
|
||||
:soft_skills, :projects, :other, :interests, :motivation)
|
||||
end
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
class User < ActiveRecord::Base
|
||||
validates :name, presence: true
|
||||
validates_presence_of :street
|
||||
validates_presence_of :city
|
||||
validates_presence_of :country
|
||||
|
||||
enum role: [:user, :teacher, :admin]
|
||||
|
||||
|
|
|
@ -12,21 +12,28 @@
|
|||
- if devise_mapping.confirmable? && resource.pending_reconfirmation?
|
||||
%div
|
||||
Currently waiting confirmation for: #{resource.unconfirmed_email}
|
||||
%fieldset
|
||||
%p Leave these fields blank if you don't want to change your password.
|
||||
.form-group
|
||||
= f.label :password
|
||||
= f.password_field :password, :autocomplete => 'off', class: 'form-control'
|
||||
.form-group
|
||||
= f.label :password_confirmation
|
||||
= f.password_field :password_confirmation, class: 'form-control'
|
||||
%fieldset
|
||||
%p You must enter your current password to make changes.
|
||||
.form-group
|
||||
= f.label :current_password
|
||||
= f.password_field :current_password, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :street
|
||||
= f.text_field :street, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :city
|
||||
= f.text_field :city, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :country
|
||||
= f.text_field :country, class: 'form-control'
|
||||
%p Leave these fields blank if you don't want to change your password.
|
||||
.form-group
|
||||
= f.label :password
|
||||
= f.password_field :password, :autocomplete => 'off', class: 'form-control'
|
||||
.form-group
|
||||
= f.label :password_confirmation
|
||||
= f.password_field :password_confirmation, class: 'form-control'
|
||||
%p You must enter your current password to make changes.
|
||||
.form-group
|
||||
= f.label :current_password
|
||||
= f.password_field :current_password, class: 'form-control'
|
||||
= f.submit 'Update', :class => 'btn btn-success'
|
||||
.authform
|
||||
%h3 Cancel Account
|
||||
%p Unhappy? We'll be sad to see you go.
|
||||
= button_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete, :class => 'btn btn-success'
|
||||
= button_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete, :class => 'btn btn-danger'
|
||||
|
|
|
@ -20,6 +20,15 @@
|
|||
.form-group
|
||||
= f.label :email
|
||||
= f.email_field :email, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :street
|
||||
= f.text_field :street, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :city
|
||||
= f.text_field :city, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :country
|
||||
= f.text_field :country, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :password
|
||||
= f.password_field :password, class: 'form-control'
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
%h1 Listing resumes
|
||||
|
||||
%table
|
||||
%thead
|
||||
%tr
|
||||
%th School
|
||||
%th Uni
|
||||
%th Internship
|
||||
%th Work
|
||||
%th Tech skills
|
||||
%th Soft skills
|
||||
%th Projects
|
||||
%th Other
|
||||
%th Intrests
|
||||
%th Motivation
|
||||
%th Address1
|
||||
%th City
|
||||
%th Country
|
||||
%th User
|
||||
%th
|
||||
%th
|
||||
%th
|
||||
|
||||
%tbody
|
||||
- @resumes.each do |resume|
|
||||
%tr
|
||||
%td= resume.school
|
||||
%td= resume.uni
|
||||
%td= resume.internship
|
||||
%td= resume.work
|
||||
%td= resume.tech_skills
|
||||
%td= resume.soft_skills
|
||||
%td= resume.projects
|
||||
%td= resume.other
|
||||
%td= resume.interests
|
||||
%td= resume.motivation
|
||||
%td= resume.street
|
||||
%td= resume.city
|
||||
%td= resume.country
|
||||
%td= resume.user_id
|
||||
%td= link_to 'Show', resume
|
||||
|
||||
%br
|
||||
|
||||
= link_to 'New Resume', new_resume_path
|
|
@ -73,31 +73,10 @@
|
|||
%b Finance plan:
|
||||
.col-md-8
|
||||
= resume_in_place :finance
|
||||
.row
|
||||
.row.margin-bottom-30
|
||||
.col-md-1
|
||||
.col-md-1
|
||||
%p
|
||||
%b Other:
|
||||
.col-md-8
|
||||
= resume_in_place :other
|
||||
.row
|
||||
.col-md-1
|
||||
.col-md-1
|
||||
%p
|
||||
%b Address:
|
||||
.col-md-8
|
||||
= resume_in_place :street
|
||||
.row
|
||||
.col-md-1
|
||||
.col-md-1
|
||||
%p
|
||||
%b City:
|
||||
.col-md-8
|
||||
= resume_in_place :city
|
||||
.row.margin-bottom-30
|
||||
.col-md-1
|
||||
.col-md-1
|
||||
%p
|
||||
%b Country:
|
||||
.col-md-8
|
||||
= resume_in_place :country
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
class AddStreetCityCountryToUser < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
add_column :users, :street, :string
|
||||
add_column :users, :city, :string
|
||||
add_column :users, :country, :string
|
||||
end
|
||||
end
|
11
db/schema.rb
11
db/schema.rb
|
@ -1,4 +1,3 @@
|
|||
# encoding: UTF-8
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
|
@ -11,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160517133538) do
|
||||
ActiveRecord::Schema.define(version: 20170602115219) do
|
||||
|
||||
create_table "applies", force: :cascade do |t|
|
||||
t.integer "primary_choice_course_id"
|
||||
|
@ -75,9 +74,11 @@ ActiveRecord::Schema.define(version: 20160517133538) do
|
|||
t.string "unconfirmed_email"
|
||||
t.integer "role"
|
||||
t.integer "course_id"
|
||||
t.string "street"
|
||||
t.string "city"
|
||||
t.string "country"
|
||||
t.index ["email"], name: "index_users_on_email", unique: true
|
||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||
end
|
||||
|
||||
add_index "users", ["email"], name: "index_users_on_email", unique: true
|
||||
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||
|
||||
end
|
||||
|
|
|
@ -5,6 +5,10 @@ FactoryGirl.define do
|
|||
email "test@example.com"
|
||||
password "please123"
|
||||
|
||||
street "WhereIlive 111"
|
||||
city "CityOfTesters"
|
||||
country "WhereIam"
|
||||
|
||||
trait :admin do
|
||||
role 'admin'
|
||||
end
|
||||
|
|
|
@ -9,16 +9,13 @@ feature 'User profile page', :devise do
|
|||
Warden.test_reset!
|
||||
end
|
||||
|
||||
# Scenario: User sees own profile
|
||||
# Given I am signed in
|
||||
# When I visit the user profile page
|
||||
# Then I see my own email address
|
||||
scenario 'user sees own profile' do
|
||||
user = FactoryGirl.create(:user)
|
||||
login_as(user, :scope => :user)
|
||||
visit edit_user_registration_path
|
||||
expect(page).to have_content 'Password confirmation'
|
||||
expect(find_field('user_email').value).to eq user.email
|
||||
expect(find_field('user_street').value).to eq user.street
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -9,10 +9,6 @@ feature 'User edit', :devise do
|
|||
Warden.test_reset!
|
||||
end
|
||||
|
||||
# Scenario: User changes email address
|
||||
# Given I am signed in
|
||||
# When I change my email address
|
||||
# Then I see an account updated message
|
||||
scenario 'user changes email address' do
|
||||
user = FactoryGirl.create(:user)
|
||||
login_as(user, :scope => :user)
|
||||
|
@ -24,10 +20,18 @@ feature 'User edit', :devise do
|
|||
expect(page).to have_content(/.*#{txts[0]}.*|.*#{txts[1]}.*/)
|
||||
end
|
||||
|
||||
# Scenario: User cannot edit another user's profile
|
||||
# Given I am signed in
|
||||
# When I try to edit another user's profile
|
||||
# Then I see my own 'edit profile' page
|
||||
["Street","City","Country"].each do |target|
|
||||
scenario "user changes #{target}" do
|
||||
user = FactoryGirl.create(:user)
|
||||
login_as(user, :scope => :user)
|
||||
visit edit_user_registration_path(user)
|
||||
fill_in target, :with => "New#{target}"
|
||||
fill_in 'Current password', :with => user.password
|
||||
click_button 'Update'
|
||||
expect(user.reload.send(target.downcase)).to eq("New#{target}")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "user cannot cannot edit another user's profile", :me do
|
||||
me = FactoryGirl.create(:user)
|
||||
other = FactoryGirl.create(:user, email: 'other@example.com')
|
||||
|
|
|
@ -5,62 +5,38 @@
|
|||
feature 'Sign Up', :devise do
|
||||
|
||||
scenario 'after good sign up redirect to camp' do
|
||||
sign_up_with("TestName",'test1@example.com', 'please123', 'please123')
|
||||
sign_up_with()
|
||||
expect(page.current_path).to eq page_path(:camp)
|
||||
end
|
||||
|
||||
# Scenario: Visitor can sign up with valid email address and password
|
||||
# Given I am not signed in
|
||||
# When I sign up with a valid email address and password
|
||||
# Then I see a successful sign up message
|
||||
scenario 'visitor can sign up with valid email address and password' do
|
||||
sign_up_with("TestName",'test@example.com', 'please123', 'please123')
|
||||
sign_up_with()
|
||||
txts = [I18n.t( 'devise.registrations.signed_up'), I18n.t( 'devise.registrations.signed_up_but_unconfirmed')]
|
||||
expect(page).to have_content(/.*#{txts[0]}.*|.*#{txts[1]}.*/)
|
||||
end
|
||||
|
||||
# Scenario: Visitor cannot sign up with invalid email address
|
||||
# Given I am not signed in
|
||||
# When I sign up with an invalid email address
|
||||
# Then I see an invalid email message
|
||||
scenario 'visitor cannot sign up with invalid email address' do
|
||||
sign_up_with("TestName",'bogus', 'please123', 'please123')
|
||||
sign_up_with( email: 'bogus')
|
||||
expect(page).to have_content 'Email is invalid'
|
||||
end
|
||||
|
||||
# Scenario: Visitor cannot sign up without password
|
||||
# Given I am not signed in
|
||||
# When I sign up without a password
|
||||
# Then I see a missing password message
|
||||
scenario 'visitor cannot sign up without password' do
|
||||
sign_up_with("TestName",'test@example.com', '', '')
|
||||
sign_up_with(password: '')
|
||||
expect(page).to have_content "Password can't be blank"
|
||||
end
|
||||
|
||||
# Scenario: Visitor cannot sign up with a short password
|
||||
# Given I am not signed in
|
||||
# When I sign up with a short password
|
||||
# Then I see a 'too short password' message
|
||||
scenario 'visitor cannot sign up with a short password' do
|
||||
sign_up_with("TestName",'test@example.com', 'please', 'please')
|
||||
sign_up_with(password: "please" )
|
||||
expect(page).to have_content "Password is too short"
|
||||
end
|
||||
|
||||
# Scenario: Visitor cannot sign up without password confirmation
|
||||
# Given I am not signed in
|
||||
# When I sign up without a password confirmation
|
||||
# Then I see a missing password confirmation message
|
||||
scenario 'visitor cannot sign up without password confirmation' do
|
||||
sign_up_with("TestName",'test@example.com', 'please123', '')
|
||||
sign_up_with(confirmation: '')
|
||||
expect(page).to have_content "Password confirmation doesn't match"
|
||||
end
|
||||
|
||||
# Scenario: Visitor cannot sign up with mismatched password and confirmation
|
||||
# Given I am not signed in
|
||||
# When I sign up with a mismatched password confirmation
|
||||
# Then I should see a mismatched password message
|
||||
scenario 'visitor cannot sign up with mismatched password and confirmation' do
|
||||
sign_up_with("TestName" , 'test@example.com', 'please123', 'mismatch')
|
||||
sign_up_with(password: 'please123', confirmation: 'mismatch')
|
||||
expect(page).to have_content "Password confirmation doesn't match"
|
||||
end
|
||||
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
describe User do
|
||||
|
||||
before(:each) { @user = User.new(email: 'user@example.com') }
|
||||
describe "emails" do
|
||||
before(:each) { @user = User.new(email: 'user@example.com') }
|
||||
|
||||
subject { @user }
|
||||
subject { @user }
|
||||
|
||||
it { should respond_to(:email) }
|
||||
it { should respond_to(:email) }
|
||||
|
||||
it "#email returns a string" do
|
||||
expect(@user.email).to match 'user@example.com'
|
||||
it "#email returns a string" do
|
||||
expect(@user.email).to match 'user@example.com'
|
||||
end
|
||||
end
|
||||
|
||||
it "factory works" do
|
||||
user = build :user
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
module Features
|
||||
module SessionHelpers
|
||||
def sign_up_with(name , email, password, confirmation)
|
||||
def sign_up_with(options = {})
|
||||
user = options[:user] || build(:user)
|
||||
visit new_user_registration_path
|
||||
within ".authform" do
|
||||
fill_in 'Name', with: name
|
||||
fill_in 'Email', with: email
|
||||
fill_in 'Password', with: password
|
||||
fill_in 'Password confirmation', :with => confirmation
|
||||
fill_in 'Name', with: options[:name] || user.name
|
||||
fill_in 'Email', with: options[:email] || user.email
|
||||
fill_in 'Street', with: options[:street] || user.street
|
||||
fill_in 'City', with: options[:city] || user.city
|
||||
fill_in 'Country',with: options[:country] || user.country
|
||||
fill_in 'Password', with: options[:password] || user.password
|
||||
fill_in 'Password confirmation', :with => options[:confirmation] || options[:confirmation] || user.password
|
||||
end
|
||||
click_button 'Start'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue