Skip to content

Commit

Permalink
Merge pull request #6096 from thejonroberts/rspec-rails-setup-re-install
Browse files Browse the repository at this point in the history
RSpec-Rails Configuration
  • Loading branch information
compwron authored Dec 5, 2024
2 parents c6b9a85 + d78fa52 commit 18aec61
Show file tree
Hide file tree
Showing 65 changed files with 342 additions and 239 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ vendor/bundle/
# produced by tests (?)
.rakeTasks

# produced by tests (?)
*.csv

.*.swp

# Used for local developmen on Nix systems
Expand Down
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--require spec_helper --order random
--require spec_helper
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ group :test do
gem "rails-controller-testing"
gem "rake"
gem "selenium-webdriver"
gem "simplecov"
gem "simplecov", require: false
gem "webmock" # HTTP request stubber
end
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -672,4 +672,4 @@ RUBY VERSION
ruby 3.2.4p170

BUNDLED WITH
2.5.22
2.5.23
2 changes: 1 addition & 1 deletion app/services/volunteer_birthday_reminder_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def send_reminders
.deliver(volunteer.supervisor)
end
else
puts "Volunteer Birthday Reminder Rake task skipped. Today is not the 15th of the month."
Rails.logger.info { "Volunteer Birthday Reminder Rake task skipped. Today is not the 15th of the month." }
end
end
end
2 changes: 1 addition & 1 deletion spec/datatables/reimbursement_datatable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# Requires the following to be defined:
# - `sorted_case_contacts` = array of reimbursement records ordered in the expected way
shared_examples_for "a sorted results set" do
RSpec.shared_examples_for "a sorted results set" do
it "should order ascending by default" do
expect(first_result[:id]).to eq(sorted_case_contacts.first.id.to_s)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/casa_orgs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
twilio_phone_number { "+15555555555" }

trait :with_logo do
logo { Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "org_logo.jpeg")) }
logo { Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "files", "org_logo.jpeg")) }
end

trait :all_reimbursements_enabled do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
case_number,case_assignment,birth_month_year_youth,next_court_date
CINA-01-4347,[email protected], March 2011,Sept 16 2022
CINA-01-4348,"[email protected], [email protected]",February 2000,Jan 1 2023
CINA-01-4349,,December 2016,
case_number,case_assignment,birth_month_year_youth,next_court_date
CINA-01-4347,[email protected], March 2011,Sept 16 2022
CINA-01-4348,"[email protected], [email protected]",February 2000,Jan 1 2023
CINA-01-4349,,December 2016,
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
email,display_name,supervisor_volunteers,phone_number
[email protected],s5,[email protected],11111111111
[email protected],s6,[email protected],11111111111
email,display_name,supervisor_volunteers,phone_number
[email protected],s5,[email protected],11111111111
[email protected],s6,[email protected],11111111111
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
email,display_name,supervisor_volunteers,phone_number
[email protected],Supervisor One,[email protected],11111111111
[email protected],Supervisor Two,"[email protected], [email protected]",11111111111
[email protected],Supervisor Three,,11111111111
email,display_name,supervisor_volunteers,phone_number
[email protected],Supervisor One,[email protected],11111111111
[email protected],Supervisor Two,"[email protected], [email protected]",11111111111
[email protected],Supervisor Three,,11111111111
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
email,display_name,supervisor_volunteers,phone_number
[email protected],Supervisor One,[email protected],11111111111
,Supervisor Two,"[email protected], [email protected]",11111111111
email,display_name,supervisor_volunteers,phone_number
[email protected],Supervisor One,[email protected],11111111111
,Supervisor Two,"[email protected], [email protected]",11111111111
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
display_name,email,phone_number
Volunteer One,[email protected],11234567890
Volunteer Two,[email protected],11234567891
Volunteer Three,[email protected],11234567892
display_name,email,phone_number
Volunteer One,[email protected],11234567890
Volunteer Two,[email protected],11234567891
Volunteer Three,[email protected],11234567892
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
display_name,email,phone_number
Volunteer One,[email protected],11111111111
Volunteer Two,11111111111
Volunteer Three,,11111111111
display_name,email,phone_number
Volunteer One,[email protected],11111111111
Volunteer Two,11111111111
Volunteer Three,,11111111111
2 changes: 1 addition & 1 deletion spec/helpers/banner_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe BannerHelper do
RSpec.describe BannerHelper, type: :helper do
describe "#conditionally_add_hidden_class" do
it "returns d-none if current banner is inactive" do
current_organization = double
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/case_contacts_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe CaseContactsHelper do
RSpec.describe CaseContactsHelper, type: :helper do
describe "#render_back_link" do
it "renders back link to home page when user is a volunteer" do
current_user = create(:volunteer)
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/court_dates_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe CourtDatesHelper do
RSpec.describe CourtDatesHelper, type: :helper do
describe "#when_do_we_have_court_dates" do
subject { helper.when_do_we_have_court_dates(casa_case) }

Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/court_orders_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe CourtDatesHelper do
RSpec.describe CourtDatesHelper, type: :helper do
describe "#court_order_select_options" do
context "when no court orders" do
it "empty" do
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/followup_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe FollowupHelper do
RSpec.describe FollowupHelper, type: :helper do
describe "#followup_icon" do
context "volunteer created followup" do
it "is orange circle with an exclamation point" do
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/mileage_rates_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe MileageRatesHelper do
RSpec.describe MileageRatesHelper, type: :helper do
describe "#effective_date_parser" do
context "with date" do
let(:date) { DateTime.parse("01-01-2021") }
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/notifications_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe NotificationsHelper do
RSpec.describe NotificationsHelper, type: :helper do
context "notifications with respect to deploy time" do
let(:notification_created_after_deploy_a) { create(:notification) }
let(:notification_created_after_deploy_b) { create(:notification, created_at: 1.day.ago) }
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/other_duties_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe OtherDutiesHelper do
RSpec.describe OtherDutiesHelper, type: :helper do
describe "#duration_minutes" do
it "returns remainder if duration_minutes is set" do
other_duty = build(:other_duty, duration_minutes: 80)
Expand Down
108 changes: 52 additions & 56 deletions spec/helpers/phone_number_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,71 +1,67 @@
require "rails_helper"

