Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Failures:
- 1) DevicesController device#update is handled
- Failure/Error: patch :update, params: { device: @device }
- ActionController::UrlGenerationError:
- 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">}
- RSpec.describe DevicesController, type: :controller do
- before(:each) { @user = User.create(email: 'test@test.com', password: 'password', password_confirmation: 'password') }
- it 'device#update is handled' do
- sign_in(@user)
- @device = @user.devices.first
- patch :update, params: { device: @device }
- @device.reload
- expect(response.status).to eq(200)
- end
- end
- class DevicesController < ApplicationController
- before_action :set_device, only: %i[edit show update]
- respond_to :html
- def update
- if @device.update(device_params)
- flash[:notice] = 'Successful update'
- respond_with :edit, :device
- else
- flash[:warning] = 'Address formats allowed: x.x.x.x OR x.x.x.x-x OR x.x.x.x/x'
- respond_with :edit, :device
- end
- end
- private def set_device
- @device = Device.find(params[:id])
- end
- private def device_params
- params.require(:device).permit(:token, :nickname, :ips_scan, :ips_exclude)
- end
- end
- patch :update, params: { device: @device, nickname: 'foobar' }
- $ rake routes
- edit_device GET /devices/:id/edit(.:format) devices#edit
- device GET /devices/:id(.:format) devices#show
- PATCH /devices/:id(.:format) devices#update
- PUT /devices/:id(.:format) devices#update
Add Comment
Please, Sign In to add comment