Skip to content

Commit

Permalink
Merge pull request #130 from tnodland/model_cleanup
Browse files Browse the repository at this point in the history
updates models with validates_inclusion_of to validate boolean attribute
  • Loading branch information
whois-jon-peterson authored Apr 2, 2019
2 parents 1c75a17 + 7af545c commit e1e42c1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--require spec_helper
--format documentation
--order=random
2 changes: 2 additions & 0 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Item < ApplicationRecord
:current_price,
:merchant_id

validates_inclusion_of :enabled, in: [true, false]

belongs_to :user, foreign_key: 'merchant_id'
has_many :order_items
has_many :orders, through: :order_items
Expand Down
2 changes: 2 additions & 0 deletions app/models/order_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ class OrderItem < ApplicationRecord
:item_id,
:quantity,
:ordered_price

validates_inclusion_of :fulfilled, in: [true, false]
end
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ class User < ApplicationRecord
:email,
:password,
:role

validates_uniqueness_of :email

validates_inclusion_of :enabled, in: [true, false]

has_many :orders
has_many :items, foreign_key: "merchant_id"

Expand Down
6 changes: 3 additions & 3 deletions spec/models/user_roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
RSpec.describe User do
describe 'roles' do
it 'can create an admin' do
admin = create(:admin)
user = create(:admin)

expect(user.role).to eq("admin")
expect(user.admin?).to be_truthy
end

it 'can create a merchant' do
admin = create(:merchant)
user = create(:merchant)

expect(user.role).to eq("merchant")
expect(user.merchant?).to be_truthy
end
it 'can create an admin' do
admin = create(:user)
user = create(:user)

expect(user.role).to eq("user")
expect(user.user?).to be_truthy
Expand Down

0 comments on commit e1e42c1

Please sign in to comment.