Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: Milhouse/demo_app
base: edce99383a
...
head fork: Milhouse/demo_app
compare: bbf41f3e5b
  • 2 commits
  • 32 files changed
  • 0 commit comments
  • 1 contributor
Showing with 585 additions and 0 deletions.
  1. +3 −0  app/assets/javascripts/microposts.js.coffee
  2. +3 −0  app/assets/javascripts/users.js.coffee
  3. +3 −0  app/assets/stylesheets/microposts.css.scss
  4. +56 −0 app/assets/stylesheets/scaffolds.css.scss
  5. +3 −0  app/assets/stylesheets/users.css.scss
  6. +83 −0 app/controllers/microposts_controller.rb
  7. +83 −0 app/controllers/users_controller.rb
  8. +2 −0  app/helpers/microposts_helper.rb
  9. +2 −0  app/helpers/users_helper.rb
  10. +4 −0 app/models/micropost.rb
  11. +3 −0  app/models/user.rb
  12. +25 −0 app/views/microposts/_form.html.erb
  13. +6 −0 app/views/microposts/edit.html.erb
  14. +25 −0 app/views/microposts/index.html.erb
  15. +5 −0 app/views/microposts/new.html.erb
  16. +15 −0 app/views/microposts/show.html.erb
  17. +25 −0 app/views/users/_form.html.erb
  18. +6 −0 app/views/users/edit.html.erb
  19. +25 −0 app/views/users/index.html.erb
  20. +5 −0 app/views/users/new.html.erb
  21. +15 −0 app/views/users/show.html.erb
  22. +10 −0 db/migrate/20120218190938_create_users.rb
  23. +10 −0 db/migrate/20120218191622_create_microposts.rb
  24. +30 −0 db/schema.rb
  25. +9 −0 test/fixtures/microposts.yml
  26. +9 −0 test/fixtures/users.yml
  27. +49 −0 test/functional/microposts_controller_test.rb
  28. +49 −0 test/functional/users_controller_test.rb
  29. +4 −0 test/unit/helpers/microposts_helper_test.rb
  30. +4 −0 test/unit/helpers/users_helper_test.rb
  31. +7 −0 test/unit/micropost_test.rb
  32. +7 −0 test/unit/user_test.rb
