Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

scaffold user, club

  • Loading branch information...
commit 573a67ce96b0a25b74fb573d145721f9788f82c2 1 parent 5d63bbb
@fr-fujiwara fr-fujiwara authored
Showing with 1,027 additions and 0 deletions.
  1. +3 −0  app/assets/javascripts/clubs.js.coffee
  2. +3 −0  app/assets/javascripts/users.js.coffee
  3. +3 −0  app/assets/stylesheets/clubs.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/clubs_controller.rb
  7. +83 −0 app/controllers/users_controller.rb
  8. +2 −0  app/helpers/clubs_helper.rb
  9. +2 −0  app/helpers/users_helper.rb
  10. +2 −0  app/models/club.rb
  11. +2 −0  app/models/user.rb
  12. +13 −0 app/views/clubs/_form.html.haml
  13. +7 −0 app/views/clubs/edit.html.haml
  14. +19 −0 app/views/clubs/index.html.haml
  15. +5 −0 app/views/clubs/new.html.haml
  16. +9 −0 app/views/clubs/show.html.haml
  17. +16 −0 app/views/users/_form.html.haml
  18. +7 −0 app/views/users/edit.html.haml
  19. +21 −0 app/views/users/index.html.haml
  20. +5 −0 app/views/users/new.html.haml
  21. +12 −0 app/views/users/show.html.haml
  22. +4 −0 config/routes.rb
  23. +10 −0 db/migrate/20120416061301_create_users.rb
  24. +9 −0 db/migrate/20120416061347_create_clubs.rb
  25. +37 −0 db/schema.rb
  26. +164 −0 spec/controllers/clubs_controller_spec.rb
  27. +164 −0 spec/controllers/users_controller_spec.rb
  28. +15 −0 spec/helpers/clubs_helper_spec.rb
  29. +15 −0 spec/helpers/users_helper_spec.rb
  30. +5 −0 spec/models/club_spec.rb
  31. +5 −0 spec/models/user_spec.rb
  32. +11 −0 spec/requests/clubs_spec.rb
  33. +11 −0 spec/requests/users_spec.rb
  34. +35 −0 spec/routing/clubs_routing_spec.rb
  35. +35 −0 spec/routing/users_routing_spec.rb
  36. +18 −0 spec/views/clubs/edit.html.haml_spec.rb
  37. +20 −0 spec/views/clubs/index.html.haml_spec.rb
  38. +18 −0 spec/views/clubs/new.html.haml_spec.rb
  39. +15 −0 spec/views/clubs/show.html.haml_spec.rb
  40. +20 −0 spec/views/users/edit.html.haml_spec.rb
  41. +23 −0 spec/views/users/index.html.haml_spec.rb
  42. +20 −0 spec/views/users/new.html.haml_spec.rb
  43. +17 −0 spec/views/users/show.html.haml_spec.rb
