Skip to content

Commit

Permalink
Much nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Jan 28, 2016
1 parent c2c00b5 commit 2ebe8f5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
8 changes: 4 additions & 4 deletions app/controllers/glucose_measurements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ def edit
def create
@glucose_measurement = GlucoseMeasurement.new(glucose_measurement_params)
if @glucose_measurement.save
redirect_to @glucose_measurement
redirect_to glucose_measurements_path
else
render 'new'
render :new
end
end

def update
@glucose_measurement = GlucoseMeasurement.find(params[:id])

if @glucose_measurement.update(glucose_measurement_params)
redirect_to @glucose_measurement
redirect_to glucose_measurements_path
else
render 'edit'
render :edit
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/glucose_measurements_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@
}.to change(GlucoseMeasurement, :count).by 1
end

it 'redirects to the new measurement' do
it 'redirects to the index page' do
post :create, glucose_measurement: attributes_for(:glucose_measurement)
expect(response).to redirect_to GlucoseMeasurement.last
# expect(response).to redirect_to render_template :index
expect(response).to redirect_to glucose_measurements_url
end
end

Expand Down Expand Up @@ -78,8 +77,9 @@
end

it 'redirects to the updated measurement' do
put :update, id: test_measurement, glucose_measurement: attributes_for(:invalid_glucose_measurement)
put :update, id: test_measurement, glucose_measurement: attributes_for(:glucose_measurement)
expect(assigns :glucose_measurement).to eq test_measurement
expect(response).to redirect_to glucose_measurements_url
end
end

Expand Down
10 changes: 4 additions & 6 deletions spec/requests/glucose_measurements_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
click_button 'Create'
}.to change(GlucoseMeasurement, :count).by 1

within 'h1' do
expect(page).to have_content 'Datetime: 2016-01-27 17:53:00'
end

within 'h2' do
expect(page).to have_content '5.6'
within 'th' do
expect(page).to have_content 'Wednesday January 27th'
end
expect(page).to have_content '17:53'
expect(page).to have_content '5.6'
end

it 'Edit a measurement' do
Expand Down

0 comments on commit 2ebe8f5

Please sign in to comment.