Skip to content

Commit

Permalink
Finishes user signup
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagonbotelho committed May 26, 2015
1 parent 465350d commit 7770a5f
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 2 deletions.
80 changes: 80 additions & 0 deletions app/assets/stylesheets/custom.css.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
@import "bootstrap-sprockets";
@import "bootstrap";

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

/* variables */

$gray-medium-light: #eaeaea;
Expand Down Expand Up @@ -113,3 +120,76 @@ footer ul li {
float: left;
margin-left: 15px;
}

/* 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;
}
}

.debug_dump {
clear: both;
float:left;
width: 100%;
margin-top: 45px;
@include box_sizing;
}
21 changes: 21 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end

def new
@user = User.new
end

def create
@user = User.new(user_params)
if @user.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
8 changes: 8 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
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 @@ -10,8 +10,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: 21 additions & 2 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<% provide(:title, 'Sign up') %>

<h1>Sign Up</h1>

<p>This will be the page where users sign up</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.email_field :email, class: 'form-control' %>

<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>

<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, class: 'form-control' %>

<%= f.submit "Create my Account", class: "btn btn-primary" %>
<% end %>
</div>
</div>
12 changes: 12 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= 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

# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
Expand Down
27 changes: 27 additions & 0 deletions test/integration/users_signup_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'test_helper'

class UsersSignupTest < ActionDispatch::IntegrationTest

test "invalid signup information" do
get signup_path
assert_no_difference 'User.count' do
post users_path, user: { name: "",
email: "user@invalid",
password: "foo",
password_confirmation: "bar"}
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 7770a5f

Please sign in to comment.