Skip to content

Commit

Permalink
pass position create specs
Browse files Browse the repository at this point in the history
  • Loading branch information
christinalcole committed Sep 10, 2017
1 parent 6822d5f commit 283a90b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
24 changes: 24 additions & 0 deletions app/controllers/positions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class PositionsController < ApplicationController
def index
@positions = Position.all
end

def new
@position = Position.new
end

def create
# raise.params.inspect
@position = Position.new(position_params)
if @position.save
redirect_to positions_path
else
render :new
end
end

private
def position_params
params.require(:position).permit(:name)
end
end
5 changes: 5 additions & 0 deletions app/views/positions/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h2>Positions entered to the database: </h2>

<% @positions.each do |position| %>
<%= position.name %>
<% end %>
18 changes: 18 additions & 0 deletions app/views/positions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<hr>positions#new<hr>

<% if @position.errors.any?%>
<h3><%= pluralize(@position.errors.count, "error") %> occurred: </h3>
<% @position.errors.full_messages.each do |msg| %>
<ul>
<li><%= msg %></li>
</ul>
<% end %>
<% end %>

<h2>Create a New Position:</h2>
<%= form_for @position do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>

<%= f.submit %>
<% end %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
resources :positions
end
end

resources :positions, except: [:show]
end
19 changes: 18 additions & 1 deletion spec/features/positions/position_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@

RSpec.feature 'Positions Management', type: :feature do
context 'create positions' do
scenario 'a new position can be added to the db'
scenario 'a form exists to add a new position to the db' do
visit new_position_path
expect(page).to have_css("form#new_position")
end
scenario 'a new position is created when the form is submitted' do
visit new_position_path
fill_in 'position[name]', with: 'Navigator'
click_button 'Create Position'

expect(Position.last.name).to eq("Navigator")
expect(page).to have_content("Navigator")
end
end

context 'editing positions' do
scenario 'an existing position can be updated'
scenario 'an existing position can be removed'
end

context 'listing positions' do
scenario 'existing positions in the database can be listed'
end
end

0 comments on commit 283a90b

Please sign in to comment.