From 808f70d0fd542e6b56e43cc8adbda90277c5017f Mon Sep 17 00:00:00 2001 From: int Date: Thu, 8 Mar 2012 17:39:34 +0400 Subject: [PATCH] final add --- app/assets/javascripts/home.js.coffee | 3 + app/assets/javascripts/microposts.js.coffee | 3 + app/assets/javascripts/posts.js.coffee | 3 + app/assets/javascripts/users.js.coffee | 3 + app/assets/stylesheets/home.css.scss | 3 + app/assets/stylesheets/microposts.css.scss | 3 + app/assets/stylesheets/posts.css.scss | 3 + app/assets/stylesheets/scaffolds.css.scss | 56 +++++++++++++ app/assets/stylesheets/users.css.scss | 3 + app/controllers/home_controller.rb | 4 + app/controllers/microposts_controller.rb | 83 +++++++++++++++++++ app/controllers/posts_controller.rb | 83 +++++++++++++++++++ app/controllers/users_controller.rb | 83 +++++++++++++++++++ app/helpers/home_helper.rb | 2 + app/helpers/microposts_helper.rb | 2 + app/helpers/posts_helper.rb | 2 + app/helpers/users_helper.rb | 2 + app/models/micropost.rb | 4 + app/models/post.rb | 2 + app/views/home/index.html.erb | 10 +++ app/views/microposts/_form.html.erb | 25 ++++++ app/views/microposts/edit.html.erb | 6 ++ app/views/microposts/index.html.erb | 26 ++++++ app/views/microposts/new.html.erb | 5 ++ app/views/microposts/show.html.erb | 15 ++++ app/views/posts/_form.html.erb | 29 +++++++ app/views/posts/edit.html.erb | 6 ++ app/views/posts/index.html.erb | 27 ++++++ app/views/posts/new.html.erb | 5 ++ app/views/posts/show.html.erb | 20 +++++ app/views/users/_form.html.erb | 25 ++++++ app/views/users/edit.html.erb | 6 ++ app/views/users/index.html.erb | 25 ++++++ app/views/users/new.html.erb | 5 ++ app/views/users/show.html.erb | 15 ++++ db/migrate/20120308121033_create_posts.rb | 11 +++ db/migrate/20120308121553_create_users.rb | 10 +++ .../20120308123643_create_microposts.rb | 10 +++ db/schema.rb | 38 +++++++++ test/fixtures/microposts.yml | 9 ++ test/fixtures/posts.yml | 11 +++ test/fixtures/users.yml | 9 ++ test/functional/home_controller_test.rb | 9 ++ test/functional/microposts_controller_test.rb | 49 +++++++++++ test/functional/posts_controller_test.rb | 49 +++++++++++ test/functional/users_controller_test.rb | 49 +++++++++++ test/unit/helpers/home_helper_test.rb | 4 + test/unit/helpers/microposts_helper_test.rb | 4 + test/unit/helpers/posts_helper_test.rb | 4 + test/unit/helpers/users_helper_test.rb | 4 + test/unit/micropost_test.rb | 7 ++ test/unit/post_test.rb | 7 ++ test/unit/user_test.rb | 7 ++ 53 files changed, 888 insertions(+) create mode 100644 app/assets/javascripts/home.js.coffee create mode 100644 app/assets/javascripts/microposts.js.coffee create mode 100644 app/assets/javascripts/posts.js.coffee create mode 100644 app/assets/javascripts/users.js.coffee create mode 100644 app/assets/stylesheets/home.css.scss create mode 100644 app/assets/stylesheets/microposts.css.scss create mode 100644 app/assets/stylesheets/posts.css.scss create mode 100644 app/assets/stylesheets/scaffolds.css.scss create mode 100644 app/assets/stylesheets/users.css.scss create mode 100644 app/controllers/home_controller.rb create mode 100644 app/controllers/microposts_controller.rb create mode 100644 app/controllers/posts_controller.rb create mode 100644 app/controllers/users_controller.rb create mode 100644 app/helpers/home_helper.rb create mode 100644 app/helpers/microposts_helper.rb create mode 100644 app/helpers/posts_helper.rb create mode 100644 app/helpers/users_helper.rb create mode 100644 app/models/micropost.rb create mode 100644 app/models/post.rb create mode 100644 app/views/home/index.html.erb create mode 100644 app/views/microposts/_form.html.erb create mode 100644 app/views/microposts/edit.html.erb create mode 100644 app/views/microposts/index.html.erb create mode 100644 app/views/microposts/new.html.erb create mode 100644 app/views/microposts/show.html.erb create mode 100644 app/views/posts/_form.html.erb create mode 100644 app/views/posts/edit.html.erb create mode 100644 app/views/posts/index.html.erb create mode 100644 app/views/posts/new.html.erb create mode 100644 app/views/posts/show.html.erb create mode 100644 app/views/users/_form.html.erb create mode 100644 app/views/users/edit.html.erb create mode 100644 app/views/users/index.html.erb create mode 100644 app/views/users/new.html.erb create mode 100644 app/views/users/show.html.erb create mode 100644 db/migrate/20120308121033_create_posts.rb create mode 100644 db/migrate/20120308121553_create_users.rb create mode 100644 db/migrate/20120308123643_create_microposts.rb create mode 100644 db/schema.rb create mode 100644 test/fixtures/microposts.yml create mode 100644 test/fixtures/posts.yml create mode 100644 test/fixtures/users.yml create mode 100644 test/functional/home_controller_test.rb create mode 100644 test/functional/microposts_controller_test.rb create mode 100644 test/functional/posts_controller_test.rb create mode 100644 test/functional/users_controller_test.rb create mode 100644 test/unit/helpers/home_helper_test.rb create mode 100644 test/unit/helpers/microposts_helper_test.rb create mode 100644 test/unit/helpers/posts_helper_test.rb create mode 100644 test/unit/helpers/users_helper_test.rb create mode 100644 test/unit/micropost_test.rb create mode 100644 test/unit/post_test.rb create mode 100644 test/unit/user_test.rb diff --git a/app/assets/javascripts/home.js.coffee b/app/assets/javascripts/home.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/home.js.coffee @@ -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/ diff --git a/app/assets/javascripts/microposts.js.coffee b/app/assets/javascripts/microposts.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/microposts.js.coffee @@ -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/ diff --git a/app/assets/javascripts/posts.js.coffee b/app/assets/javascripts/posts.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/posts.js.coffee @@ -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/ diff --git a/app/assets/javascripts/users.js.coffee b/app/assets/javascripts/users.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/users.js.coffee @@ -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/ diff --git a/app/assets/stylesheets/home.css.scss b/app/assets/stylesheets/home.css.scss new file mode 100644 index 0000000..f0ddc68 --- /dev/null +++ b/app/assets/stylesheets/home.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the home controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/microposts.css.scss b/app/assets/stylesheets/microposts.css.scss new file mode 100644 index 0000000..c14d62c --- /dev/null +++ b/app/assets/stylesheets/microposts.css.scss @@ -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/ diff --git a/app/assets/stylesheets/posts.css.scss b/app/assets/stylesheets/posts.css.scss new file mode 100644 index 0000000..ed4dfd1 --- /dev/null +++ b/app/assets/stylesheets/posts.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Posts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 0000000..05188f0 --- /dev/null +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -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; } } diff --git a/app/assets/stylesheets/users.css.scss b/app/assets/stylesheets/users.css.scss new file mode 100644 index 0000000..31a2eac --- /dev/null +++ b/app/assets/stylesheets/users.css.scss @@ -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/ diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..95f2992 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,4 @@ +class HomeController < ApplicationController + def index + end +end diff --git a/app/controllers/microposts_controller.rb b/app/controllers/microposts_controller.rb new file mode 100644 index 0000000..6ed1cd4 --- /dev/null +++ b/app/controllers/microposts_controller.rb @@ -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 diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb new file mode 100644 index 0000000..6f4fb40 --- /dev/null +++ b/app/controllers/posts_controller.rb @@ -0,0 +1,83 @@ +class PostsController < ApplicationController + # GET /posts + # GET /posts.json + def index + @posts = Post.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @posts } + end + end + + # GET /posts/1 + # GET /posts/1.json + def show + @post = Post.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @post } + end + end + + # GET /posts/new + # GET /posts/new.json + def new + @post = Post.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @post } + end + end + + # GET /posts/1/edit + def edit + @post = Post.find(params[:id]) + end + + # POST /posts + # POST /posts.json + def create + @post = Post.new(params[:post]) + + respond_to do |format| + if @post.save + format.html { redirect_to @post, notice: 'Post was successfully created.' } + format.json { render json: @post, status: :created, location: @post } + else + format.html { render action: "new" } + format.json { render json: @post.errors, status: :unprocessable_entity } + end + end + end + + # PUT /posts/1 + # PUT /posts/1.json + def update + @post = Post.find(params[:id]) + + respond_to do |format| + if @post.update_attributes(params[:post]) + format.html { redirect_to @post, notice: 'Post was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @post.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /posts/1 + # DELETE /posts/1.json + def destroy + @post = Post.find(params[:id]) + @post.destroy + + respond_to do |format| + format.html { redirect_to posts_url } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..dcf538d --- /dev/null +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/helpers/microposts_helper.rb b/app/helpers/microposts_helper.rb new file mode 100644 index 0000000..f08aad2 --- /dev/null +++ b/app/helpers/microposts_helper.rb @@ -0,0 +1,2 @@ +module MicropostsHelper +end diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb new file mode 100644 index 0000000..a7b8cec --- /dev/null +++ b/app/helpers/posts_helper.rb @@ -0,0 +1,2 @@ +module PostsHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000..2310a24 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/micropost.rb b/app/models/micropost.rb new file mode 100644 index 0000000..e6ca567 --- /dev/null +++ b/app/models/micropost.rb @@ -0,0 +1,4 @@ +class Micropost < ActiveRecord::Base + belongs_to :user + validates :content, :length => { :maximum => 10 } +end diff --git a/app/models/post.rb b/app/models/post.rb new file mode 100644 index 0000000..791dcb5 --- /dev/null +++ b/app/models/post.rb @@ -0,0 +1,2 @@ +class Post < ActiveRecord::Base +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 0000000..92b6cd4 --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,10 @@ +

Заголовок

+

Моё первое приложение для web на ruby on rails ;)

+ +

Hello, Rails!

+ +<%= link_to "Пробный Блог", posts_path %> + +<%= link_to "Юзеры", users_path %> + +<%= link_to "Микропосты", microposts_path %> diff --git a/app/views/microposts/_form.html.erb b/app/views/microposts/_form.html.erb new file mode 100644 index 0000000..88d3896 --- /dev/null +++ b/app/views/microposts/_form.html.erb @@ -0,0 +1,25 @@ +<%= form_for(@micropost) do |f| %> + <% if @micropost.errors.any? %> +
+

<%= pluralize(@micropost.errors.count, "ошибка(ки)") %> мешают созданию этого микропоста:

+ + +
+ <% end %> + +
+ <%= f.label :content %>
+ <%= f.text_field :content %> +
+
+ <%= f.label :user_id %>
+ <%= f.number_field :user_id %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/microposts/edit.html.erb b/app/views/microposts/edit.html.erb new file mode 100644 index 0000000..30f1480 --- /dev/null +++ b/app/views/microposts/edit.html.erb @@ -0,0 +1,6 @@ +

Editing micropost

+ +<%= render 'form' %> + +<%= link_to 'Show', @micropost %> | +<%= link_to 'Back', microposts_path %> diff --git a/app/views/microposts/index.html.erb b/app/views/microposts/index.html.erb new file mode 100644 index 0000000..a50f730 --- /dev/null +++ b/app/views/microposts/index.html.erb @@ -0,0 +1,26 @@ +

