如何使此规范正常工作
实际结果:
expected: [#<Department id: 1, user_id: 1, ...
got: [#<Department id: 1, user_id: "1", ...
这是我的规范:
describe "GET department list" do
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
@current_user = Fabricate(:user_with_active_account_and_departments)
# creates a user with 10 departments
@current_user.confirm!
# or set a confirmed_at inside the factory.
# Only necessary if you are using the confirmable module
sign_in @current_user
end
it "assigns all departments of current_user to @departments" do
get :departments, {id: @current_user}
assigns(:users_departments).should eq (@current_user.departments)
end
end
答案 0 :(得分:3)
将departments
表中的列类型从字符串更改为整数:
def self.up
change_column :departments, :user_id, :integer
end
def self.down
change_column :departments, :user_id, :string
end