5

I am attempting to create a RSpec controller test for a namespaced controller, but rspec doesn't seem able to detect the nesting and generate the proper path for the post :create action.

This is my spec code:

# for: /app/controllers/admin/crm/report_adjustments_controller.rb
require 'spec_helper'
describe Admin::Crm::ReportAdjustmentsController do
  render_views

  before(:each) do
    signin
  end

  describe "GET 'index'" do
    it "returns http success" do
      get :index
      response.should be_success
    end
  end

  describe "POST 'create'" do
    it "creates with right parameters" do
      expect {
        post :create, report_adjustment: {distributor_id: @ole_distributor.id, amount: "30.0", date: Date.today }
      }.to change(Crm::ReportAdjustment, :count).by(1)
      response.should be_success
    end
  end
end

# routes.rb
namespace :admin do
  namespace :crm do
    resources :report_adjustments
  end
end

For this code, the get :index works just fine, but when post :create is called, the following error is generated: undefined method 'crm_report_adjustment_url'

Why would RSpec be smart enough to figure things out with get :index, but not with post :create? How do I get RSpec to properly load the right route, which is admin_crm_report_adjustments_url?

Thanks in advance.

1

1 Answer 1

1

Try posting to the url instead:

post admin_crm_report_adjustments_url

# or 

post "/admin/crm/report_adjustments"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.