View
3  app/assets/javascripts/clubs.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/
View
3  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/
View
3  app/assets/stylesheets/clubs.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the clubs controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
56 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; } }
View
3  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/
View
83 app/controllers/clubs_controller.rb
@@ -0,0 +1,83 @@
+class ClubsController < ApplicationController
+ # GET /clubs
+ # GET /clubs.json
+ def index
+ @clubs = Club.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @clubs }
+ end
+ end
+
+ # GET /clubs/1
+ # GET /clubs/1.json
+ def show
+ @club = Club.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @club }
+ end
+ end
+
+ # GET /clubs/new
+ # GET /clubs/new.json
+ def new
+ @club = Club.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @club }
+ end
+ end
+
+ # GET /clubs/1/edit
+ def edit
+ @club = Club.find(params[:id])
+ end
+
+ # POST /clubs
+ # POST /clubs.json
+ def create
+ @club = Club.new(params[:club])
+
+ respond_to do |format|
+ if @club.save
+ format.html { redirect_to @club, notice: 'Club was successfully created.' }
+ format.json { render json: @club, status: :created, location: @club }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @club.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /clubs/1
+ # PUT /clubs/1.json
+ def update
+ @club = Club.find(params[:id])
+
+ respond_to do |format|
+ if @club.update_attributes(params[:club])
+ format.html { redirect_to @club, notice: 'Club was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @club.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /clubs/1
+ # DELETE /clubs/1.json
+ def destroy
+ @club = Club.find(params[:id])
+ @club.destroy
+
+ respond_to do |format|
+ format.html { redirect_to clubs_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
83 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
View
2  app/helpers/clubs_helper.rb
@@ -0,0 +1,2 @@
+module ClubsHelper
+end
View
2  app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
View
2  app/models/club.rb
@@ -0,0 +1,2 @@
+class Club < ActiveRecord::Base
+end
View
2  app/models/user.rb
@@ -0,0 +1,2 @@
+class User < ActiveRecord::Base
+end
View
13 app/views/clubs/_form.html.haml
@@ -0,0 +1,13 @@
+= form_for @club do |f|
+ -if @club.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(@club.errors.count, "error")} prohibited this club from being saved:"
+ %ul
+ - @club.errors.full_messages.each do |msg|
+ %li= msg
+
+ .field
+ = f.label :name
+ = f.text_field :name
+ .actions
+ = f.submit 'Save'
View
7 app/views/clubs/edit.html.haml
@@ -0,0 +1,7 @@
+%h1 Editing club
+
+= render 'form'
+
+= link_to 'Show', @club
+\|
+= link_to 'Back', clubs_path
View
19 app/views/clubs/index.html.haml
@@ -0,0 +1,19 @@
+%h1 Listing clubs
+
+%table
+ %tr
+ %th Name
+ %th
+ %th
+ %th
+
+ - @clubs.each do |club|
+ %tr
+ %td= club.name
+ %td= link_to 'Show', club
+ %td= link_to 'Edit', edit_club_path(club)
+ %td= link_to 'Destroy', club, :confirm => 'Are you sure?', :method => :delete
+
+%br
+
+= link_to 'New Club', new_club_path
View
5 app/views/clubs/new.html.haml
@@ -0,0 +1,5 @@
+%h1 New club
+
+= render 'form'
+
+= link_to 'Back', clubs_path
View
9 app/views/clubs/show.html.haml
@@ -0,0 +1,9 @@
+%p#notice= notice
+
+%p
+ %b Name:
+ = @club.name
+
+= link_to 'Edit', edit_club_path(@club)
+\|
+= link_to 'Back', clubs_path
View
16 app/views/users/_form.html.haml
@@ -0,0 +1,16 @@
+= form_for @user do |f|
+ -if @user.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(@user.errors.count, "error")} prohibited this user from being saved:"
+ %ul
+ - @user.errors.full_messages.each do |msg|
+ %li= msg
+
+ .field
+ = f.label :name
+ = f.text_field :name
+ .field
+ = f.label :club_id
+ = f.number_field :club_id
+ .actions
+ = f.submit 'Save'
View
7 app/views/users/edit.html.haml
@@ -0,0 +1,7 @@
+%h1 Editing user
+
+= render 'form'
+
+= link_to 'Show', @user
+\|
+= link_to 'Back', users_path
View
21 app/views/users/index.html.haml
@@ -0,0 +1,21 @@
+%h1 Listing users
+
+%table
+ %tr
+ %th Name
+ %th Club
+ %th
+ %th
+ %th
+
+ - @users.each do |user|
+ %tr
+ %td= user.name
+ %td= user.club_id
+ %td= link_to 'Show', user
+ %td= link_to 'Edit', edit_user_path(user)
+ %td= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete
+
+%br
+
+= link_to 'New User', new_user_path
View
5 app/views/users/new.html.haml
@@ -0,0 +1,5 @@
+%h1 New user
+
+= render 'form'
+
+= link_to 'Back', users_path
View
12 app/views/users/show.html.haml
@@ -0,0 +1,12 @@
+%p#notice= notice
+
+%p
+ %b Name:
+ = @user.name
+%p
+ %b Club:
+ = @user.club_id
+
+= link_to 'Edit', edit_user_path(@user)
+\|
+= link_to 'Back', users_path
View
4 config/routes.rb
@@ -1,4 +1,8 @@
C2::Application.routes.draw do
+ resources :clubs
+
+ resources :users
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
10 db/migrate/20120416061301_create_users.rb
@@ -0,0 +1,10 @@
+class CreateUsers < ActiveRecord::Migration
+ def change
+ create_table :users do |t|
+ t.string :name
+ t.integer :club_id
+
+ t.timestamps
+ end
+ end
+end
View
9 db/migrate/20120416061347_create_clubs.rb
@@ -0,0 +1,9 @@
+class CreateClubs < ActiveRecord::Migration
+ def change
+ create_table :clubs do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
View
37 db/schema.rb
@@ -0,0 +1,37 @@
+# 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 => 20120416054714) do
+
+ create_table "activities", :force => true do |t|
+ t.string "title"
+ t.integer "club_id"
+ t.string "photo"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "clubs", :force => true do |t|
+ t.string "name"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "users", :force => true do |t|
+ t.string "name"
+ t.integer "club_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+end
View
164 spec/controllers/clubs_controller_spec.rb
@@ -0,0 +1,164 @@
+require 'spec_helper'
+
+# This spec was generated by rspec-rails when you ran the scaffold generator.
+# It demonstrates how one might use RSpec to specify the controller code that
+# was generated by Rails when you ran the scaffold generator.
+#
+# It assumes that the implementation code is generated by the rails scaffold
+# generator. If you are using any extension libraries to generate different
+# controller code, this generated spec may or may not pass.
+#
+# It only uses APIs available in rails and/or rspec-rails. There are a number
+# of tools you can use to make these specs even more expressive, but we're
+# sticking to rails and rspec-rails APIs to keep things simple and stable.
+#
+# Compared to earlier versions of this generator, there is very limited use of
+# stubs and message expectations in this spec. Stubs are only used when there
+# is no simpler way to get a handle on the object needed for the example.
+# Message expectations are only used when there is no simpler way to specify
+# that an instance is receiving a specific message.
+
+describe ClubsController do
+
+ # This should return the minimal set of attributes required to create a valid
+ # Club. As you add validations to Club, be sure to
+ # update the return value of this method accordingly.
+ def valid_attributes
+ {}
+ end
+
+ # This should return the minimal set of values that should be in the session
+ # in order to pass any filters (e.g. authentication) defined in
+ # ClubsController. Be sure to keep this updated too.
+ def valid_session
+ {}
+ end
+
+ describe "GET index" do
+ it "assigns all clubs as @clubs" do
+ club = Club.create! valid_attributes
+ get :index, {}, valid_session
+ assigns(:clubs).should eq([club])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested club as @club" do
+ club = Club.create! valid_attributes
+ get :show, {:id => club.to_param}, valid_session
+ assigns(:club).should eq(club)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new club as @club" do
+ get :new, {}, valid_session
+ assigns(:club).should be_a_new(Club)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested club as @club" do
+ club = Club.create! valid_attributes
+ get :edit, {:id => club.to_param}, valid_session
+ assigns(:club).should eq(club)
+ end
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new Club" do
+ expect {
+ post :create, {:club => valid_attributes}, valid_session
+ }.to change(Club, :count).by(1)
+ end
+
+ it "assigns a newly created club as @club" do
+ post :create, {:club => valid_attributes}, valid_session
+ assigns(:club).should be_a(Club)
+ assigns(:club).should be_persisted
+ end
+
+ it "redirects to the created club" do
+ post :create, {:club => valid_attributes}, valid_session
+ response.should redirect_to(Club.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved club as @club" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Club.any_instance.stub(:save).and_return(false)
+ post :create, {:club => {}}, valid_session
+ assigns(:club).should be_a_new(Club)
+ end
+
+ it "re-renders the 'new' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Club.any_instance.stub(:save).and_return(false)
+ post :create, {:club => {}}, valid_session
+ response.should render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ it "updates the requested club" do
+ club = Club.create! valid_attributes
+ # Assuming there are no other clubs in the database, this
+ # specifies that the Club created on the previous line
+ # receives the :update_attributes message with whatever params are
+ # submitted in the request.
+ Club.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, {:id => club.to_param, :club => {'these' => 'params'}}, valid_session
+ end
+
+ it "assigns the requested club as @club" do
+ club = Club.create! valid_attributes
+ put :update, {:id => club.to_param, :club => valid_attributes}, valid_session
+ assigns(:club).should eq(club)
+ end
+
+ it "redirects to the club" do
+ club = Club.create! valid_attributes
+ put :update, {:id => club.to_param, :club => valid_attributes}, valid_session
+ response.should redirect_to(club)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the club as @club" do
+ club = Club.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ Club.any_instance.stub(:save).and_return(false)
+ put :update, {:id => club.to_param, :club => {}}, valid_session
+ assigns(:club).should eq(club)
+ end
+
+ it "re-renders the 'edit' template" do
+ club = Club.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ Club.any_instance.stub(:save).and_return(false)
+ put :update, {:id => club.to_param, :club => {}}, valid_session
+ response.should render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested club" do
+ club = Club.create! valid_attributes
+ expect {
+ delete :destroy, {:id => club.to_param}, valid_session
+ }.to change(Club, :count).by(-1)
+ end
+
+ it "redirects to the clubs list" do
+ club = Club.create! valid_attributes
+ delete :destroy, {:id => club.to_param}, valid_session
+ response.should redirect_to(clubs_url)
+ end
+ end
+
+end
View
164 spec/controllers/users_controller_spec.rb
@@ -0,0 +1,164 @@
+require 'spec_helper'
+
+# This spec was generated by rspec-rails when you ran the scaffold generator.
+# It demonstrates how one might use RSpec to specify the controller code that
+# was generated by Rails when you ran the scaffold generator.
+#
+# It assumes that the implementation code is generated by the rails scaffold
+# generator. If you are using any extension libraries to generate different
+# controller code, this generated spec may or may not pass.
+#
+# It only uses APIs available in rails and/or rspec-rails. There are a number
+# of tools you can use to make these specs even more expressive, but we're
+# sticking to rails and rspec-rails APIs to keep things simple and stable.
+#
+# Compared to earlier versions of this generator, there is very limited use of
+# stubs and message expectations in this spec. Stubs are only used when there
+# is no simpler way to get a handle on the object needed for the example.
+# Message expectations are only used when there is no simpler way to specify
+# that an instance is receiving a specific message.
+
+describe UsersController do
+
+ # This should return the minimal set of attributes required to create a valid
+ # User. As you add validations to User, be sure to
+ # update the return value of this method accordingly.
+ def valid_attributes
+ {}
+ end
+
+ # This should return the minimal set of values that should be in the session
+ # in order to pass any filters (e.g. authentication) defined in
+ # UsersController. Be sure to keep this updated too.
+ def valid_session
+ {}
+ end
+
+ describe "GET index" do
+ it "assigns all users as @users" do
+ user = User.create! valid_attributes
+ get :index, {}, valid_session
+ assigns(:users).should eq([user])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested user as @user" do
+ user = User.create! valid_attributes
+ get :show, {:id => user.to_param}, valid_session
+ assigns(:user).should eq(user)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new user as @user" do
+ get :new, {}, valid_session
+ assigns(:user).should be_a_new(User)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested user as @user" do
+ user = User.create! valid_attributes
+ get :edit, {:id => user.to_param}, valid_session
+ assigns(:user).should eq(user)
+ end
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new User" do
+ expect {
+ post :create, {:user => valid_attributes}, valid_session
+ }.to change(User, :count).by(1)
+ end
+
+ it "assigns a newly created user as @user" do
+ post :create, {:user => valid_attributes}, valid_session
+ assigns(:user).should be_a(User)
+ assigns(:user).should be_persisted
+ end
+
+ it "redirects to the created user" do
+ post :create, {:user => valid_attributes}, valid_session
+ response.should redirect_to(User.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved user as @user" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ User.any_instance.stub(:save).and_return(false)
+ post :create, {:user => {}}, valid_session
+ assigns(:user).should be_a_new(User)
+ end
+
+ it "re-renders the 'new' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ User.any_instance.stub(:save).and_return(false)
+ post :create, {:user => {}}, valid_session
+ response.should render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ it "updates the requested user" do
+ user = User.create! valid_attributes
+ # Assuming there are no other users in the database, this
+ # specifies that the User created on the previous line
+ # receives the :update_attributes message with whatever params are
+ # submitted in the request.
+ User.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, {:id => user.to_param, :user => {'these' => 'params'}}, valid_session
+ end
+
+ it "assigns the requested user as @user" do
+ user = User.create! valid_attributes
+ put :update, {:id => user.to_param, :user => valid_attributes}, valid_session
+ assigns(:user).should eq(user)
+ end
+
+ it "redirects to the user" do
+ user = User.create! valid_attributes
+ put :update, {:id => user.to_param, :user => valid_attributes}, valid_session
+ response.should redirect_to(user)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the user as @user" do
+ user = User.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ User.any_instance.stub(:save).and_return(false)
+ put :update, {:id => user.to_param, :user => {}}, valid_session
+ assigns(:user).should eq(user)
+ end
+
+ it "re-renders the 'edit' template" do
+ user = User.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ User.any_instance.stub(:save).and_return(false)
+ put :update, {:id => user.to_param, :user => {}}, valid_session
+ response.should render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested user" do
+ user = User.create! valid_attributes
+ expect {
+ delete :destroy, {:id => user.to_param}, valid_session
+ }.to change(User, :count).by(-1)
+ end
+
+ it "redirects to the users list" do
+ user = User.create! valid_attributes
+ delete :destroy, {:id => user.to_param}, valid_session
+ response.should redirect_to(users_url)
+ end
+ end
+
+end
View
15 spec/helpers/clubs_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the ClubsHelper. For example:
+#
+# describe ClubsHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe ClubsHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
15 spec/helpers/users_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the UsersHelper. For example:
+#
+# describe UsersHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe UsersHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/models/club_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Club do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/models/user_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe User do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
11 spec/requests/clubs_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "Clubs" do
+ describe "GET /clubs" do
+ it "works! (now write some real specs)" do
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
+ get clubs_path
+ response.status.should be(200)
+ end
+ end
+end
View
11 spec/requests/users_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "Users" do
+ describe "GET /users" do
+ it "works! (now write some real specs)" do
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
+ get users_path
+ response.status.should be(200)
+ end
+ end
+end
View
35 spec/routing/clubs_routing_spec.rb
@@ -0,0 +1,35 @@
+require "spec_helper"
+
+describe ClubsController do
+ describe "routing" do
+
+ it "routes to #index" do
+ get("/clubs").should route_to("clubs#index")
+ end
+
+ it "routes to #new" do
+ get("/clubs/new").should route_to("clubs#new")
+ end
+
+ it "routes to #show" do
+ get("/clubs/1").should route_to("clubs#show", :id => "1")
+ end
+
+ it "routes to #edit" do
+ get("/clubs/1/edit").should route_to("clubs#edit", :id => "1")
+ end
+
+ it "routes to #create" do
+ post("/clubs").should route_to("clubs#create")
+ end
+
+ it "routes to #update" do
+ put("/clubs/1").should route_to("clubs#update", :id => "1")
+ end
+
+ it "routes to #destroy" do
+ delete("/clubs/1").should route_to("clubs#destroy", :id => "1")
+ end
+
+ end
+end
View
35 spec/routing/users_routing_spec.rb
@@ -0,0 +1,35 @@
+require "spec_helper"
+
+describe UsersController do
+ describe "routing" do
+
+ it "routes to #index" do
+ get("/users").should route_to("users#index")
+ end
+
+ it "routes to #new" do
+ get("/users/new").should route_to("users#new")
+ end
+
+ it "routes to #show" do
+ get("/users/1").should route_to("users#show", :id => "1")
+ end
+
+ it "routes to #edit" do
+ get("/users/1/edit").should route_to("users#edit", :id => "1")
+ end
+
+ it "routes to #create" do
+ post("/users").should route_to("users#create")
+ end
+
+ it "routes to #update" do
+ put("/users/1").should route_to("users#update", :id => "1")
+ end
+
+ it "routes to #destroy" do
+ delete("/users/1").should route_to("users#destroy", :id => "1")
+ end
+
+ end
+end
View
18 spec/views/clubs/edit.html.haml_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe "clubs/edit" do
+ before(:each) do
+ @club = assign(:club, stub_model(Club,
+ :name => "MyString"
+ ))
+ end
+
+ it "renders the edit club form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form", :action => clubs_path(@club), :method => "post" do
+ assert_select "input#club_name", :name => "club[name]"
+ end
+ end
+end
View
20 spec/views/clubs/index.html.haml_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe "clubs/index" do
+ before(:each) do
+ assign(:clubs, [
+ stub_model(Club,
+ :name => "Name"
+ ),
+ stub_model(Club,
+ :name => "Name"
+ )
+ ])
+ end
+
+ it "renders a list of clubs" do
+ render
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "tr>td", :text => "Name".to_s, :count => 2
+ end
+end
View
18 spec/views/clubs/new.html.haml_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe "clubs/new" do
+ before(:each) do
+ assign(:club, stub_model(Club,
+ :name => "MyString"
+ ).as_new_record)
+ end
+
+ it "renders new club form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form", :action => clubs_path, :method => "post" do
+ assert_select "input#club_name", :name => "club[name]"
+ end
+ end
+end
View
15 spec/views/clubs/show.html.haml_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe "clubs/show" do
+ before(:each) do
+ @club = assign(:club, stub_model(Club,
+ :name => "Name"
+ ))
+ end
+
+ it "renders attributes in <p>" do
+ render
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ rendered.should match(/Name/)
+ end
+end
View
20 spec/views/users/edit.html.haml_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe "users/edit" do
+ before(:each) do
+ @user = assign(:user, stub_model(User,
+ :name => "MyString",
+ :club_id => 1
+ ))
+ end
+
+ it "renders the edit user form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form", :action => users_path(@user), :method => "post" do
+ assert_select "input#user_name", :name => "user[name]"
+ assert_select "input#user_club_id", :name => "user[club_id]"
+ end
+ end
+end
View
23 spec/views/users/index.html.haml_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+describe "users/index" do
+ before(:each) do
+ assign(:users, [
+ stub_model(User,
+ :name => "Name",
+ :club_id => 1
+ ),
+ stub_model(User,
+ :name => "Name",
+ :club_id => 1
+ )
+ ])
+ end
+
+ it "renders a list of users" do
+ render
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "tr>td", :text => "Name".to_s, :count => 2
+ assert_select "tr>td", :text => 1.to_s, :count => 2
+ end
+end
View
20 spec/views/users/new.html.haml_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe "users/new" do
+ before(:each) do
+ assign(:user, stub_model(User,
+ :name => "MyString",
+ :club_id => 1
+ ).as_new_record)
+ end
+
+ it "renders new user form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form", :action => users_path, :method => "post" do
+ assert_select "input#user_name", :name => "user[name]"
+ assert_select "input#user_club_id", :name => "user[club_id]"
+ end
+ end
+end
View
17 spec/views/users/show.html.haml_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe "users/show" do
+ before(:each) do
+ @user = assign(:user, stub_model(User,
+ :name => "Name",
+ :club_id => 1
+ ))
+ end
+
+ it "renders attributes in <p>" do
+ render
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ rendered.should match(/Name/)
+ rendered.should match(/1/)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.