Skip to content

Commit

Permalink
refactor(tests): remove relinace on preseeded db (systems 2)
Browse files Browse the repository at this point in the history
Related systems tests 2
  • Loading branch information
elasticspoon authored and dorner committed May 12, 2024
1 parent fb9af31 commit 7326a15
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 227 deletions.
16 changes: 9 additions & 7 deletions spec/support/date_range_picker_shared_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ def date_range_picker_select_range(range_name)
# I'm looking at you, spec/system/request_system_spec.rb:4
described_class.destroy_all
end
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }

let!(:very_old) { create(described_class.to_s.underscore.to_sym, date_field.to_sym => Time.zone.local(2000, 7, 31), :organization => @organization) }
let!(:recent) { create(described_class.to_s.underscore.to_sym, date_field.to_sym => Time.zone.local(2019, 7, 24), :organization => @organization) }
let!(:today) { create(described_class.to_s.underscore.to_sym, date_field.to_sym => Time.zone.local(2019, 7, 31), :organization => @organization) }
let!(:very_old) { create(described_class.to_s.underscore.to_sym, date_field.to_sym => Time.zone.local(2000, 7, 31), :organization => organization) }
let!(:recent) { create(described_class.to_s.underscore.to_sym, date_field.to_sym => Time.zone.local(2019, 7, 24), :organization => organization) }
let!(:today) { create(described_class.to_s.underscore.to_sym, date_field.to_sym => Time.zone.local(2019, 7, 31), :organization => organization) }

context "when choosing 'All Time'" do
before do
sign_out @user
sign_out user
travel_to Time.zone.local(2019, 7, 31)
sign_in @user
sign_in user
end

after do
Expand All @@ -43,9 +45,9 @@ def date_range_picker_select_range(range_name)

context "when choosing 'Last Month'" do
before do
sign_out @user
sign_out user
travel_to Time.zone.local(2019, 8, 1)
sign_in @user
sign_in user
end

after do
Expand Down
9 changes: 5 additions & 4 deletions spec/support/inventory_assistant.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
def setup_storage_location(storage_location, *items)
organization = storage_location.organization
if items.empty?
items << create(:item, organization: @organization)
items << create(:item, organization: @organization)
items << create(:item, organization: @organization)
items << create(:item, organization: organization)
items << create(:item, organization: organization)
items << create(:item, organization: organization)
end

TestInventory.create_inventory(storage_location.organization, {
TestInventory.create_inventory(organization, {
storage_location.id => items.map { |i| [i.id, 50] }
})
end
32 changes: 18 additions & 14 deletions spec/system/adjustment_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
RSpec.describe "Adjustment management", type: :system, js: true do
let!(:url_prefix) { "/#{@organization.to_param}" }
let!(:storage_location) { create(:storage_location, :with_items, organization: @organization) }
RSpec.describe "Adjustment management", type: :system, js: true, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }
let(:organization_admin) { create(:organization_admin, organization: organization) }

let!(:url_prefix) { "/#{organization.to_param}" }
let!(:storage_location) { create(:storage_location, :with_items, organization: organization) }
let(:add_quantity) { 10 }
let(:sub_quantity) { -10 }

subject { url_prefix + "/adjustments" }

before do
sign_in(@user)
sign_in(user)
end

context "With a new adjustment" do
context "with a storage location that is bare", js: true do
let!(:bare_storage_location) { create(:storage_location, name: "We Got Nothin", organization: @organization) }
let!(:bare_storage_location) { create(:storage_location, name: "We Got Nothin", organization: organization) }

before do
visit subject
Expand Down Expand Up @@ -61,7 +65,7 @@

it "politely informs the user that they're adjusting way too hard", js: true do
sub_quantity = -9001
storage_location = create(:storage_location, :with_items, name: "PICK THIS ONE", item_quantity: 10, organization: @organization)
storage_location = create(:storage_location, :with_items, name: "PICK THIS ONE", item_quantity: 10, organization: organization)
visit url_prefix + "/adjustments"
click_on "New Adjustment"
select storage_location.name, from: "From storage location"
Expand All @@ -78,7 +82,7 @@
it "politely informs the user if they try to adjust down below zero, even if they use multiple adjustments to do so" do
sub_quantity = -9

storage_location = create(:storage_location, :with_items, name: "PICK THIS ONE", item_quantity: 10, organization: @organization)
storage_location = create(:storage_location, :with_items, name: "PICK THIS ONE", item_quantity: 10, organization: organization)
visit url_prefix + "/adjustments"
click_on "New Adjustment"
select storage_location.name, from: "From storage location"
Expand Down Expand Up @@ -111,9 +115,9 @@
end

it "can filter the #index by storage location" do
storage_location2 = create(:storage_location, name: "there", organization: @organization)
create(:adjustment, organization: @organization, storage_location: storage_location)
create(:adjustment, organization: @organization, storage_location: storage_location2)
storage_location2 = create(:storage_location, name: "there", organization: organization)
create(:adjustment, organization: organization, storage_location: storage_location)
create(:adjustment, organization: organization, storage_location: storage_location2)

visit subject
select storage_location.name, from: "filters[at_location]"
Expand All @@ -123,12 +127,12 @@
end

it "can filter the #index by user" do
storage_location2 = create(:storage_location, name: "there", organization: @organization)
create(:adjustment, organization: @organization, storage_location: storage_location, user_id: @user.id)
create(:adjustment, organization: @organization, storage_location: storage_location2, user_id: @organization_admin.id)
storage_location2 = create(:storage_location, name: "there", organization: organization)
create(:adjustment, organization: organization, storage_location: storage_location, user_id: user.id)
create(:adjustment, organization: organization, storage_location: storage_location2, user_id: organization_admin.id)

visit subject
select @user.name, from: "filters[by_user]"
select user.name, from: "filters[by_user]"
click_on "Filter"

expect(page).to have_css("table tr", count: 2)
Expand Down
Loading

0 comments on commit 7326a15

Please sign in to comment.