diff --git a/app/models/device.rb b/app/models/device.rb index 03a092c2..f8e49252 100644 --- a/app/models/device.rb +++ b/app/models/device.rb @@ -6,12 +6,13 @@ class Device < ActiveRecord::Base belongs_to :kit belongs_to :owner, class_name: 'User' - validates_presence_of :owner, :mac_address, :name + validates_presence_of :owner, :name # validates_presence_of :mac_address, :name # validates :mac_address, uniqueness: true, format: { with: /\A([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}\z/ }#, unless: Proc.new { |d| d.mac_address == 'unknown' } - validates_uniqueness_of :mac_address#, on: :create - validates_format_of :mac_address, with: /\A([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}\z/#, on: :create, allow_blank: true + validates_uniqueness_of :mac_address, allow_nil: true #, on: :create + validates_format_of :mac_address, with: /\A([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}\z/, allow_nil: true + #, on: :create, allow_blank: true default_scope { with_active_state.includes(:owner) } @@ -96,7 +97,7 @@ def banned_name end # after_validation :reverse_geocode - after_initialize :set_default_name + # after_initialize :set_default_name # these get overridden the device is a kit has_many :components, as: :board @@ -221,9 +222,9 @@ def calculate_geohash end end - def set_default_name - self.name ||= "My SCK" - end + # def set_default_name + # self.name ||= "My SCK" + # end end diff --git a/spec/models/device_spec.rb b/spec/models/device_spec.rb index 090ab93a..13e6b3fd 100644 --- a/spec/models/device_spec.rb +++ b/spec/models/device_spec.rb @@ -5,7 +5,7 @@ it { is_expected.to belong_to(:owner) } it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_presence_of(:owner) } - it { is_expected.to validate_presence_of(:mac_address) } + # it { is_expected.to validate_presence_of(:mac_address) } let(:device) { create(:device) } diff --git a/spec/requests/v0/devices_spec.rb b/spec/requests/v0/devices_spec.rb index 4335d97f..22c7b2a0 100644 --- a/spec/requests/v0/devices_spec.rb +++ b/spec/requests/v0/devices_spec.rb @@ -131,8 +131,8 @@ it "does not create a device with missing parameters" do api_post 'devices', { - access_token: token.token, - name: 'a device' + name: nil, + access_token: token.token } expect(response.status).to eq(422) end @@ -147,10 +147,10 @@ expect(response.status).to eq(401) end - it "does not create a device with empty parameters access_token" do - api_post "devices", { device: { name: nil }, access_token: token.token } - expect(response.status).to eq(422) - end + # it "does not create a device with empty parameters access_token" do + # api_post "devices", { device: { name: nil }, access_token: token.token } + # expect(response.status).to eq(422) + # end end describe "DELETE /devices/:id" do diff --git a/spec/requests/v0/static_spec.rb b/spec/requests/v0/static_spec.rb index 4efc4bd3..a9558786 100644 --- a/spec/requests/v0/static_spec.rb +++ b/spec/requests/v0/static_spec.rb @@ -22,6 +22,7 @@ measurements_url sensors_url users_url + tags_url ) end end