From e9a3c0f4ee349badb7671df86a50888efaedf613 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Wed, 30 Oct 2013 23:32:20 +0000 Subject: [PATCH] rails g scaffold PlantPart... Also migration to remove the string plant_part. --- app/assets/javascripts/plant_parts.js.coffee | 3 + app/controllers/plant_parts_controller.rb | 83 +++++++++ app/helpers/plant_parts_helper.rb | 2 + app/models/harvest.rb | 23 +-- app/models/plant_part.rb | 3 + app/views/harvests/_form.html.haml | 2 +- app/views/plant_parts/_form.html.haml | 13 ++ app/views/plant_parts/edit.html.haml | 7 + app/views/plant_parts/index.html.haml | 19 ++ app/views/plant_parts/new.html.haml | 5 + app/views/plant_parts/show.html.haml | 9 + config/routes.rb | 3 + .../20131030230908_create_plant_parts.rb | 9 + ...1202_change_plant_part_to_plant_part_id.rb | 11 ++ db/schema.rb | 10 +- .../plant_parts_controller_spec.rb | 164 ++++++++++++++++++ spec/factories/harvests.rb | 1 + spec/factories/plant_parts.rb | 7 + spec/helpers/plant_parts_helper_spec.rb | 15 ++ spec/models/harvest_spec.rb | 15 -- spec/models/plant_part_spec.rb | 5 + spec/requests/plant_parts_spec.rb | 11 ++ spec/routing/plant_parts_routing_spec.rb | 35 ++++ spec/views/harvests/edit.html.haml_spec.rb | 2 +- spec/views/harvests/new.html.haml_spec.rb | 2 +- spec/views/plant_parts/edit.html.haml_spec.rb | 18 ++ .../views/plant_parts/index.html.haml_spec.rb | 20 +++ spec/views/plant_parts/new.html.haml_spec.rb | 18 ++ spec/views/plant_parts/show.html.haml_spec.rb | 15 ++ 29 files changed, 489 insertions(+), 41 deletions(-) create mode 100644 app/assets/javascripts/plant_parts.js.coffee create mode 100644 app/controllers/plant_parts_controller.rb create mode 100644 app/helpers/plant_parts_helper.rb create mode 100644 app/models/plant_part.rb create mode 100644 app/views/plant_parts/_form.html.haml create mode 100644 app/views/plant_parts/edit.html.haml create mode 100644 app/views/plant_parts/index.html.haml create mode 100644 app/views/plant_parts/new.html.haml create mode 100644 app/views/plant_parts/show.html.haml create mode 100644 db/migrate/20131030230908_create_plant_parts.rb create mode 100644 db/migrate/20131030231202_change_plant_part_to_plant_part_id.rb create mode 100644 spec/controllers/plant_parts_controller_spec.rb create mode 100644 spec/factories/plant_parts.rb create mode 100644 spec/helpers/plant_parts_helper_spec.rb create mode 100644 spec/models/plant_part_spec.rb create mode 100644 spec/requests/plant_parts_spec.rb create mode 100644 spec/routing/plant_parts_routing_spec.rb create mode 100644 spec/views/plant_parts/edit.html.haml_spec.rb create mode 100644 spec/views/plant_parts/index.html.haml_spec.rb create mode 100644 spec/views/plant_parts/new.html.haml_spec.rb create mode 100644 spec/views/plant_parts/show.html.haml_spec.rb diff --git a/app/assets/javascripts/plant_parts.js.coffee b/app/assets/javascripts/plant_parts.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/plant_parts.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/controllers/plant_parts_controller.rb b/app/controllers/plant_parts_controller.rb new file mode 100644 index 000000000..c094f7f24 --- /dev/null +++ b/app/controllers/plant_parts_controller.rb @@ -0,0 +1,83 @@ +class PlantPartsController < ApplicationController + # GET /plant_parts + # GET /plant_parts.json + def index + @plant_parts = PlantPart.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @plant_parts } + end + end + + # GET /plant_parts/1 + # GET /plant_parts/1.json + def show + @plant_part = PlantPart.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @plant_part } + end + end + + # GET /plant_parts/new + # GET /plant_parts/new.json + def new + @plant_part = PlantPart.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @plant_part } + end + end + + # GET /plant_parts/1/edit + def edit + @plant_part = PlantPart.find(params[:id]) + end + + # POST /plant_parts + # POST /plant_parts.json + def create + @plant_part = PlantPart.new(params[:plant_part]) + + respond_to do |format| + if @plant_part.save + format.html { redirect_to @plant_part, notice: 'Plant part was successfully created.' } + format.json { render json: @plant_part, status: :created, location: @plant_part } + else + format.html { render action: "new" } + format.json { render json: @plant_part.errors, status: :unprocessable_entity } + end + end + end + + # PUT /plant_parts/1 + # PUT /plant_parts/1.json + def update + @plant_part = PlantPart.find(params[:id]) + + respond_to do |format| + if @plant_part.update_attributes(params[:plant_part]) + format.html { redirect_to @plant_part, notice: 'Plant part was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @plant_part.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /plant_parts/1 + # DELETE /plant_parts/1.json + def destroy + @plant_part = PlantPart.find(params[:id]) + @plant_part.destroy + + respond_to do |format| + format.html { redirect_to plant_parts_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/plant_parts_helper.rb b/app/helpers/plant_parts_helper.rb new file mode 100644 index 000000000..b97b124e8 --- /dev/null +++ b/app/helpers/plant_parts_helper.rb @@ -0,0 +1,2 @@ +module PlantPartsHelper +end diff --git a/app/models/harvest.rb b/app/models/harvest.rb index 62e6a4ee9..f4b0f1449 100644 --- a/app/models/harvest.rb +++ b/app/models/harvest.rb @@ -3,10 +3,11 @@ class Harvest < ActiveRecord::Base friendly_id :harvest_slug, use: :slugged attr_accessible :crop_id, :harvested_at, :description, :owner_id, - :quantity, :unit, :weight_quantity, :weight_unit, :plant_part, :slug + :quantity, :unit, :weight_quantity, :weight_unit, :plant_part_id, :slug belongs_to :crop belongs_to :owner, :class_name => 'Member' + belongs_to :plant_part validates :quantity, :numericality => { :only_integer => false }, @@ -44,26 +45,6 @@ class Harvest < ActiveRecord::Base after_validation :cleanup_quantities - PLANT_PARTS = [ - 'fruit', - 'flower', - 'pollen', - 'seed', - 'pod', - 'leaf', - 'stem', - 'bark', - 'bulb', - 'root', - 'tuber', - 'whole plant', - 'other' - ] - validates :plant_part, :inclusion => { :in => PLANT_PARTS, - :message => "%{value} is not a valid plant part" }, - :allow_nil => true, - :allow_blank => true - def cleanup_quantities if quantity == 0 self.quantity = nil diff --git a/app/models/plant_part.rb b/app/models/plant_part.rb new file mode 100644 index 000000000..096a8316b --- /dev/null +++ b/app/models/plant_part.rb @@ -0,0 +1,3 @@ +class PlantPart < ActiveRecord::Base + attr_accessible :name +end diff --git a/app/views/harvests/_form.html.haml b/app/views/harvests/_form.html.haml index 7d99e40c7..3a985d82e 100644 --- a/app/views/harvests/_form.html.haml +++ b/app/views/harvests/_form.html.haml @@ -10,7 +10,7 @@ = f.label 'What did you harvest?', :class => 'control-label' .controls = collection_select(:harvest, :crop_id, Crop.all, :id, :name, :selected => @harvest.crop_id || @crop.id) - = f.select(:plant_part, Harvest::PLANT_PARTS, { :include_blank => false }, :class => 'input-medium') + = collection_select(:harvest, :plant_part_id, PlantPart.all, :id, :name, :selected => @harvest.plant_part_id) %span.help-block Can't find what you're looking for? = link_to "Request new crops.", Growstuff::Application.config.new_crops_request_link diff --git a/app/views/plant_parts/_form.html.haml b/app/views/plant_parts/_form.html.haml new file mode 100644 index 000000000..16bf0268d --- /dev/null +++ b/app/views/plant_parts/_form.html.haml @@ -0,0 +1,13 @@ += form_for @plant_part do |f| + - if @plant_part.errors.any? + #error_explanation + %h2= "#{pluralize(@plant_part.errors.count, "error")} prohibited this plant_part from being saved:" + %ul + - @plant_part.errors.full_messages.each do |msg| + %li= msg + + .field + = f.label :name + = f.text_field :name + .actions + = f.submit 'Save' diff --git a/app/views/plant_parts/edit.html.haml b/app/views/plant_parts/edit.html.haml new file mode 100644 index 000000000..6add25fb3 --- /dev/null +++ b/app/views/plant_parts/edit.html.haml @@ -0,0 +1,7 @@ +%h1 Editing plant_part + += render 'form' + += link_to 'Show', @plant_part +\| += link_to 'Back', plant_parts_path diff --git a/app/views/plant_parts/index.html.haml b/app/views/plant_parts/index.html.haml new file mode 100644 index 000000000..e9543524d --- /dev/null +++ b/app/views/plant_parts/index.html.haml @@ -0,0 +1,19 @@ +%h1 Listing plant_parts + +%table + %tr + %th Name + %th + %th + %th + + - @plant_parts.each do |plant_part| + %tr + %td= plant_part.name + %td= link_to 'Show', plant_part + %td= link_to 'Edit', edit_plant_part_path(plant_part) + %td= link_to 'Destroy', plant_part, :method => :delete, :data => { :confirm => 'Are you sure?' } + +%br + += link_to 'New Plant part', new_plant_part_path diff --git a/app/views/plant_parts/new.html.haml b/app/views/plant_parts/new.html.haml new file mode 100644 index 000000000..604c38a04 --- /dev/null +++ b/app/views/plant_parts/new.html.haml @@ -0,0 +1,5 @@ +%h1 New plant_part + += render 'form' + += link_to 'Back', plant_parts_path diff --git a/app/views/plant_parts/show.html.haml b/app/views/plant_parts/show.html.haml new file mode 100644 index 000000000..36c89176d --- /dev/null +++ b/app/views/plant_parts/show.html.haml @@ -0,0 +1,9 @@ +%p#notice= notice + +%p + %b Name: + = @plant_part.name + += link_to 'Edit', edit_plant_part_path(@plant_part) +\| += link_to 'Back', plant_parts_path diff --git a/config/routes.rb b/config/routes.rb index 1be11c8a5..eb0c323c5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ Growstuff::Application.routes.draw do + resources :plant_parts + + devise_for :members, :controllers => { :registrations => "registrations" } resources :members diff --git a/db/migrate/20131030230908_create_plant_parts.rb b/db/migrate/20131030230908_create_plant_parts.rb new file mode 100644 index 000000000..896eeeeac --- /dev/null +++ b/db/migrate/20131030230908_create_plant_parts.rb @@ -0,0 +1,9 @@ +class CreatePlantParts < ActiveRecord::Migration + def change + create_table :plant_parts do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/migrate/20131030231202_change_plant_part_to_plant_part_id.rb b/db/migrate/20131030231202_change_plant_part_to_plant_part_id.rb new file mode 100644 index 000000000..cfadbf1c6 --- /dev/null +++ b/db/migrate/20131030231202_change_plant_part_to_plant_part_id.rb @@ -0,0 +1,11 @@ +class ChangePlantPartToPlantPartId < ActiveRecord::Migration + def up + remove_column :harvests, :plant_part + add_column :harvests, :plant_part_id, :integer + end + + def down + remove_column :harvests, :plant_part_id + add_column :harvests, :plant_part, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 2cd1124d9..ff7a0f8b6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20131029053113) do +ActiveRecord::Schema.define(:version => 20131030231202) do create_table "account_types", :force => true do |t| t.string "name", :null => false @@ -105,7 +105,7 @@ ActiveRecord::Schema.define(:version => 20131029053113) do t.string "slug" t.decimal "weight_quantity" t.string "weight_unit" - t.string "plant_part" + t.integer "plant_part_id" end create_table "members", :force => true do |t| @@ -205,6 +205,12 @@ ActiveRecord::Schema.define(:version => 20131029053113) do t.integer "planting_id" end + create_table "plant_parts", :force => true do |t| + t.string "name" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "plantings", :force => true do |t| t.integer "garden_id", :null => false t.integer "crop_id", :null => false diff --git a/spec/controllers/plant_parts_controller_spec.rb b/spec/controllers/plant_parts_controller_spec.rb new file mode 100644 index 000000000..1d8c1a6ec --- /dev/null +++ b/spec/controllers/plant_parts_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 PlantPartsController do + + # This should return the minimal set of attributes required to create a valid + # PlantPart. As you add validations to PlantPart, be sure to + # update the return value of this method accordingly. + def valid_attributes + { "name" => "MyString" } + 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 + # PlantPartsController. Be sure to keep this updated too. + def valid_session + {} + end + + describe "GET index" do + it "assigns all plant_parts as @plant_parts" do + plant_part = PlantPart.create! valid_attributes + get :index, {}, valid_session + assigns(:plant_parts).should eq([plant_part]) + end + end + + describe "GET show" do + it "assigns the requested plant_part as @plant_part" do + plant_part = PlantPart.create! valid_attributes + get :show, {:id => plant_part.to_param}, valid_session + assigns(:plant_part).should eq(plant_part) + end + end + + describe "GET new" do + it "assigns a new plant_part as @plant_part" do + get :new, {}, valid_session + assigns(:plant_part).should be_a_new(PlantPart) + end + end + + describe "GET edit" do + it "assigns the requested plant_part as @plant_part" do + plant_part = PlantPart.create! valid_attributes + get :edit, {:id => plant_part.to_param}, valid_session + assigns(:plant_part).should eq(plant_part) + end + end + + describe "POST create" do + describe "with valid params" do + it "creates a new PlantPart" do + expect { + post :create, {:plant_part => valid_attributes}, valid_session + }.to change(PlantPart, :count).by(1) + end + + it "assigns a newly created plant_part as @plant_part" do + post :create, {:plant_part => valid_attributes}, valid_session + assigns(:plant_part).should be_a(PlantPart) + assigns(:plant_part).should be_persisted + end + + it "redirects to the created plant_part" do + post :create, {:plant_part => valid_attributes}, valid_session + response.should redirect_to(PlantPart.last) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved plant_part as @plant_part" do + # Trigger the behavior that occurs when invalid params are submitted + PlantPart.any_instance.stub(:save).and_return(false) + post :create, {:plant_part => { "name" => "invalid value" }}, valid_session + assigns(:plant_part).should be_a_new(PlantPart) + end + + it "re-renders the 'new' template" do + # Trigger the behavior that occurs when invalid params are submitted + PlantPart.any_instance.stub(:save).and_return(false) + post :create, {:plant_part => { "name" => "invalid value" }}, valid_session + response.should render_template("new") + end + end + end + + describe "PUT update" do + describe "with valid params" do + it "updates the requested plant_part" do + plant_part = PlantPart.create! valid_attributes + # Assuming there are no other plant_parts in the database, this + # specifies that the PlantPart created on the previous line + # receives the :update_attributes message with whatever params are + # submitted in the request. + PlantPart.any_instance.should_receive(:update_attributes).with({ "name" => "MyString" }) + put :update, {:id => plant_part.to_param, :plant_part => { "name" => "MyString" }}, valid_session + end + + it "assigns the requested plant_part as @plant_part" do + plant_part = PlantPart.create! valid_attributes + put :update, {:id => plant_part.to_param, :plant_part => valid_attributes}, valid_session + assigns(:plant_part).should eq(plant_part) + end + + it "redirects to the plant_part" do + plant_part = PlantPart.create! valid_attributes + put :update, {:id => plant_part.to_param, :plant_part => valid_attributes}, valid_session + response.should redirect_to(plant_part) + end + end + + describe "with invalid params" do + it "assigns the plant_part as @plant_part" do + plant_part = PlantPart.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + PlantPart.any_instance.stub(:save).and_return(false) + put :update, {:id => plant_part.to_param, :plant_part => { "name" => "invalid value" }}, valid_session + assigns(:plant_part).should eq(plant_part) + end + + it "re-renders the 'edit' template" do + plant_part = PlantPart.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + PlantPart.any_instance.stub(:save).and_return(false) + put :update, {:id => plant_part.to_param, :plant_part => { "name" => "invalid value" }}, valid_session + response.should render_template("edit") + end + end + end + + describe "DELETE destroy" do + it "destroys the requested plant_part" do + plant_part = PlantPart.create! valid_attributes + expect { + delete :destroy, {:id => plant_part.to_param}, valid_session + }.to change(PlantPart, :count).by(-1) + end + + it "redirects to the plant_parts list" do + plant_part = PlantPart.create! valid_attributes + delete :destroy, {:id => plant_part.to_param}, valid_session + response.should redirect_to(plant_parts_url) + end + end + +end diff --git a/spec/factories/harvests.rb b/spec/factories/harvests.rb index 407ccc875..71356388a 100644 --- a/spec/factories/harvests.rb +++ b/spec/factories/harvests.rb @@ -3,6 +3,7 @@ FactoryGirl.define do factory :harvest do crop + plant_part owner harvested_at "2013-09-17" quantity "3" diff --git a/spec/factories/plant_parts.rb b/spec/factories/plant_parts.rb new file mode 100644 index 000000000..c0d6c53aa --- /dev/null +++ b/spec/factories/plant_parts.rb @@ -0,0 +1,7 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :plant_part do + name "pollen" + end +end diff --git a/spec/helpers/plant_parts_helper_spec.rb b/spec/helpers/plant_parts_helper_spec.rb new file mode 100644 index 000000000..bae3d4ba7 --- /dev/null +++ b/spec/helpers/plant_parts_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the PlantPartsHelper. For example: +# +# describe PlantPartsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe PlantPartsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/harvest_spec.rb b/spec/models/harvest_spec.rb index da9caa199..fc882a67c 100644 --- a/spec/models/harvest_spec.rb +++ b/spec/models/harvest_spec.rb @@ -118,19 +118,4 @@ describe Harvest do end end - context "plant parts" do - it 'all valid plant parts should work' do - Harvest::PLANT_PARTS.push(nil, '').each do |p| - @harvest = FactoryGirl.build(:harvest, :plant_part => p) - @harvest.should be_valid - end - end - - it 'should refuse invalid plant parts' do - @harvest = FactoryGirl.build(:harvest, :plant_part => 'leg') - @harvest.should_not be_valid - @harvest.errors[:plant_part].should include("leg is not a valid plant part") - end - end - end diff --git a/spec/models/plant_part_spec.rb b/spec/models/plant_part_spec.rb new file mode 100644 index 000000000..78ba72cf2 --- /dev/null +++ b/spec/models/plant_part_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe PlantPart do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/plant_parts_spec.rb b/spec/requests/plant_parts_spec.rb new file mode 100644 index 000000000..4f607b22f --- /dev/null +++ b/spec/requests/plant_parts_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe "PlantParts" do + describe "GET /plant_parts" 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 plant_parts_path + response.status.should be(200) + end + end +end diff --git a/spec/routing/plant_parts_routing_spec.rb b/spec/routing/plant_parts_routing_spec.rb new file mode 100644 index 000000000..419b4a05e --- /dev/null +++ b/spec/routing/plant_parts_routing_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe PlantPartsController do + describe "routing" do + + it "routes to #index" do + get("/plant_parts").should route_to("plant_parts#index") + end + + it "routes to #new" do + get("/plant_parts/new").should route_to("plant_parts#new") + end + + it "routes to #show" do + get("/plant_parts/1").should route_to("plant_parts#show", :id => "1") + end + + it "routes to #edit" do + get("/plant_parts/1/edit").should route_to("plant_parts#edit", :id => "1") + end + + it "routes to #create" do + post("/plant_parts").should route_to("plant_parts#create") + end + + it "routes to #update" do + put("/plant_parts/1").should route_to("plant_parts#update", :id => "1") + end + + it "routes to #destroy" do + delete("/plant_parts/1").should route_to("plant_parts#destroy", :id => "1") + end + + end +end diff --git a/spec/views/harvests/edit.html.haml_spec.rb b/spec/views/harvests/edit.html.haml_spec.rb index 2c267e1bd..b2e4bc665 100644 --- a/spec/views/harvests/edit.html.haml_spec.rb +++ b/spec/views/harvests/edit.html.haml_spec.rb @@ -9,7 +9,7 @@ describe "harvests/edit" do it "renders new harvest form" do assert_select "form", :action => harvests_path, :method => "post" do assert_select "select#harvest_crop_id", :name => "harvest[crop_id]" - assert_select "select#harvest_plant_part", :name => "harvest[plant_part]" + assert_select "select#harvest_plant_part_id", :name => "harvest[plant_part_id]" assert_select "input#harvest_quantity", :name => "harvest[quantity]" assert_select "input#harvest_weight_quantity", :name => "harvest[quantity]" assert_select "select#harvest_unit", :name => "harvest[unit]" diff --git a/spec/views/harvests/new.html.haml_spec.rb b/spec/views/harvests/new.html.haml_spec.rb index 590aeea03..a09233fac 100644 --- a/spec/views/harvests/new.html.haml_spec.rb +++ b/spec/views/harvests/new.html.haml_spec.rb @@ -9,7 +9,7 @@ describe "harvests/new" do it "renders new harvest form" do assert_select "form", :action => harvests_path, :method => "post" do assert_select "select#harvest_crop_id", :name => "harvest[crop_id]" - assert_select "select#harvest_plant_part", :name => "harvest[plant_part]" + assert_select "select#harvest_plant_part_id", :name => "harvest[plant_part_id]" assert_select "input#harvest_quantity", :name => "harvest[quantity]" assert_select "input#harvest_weight_quantity", :name => "harvest[quantity]" assert_select "select#harvest_unit", :name => "harvest[unit]" diff --git a/spec/views/plant_parts/edit.html.haml_spec.rb b/spec/views/plant_parts/edit.html.haml_spec.rb new file mode 100644 index 000000000..2011b34c3 --- /dev/null +++ b/spec/views/plant_parts/edit.html.haml_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe "plant_parts/edit" do + before(:each) do + @plant_part = assign(:plant_part, stub_model(PlantPart, + :name => "MyString" + )) + end + + it "renders the edit plant_part form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => plant_parts_path(@plant_part), :method => "post" do + assert_select "input#plant_part_name", :name => "plant_part[name]" + end + end +end diff --git a/spec/views/plant_parts/index.html.haml_spec.rb b/spec/views/plant_parts/index.html.haml_spec.rb new file mode 100644 index 000000000..7e88379ba --- /dev/null +++ b/spec/views/plant_parts/index.html.haml_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe "plant_parts/index" do + before(:each) do + assign(:plant_parts, [ + stub_model(PlantPart, + :name => "Name" + ), + stub_model(PlantPart, + :name => "Name" + ) + ]) + end + + it "renders a list of plant_parts" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => "Name".to_s, :count => 2 + end +end diff --git a/spec/views/plant_parts/new.html.haml_spec.rb b/spec/views/plant_parts/new.html.haml_spec.rb new file mode 100644 index 000000000..6a415fd4e --- /dev/null +++ b/spec/views/plant_parts/new.html.haml_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe "plant_parts/new" do + before(:each) do + assign(:plant_part, stub_model(PlantPart, + :name => "MyString" + ).as_new_record) + end + + it "renders new plant_part form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => plant_parts_path, :method => "post" do + assert_select "input#plant_part_name", :name => "plant_part[name]" + end + end +end diff --git a/spec/views/plant_parts/show.html.haml_spec.rb b/spec/views/plant_parts/show.html.haml_spec.rb new file mode 100644 index 000000000..8abdcee89 --- /dev/null +++ b/spec/views/plant_parts/show.html.haml_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe "plant_parts/show" do + before(:each) do + @plant_part = assign(:plant_part, stub_model(PlantPart, + :name => "Name" + )) + 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(/Name/) + end +end