Skip to content

Commit

Permalink
Remove unused methods from Organization model (#4938)
Browse files Browse the repository at this point in the history
* Remove unused methods from organization model

* Remove Organization#total_inventory method too

* Remove Organization#display_users method
  • Loading branch information
coalest authored Jan 21, 2025
1 parent fdc710f commit 68ff55e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 113 deletions.
41 changes: 2 additions & 39 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class Organization < ApplicationRecord
has_many :product_drives
has_many :donation_sites
has_many :donations
has_many :items
has_many :item_categories
has_many :manufacturers
has_many :partners
has_many :partner_groups
Expand All @@ -77,29 +79,6 @@ class Organization < ApplicationRecord
has_many :request_units, class_name: 'Unit'
end

has_many :items, dependent: :destroy do
def other
where(partner_key: "other")
end

def during(date_start, date_end = Time.zone.now.strftime("%Y-%m-%d"))
select("COUNT(line_items.id) as amount, name")
.joins(:line_items)
.where("line_items.created_at BETWEEN ? and ?", date_start, date_end)
.group(:name)
end

def top(limit = 5)
order('count(line_items.id) DESC')
.limit(limit)
end

def bottom(limit = 5)
order('count(line_items.id) ASC')
.limit(limit)
end
end
has_many :item_categories, dependent: :destroy
has_many :barcode_items, dependent: :destroy do
def all
unscope(where: :organization_id).where("barcode_items.organization_id = ? OR barcode_items.barcodeable_type = ?", proxy_association.owner.id, "BaseItem")
Expand Down Expand Up @@ -171,10 +150,6 @@ def to_param
short_name
end

def display_users
users.map(&:email).join(", ")
end

def ordered_requests
requests.order(status: :asc, updated_at: :desc)
end
Expand All @@ -189,14 +164,6 @@ def address_changed?
street_changed? || city_changed? || state_changed? || zipcode_changed?
end

def address_inline
address.split("\n").map(&:strip).join(", ")
end

def total_inventory
View::Inventory.total_inventory(id)
end

def self.seed_items(organization = Organization.all)
base_items = BaseItem.without_kit.map(&:to_h)

Expand Down Expand Up @@ -240,10 +207,6 @@ def item_id_to_display_string_map
end
end

def valid_items_for_select
valid_items.map { |item| [item[:name], item[:id]] }.sort
end

def from_email
return get_admin_email if email.blank?

Expand Down
74 changes: 0 additions & 74 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,68 +141,6 @@
end
end
end

describe "items" do
let(:organization) { create(:organization, :with_items) }

before do
organization.items.each_with_index do |item, index|
(index + 1).times { LineItem.create!(quantity: rand(250..500), item: item, itemizable: Distribution.new) }
end
end

describe ".other" do
it "returns all items for this organization designated 'other'" do
create(:item, name: "SOMETHING", partner_key: "other", organization: organization)
expect(organization.items.other.size).to eq(2)
end
end

describe ".during" do
it "return ranking of all items" do
ranking_items = organization.items.during('1950-01-01', '3000-01-01')
expect(ranking_items.length).to eq(organization.items.length)
end
end

describe ".during.top" do
it "return just 3 elements" do
ranking_items = organization.items.during('1950-01-01', '3000-01-01').top(3)
expect(ranking_items.length).to eq(3)
end
it "return 3 most used items" do
ranking_items = organization.items.during('1950-01-01', '3000-01-01').top(3)

expect(ranking_items[0].amount).to eq(organization.items.length)
expect(ranking_items[0].name).to eq(organization.items[organization.items.length - 1].name)

expect(ranking_items[1].amount).to eq(organization.items.length - 1)
expect(ranking_items[1].name).to eq(organization.items[organization.items.length - 2].name)

expect(ranking_items[2].amount).to eq(organization.items.length - 2)
expect(ranking_items[2].name).to eq(organization.items[organization.items.length - 3].name)
end
end

describe ".during.bottom" do
it "return just 3 elements" do
ranking_items = organization.items.during('1950-01-01', '3000-01-01').bottom(3)
expect(ranking_items.length).to eq(3)
end
it "return 3 least used items" do
ranking_items = organization.items.during('1950-01-01', '3000-01-01').bottom(3)

expect(ranking_items[0].amount).to eq(1)
expect(ranking_items[0].name).to eq(organization.items[0].name)

expect(ranking_items[1].amount).to eq(2)
expect(ranking_items[1].name).to eq(organization.items[1].name)

expect(ranking_items[2].amount).to eq(3)
expect(ranking_items[2].name).to eq(organization.items[2].name)
end
end
end
end

describe '#assign_attributes_from_account_request' do
Expand Down Expand Up @@ -346,18 +284,6 @@
end
end

describe "total_inventory" do
it "returns a sum total of all inventory at all storage locations" do
item = create(:item, organization: organization)
create(:storage_location, :with_items, item: item, item_quantity: 100, organization: organization)
create(:storage_location, :with_items, item: item, item_quantity: 150, organization: organization)
expect(organization.total_inventory).to eq(250)
end
it "returns 0 if there is nothing" do
expect(organization.total_inventory).to eq(0)
end
end

describe "geocode" do
it "adds coordinates to the database" do
expect(organization.latitude).to be_a(Float)
Expand Down

0 comments on commit 68ff55e

Please sign in to comment.