Listing microposts

+ + + + + + + + + + +<% @microposts.each do |micropost| %> + + + + + + + +<% end %> +
ContentUser
<%= micropost.content %><%= micropost.user_id %><%= link_to 'Show', micropost %><%= link_to 'Edit', edit_micropost_path(micropost) %><%= link_to 'Destroy', micropost, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Micropost', new_micropost_path %> + diff --git a/app/views/microposts/new.html.erb b/app/views/microposts/new.html.erb new file mode 100644 index 0000000..b0ef41f --- /dev/null +++ b/app/views/microposts/new.html.erb @@ -0,0 +1,5 @@ +

New micropost

+ +<%= render 'form' %> + +<%= link_to 'Back', microposts_path %> diff --git a/app/views/microposts/show.html.erb b/app/views/microposts/show.html.erb new file mode 100644 index 0000000..e15f8ee --- /dev/null +++ b/app/views/microposts/show.html.erb @@ -0,0 +1,15 @@ +

<%= notice %>

+ +

+ Content: + <%= @micropost.content %> +

+ +

+ User: + <%= @micropost.user_id %> +

+ + +<%= link_to 'Edit', edit_micropost_path(@micropost) %> | +<%= link_to 'Back', microposts_path %> diff --git a/app/views/posts/_form.html.erb b/app/views/posts/_form.html.erb new file mode 100644 index 0000000..eddcce5 --- /dev/null +++ b/app/views/posts/_form.html.erb @@ -0,0 +1,29 @@ +<%= form_for(@post) do |f| %> + <% if @post.errors.any? %> +
+

