diff --git a/app/models/asset.rb b/app/models/asset.rb index 136f4fe..8dede4a 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -6,5 +6,6 @@ class Asset < ApplicationRecord validates :status, presence: true belongs_to :space has_many :asset_suppliers + has_many :suppliers, through: :asset_suppliers has_many :maintenances end diff --git a/app/models/contract.rb b/app/models/contract.rb index e8eca78..55930ad 100644 --- a/app/models/contract.rb +++ b/app/models/contract.rb @@ -2,6 +2,11 @@ class Contract < ApplicationRecord validates :start_date, presence: true validates :finish_date, presence: true - belongs_to :space + has_many :payments + has_many :contract_spaces + has_many :spaces, through: :contract_spaces belongs_to :user + def name + "#{start_date} | #{finish_date}" + end end diff --git a/app/models/contract_space.rb b/app/models/contract_space.rb new file mode 100644 index 0000000..4020d89 --- /dev/null +++ b/app/models/contract_space.rb @@ -0,0 +1,5 @@ +# ContractSpace +class ContractSpace < ApplicationRecord + belongs_to :contract + belongs_to :space +end diff --git a/app/models/payment.rb b/app/models/payment.rb new file mode 100644 index 0000000..ce2509b --- /dev/null +++ b/app/models/payment.rb @@ -0,0 +1,8 @@ +# Payment +class Payment < ApplicationRecord + validates :due_date, presence: true + validates :payment_date, presence: true + validates :amount, presence: true + validates :status, presence: true + belongs_to :contract +end diff --git a/app/models/space.rb b/app/models/space.rb index f10b9c9..a0c30c1 100644 --- a/app/models/space.rb +++ b/app/models/space.rb @@ -4,7 +4,22 @@ class Space < ApplicationRecord validates :name, presence: true belongs_to :parent, inverse_of: :children, foreign_key: :space_id, class_name: 'Space', optional: true has_many :children, inverse_of: :parent, foreign_key: :space_id, class_name: 'Space' - has_many :contracts has_many :assets has_one :warehouse + has_many :contract_spaces + has_many :contracts, through: :contract_spaces + + before_save :generate_full_name + + protected + + def generate_full_name + self.full_name = array_parents.reverse.map(&:name).join(' | ') + end + + def array_parents + objects = [self] + objects.push(objects.last.parent) while objects.last.parent + objects + end end diff --git a/app/models/supplier.rb b/app/models/supplier.rb index 110330c..3f9f510 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -4,6 +4,7 @@ class Supplier < ApplicationRecord validates :supplier_identity, presence: true, uniqueness: true validates :services, presence: true validates :category, presence: true - has_many :asset_suppliers has_many :maintenances + has_many :asset_suppliers + has_many :assets, through: :asset_suppliers end diff --git a/config/initializers/rails_admin.rb b/config/initializers/rails_admin.rb index 8ea9584..4838237 100644 --- a/config/initializers/rails_admin.rb +++ b/config/initializers/rails_admin.rb @@ -42,11 +42,13 @@ config.model (User) { list { configure :id { hide } } } config.model (Organization) { list { configure :id { hide } } } config.model (Asset) { list { configure :id { hide } } } - config.model (AssetSupplier) { list { configure :id { hide } } } config.model (Contract) { list { configure :id { hide } } } config.model (Maintenance) { list { configure :id { hide } } } config.model (Space) { list { configure :id { hide } } } config.model (Supplier) { list { configure :id { hide } } } config.model (Supply) { list { configure :id { hide } } } config.model (Warehouse) { list { configure :id { hide } } } + config.model (Payment) { list { configure :id { hide } } } + config.model (ContractSpace) { list { configure :id { hide } } } + config.model (AssetSupplier) { list { configure :id { hide } } } end diff --git a/db/migrate/20180209171717_change_type_category_asset_description.rb b/db/migrate/20180209171717_change_type_category_asset_description.rb new file mode 100644 index 0000000..a7882fd --- /dev/null +++ b/db/migrate/20180209171717_change_type_category_asset_description.rb @@ -0,0 +1,7 @@ +class ChangeTypeCategoryAssetDescription < ActiveRecord::Migration[5.1] + def up + change_table :assets do |t| + t.change :description, :text + end + end +end diff --git a/db/migrate/20180209171835_change_type_category_organization_description.rb b/db/migrate/20180209171835_change_type_category_organization_description.rb new file mode 100644 index 0000000..189b8f3 --- /dev/null +++ b/db/migrate/20180209171835_change_type_category_organization_description.rb @@ -0,0 +1,7 @@ +class ChangeTypeCategoryOrganizationDescription < ActiveRecord::Migration[5.1] + def up + change_table :organizations do |t| + t.change :description, :text + end + end +end diff --git a/db/migrate/20180209172057_change_type_category_supplier_address.rb b/db/migrate/20180209172057_change_type_category_supplier_address.rb new file mode 100644 index 0000000..66ceb2e --- /dev/null +++ b/db/migrate/20180209172057_change_type_category_supplier_address.rb @@ -0,0 +1,7 @@ +class ChangeTypeCategorySupplierAddress < ActiveRecord::Migration[5.1] + def up + change_table :suppliers do |t| + t.change :address, :text + end + end +end diff --git a/db/migrate/20180209172202_change_type_category_supply_description.rb b/db/migrate/20180209172202_change_type_category_supply_description.rb new file mode 100644 index 0000000..4ff62cd --- /dev/null +++ b/db/migrate/20180209172202_change_type_category_supply_description.rb @@ -0,0 +1,7 @@ +class ChangeTypeCategorySupplyDescription < ActiveRecord::Migration[5.1] + def up + change_table :supplies do |t| + t.change :description, :text + end + end +end diff --git a/db/migrate/20180209172241_change_type_category_supply_note.rb b/db/migrate/20180209172241_change_type_category_supply_note.rb new file mode 100644 index 0000000..8c74532 --- /dev/null +++ b/db/migrate/20180209172241_change_type_category_supply_note.rb @@ -0,0 +1,7 @@ +class ChangeTypeCategorySupplyNote < ActiveRecord::Migration[5.1] + def up + change_table :supplies do |t| + t.change :note, :text + end + end +end diff --git a/db/migrate/20180209172347_change_type_category_user_address.rb b/db/migrate/20180209172347_change_type_category_user_address.rb new file mode 100644 index 0000000..39b0363 --- /dev/null +++ b/db/migrate/20180209172347_change_type_category_user_address.rb @@ -0,0 +1,7 @@ +class ChangeTypeCategoryUserAddress < ActiveRecord::Migration[5.1] + def up + change_table :users do |t| + t.change :address, :text + end + end +end diff --git a/db/migrate/20180209174923_add_full_name_to_space.rb b/db/migrate/20180209174923_add_full_name_to_space.rb new file mode 100644 index 0000000..74f58eb --- /dev/null +++ b/db/migrate/20180209174923_add_full_name_to_space.rb @@ -0,0 +1,5 @@ +class AddFullNameToSpace < ActiveRecord::Migration[5.1] + def change + add_column :spaces, :full_name, :string + end +end diff --git a/db/migrate/20180212043454_remove_references_on_contract.rb b/db/migrate/20180212043454_remove_references_on_contract.rb new file mode 100644 index 0000000..6a32f68 --- /dev/null +++ b/db/migrate/20180212043454_remove_references_on_contract.rb @@ -0,0 +1,5 @@ +class RemoveReferencesOnContract < ActiveRecord::Migration[5.1] + def change + remove_reference(:contracts, :space, index: true) + end +end diff --git a/db/migrate/20180212161659_create_payments.rb b/db/migrate/20180212161659_create_payments.rb new file mode 100644 index 0000000..92e84da --- /dev/null +++ b/db/migrate/20180212161659_create_payments.rb @@ -0,0 +1,15 @@ +class CreatePayments < ActiveRecord::Migration[5.1] + def change + create_table :payments do |t| + t.integer :payment + t.date :payment_date + t.date :warning_date + t.integer :quantity + t.string :status + t.text :note + t.references :contract, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/migrate/20180214175011_changes_on_payment.rb b/db/migrate/20180214175011_changes_on_payment.rb new file mode 100644 index 0000000..b64ee0e --- /dev/null +++ b/db/migrate/20180214175011_changes_on_payment.rb @@ -0,0 +1,8 @@ +class ChangesOnPayment < ActiveRecord::Migration[5.1] + def change + rename_column :payments, :warning_date, :due_date + rename_column :payments, :quantity, :amount + remove_column :payments, :payment, :integer + change_column :payments, :amount, :float + end +end diff --git a/db/migrate/20180214194333_remove_references_on_contract_spaces.rb b/db/migrate/20180214194333_remove_references_on_contract_spaces.rb new file mode 100644 index 0000000..f72b666 --- /dev/null +++ b/db/migrate/20180214194333_remove_references_on_contract_spaces.rb @@ -0,0 +1,6 @@ +class RemoveReferencesOnContractSpaces < ActiveRecord::Migration[5.1] + def change + remove_reference(:contract_spaces, :space, index: true) + remove_reference(:contract_spaces, :contract, index: true) + end +end diff --git a/db/migrate/20180214194838_drop_contract_space.rb b/db/migrate/20180214194838_drop_contract_space.rb new file mode 100644 index 0000000..762cfd2 --- /dev/null +++ b/db/migrate/20180214194838_drop_contract_space.rb @@ -0,0 +1,5 @@ +class DropContractSpace < ActiveRecord::Migration[5.1] + def change + drop_table :contract_spaces + end +end diff --git a/db/migrate/20180214201411_contracts_spaces.rb b/db/migrate/20180214201411_contracts_spaces.rb new file mode 100644 index 0000000..07b3927 --- /dev/null +++ b/db/migrate/20180214201411_contracts_spaces.rb @@ -0,0 +1,6 @@ +class ContractsSpaces < ActiveRecord::Migration[5.1] + create_table :contracts_spaces, id: false do |t| + t.belongs_to :contract, index: true + t.belongs_to :space, index: true + end +end diff --git a/db/migrate/20180214211752_remove_references_on_asset_supplier.rb b/db/migrate/20180214211752_remove_references_on_asset_supplier.rb new file mode 100644 index 0000000..3302837 --- /dev/null +++ b/db/migrate/20180214211752_remove_references_on_asset_supplier.rb @@ -0,0 +1,6 @@ +class RemoveReferencesOnAssetSupplier < ActiveRecord::Migration[5.1] + def change + remove_reference(:asset_suppliers, :asset, index: true) + remove_reference(:asset_suppliers, :supplier, index: true) + end +end diff --git a/db/migrate/20180214212102_drop_asset_supplier.rb b/db/migrate/20180214212102_drop_asset_supplier.rb new file mode 100644 index 0000000..2651317 --- /dev/null +++ b/db/migrate/20180214212102_drop_asset_supplier.rb @@ -0,0 +1,5 @@ +class DropAssetSupplier < ActiveRecord::Migration[5.1] + def change + drop_table :asset_suppliers + end +end diff --git a/db/migrate/20180214212252_assets_suppliers.rb b/db/migrate/20180214212252_assets_suppliers.rb new file mode 100644 index 0000000..fb128eb --- /dev/null +++ b/db/migrate/20180214212252_assets_suppliers.rb @@ -0,0 +1,6 @@ +class AssetsSuppliers < ActiveRecord::Migration[5.1] + create_table :assets_suppliers, id: false do |t| + t.belongs_to :asset, index: true + t.belongs_to :supplier, index: true + end +end diff --git a/db/migrate/20180215171145_remove_relation_contracts_space.rb b/db/migrate/20180215171145_remove_relation_contracts_space.rb new file mode 100644 index 0000000..707856c --- /dev/null +++ b/db/migrate/20180215171145_remove_relation_contracts_space.rb @@ -0,0 +1,5 @@ +class RemoveRelationContractsSpace < ActiveRecord::Migration[5.1] + def change + drop_table :contracts_spaces + end +end diff --git a/db/migrate/20180215171311_remove_relation_assets_suppliers.rb b/db/migrate/20180215171311_remove_relation_assets_suppliers.rb new file mode 100644 index 0000000..fdb0aae --- /dev/null +++ b/db/migrate/20180215171311_remove_relation_assets_suppliers.rb @@ -0,0 +1,5 @@ +class RemoveRelationAssetsSuppliers < ActiveRecord::Migration[5.1] + def change + drop_table :assets_suppliers + end +end diff --git a/db/migrate/20180215173742_create_contract_spaces.rb b/db/migrate/20180215173742_create_contract_spaces.rb new file mode 100644 index 0000000..50abc57 --- /dev/null +++ b/db/migrate/20180215173742_create_contract_spaces.rb @@ -0,0 +1,11 @@ +class CreateContractSpaces < ActiveRecord::Migration[5.1] + def change + create_table :contract_spaces do |t| + t.belongs_to :contract, index: true + t.belongs_to :space, index: true + t.datetime :appointment_date + + t.timestamps + end + end +end diff --git a/db/migrate/20180204230315_create_asset_suppliers.rb b/db/migrate/20180215175137_create_asset_suppliers.rb similarity index 61% rename from db/migrate/20180204230315_create_asset_suppliers.rb rename to db/migrate/20180215175137_create_asset_suppliers.rb index b58209a..4f4bd00 100644 --- a/db/migrate/20180204230315_create_asset_suppliers.rb +++ b/db/migrate/20180215175137_create_asset_suppliers.rb @@ -1,9 +1,9 @@ class CreateAssetSuppliers < ActiveRecord::Migration[5.1] def change create_table :asset_suppliers do |t| - t.references :asset, foreign_key: true - t.references :supplier, foreign_key: true - + t.belongs_to :asset, index: true + t.belongs_to :supplier, index: true + t.timestamps end end diff --git a/db/migrate/20180215181142_remove_column_on_contract_space.rb b/db/migrate/20180215181142_remove_column_on_contract_space.rb new file mode 100644 index 0000000..4b84040 --- /dev/null +++ b/db/migrate/20180215181142_remove_column_on_contract_space.rb @@ -0,0 +1,5 @@ +class RemoveColumnOnContractSpace < ActiveRecord::Migration[5.1] + def change + remove_column :contract_spaces, :appointment_date, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index ccd36aa..64a74d7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180208203810) do +ActiveRecord::Schema.define(version: 20180215181142) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -32,7 +32,7 @@ t.string "category" t.string "sub_category" t.integer "status" - t.string "description" + t.text "description" t.integer "interval" t.bigint "space_id" t.datetime "created_at", null: false @@ -40,14 +40,21 @@ t.index ["space_id"], name: "index_assets_on_space_id" end + create_table "contract_spaces", force: :cascade do |t| + t.bigint "contract_id" + t.bigint "space_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["contract_id"], name: "index_contract_spaces_on_contract_id" + t.index ["space_id"], name: "index_contract_spaces_on_space_id" + end + create_table "contracts", force: :cascade do |t| t.date "start_date" t.date "finish_date" - t.bigint "space_id" t.bigint "user_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index ["space_id"], name: "index_contracts_on_space_id" t.index ["user_id"], name: "index_contracts_on_user_id" end @@ -64,13 +71,25 @@ create_table "organizations", force: :cascade do |t| t.string "name" - t.string "description" + t.text "description" t.string "organization_identifier" t.string "website" t.datetime "created_at", null: false t.datetime "updated_at", null: false end + create_table "payments", force: :cascade do |t| + t.date "payment_date" + t.date "due_date" + t.float "amount" + t.string "status" + t.text "note" + t.bigint "contract_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["contract_id"], name: "index_payments_on_contract_id" + end + create_table "spaces", force: :cascade do |t| t.string "space_identifier" t.string "name" @@ -80,6 +99,7 @@ t.bigint "space_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "full_name" t.index ["space_id"], name: "index_spaces_on_space_id" end @@ -90,7 +110,7 @@ t.integer "ranking" t.string "services" t.string "category" - t.string "address" + t.text "address" t.string "bank" t.string "current_account" t.string "email" @@ -102,7 +122,7 @@ create_table "supplies", force: :cascade do |t| t.string "name" - t.string "description" + t.text "description" t.string "brand" t.string "color" t.string "presentation" @@ -112,7 +132,7 @@ t.integer "stock" t.integer "stock_minimun" t.integer "stock_reposition" - t.string "note" + t.text "note" t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -127,7 +147,7 @@ t.date "birthday" t.string "role" t.integer "user_identifier" - t.string "address" + t.text "address" t.text "bio" t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -144,13 +164,11 @@ t.index ["supply_id"], name: "index_warehouses_on_supply_id" end - add_foreign_key "asset_suppliers", "assets" - add_foreign_key "asset_suppliers", "suppliers" add_foreign_key "assets", "spaces" - add_foreign_key "contracts", "spaces" add_foreign_key "contracts", "users" add_foreign_key "maintenances", "assets" add_foreign_key "maintenances", "suppliers" + add_foreign_key "payments", "contracts" add_foreign_key "spaces", "spaces" add_foreign_key "users", "organizations" add_foreign_key "warehouses", "spaces" diff --git a/spec/factories/contract_spaces.rb b/spec/factories/contract_spaces.rb new file mode 100644 index 0000000..03e14b3 --- /dev/null +++ b/spec/factories/contract_spaces.rb @@ -0,0 +1,4 @@ +FactoryBot.define do + factory :contract_space do + end +end diff --git a/spec/factories/payments.rb b/spec/factories/payments.rb new file mode 100644 index 0000000..2955370 --- /dev/null +++ b/spec/factories/payments.rb @@ -0,0 +1,9 @@ +FactoryBot.define do + factory :payment do + payment_date FFaker::IdentificationESCO.expedition_date + due_date FFaker::IdentificationESCO.expedition_date + amount FFaker::PhoneNumberAU.home_work_phone_prefix + status 'Completo' + note FFaker::Book.description + end +end diff --git a/spec/models/asset_spec.rb b/spec/models/asset_spec.rb index d8e5d3f..5d29b2d 100644 --- a/spec/models/asset_spec.rb +++ b/spec/models/asset_spec.rb @@ -1,12 +1,7 @@ require 'rails_helper' RSpec.describe Asset, type: :model do - it 'is valid with a name ,category , sub_category and status' do - space = build(:space) - asset = build(:asset, space: space) - expect(asset).to be_valid - end - + it { expect(build(:asset, space: build(:space))).to be_valid } it { should validate_presence_of(:name) } it { should validate_presence_of(:category) } it { should validate_presence_of(:sub_category) } diff --git a/spec/models/asset_supplier_spec.rb b/spec/models/asset_supplier_spec.rb index f6516ac..af46e13 100644 --- a/spec/models/asset_supplier_spec.rb +++ b/spec/models/asset_supplier_spec.rb @@ -1,10 +1,5 @@ require 'rails_helper' RSpec.describe AssetSupplier, type: :model do - it 'is valid' do - supplier = build(:supplier) - asset = build(:asset) - asset_supplier = build(:asset_supplier, supplier: supplier, asset: asset) - expect(asset_supplier).to be_valid - end + it { expect(build(:asset_supplier, asset: build(:asset), supplier: build(:supplier))).to be_valid } end diff --git a/spec/models/contract_space_spec.rb b/spec/models/contract_space_spec.rb new file mode 100644 index 0000000..774cf50 --- /dev/null +++ b/spec/models/contract_space_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ContractSpace, type: :model do + it { expect(build(:contract_space, contract: build(:contract), space: build(:space))).to be_valid } +end diff --git a/spec/models/contract_spec.rb b/spec/models/contract_spec.rb index 80146f7..c9282c5 100644 --- a/spec/models/contract_spec.rb +++ b/spec/models/contract_spec.rb @@ -1,12 +1,11 @@ require 'rails_helper' RSpec.describe Contract, type: :model do - it 'is valid with a start date and finish date' do - user = build(:user) - space = build(:space) - contract = build(:contract, user: user, space: space) + it { + contract = build(:contract, user: build(:user)) expect(contract).to be_valid - end + expect(contract.name).to eq("#{contract.start_date} | #{contract.finish_date}") + } it { should validate_presence_of(:start_date) } it { should validate_presence_of(:finish_date) } diff --git a/spec/models/maintenance_spec.rb b/spec/models/maintenance_spec.rb index 4e34651..ecfddeb 100644 --- a/spec/models/maintenance_spec.rb +++ b/spec/models/maintenance_spec.rb @@ -1,13 +1,7 @@ require 'rails_helper' RSpec.describe Maintenance, type: :model do - it 'is valid with a registration date and status' do - supplier = build(:supplier) - asset = build(:asset) - maintenance = build(:maintenance, supplier: supplier, asset: asset) - expect(maintenance).to be_valid - end - + it { expect(build(:maintenance, supplier: build(:supplier), asset: build(:asset))).to be_valid } it { should validate_presence_of(:registration_date) } it { should validate_presence_of(:status) } end diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index 01a45b4..a1ca9a7 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -1,11 +1,7 @@ require 'rails_helper' RSpec.describe Organization, type: :model do - it 'is valid with a name and organization_identifier' do - organization = build(:organization) - expect(organization).to be_valid - end - + it { expect(build(:organization)).to be_valid } it { should validate_presence_of(:name) } it { should validate_presence_of(:organization_identifier) } it { should validate_uniqueness_of(:organization_identifier) } diff --git a/spec/models/payment_spec.rb b/spec/models/payment_spec.rb new file mode 100644 index 0000000..7d3268b --- /dev/null +++ b/spec/models/payment_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe Payment, type: :model do + it { expect(build(:payment, contract: build(:contract))).to be_valid } + it { should validate_presence_of(:due_date) } + it { should validate_presence_of(:payment_date) } + it { should validate_presence_of(:amount) } + it { should validate_presence_of(:status) } +end diff --git a/spec/models/space_spec.rb b/spec/models/space_spec.rb index 2bab79b..c8a9f9e 100644 --- a/spec/models/space_spec.rb +++ b/spec/models/space_spec.rb @@ -1,11 +1,7 @@ require 'rails_helper' RSpec.describe Space, type: :model do - it 'is valid with a code, name and capacity' do - space = build(:space) - expect(space).to be_valid - end - + it { expect(build(:space)).to be_valid } it { should validate_presence_of(:space_identifier) } it { should validate_presence_of(:name) } it { should validate_uniqueness_of(:space_identifier) } diff --git a/spec/models/supplier_spec.rb b/spec/models/supplier_spec.rb index 5306589..c36cecf 100644 --- a/spec/models/supplier_spec.rb +++ b/spec/models/supplier_spec.rb @@ -1,11 +1,7 @@ require 'rails_helper' RSpec.describe Supplier, type: :model do - it 'is valid with a name, supplier_identity, services, category' do - supplier = build(:supplier) - expect(supplier).to be_valid - end - + it { expect(build(:supplier)).to be_valid } it { should validate_presence_of(:name) } it { should validate_presence_of(:supplier_identity) } it { should validate_uniqueness_of(:supplier_identity) } diff --git a/spec/models/supply_spec.rb b/spec/models/supply_spec.rb index d73ff90..4775ae5 100644 --- a/spec/models/supply_spec.rb +++ b/spec/models/supply_spec.rb @@ -1,11 +1,7 @@ require 'rails_helper' RSpec.describe Supply, type: :model do - it 'is valid with a name ,presentation, stock, stock minumin and stock reposition' do - supply = build(:supply) - expect(supply).to be_valid - end - + it { expect(build(:supply)).to be_valid } it { should validate_presence_of(:name) } it { should validate_presence_of(:stock) } it { should validate_presence_of(:stock_minimun) } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 0105198..22c8cc4 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,12 +1,11 @@ require 'rails_helper' RSpec.describe User, type: :model do - it 'is valid with a first name, last name, email, role and user_identifier' do - organization = build(:organization) - user = build(:user, organization: organization) + it { + user = build(:user, organization: build(:organization)) expect(user).to be_valid expect(user.name).to eq("#{user.first_name} #{user.last_name}") - end + } it { should validate_presence_of(:first_name) } it { should validate_presence_of(:last_name) } diff --git a/spec/models/warehouse_spec.rb b/spec/models/warehouse_spec.rb index 56f8165..f868383 100644 --- a/spec/models/warehouse_spec.rb +++ b/spec/models/warehouse_spec.rb @@ -1,10 +1,5 @@ require 'rails_helper' RSpec.describe Warehouse, type: :model do - it 'is valid ' do - supply = build(:supply) - space = build(:space) - warehouse = build(:warehouse, space: space, supply: supply) - expect(warehouse).to be_valid - end + it { expect(build(:warehouse, space: build(:space), supply: build(:supply))).to be_valid } end