how to check array changes in rspec after a service call?

Viewed 259

The goal is simple

example we have an array

[
  {name: "ghost", state: "rejected"}, 
  {name: "donkey", state: "rejected"}
]

After running the Service call UpdateAllUsers, it would change all the users to 'accepted'

   [
      {name: "ghost", state: "accepted"}, 
      {name: "donkey", state: "accepted"}
    ]

The question here is how do i check all the object in the array to have the same value after that service call in rspec?

example in rspec

describe 'call' do
   let(:all_users) { build(:users, 2, state: "rejected")

    service_call { UpdateAllUsers.new.call }


    it "change all user state to approved" do
         # The goal is to check all the users state after the Service call.
         # Can't find a way to do so
         # the after state should be state => 'accepted'
     end
end
1 Answers

May be is too late but it could be useful if someone stumble with the same problem.

describe 'call' do
   let(:all_users) { build(:users, 2, state: "rejected")

    service_call { UpdateAllUsers.new.call }


    it "change all user state to approved" do
         # The goal is to check all the users state after the Service call.
         # Can't find a way to do so
         # the after state should be state => 'accepted'
        all_users.each do |user|
          expect(user).to include(:state => 'accepted')
        end
    end
end
Related