Browse Source

Check if org holds own stock

pull/1809/head
Jack S 3 years ago
parent
commit
929c37f014
  1. 6
      app/helpers/filters_helper.rb
  2. 2
      app/views/schemes/_scheme_filters.html.erb
  3. 70
      spec/helpers/filters_helper_spec.rb
  4. 6
      spec/requests/schemes_controller_spec.rb

6
app/helpers/filters_helper.rb

@ -91,6 +91,12 @@ module FiltersHelper
[OpenStruct.new(id: "", name: "Select an option")] + organisation_options.map { |org| OpenStruct.new(id: org.id, name: org.name) }
end
def show_scheme_managing_org_filter?(user)
org = user.organisation
user.support? || org.stock_owners.count > 1 || (org.holds_own_stock? && org.stock_owners.count.positive?)
end
private
def applied_filters_count(filter_type)

2
app/views/schemes/_scheme_filters.html.erb

@ -23,7 +23,7 @@
category: "status",
} %>
<% if current_user.support? || current_user.organisation.stock_owners.count > 1 %>
<% if show_scheme_managing_org_filter?(current_user) %>
<%= render partial: "filters/radio_filter", locals: {
f:,
options: {

70
spec/helpers/filters_helper_spec.rb

@ -290,4 +290,74 @@ RSpec.describe FiltersHelper do
end
end
end
describe "#show_scheme_managing_org_filter?" do
context "when support user" do
let(:user) { create(:user, :support, organisation: create(:organisation, stock_owners: [])) }
it "returns true" do
expect(show_scheme_managing_org_filter?(user)).to be true
end
end
context "when not support user" do
let(:stock_owner1) { create(:organisation) }
let(:stock_owner2) { create(:organisation) }
context "when org's stock_owners > 1" do
let(:user) { create(:user, organisation: create(:organisation, holds_own_stock: false)) }
before do
create(
:organisation_relationship,
child_organisation: user.organisation,
parent_organisation: stock_owner1,
)
create(
:organisation_relationship,
child_organisation: user.organisation,
parent_organisation: stock_owner2,
)
end
it "returns true" do
expect(show_scheme_managing_org_filter?(user)).to be true
end
end
context "when org's stock_owners == 1" do
before do
create(
:organisation_relationship,
child_organisation: user.organisation,
parent_organisation: stock_owner1,
)
end
context "when holds own stock" do
let(:user) { create(:user, organisation: create(:organisation, holds_own_stock: true)) }
it "returns true" do
expect(show_scheme_managing_org_filter?(user)).to be true
end
end
context "when does not hold own stock" do
let(:user) { create(:user, organisation: create(:organisation, holds_own_stock: false)) }
it "returns false" do
expect(show_scheme_managing_org_filter?(user)).to be false
end
end
end
context "when org's stock_owners == 0" do
let(:user) { create(:user) }
it "returns false" do
expect(show_scheme_managing_org_filter?(user)).to be false
end
end
end
end
end

6
spec/requests/schemes_controller_spec.rb

@ -336,12 +336,6 @@ RSpec.describe SchemesController, type: :request do
let!(:scheme1) { create(:scheme, owning_organisation: organisation1) }
let!(:scheme2) { create(:scheme, owning_organisation: user.organisation) }
# before do
# org = user.organisation
# org.stock_owners = [organisation1, user.organisation]
# org.save!
# end
context "when filtering by all owning orgs" do
it "shows schemes for all owning orgs" do
get "/schemes?owning_organisation_select=all", headers:, params: {}

Loading…
Cancel
Save