Refactor tests for saving things when pet is saved
This got more complicated with the items case, and I think this is a stronger idiom for communicating it!
This commit is contained in:
parent
6d25b3424f
commit
8a38ce90dc
1 changed files with 6 additions and 15 deletions
|
@ -20,10 +20,7 @@ RSpec.describe Pet, type: :model do
|
||||||
it("is a Chia") { expect(pet_type.species).to eq Species.find_by_name!("chia") }
|
it("is a Chia") { expect(pet_type.species).to eq Species.find_by_name!("chia") }
|
||||||
it("has the standard Chia body") { expect(pet_type.body_id).to eq 212 }
|
it("has the standard Chia body") { expect(pet_type.body_id).to eq 212 }
|
||||||
it("uses the pet's image hash") { expect(pet_type.image_hash).to eq "m:thyass" }
|
it("uses the pet's image hash") { expect(pet_type.image_hash).to eq "m:thyass" }
|
||||||
|
it("is saved when saving the pet") { pet.save!; should be_persisted }
|
||||||
it("is saved when saving the pet") do
|
|
||||||
expect { pet.save! }.to change { pet_type.persisted? }.from(false).to(true)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "its pet state" do
|
describe "its pet state" do
|
||||||
|
@ -32,16 +29,13 @@ RSpec.describe Pet, type: :model do
|
||||||
it("is new and unsaved") { should be_new_record }
|
it("is new and unsaved") { should be_new_record }
|
||||||
it("belongs to the pet's pet type") { expect(pet_state.pet_type).to eq pet.pet_type }
|
it("belongs to the pet's pet type") { expect(pet_state.pet_type).to eq pet.pet_type }
|
||||||
it("isn't labeled yet") { expect(pet_state.pose).to eq "UNKNOWN" }
|
it("isn't labeled yet") { expect(pet_state.pose).to eq "UNKNOWN" }
|
||||||
|
it("is saved when saving the pet") { pet.save!; should be_persisted }
|
||||||
it "is saved when saving the pet" do
|
|
||||||
expect { pet.save! }.to change { pet_state.persisted? }.from(false).to(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "its biology assets" do
|
describe "its biology assets" do
|
||||||
subject(:biology_assets) { pet_state.swf_assets }
|
subject(:biology_assets) { pet_state.swf_assets }
|
||||||
let(:asset_ids) { biology_assets.map(&:remote_id) }
|
let(:asset_ids) { biology_assets.map(&:remote_id) }
|
||||||
|
|
||||||
it("are all new") { expect(biology_assets.all?(&:new_record?)).to be true }
|
it("are all new") { should all be_new_record }
|
||||||
it("match the expected IDs") do
|
it("match the expected IDs") do
|
||||||
pet.save! # TODO: I wish this were set up before saving.
|
pet.save! # TODO: I wish this were set up before saving.
|
||||||
|
|
||||||
|
@ -125,7 +119,7 @@ RSpec.describe Pet, type: :model do
|
||||||
subject(:biology_assets) { pet.pet_state.swf_assets }
|
subject(:biology_assets) { pet.pet_state.swf_assets }
|
||||||
let(:asset_ids) { biology_assets.map(&:remote_id) }
|
let(:asset_ids) { biology_assets.map(&:remote_id) }
|
||||||
|
|
||||||
it("are all new") { expect(biology_assets.map(&:new_record?)).to all be(true) }
|
it("are all new") { should all be_new_record }
|
||||||
it("match the expected IDs") do
|
it("match the expected IDs") do
|
||||||
pet.save! # TODO: I wish this were set up before saving.
|
pet.save! # TODO: I wish this were set up before saving.
|
||||||
|
|
||||||
|
@ -136,11 +130,8 @@ RSpec.describe Pet, type: :model do
|
||||||
describe "its items" do
|
describe "its items" do
|
||||||
subject(:items) { pet.items }
|
subject(:items) { pet.items }
|
||||||
|
|
||||||
it("are all new") { expect(items.map(&:new_record?)).to all be(true) }
|
it("are all new") { should all be_new_record }
|
||||||
it("are saved when saving the pet") do
|
it("are saved when saving the pet") { pet.save! ; should all be_persisted }
|
||||||
expect { pet.save! }.to change { items.map(&:persisted?) }.
|
|
||||||
from(all(be(false))).to(all(be(true)))
|
|
||||||
end
|
|
||||||
it("have the expected item metadata") do
|
it("have the expected item metadata") do
|
||||||
should contain_exactly(
|
should contain_exactly(
|
||||||
a_record_matching(
|
a_record_matching(
|
||||||
|
|
Loading…
Reference in a new issue