ruby on rails - Ajax Datatables testing with rspec and capybara -


i'm trying create tests app, can't make tests pages datatables work. i'm loading records table ajax. if go browser works fine none of tests pass.

heres code.

index.html.slim

table.table.table-striped.table-bordered.table-hover.table-checkable.order-column#dtable data-source="#{ admin_analysts_path(format: :json)}"   thead     tr       th nome       th email   tbody 

analysts_controller def index add_breadcrumb "todos analistas"

respond_to |format|   format.html   format.json { render json: analystsdatatable.new(view_context)} end 

end

analysts_datatable.rb

class analystsdatatable   delegate :params, :h, :link_to, :number_to_currency, to: :@view    def initialize(view)     @view = view   end    def as_json(options = {})     {       draw: params[:draw].to_i,       recordstotal: analyst.count,       recordsfiltered: analysts.total_entries,       data: data     }   end  private    def data     analysts.map |analyst|       [         link_to(analyst.name, [:admin,analyst]),         (analyst.email)       ]     end   end    def analysts     @analysts ||= fetch_analysts   end    def fetch_analysts     analysts = analyst.order("#{sort_column} #{sort_direction}")     analysts = analysts.page(page)     if params[:length]       analysts = analysts.per_page(params[:length])     end     if params[:search][:value].present?       analysts = analysts.where("name :search or email :search", search: "%#{params[:search][:value]}%")     end     analysts   end    def page     params[:start].to_i == 0 ? 1 : ((params[:start].to_i)/params[:length].to_i) +1   end    def sort_column     columns = %w[name email]     columns[params[:order]['0'][:column].to_i]    end    def sort_direction     params[:order]['0'][:dir] == "desc" ? "desc" : "asc"   end end 

and test configuration javascript spec_helper.rb

capybara.javascript_driver = :webkit 

and test

scenario 'check analysts', :js => true       login_as administrator, scope: :administrator      analyst1     visit admin_analysts_path      expect(page).to have_content("#{analyst.name}")     expect(page).to have_content("#{analyst1.name}")   end 

i saw 1 answer sugested change capybara server because uri large, changed puma didn't work. tried use find method said wait till element loaded.

any suggestion valid, thanks.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -