testing - Rails Integration Test -


i taking rails class , stuck on integration test. have made simple app user can use share link website. want create test will:

  1. get amount of links in database
  2. post new link
  3. check number of links has increased 1.

here have far:

test "posts new link , check count"    @link = links.all    "/links/new"    post_via_redirect "/links/new", :url => links(:test_link).url, :description => links(:test_link).description    assert_equal '/links/new', path    assert_difference("link.count",n) 

i know doesn't work cannot figure out wording/syntax , appreciate nod in right direction. please let me know if should include other information.

this simple. assume use minitest functional tests.

the test cases should wrapped class mylinkscontrollertest < actiondispatch::integrationtest mylinkscontrollertest should have same name actual controller.

get amount of links in database.

 test 'should index page'     :index     assert_response :success     refute assigns(:links).empty?   end 

:get :index page , sure response :success or :ok. refute if @links variable empty array(doesn't contain link).

post new link

  test "should new page"     :new     assert_response :success   end 

check get request of :new action. (not sure action, test success response)

check number of links has increased 1.

 test "post action should create link , redirect"     assert_difference "link.count", 1       post :create, link_name: "some name", link: '/some_link_here'        assert_response :redirect     end   end 

:post :create action of params , sure response :redirect , link.count increased 1.

happy testing!


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -