Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test a scaffold

  • Loading branch information...
commit f5f9c25f29ed3064ec6f257db84f3d4dd928344a 1 parent eb91e24
Peter Kordel pkordel authored
3  app/assets/javascripts/reviews.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/reviews.css.scss
View
@@ -0,0 +1,3 @@
+// Place all the styles related to the Reviews 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; } }
83 app/controllers/reviews_controller.rb
View
@@ -0,0 +1,83 @@
+class ReviewsController < ApplicationController
+ # GET /reviews
+ # GET /reviews.json
+ def index
+ @reviews = Review.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @reviews }
+ end
+ end
+
+ # GET /reviews/1
+ # GET /reviews/1.json
+ def show
+ @review = Review.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @review }
+ end
+ end
+
+ # GET /reviews/new
+ # GET /reviews/new.json
+ def new
+ @review = Review.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @review }
+ end
+ end
+
+ # GET /reviews/1/edit
+ def edit
+ @review = Review.find(params[:id])
+ end
+
+ # POST /reviews
+ # POST /reviews.json
+ def create
+ @review = Review.new(params[:review])
+
+ respond_to do |format|
+ if @review.save
+ format.html { redirect_to @review, notice: 'Review was successfully created.' }
+ format.json { render json: @review, status: :created, location: @review }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @review.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /reviews/1
+ # PUT /reviews/1.json
+ def update
+ @review = Review.find(params[:id])
+
+ respond_to do |format|
+ if @review.update_attributes(params[:review])
+ format.html { redirect_to @review, notice: 'Review was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @review.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /reviews/1
+ # DELETE /reviews/1.json
+ def destroy
+ @review = Review.find(params[:id])
+ @review.destroy
+
+ respond_to do |format|
+ format.html { redirect_to reviews_url }
+ format.json { head :no_content }
+ end
+ end
+end
2  app/helpers/reviews_helper.rb
View
@@ -0,0 +1,2 @@
+module ReviewsHelper
+end
2  app/models/review.rb
View
@@ -0,0 +1,2 @@
+class Review < ActiveRecord::Base
+end
14 app/views/layouts/application.html.slim
View
@@ -1,20 +1,20 @@
doctype html
/![if lt IE 7 ]
- html class="ie ie6" lang="en"
+ html class="ie ie6" lang="nb"
/![if IE 7 ]
- html class="ie ie7" lang="en"
+ html class="ie ie7" lang="nb"
/![if IE 8 ]
- html class="ie ie8" lang="en"
+ html class="ie ie8" lang="nb"
/![if (gte IE 9)|!(IE)]
- html lang="en"
-html lang="en"
+ html lang="nb"
+html lang="nb"
head
meta charset="utf-8"
- title Booky
+ title = "Deichman::#{I18n.t(controller_name.to_s)}"
/![if lt IE 9]
script src="http://html5shim.googlecode.com/svn/trunk/html5.js"
- <!-- http://t.co/dKP3o1e -->
+ /! http://t.co/dKP3o1e
meta name="HandheldFriendly" content="True"
meta name="MobileOptimized" content="320"
meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"
22 app/views/reviews/_form.html.slim
View
@@ -0,0 +1,22 @@
+= form_for @review do |f|
+ -if @review.errors.any?
+ #error_explanation
+ h2 = "#{pluralize(@review.errors.count, "error")} prohibited this review from being saved:"
+ ul
+ - @review.errors.full_messages.each do |msg|
+ li= msg
+
+ .field
+ = f.label :isbn
+ = f.text_field :isbn
+ .field
+ = f.label :title
+ = f.text_field :title
+ .field
+ = f.label :summary
+ = f.text_area :summary
+ .field
+ = f.label :body
+ = f.text_area :body
+ .actions
+ = f.submit 'Save'
8 app/views/reviews/edit.html.slim
View
@@ -0,0 +1,8 @@
+h1 Editing review
+
+== render 'form'
+
+= link_to 'Show', @review
+'|
+= link_to 'Back', reviews_path
+
25 app/views/reviews/index.html.slim
View
@@ -0,0 +1,25 @@
+h1 Listing reviews
+
+table
+ tr
+ th Isbn
+ th Title
+ th Summary
+ th Body
+ th
+ th
+ th
+
+ - @reviews.each do |review|
+ tr
+ td= review.isbn
+ td= review.title
+ td= review.summary
+ td= review.body
+ td= link_to 'Show', review
+ td= link_to 'Edit', edit_review_path(review)
+ td= link_to 'Destroy', review, :confirm => 'Are you sure?', :method => :delete
+
+br
+
+= link_to 'New Review', new_review_path
5 app/views/reviews/new.html.slim
View
@@ -0,0 +1,5 @@
+h1 = t("#{controller_name}.#{action_name}")
+
+== render 'form'
+
+= link_to 'Back', reviews_path
18 app/views/reviews/show.html.slim
View
@@ -0,0 +1,18 @@
+p#notice = notice
+
+p
+ b Isbn:
+ = @review.isbn
+p
+ b Title:
+ = @review.title
+p
+ b Summary:
+ = @review.summary
+p
+ b Body:
+ = @review.body
+
+= link_to 'Edit', edit_review_path(@review)
+'|
+= link_to 'Back', reviews_path
2  config/application.rb
View
@@ -31,7 +31,7 @@ class Application < Rails::Application
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
- # config.i18n.default_locale = :de
+ config.i18n.default_locale = :nb
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
2  config/locales/en.yml
View
@@ -2,4 +2,4 @@
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
- hello: "Hello world"
+ reviews: "Book Reviews"
2  config/locales/nb.yml
View
@@ -0,0 +1,2 @@
+nb:
+ reviews: Bokanbefalinger
201 config/locales/rails.nb.yml
View
@@ -0,0 +1,201 @@
+nb:
+ date:
+ abbr_day_names:
+ - søn
+ - man
+ - tir
+ - ons
+ - tor
+ - fre
+ - lør
+ abbr_month_names:
+ -
+ - jan
+ - feb
+ - mar
+ - apr
+ - mai
+ - jun
+ - jul
+ - aug
+ - sep
+ - okt
+ - nov
+ - des
+ day_names:
+ - søndag
+ - mandag
+ - tirsdag
+ - onsdag
+ - torsdag
+ - fredag
+ - lørdag
+ formats:
+ default: ! '%d.%m.%Y'
+ long: ! '%e. %B %Y'
+ short: ! '%e. %b'
+ month_names:
+ -
+ - januar
+ - februar
+ - mars
+ - april
+ - mai
+ - juni
+ - juli
+ - august
+ - september
+ - oktober
+ - november
+ - desember
+ order:
+ - :day
+ - :month
+ - :year
+ datetime:
+ distance_in_words:
+ about_x_hours:
+ one: rundt 1 time
+ other: rundt %{count} timer
+ about_x_months:
+ one: rundt 1 måned
+ other: rundt %{count} måneder
+ about_x_years:
+ one: rundt 1 år
+ other: rundt %{count} år
+ almost_x_years:
+ one: nesten 1 år
+ other: nesten %{count} år
+ half_a_minute: et halvt minutt
+ less_than_x_minutes:
+ one: mindre enn 1 minutt
+ other: mindre enn %{count} minutter
+ less_than_x_seconds:
+ one: mindre enn 1 sekund
+ other: mindre enn %{count} sekunder
+ over_x_years:
+ one: over 1 år
+ other: over %{count} år
+ x_days:
+ one: 1 dag
+ other: ! '%{count} dager'
+ x_minutes:
+ one: 1 minutt
+ other: ! '%{count} minutter'
+ x_months:
+ one: 1 måned
+ other: ! '%{count} måneder'
+ x_seconds:
+ one: 1 sekund
+ other: ! '%{count} sekunder'
+ prompts:
+ day: Dag
+ hour: Time
+ minute: Minutt
+ month: Måned
+ second: Sekund
+ year: År
+ errors:
+ format: ! '%{attribute} %{message}'
+ messages:
+ accepted: må være akseptert
+ blank: kan ikke være blank
+ confirmation: passer ikke bekreftelsen
+ empty: kan ikke være tom
+ equal_to: må være lik %{count}
+ even: må være partall
+ exclusion: er reservert
+ greater_than: må være større enn %{count}
+ greater_than_or_equal_to: må være større enn eller lik %{count}
+ inclusion: er ikke inkludert i listen
+ invalid: er ugyldig
+ less_than: må være mindre enn %{count}
+ less_than_or_equal_to: må være mindre enn eller lik %{count}
+ not_a_number: er ikke et tall
+ not_an_integer: er ikke et heltall
+ odd: må være oddetall
+ record_invalid: ! 'Det oppstod feil: %{errors}'
+ taken: er allerede i bruk
+ too_long: er for lang (maksimum %{count} tegn)
+ too_short: er for kort (minimum %{count} tegn)
+ wrong_length: er av feil lengde (maksimum %{count} tegn)
+ template:
+ body: ! 'Det oppstod problemer i følgende felt:'
+ header:
+ one: Kunne ikke lagre %{model} på grunn av én feil.
+ other: Kunne ikke lagre %{model} på grunn av %{count} feil.
+ helpers:
+ select:
+ prompt: Vennligst velg
+ submit:
+ create: Lag %{model}
+ submit: Lagre %{model}
+ update: Oppdater %{model}
+ number:
+ currency:
+ format:
+ delimiter: ! ' '
+ format: ! '%n %u'
+ precision: 2
+ separator: ! ','
+ significant: false
+ strip_insignificant_zeros: true
+ unit: kr
+ format:
+ delimiter: ! ' '
+ precision: 2
+ separator: ! ','
+ significant: false
+ strip_insignificant_zeros: true
+ human:
+ decimal_units:
+ format: ! '%n %u'
+ units:
+ billion:
+ one: milliard
+ other: milliarder
+ million:
+ one: million
+ other: millioner
+ quadrillion:
+ one: billiard
+ other: billiarder
+ thousand: tusen
+ trillion:
+ one: billion
+ other: billioner
+ unit: ''
+ format:
+ delimiter: ! ' '
+ precision: 1
+ significant: false
+ strip_insignificant_zeros: true
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Bytes
+ gb: GB
+ kb: kB
+ mb: MB
+ tb: TB
+ percentage:
+ format:
+ delimiter: ''
+ precision:
+ format:
+ delimiter: ''
+ support:
+ array:
+ last_word_connector: ! ' og '
+ two_words_connector: ! ' og '
+ words_connector: ! ', '
+ time:
+ am: ''
+ formats:
+ default: ! '%A, %e. %B %Y, %H:%M'
+ long: ! '%A, %e. %B %Y, %H:%M'
+ short: ! '%e. %B, %H:%M'
+ pm: ''
+
3  config/routes.rb
View
@@ -1,4 +1,7 @@
Booky::Application.routes.draw do
+ resources :reviews
+ root :to => 'reviews#index'
+
# The priority is based upon order of creation:
# first created -> highest priority.
12 db/migrate/20120125154447_create_reviews.rb
View
@@ -0,0 +1,12 @@
+class CreateReviews < ActiveRecord::Migration
+ def change
+ create_table :reviews do |t|
+ t.string :isbn
+ t.string :title
+ t.text :summary
+ t.text :body
+
+ t.timestamps
+ end
+ end
+end
25 db/schema.rb
View
@@ -0,0 +1,25 @@
+# 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 => 20120125154447) do
+
+ create_table "reviews", :force => true do |t|
+ t.string "isbn"
+ t.string "title"
+ t.text "summary"
+ t.text "body"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+end
241 public/index.html
View
@@ -1,241 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Ruby on Rails: Welcome aboard</title>
- <style type="text/css" media="screen">
- body {
- margin: 0;
- margin-bottom: 25px;
- padding: 0;
- background-color: #f0f0f0;
- font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
- font-size: 13px;
- color: #333;
- }
-
- h1 {
- font-size: 28px;
- color: #000;
- }
-
- a {color: #03c}
- a:hover {
- background-color: #03c;
- color: white;
- text-decoration: none;
- }
-
-
- #page {
- background-color: #f0f0f0;
- width: 750px;
- margin: 0;
- margin-left: auto;
- margin-right: auto;
- }
-
- #content {
- float: left;
- background-color: white;
- border: 3px solid #aaa;
- border-top: none;
- padding: 25px;
- width: 500px;
- }
-
- #sidebar {
- float: right;
- width: 175px;
- }
-
- #footer {
- clear: both;
- }
-
- #header, #about, #getting-started {
- padding-left: 75px;
- padding-right: 30px;
- }
-
-
- #header {
- background-image: url("assets/rails.png");
- background-repeat: no-repeat;
- background-position: top left;
- height: 64px;
- }
- #header h1, #header h2 {margin: 0}
- #header h2 {
- color: #888;
- font-weight: normal;
- font-size: 16px;
- }
-
-
- #about h3 {
- margin: 0;
- margin-bottom: 10px;
- font-size: 14px;
- }
-
- #about-content {
- background-color: #ffd;
- border: 1px solid #fc0;
- margin-left: -55px;
- margin-right: -10px;
- }
- #about-content table {
- margin-top: 10px;
- margin-bottom: 10px;
- font-size: 11px;
- border-collapse: collapse;
- }
- #about-content td {
- padding: 10px;
- padding-top: 3px;
- padding-bottom: 3px;
- }
- #about-content td.name {color: #555}
- #about-content td.value {color: #000}
-
- #about-content ul {
- padding: 0;
- list-style-type: none;
- }
-
- #about-content.failure {
- background-color: #fcc;
- border: 1px solid #f00;
- }
- #about-content.failure p {
- margin: 0;
- padding: 10px;
- }
-
-
- #getting-started {
- border-top: 1px solid #ccc;
- margin-top: 25px;
- padding-top: 15px;
- }
- #getting-started h1 {
- margin: 0;
- font-size: 20px;
- }
- #getting-started h2 {
- margin: 0;
- font-size: 14px;
- font-weight: normal;
- color: #333;
- margin-bottom: 25px;
- }
- #getting-started ol {
- margin-left: 0;
- padding-left: 0;
- }
- #getting-started li {
- font-size: 18px;
- color: #888;
- margin-bottom: 25px;
- }
- #getting-started li h2 {
- margin: 0;
- font-weight: normal;
- font-size: 18px;
- color: #333;
- }
- #getting-started li p {
- color: #555;
- font-size: 13px;
- }
-
-
- #sidebar ul {
- margin-left: 0;
- padding-left: 0;
- }
- #sidebar ul h3 {
- margin-top: 25px;
- font-size: 16px;
- padding-bottom: 10px;
- border-bottom: 1px solid #ccc;
- }
- #sidebar li {
- list-style-type: none;
- }
- #sidebar ul.links li {
- margin-bottom: 5px;
- }
-
- .filename {
- font-style: italic;
- }
- </style>
- <script type="text/javascript">
- function about() {
- info = document.getElementById('about-content');
- if (window.XMLHttpRequest)
- { xhr = new XMLHttpRequest(); }
- else
- { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
- xhr.open("GET","rails/info/properties",false);
- xhr.send("");
- info.innerHTML = xhr.responseText;
- info.style.display = 'block'
- }
- </script>
- </head>
- <body>
- <div id="page">
- <div id="sidebar">
- <ul id="sidebar-items">
- <li>
- <h3>Browse the documentation</h3>
- <ul class="links">
- <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
- <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
- <li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
- <li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
- </ul>
- </li>
- </ul>
- </div>
-
- <div id="content">
- <div id="header">
- <h1>Welcome aboard</h1>
- <h2>You&rsquo;re riding Ruby on Rails!</h2>
- </div>
-
- <div id="about">
- <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
- <div id="about-content" style="display: none"></div>
- </div>
-
- <div id="getting-started">
- <h1>Getting started</h1>
- <h2>Here&rsquo;s how to get rolling:</h2>
-
- <ol>
- <li>
- <h2>Use <code>rails generate</code> to create your models and controllers</h2>
- <p>To see all available options, run it without parameters.</p>
- </li>
-
- <li>
- <h2>Set up a default route and remove <span class="filename">public/index.html</span></h2>
- <p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
- </li>
-
- <li>
- <h2>Create your database</h2>
- <p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
- </li>
- </ol>
- </div>
- </div>
-
- <div id="footer">&nbsp;</div>
- </div>
- </body>
-</html>
164 spec/controllers/reviews_controller_spec.rb
View
@@ -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 ReviewsController do
+
+ # This should return the minimal set of attributes required to create a valid
+ # Review. As you add validations to Review, 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
+ # ReviewsController. Be sure to keep this updated too.
+ def valid_session
+ {}
+ end
+
+ describe "GET index" do
+ it "assigns all reviews as @reviews" do
+ review = Review.create! valid_attributes
+ get :index, {}, valid_session
+ assigns(:reviews).should eq([review])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested review as @review" do
+ review = Review.create! valid_attributes
+ get :show, {:id => review.to_param}, valid_session
+ assigns(:review).should eq(review)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new review as @review" do
+ get :new, {}, valid_session
+ assigns(:review).should be_a_new(Review)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested review as @review" do
+ review = Review.create! valid_attributes
+ get :edit, {:id => review.to_param}, valid_session
+ assigns(:review).should eq(review)
+ end
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new Review" do
+ expect {
+ post :create, {:review => valid_attributes}, valid_session
+ }.to change(Review, :count).by(1)
+ end
+
+ it "assigns a newly created review as @review" do
+ post :create, {:review => valid_attributes}, valid_session
+ assigns(:review).should be_a(Review)
+ assigns(:review).should be_persisted
+ end
+
+ it "redirects to the created review" do
+ post :create, {:review => valid_attributes}, valid_session
+ response.should redirect_to(Review.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved review as @review" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Review.any_instance.stub(:save).and_return(false)
+ post :create, {:review => {}}, valid_session
+ assigns(:review).should be_a_new(Review)
+ end
+
+ it "re-renders the 'new' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Review.any_instance.stub(:save).and_return(false)
+ post :create, {:review => {}}, valid_session
+ response.should render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ it "updates the requested review" do
+ review = Review.create! valid_attributes
+ # Assuming there are no other reviews in the database, this
+ # specifies that the Review created on the previous line
+ # receives the :update_attributes message with whatever params are
+ # submitted in the request.
+ Review.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, {:id => review.to_param, :review => {'these' => 'params'}}, valid_session
+ end
+
+ it "assigns the requested review as @review" do
+ review = Review.create! valid_attributes
+ put :update, {:id => review.to_param, :review => valid_attributes}, valid_session
+ assigns(:review).should eq(review)
+ end
+
+ it "redirects to the review" do
+ review = Review.create! valid_attributes
+ put :update, {:id => review.to_param, :review => valid_attributes}, valid_session
+ response.should redirect_to(review)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the review as @review" do
+ review = Review.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ Review.any_instance.stub(:save).and_return(false)
+ put :update, {:id => review.to_param, :review => {}}, valid_session
+ assigns(:review).should eq(review)
+ end
+
+ it "re-renders the 'edit' template" do
+ review = Review.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ Review.any_instance.stub(:save).and_return(false)
+ put :update, {:id => review.to_param, :review => {}}, valid_session
+ response.should render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested review" do
+ review = Review.create! valid_attributes
+ expect {
+ delete :destroy, {:id => review.to_param}, valid_session
+ }.to change(Review, :count).by(-1)
+ end
+
+ it "redirects to the reviews list" do
+ review = Review.create! valid_attributes
+ delete :destroy, {:id => review.to_param}, valid_session
+ response.should redirect_to(reviews_url)
+ end
+ end
+
+end
15 spec/helpers/reviews_helper_spec.rb
View
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the ReviewsHelper. For example:
+#
+# describe ReviewsHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe ReviewsHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
5 spec/models/review_spec.rb
View
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Review do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
11 spec/requests/reviews_spec.rb
View
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "Reviews" do
+ describe "GET /reviews" 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 reviews_path
+ response.status.should be(200)
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.