RSpec.describe PhoneNumberHelper do
describe "phone number helper" do
include PhoneNumberHelper

context "validates phone number" do
it "with empty string" do
valid, error = valid_phone_number("")
expect(valid).to be(true)
expect(error).to be_nil
end
RSpec.describe PhoneNumberHelper, type: :helper do
context "validates phone number" do
it "with empty string" do
valid, error = valid_phone_number("")
expect(valid).to be(true)
expect(error).to be_nil
end

it "with 10 digit phone number prepended with US country code" do
valid, error = valid_phone_number("+12223334444")
expect(valid).to be(true)
expect(error).to be_nil
end
it "with 10 digit phone number prepended with US country code" do
valid, error = valid_phone_number("+12223334444")
expect(valid).to be(true)
expect(error).to be_nil
end

it "with 10 digit phone number prepended with US country code without the plus sign" do
valid, error = valid_phone_number("12223334444")
expect(valid).to be(true)
expect(error).to be_nil
end
it "with 10 digit phone number prepended with US country code without the plus sign" do
valid, error = valid_phone_number("12223334444")
expect(valid).to be(true)
expect(error).to be_nil
end

it "with 10 phone number with spaces" do
valid, error = valid_phone_number("222 333 4444")
expect(valid).to be(true)
expect(error).to be_nil
end
it "with 10 phone number with spaces" do
valid, error = valid_phone_number("222 333 4444")
expect(valid).to be(true)
expect(error).to be_nil
end

it "with 10 phone number with parentheses" do
valid, error = valid_phone_number("(222)3334444")
expect(valid).to be(true)
expect(error).to be_nil
end
it "with 10 phone number with parentheses" do
valid, error = valid_phone_number("(222)3334444")
expect(valid).to be(true)
expect(error).to be_nil
end

it "with 10 phone number with dashes" do
valid, error = valid_phone_number("222-333-4444")
expect(valid).to be(true)
expect(error).to be_nil
end
it "with 10 phone number with dashes" do
valid, error = valid_phone_number("222-333-4444")
expect(valid).to be(true)
expect(error).to be_nil
end

it "with 10 phone number with dots" do
valid, error = valid_phone_number("222.333.4444")
expect(valid).to be(true)
expect(error).to be_nil
end
it "with 10 phone number with dots" do
valid, error = valid_phone_number("222.333.4444")
expect(valid).to be(true)
expect(error).to be_nil
end
end

