Skip to content
This repository was archived by the owner on Jul 24, 2020. It is now read-only.

Commit 6047360

Browse files
committedFeb 17, 2017
Avoid needlessly persisting to db in equipment model spec
Resolves #1665 -change spec to build_stubbed instead of build
1 parent 0e87e1a commit 6047360

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed
 

‎spec/models/equipment_model_spec.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def mock_eq_model(**attrs)
1313
end
1414

1515
describe 'basic validations' do
16-
subject { EquipmentModel.new(ordering: 1) }
16+
let!(:model) { mock_eq_model }
1717
it { is_expected.to have_and_belong_to_many(:requirements) }
1818
it { is_expected.to have_many(:equipment_items) }
1919
it { is_expected.to have_many(:reservations) }
@@ -23,17 +23,20 @@ def mock_eq_model(**attrs)
2323
it { is_expected.to accept_nested_attributes_for(:checkout_procedures) }
2424
it { is_expected.to have_and_belong_to_many(:associated_equipment_models) }
2525
it { is_expected.to validate_presence_of(:name) }
26-
it { is_expected.to validate_uniqueness_of(:name) }
2726
it { is_expected.to validate_presence_of(:description) }
2827
it { is_expected.to belong_to(:category) }
2928
it { is_expected.to validate_presence_of(:ordering) }
3029
it 'requires an associated category' do
31-
model = mock_eq_model
3230
model.category = nil
3331
expect(model.valid?).to be_falsey
3432
end
3533
end
3634

35+
describe 'validations requiring peristance' do
36+
subject {FactoryGirl.build(:equipment_model)}
37+
it { is_expected.to validate_uniqueness_of(:name) }
38+
end
39+
3740
describe 'attribute-specific validations' do
3841
shared_examples 'integer attribute' do |attr|
3942
it 'is valid with an integer value' do

0 commit comments

Comments
 (0)