added crop_id and garden_id params to controller

This commit is contained in:
Skud
2012-12-23 10:01:19 +11:00
parent bf2b1d6596
commit 02daab4fc1
2 changed files with 39 additions and 24 deletions

View File

@@ -27,6 +27,10 @@ class PlantingsController < ApplicationController
def new
@planting = Planting.new
# using find_by_id here because it returns nil, unlike find
@crop = Crop.find_by_id(params[:crop_id])
@garden = Garden.find_by_id(params[:garden_id])
respond_to do |format|
format.html # new.html.erb
format.json { render json: @planting }

View File

@@ -1,35 +1,11 @@
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 PlantingsController do
# This should return the minimal set of attributes required to create a valid
# Planting. As you add validations to Planting, be sure to
# update the return value of this method accordingly.
def valid_attributes
{ :garden_id => 1, :crop_id => 1 }
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
# PlantingsController. Be sure to keep this updated too.
def valid_session
{}
end
@@ -55,6 +31,41 @@ describe PlantingsController do
get :new, {}, valid_session
assigns(:planting).should be_a_new(Planting)
end
it "picks up crop from params" do
crop = Crop.create!(
:system_name => 'Maize',
:en_wikipedia_url => 'http://blah'
)
get :new, {:crop_id => crop.id}, valid_session
assigns(:crop).should eq(crop)
end
it "doesn't die if no crop specified" do
get :new, {}, valid_session
assigns(:crop).should be_nil
end
it "picks up garden from params" do
user = User.create!(
:username => 'blah',
:password => 'blahblah',
:email => 'blah@example.com',
:tos_agreement => true
)
garden = Garden.create!(
:name => 'blah',
:user_id => user.id
)
get :new, {:garden_id => garden.id}, valid_session
assigns(:garden).should eq(garden)
end
it "doesn't die if no garden specified" do
get :new, {}, valid_session
assigns(:garden).should be_nil
end
end
describe "GET edit" do