how to write a Rspec test for update string attribute? I have attribute: "status" and array for that = ['First','Second'] - model Post
it "update status attribute" do expect(@result).to change(Post, :status) end
is it correct?
My interactor:
class User::Post::RequestVerification < ActiveInteraction::Base
object :user
string :status, default: nil
integer :id, default: nil
validate :status
def execute
update_status!
end
def post
@post ||= post.find(id)
end
def update_status!
@post.update_atrributes!(
status: ['First', 'Second']
)
end
def status
errors.add(:base, 'error')
end
end
My RspecTest:
require 'rails_helper'
describe User::Post::RequestVerification do
before do
@result = User::Post::RequestVerification.run(new_params[:post])
end
let!(:user) {Post.new}
let!(:user) { User.create }
let!(:new_params) do
{
post: {
status: 'First'
}
}
end
it "should update status" do
expect(@result).to change(Post, :status)
end
end
I want to write a test to update one attribute.
Looks like the syntax of change
is different. There is similar question with the similar error you mention. I won't copy the answer while I can refer you there.
expected #count to have changed by 1, but was not given a block
Also, looks like you need to chain change
with by
or from(..).to(..)
Take a look at the documentation https://www.relishapp.com/rspec/rspec-expectations/v/2-0/docs/matchers/expect-change
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.