context "invalidates phone number" do
it "with incorrect country code" do
valid, error = valid_phone_number("+22223334444")
expect(valid).to be(false)
expect(error).to have_text("must be 10 digits or 12 digits including country code (+1)")
end
context "invalidates phone number" do
it "with incorrect country code" do
valid, error = valid_phone_number("+22223334444")
expect(valid).to be(false)
expect(error).to have_text("must be 10 digits or 12 digits including country code (+1)")
end

it "with short phone number" do
valid, error = valid_phone_number("+122")
expect(valid).to be(false)
expect(error).to have_text("must be 10 digits or 12 digits including country code (+1)")
end
it "with short phone number" do
valid, error = valid_phone_number("+122")
expect(valid).to be(false)
expect(error).to have_text("must be 10 digits or 12 digits including country code (+1)")
end

it "with long phone number" do
valid, error = valid_phone_number("+12223334444555")
expect(valid).to be(false)
expect(error).to have_text("must be 10 digits or 12 digits including country code (+1)")
end
it "with long phone number" do
valid, error = valid_phone_number("+12223334444555")
expect(valid).to be(false)
expect(error).to have_text("must be 10 digits or 12 digits including country code (+1)")
end
end
end
2 changes: 1 addition & 1 deletion spec/helpers/report_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe ReportHelper do
RSpec.describe ReportHelper, type: :helper do
describe "#boolean_choices" do
it "returns array with correct options" do
expect(helper.boolean_choices).to eq [["Both", ""], ["Yes", true], ["No", false]]
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/sidebar_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe SidebarHelper do
RSpec.describe SidebarHelper, type: :helper do
describe "#menu_item" do
it "does not render sidebar menu item when not visible" do
menu_item = helper.menu_item(label: "Supervisors", path: supervisors_path, visible: false)
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/sms_body_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe SmsBodyHelper do
RSpec.describe SmsBodyHelper, type: :helper do
describe "#account_activation_msg" do
it "correct short links provided" do
expected_response = account_activation_msg("primogems", {0 => "www.pasta.com", 1 => "www.yogurt.com"})
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/ui_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe UiHelper do
RSpec.describe UiHelper, type: :helper do
describe "#grouped_options_for_assigning_case" do
before(:each) do
@casa_cases = create_list(:casa_case, 4)
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/importers/case_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
RSpec.describe CaseImporter do
subject(:case_importer) { CaseImporter.new(import_file_path, casa_org_id) }

let(:casa_org_id) { import_user.casa_org.id }
let!(:import_user) { build(:casa_admin) }
let(:import_file_path) { Rails.root.join("spec", "fixtures", "casa_cases.csv") }
let(:casa_org) { create :casa_org }
let(:casa_org_id) { casa_org.id }
let(:import_file_path) { file_fixture "casa_cases.csv" }

before do
allow(case_importer).to receive(:email_addresses_to_users) do |_clazz, comma_separated_emails|
Expand Down Expand Up @@ -91,7 +91,7 @@
end

context "when there's no case number" do
let(:import_file_path) { Rails.root.join("spec", "fixtures", "casa_cases_without_case_number.csv") }
let(:import_file_path) { file_fixture "casa_cases_without_case_number.csv" }

it "returns an error message if row does not contain a case number" do
alert = case_importer.import_cases
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/importers/file_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe FileImporter do
let!(:import_user) { build_stubbed(:casa_admin) }
let(:import_file_path) { Rails.root.join("spec", "fixtures", "generic.csv") }
let(:import_file_path) { file_fixture "generic.csv" }
let(:file_importer) { FileImporter.new(import_file_path, import_user.casa_org.id, "something", ["header"]) }

describe "import" do
Expand Down Expand Up @@ -40,7 +40,7 @@
end

it "returns an error if file has no rows" do
no_row_path = Rails.root.join("spec", "fixtures", "no_rows.csv")
no_row_path = file_fixture "no_rows.csv"
no_row_importer = FileImporter.new(no_row_path, import_user.casa_org.id, "something", ["header"])
expect(no_row_importer.import[:message]).eql?(FileImporter::ERR_NO_ROWS)
end
Expand Down
Loading

0 comments on commit 18aec61

Please sign in to comment.