From 144d2e494675d07f1caecd319a1db11222b111e3 Mon Sep 17 00:00:00 2001 From: Daniel Schlossberg Date: Fri, 27 Jan 2012 22:05:50 -0500 Subject: [PATCH] daniel made me do it --- app/assets/javascripts/price.js.coffee | 3 + .../javascripts/price_histories.js.coffee | 3 + app/assets/javascripts/units.js.coffee | 3 + app/assets/stylesheets/price.css.scss | 3 + .../stylesheets/price_histories.css.scss | 3 + app/assets/stylesheets/units.css.scss | 3 + app/controllers/price_histories_controller.rb | 83 +++++++++ app/controllers/units_controller.rb | 83 +++++++++ app/helpers/price_helper.rb | 2 + app/helpers/price_histories_helper.rb | 2 + app/helpers/units_helper.rb | 2 + app/models/commodity.rb | 4 + app/models/price_history.rb | 2 + app/views/layouts/application.html.erb | 10 +- app/views/price_histories/_form.html.erb | 49 ++++++ app/views/price_histories/edit.html.erb | 6 + app/views/price_histories/index.html.erb | 37 ++++ app/views/price_histories/new.html.erb | 5 + app/views/price_histories/show.html.erb | 45 +++++ app/views/units/_form.html.erb | 17 ++ app/views/units/edit.html.erb | 6 + app/views/units/index.html.erb | 21 +++ app/views/units/new.html.erb | 5 + app/views/units/show.html.erb | 5 + config/routes.rb | 4 + db/migrate/20120128023155_create_units.rb | 8 + .../20120128025115_create_price_histories.rb | 16 ++ db/schema.rb | 23 ++- spec/controllers/price_controller_spec.rb | 5 + .../price_histories_controller_spec.rb | 164 ++++++++++++++++++ spec/controllers/units_controller_spec.rb | 164 ++++++++++++++++++ spec/helpers/price_helper_spec.rb | 15 ++ spec/helpers/price_histories_helper_spec.rb | 15 ++ spec/helpers/units_helper_spec.rb | 15 ++ spec/models/price_history_spec.rb | 5 + spec/requests/price_histories_spec.rb | 11 ++ spec/requests/units_spec.rb | 11 ++ spec/routing/price_histories_routing_spec.rb | 35 ++++ spec/routing/units_routing_spec.rb | 35 ++++ .../price_histories/edit.html.erb_spec.rb | 32 ++++ .../price_histories/index.html.erb_spec.rb | 48 +++++ .../price_histories/new.html.erb_spec.rb | 32 ++++ .../price_histories/show.html.erb_spec.rb | 36 ++++ spec/views/units/edit.html.erb_spec.rb | 15 ++ spec/views/units/index.html.erb_spec.rb | 14 ++ spec/views/units/new.html.erb_spec.rb | 15 ++ spec/views/units/show.html.erb_spec.rb | 11 ++ 47 files changed, 1120 insertions(+), 11 deletions(-) create mode 100644 app/assets/javascripts/price.js.coffee create mode 100644 app/assets/javascripts/price_histories.js.coffee create mode 100644 app/assets/javascripts/units.js.coffee create mode 100644 app/assets/stylesheets/price.css.scss create mode 100644 app/assets/stylesheets/price_histories.css.scss create mode 100644 app/assets/stylesheets/units.css.scss create mode 100644 app/controllers/price_histories_controller.rb create mode 100644 app/controllers/units_controller.rb create mode 100644 app/helpers/price_helper.rb create mode 100644 app/helpers/price_histories_helper.rb create mode 100644 app/helpers/units_helper.rb create mode 100644 app/models/price_history.rb create mode 100644 app/views/price_histories/_form.html.erb create mode 100644 app/views/price_histories/edit.html.erb create mode 100644 app/views/price_histories/index.html.erb create mode 100644 app/views/price_histories/new.html.erb create mode 100644 app/views/price_histories/show.html.erb create mode 100644 app/views/units/_form.html.erb create mode 100644 app/views/units/edit.html.erb create mode 100644 app/views/units/index.html.erb create mode 100644 app/views/units/new.html.erb create mode 100644 app/views/units/show.html.erb create mode 100644 db/migrate/20120128023155_create_units.rb create mode 100644 db/migrate/20120128025115_create_price_histories.rb create mode 100644 spec/controllers/price_controller_spec.rb create mode 100644 spec/controllers/price_histories_controller_spec.rb create mode 100644 spec/controllers/units_controller_spec.rb create mode 100644 spec/helpers/price_helper_spec.rb create mode 100644 spec/helpers/price_histories_helper_spec.rb create mode 100644 spec/helpers/units_helper_spec.rb create mode 100644 spec/models/price_history_spec.rb create mode 100644 spec/requests/price_histories_spec.rb create mode 100644 spec/requests/units_spec.rb create mode 100644 spec/routing/price_histories_routing_spec.rb create mode 100644 spec/routing/units_routing_spec.rb create mode 100644 spec/views/price_histories/edit.html.erb_spec.rb create mode 100644 spec/views/price_histories/index.html.erb_spec.rb create mode 100644 spec/views/price_histories/new.html.erb_spec.rb create mode 100644 spec/views/price_histories/show.html.erb_spec.rb create mode 100644 spec/views/units/edit.html.erb_spec.rb create mode 100644 spec/views/units/index.html.erb_spec.rb create mode 100644 spec/views/units/new.html.erb_spec.rb create mode 100644 spec/views/units/show.html.erb_spec.rb diff --git a/app/assets/javascripts/price.js.coffee b/app/assets/javascripts/price.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/price.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/price_histories.js.coffee b/app/assets/javascripts/price_histories.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/price_histories.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/units.js.coffee b/app/assets/javascripts/units.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/units.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/price.css.scss b/app/assets/stylesheets/price.css.scss new file mode 100644 index 0000000..f0378aa --- /dev/null +++ b/app/assets/stylesheets/price.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the price 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/price_histories.css.scss b/app/assets/stylesheets/price_histories.css.scss new file mode 100644 index 0000000..66105b9 --- /dev/null +++ b/app/assets/stylesheets/price_histories.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the PriceHistories 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/units.css.scss b/app/assets/stylesheets/units.css.scss new file mode 100644 index 0000000..a7de626 --- /dev/null +++ b/app/assets/stylesheets/units.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the units 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/price_histories_controller.rb b/app/controllers/price_histories_controller.rb new file mode 100644 index 0000000..a1de26d --- /dev/null +++ b/app/controllers/price_histories_controller.rb @@ -0,0 +1,83 @@ +class PriceHistoriesController < ApplicationController + # GET /price_histories + # GET /price_histories.json + def index + @price_histories = PriceHistory.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @price_histories } + end + end + + # GET /price_histories/1 + # GET /price_histories/1.json + def show + @price_history = PriceHistory.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @price_history } + end + end + + # GET /price_histories/new + # GET /price_histories/new.json + def new + @price_history = PriceHistory.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @price_history } + end + end + + # GET /price_histories/1/edit + def edit + @price_history = PriceHistory.find(params[:id]) + end + + # POST /price_histories + # POST /price_histories.json + def create + @price_history = PriceHistory.new(params[:price_history]) + + respond_to do |format| + if @price_history.save + format.html { redirect_to @price_history, notice: 'Price history was successfully created.' } + format.json { render json: @price_history, status: :created, location: @price_history } + else + format.html { render action: "new" } + format.json { render json: @price_history.errors, status: :unprocessable_entity } + end + end + end + + # PUT /price_histories/1 + # PUT /price_histories/1.json + def update + @price_history = PriceHistory.find(params[:id]) + + respond_to do |format| + if @price_history.update_attributes(params[:price_history]) + format.html { redirect_to @price_history, notice: 'Price history was successfully updated.' } + format.json { head :ok } + else + format.html { render action: "edit" } + format.json { render json: @price_history.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /price_histories/1 + # DELETE /price_histories/1.json + def destroy + @price_history = PriceHistory.find(params[:id]) + @price_history.destroy + + respond_to do |format| + format.html { redirect_to price_histories_url } + format.json { head :ok } + end + end +end diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb new file mode 100644 index 0000000..bd62f65 --- /dev/null +++ b/app/controllers/units_controller.rb @@ -0,0 +1,83 @@ +class UnitsController < ApplicationController + # GET /units + # GET /units.json + def index + @units = Unit.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @units } + end + end + + # GET /units/1 + # GET /units/1.json + def show + @unit = Unit.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @unit } + end + end + + # GET /units/new + # GET /units/new.json + def new + @unit = Unit.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @unit } + end + end + + # GET /units/1/edit + def edit + @unit = Unit.find(params[:id]) + end + + # POST /units + # POST /units.json + def create + @unit = Unit.new(params[:unit]) + + respond_to do |format| + if @unit.save + format.html { redirect_to @unit, notice: 'Unit was successfully created.' } + format.json { render json: @unit, status: :created, location: @unit } + else + format.html { render action: "new" } + format.json { render json: @unit.errors, status: :unprocessable_entity } + end + end + end + + # PUT /units/1 + # PUT /units/1.json + def update + @unit = Unit.find(params[:id]) + + respond_to do |format| + if @unit.update_attributes(params[:unit]) + format.html { redirect_to @unit, notice: 'Unit was successfully updated.' } + format.json { head :ok } + else + format.html { render action: "edit" } + format.json { render json: @unit.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /units/1 + # DELETE /units/1.json + def destroy + @unit = Unit.find(params[:id]) + @unit.destroy + + respond_to do |format| + format.html { redirect_to units_url } + format.json { head :ok } + end + end +end diff --git a/app/helpers/price_helper.rb b/app/helpers/price_helper.rb new file mode 100644 index 0000000..d8f05a0 --- /dev/null +++ b/app/helpers/price_helper.rb @@ -0,0 +1,2 @@ +module PriceHelper +end diff --git a/app/helpers/price_histories_helper.rb b/app/helpers/price_histories_helper.rb new file mode 100644 index 0000000..4638472 --- /dev/null +++ b/app/helpers/price_histories_helper.rb @@ -0,0 +1,2 @@ +module PriceHistoriesHelper +end diff --git a/app/helpers/units_helper.rb b/app/helpers/units_helper.rb new file mode 100644 index 0000000..d8b2f3f --- /dev/null +++ b/app/helpers/units_helper.rb @@ -0,0 +1,2 @@ +module UnitsHelper +end diff --git a/app/models/commodity.rb b/app/models/commodity.rb index 6e1ffd8..f0dfff0 100644 --- a/app/models/commodity.rb +++ b/app/models/commodity.rb @@ -1,2 +1,6 @@ class Commodity < ActiveRecord::Base +# has_one retail_unit, :class_name => 'unit' +# has_one wholesale_unit, :class_name => 'unit' +# has_one farm_gate_unit, :class_name => 'unit' +# has_one delivered_unit, :class_name => 'unit' end diff --git a/app/models/price_history.rb b/app/models/price_history.rb new file mode 100644 index 0000000..683d6ce --- /dev/null +++ b/app/models/price_history.rb @@ -0,0 +1,2 @@ +class PriceHistory < ActiveRecord::Base +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 317c20e..5eed88c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -12,15 +12,15 @@

