Skip to content

Commit

Permalink
Finish user signup
Browse files Browse the repository at this point in the history
  • Loading branch information
bodfarian committed Nov 1, 2014
1 parent 39f4f33 commit 090e66c
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 3 deletions.
88 changes: 87 additions & 1 deletion app/assets/stylesheets/custom.css.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
@import "bootstrap-sprockets";
@import "bootstrap";

/* mixins, variables, etc. */

$gray-medium-light: #eaeaea;

@mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

/* universal */

html {
Expand Down Expand Up @@ -128,4 +138,80 @@ footer {
}
}
}


/* sidebar */

aside {
section.user_info {
margin-top: 20px;
}
section {
padding: 10px 0;
margin-top: 20px;
&:first-child {
border: 0;
padding-top: 0;
}
span {
display: block;
margin-bottom: 3px;
line-height: 1;
}
h1 {
font-size: 1.4em;
text-align: left;
letter-spacing: -1px;
margin-bottom: 3px;
margin-top: 0px;
}
}
}

.gravatar {
float: left;
margin-right: 10px;
}

.gravatar_edit {
margin-top: 15px;
}

/* forms */

input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
@include box_sizing;
}

input {
height: auto !important;
}

#error_explanation {
color: red;
ul {
color: red;
margin: 0 0 30px 0;
}
}

.field_with_errors {
@extend .has-error;
.form-control {
color: $state-danger-text;
}
}


/* miscellaneous */

.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
@include box_sizing;
}

25 changes: 25 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
class UsersController < ApplicationController

def show
@user = User.find(params[:id])
# debugger
end

def new
@user = User.new
end

def create
@user = User.new(user_params)
if @user.save
# Handle a successful save.
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end

private

def user_params
params.require(:user).permit(:name, :email, :password,
:password_confirmation)
end
end
7 changes: 7 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
module UsersHelper

# Returns the Gravatar for the given user.
def gravatar_for(user)
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
image_tag(gravatar_url, alt: user.name, class: "gravatar")
end
end
4 changes: 4 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
<body>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |message_type, message| %>
<div class="alert alert-<%= message_type %>"><%= message %></div>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
12 changes: 12 additions & 0 deletions app/views/shared/_error_messages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% if @user.errors.any? %>
<div id="error_explanation">
<div class="alert alert-danger">
The form contains <%= pluralize(@user.errors.count, "error") %>.
</div>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
23 changes: 22 additions & 1 deletion app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<p>This will be a signup page for new users.</p>

<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages' %>

<%= f.label :name %>
<%= f.text_field :name, class: 'form_control' %>

<%= f.label :email %>
<%= f.text_field :email, class: 'form_control' %>

<%= f.label :password %>
<%= f.password_field :password, class: 'form_control' %>

<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation, class: 'form_control' %>

<%= f.submit "Create my account", class: "btn btn primary" %>
<% end %>
</div>
</div>
11 changes: 11 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% provide(:title, @user.name) %>
<div class="row">
<aside class="col-md-4">
<section class="user_info">
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
</section>
</aside>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
get 'signup' => 'users#new'
resources :users
end

# Old routes - before creating named routes
Expand Down
2 changes: 1 addition & 1 deletion spring/50c4ccb1d8f630979e84c03ba14676d1.pid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1466
4451
28 changes: 28 additions & 0 deletions test/integration/users_signup_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'test_helper'

class UsersSignupTest < ActionDispatch::IntegrationTest

# test "the truth" do
test "invalid signup information" do
# assert true
assert_no_difference 'User.count' do
post users_path, user: { name: "",
email: "user@invalid",
password: "foo",
password_confirmation: "bar" }
# end
end
assert_template 'users/new'
end

test "valid signup information" do
get signup_path
assert_difference 'User.count', 1 do
post_via_redirect users_path, user: { name: "Example User",
email: "[email protected]",
password: "password",
password_confirmation: "password" }
end
assert_template 'users/show'
end
end

0 comments on commit 090e66c

Please sign in to comment.