Skip to content

Commit

Permalink
Merge pull request rubyforgood#4359 from elasticspoon/fix-more-specs
Browse files Browse the repository at this point in the history
fix: specs that got added
  • Loading branch information
awwaiid authored May 15, 2024
2 parents adab5e7 + d5aed3c commit cace801
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 63 deletions.
9 changes: 6 additions & 3 deletions spec/requests/reports/activity_graph_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
require "rails_helper"

RSpec.describe "Reports::ActivityGraph", type: :request do
RSpec.describe "Reports::ActivityGraph", type: :request, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }

let(:default_params) do
{organization_name: @organization.to_param}
{organization_name: organization.to_param}
end

describe "while signed in" do
before do
sign_in @user
sign_in user
end

describe "GET #index" do
Expand Down
25 changes: 14 additions & 11 deletions spec/requests/reports/distributions_summary_requests_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
require "rails_helper"

RSpec.describe "Distributions", type: :request do
RSpec.describe "Distributions", type: :request, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }

context "while signed in" do
before do
travel_to("2024-01-17")
end

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

context "the index page" do
context "without filters" do
before do
get reports_distributions_summary_path(@user.organization)
get reports_distributions_summary_path(user.organization)
end

it "shows a list of recent distributions" do
Expand All @@ -28,18 +31,18 @@
context "with filters" do
before do
# Create a bunch of historical distributions
create :distribution, :with_items, item_quantity: 2, issued_at: 0.days.ago
create :distribution, :with_items, item_quantity: 3, issued_at: 1.day.ago
create :distribution, :with_items, item_quantity: 7, issued_at: 3.days.ago
create :distribution, :with_items, item_quantity: 11, issued_at: 10.days.ago
create :distribution, :with_items, item_quantity: 13, issued_at: 20.days.ago
create :distribution, :with_items, item_quantity: 17, issued_at: 30.days.ago
create :distribution, :with_items, item_quantity: 2, issued_at: 0.days.ago, organization: organization
create :distribution, :with_items, item_quantity: 3, issued_at: 1.day.ago, organization: organization
create :distribution, :with_items, item_quantity: 7, issued_at: 3.days.ago, organization: organization
create :distribution, :with_items, item_quantity: 11, issued_at: 10.days.ago, organization: organization
create :distribution, :with_items, item_quantity: 13, issued_at: 20.days.ago, organization: organization
create :distribution, :with_items, item_quantity: 17, issued_at: 30.days.ago, organization: organization
end

let(:formatted_date_range) { date_range.map { _1.to_formatted_s(:date_picker) }.join(" - ") }

before do
get reports_distributions_summary_path(@user.organization), params: {filters: {date_range: formatted_date_range}}
get reports_distributions_summary_path(user.organization), params: {filters: {date_range: formatted_date_range}}
end

context "today" do
Expand Down Expand Up @@ -83,7 +86,7 @@
context "while not signed in" do
describe "GET #index" do
it "redirects user to sign in page" do
get reports_distributions_summary_path(@user.organization)
get reports_distributions_summary_path(user.organization)
expect(response).to redirect_to(new_user_session_path)
end
end
Expand Down
23 changes: 13 additions & 10 deletions spec/requests/reports/donations_summary_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
require "rails_helper"

RSpec.describe "Reports::DonationsSummary", type: :request do
RSpec.describe "Reports::DonationsSummary", type: :request, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }

let(:default_params) do
{organization_name: @organization.to_param}
{organization_name: organization.to_param}
end

describe "while signed in" do
before do
sign_in @user
sign_in user
end

describe "GET #index" do
Expand All @@ -33,18 +36,18 @@
context "with filters" do
before do
# Create a bunch of historical donations
create :donation, :with_items, item_quantity: 2, issued_at: 0.days.ago
create :donation, :with_items, item_quantity: 3, issued_at: 1.day.ago
create :donation, :with_items, item_quantity: 7, issued_at: 3.days.ago
create :donation, :with_items, item_quantity: 11, issued_at: 10.days.ago
create :donation, :with_items, item_quantity: 13, issued_at: 20.days.ago
create :donation, :with_items, item_quantity: 17, issued_at: 30.days.ago
create :donation, :with_items, item_quantity: 2, issued_at: 0.days.ago, organization: organization
create :donation, :with_items, item_quantity: 3, issued_at: 1.day.ago, organization: organization
create :donation, :with_items, item_quantity: 7, issued_at: 3.days.ago, organization: organization
create :donation, :with_items, item_quantity: 11, issued_at: 10.days.ago, organization: organization
create :donation, :with_items, item_quantity: 13, issued_at: 20.days.ago, organization: organization
create :donation, :with_items, item_quantity: 17, issued_at: 30.days.ago, organization: organization
end

