Skip to content

Commit

Permalink
devices are invalid without a name
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Mar 7, 2024
1 parent 5ce04c6 commit 812f8f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/models/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Device < ActiveRecord::Base

accepts_nested_attributes_for :postprocessing, update_only: true

validates_presence_of :name, :owner, on: :create
validates_presence_of :name
validates_presence_of :owner, on: :create
#validates_uniqueness_of :name, scope: :owner_id, on: :create

validates_uniqueness_of :device_token, allow_nil: true
Expand Down
7 changes: 6 additions & 1 deletion spec/requests/v0/devices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,15 @@
end

it "will update a device with empty parameters access_token" do
api_put "devices/#{device.id}", { name: nil, access_token: token.token }
api_put "devices/#{device.id}", { access_token: token.token }
expect(response.status).to eq(200)
end

it "does not allow an empty device name" do
api_put "devices/#{device.id}", { name: nil, access_token: token.token }
expect(response.status).to eq(422)
end

it 'can read and update a jsonb' do
expect(device.postprocessing).to be_nil
j = api_put "devices/#{device.id}", { postprocessing_attributes: {"blueprint_url":"999"}, access_token: token.token, name: 'ABBA' }
Expand Down

0 comments on commit 812f8f4

Please sign in to comment.