Skip to content

Commit

Permalink
Merge pull request #13 from angiecstn/rsc_create_hospitals
Browse files Browse the repository at this point in the history
RSC can create hospitals
  • Loading branch information
Prozak8 committed Nov 6, 2018
2 parents f13a519 + e7d5958 commit 0829fb0
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 11 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# Ignore uploaded files in development
/storage/*

.DS_Store
/node_modules
/yarn-error.log

Expand Down
Binary file added app/assets/.DS_Store
Binary file not shown.
Binary file added app/assets/images/.DS_Store
Binary file not shown.
15 changes: 15 additions & 0 deletions app/controllers/hospitals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@ class HospitalsController < ApplicationController
def index
@hospitals = Hospital.all
end

def create
hospital = Hospital.create(hospital_params)
if hospital.persisted?
redirect_to hospitals_path, notice: 'Hospital added'
else
redirect_to hospitals_path, notice: 'Hospital already exists. Your hospital could not be saved'
end
end

private

def hospital_params
params.require(:hospital).permit(:name)
end
end
2 changes: 1 addition & 1 deletion app/models/hospital.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Hospital < ApplicationRecord
validates_presence_of :name
validates :name, uniqueness: true
end
12 changes: 8 additions & 4 deletions app/views/hospitals/_index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
.list-name= hospital.name
.list-button-area
%button.button Remove
.list-grid
%input.form-input-field{placeholder: "Add Hospitals"}
.list-button-area
%button.button Add
= form_with url: hospitals_path, scope: :hospital do |f|
.list-grid
.list-name
= f.text_field :name, id: "Name", class: "form-input-field"
.list-button-area
= f.submit value: "Add Hospital", class: "button text-center"


2 changes: 1 addition & 1 deletion app/views/hospitals/index.js.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

var templateContent = '<%= escape_javascript(render partial: 'index') %>'
displayTemplate(templateContent)
displayTemplate(templateContent)
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
resources :jobs, only: [:new, :create]
resources :users, only: [:create, :new]
resources :staffcos, only: :index
resources :hospitals, only: :index
resources :hospitals, only: [:index, :create, :new]
end
end
4 changes: 3 additions & 1 deletion features/rsc_can_add_new_job.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Feature: Rsc can add new job

Scenario: RSC creates a new job
Then I should see "Create New Job"
And I fill in job form
And I fill in "Name" with "Heart Surgeon"
And I fill in "Hospital" with "Karolinska"
And I fill in "Date finish" with "7/7/2019"
And I click on "Submit"
Then I should see "The job was successfully created"
And I should see "Heart Surgeon"
Expand Down
25 changes: 25 additions & 0 deletions features/rsc_can_create_new_hospitals.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@javascript

Feature: RSC creates a new hospital
As a RSC,
In order to create hospitals,
I would like to access the dashboard, click on the “Hospitals” button and fill in the hospital name.

Background:
Given the following hospitals exists
| name |
| Hospital 2 |
Given I am on the landing page
And I click on "Hospitals"

Scenario: RSC can successfully add new hospitals
And I fill in "Name" with "Hospital 3"
And I click on "Add Hospital"
And I should see "Hospital added"
Then I should see "Hospital 3"

Scenario: RSC cannot add hospitals if it already exists
And I fill in "Name" with "Hospital 2"
And I click on "Add Hospital"
Then I should see "Hospital already exists. Your hospital could not be saved"

2 changes: 1 addition & 1 deletion features/step_definitions/assertion_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
fill_in 'Working hours', with: '9 hours'
fill_in 'Date start', with: 'Tomorrow'
fill_in 'Date finish', with: 'Next Year'
end
end
2 changes: 1 addition & 1 deletion spec/models/hospital_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
end

describe 'Validations' do
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_uniqueness_of(:name) }
end

describe 'Factory' do
Expand Down

0 comments on commit 0829fb0

Please sign in to comment.