Kariokee - The db you were waiting for!

diff --git a/app/views/price_histories/_form.html.erb b/app/views/price_histories/_form.html.erb new file mode 100644 index 0000000..5873c64 --- /dev/null +++ b/app/views/price_histories/_form.html.erb @@ -0,0 +1,49 @@ +<%= form_for(@price_history) do |f| %> + <% if @price_history.errors.any? %> +
+

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

+ +
    + <% @price_history.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :farmGateLow %>
+ <%= f.number_field :farmGateLow %> +
+
+ <%= f.label :farmGateHigh %>
+ <%= f.number_field :farmGateHigh %> +
+
+ <%= f.label :deliverHigh %>
+ <%= f.number_field :deliverHigh %> +
+
+ <%= f.label :deliverLow %>
+ <%= f.number_field :deliverLow %> +
+
+ <%= f.label :wholesaleHigh %>
+ <%= f.number_field :wholesaleHigh %> +
+
+ <%= f.label :wholesaleHigh %>
+ <%= f.number_field :wholesaleHigh %> +
+
+ <%= f.label :retailHigh %>
+ <%= f.number_field :retailHigh %> +
+
+ <%= f.label :retailLow %>
+ <%= f.number_field :retailLow %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/price_histories/edit.html.erb b/app/views/price_histories/edit.html.erb new file mode 100644 index 0000000..10df8cc --- /dev/null +++ b/app/views/price_histories/edit.html.erb @@ -0,0 +1,6 @@ +

