Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: wdk122/sample_app
base: e42afc7a29
...
head fork: wdk122/sample_app
compare: 40b1d819ea
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 12 files changed
  • 0 commit comments
  • 1 contributor
View
95 app/assets/stylesheets/custom.css.scss
@@ -4,6 +4,12 @@
$grayMediumLight: #eaeaea;
+@mixin box_sizing {
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ box-sizing: border-box;
+}
+
/* universal */
html {
@@ -98,4 +104,91 @@ footer {
margin-left: 10px;
}
}
-}
+}
+
+/* miscellaneous */
+
+.debug_dump {
+ clear: both;
+ float: left;
+ width: 100%;
+ margin-top: 45px;
+ @include box_sizing;
+}
+
+/* sidebar */
+aside {
+ section {
+ padding: 10px 0;
+ border-top: 1px solid $grayLighter;
+ &:first-child {
+ border: 0;
+ padding-top: 0;
+ }
+ span {
+ display: block;
+ margin-bottom: 3px;
+ line-height: 1;
+ }
+ h1 {
+ font-size: 1.6em;
+ text-align: left;
+ letter-spacing: -1px;
+ margin-bottom: 3px;
+ }
+ }
+}
+
+.gravatar {
+ float: left;
+ margin-right: 10px;
+}
+
+/* forms */
+
+input, textarea, select, .uneditable-input {
+ border: 1px solid #bbb;
+ width: 100%;
+ padding: 10px;
+ margin-bottom: 15px;
+ @include box_sizing;
+}
+
+input {
+ height: auto !important;
+}
+
+#error_explanation {
+ color: #f00;
+ ul {
+ list-style: none;
+ margin: 0 0 18px 0;
+ }
+}
+
+.field_with_errors {
+ @extend .control-group;
+ @extend .error;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
20 app/controllers/users_controller.rb
@@ -1,4 +1,20 @@
class UsersController < ApplicationController
- def new
- end
+
+ def show
+ @user = User.find(params[:id])
+ end
+
+ def new
+ @user = User.new
+ end
+
+ def create
+ @user = User.new(params[:user])
+ if @user.save
+ flash[:success] = "Welcome to the Sample App!"
+ redirect_to @user
+ else
+ render 'new'
+ end
+ end
end
View
7 app/helpers/users_helper.rb
@@ -1,2 +1,9 @@
module UsersHelper
+
+ # Returns the Gravatar (http://gravatar.com/) 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
View
4 app/views/layouts/application.html.erb
@@ -10,8 +10,12 @@
<body>
<%= render 'layouts/header' %>
<div class="container">
+ <% flash.each do |key, value| %>
+ <div class="alert alert-<%= key %>"><%= value %></div>
+ <% end %>
<%= yield %>
<%= render 'layouts/footer' %>
+ <%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
View
12 app/views/shared/_error_messages.html.erb
@@ -0,0 +1,12 @@
+<% if @user.errors.any? %>
+ <div id="error_explanation">
+ <div class="alert alert-error">
+ The form contains <%= pluralize(@user.errors.count, "error") %>.
+ </div>
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li>* <%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+<% end %>
View
24 app/views/users/new.html.erb
@@ -1,3 +1,25 @@
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
-<p>Find me in app/views/users/new.html.erb</p>
+
+<div class="row">
+ <div class="span6 offset3">
+ <%= form_for(@user) do |f| %>
+
+ <%= render 'shared/error_messages' %>
+
+ <%= f.label :name %>
+ <%= f.text_field :name %>
+
+ <%= f.label :email %>
+ <%= f.text_field :email %>
+
+ <%= f.label :password %>
+ <%= f.password_field :password %>
+
+ <%= f.label :password_confirmation, "Confirmation" %>
+ <%= f.password_field :password_confirmation %>
+
+ <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
+ <% end %>
+ </div>
+</div>
View
11 app/views/users/show.html.erb
@@ -0,0 +1,11 @@
+<% provide(:title, @user.name) %>
+<div class="row">
+ <aside class="span4">
+ <section>
+ <h1>
+ <%= gravatar_for @user %>
+ <%= @user.name %>
+ </h1>
+ </section>
+ </aside>
+</div>
View
2  config/environments/production.rb
@@ -28,7 +28,7 @@
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
- # config.force_ssl = true
+ config.force_ssl = true
# See everything in the log (default is :info)
# config.log_level = :debug
View
6 config/environments/test.rb
@@ -34,4 +34,10 @@
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
+
+ # Speed up tests by lowering BCrypt's cost function.
+ require 'bcrypt'
+ silence_warnings do
+ BCrypt::Engine::DEFAULT_COST = BCrypt::Engine::MIN_COST
+ end
end
View
6 config/routes.rb
@@ -1,5 +1,6 @@
SampleApp::Application.routes.draw do
- get "users/new" #this line doesn't follow REST
+
+ resources :users
root to: 'static_pages#home'
@@ -7,7 +8,8 @@
match "/help", to: 'static_pages#help' #matches "/help" to the help action in StaticPages controller
match "/about", to: 'static_pages#about'
- match "/contact", to: 'static_pages#contact'
+ match "/contact", to: 'static_pages#contact'
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
8 spec/factories.rb
@@ -0,0 +1,8 @@
+FactoryGirl.define do
+ factory :user do
+ name "Michael Hartl"
+ email "michael@example.com"
+ password "foobar"
+ password_confirmation "foobar"
+ end
+end
View
40 spec/requests/user_pages_spec.rb
@@ -4,10 +4,44 @@
subject { page }
+ describe "profile page" do
+ let(:user) { FactoryGirl.create(:user) }
+ before { visit user_path(user) }
+
+ it { should have_selector('h1', text: user.name) }
+ it { should have_selector('title', text: user.name) }
+ end
+
describe "signup page" do
before { visit signup_path }
- it { should have_selector('h1', text: 'Sign up') }
- it { should have_selector('title', text: full_title('Sign up')) }
+ it { should have_selector('h1', text: 'Sign up') }
+ it { should have_selector('title', text: 'Sign up') }
end
-end
+
+ describe "signup" do
+ before { visit signup_path }
+
+ let(:submit) { "Create my account" }
+
+ describe "with invalid information" do
+ it "should not create a user" do
+ expect { click_button submit }.not_to change(User, :count)
+ end
+ end
+
+ describe "with valid information" do
+ before do
+ fill_in "Name", with: "Example User"
+ fill_in "Email", with: "user@example.com"
+ fill_in "Password", with: "foobar"
+ fill_in "Confirmation", with: "foobar"
+ end
+
+ it "should create a user" do
+ expect { click_button submit }.to change(User, :count).by(1)
+ end
+ end
+ end
+end
+

No commit comments for this range

Something went wrong with that request. Please try again.