Commit 4dc8cc6
Changed files (15)
app
assets
stylesheets
controllers
models
views
layouts
profiles
db
spec
controllers
features
models
app/assets/stylesheets/profiles.scss
@@ -1,6 +0,0 @@
-.profiles.show {
- table {
- margin-left: auto;
- margin-right: auto;
- }
-}
app/controllers/profiles_controller.rb
@@ -1,6 +1,13 @@
-class ProfilesController < PublicController
+class ProfilesController < ApplicationController
+
def show
@user = User.find_by(username: params[:id])
@program = Program.stronglifts
end
+
+ def edit
+ @user = User.find_by(username: params[:id]) if @current_user.username == params[:id]
+ @program = Program.stronglifts
+ end
+
end
app/models/profile.rb
@@ -0,0 +1,3 @@
+class Profile < ActiveRecord::Base
+ belongs_to :user
+end
app/models/user.rb
@@ -2,6 +2,7 @@ class User < ActiveRecord::Base
has_secure_password
has_many :training_sessions
has_many :exercise_sessions, through: :training_sessions
+ has_one :profile
USERNAME_REGEX=/\A[-a-z0-9_.]*\z/i
validates :username, presence: true, format: { with: USERNAME_REGEX }, uniqueness: true
app/views/layouts/application.html.erb
@@ -64,10 +64,11 @@
<li class="has-dropdown">
<a href="#"><%= gravatar_for(@current_user, size: 16) %> <%= @current_user.username %></a>
<ul class="dropdown">
- <li><%= link_to "Training Sessions", training_sessions_path %></li>
- <li><%= link_to "My Public Profile", profile_path(@current_user) %></li>
+ <li><%= link_to t("nav.user.training_sessions"), training_sessions_path %></li>
+ <li><%= link_to t("nav.user.profile_edit"), edit_profile_path(@current_user) %></li>
+ <li><%= link_to t("nav.user.profile_view"), profile_path(@current_user) %></li>
<li class="divider"></li>
- <li><%= link_to "Log Out", session_path('me'), method: :delete %></li>
+ <li><%= link_to t("nav.user.log_out"), session_path('me'), method: :delete %></li>
</ul>
</li>
</ul>
@@ -77,13 +78,15 @@
</div>
</div>
<!-- End Navigation -->
+ <!-- START CONTENT -->
<%= yield %>
+ <!-- END CONTENT -->
<!-- Footer -->
<footer class="row">
<div class="large-12 columns"><hr />
<div class="row">
<div class="large-6 columns">
- <p>© Copyright no one at all. Go to town.</p>
+ <p><%= t("footer.copyright") %></p>
</div>
<div class="large-6 columns">
<ul class="inline-list right">
app/views/profiles/edit.html.erb
@@ -0,0 +1,12 @@
+<div class="row">
+
+ <div class="small-12 columns text-center">
+ <%= gravatar_for(@user, size: 128) %>
+ <h1><%= @user.username %></h1>
+ <%= form_for @user do |f| %>
+ <%= f.input :gender %>
+ <%= f.input :social_tolerance %>
+ <% end %>
+ </div>
+
+</div>
\ No newline at end of file
app/views/profiles/show.html.erb
@@ -1,9 +1,6 @@
-<div class="small-12 columns">
<div class="row">
- <div class="small-2 columns">
-
- </div>
- <div class="small-8 columns text-center">
+
+ <div class="small-12 medium-4 columns small-text-center medium-text-left">
<%= link_to profile_path(@user), class: 'th [radius]' do %>
<%= gravatar_for(@user, size: 128) %>
<% end %>
@@ -13,7 +10,9 @@
<% else %>
<p><%= t('.no_workouts_completed') %></p>
<% end %>
+ </div>
+ <div class="small-12 medium-8 columns small-text-center medium-text-left">
<h2><%= t('.personal_records') %></h2>
<table role="grid">
<thead>
@@ -30,14 +29,17 @@
<% end %>
</tbody>
</table>
+ </div>
+
+</div>
+
+<div>
+ <div class="small-12 columns small-text-center medium-text-left">
<h2><%= t('.training_history') %></h2>
<% @program.exercises.uniq.each do |exercise| %>
<%= render @user.history_for(exercise) %>
<% end %>
</div>
- <div class="small-2 columns">
-
- </div>
-</div>
-</div>
+
+</div>
\ No newline at end of file
config/locales/en.yml
@@ -20,6 +20,12 @@
# available at http://guides.rubyonrails.org/i18n.html.
en:
+ nav:
+ user:
+ training_sessions: "Training sessions"
+ log_out: "Log out"
+ profile_edit: "Edit profile"
+ profile_view: "View profile"
registrations:
new:
username: "Username"
@@ -49,9 +55,11 @@ en:
register_link: "Create an account"
training_sessions:
index:
- backup_file: 'File'
+ backup_file: "File"
upload_backup_button: "Upload"
upload:
- success: 'Our minions have been summoned to unpack your backup.'
+ success: "Our minions have been summoned to unpack your backup."
training_session:
body_weight: Body Weight
+ footer:
+ copyright: "© Copyright stronglifters.com. All rights reserved."
\ No newline at end of file
config/routes.rb
@@ -8,7 +8,7 @@ Rails.application.routes.draw do
end
end
resources :programs, only: [:show]
- resources :profiles, only: [:show], constraints: { id: /[^\/]+/ }
+ resources :profiles, only: [:new, :create, :show, :edit], constraints: { id: /[^\/]+/ }
get "/u/:id" => "profiles#show", constraints: { id: /[^\/]+/ }
get "/dashboard" => "training_sessions#index", as: :dashboard
get "/terms" => "static_pages#terms"
db/migrate/20150616021904_create_profiles.rb
@@ -0,0 +1,11 @@
+class CreateProfiles < ActiveRecord::Migration
+ def change
+ create_table :profiles do |t|
+ t.uuid :user_id, null: false
+ t.boolean :gender
+ t.integer :social_tolerance
+ t.timestamps null: false
+ end
+ add_index :profiles, :user_id
+ end
+end
db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20150530181053) do
+ActiveRecord::Schema.define(version: 20150616021904) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -41,6 +41,16 @@ ActiveRecord::Schema.define(version: 20150530181053) do
t.datetime "updated_at", null: false
end
+ create_table "profiles", force: :cascade do |t|
+ t.uuid "user_id", null: false
+ t.boolean "gender"
+ t.integer "social_tolerance"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_index "profiles", ["user_id"], name: "index_profiles_on_user_id", using: :btree
+
create_table "programs", id: :uuid, default: "uuid_generate_v4()", force: :cascade do |t|
t.string "name", null: false
t.datetime "created_at", null: false
spec/controllers/profiles_controller_spec.rb
@@ -1,15 +1,83 @@
require "rails_helper"
describe ProfilesController do
- describe "#show" do
- include_context "stronglifts_program"
+
+ describe "authenticated" do
+
+ describe "#show" do
+ include_context "stronglifts_program"
- let(:user) { create(:user) }
+ let(:user) { create(:user) }
+ let(:other_user) { create(:user) }
- it "loads the users profile" do
- get :show, id: user.to_param
- expect(assigns(:user)).to eql(user)
- expect(assigns(:program)).to eql(Program.stronglifts)
+ before :each do
+ http_login(user)
+ end
+
+ it "loads the user's profile" do
+ get :show, id: user.to_param
+ expect(assigns(:user)).to eql(user)
+ expect(assigns(:program)).to eql(Program.stronglifts)
+ end
+ it "loads the other user's profile" do
+ get :show, id: other_user.to_param
+ expect(assigns(:user)).to eql(other_user)
+ expect(assigns(:program)).to eql(Program.stronglifts)
+ end
+ end
+
+ describe "#edit" do
+ include_context "stronglifts_program"
+
+ let(:user) { create(:user) }
+ let(:other_user) { create(:user) }
+
+ before :each do
+ http_login(user)
+ end
+
+ it "loads the user's profile into an edit view" do
+ get :edit, id: user.to_param
+ expect(assigns(:user)).to eql(user)
+ expect(assigns(:program)).to eql(Program.stronglifts)
+ end
+
+ it "will not load the other user's profile into an edit view" do
+ get :edit, id: other_user.to_param
+ expect(assigns(:user)).to eql(nil)
+ expect(assigns(:program)).to eql(Program.stronglifts)
+ end
+
+ end
+
+ end
+
+ describe "unauthenticated" do
+
+ describe "#show" do
+ include_context "stronglifts_program"
+
+ let(:user) { create(:user) }
+
+ it "loads the user's profile" do
+ get :show, id: user.to_param
+ expect(assigns(:user)).to eql(nil)
+ expect(assigns(:program)).to eql(nil)
+ end
+ end
+
+ describe "#edit" do
+ include_context "stronglifts_program"
+
+ let(:user) { create(:user) }
+
+ it "loads the user's profile into an edit view" do
+ get :edit, id: user.to_param
+ expect(assigns(:user)).to eql(nil)
+ expect(assigns(:program)).to eql(nil)
+ end
end
+
end
+
end
spec/features/profiles_spec.rb
@@ -7,6 +7,7 @@ feature "Profiles", type: :feature do
let(:user) { create(:user) }
before :each do
+ http_login(user)
subject.visit_page
end
spec/models/profile_spec.rb
@@ -0,0 +1,13 @@
+require 'rails_helper'
+
+describe Profile do
+
+ describe "gender" do
+ it "defaults to no value" do
+ user = User.new(email: nil)
+ expect(user).to_not be_valid
+ expect(user.errors[:email]).to_not be_empty
+ end
+ end
+
+end
spec/factories.rb
@@ -1,4 +1,7 @@
-FactoryGirl.define do
+FactoryGirl.define do factory :profile do
+
+ end
+
factory :exercise do
name { FFaker::Internet.user_name }
end