Editing price_history

+ +<%= render 'form' %> + +<%= link_to 'Show', @price_history %> | +<%= link_to 'Back', price_histories_path %> diff --git a/app/views/price_histories/index.html.erb b/app/views/price_histories/index.html.erb new file mode 100644 index 0000000..93d2b33 --- /dev/null +++ b/app/views/price_histories/index.html.erb @@ -0,0 +1,37 @@ +

Listing price_histories

+ + + + + + + + + + + + + + + + +<% @price_histories.each do |price_history| %> + + + + + + + + + + + + + +<% end %> +
FarmgatelowFarmgatehighDeliverhighDeliverlowWholesalehighWholesalehighRetailhighRetaillow
<%= price_history.farmGateLow %><%= price_history.farmGateHigh %><%= price_history.deliverHigh %><%= price_history.deliverLow %><%= price_history.wholesaleHigh %><%= price_history.wholesaleHigh %><%= price_history.retailHigh %><%= price_history.retailLow %><%= link_to 'Show', price_history %><%= link_to 'Edit', edit_price_history_path(price_history) %><%= link_to 'Destroy', price_history, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Price history', new_price_history_path %> diff --git a/app/views/price_histories/new.html.erb b/app/views/price_histories/new.html.erb new file mode 100644 index 0000000..530f775 --- /dev/null +++ b/app/views/price_histories/new.html.erb @@ -0,0 +1,5 @@ +

