Guest User

Untitled

a guest
Feb 20th, 2018
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. Failures:
  2.  
  3. 1) DevicesController device#update is handled
  4. Failure/Error: patch :update, params: { device: @device }
  5.  
  6. ActionController::UrlGenerationError:
  7. No route matches {:action=>"update", :controller=>"devices", :device=>#<Device id: 3, token: "Xn/6ut68w", nickname: "rough-snowflake-470", network: nil, ip_address: nil, gateway: nil, version: nil, ips_scan: nil, ips_exclude: nil, user_id: 3, created_at: "2018-02-21 02:44:16", updated_at: "2018-02-21 02:44:16">}
  8.  
  9. RSpec.describe DevicesController, type: :controller do
  10.  
  11. before(:each) { @user = User.create(email: 'test@test.com', password: 'password', password_confirmation: 'password') }
  12.  
  13. it 'device#update is handled' do
  14. sign_in(@user)
  15. @device = @user.devices.first
  16. patch :update, params: { device: @device }
  17. @device.reload
  18. expect(response.status).to eq(200)
  19. end
  20. end
  21.  
  22. class DevicesController < ApplicationController
  23. before_action :set_device, only: %i[edit show update]
  24. respond_to :html
  25.  
  26. def update
  27. if @device.update(device_params)
  28. flash[:notice] = 'Successful update'
  29. respond_with :edit, :device
  30. else
  31. flash[:warning] = 'Address formats allowed: x.x.x.x OR x.x.x.x-x OR x.x.x.x/x'
  32. respond_with :edit, :device
  33. end
  34. end
  35.  
  36. private def set_device
  37. @device = Device.find(params[:id])
  38. end
  39.  
  40. private def device_params
  41. params.require(:device).permit(:token, :nickname, :ips_scan, :ips_exclude)
  42. end
  43. end
  44.  
  45. patch :update, params: { device: @device, nickname: 'foobar' }
  46.  
  47. $ rake routes
  48. edit_device GET /devices/:id/edit(.:format) devices#edit
  49. device GET /devices/:id(.:format) devices#show
  50. PATCH /devices/:id(.:format) devices#update
  51. PUT /devices/:id(.:format) devices#update
Add Comment
Please, Sign In to add comment