Created
July 2, 2013 01:53
-
-
Save onigra/5906234 to your computer and use it in GitHub Desktop.
unittestでDB更新結果のassertする場合、reloadを忘れずに ref: http://qiita.com/nekogeruge_987/items/de0317203cfe59558c4e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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