Created
January 17, 2012 13:06
-
-
Save wenbert/1626573 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AllergiesControllerTest: | |
FAIL should create allergy (0.40s) | |
"Allergy.count" didn't change by 1. | |
<3> expected but was | |
<2>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment