Skip to content

Commit

Permalink
mac not required on create
Browse files Browse the repository at this point in the history
  • Loading branch information
johnrees committed Sep 9, 2015
1 parent 723d011 commit 314bfec
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
15 changes: 8 additions & 7 deletions app/models/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/models/device_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
12 changes: 6 additions & 6 deletions spec/requests/v0/devices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/requests/v0/static_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
measurements_url
sensors_url
users_url
tags_url
)
end
end
Expand Down

0 comments on commit 314bfec

Please sign in to comment.