Unable to run tests for routes with path:

Unable to run tests for routes with path:

Questions : Unable to run tests for routes with path:

819

I’m building a web app that has some social in4codes_ruby-on-rails media features and I was finally able to get in4codes_ruby-on-rails my routes to display slugs instead of ids in4codes_ruby-on-rails using the friendly_id gem.

Routes file:

resources :account_users, param: :slug, path: "" do resources :friendships, path: :friends, only: %i[index show destroy] end 

Running rails routes |grep friendship in the in4codes_ruby-on-rails terminal:

account_user_friendships GET /:account_user_slug/friends(.:format) friendships#index account_user_friendship GET /:account_user_slug/friends/:id(.:format) friendships#show DELETE /:account_user_slug/friends/:id(.:format) friendships#destroy 

This actually works great on my local in4codes_ruby-on-rails machine and runs without a hitch when I spin in4codes_ruby-on-rails up the server and click through the app on in4codes_ruby-on-rails the browser. However, when when I try to run in4codes_ruby-on-rails my test cases for the controller that were in4codes_ruby-on-rails written before I added the option path: “”, in4codes_ruby-on-rails all of my previously passing tests are now in4codes_ruby-on-rails failing and I get redirected to the root in4codes_ruby-on-rails path.

This is one of my test cases (after signing in4codes_ruby-on-rails the user in with Devise) using minitest and in4codes_ruby-on-rails the shoulda gem:

should "be able to see own friends" do account_user = @user.default_account_user friendship = create(:friendship, account_user: account_user) valid_friendships = [friendship] # create a friend request unrelated to the signed in user to ensure that only valid requests are displayed create(:friend_request) puts account_user_friendships_url(account_user) byebug get account_user_friendships_url(account_user) assert_response :success assert_equal valid_friendships, @controller.view_assigns["friendships"] end 

Here is the result that i get in the in4codes_ruby-on-rails terminal:

# Running: http://www.example.com/username1/friends # puts statement for account_user_friendships_url F Failure: FriendshipsControllerTest#test_: signed in index should be able to see own friends.  Expected response to be a <2XX: success>, but was a <302: Found> redirect to <http://www.example.com/> Response body: 

This is the same result for all of my tests in4codes_ruby-on-rails for the controller. Stepping into the code in4codes_ruby-on-rails using byebug, I found that the path helper in4codes_ruby-on-rails I’m using account_user_friendhsips_url is in4codes_ruby-on-rails actually sending me to method_missing:

http://www.example.com/username1/friends [29, 38] in /test/controllers/friendships_controller_test.rb 29: # create a friend request unrelated to the signed in user to ensure that only valid requests are displayed 30: create(:friend_request) 31: puts account_user_friendships_url(account_user) 32: byebug 33: => 34: get account_user_friendships_url(account_user) 35: # get "/#{account_user.username}/friends" 36: 37: assert_response :success 38: assert_equal valid_friendships, @controller.view_assigns["friendships"] (byebug) step [423, 432] in /Users/thaigq/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/actionpack-6.1.4.1/lib/action_dispatch/testing/integration.rb 423: integration_session.respond_to?(method) || super 424: end 425: 426: # Delegate unhandled messages to the current session instance. 427: def method_missing(method, *args, &block) => 428: if integration_session.respond_to?(method) 429: integration_session.public_send(method, *args, &block).tap do 430: copy_session_variables! 431: end 432: else (byebug) 

I have also tried inputting the route in4codes_ruby-on-rails manually in the test case, replacing in4codes_ruby-on-rails account_user_friendships_url with in4codes_ruby-on-rails “/#{account_user.username}/friends” but get in4codes_ruby-on-rails the same result. Can anybody help me with in4codes_ruby-on-rails this please? I would like to test my in4codes_ruby-on-rails controllers, but am unable to because of in4codes_ruby-on-rails this.

Total Answers 0