← Back to Upcase

Using xhr to change the value and checking in the rspec


(Charlieanna) #1
 expect{xhr :post, :create,question_id: @question}.to change{Question.first.approved}.from(false).to(true)

works but

expect{xhr :post, :create,question_id: @question}.to change{@question.approved}.from(false).to(true)

does not. Why?

 before do
    @event = Event.create(name:"Amazon")
    @question = @event.questions.create(body:"Will IdleCampus ever be a company?",approved: false)
    @user = User.new_guest
    if @user.save
      session[:user_id] = @user.id
    end
  end

xhr isnt changing the @question variable but changes it in the database when I refer it to using Question.first since it is the only object in the database.