let(:formatted_date_range) { date_range.map { _1.to_formatted_s(:date_picker) }.join(" - ") }

before do
get reports_donations_summary_path(@user.organization), params: {filters: {date_range: formatted_date_range}}
get reports_donations_summary_path(user.organization), params: {filters: {date_range: formatted_date_range}}
end

context "today" do
Expand Down
11 changes: 7 additions & 4 deletions spec/requests/reports/itemized_distributions_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
require "rails_helper"

RSpec.describe "Reports::ItemizedDistributions", type: :request do
RSpec.describe "Reports::ItemizedDistributions", type: :request, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }

let(:default_params) do
{organization_name: @organization.to_param}
{organization_name: organization.to_param}
end

describe "while signed in" do
before do
sign_in @user
sign_in user
end

describe "GET #index" do
Expand All @@ -33,7 +36,7 @@
end

context "with a distribution" do
let(:distribution) { create(:distribution, :with_items, organization: @organization) }
let(:distribution) { create(:distribution, :with_items, organization: organization) }

it "Shows an item from the distribution" do
distribution
Expand Down
11 changes: 7 additions & 4 deletions spec/requests/reports/itemized_donations_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
require "rails_helper"

RSpec.describe "Reports::ItemizedDonations", type: :request do
RSpec.describe "Reports::ItemizedDonations", type: :request, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }

let(:default_params) do
{organization_name: @organization.to_param}
{organization_name: organization.to_param}
end

describe "while signed in" do
before do
sign_in @user
sign_in user
end

describe "GET #index" do
Expand All @@ -33,7 +36,7 @@
end

context "with a donation" do
let(:donation) { create(:donation, :with_items, organization: @organization) }
let(:donation) { create(:donation, :with_items, organization: organization) }

it "Shows an item from the donation" do
donation
Expand Down
9 changes: 6 additions & 3 deletions spec/requests/reports/manufacturer_donations_summary_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
require "rails_helper"

RSpec.describe "Reports::ManufacturerDonationsSummary", type: :request do
RSpec.describe "Reports::ManufacturerDonationsSummary", type: :request, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }

let(:default_params) do
{organization_name: @organization.to_param}
{organization_name: organization.to_param}
end

describe "while signed in" do
before do
sign_in @user
sign_in user
end

describe "GET #index" do
Expand Down
37 changes: 20 additions & 17 deletions spec/requests/reports/product_drives_summary_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
require "rails_helper"

RSpec.describe "Reports::ProductDrivesSummary", type: :request do
RSpec.describe "Reports::ProductDrivesSummary", type: :request, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }

let(:default_params) do
{organization_name: @organization.to_param}
{organization_name: organization.to_param}
end

describe "while signed in" do
before do
sign_in @user
sign_in user
end

describe "GET #index" do
Expand All @@ -23,25 +26,25 @@
context "with filters" do
before do
# Create a bunch of historical product_drives
create :product_drive_donation, :with_items, item_quantity: 2, money_raised: 700, issued_at: 0.days.ago
create :product_drive_donation, :with_items, item_quantity: 3, money_raised: 700, issued_at: 1.day.ago
create :product_drive_donation, :with_items, item_quantity: 7, money_raised: 700, issued_at: 3.days.ago
create :product_drive_donation, :with_items, item_quantity: 11, money_raised: 700, issued_at: 10.days.ago
create :product_drive_donation, :with_items, item_quantity: 13, money_raised: 700, issued_at: 20.days.ago
create :product_drive_donation, :with_items, item_quantity: 17, money_raised: 700, issued_at: 30.days.ago

create :product_drive_donation, :with_items, item_quantity: 12, money_raised: 1700, issued_at: 0.days.ago
create :product_drive_donation, :with_items, item_quantity: 13, money_raised: 1700, issued_at: 1.day.ago
create :product_drive_donation, :with_items, item_quantity: 17, money_raised: 1700, issued_at: 3.days.ago
create :product_drive_donation, :with_items, item_quantity: 111, money_raised: 1700, issued_at: 10.days.ago
create :product_drive_donation, :with_items, item_quantity: 113, money_raised: 1700, issued_at: 20.days.ago
create :product_drive_donation, :with_items, item_quantity: 117, money_raised: 1700, issued_at: 30.days.ago
create :product_drive_donation, :with_items, item_quantity: 2, money_raised: 700, issued_at: 0.days.ago, organization: organization
create :product_drive_donation, :with_items, item_quantity: 3, money_raised: 700, issued_at: 1.day.ago, organization: organization
create :product_drive_donation, :with_items, item_quantity: 7, money_raised: 700, issued_at: 3.days.ago, organization: organization
create :product_drive_donation, :with_items, item_quantity: 11, money_raised: 700, issued_at: 10.days.ago, organization: organization
create :product_drive_donation, :with_items, item_quantity: 13, money_raised: 700, issued_at: 20.days.ago, organization: organization
create :product_drive_donation, :with_items, item_quantity: 17, money_raised: 700, issued_at: 30.days.ago, organization: organization

create :product_drive_donation, :with_items, item_quantity: 12, money_raised: 1700, issued_at: 0.days.ago, organization: organization
create :product_drive_donation, :with_items, item_quantity: 13, money_raised: 1700, issued_at: 1.day.ago, organization: organization
create :product_drive_donation, :with_items, item_quantity: 17, money_raised: 1700, issued_at: 3.days.ago, organization: organization
create :product_drive_donation, :with_items, item_quantity: 111, money_raised: 1700, issued_at: 10.days.ago, organization: organization
create :product_drive_donation, :with_items, item_quantity: 113, money_raised: 1700, issued_at: 20.days.ago, organization: organization
create :product_drive_donation, :with_items, item_quantity: 117, money_raised: 1700, issued_at: 30.days.ago, organization: organization
end

let(:formatted_date_range) { date_range.map { _1.to_formatted_s(:date_picker) }.join(" - ") }

before do
get reports_product_drives_summary_path(@user.organization), params: {filters: {date_range: formatted_date_range}}
get reports_product_drives_summary_path(user.organization), params: {filters: {date_range: formatted_date_range}}
end

context "today" do
Expand Down
25 changes: 14 additions & 11 deletions spec/requests/reports/purchases_summary_requests_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
require "rails_helper"

RSpec.describe "Purchases", type: :request do
RSpec.describe "Purchases", type: :request, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }

context "while signed in" do
before do
sign_in(@user)
sign_in(user)
end

describe "GET #index" do
it "shows a list of recent purchases" do
get reports_purchases_summary_path(@user.organization)
get reports_purchases_summary_path(user.organization)
expect(response.body).to include("Recent purchases")
end
end

context "with filters" do
before do
# Create a bunch of historical purchases
create :purchase, :with_items, item_quantity: 2, issued_at: 0.days.ago
create :purchase, :with_items, item_quantity: 3, issued_at: 1.day.ago
create :purchase, :with_items, item_quantity: 7, issued_at: 3.days.ago
create :purchase, :with_items, item_quantity: 11, issued_at: 10.days.ago
create :purchase, :with_items, item_quantity: 13, issued_at: 20.days.ago
create :purchase, :with_items, item_quantity: 17, issued_at: 30.days.ago
create :purchase, :with_items, item_quantity: 2, issued_at: 0.days.ago, organization: organization
create :purchase, :with_items, item_quantity: 3, issued_at: 1.day.ago, organization: organization
create :purchase, :with_items, item_quantity: 7, issued_at: 3.days.ago, organization: organization
create :purchase, :with_items, item_quantity: 11, issued_at: 10.days.ago, organization: organization
create :purchase, :with_items, item_quantity: 13, issued_at: 20.days.ago, organization: organization
create :purchase, :with_items, item_quantity: 17, issued_at: 30.days.ago, organization: organization
end

let(:formatted_date_range) { date_range.map { _1.to_formatted_s(:date_picker) }.join(" - ") }

before do
get reports_purchases_summary_path(@user.organization), params: {filters: {date_range: formatted_date_range}}
get reports_purchases_summary_path(user.organization), params: {filters: {date_range: formatted_date_range}}
end

context "today" do
Expand Down Expand Up @@ -74,7 +77,7 @@
context "while not signed in" do
describe "GET #index" do
it "redirects user to sign in page" do
get reports_purchases_summary_path(@user.organization)
get reports_purchases_summary_path(user.organization)
expect(response).to redirect_to(new_user_session_path)
end
end
Expand Down

0 comments on commit cace801

Please sign in to comment.