rails rspec update_all method works in controller but doesn't in rspec -
** controller
puts merchants.first.is_blocked // 1 merchant.update_all( {:is_blocked => 0}, "mch_id in (#{@merchants.map(&:mch_id).join(",")})" ) puts merchants.first.is_blocked // 0, works
** rspec
expect { :update_merchants, params }.to alter { merchant_1.is_blocked }.from(1).to(0) // result should have been changed 0, 1
i don't know reason why "update_all" method works in controller , doesn't work in rspec
firstly, update_all line pretty nasty. assuming @merchants
arel query conditions required locate merchants want update, please consider converting this:
@merchants.update_all(is_blocked: 0)
if @merchants array of records, utilize this:
merchant.where(id: @merchants.map(&:id)).update_all(is_blocked: 0)
secondly, get
request should never modify database. consider changing put
request.
finally, if merchant_1
instance variable created/fetched before calling method, test still has pre-change value. either need re-fetch it, or phone call reload
on before you'll see updated values.
expect { :update_merchants, params }.to alter { merchant_1.reload.is_blocked }.from(1).to(0)
ruby-on-rails rspec
No comments:
Post a Comment