<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :name %>
+ <%= f.text_field :name %> +
+
+ <%= f.label :title %>
+ <%= f.text_field :title %> +
+
+ <%= f.label :content %>
+ <%= f.text_area :content %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/posts/edit.html.erb b/app/views/posts/edit.html.erb new file mode 100644 index 0000000..7205802 --- /dev/null +++ b/app/views/posts/edit.html.erb @@ -0,0 +1,6 @@ +

Editing post

+ +<%= render 'form' %> + +<%= link_to 'Show', @post %> | +<%= link_to 'Back', posts_path %> diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb new file mode 100644 index 0000000..45dee1b --- /dev/null +++ b/app/views/posts/index.html.erb @@ -0,0 +1,27 @@ +

Listing posts

+ + + + + + + + + + + +<% @posts.each do |post| %> + + + + + + + + +<% end %> +
NameTitleContent
<%= post.name %><%= post.title %><%= post.content %><%= link_to 'Show', post %><%= link_to 'Edit', edit_post_path(post) %><%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Post', new_post_path %> diff --git a/app/views/posts/new.html.erb b/app/views/posts/new.html.erb new file mode 100644 index 0000000..36ad742 --- /dev/null +++ b/app/views/posts/new.html.erb @@ -0,0 +1,5 @@ +

New post

+ +<%= render 'form' %> + +<%= link_to 'Back', posts_path %> diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb new file mode 100644 index 0000000..a448a50 --- /dev/null +++ b/app/views/posts/show.html.erb @@ -0,0 +1,20 @@ +

<%= notice %>

+ +

+ Name: + <%= @post.name %> +

+ +

+ Title: + <%= @post.title %> +

+ +

+ Content: + <%= @post.content %> +

+ + +<%= link_to 'Edit', edit_post_path(@post) %> | +<%= link_to 'Back', posts_path %> diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb new file mode 100644 index 0000000..8c2c67b --- /dev/null +++ b/app/views/users/_form.html.erb @@ -0,0 +1,25 @@ +<%= form_for(@user) do |f| %> + <% if @user.errors.any? %> +
+

<%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :name %>
+ <%= f.text_field :name %> +
+
+ <%= f.label :email %>
+ <%= f.text_field :email %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb new file mode 100644 index 0000000..99bd4cc --- /dev/null +++ b/app/views/users/edit.html.erb @@ -0,0 +1,6 @@ +

Editing user

+ +<%= render 'form' %> + +<%= link_to 'Show', @user %> | +<%= link_to 'Back', users_path %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 0000000..d2070a5 --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,25 @@ +

Listing users

+ + + + + + + + + + +<% @users.each do |user| %> + + + + + + + +<% end %> +
NameEmail
<%= user.name %><%= user.email %><%= link_to 'Show', user %><%= link_to 'Edit', edit_user_path(user) %><%= link_to 'Destroy', user, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New User', new_user_path %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 0000000..efc0404 --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,5 @@ +

New user

+ +<%= render 'form' %> + +<%= link_to 'Back', users_path %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000..72612cb --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,15 @@ +

<%= notice %>

+ +

+ Name: + <%= @user.name %> +

+ +

+ Email: + <%= @user.email %> +