New price_history

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

<%= notice %>

+ +

+ Farmgatelow: + <%= @price_history.farmGateLow %> +

+ +

+ Farmgatehigh: + <%= @price_history.farmGateHigh %> +

+ +

+ Deliverhigh: + <%= @price_history.deliverHigh %> +

+ +

+ Deliverlow: + <%= @price_history.deliverLow %> +

+ +

+ Wholesalehigh: + <%= @price_history.wholesaleHigh %> +

+ +

+ Wholesalehigh: + <%= @price_history.wholesaleHigh %> +

+ +

+ Retailhigh: + <%= @price_history.retailHigh %> +

+ +

+ Retaillow: + <%= @price_history.retailLow %> +

+ + +<%= link_to 'Edit', edit_price_history_path(@price_history) %> | +<%= link_to 'Back', price_histories_path %> diff --git a/app/views/units/_form.html.erb b/app/views/units/_form.html.erb new file mode 100644 index 0000000..3a16227 --- /dev/null +++ b/app/views/units/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for(@unit) do |f| %> + <% if @unit.errors.any? %> +
+

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

+ +
    + <% @unit.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/units/edit.html.erb b/app/views/units/edit.html.erb new file mode 100644 index 0000000..0c99fca --- /dev/null +++ b/app/views/units/edit.html.erb @@ -0,0 +1,6 @@ +

Editing unit

+ +<%= render 'form' %> + +<%= link_to 'Show', @unit %> | +<%= link_to 'Back', units_path %> diff --git a/app/views/units/index.html.erb b/app/views/units/index.html.erb new file mode 100644 index 0000000..3cb75e0 --- /dev/null +++ b/app/views/units/index.html.erb @@ -0,0 +1,21 @@ +

Listing units

+ + + + + + + + +<% @units.each do |unit| %> + + + + + +<% end %> +
<%= link_to 'Show', unit %><%= link_to 'Edit', edit_unit_path(unit) %><%= link_to 'Destroy', unit, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Unit', new_unit_path %> diff --git a/app/views/units/new.html.erb b/app/views/units/new.html.erb new file mode 100644 index 0000000..9a37684 --- /dev/null +++ b/app/views/units/new.html.erb @@ -0,0 +1,5 @@ +

New unit

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

<%= notice %>

