|
182 | 182 | expect(storage_location.longitude).not_to eq(nil)
|
183 | 183 | end
|
184 | 184 | end
|
| 185 | + |
| 186 | + describe "csv_export_attributes" do |
| 187 | + it "returns an array of storage location attributes, followed by inventory item quantities that are sorted by alphabetized item names" do |
| 188 | + item1 = create(:item, name: "C") |
| 189 | + item2 = create(:item, name: "B") |
| 190 | + item3 = create(:item, name: "A") |
| 191 | + inactive_item = create(:item, name: "inactive item", active: false) |
| 192 | + name = "New Storage Location" |
| 193 | + address = "1500 Remount Road, Front Royal, VA 22630" |
| 194 | + warehouse_type = "Warehouse with loading bay" |
| 195 | + square_footage = rand(1000..10000) |
| 196 | + storage_location = create(:storage_location, name: name, address: address, warehouse_type: warehouse_type, square_footage: square_footage) |
| 197 | + quantity1 = rand(100..1000) |
| 198 | + quantity2 = rand(100..1000) |
| 199 | + quantity3 = rand(100..1000) |
| 200 | + TestInventory.create_inventory(storage_location.organization, { |
| 201 | + storage_location.id => { |
| 202 | + item1.id => quantity1, |
| 203 | + item2.id => quantity2, |
| 204 | + item3.id => quantity3, |
| 205 | + inactive_item.id => 1 |
| 206 | + } |
| 207 | + }) |
| 208 | + sum = quantity1 + quantity2 + quantity3 |
| 209 | + expect(storage_location.csv_export_attributes).to eq([name, address, square_footage, warehouse_type, sum, quantity3, quantity2, quantity1]) |
| 210 | + end |
| 211 | + end |
| 212 | + |
| 213 | + describe "self.with_transfers_to and self.with_transfers_from" do |
| 214 | + it "returns storage locations with transfers to/from for an organization" do |
| 215 | + storage_location1 = create(:storage_location, name: "loc1", organization: organization) |
| 216 | + storage_location2 = create(:storage_location, name: "loc2", organization: organization) |
| 217 | + storage_location3 = create(:storage_location, name: "loc3", organization: organization) |
| 218 | + storage_location4 = create(:storage_location, name: "loc4", organization: create(:organization)) |
| 219 | + storage_location5 = create(:storage_location, name: "loc5", organization: storage_location4.organization) |
| 220 | + create(:transfer, from: storage_location3, to: storage_location1, organization: organization) |
| 221 | + create(:transfer, from: storage_location3, to: storage_location2, organization: organization) |
| 222 | + create(:transfer, from: storage_location5, to: storage_location4, organization: storage_location4.organization) |
| 223 | + expect(StorageLocation.with_transfers_to(organization).to_a).to match_array([storage_location1, storage_location2]) |
| 224 | + expect(StorageLocation.with_transfers_from(organization).to_a).to match_array([storage_location3]) |
| 225 | + end |
| 226 | + end |
185 | 227 | end
|
186 | 228 |
|
187 | 229 | describe "versioning" do
|
|
0 commit comments