Skip to content

Instantly share code, notes, and snippets.

@onigra
Created July 2, 2013 01:53
Show Gist options
  • Save onigra/5906234 to your computer and use it in GitHub Desktop.
Save onigra/5906234 to your computer and use it in GitHub Desktop.
unittestでDB更新結果のassertする場合、reloadを忘れずに ref: http://qiita.com/nekogeruge_987/items/de0317203cfe59558c4e
def stock
return redirect_to '/404.html' unless request.xhr?
@list = List.find(params[:id])
if @list.is_stocked?
@list.is_stocked = false
else
@list.is_stocked = true
end
respond_to do |format|
if @list.save
format.js { @list }
else
format.js { render :action => "alert/error" }
end
end
end
test "is_stockedを更新する" do
xhr :get, :stock, :id => @stock_flag_is_true.id
assert_equal false, @stock_flag_is_true.reload.is_stocked
assert_response :success
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment