maclover7
maclover7

Reputation: 137

Rails update_attribute issue

I'm having an issue with the update_attribute updater in Rails. Here's my controller:

class FeatureUpdatesController < ApplicationController
before_action :set_feature

  def backlog
    @feature.update_attribute(:deploy_status, "backlog")
    redirect_to root_path
    flash[:success] = "The status for this feature is now in the backlog"
  end

private
  def set_feature
    @feature = Feature.find(params[:id])
  end
end

Here's my tests:

require 'rails_helper'
RSpec.describe FeatureUpdatesController, type: :controller do
  describe "PUT #backlog" do
    create(:user) && sign_in(user)
    it "updates deploy_status to backlog" do
      feature = FactoryGirl.create(:feature)
      put :backlog, id: feature.id
      expect(feature.deploy_status).to eq("backlog")
    end
  end

Instead of deploy_status coming back as "backlog", it comes back as nil. Any ideas with this?

Upvotes: 1

Views: 59

Answers (1)

Lazarus Lazaridis
Lazarus Lazaridis

Reputation: 6029

I think you have to reload the feature:

... put :backlog, id: feature.id feature.reload expect(feature.deploy_status).to eq('backlog')

Upvotes: 3

Related Questions