Skip to content

Instantly share code, notes, and snippets.

@wenbert
Created January 17, 2012 13:05
Show Gist options
  • Save wenbert/1626569 to your computer and use it in GitHub Desktop.
Save wenbert/1626569 to your computer and use it in GitHub Desktop.
## error
AllergiesControllerTest:
FAIL should create allergy (0.40s)
"Allergy.count" didn't change by 1.
<3> expected but was
<2>.
## test
test "should create allergy" do
assert_difference('Allergy.count') do
post :create, :post => @allergy, :patient_id => @allergy.patient_id
end
assert_redirected_to patients_path
end
#controller
# GET /allergies/new
# GET /allergies/new.json
def new
@patient = Patient.find(params[:patient_id])
@allergy = @patient.allergies.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @allergy }
end
end
# GET /allergies/1/edit
def edit
@allergy = Allergy.find(params[:id])
end
# POST /allergies
# POST /allergies.json
def create
#@allergy = Allergy.new(params[:allergy])
@allergy = Patient.find(params[:patient_id]).allergies.build(params[:allergy])
respond_to do |format|
if @allergy.save
format.html { redirect_to patient_url(params[:patient_id]), notice: 'Allergy was successfully created.' }
#format.json { render json: @allergy, status: :created, location: @allergy }
else
format.html { render action: "new" }
format.json { render json: @allergy.errors, status: :unprocessable_entity }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment