-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now I have another problem :/
- Loading branch information
pikesley
committed
Jan 29, 2016
1 parent
ec1c091
commit eb93591
Showing
17 changed files
with
221 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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://coffeescript.org/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the CarbohydrateIntake controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CarbohydrateIntakesController < GenericController | ||
private | ||
|
||
def metrics_path | ||
carbohydrate_intakes_path | ||
end | ||
|
||
def acceptable_params | ||
params.require(:carbohydrate_intake).permit(:datetime, :weight, :description) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module CarbohydrateIntakeHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<%= form_for @metric do |f| %> | ||
<% if @metric.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2> | ||
<%= pluralize(@metric.errors.count, "error") %> prohibited | ||
this measurement from being saved: | ||
</h2> | ||
<ul> | ||
<% @metric.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<p> | ||
<%= f.label :datetime, 'Date and time' %><br> | ||
<%= f.text_field :datetime, id: 'carbohydrate_intake_datetime', class: 'form-control' %> | ||
</p> | ||
|
||
<p> | ||
<%= f.label :weight %><br> | ||
<%= f.text_field :weight, class: 'form-control' %> | ||
</p> | ||
|
||
<p> | ||
<%= f.label :description %><br> | ||
<%= f.text_field :description, class: 'form-control' %> | ||
</p> | ||
|
||
<p> | ||
<%= f.submit class: 'btn btn-success' %> | ||
|
||
</p> | ||
<% end %> | ||
|
||
<script type="text/javascript"> | ||
$(function () { | ||
$('#carbohydrate_intake_datetime').datetimepicker({ | ||
format: 'YYYY-MM-DD HH:mm', | ||
defaultDate: moment() | ||
}); | ||
}); | ||
</script> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<h1>Carbs Intake</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Delete', carbohydrate_intake_path(@metric), | ||
class: 'btn btn-warning', | ||
method: :delete, | ||
data: { | ||
confirm: 'Are you sure?' | ||
} %> | ||
<%= link_to 'Back', carbohydrate_intakes_path, class: 'btn btn-default' %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= render partial: 'shared/index', locals: { | ||
title: 'carbs' | ||
} %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New Carbohydrate Intake</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', carbohydrate_intakes_path, class: 'btn btn-default' %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<h1>Datetime: <%= @metric.datetime %></h1> | ||
<h2>Weight: <%= @metric.value %></h2> | ||
|
||
<%= link_to 'Back', carbohydrate_intakes_path %> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<%= link_to 'Glucose', glucose_measurements_path, class: 'btn btn-success' %> | ||
<%= link_to 'Carbs', carbohydrate_intakes_path, class: 'btn btn-success' %> | ||
<%= link_to 'Meds', medication_events_path, class: 'btn btn-success' %> |
122 changes: 122 additions & 0 deletions
122
spec/controllers/carbohydrate_intake_controller_spec.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
describe CarbohydrateIntakesController, type: :controller do | ||
before :each do | ||
sign_in | ||
end | ||
|
||
describe 'GET #index' do | ||
it 'populates an array of measurements' do | ||
carbohydrate_intake = create(:carbohydrate_intake) | ||
get :index | ||
expect(assigns(:metrics)).to eq [carbohydrate_intake] | ||
end | ||
|
||
it 'renders the #index view' do | ||
get :index | ||
expect(response).to render_template :index | ||
end | ||
end | ||
|
||
describe 'GET #show' do | ||
it 'assigns the requested measurement to @metric' do | ||
carbohydrate_intake = create(:carbohydrate_intake) | ||
get :show, id: carbohydrate_intake | ||
expect(assigns(:metric)).to eq carbohydrate_intake | ||
end | ||
|
||
it 'renders the #show view' do | ||
get :show, id: create(:carbohydrate_intake) | ||
expect(response).to render_template :show | ||
end | ||
end | ||
|
||
describe 'POST #create' do | ||
context 'with valid attributes' do | ||
it 'creates a new measurement' do | ||
expect { | ||
post :create, carbohydrate_intake: attributes_for(:carbohydrate_intake) | ||
}.to change(CarbohydrateIntake, :count).by 1 | ||
end | ||
|
||
it 'redirects to the index page' do | ||
post :create, carbohydrate_intake: attributes_for(:carbohydrate_intake) | ||
expect(response).to redirect_to carbohydrate_intakes_url | ||
end | ||
end | ||
|
||
context 'with invalid attributes' do | ||
it 'does not save the new contact' do | ||
expect { | ||
post :create, carbohydrate_intake: attributes_for(:invalid_carbohydrate_intake) | ||
}.to_not change(CarbohydrateIntake, :count) | ||
end | ||
|
||
it 're-renders the #new view' do | ||
post :create, carbohydrate_intake: attributes_for(:invalid_carbohydrate_intake) | ||
expect(response).to render_template :new | ||
end | ||
end | ||
end | ||
|
||
describe 'PUT #update' do | ||
let (:test_carbs) { create :carbohydrate_intake, datetime: '1974-06-15 12:00:00', weight: 50.0 } | ||
|
||
context 'valid attributes' do | ||
it 'locates the requested measurement' do | ||
put :update, id: test_carbs, carbohydrate_intake: attributes_for(:carbohydrate_intake) | ||
expect(assigns :metric).to eq test_carbs | ||
end | ||
|
||
it 'changes test_carbs` attributes' do | ||
put :update, id: test_carbs, | ||
carbohydrate_intake: attributes_for(:carbohydrate_intake, | ||
datetime: '1975-06-15 13:00:00', | ||
weight: 65) | ||
test_carbs.reload | ||
expect(test_carbs.datetime).to eq '1975-06-15 13:00:00' | ||
expect(test_carbs.weight).to eq 65 | ||
end | ||
|
||
it 'redirects to the index page' do | ||
put :update, id: test_carbs, carbohydrate_intake: attributes_for(:glucose_measurement) | ||
expect(assigns :metric).to eq test_carbs | ||
expect(response).to redirect_to carbohydrate_intakes_url | ||
end | ||
end | ||
|
||
context 'invalid attributes' do | ||
it 'locates the requested measurement' do | ||
put :update, id: test_carbs, carbohydrate_intake: attributes_for(:invalid_carbohydrate_intake) | ||
expect(assigns(:metric)).to eq test_carbs | ||
end | ||
|
||
it 'does not change the test_carbs attributes' do | ||
put :update, id: test_carbs, | ||
carbohydrate_intake: attributes_for(:carbohydrate_intake, | ||
datetime: nil, | ||
weight: 40) | ||
test_carbs.reload | ||
expect(test_carbs.weight).to_not eq 40 | ||
expect(test_carbs.datetime).to eq '1974-06-15 12:00:00' | ||
end | ||
|
||
it 're-renders the #edit view' do | ||
put :update, id: test_carbs, carbohydrate_intake: attributes_for(:invalid_carbohydrate_intake) | ||
expect(response).to render_template :edit | ||
end | ||
end | ||
end | ||
|
||
describe 'DELETE #destroy' do | ||
let! (:test_carbs) { create :carbohydrate_intake } | ||
it 'deletes the carbs' do | ||
expect { | ||
delete :destroy, id: test_carbs | ||
}.to change(CarbohydrateIntake, :count).by -1 | ||
end | ||
|
||
it 'redirects to #index' do | ||
delete :destroy, id: test_carbs | ||
expect(response).to redirect_to carbohydrate_intakes_url | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe GenericController, type: :controller do | ||
describe GenericController, type: :controller do | ||
|
||
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
describe CarbohydrateIntakeHelper, type: :helper do | ||
end |