Skip to content

Commit

Permalink
Improve rspec testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie committed Jan 26, 2024
1 parent e3c84ae commit a34c50f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
Capybara.app_host = nil
end

let(:anne) { create(:placements_user, :anne) }
let(:patricia) { create(:placements_user, :patricia) }
let(:mary) { create(:placements_user, :mary) }
let(:colin) { create(:placements_support_user, :colin) }

scenario "I sign in as persona Anne" do
given_there_is_an_existing_persona_for(anne)
given_there_is_an_existing_persona_for("Anne")
when_i_visit_the_personas_page
then_i_see_the_persona_for("Anne")
when_i_click_sign_in_as("Anne")
Expand All @@ -23,7 +18,7 @@
end

scenario "I sign in as persona Patricia" do
given_there_is_an_existing_persona_for(patricia)
given_there_is_an_existing_persona_for("Patrica")
when_i_visit_the_personas_page
then_i_see_the_persona_for("Patricia")
when_i_click_sign_in_as("Patricia")
Expand All @@ -32,7 +27,7 @@
end

scenario "I sign in as persona Mary" do
given_there_is_an_existing_persona_for(mary)
given_there_is_an_existing_persona_for("Mary")
when_i_visit_the_personas_page
then_i_see_the_persona_for("Mary")
when_i_click_sign_in_as("Mary")
Expand All @@ -42,7 +37,7 @@
end

scenario "I sign in as support user persona Colin" do
given_there_is_an_existing_persona_for(colin)
given_there_is_an_existing_persona_for("Colin")
and_there_are_placement_organisations
when_i_visit_the_personas_page
then_i_see_the_persona_for("Colin")
Expand All @@ -56,7 +51,9 @@

private

def given_there_is_an_existing_persona_for(_user); end
def given_there_is_an_existing_persona_for(persona_name)
create(:placements_user, persona_name.downcase.to_sym)
end

def when_i_visit_the_personas_page
visit personas_path
Expand Down
25 changes: 25 additions & 0 deletions spec/models/claims/support_user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# == Schema Information
#
# Table name: users
#
# id :uuid not null, primary key
# email :string not null
# first_name :string not null
# last_name :string not null
# type :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_users_on_type_and_email (type,email) UNIQUE
#
require "rails_helper"

RSpec.describe Claims::SupportUser do
describe "#is_support_user?" do
it "returns true" do
expect(described_class.new.is_support_user?).to eq(true)
end
end
end
15 changes: 3 additions & 12 deletions spec/models/placements/support_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,9 @@
require "rails_helper"

RSpec.describe Placements::SupportUser do
describe "default scope" do
let(:email) { "[email protected]" }
let!(:support_user_with_placements_service) do
create(:placements_support_user, email:)
end
let!(:support_user_with_claims_service) do
create(:claims_support_user, email:)
end

it "is scoped to placement support users" do
user = described_class.find(support_user_with_placements_service.id)
expect(described_class.all).to contain_exactly(user)
describe "#is_support_user?" do
it "returns true" do
expect(described_class.new.is_support_user?).to eq(true)
end
end
end
30 changes: 30 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,34 @@
it { is_expected.to validate_presence_of(:last_name) }
it { is_expected.to validate_presence_of(:type) }
end

context "scopes" do
describe "#claims" do
it "only returns users of type Claims::User" do
claims_user = create(:claims_user)
create(:claims_support_user)
create(:placements_user)
create(:placements_support_user)

expect(described_class.claims).to contain_exactly(claims_user)
end
end

describe "#placements" do
it "only returns users of type Placements::User" do
create(:claims_user)
create(:claims_support_user)
create(:placements_support_user)
placements_user = create(:placements_user)

expect(described_class.placements).to contain_exactly(placements_user)
end
end
end

describe "#is_support_user?" do
it "returns false" do
expect(subject.is_support_user?).to eq(false)
end
end
end

0 comments on commit a34c50f

Please sign in to comment.