+ + +<%= link_to 'Edit', edit_user_path(@user) %> | +<%= link_to 'Back', users_path %> diff --git a/db/migrate/20120308121033_create_posts.rb b/db/migrate/20120308121033_create_posts.rb new file mode 100644 index 0000000..d45a961 --- /dev/null +++ b/db/migrate/20120308121033_create_posts.rb @@ -0,0 +1,11 @@ +class CreatePosts < ActiveRecord::Migration + def change + create_table :posts do |t| + t.string :name + t.string :title + t.text :content + + t.timestamps + end + end +end diff --git a/db/migrate/20120308121553_create_users.rb b/db/migrate/20120308121553_create_users.rb new file mode 100644 index 0000000..7e0dcd9 --- /dev/null +++ b/db/migrate/20120308121553_create_users.rb @@ -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 diff --git a/db/migrate/20120308123643_create_microposts.rb b/db/migrate/20120308123643_create_microposts.rb new file mode 100644 index 0000000..1ea9615 --- /dev/null +++ b/db/migrate/20120308123643_create_microposts.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..f18e0de --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,38 @@ +# 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 => 20120308123643) 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 "posts", :force => true do |t| + t.string "name" + t.string "title" + t.text "content" + 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 diff --git a/test/fixtures/microposts.yml b/test/fixtures/microposts.yml new file mode 100644 index 0000000..0965034 --- /dev/null +++ b/test/fixtures/microposts.yml @@ -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 diff --git a/test/fixtures/posts.yml b/test/fixtures/posts.yml new file mode 100644 index 0000000..33ce9e2 --- /dev/null +++ b/test/fixtures/posts.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + name: MyString + title: MyString + content: MyText + +two: + name: MyString + title: MyString + content: MyText diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000..f070597 --- /dev/null +++ b/test/fixtures/users.yml @@ -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 diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb new file mode 100644 index 0000000..0d9bb47 --- /dev/null +++ b/test/functional/home_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class HomeControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + end + +end diff --git a/test/functional/microposts_controller_test.rb b/test/functional/microposts_controller_test.rb new file mode 100644 index 0000000..ae227c3 --- /dev/null +++ b/test/functional/microposts_controller_test.rb @@ -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 diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb new file mode 100644 index 0000000..20fde3e --- /dev/null +++ b/test/functional/posts_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class PostsControllerTest < ActionController::TestCase + setup do + @post = posts(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:posts) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create post" do + assert_difference('Post.count') do + post :create, post: @post.attributes + end + + assert_redirected_to post_path(assigns(:post)) + end + + test "should show post" do + get :show, id: @post + assert_response :success + end + + test "should get edit" do + get :edit, id: @post + assert_response :success + end + + test "should update post" do + put :update, id: @post, post: @post.attributes + assert_redirected_to post_path(assigns(:post)) + end + + test "should destroy post" do + assert_difference('Post.count', -1) do + delete :destroy, id: @post + end + + assert_redirected_to posts_path + end +end diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb new file mode 100644 index 0000000..9a5355e --- /dev/null +++ b/test/functional/users_controller_test.rb @@ -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 diff --git a/test/unit/helpers/home_helper_test.rb b/test/unit/helpers/home_helper_test.rb new file mode 100644 index 0000000..4740a18 --- /dev/null +++ b/test/unit/helpers/home_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class HomeHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/microposts_helper_test.rb b/test/unit/helpers/microposts_helper_test.rb new file mode 100644 index 0000000..cff90b5 --- /dev/null +++ b/test/unit/helpers/microposts_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class MicropostsHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/posts_helper_test.rb b/test/unit/helpers/posts_helper_test.rb new file mode 100644 index 0000000..48549c2 --- /dev/null +++ b/test/unit/helpers/posts_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class PostsHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/users_helper_test.rb b/test/unit/helpers/users_helper_test.rb new file mode 100644 index 0000000..96af37a --- /dev/null +++ b/test/unit/helpers/users_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class UsersHelperTest < ActionView::TestCase +end diff --git a/test/unit/micropost_test.rb b/test/unit/micropost_test.rb new file mode 100644 index 0000000..def8e93 --- /dev/null +++ b/test/unit/micropost_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MicropostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb new file mode 100644 index 0000000..6d9d463 --- /dev/null +++ b/test/unit/post_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb new file mode 100644 index 0000000..82f61e0 --- /dev/null +++ b/test/unit/user_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end