grok-4-0709· xAI
LMArena Human Preference 140K
Expand this code for new, create, update and destroy context 'show' do context 'user…
- User
Expand this code for new, create, update and destroy context 'show' do context 'user with access to parent entity' do it 'allows access' do customer = create :customer entity = create :entity, customer_id: customer.id user = create :user, role: :guest, customer: customer, entity_ids: [entity.id] device = create :device, entity: entity, customer: customer
cookies['enectiva_jwt'] = sign_in user get "/cs/devices/#{device.id}" expect(response).to have_http_status(:ok) end end context 'user without access to parent entity' do it 'redirects to missing entity page' do customer = create :customer entity = create :entity, customer_id: customer.id user = create :user, role: :guest, customer: customer, entity_ids: [] device = create :device, entity: entity, customer: customer cookies['enectiva_jwt'] = sign_in user get "/cs/devices/#{device.id}" expect(response).to have_http_status(:not_found) end endend
- Assistant
context 'new' do context 'user with access to parent entity' do it 'allows access' do customer = create :customer entity = create :entity, customer_id: customer.id user = create :user, role: :guest, customer: customer, entity_ids: [entity.id] cookies['enectiva_jwt'] = sign_in user get "/cs/devices/new?entity_id=#{entity.id}" expect(response).to have_http_status(:ok) end end context 'user without access to parent entity' do it 'redirects to missing entity page' do customer = create :customer entity = create :entity, customer_id: customer.id user = create :user, role: :guest, customer: customer, entity_ids: [] cookies['enectiva_jwt'] = sign_in user get "/cs/devices/new?entity_id=#{entity.id}" expect(response).to have_http_status(:not_found) end end end context 'create' do context 'user with access to parent entity' do it 'allows creation' do customer = create :customer entity = create :entity, customer_id: customer.id user = create :user, role: :guest, customer: customer, entity_ids: [entity.id] cookies['enectiva_jwt'] = sign_in user expect { post "/cs/devices", params: { device: { entity_id: entity.id, customer_id: customer.id } } # Adjust params as needed for required device fields }.to change(Device, :count).by(1) expect(response).to have_http_status(:found) end end context 'user without access to parent entity' do it 'denies creation' do customer = create :customer entity = create :entity, customer_id: customer.id user = create :user, role: :guest, customer: customer, entity_ids: [] cookies['enectiva_jwt'] = sign_in user expect { post "/cs/devices", params: { device: { entity_id: entity.id, customer_id: customer.id } } # Adjust params as needed for required device fields }.not_to change(Device, :count) expect(response).to have_http_status(:not_found) end end end context 'update' do context 'user with access to parent entity' do it 'allows update' do customer = create :customer entity = create :entity, customer_id: customer.id user = create :user, role: :guest, customer: customer, entity_ids: [entity.id] device = create :device, entity: entity, customer: customer cookies['enectiva_jwt'] = sign_in user patch "/cs/devices/#{device.id}", params: { device: { name: 'Updated' } } # Adjust params as needed for updatable fields expect(response).to have_http_status(:found) expect(device.reload.name).to eq('Updated') # Adjust based on actual updated field end end context 'user without access to parent entity' do it 'denies update' do customer = create :customer entity = create :entity, customer_id: customer.id user = create :user, role: :guest, customer: customer, entity_ids: [] device = create :device, entity: entity, customer: customer cookies['enectiva_jwt'] = sign_in user patch "/cs/devices/#{device.id}", params: { device: { name: 'Updated' } } # Adjust params as needed for updatable fields expect(response).to have_http_status(:not_found) expect(device.reload.name).not_to eq('Updated') # Adjust based on actual updated field end end end context 'destroy' do context 'user with access to parent entity' do it 'allows destruction' do customer = create :customer entity = create :entity, customer_id: customer.id user = create :user, role: :guest, customer: customer, entity_ids: [entity.id] device = create :device, entity: entity, customer: customer cookies['enectiva_jwt'] = sign_in user expect { delete "/cs/devices/#{device.id}" }.to change(Device, :count).by(-1) expect(response).to have_http_status(:found) end end context 'user without access to parent entity' do it 'denies destruction' do customer = create :customer entity = create :entity, customer_id: customer.id user = create :user, role: :guest, customer: customer, entity_ids: [] device = create :device, entity: entity, customer: customer cookies['enectiva_jwt'] = sign_in user expect { delete "/cs/devices/#{device.id}" }.not_to change(Device, :count) expect(response).to have_http_status(:not_found) end end end
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.