I'm trying to test a creation of PageVote. It works just fine: user clicks on an image, PageVote gets created
But testing it with capybara and phantomjs doesnt work =(
here is the test:
it "should change the PageVote after clicking on a vote link", js: true do
visit page_path( @page, locale: :ru )
expect( PageVote.count ).to eq(0)
find("#vote-5").click
expect( PageVote.count ).to eq(1)
end
the controller
def create
Rails.logger.debug "Count before: " + PageVote.count.to_s
@page = Page.find( params[ :page ] )
@vote = PageVote.new( ip_address: request.env['REMOTE_ADDR'], vote: params[ :vote ], page: @page )
@vote.save
Rails.logger.debug "Count after: " + PageVote.count.to_s
respond_to do |format|
format.html { redirect_to page_path( @page ) }
format.js
end
end
And logs for the test are
Started POST "/ru/page_votes?page=1&vote=5" for 127.0.0.1 at 2014-11-25 22:51:04 +0300
[1m[35m (9.0ms)[0m SELECT COUNT(*) FROM "page_votes"
Processing by PageVotesController#create as JS
Parameters: {"page"=>"1", "vote"=>"5", "locale"=>"ru"}
[1m[36m (2.0ms)[0m [1mROLLBACK[0m [1m[35m (1.0ms)[0m SELECT COUNT() FROM "page_votes" Count before: 0 [1m[36mPage Load (2.0ms)[0m [1mSELECT "pages". FROM "pages" INNER JOIN "page_translations" ON "page_translations"."page_id" = "pages"."id" WHERE "page_translations"."locale" = 'ru' AND "pages"."id" = $1 LIMIT 1[0m [["id", 1]] [1m[35mPage::Translation Load (1.0ms)[0m SELECT "page_translations".* FROM "page_translations" WHERE "page_translations"."page_id" IN (1) [1m[36m (2.0ms)[0m [1mBEGIN[0m [1m[35m (0.0ms)[0m COMMIT Completed 401 Unauthorized in 38ms
There is no authentication required to make a vote.
Does anybody knows what to do?