ruby on rails - RSpec test failing for routes that accept id param -


i'm trying test articlescontroller in rails applications. of routes not accept params passing. of routes expect id param failing.

failures:

  1) articlescontroller should find article id      failure/error: :info, id: @article[:id]      actioncontroller::urlgenerationerror:        no route matches {:action=>"info", :controller=>"articles", :id=>"60"}      # ./spec/controllers/articles_controller_spec.rb:26:in `block (2 levels) in <top (required)>'    2) articlescontroller should export folder      failure/error: :export_folder, id: @article[:id]      actioncontroller::urlgenerationerror:        no route matches {:action=>"export_folder", :controller=>"articles", :id=>"60"}      # ./spec/controllers/articles_controller_spec.rb:56:in `block (2 levels) in <top (required)>'    3) articlescontroller should export article id      failure/error: :export, id: @article[:id]      actioncontroller::urlgenerationerror:        no route matches {:action=>"export", :controller=>"articles", :id=>"60"}      # ./spec/controllers/articles_controller_spec.rb:50:in `block (2 levels) in <top (required)>' 

config/routes.rb

get '/articles/list' => 'articles#list', defaults: { format: :html }   '/articles/trendlist' => 'articles#trendlist', defaults: { format: :html }   '/articles/show/:id' => 'articles#show', defaults: { format: :html }, as: :show_article   '/articles/index'   '/articles/info/:id' => 'articles#info', as: :article_info   '/articles/export/:id' => 'articles#export', as: :export_article   '/articles/view/:id' => 'articles#view'   '/articles/favorite/:id' => 'articles#favorite'   '/articles/trending' => 'articles#trending', defaults: { format: :json }   '/articles/deleted' => 'articles#deleted', defaults: { format: :json }   '/articles/csv/:id' => 'articles#csv'   '/articles/export_folder/:id' => 'articles#export_folder', as: :export_folder 

spec/controllers/articles_controller.rb

require 'spec_helper'  describe articlescontroller   before(:all)     article.destroy_all     comfy::cms::layout.destroy_all     comfy::cms::site.destroy_all     site = factorygirl.create(:cms_site)     layout = factorygirl.create(:cms_layout, site_id: site[:id])     @article = factorygirl.create(:cms_page, layout_id: layout[:id], site_id: site[:id])   end    'should index articles'     :index     expect(response.response_code).to eq(200)     expect(response.headers).to include( 'content-type' => 'application/json; charset=utf-8')   end    'should list articles'     :list     expect(response.response_code).to eq(200)     expect(response.headers).to include( 'content-type' => 'text/html; charset=utf-8')   end    'should find article id'     :info, id: @article[:id]     expect(response.response_code).to eq(200)     expect(response.headers).to include( 'content-type' => 'application/json; charset=utf-8')   end    'should list deleted articles'     :deleted     expect(response.response_code).to eq(200)     expect(response.headers).to include( 'content-type' => 'application/json; charset=utf-8')   end    'should list trending articles'     :trending     expect(response.response_code).to eq(200)     expect(response.headers).to include( 'content-type' => 'application/json; charset=utf-8')   end    'should update trending articles'     :trendlist     expect(response.response_code).to eq(200)     expect(response.headers).to include( 'content-type' => 'text/html; charset=utf-8')   end    'should export article id'     :export, id: @article[:id]     expect(response.response_code).to eq(200)     expect(response.headers).to include( 'content-type' => 'text/csv; charset=utf-8')   end    'should export folder'     :export_folder, id: @article[:id]     response.response_code.should eq(200)     expect(response.headers).to include( 'content-type' => 'text/html; charset=utf-8')   end end 

rake routes

prefix verb   uri pattern                                                               controller#action                                         tags    /tags(.:format)                                                           tags#index                                articles_list    /articles/list(.:format)                                                  articles#list                           articles_trendlist    /articles/trendlist(.:format)                                             articles#trendlist                                     articles    /articles/show/:id(.:format)                                              articles/articles#show                               articles_index    /articles/index(.:format)                                                 articles#index                                                 /articles/info/:id(.:format)                                              articles/articles#info                                                 /articles/export/:id(.:format)                                            articles/articles#export                                                 /articles/view/:id(.:format)                                              articles/articles#view                                                 /articles/favorite/:id(.:format)                                          articles/articles#favorite                            articles_trending    /articles/trending(.:format)                                              articles#trending                             articles_deleted    /articles/deleted(.:format)                                               articles#deleted                                                 /articles/csv/:id(.:format)                                               articles/articles#csv                                                 /articles/export_folder/:id(.:format)                                     articles/articles#export_folder 

app/controllers/articles_controller.rb

class articlescontroller < applicationcontroller   include articleshelper    before_action :set_default_response_format, except: [:pdf, :show, :list, :trendlist, :export_folder]    def index     @articles = searcharticlescommand.new(params).execute   end    def deleted     @dlist = article.deleted.map(&:article_id)     render :ids, status: :ok   end    def info     id = params[:id].to_i     @article = article.published.find_by(id: id)   end    def list     @articles = article.folder     render 'articles/list'   end    def favorite     ...     render json: { result: true, is_liked: "#{is_liked}" }   end    def view     ...     render json: { result: true }   end    def trending     load_trending_articles   end    def trendlist     load_trending_articles     render 'articles/trendlist'   end    def export     id = params[:id].to_i     @article = article.published.find_by(id: id)      render pdf: @article.label.gsub(/\s/, '_'),            template: 'articles/export.pdf.erb',            dispostion: 'attachment',            locals: { paragraphs: @article.paragraphs, images: @article.images } 

that not namespace used for. can read more on here. use resources instead , specify member 1 id:

resources :articles, only: []   collection      :list     :trendlist     :trending     :deleted   end    member     :info     :export     :view     :favorite     :csv     :export_folder   end end  'articles/index', to: 'articles#index' 'articles/show/:id', to: 'articles#show' 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -