I am using factory girl to create a model with inventory_count = 3. In my test, I want to test a case for when inventory_count = 0..so here’s what I did:
before(:each) do
@user = FactoryGirl.create(:user)
@piece = FactoryGirl.create(:piece)
@lineup = @user.lineup
end
it 'should have status \'Waiting List\' if the piece doesn\'t have available inventory' do
@piece.available_count = 0
@lineup.pieces << @piece
piece_lineup = @lineup.piece_lineups.find_by_piece_id(@piece.id)
piece_lineup.set_status
piece_lineup.status.should == 'Waiting List'
end
I put a debugger after @piece.available_count = 0 and it is = 0, but when it gets down to the next line it switches back to the old value. I tried adding a .save to @piece but it still didn’t work. Am i doing something wrong? Should I be creating the new value model in factorygirl instead of trying to do it on the fly?
I believe it would be better practice to write:
to create a
piecemodel with its count already 0.Also, you’re question begins mentioning
inventory_count. Did you actually meanavailable_count? Just want to make sure you didn’t have a typo.