Skip to content

Commit

Permalink
Add role to surveyors index
Browse files Browse the repository at this point in the history
  • Loading branch information
lfilmeyer committed Aug 16, 2024
1 parent a1932e6 commit ac44481
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/app/controllers/surveyors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SurveyorsController < ApplicationController

# GET /surveyors or /surveyors.json
def index
@surveyors = policy_scope(Surveyor).where(search_params)
@surveyors = policy_scope(Surveyor).where(search_params).includes(:user)
end

# GET /surveyors/1 or /surveyors/1.json
Expand Down
2 changes: 2 additions & 0 deletions backend/app/views/surveyors/_surveyor.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

json.extract! surveyor, :id, :user_id, :assignment_ids, :firstname, :lastname, :email, :phone, :street_address, :city,
:state, :zipcode, :geocode, :status

json.role surveyor.user.role
json.url surveyor_url(surveyor, format: :json)
34 changes: 30 additions & 4 deletions backend/spec/requests/surveyors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,45 @@
end

describe 'GET /index' do
before do
@surveyor = Surveyor.create! valid_attributes
sign_in user
end

it 'renders a successful response' do
Surveyor.create! valid_attributes
get surveyors_url, as: :json
expect(response).to be_successful

surveyors_json = JSON.parse(response.body)
expect(surveyors_json[0]['id']).to eq(@surveyor.id)
end
end

describe 'GET /show' do
it 'renders a successful response' do
before do
@surveyor = Surveyor.create! valid_attributes
sign_in user
surveyor = Surveyor.create! valid_attributes
get surveyor_url(surveyor), as: :json
end

it 'renders a successful response' do
get surveyor_url(@surveyor), as: :json
expect(response).to be_successful

surveyor_json = JSON.parse(response.body)
expect(surveyor_json['id']).to eq(@surveyor.id)
expect(surveyor_json['user_id']).to eq(user.id)
expect(surveyor_json['assignment_ids']).to eq([])
expect(surveyor_json['firstname']).to eq('John')
expect(surveyor_json['lastname']).to eq('Smith')
expect(surveyor_json['email']).to eq('[email protected]')
expect(surveyor_json['phone']).to eq('1234567890')
expect(surveyor_json['street_address']).to eq('123 First Street')
expect(surveyor_json['city']).to eq('Cambridge')
expect(surveyor_json['state']).to eq('MA')
expect(surveyor_json['zipcode']).to eq('01234')
expect(surveyor_json['status']).to eq('active')
expect(surveyor_json['role']).to eq('surveyor')
expect(surveyor_json['url']).to eq("http://www.example.com/surveyors/#{@surveyor.id}.json")
end
end

Expand Down

0 comments on commit ac44481

Please sign in to comment.