Skip to content

Commit

Permalink
Refactor test for efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
Kizr committed Jun 18, 2024
1 parent d1964b8 commit f0c0a41
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions spec/wizards/placements/add_placement/steps/phase_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,46 @@
it { is_expected.to validate_presence_of(:school) }
it { is_expected.to validate_presence_of(:phase) }

context "when the phase is primary" do
it "is valid" do
step = described_class.new(school: create(:placements_school), phase: "Primary")
context "when validating the phase" do
let(:school) { build(:placements_school) }

expect(step).to be_valid
context "and the phase is primary" do
it "is valid" do
step = described_class.new(school:, phase: "Primary")

expect(step).to be_valid
end
end
end

context "when the phase is secondary" do
it "is valid" do
step = described_class.new(school: create(:placements_school), phase: "Secondary")
context "and the phase is secondary" do
it "is valid" do
step = described_class.new(school:, phase: "Secondary")

expect(step).to be_valid
expect(step).to be_valid
end
end
end

context "when the is not primary or secondary" do
it "is invalid" do
step = described_class.new(school: create(:placements_school), phase: "Nursery")
context "and the phase is not primary or secondary" do
it "is invalid" do
step = described_class.new(school:, phase: "Nursery")

expect(step).not_to be_valid
expect(step).not_to be_valid
end
end
end
end

describe "#phases_for_selection" do
it "returns primary and secondary phases" do
step = described_class.new(school: create(:placements_school))
step = described_class.new(school: build(:placements_school))

expect(step.phases_for_selection).to eq({ primary: "Primary", secondary: "Secondary" })
end
end

describe "#wizard_attributes" do
it "returns the phase" do
step = described_class.new(school: create(:placements_school), phase: "Primary")
step = described_class.new(school: build(:placements_school), phase: "Primary")

expect(step.wizard_attributes).to eq({ phase: "Primary" })
end
Expand Down

0 comments on commit f0c0a41

Please sign in to comment.