title: ActiveRecord decrement not working in test
body: <p>In my Rails 5.1.6 application I created an <code>Attendance</code> model association between users and events so that users can participate to a given event. Events have an integer <code>seats</code> attribute that is decremented each time a participation is created. The Attendance controller is:</p>
  
  <pre><code>before_action :logged_in_user
  before_action :participants_limit, only: :create
  
  def create
    @attendance = current_user.attendances.build(attendance_params)
    if @attendance.save
      @event.decrement(:seats)
      flash[:success] = "Congratulation! Your participation has been recorded."
      redirect_back(fallback_location: root_url)
    else
      flash[:danger] = @event.errors.full_messages.join(', ')
      redirect_back(fallback_location: root_url)
    end
  end
  
  
  private
  
      def attendance_params
        params.require(:attendance).permit(:event_id)
      end
  
      def participants_limit
        @event = Event.find(params[:attendance][:event_id])
        if @event.seats == 0
          flash[:danger] = 'Attention! Unfortunately this event is full!'
          redirect_back(fallback_location: root_url)
        end
      end
  </code></pre>
  
  <p>I would like to test the create action of the <code>Attendance</code> controller, so I created the following test:</p>
  
  <pre><code>def setup
    @event = events(:event_1)
    @user = users(:user_12)
  end
  
  test "should redirect create when participants limit reached" do
    assert @event.participants.count == 2
    assert @event.seats == 5
    participants = (1..5).map do |num|
      users("user_#{num}".to_sym)
    end
    participants.each do |user|
      log_in_as(user)
      post attendances_path, params: { attendance: { user_id: user.id, event_id: @event.id } }
    end
    assert @event.participants.count == 7
    assert @event.seats == 0
    log_in_as(@user)
    assert_no_difference 'Attendance.count' do
      post attendances_path, params: { attendance: { user_id: @user.id, event_id: @event.id } }
    end
    assert_redirected_to root_url
  end
  </code></pre>
  
  <p>The test fails at the line <code>assert @event.seats == 0</code>: seats are not decremented and result still 5: why is that? I wonder why the decrement method is not working, and if there is something am I missing in the test.</p>