From e580d4626176c8deb6f44fec7e66f980b5923b29 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 24 Jul 2008 07:56:00 +0000 Subject: [PATCH] Created tables, product scaffold --- app/controllers/products_controller.rb | 85 +++++++++++ app/helpers/products_helper.rb | 2 + app/models/product.rb | 2 + app/views/layouts/products.html.erb | 17 +++ app/views/products/edit.html.erb | 24 ++++ app/views/products/index.html.erb | 24 ++++ app/views/products/new.html.erb | 23 +++ app/views/products/show.html.erb | 18 +++ config/database.yml | 33 +++-- config/routes.rb | 2 + db/migrate/20080724075409_create_products.rb | 15 ++ db/schema.rb | 22 +++ log/development.log | 143 +++++++++++++++++++ public/stylesheets/scaffold.css | 54 +++++++ test/fixtures/products.yml | 11 ++ test/functional/products_controller_test.rb | 45 ++++++ test/unit/product_test.rb | 8 ++ 17 files changed, 515 insertions(+), 13 deletions(-) create mode 100644 app/controllers/products_controller.rb create mode 100644 app/helpers/products_helper.rb create mode 100644 app/models/product.rb create mode 100644 app/views/layouts/products.html.erb create mode 100644 app/views/products/edit.html.erb create mode 100644 app/views/products/index.html.erb create mode 100644 app/views/products/new.html.erb create mode 100644 app/views/products/show.html.erb create mode 100644 db/migrate/20080724075409_create_products.rb create mode 100644 db/schema.rb create mode 100644 public/stylesheets/scaffold.css create mode 100644 test/fixtures/products.yml create mode 100644 test/functional/products_controller_test.rb create mode 100644 test/unit/product_test.rb diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000..1685ca5 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,85 @@ +class ProductsController < ApplicationController + # GET /products + # GET /products.xml + def index + @products = Product.find(:all) + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @products } + end + end + + # GET /products/1 + # GET /products/1.xml + def show + @product = Product.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @product } + end + end + + # GET /products/new + # GET /products/new.xml + def new + @product = Product.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @product } + end + end + + # GET /products/1/edit + def edit + @product = Product.find(params[:id]) + end + + # POST /products + # POST /products.xml + def create + @product = Product.new(params[:product]) + + respond_to do |format| + if @product.save + flash[:notice] = 'Product was successfully created.' + format.html { redirect_to(@product) } + format.xml { render :xml => @product, :status => :created, :location => @product } + else + format.html { render :action => "new" } + format.xml { render :xml => @product.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /products/1 + # PUT /products/1.xml + def update + @product = Product.find(params[:id]) + + respond_to do |format| + if @product.update_attributes(params[:product]) + flash[:notice] = 'Product was successfully updated.' + format.html { redirect_to(@product) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @product.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /products/1 + # DELETE /products/1.xml + def destroy + @product = Product.find(params[:id]) + @product.destroy + + respond_to do |format| + format.html { redirect_to(products_url) } + format.xml { head :ok } + end + end +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000..ab5c42b --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000..077a819 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,2 @@ +class Product < ActiveRecord::Base +end diff --git a/app/views/layouts/products.html.erb b/app/views/layouts/products.html.erb new file mode 100644 index 0000000..b9f60be --- /dev/null +++ b/app/views/layouts/products.html.erb @@ -0,0 +1,17 @@ + + + + + + Products: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000..af3b747 --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,24 @@ +

Editing product

+ +<% form_for(@product) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :title %>
+ <%= f.text_field :title %> +

+

+ <%= f.label :description %>
+ <%= f.text_area :description %> +

+

+ <%= f.label :image_url %>
+ <%= f.text_field :image_url %> +

+

+ <%= f.submit "Update" %> +

+<% end %> + +<%= link_to 'Show', @product %> | +<%= link_to 'Back', products_path %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000..88120ee --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,24 @@ +

Listing products

+ + + + + + + + +<% for product in @products %> + + + + + + + + +<% end %> +
TitleDescriptionImage url
<%=h product.title %><%=h product.description %><%=h product.image_url %><%= link_to 'Show', product %><%= link_to 'Edit', edit_product_path(product) %><%= link_to 'Destroy', product, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New product', new_product_path %> diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000..f935937 --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,23 @@ +

New product

+ +<% form_for(@product) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :title %>
+ <%= f.text_field :title %> +

+

+ <%= f.label :description %>
+ <%= f.text_area :description %> +

+

+ <%= f.label :image_url %>
+ <%= f.text_field :image_url %> +

+

+ <%= f.submit "Create" %> +

+<% end %> + +<%= link_to 'Back', products_path %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 0000000..a5f0eac --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,18 @@ +

+ Title: + <%=h @product.title %> +

+ +

+ Description: + <%=h @product.description %> +

+ +

+ Image url: + <%=h @product.image_url %> +

+ + +<%= link_to 'Edit', edit_product_path(@product) %> | +<%= link_to 'Back', products_path %> diff --git a/config/database.yml b/config/database.yml index fff44a4..ccc19af 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,19 +1,26 @@ -# SQLite version 3.x -# gem install sqlite3-ruby (not necessary on OS X Leopard) development: - adapter: sqlite3 - database: db/development.sqlite3 - timeout: 5000 + host: localhost + adapter: mysql + database: depot_development + port: 3306 + username: depot + password: -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". +# Warning: The database defined as 'test' will be erased and +# re-generated from your development database when you run 'rake'. # Do not set this db to the same as development or production. test: - adapter: sqlite3 - database: db/test.sqlite3 - timeout: 5000 + host: localhost + adapter: mysql + database: depot_test + port: 3306 + username: depot + password: production: - adapter: sqlite3 - database: db/production.sqlite3 - timeout: 5000 + host: localhost + adapter: mysql + database: depot_production + port: 3306 + username: depot + password: diff --git a/config/routes.rb b/config/routes.rb index b579d6c..fa21f85 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ ActionController::Routing::Routes.draw do |map| + map.resources :products + # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: diff --git a/db/migrate/20080724075409_create_products.rb b/db/migrate/20080724075409_create_products.rb new file mode 100644 index 0000000..6b51c3f --- /dev/null +++ b/db/migrate/20080724075409_create_products.rb @@ -0,0 +1,15 @@ +class CreateProducts < ActiveRecord::Migration + def self.up + create_table :products do |t| + t.string :title + t.text :description + t.string :image_url + + t.timestamps + end + end + + def self.down + drop_table :products + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..c702c8e --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,22 @@ +# 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 => 20080724075409) do + + create_table "products", :force => true do |t| + t.string "title" + t.text "description" + t.string "image_url" + t.datetime "created_at" + t.datetime "updated_at" + end + +end diff --git a/log/development.log b/log/development.log index e69de29..0057ea8 100644 --- a/log/development.log +++ b/log/development.log @@ -0,0 +1,143 @@ + + +Processing ProductsController#index (for 127.0.0.1 at 2008-07-24 08:54:29) [GET] + Session ID: 516264dbb9a2fb7792ea3375d071afc7 + Parameters: {"action"=>"index", "controller"=>"products"} + SQL (0.000156) SET SQL_AUTO_IS_NULL=0 + Product Load (0.000000) Mysql::Error: Table 'depot_development.products' doesn't exist: SELECT * FROM `products`  + + +ActiveRecord::StatementInvalid (Mysql::Error: Table 'depot_development.products' doesn't exist: SELECT * FROM `products` ): + /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:147:in `log' + /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:299:in `execute' + /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:515:in `select' + /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache' + /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:59:in `select_all' + /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:80:in `cache_sql' + /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:59:in `select_all' + /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:582:in `find_by_sql' + /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1341:in `find_every' + /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:536:in `find' + /app/controllers/products_controller.rb:5:in `index' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `send' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `perform_action_without_filters' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:580:in `call_filters' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:573:in `perform_action_without_benchmark' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' + /usr/lib/ruby/1.8/benchmark.rb:293:in `measure' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/rescue.rb:201:in `perform_action_without_caching' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:13:in `perform_action' + /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache' + /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/query_cache.rb:8:in `cache' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:12:in `perform_action' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `send' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `process_without_filters' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:569:in `process_without_session_management_support' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/session_management.rb:130:in `process' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:389:in `process' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:149:in `handle_request' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in `dispatch' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `synchronize' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `dispatch' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi' + /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in `dispatch' + /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:112:in `handle_dispatch' + /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:78:in `service' + /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' + /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' + /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' + /usr/lib/ruby/1.8/webrick/server.rb:162:in `start' + /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' + /usr/lib/ruby/1.8/webrick/server.rb:95:in `start' + /usr/lib/ruby/1.8/webrick/server.rb:92:in `each' + /usr/lib/ruby/1.8/webrick/server.rb:92:in `start' + /usr/lib/ruby/1.8/webrick/server.rb:23:in `start' + /usr/lib/ruby/1.8/webrick/server.rb:82:in `start' + /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:62:in `dispatch' + /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/servers/webrick.rb:66 + /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' + /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' + /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require' + /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in' + /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require' + /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39 + /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' + /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' + script/server:3 + +Rendering /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/templates/rescues/layout.erb (internal_server_error) + SQL (0.000168) SET SQL_AUTO_IS_NULL=0 + SQL (0.000306) SHOW TABLES + SQL (0.043538) CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB + SQL (0.004163) CREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`) + SQL (0.000244) SHOW TABLES + SQL (0.000338) SELECT version FROM schema_migrations +Migrating to CreateProducts (20080724075409) + SQL (0.000068) SELECT version FROM schema_migrations + SQL (0.002555) CREATE TABLE `products` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `title` varchar(255) DEFAULT NULL NULL, `description` text DEFAULT NULL NULL, `image_url` varchar(255) DEFAULT NULL NULL, `created_at` datetime DEFAULT NULL NULL, `updated_at` datetime DEFAULT NULL NULL) ENGINE=InnoDB + SQL (0.000787) INSERT INTO schema_migrations (version) VALUES ('20080724075409') + SQL (0.000238) SELECT version FROM schema_migrations + SQL (0.000215) SHOW TABLES + SQL (0.000852) SHOW FIELDS FROM `products` + SQL (0.000711) describe `products` + SQL (0.000320) SHOW KEYS FROM `products` + + +Processing ProductsController#index (for 127.0.0.1 at 2008-07-24 08:54:57) [GET] + Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo +SGFzaHsABjoKQHVzZWR7AA==--9a7a4cb8d57b822aeb31c468bcb62a33430f150b + Parameters: {"action"=>"index", "controller"=>"products"} + Product Load (0.000316) SELECT * FROM `products`  +Rendering template within layouts/products +Rendering products/index +Completed in 0.01792 (55 reqs/sec) | Rendering: 0.00568 (31%) | DB: 0.00047 (2%) | 200 OK [http://localhost/products] + + +Processing ProductsController#new (for 127.0.0.1 at 2008-07-24 08:55:01) [GET] + Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo +SGFzaHsABjoKQHVzZWR7AA==--9a7a4cb8d57b822aeb31c468bcb62a33430f150b + Parameters: {"action"=>"new", "controller"=>"products"} + Product Columns (0.000866) SHOW FIELDS FROM `products` +Rendering template within layouts/products +Rendering products/new +Completed in 0.02357 (42 reqs/sec) | Rendering: 0.01115 (47%) | DB: 0.00087 (3%) | 200 OK [http://localhost/products/new] + + +Processing ProductsController#create (for 127.0.0.1 at 2008-07-24 08:55:07) [POST] + Session ID: BAh7BzoMY3NyZl9pZCIlOWM2MWUxN2RiODdmNDI2MTQxNjIwODM5ZmY2Yzdj +OWIiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh +c2h7AAY6CkB1c2VkewA=--be2cb095a3a64313ddeabee8ee4f7ac896aae350 + Parameters: {"commit"=>"Create", "product"=>{"image_url"=>"lkj l;j", "title"=>"lkj ", "description"=>"l;kj lk;j l;kj lj"}, "authenticity_token"=>"466a8d52a74d0603850d0b0d709e5f2c5e3ce774", "action"=>"create", "controller"=>"products"} + Product Columns (0.000988) SHOW FIELDS FROM `products` + SQL (0.000084) BEGIN + Product Create (0.000799) INSERT INTO `products` (`image_url`, `updated_at`, `title`, `description`, `created_at`) VALUES('lkj l;j', '2008-07-24 07:55:07', 'lkj ', 'l;kj lk;j l;kj lj', '2008-07-24 07:55:07') + SQL (0.002049) COMMIT +Redirected to http://localhost:3000/products/1 +Completed in 0.02044 (48 reqs/sec) | DB: 0.00392 (19%) | 302 Found [http://localhost/products] + + +Processing ProductsController#show (for 127.0.0.1 at 2008-07-24 08:55:07) [GET] + Session ID: BAh7BzoMY3NyZl9pZCIlOWM2MWUxN2RiODdmNDI2MTQxNjIwODM5ZmY2Yzdj +OWIiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh +c2h7BjoLbm90aWNlIiZQcm9kdWN0IHdhcyBzdWNjZXNzZnVsbHkgY3JlYXRl +ZC4GOgpAdXNlZHsGOwdG--f2c2ee2eb4620b461f69f905e5860ebe7060c7f2 + Parameters: {"action"=>"show", "id"=>"1", "controller"=>"products"} + Product Columns (0.001114) SHOW FIELDS FROM `products` + Product Load (0.000544) SELECT * FROM `products` WHERE (`products`.`id` = 1)  +Rendering template within layouts/products +Rendering products/show +Completed in 0.02537 (39 reqs/sec) | Rendering: 0.00662 (26%) | DB: 0.00166 (6%) | 200 OK [http://localhost/products/1] + + +Processing ProductsController#index (for 127.0.0.1 at 2008-07-24 08:55:09) [GET] + Session ID: BAh7BzoMY3NyZl9pZCIlOWM2MWUxN2RiODdmNDI2MTQxNjIwODM5ZmY2Yzdj +OWIiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh +c2h7BjoLbm90aWNlIiZQcm9kdWN0IHdhcyBzdWNjZXNzZnVsbHkgY3JlYXRl +ZC4GOgpAdXNlZHsGOwdU--e278ebd0c668af234fdcc2a973394c40ab1571fd + Parameters: {"action"=>"index", "controller"=>"products"} + Product Load (0.000324) SELECT * FROM `products`  +Rendering template within layouts/products +Rendering products/index + Product Columns (0.003374) SHOW FIELDS FROM `products` +Completed in 0.02020 (49 reqs/sec) | Rendering: 0.00515 (25%) | DB: 0.00370 (18%) | 200 OK [http://localhost/products] diff --git a/public/stylesheets/scaffold.css b/public/stylesheets/scaffold.css new file mode 100644 index 0000000..093c209 --- /dev/null +++ b/public/stylesheets/scaffold.css @@ -0,0 +1,54 @@ +body { background-color: #fff; color: #333; } + +body, 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; } +a:visited { color: #666; } +a:hover { color: #fff; background-color:#000; } + +.fieldWithErrors { + padding: 2px; + background-color: red; + display: table; +} + +#errorExplanation { + width: 400px; + border: 2px solid red; + padding: 7px; + padding-bottom: 12px; + margin-bottom: 20px; + background-color: #f0f0f0; +} + +#errorExplanation h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + background-color: #c00; + color: #fff; +} + +#errorExplanation p { + color: #333; + margin-bottom: 0; + padding: 5px; +} + +#errorExplanation ul li { + font-size: 12px; + list-style: square; +} + diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000..9e23036 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + title: MyString + description: MyText + image_url: MyString + +two: + title: MyString + description: MyText + image_url: MyString diff --git a/test/functional/products_controller_test.rb b/test/functional/products_controller_test.rb new file mode 100644 index 0000000..18c523a --- /dev/null +++ b/test/functional/products_controller_test.rb @@ -0,0 +1,45 @@ +require 'test_helper' + +class ProductsControllerTest < ActionController::TestCase + def test_should_get_index + get :index + assert_response :success + assert_not_nil assigns(:products) + end + + def test_should_get_new + get :new + assert_response :success + end + + def test_should_create_product + assert_difference('Product.count') do + post :create, :product => { } + end + + assert_redirected_to product_path(assigns(:product)) + end + + def test_should_show_product + get :show, :id => products(:one).id + assert_response :success + end + + def test_should_get_edit + get :edit, :id => products(:one).id + assert_response :success + end + + def test_should_update_product + put :update, :id => products(:one).id, :product => { } + assert_redirected_to product_path(assigns(:product)) + end + + def test_should_destroy_product + assert_difference('Product.count', -1) do + delete :destroy, :id => products(:one).id + end + + assert_redirected_to products_path + end +end diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb new file mode 100644 index 0000000..cd51c07 --- /dev/null +++ b/test/unit/product_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class ProductTest < ActiveSupport::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end -- 2.34.1