From 79597f235a91a45be60c30d4ace8ec10b2da5d8b Mon Sep 17 00:00:00 2001 From: meganchen15 Date: Mon, 4 Jan 2016 15:01:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0blogs=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/controllers/blogs_controller_test.rb | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/controllers/blogs_controller_test.rb diff --git a/test/controllers/blogs_controller_test.rb b/test/controllers/blogs_controller_test.rb new file mode 100644 index 0000000..74037f7 --- /dev/null +++ b/test/controllers/blogs_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' +require 'blogs_controller' +class BlogsControllerTest < ActionController::TestCase + setup do + @controller = BlogsController.new + @blog = BlogInfo.new + @blog.name = 'testblog' + @blog.blog_title = 'New Year around the world' + @blog.email = 'testuser@gmail.com' + @blog.description = 'How do people around the world celebrate their new year?' + @blog.save + + @user = User.new + @user.username = 'testuser' + @user.email = 'testuser@gmail.com' + @user.password = '123456' + @user.password_confirmation = '123456' + @user.admin = 1 + @user.save + end + + test "should get index" do + get :index + assert_response :success + end + + test "should set userinfo" do + patch :set_userinfo, username: @user.username, :user => {:nick_name => 'honey', :avatar => '/users/megan/downloads/1.jpg'} + assert_not_nil assigns(:user) + assert_redirected_to set_blogs_path + end + + test "should update blog" do + post :update_blog, :blog => {:name => 'test', :blog_title => 'test', :email => 'testuser@gmail.com', :description => 'This is a test.'} + assert_redirected_to set_blogs_path + end + + test "should update password" do + patch :update_password, username: @user.username, :user=>{:old_password => @user.password, :password => 'friends', :password_confirmation => 'friends'} + assert_response :success + assert_redirected_to login_path(assigns(:user)) + end + + test "should not update password" do + post :update_password, {:old_password => 'notvalid', :password => 'friends', :password_confirmation => 'friends'} + assert_response :error + end + +end