Skip to content

Commit

Permalink
Merge pull request #65 from ministryofjustice/fix/invite-office
Browse files Browse the repository at this point in the history
Update user invite controller
  • Loading branch information
colinbruce committed May 5, 2015
2 parents 6cf23e5 + c1dbed0 commit 1fde037
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/users/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def invite_resource
end

def invite_params
params.require(:user).permit(:email, :role, :name)
params.require(:user).permit(:email, :role, :name, :office_id)
end
end
2 changes: 2 additions & 0 deletions app/views/users/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ table
tr
th Name
th Role
th Office
th colspan="2"  

-@users.each do |user|
Expand All @@ -13,6 +14,7 @@ table
=user.name
td
=user.role
td =user.office.name if user.office.present?
td =link_to 'Edit', edit_user_path(user)
td =link_to 'Destroy', user_path(user), method: :delete

Expand Down
4 changes: 2 additions & 2 deletions app/views/users/invitations/new.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ h2
= f.label(:roles, 'Role')
= f.collection_select :role, User::ROLES, :to_s, :humanize
.form-group
= f.label(:office, 'Office')
= f.collection_select :office, Office.all, :id, :name
= f.label(:office_id, 'Office')
= f.collection_select :office_id, Office.all, :id, :name
p
= f.submit t("devise.invitations.new.submit_button"), class: 'button btn tiny'
4 changes: 3 additions & 1 deletion app/views/users/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
h2 =@user.email

div
=@user.role
=@user.role

div =@user.office.name
4 changes: 2 additions & 2 deletions spec/controllers/offices_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
it 'assigns all offices as @offices' do
office = Office.create! valid_attributes
get :index, {}, valid_session
expect(assigns(:offices)).to eq([office])
expect(assigns(:offices)).to include(office)
end
end

Expand Down Expand Up @@ -143,7 +143,7 @@
it 'assigns all offices as @offices' do
office = Office.create! valid_attributes
get :index, {}, valid_session
expect(assigns(:offices)).to eq([office])
expect(assigns(:offices)).to include(office)
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
sequence(:email) { |n| "user_#{n}@digital.justice.gov.uk" }
password 'password'
name 'user'
association :office
factory :admin_user do
role 'admin'
end
Expand Down
3 changes: 2 additions & 1 deletion spec/features/user_invite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
fill_in 'user_email', with: new_email
fill_in 'user_name', with: new_name
select('User', from: 'user_role')
select('Bristol', from: 'user_office')
select('Bristol', from: 'user_office_id')

click_button 'Send an invitation'

expect(page).to have_xpath('//a', text: new_name)
expect(page).to have_xpath('//td', text: offices.name)
end
end
end

0 comments on commit 1fde037

Please sign in to comment.