+ + +<%= link_to 'Edit', edit_unit_path(@unit) %> | +<%= link_to 'Back', units_path %> diff --git a/config/routes.rb b/config/routes.rb index 9ca5a97..b4e81d1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,11 @@ Kanakoo::Application.routes.draw do + resources :price_histories + resources :commodities resources :locations + + resources :units root :to => 'locations#index' diff --git a/db/migrate/20120128023155_create_units.rb b/db/migrate/20120128023155_create_units.rb new file mode 100644 index 0000000..513fd3d --- /dev/null +++ b/db/migrate/20120128023155_create_units.rb @@ -0,0 +1,8 @@ +class CreateUnits < ActiveRecord::Migration + def change + create_table :units do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20120128025115_create_price_histories.rb b/db/migrate/20120128025115_create_price_histories.rb new file mode 100644 index 0000000..08a3c0e --- /dev/null +++ b/db/migrate/20120128025115_create_price_histories.rb @@ -0,0 +1,16 @@ +class CreatePriceHistories < ActiveRecord::Migration + def change + create_table :price_histories do |t| + t.integer :farmGateLow + t.integer :farmGateHigh + t.integer :deliverHigh + t.integer :deliverLow + t.integer :wholesaleHigh + t.integer :wholesaleHigh + t.integer :retailHigh + t.integer :retailLow + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index e09b1bf..99038b0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,8 +11,7 @@ # # It's strongly recommended to check this file into your version control system. - -ActiveRecord::Schema.define(:version => 20120128010518) do +ActiveRecord::Schema.define(:version => 20120128025115) do create_table "commodities", :force => true do |t| t.string "nameEnglish" @@ -32,11 +31,18 @@ t.datetime "updated_at" end - create_table "units", :force => true do |t| - t.string "name" - t.string "swahili" + create_table "price_histories", :force => true do |t| + t.integer "farmGateLow" + t.integer "farmGateHigh" + t.integer "deliverHigh" + t.integer "deliverLow" + t.integer "wholesaleHigh" + t.integer "retailHigh" + t.integer "retailLow" + t.datetime "created_at" + t.datetime "updated_at" end - + create_table "prices", :force => true do |t| t.integer "unitPriceLow" t.integer "unitPriceHigh" @@ -50,4 +56,9 @@ t.datetime "updated_at" end + create_table "units", :force => true do |t| + t.datetime "created_at" + t.datetime "updated_at" + end + end diff --git a/spec/controllers/price_controller_spec.rb b/spec/controllers/price_controller_spec.rb new file mode 100644 index 0000000..4a31007 --- /dev/null +++ b/spec/controllers/price_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe PriceController do + +end diff --git a/spec/controllers/price_histories_controller_spec.rb b/spec/controllers/price_histories_controller_spec.rb new file mode 100644 index 0000000..66f67f9 --- /dev/null +++ b/spec/controllers/price_histories_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 PriceHistoriesController do + + # This should return the minimal set of attributes required to create a valid + # PriceHistory. As you add validations to PriceHistory, 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 + # PriceHistoriesController. Be sure to keep this updated too. + def valid_session + {} + end + + describe "GET index" do + it "assigns all price_histories as @price_histories" do + price_history = PriceHistory.create! valid_attributes + get :index, {}, valid_session + assigns(:price_histories).should eq([price_history]) + end + end + + describe "GET show" do + it "assigns the requested price_history as @price_history" do + price_history = PriceHistory.create! valid_attributes + get :show, {:id => price_history.to_param}, valid_session + assigns(:price_history).should eq(price_history) + end + end + + describe "GET new" do + it "assigns a new price_history as @price_history" do + get :new, {}, valid_session + assigns(:price_history).should be_a_new(PriceHistory) + end + end + + describe "GET edit" do + it "assigns the requested price_history as @price_history" do + price_history = PriceHistory.create! valid_attributes + get :edit, {:id => price_history.to_param}, valid_session + assigns(:price_history).should eq(price_history) + end + end + + describe "POST create" do + describe "with valid params" do + it "creates a new PriceHistory" do + expect { + post :create, {:price_history => valid_attributes}, valid_session + }.to change(PriceHistory, :count).by(1) + end + + it "assigns a newly created price_history as @price_history" do + post :create, {:price_history => valid_attributes}, valid_session + assigns(:price_history).should be_a(PriceHistory) + assigns(:price_history).should be_persisted + end + + it "redirects to the created price_history" do + post :create, {:price_history => valid_attributes}, valid_session + response.should redirect_to(PriceHistory.last) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved price_history as @price_history" do + # Trigger the behavior that occurs when invalid params are submitted + PriceHistory.any_instance.stub(:save).and_return(false) + post :create, {:price_history => {}}, valid_session + assigns(:price_history).should be_a_new(PriceHistory) + end + + it "re-renders the 'new' template" do + # Trigger the behavior that occurs when invalid params are submitted + PriceHistory.any_instance.stub(:save).and_return(false) + post :create, {:price_history => {}}, valid_session + response.should render_template("new") + end + end + end + + describe "PUT update" do + describe "with valid params" do + it "updates the requested price_history" do + price_history = PriceHistory.create! valid_attributes + # Assuming there are no other price_histories in the database, this + # specifies that the PriceHistory created on the previous line + # receives the :update_attributes message with whatever params are + # submitted in the request. + PriceHistory.any_instance.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, {:id => price_history.to_param, :price_history => {'these' => 'params'}}, valid_session + end + + it "assigns the requested price_history as @price_history" do + price_history = PriceHistory.create! valid_attributes + put :update, {:id => price_history.to_param, :price_history => valid_attributes}, valid_session + assigns(:price_history).should eq(price_history) + end + + it "redirects to the price_history" do + price_history = PriceHistory.create! valid_attributes + put :update, {:id => price_history.to_param, :price_history => valid_attributes}, valid_session + response.should redirect_to(price_history) + end + end + + describe "with invalid params" do + it "assigns the price_history as @price_history" do + price_history = PriceHistory.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + PriceHistory.any_instance.stub(:save).and_return(false) + put :update, {:id => price_history.to_param, :price_history => {}}, valid_session + assigns(:price_history).should eq(price_history) + end + + it "re-renders the 'edit' template" do + price_history = PriceHistory.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + PriceHistory.any_instance.stub(:save).and_return(false) + put :update, {:id => price_history.to_param, :price_history => {}}, valid_session + response.should render_template("edit") + end + end + end + + describe "DELETE destroy" do + it "destroys the requested price_history" do + price_history = PriceHistory.create! valid_attributes + expect { + delete :destroy, {:id => price_history.to_param}, valid_session + }.to change(PriceHistory, :count).by(-1) + end + + it "redirects to the price_histories list" do + price_history = PriceHistory.create! valid_attributes + delete :destroy, {:id => price_history.to_param}, valid_session + response.should redirect_to(price_histories_url) + end + end + +end diff --git a/spec/controllers/units_controller_spec.rb b/spec/controllers/units_controller_spec.rb new file mode 100644 index 0000000..928f553 --- /dev/null +++ b/spec/controllers/units_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 UnitsController do + + # This should return the minimal set of attributes required to create a valid + # Unit. As you add validations to Unit, 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 + # UnitsController. Be sure to keep this updated too. + def valid_session + {} + end + + describe "GET index" do + it "assigns all units as @units" do + unit = Unit.create! valid_attributes + get :index, {}, valid_session + assigns(:units).should eq([unit]) + end + end + + describe "GET show" do + it "assigns the requested unit as @unit" do + unit = Unit.create! valid_attributes + get :show, {:id => unit.to_param}, valid_session + assigns(:unit).should eq(unit) + end + end + + describe "GET new" do + it "assigns a new unit as @unit" do + get :new, {}, valid_session + assigns(:unit).should be_a_new(Unit) + end + end + + describe "GET edit" do + it "assigns the requested unit as @unit" do + unit = Unit.create! valid_attributes + get :edit, {:id => unit.to_param}, valid_session + assigns(:unit).should eq(unit) + end + end + + describe "POST create" do + describe "with valid params" do + it "creates a new Unit" do + expect { + post :create, {:unit => valid_attributes}, valid_session + }.to change(Unit, :count).by(1) + end + + it "assigns a newly created unit as @unit" do + post :create, {:unit => valid_attributes}, valid_session + assigns(:unit).should be_a(Unit) + assigns(:unit).should be_persisted + end + + it "redirects to the created unit" do + post :create, {:unit => valid_attributes}, valid_session + response.should redirect_to(Unit.last) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved unit as @unit" do + # Trigger the behavior that occurs when invalid params are submitted + Unit.any_instance.stub(:save).and_return(false) + post :create, {:unit => {}}, valid_session + assigns(:unit).should be_a_new(Unit) + end + + it "re-renders the 'new' template" do + # Trigger the behavior that occurs when invalid params are submitted + Unit.any_instance.stub(:save).and_return(false) + post :create, {:unit => {}}, valid_session + response.should render_template("new") + end + end + end + + describe "PUT update" do + describe "with valid params" do + it "updates the requested unit" do + unit = Unit.create! valid_attributes + # Assuming there are no other units in the database, this + # specifies that the Unit created on the previous line + # receives the :update_attributes message with whatever params are + # submitted in the request. + Unit.any_instance.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, {:id => unit.to_param, :unit => {'these' => 'params'}}, valid_session + end + + it "assigns the requested unit as @unit" do + unit = Unit.create! valid_attributes + put :update, {:id => unit.to_param, :unit => valid_attributes}, valid_session + assigns(:unit).should eq(unit) + end + + it "redirects to the unit" do + unit = Unit.create! valid_attributes + put :update, {:id => unit.to_param, :unit => valid_attributes}, valid_session + response.should redirect_to(unit) + end + end + + describe "with invalid params" do + it "assigns the unit as @unit" do + unit = Unit.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Unit.any_instance.stub(:save).and_return(false) + put :update, {:id => unit.to_param, :unit => {}}, valid_session + assigns(:unit).should eq(unit) + end + + it "re-renders the 'edit' template" do + unit = Unit.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Unit.any_instance.stub(:save).and_return(false) + put :update, {:id => unit.to_param, :unit => {}}, valid_session + response.should render_template("edit") + end + end + end + + describe "DELETE destroy" do + it "destroys the requested unit" do + unit = Unit.create! valid_attributes + expect { + delete :destroy, {:id => unit.to_param}, valid_session + }.to change(Unit, :count).by(-1) + end + + it "redirects to the units list" do + unit = Unit.create! valid_attributes + delete :destroy, {:id => unit.to_param}, valid_session + response.should redirect_to(units_url) + end + end + +end diff --git a/spec/helpers/price_helper_spec.rb b/spec/helpers/price_helper_spec.rb new file mode 100644 index 0000000..680089e --- /dev/null +++ b/spec/helpers/price_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the PriceHelper. For example: +# +# describe PriceHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe PriceHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/price_histories_helper_spec.rb b/spec/helpers/price_histories_helper_spec.rb new file mode 100644 index 0000000..8a5fac7 --- /dev/null +++ b/spec/helpers/price_histories_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the PriceHistoriesHelper. For example: +# +# describe PriceHistoriesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe PriceHistoriesHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/units_helper_spec.rb b/spec/helpers/units_helper_spec.rb new file mode 100644 index 0000000..ba09f2a --- /dev/null +++ b/spec/helpers/units_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the UnitsHelper. For example: +# +# describe UnitsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe UnitsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/price_history_spec.rb b/spec/models/price_history_spec.rb new file mode 100644 index 0000000..ea0a1ef --- /dev/null +++ b/spec/models/price_history_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe PriceHistory do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/price_histories_spec.rb b/spec/requests/price_histories_spec.rb new file mode 100644 index 0000000..b064682 --- /dev/null +++ b/spec/requests/price_histories_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe "PriceHistories" do + describe "GET /price_histories" 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 price_histories_path + response.status.should be(200) + end + end +end diff --git a/spec/requests/units_spec.rb b/spec/requests/units_spec.rb new file mode 100644 index 0000000..068f872 --- /dev/null +++ b/spec/requests/units_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe "Units" do + describe "GET /units" 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 units_path + response.status.should be(200) + end + end +end diff --git a/spec/routing/price_histories_routing_spec.rb b/spec/routing/price_histories_routing_spec.rb new file mode 100644 index 0000000..a6d7559 --- /dev/null +++ b/spec/routing/price_histories_routing_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe PriceHistoriesController do + describe "routing" do + + it "routes to #index" do + get("/price_histories").should route_to("price_histories#index") + end + + it "routes to #new" do + get("/price_histories/new").should route_to("price_histories#new") + end + + it "routes to #show" do + get("/price_histories/1").should route_to("price_histories#show", :id => "1") + end + + it "routes to #edit" do + get("/price_histories/1/edit").should route_to("price_histories#edit", :id => "1") + end + + it "routes to #create" do + post("/price_histories").should route_to("price_histories#create") + end + + it "routes to #update" do + put("/price_histories/1").should route_to("price_histories#update", :id => "1") + end + + it "routes to #destroy" do + delete("/price_histories/1").should route_to("price_histories#destroy", :id => "1") + end + + end +end diff --git a/spec/routing/units_routing_spec.rb b/spec/routing/units_routing_spec.rb new file mode 100644 index 0000000..b4dbf3f --- /dev/null +++ b/spec/routing/units_routing_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe UnitsController do + describe "routing" do + + it "routes to #index" do + get("/units").should route_to("units#index") + end + + it "routes to #new" do + get("/units/new").should route_to("units#new") + end + + it "routes to #show" do + get("/units/1").should route_to("units#show", :id => "1") + end + + it "routes to #edit" do + get("/units/1/edit").should route_to("units#edit", :id => "1") + end + + it "routes to #create" do + post("/units").should route_to("units#create") + end + + it "routes to #update" do + put("/units/1").should route_to("units#update", :id => "1") + end + + it "routes to #destroy" do + delete("/units/1").should route_to("units#destroy", :id => "1") + end + + end +end diff --git a/spec/views/price_histories/edit.html.erb_spec.rb b/spec/views/price_histories/edit.html.erb_spec.rb new file mode 100644 index 0000000..de56272 --- /dev/null +++ b/spec/views/price_histories/edit.html.erb_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe "price_histories/edit" do + before(:each) do + @price_history = assign(:price_history, stub_model(PriceHistory, + :farmGateLow => 1, + :farmGateHigh => 1, + :deliverHigh => 1, + :deliverLow => 1, + :wholesaleHigh => 1, + :wholesaleHigh => 1, + :retailHigh => 1, + :retailLow => 1 + )) + end + + it "renders the edit price_history form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => price_histories_path(@price_history), :method => "post" do + assert_select "input#price_history_farmGateLow", :name => "price_history[farmGateLow]" + assert_select "input#price_history_farmGateHigh", :name => "price_history[farmGateHigh]" + assert_select "input#price_history_deliverHigh", :name => "price_history[deliverHigh]" + assert_select "input#price_history_deliverLow", :name => "price_history[deliverLow]" + assert_select "input#price_history_wholesaleHigh", :name => "price_history[wholesaleHigh]" + assert_select "input#price_history_wholesaleHigh", :name => "price_history[wholesaleHigh]" + assert_select "input#price_history_retailHigh", :name => "price_history[retailHigh]" + assert_select "input#price_history_retailLow", :name => "price_history[retailLow]" + end + end +end diff --git a/spec/views/price_histories/index.html.erb_spec.rb b/spec/views/price_histories/index.html.erb_spec.rb new file mode 100644 index 0000000..64d9fd9 --- /dev/null +++ b/spec/views/price_histories/index.html.erb_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe "price_histories/index" do + before(:each) do + assign(:price_histories, [ + stub_model(PriceHistory, + :farmGateLow => 1, + :farmGateHigh => 1, + :deliverHigh => 1, + :deliverLow => 1, + :wholesaleHigh => 1, + :wholesaleHigh => 1, + :retailHigh => 1, + :retailLow => 1 + ), + stub_model(PriceHistory, + :farmGateLow => 1, + :farmGateHigh => 1, + :deliverHigh => 1, + :deliverLow => 1, + :wholesaleHigh => 1, + :wholesaleHigh => 1, + :retailHigh => 1, + :retailLow => 1 + ) + ]) + end + + it "renders a list of price_histories" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => 1.to_s, :count => 2 + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => 1.to_s, :count => 2 + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => 1.to_s, :count => 2 + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => 1.to_s, :count => 2 + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => 1.to_s, :count => 2 + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => 1.to_s, :count => 2 + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => 1.to_s, :count => 2 + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => 1.to_s, :count => 2 + end +end diff --git a/spec/views/price_histories/new.html.erb_spec.rb b/spec/views/price_histories/new.html.erb_spec.rb new file mode 100644 index 0000000..7f7b19e --- /dev/null +++ b/spec/views/price_histories/new.html.erb_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe "price_histories/new" do + before(:each) do + assign(:price_history, stub_model(PriceHistory, + :farmGateLow => 1, + :farmGateHigh => 1, + :deliverHigh => 1, + :deliverLow => 1, + :wholesaleHigh => 1, + :wholesaleHigh => 1, + :retailHigh => 1, + :retailLow => 1 + ).as_new_record) + end + + it "renders new price_history form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => price_histories_path, :method => "post" do + assert_select "input#price_history_farmGateLow", :name => "price_history[farmGateLow]" + assert_select "input#price_history_farmGateHigh", :name => "price_history[farmGateHigh]" + assert_select "input#price_history_deliverHigh", :name => "price_history[deliverHigh]" + assert_select "input#price_history_deliverLow", :name => "price_history[deliverLow]" + assert_select "input#price_history_wholesaleHigh", :name => "price_history[wholesaleHigh]" + assert_select "input#price_history_wholesaleHigh", :name => "price_history[wholesaleHigh]" + assert_select "input#price_history_retailHigh", :name => "price_history[retailHigh]" + assert_select "input#price_history_retailLow", :name => "price_history[retailLow]" + end + end +end diff --git a/spec/views/price_histories/show.html.erb_spec.rb b/spec/views/price_histories/show.html.erb_spec.rb new file mode 100644 index 0000000..1aeb538 --- /dev/null +++ b/spec/views/price_histories/show.html.erb_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe "price_histories/show" do + before(:each) do + @price_history = assign(:price_history, stub_model(PriceHistory, + :farmGateLow => 1, + :farmGateHigh => 1, + :deliverHigh => 1, + :deliverLow => 1, + :wholesaleHigh => 1, + :wholesaleHigh => 1, + :retailHigh => 1, + :retailLow => 1 + )) + end + + it "renders attributes in

" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + rendered.should match(/1/) + # Run the generator again with the --webrat flag if you want to use webrat matchers + rendered.should match(/1/) + # Run the generator again with the --webrat flag if you want to use webrat matchers + rendered.should match(/1/) + # Run the generator again with the --webrat flag if you want to use webrat matchers + rendered.should match(/1/) + # Run the generator again with the --webrat flag if you want to use webrat matchers + rendered.should match(/1/) + # Run the generator again with the --webrat flag if you want to use webrat matchers + rendered.should match(/1/) + # Run the generator again with the --webrat flag if you want to use webrat matchers + rendered.should match(/1/) + # Run the generator again with the --webrat flag if you want to use webrat matchers + rendered.should match(/1/) + end +end diff --git a/spec/views/units/edit.html.erb_spec.rb b/spec/views/units/edit.html.erb_spec.rb new file mode 100644 index 0000000..a67ee7a --- /dev/null +++ b/spec/views/units/edit.html.erb_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe "units/edit" do + before(:each) do + @unit = assign(:unit, stub_model(Unit)) + end + + it "renders the edit unit form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => units_path(@unit), :method => "post" do + end + end +end diff --git a/spec/views/units/index.html.erb_spec.rb b/spec/views/units/index.html.erb_spec.rb new file mode 100644 index 0000000..1884ed2 --- /dev/null +++ b/spec/views/units/index.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe "units/index" do + before(:each) do + assign(:units, [ + stub_model(Unit), + stub_model(Unit) + ]) + end + + it "renders a list of units" do + render + end +end diff --git a/spec/views/units/new.html.erb_spec.rb b/spec/views/units/new.html.erb_spec.rb new file mode 100644 index 0000000..76bb5f0 --- /dev/null +++ b/spec/views/units/new.html.erb_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe "units/new" do + before(:each) do + assign(:unit, stub_model(Unit).as_new_record) + end + + it "renders new unit form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => units_path, :method => "post" do + end + end +end diff --git a/spec/views/units/show.html.erb_spec.rb b/spec/views/units/show.html.erb_spec.rb new file mode 100644 index 0000000..5e1b04a --- /dev/null +++ b/spec/views/units/show.html.erb_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe "units/show" do + before(:each) do + @unit = assign(:unit, stub_model(Unit)) + end + + it "renders attributes in

" do + render + end +end