尽管控制台和浏览器都可以正常工作,但我无法通过此通行证。谢谢你的帮助!
这是我的规格:
before(:each) do
@attr = {name: "Example Class"}
@create = post :create, {user_id: @user.id, student_group: @attr}
end
it "should create a user" do
lambda do
@create
end.should change {@user.student_groups.count}.by(1)
end
我new
和create
控制器中的操作:
def new
@student_group = @user.student_groups.new
@title = "Create a new class"
end
...
def create
@student_group = @user.student_groups.create(params[:student_group])
if @student_group.save
# for now redirect to
redirect_to classes_path, flash: { success: "#{@student_group.name} created! Next, add some students" }
# redirect_to new_student_group_student_path
else
@title = "Create a new class"
flash.now[:error] = "Something's gone wrong. Please try again!"
render 'new'
end
end
和错误:
1) StudentGroupsController POST 'create' success should create a user
Failure/Error: lambda do
result should have been changed by 1, but was changed by 0
# ./spec/controllers/student_groups_controller_spec.rb:113:in `block (4 levels) in <top (required)>'