Skip to content

Commit

Permalink
Merge cd1e711 into bb279a2
Browse files Browse the repository at this point in the history
  • Loading branch information
kwappa committed Jan 14, 2015
2 parents bb279a2 + cd1e711 commit 83958fc
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 114 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/users/profile.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ table.profile {
}
}

form.profile_form {
form.resume_form {
textarea {
width: 80%;
height: 24em;
Expand Down
45 changes: 0 additions & 45 deletions app/controllers/user_profiles_controller.rb

This file was deleted.

45 changes: 45 additions & 0 deletions app/controllers/user_resumes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class UserResumesController < ApplicationController
before_action :set_user_and_resume

respond_to :html
layout 'users'

def new
if @user_resume.present?
redirect_to edit_users_resume_path
else
@user_resume = UserResume.new(user_id: @user.id)
end
end

def edit
unless @user_resume.present?
redirect_to new_users_resume_path
end
end

def create
@user_resume = UserResume.new(user_id: @user.id, body: user_resume_params[:body])
@user_resume.save
flash[:notice] = 'Resume created.'
redirect_to home_path(@user.nick)
end

def update
@user_resume.update_attributes(body: user_resume_params[:body])
flash[:notice] = 'Resume updated.'
redirect_to home_path(@user.nick)
end

private

def set_user_and_resume
redirect_to(root_path) and return unless view_context.myself?(current_user)
@user = current_user
@user_resume = current_user.resume
end

def user_resume_params
params.require(:user_resume).permit(:user_id, :body)
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class User < ActiveRecord::Base
username_not_reserved: true
}

has_one :profile, class_name: 'UserProfile'
has_one :resume, class_name: 'UserResume'

devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable, :omniauthable
Expand Down
2 changes: 1 addition & 1 deletion app/models/user_profile.rb → app/models/user_resume.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class UserProfile < ActiveRecord::Base
class UserResume < ActiveRecord::Base
belongs_to :user
include Renderable
end
8 changes: 0 additions & 8 deletions app/views/user_profiles/_form.html.haml

This file was deleted.

9 changes: 9 additions & 0 deletions app/views/user_resumes/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
%div
= form_for @user_resume, url: { controller: :user_resumes, action: form_action } , html: { class: 'resume_form' } do |f|
.field
= f.text_area :body
= f.hidden_field :user_id
.actions
= button_tag class: 'pure-button' do
%i.fa.fa-save.fa-lg
Save
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
= link_to home_path(@user.nick), class: 'edit_link' do
%i.fa.fa-arrow-circle-o-left.fa-lg
%div.post-description
%div.profile_form
= render 'form', form_action: :update
= render 'form', form_action: :update
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
= link_to home_path(@user.nick), class: 'edit_link' do
%i.fa.fa-arrow-circle-o-left.fa-lg
%div.post-description
%div.profile_form
= render 'form', form_action: :create
= render 'form', form_action: :create
6 changes: 3 additions & 3 deletions app/views/users/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
%i.fa.fa-file-text.fa-lg
Resume
- if myself?(@user)
= link_to edit_users_profile_path, class: 'edit_link' do
= link_to edit_users_resume_path, class: 'edit_link' do
%i.fa.fa-edit.fa-lg
%div.post-description
%div.resume
- if @user.profile.present?
= @user.profile.render(:body).html_safe
- if @user.resume.present?
= @user.resume.render(:body).html_safe
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace :users do
get :list
resource :user_profiles, controller: '/user_profiles', as: :profile, path: :profile
resource :user_resumes, controller: '/user_resumes', as: :resume, path: :resume
end

scope ':nick' do
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20150114033834_rename_profile_to_resume.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class RenameProfileToResume < ActiveRecord::Migration
def change
if table_exists?(:user_profiles)
rename_table(:user_profiles, :user_resumes)
end
end
end
6 changes: 3 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20141224130816) do
ActiveRecord::Schema.define(version: 20150114033834) do

create_table "user_profiles", force: :cascade do |t|
create_table "user_resumes", force: :cascade do |t|
t.integer "user_id", null: false
t.text "body"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "user_profiles", ["user_id"], name: "index_user_profiles_on_user_id"
add_index "user_resumes", ["user_id"], name: "index_user_resumes_on_user_id"

create_table "users", force: :cascade do |t|
t.string "name", null: false
Expand Down
41 changes: 0 additions & 41 deletions spec/controllers/user_profiles_controller_spec.rb

This file was deleted.

41 changes: 41 additions & 0 deletions spec/controllers/user_resumes_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'rails_helper'

RSpec.describe UserResumesController, type: :controller do
let(:resume) { create(:user_resume) }

describe '#new' do
subject(:new_resume) { get :new }

context 'when user does not login' do
it { expect(new_resume).to redirect_to root_path }
end

context 'when login user without resume' do
before { sign_in create(:user) }
it { expect(new_resume).to be_ok }
end

context 'when login user with resume' do
before { sign_in resume.user }
it { expect(new_resume).to redirect_to edit_users_resume_path }
end
end

describe '#edit' do
subject(:new_resume) { get :edit }

context 'when user does not login' do
it { expect(new_resume).to redirect_to root_path }
end

context 'when login user without resume' do
before { sign_in create(:user) }
it { expect(new_resume).to redirect_to new_users_resume_path }
end

context 'when login user with resume' do
before { sign_in resume.user }
it { expect(new_resume).to be_ok }
end
end
end
20 changes: 20 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'rails_helper'

RSpec.describe UsersController, type: :controller do
render_views

describe '#index' do
let(:user) { create(:user) }
subject(:index) { get :index }
Expand Down Expand Up @@ -51,4 +53,22 @@
end
end
end

describe '#show' do
let(:user) { create(:user) }
subject(:show) { get :show, nick: user.nick }

context 'when user is not logging in' do
it { expect(show).to be_ok }
end

context 'when user is logging in as myself' do
before { sign_in user }
it { expect(show).to be_ok }
end

context 'when user does not found' do
it { expect { get :show, nick: 'NOT_EXISTING_USER' }.to raise_error ActiveRecord::RecordNotFound }
end
end
end
6 changes: 0 additions & 6 deletions spec/factories/user_profiles.rb

This file was deleted.

6 changes: 6 additions & 0 deletions spec/factories/user_resumes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryGirl.define do
factory :user_resume do
user
body "User Resume Body"
end
end

0 comments on commit 83958fc

Please sign in to comment.