3  app/assets/javascripts/microposts.js.coffee
View
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/javascripts/users.js.coffee
View
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/stylesheets/microposts.css.scss
View
@@ -0,0 +1,3 @@
+// Place all the styles related to the Microposts controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
56 app/assets/stylesheets/scaffolds.css.scss
View
@@ -0,0 +1,56 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px; }
+
+a {
+ color: #000;
+ &:visited {
+ color: #666; }
+ &:hover {
+ color: #fff;
+ background-color: #000; } }
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px; } }
+
+#notice {
+ color: green; }
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table; }
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff; }
+ ul li {
+ font-size: 12px;
+ list-style: square; } }
3  app/assets/stylesheets/users.css.scss
View
@@ -0,0 +1,3 @@
+// Place all the styles related to the Users controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
83 app/controllers/microposts_controller.rb
View
@@ -0,0 +1,83 @@
+class MicropostsController < ApplicationController
+ # GET /microposts
+ # GET /microposts.json
+ def index
+ @microposts = Micropost.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @microposts }
+ end
+ end
+
+ # GET /microposts/1
+ # GET /microposts/1.json
+ def show
+ @micropost = Micropost.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @micropost }
+ end
+ end
+
+ # GET /microposts/new
+ # GET /microposts/new.json
+ def new
+ @micropost = Micropost.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @micropost }
+ end
+ end
+
+ # GET /microposts/1/edit
+ def edit
+ @micropost = Micropost.find(params[:id])
+ end
+
+ # POST /microposts
+ # POST /microposts.json
+ def create
+ @micropost = Micropost.new(params[:micropost])
+
+ respond_to do |format|
+ if @micropost.save
+ format.html { redirect_to @micropost, notice: 'Micropost was successfully created.' }
+ format.json { render json: @micropost, status: :created, location: @micropost }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @micropost.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /microposts/1
+ # PUT /microposts/1.json
+ def update
+ @micropost = Micropost.find(params[:id])
+
+ respond_to do |format|
+ if @micropost.update_attributes(params[:micropost])
+ format.html { redirect_to @micropost, notice: 'Micropost was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @micropost.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /microposts/1
+ # DELETE /microposts/1.json
+ def destroy
+ @micropost = Micropost.find(params[:id])
+ @micropost.destroy
+
+ respond_to do |format|
+ format.html { redirect_to microposts_url }
+ format.json { head :no_content }
+ end
+ end
+end
83 app/controllers/users_controller.rb
View
@@ -0,0 +1,83 @@
+class UsersController < ApplicationController
+ # GET /users
+ # GET /users.json
+ def index
+ @users = User.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @users }
+ end
+ end
+
+ # GET /users/1
+ # GET /users/1.json
+ def show
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @user }
+ end
+ end
+
+ # GET /users/new
+ # GET /users/new.json
+ def new
+ @user = User.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @user }
+ end
+ end
+
+ # GET /users/1/edit
+ def edit
+ @user = User.find(params[:id])
+ end
+
+ # POST /users
+ # POST /users.json
+ def create
+ @user = User.new(params[:user])
+
+ respond_to do |format|
+ if @user.save
+ format.html { redirect_to @user, notice: 'User was successfully created.' }
+ format.json { render json: @user, status: :created, location: @user }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @user.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /users/1
+ # PUT /users/1.json
+ def update
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ if @user.update_attributes(params[:user])
+ format.html { redirect_to @user, notice: 'User was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @user.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /users/1
+ # DELETE /users/1.json
+ def destroy
+ @user = User.find(params[:id])
+ @user.destroy
+
+ respond_to do |format|
+ format.html { redirect_to users_url }
+ format.json { head :no_content }
+ end
+ end
+end
2  app/helpers/microposts_helper.rb
View
@@ -0,0 +1,2 @@
+module MicropostsHelper
+end
2  app/helpers/users_helper.rb
View
@@ -0,0 +1,2 @@
+module UsersHelper
+end
4 app/models/micropost.rb
View
@@ -0,0 +1,4 @@
+class Micropost < ActiveRecord::Base
+ belongs_to :user
+ validates :content, :length => { :maximum => 140 }
+end
3  app/models/user.rb
View
@@ -0,0 +1,3 @@
+class User < ActiveRecord::Base
+ has_many :microposts
+end
25 app/views/microposts/_form.html.erb
View
@@ -0,0 +1,25 @@
+<%= form_for(@micropost) do |f| %>
+ <% if @micropost.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@micropost.errors.count, "error") %> prohibited this micropost from being saved:</h2>
+
+ <ul>
+ <% @micropost.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :content %><br />
+ <%= f.text_field :content %>
+ </div>
+ <div class="field">
+ <%= f.label :user_id %><br />
+ <%= f.number_field :user_id %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
6 app/views/microposts/edit.html.erb
View
@@ -0,0 +1,6 @@
+<h1>Editing micropost</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @micropost %> |
+<%= link_to 'Back', microposts_path %>
25 app/views/microposts/index.html.erb
View
@@ -0,0 +1,25 @@
+<h1>Listing microposts</h1>
+
+<table>
+ <tr>
+ <th>Content</th>
+ <th>User</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @microposts.each do |micropost| %>
+ <tr>
+ <td><%= micropost.content %></td>
+ <td><%= micropost.user_id %></td>
+ <td><%= link_to 'Show', micropost %></td>
+ <td><%= link_to 'Edit', edit_micropost_path(micropost) %></td>
+ <td><%= link_to 'Destroy', micropost, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Micropost', new_micropost_path %>
5 app/views/microposts/new.html.erb
View
@@ -0,0 +1,5 @@
+<h1>New micropost</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', microposts_path %>
15 app/views/microposts/show.html.erb
View
@@ -0,0 +1,15 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Content:</b>
+ <%= @micropost.content %>
+</p>
+
+<p>
+ <b>User:</b>
+ <%= @micropost.user_id %>
+</p>
+
+
+<%= link_to 'Edit', edit_micropost_path(@micropost) %> |
+<%= link_to 'Back', microposts_path %>
25 app/views/users/_form.html.erb
View
@@ -0,0 +1,25 @@
+<%= form_for(@user) do |f| %>
+ <% if @user.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
+
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
6 app/views/users/edit.html.erb
View
@@ -0,0 +1,6 @@
+<h1>Editing user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @user %> |
+<%= link_to 'Back', users_path %>
25 app/views/users/index.html.erb
View
@@ -0,0 +1,25 @@
+<h1>Listing users</h1>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Email</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @users.each do |user| %>
+ <tr>
+ <td><%= user.name %></td>
+ <td><%= user.email %></td>
+ <td><%= link_to 'Show', user %></td>
+ <td><%= link_to 'Edit', edit_user_path(user) %></td>
+ <td><%= link_to 'Destroy', user, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New User', new_user_path %>
5 app/views/users/new.html.erb
View
@@ -0,0 +1,5 @@
+<h1>New user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', users_path %>
15 app/views/users/show.html.erb
View
@@ -0,0 +1,15 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Name:</b>
+ <%= @user.name %>
+</p>
+
+<p>
+ <b>Email:</b>
+ <%= @user.email %>
+</p>
+
+
+<%= link_to 'Edit', edit_user_path(@user) %> |
+<%= link_to 'Back', users_path %>
10 db/migrate/20120218190938_create_users.rb
View
@@ -0,0 +1,10 @@
+class CreateUsers < ActiveRecord::Migration
+ def change
+ create_table :users do |t|
+ t.string :name
+ t.string :email
+
+ t.timestamps
+ end
+ end
+end
10 db/migrate/20120218191622_create_microposts.rb
View
@@ -0,0 +1,10 @@
+class CreateMicroposts < ActiveRecord::Migration
+ def change
+ create_table :microposts do |t|
+ t.string :content
+ t.integer :user_id
+
+ t.timestamps
+ end
+ end
+end
30 db/schema.rb
View
@@ -0,0 +1,30 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20120218191622) do
+
+ create_table "microposts", :force => true do |t|
+ t.string "content"
+ t.integer "user_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "users", :force => true do |t|
+ t.string "name"
+ t.string "email"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+end
9 test/fixtures/microposts.yml
View
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ content: MyString
+ user_id: 1
+
+two:
+ content: MyString
+ user_id: 1
9 test/fixtures/users.yml
View
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+ email: MyString
+
+two:
+ name: MyString
+ email: MyString
49 test/functional/microposts_controller_test.rb
View
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class MicropostsControllerTest < ActionController::TestCase
+ setup do
+ @micropost = microposts(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:microposts)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create micropost" do
+ assert_difference('Micropost.count') do
+ post :create, micropost: @micropost.attributes
+ end
+
+ assert_redirected_to micropost_path(assigns(:micropost))
+ end
+
+ test "should show micropost" do
+ get :show, id: @micropost
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @micropost
+ assert_response :success
+ end
+
+ test "should update micropost" do
+ put :update, id: @micropost, micropost: @micropost.attributes
+ assert_redirected_to micropost_path(assigns(:micropost))
+ end
+
+ test "should destroy micropost" do
+ assert_difference('Micropost.count', -1) do
+ delete :destroy, id: @micropost
+ end
+
+ assert_redirected_to microposts_path
+ end
+end
49 test/functional/users_controller_test.rb
View
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class UsersControllerTest < ActionController::TestCase
+ setup do
+ @user = users(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:users)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create user" do
+ assert_difference('User.count') do
+ post :create, user: @user.attributes
+ end
+
+ assert_redirected_to user_path(assigns(:user))
+ end
+
+ test "should show user" do
+ get :show, id: @user
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @user
+ assert_response :success
+ end
+
+ test "should update user" do
+ put :update, id: @user, user: @user.attributes
+ assert_redirected_to user_path(assigns(:user))
+ end
+
+ test "should destroy user" do
+ assert_difference('User.count', -1) do
+ delete :destroy, id: @user
+ end
+
+ assert_redirected_to users_path
+ end
+end
4 test/unit/helpers/microposts_helper_test.rb
View
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class MicropostsHelperTest < ActionView::TestCase
+end
4 test/unit/helpers/users_helper_test.rb
View
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class UsersHelperTest < ActionView::TestCase
+end
7 test/unit/micropost_test.rb
View
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class MicropostTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
7 test/unit/user_test.rb
View
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class UserTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

No commit comments for this range

Something went wrong with that request. Please try again.