Capybara passes tests with errors on page - ruby-on-rails

I can do a very simple integration test using capybara to test that a page renders correctly. Unfortunately, the tests can pass even if there is an error, if the test happens to find the required content in the error page.
Example test:
scenario 'goes to "new booking" page' do
visit '/bookings/new'
expect(page).to have_content('Driver')
end
Here's an example of the output for a failed test, that only happened to fail because the tested string was not in the error page:
Failure/Error: expect(page).to have_content('Invited')
expected to find text "Invited" in "TypeError at /bookings/86703360-4d92-4b79-bdfd-bbfbf843143e =========================================================== > no implicit conversion of nil into String app/models/vehicle.rb, line 11 ------------------------------ ``` ruby 6 has_many :drivers, through: :workables 7 8 has_and_belongs_to_many :job_types 9 10 def name_with_user > 11 name + \" \" + name_of_user 12 end 13 14 def name_with_user_and_jobs 15 name + \" \" + name_of_user + \" jobs\" 16 end ``` App backtrace ------------- - app/models/vehicle.rb:11:in `name_with_user' - app/views/bookings/show.html.erb:17:in `_app_views_bookings_show_html_erb__3294924100850065400_70296497966640' - app/controllers/bookings_controller.rb:115:in `show' - spec/features/booking_spec.rb:18:in `block (2 levels) in ' Full backtrace -------------- - app/models/vehicle.rb:11:in `name_with_user' - app/views/bookings/show.html.erb:17:in `_app_views_bookings_show_html_erb__3294924100850065400_70296497966640' - actionpack (4.0.8) lib/action_view/template.rb:143:in `block in render' - activesupport (4.0.8) lib/active_support/notifications.rb:161:in `instrument' - actionpack (4.0.8) lib/action_view/template.rb:141:in `render' - actionpack (4.0.8) lib/action_view/renderer/template_renderer.rb:49:in `block (2 levels) in render_template' - actionpack (4.0.8) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument' - activesupport (4.0.8) lib/active_support/notifications.rb:159:in `block in instrument'

You can wrap the text in span/div and test for the text in selector, for eg:
have_css("#status", text: "Invited") #not tested
http://www.rubydoc.info/gems/capybara/0.4.0/Capybara/Node/Matchers

I think you may want to use within. Example:
within('.some-css-class') { expect(page).to have_content 'some content' }
This way you can narrow your search to a particular div or anything else using css selectors.

Related

Sidekiq Job Fails in Production | NameError: uninitialized constant

I have an Expenditure model:
class Expenditure < ApplicationRecord
multi_tenant :company
after_commit :related_reindex
def related_reindex
ExpenditureRelatedReindex.perform_async(id)
end
end
Here is my worker expenditure_related_reindex.rb:
class ExpenditureRelatedReindex
include Sidekiq::Worker
sidekiq_options :queue => :critical, :retry => true, :backtrace => true
def perform(record_id)
e = Expenditure.find(record_id)
MultiTenant.with(e.company) do
return unless e
e.expenditure_items.each(&:reindex)
e.children&.each(&:reindex)
end
end
end
The reindex can take some time so I want these to spin off to SideKiq. I have sime multi tenant code I should mention but I don't think it's the issue. After the record is updated I get:
NameError: uninitialized constant ExpenditureRelatedReindex
Did you mean? ExpenditureItemsHelper
from sidekiq/processor.rb:268:in `const_get'
from sidekiq/processor.rb:268:in `constantize'
from sidekiq/processor.rb:132:in `block (5 levels) in dispatch'
from sidekiq/rails.rb:43:in `block in call'
from active_support/execution_wrapper.rb:87:in `wrap'
from active_support/reloader.rb:73:in `block in wrap'
from active_support/execution_wrapper.rb:87:in `wrap'
from active_support/reloader.rb:72:in `wrap'
from sidekiq/rails.rb:42:in `call'
from sidekiq/processor.rb:131:in `block (4 levels) in dispatch'
from sidekiq/processor.rb:257:in `stats'
from sidekiq/processor.rb:126:in `block (3 levels) in dispatch'
from sidekiq/job_logger.rb:13:in `call'
from sidekiq/processor.rb:125:in `block (2 levels) in dispatch'
from sidekiq/job_retry.rb:78:in `global'
from sidekiq/processor.rb:124:in `block in dispatch'
from sidekiq/logger.rb:10:in `with'
from sidekiq/job_logger.rb:33:in `prepare'
from sidekiq/processor.rb:123:in `dispatch'
from sidekiq/processor.rb:162:in `process'
from sidekiq/processor.rb:78:in `process_one'
from sidekiq/processor.rb:68:in `run'
from sidekiq/util.rb:15:in `watchdog'
from sidekiq/util.rb:24:in `block in safe_thread'
I have even taken out the entire 'perform' block of code i.e. the worker does nothing to confirm I don't have some sort of regressive call etc. I confirm that my other workers fire and process just fine. Checked for obvious typos - banging my head against the wall at this point.
UPDATE
Ok - I have confirmed one thing - if I add any new workers with any name this triggers the same error. I even rebooted the entire production server to confirm the whole code was reloaded etc.
It ended up being Redis (or at least my fix was related). Found this post:
https://github.com/mperham/sidekiq/issues/2834#issuecomment-184800981
and it was a Redis namespace conflict. My server does have elasticsearch running also so that makes sense. I am not sure why the old workers run but the new ones failed. My fix looks like this:
config.redis = {
url: ENV['REDIS_URL'],
namespace: "some_namespace_different_for_each_app"
}
You also need the redis-namespace gem BTW

Google Cloud Talent Solution Exception: Google::Cloud::PermissionDeniedError

Using Google Cloud Talent Solution (aka Google Cloud Job Discovery), I am getting the following stack trace even though all Google API credentials are in place and enabled. Error message seems to be generic ("Permission denied")and not sure what could be wrong. Any insight is much appreciated.
====================================================================
Error message
Google::Cloud::PermissionDeniedError: 7:User not authorized to perform this action.
Sample stack trace (hide Rails)
…cloud-pubsub-0.31.0/lib/google/cloud/pubsub/
service.rb: 459:in rescue in execute'
…cloud-pubsub-0.31.0/lib/google/cloud/pubsub/
service.rb: 455:inexecute'
…cloud-pubsub-0.31.0/lib/google/cloud/pubsub/
service.rb: 150:in publish'
…e-cloud-pubsub-0.31.0/lib/google/cloud/pubsub/
topic.rb: 573:inpublish_batch_messages'
…e-cloud-pubsub-0.31.0/lib/google/cloud/pubsub/
topic.rb: 314:in publish'
…emetry_job_google/lib/google_jobs/
google_jobs_event.rb: 22:inpublish_event'
…metry_careersites/app/mixins/
job_search_event_mixin.rb: 88:in record_google_search_impressions'
…metry_careersites/app/mixins/
job_search_event_mixin.rb: 17:inevent_job_search_impressions'
…ersites/app/controllers/public_site/
jobs_controller.rb: 59:in block (2 levels) in search'
…k-5.2.1.1/lib/action_controller/metal/
mime_responds.rb: 203:inrespond_to'
…ersites/app/controllers/public_site/
jobs_controller.rb: 53:in search'
…1/lib/action_controller/metal/
basic_implicit_render.rb: 6:insend_action'
…ems/actionpack-5.2.1.1/lib/abstract_controller/
base.rb: 194:in process_action'
…npack-5.2.1.1/lib/action_controller/metal/
rendering.rb: 30:inprocess_action'
…ctionpack-5.2.1.1/lib/abstract_controller/
callbacks.rb: 42:in block in process_action'
…/activesupport-5.2.1.1/lib/active_support/
callbacks.rb: 109:inblock in run_callbacks'
…try_careersites/app/controllers/
eventing_controller.rb: 23:in block in append_tracking_info_to_rails_log'
…vesupport-5.2.1.1/lib/active_support/
tagged_logging.rb: 71:inblock in tagged'
…vesupport-5.2.1.1/lib/active_support/
tagged_logging.rb: 28:in tagged'
…vesupport-5.2.1.1/lib/active_support/
tagged_logging.rb: 71:intagged'
…try_careersites/app/controllers/
eventing_controller.rb: 22:in append_tracking_info_to_rails_log'
…/activesupport-5.2.1.1/lib/active_support/
callbacks.rb: 118:inblock in run_callbacks'
…/activesupport-5.2.1.1/lib/active_support/
callbacks.rb: 136:in run_callbacks'
…ctionpack-5.2.1.1/lib/abstract_controller/
callbacks.rb: 41:inprocess_action'
…tionpack-5.2.1.1/lib/action_controller/metal/
rescue.rb: 22:in process_action'
<truncated 60 additional frames>
…2.5.0/gems/rack-timeout-0.5.1/lib/rack/timeout/
core.rb: 123:inblock in call'
…rack-timeout-0.5.1/lib/rack/timeout/support/
timeout.rb: 19:in timeout'
…2.5.0/gems/rack-timeout-0.5.1/lib/rack/timeout/
core.rb: 122:incall'
…k-5.2.1.1/lib/action_dispatch/middleware/
request_id.rb: 27:in call'
…ruby/2.5.0/gems/rack-2.0.6/lib/rack/
method_override.rb: 22:incall'
…/vendor/ruby/2.5.0/gems/rack-2.0.6/lib/rack/
runtime.rb: 22:in call'
…ctive_support/cache/strategy/
local_cache_middleware.rb: 29:incall'
…ack-5.2.1.1/lib/action_dispatch/middleware/
executor.rb: 14:in call'
…npack-5.2.1.1/lib/action_dispatch/middleware/
static.rb: 127:incall'
…vendor/ruby/2.5.0/gems/rack-2.0.6/lib/rack/
sendfile.rb: 111:in call'
…r/ruby/2.5.0/gems/railties-5.2.1.1/lib/rails/
engine.rb: 524:incall'
…/ruby/2.5.0/gems/puma-3.12.0/lib/puma/
configuration.rb: 225:in call'
…/vendor/ruby/2.5.0/gems/puma-3.12.0/lib/puma/
server.rb: 658:inhandle_request'
…/vendor/ruby/2.5.0/gems/puma-3.12.0/lib/puma/
server.rb: 472:in process_client'
…/vendor/ruby/2.5.0/gems/puma-3.12.0/lib/puma/
server.rb: 332:inblock in run'
…or/ruby/2.5.0/gems/puma-3.12.0/lib/puma/
thread_pool.rb: 133:in `block in spawn_thread
You will need to explicitly connect the service account to the Talent Solution api and then use that service account key for the auth. See here for details.

RSpec reinterprets the action from index to show in view testing

I'm getting the following error for my index view:
1) events/index.html.erb should display all the events in a matrix formation
Failure/Error: render
ActionView::Template::Error:
No route matches {:action=>"show", :controller=>"events", :format=>nil, :id=>nil, :locale=>#<Event id: 2, name: "Miles Eichmann", description: "[\"Voluptas quia velit non est.\", \"Commodi aperiam p...", image: "event.jpg", location: nil, created_at: "2015-08-09 13:55:02", updated_at: "2015-08-09 13:55:02", whenwhen: "2015-09-07 04:00:00", speaker_id: 1, map_address: "800 Rene Levesque, Montreal, H3G 5K4", lon: 0.0, lat: 0.0, price: 3550>} missing required keys: [:id]
The test in spec/views/events/index.html.erb_spec.rb:
require 'rails_helper'
RSpec.describe "events/index.html.erb", :type => :view do
let!(:speaker) { FactoryGirl.create(:speaker) }
let!(:events) { FactoryGirl.create_list(:event, 10, speaker_id: speaker.id ) }
it "should display all the events in a matrix" do
assign(:events, events)
render
puts response
end
end
I don't understand why if I have all the actions pointing to index, the error points to :action=>"show".
If I delete the two let statements or take the ! from them, the test passes and the headers and titles of the index page are displayed (with no events, of course).
The index.html.erb makes a call to helper functions to display the events in a matrix as follows:
<!-- app/views/events/index.html.erb -->
...
<% if Event.future.count == 0 %>
<br><%= t(:staytuned) %>
<% else %>
<h2><%= t(:futureevents).mb_chars.upcase %></h2>
<%= raw(display_matrix_events(Event.future)) %>
<% end %>
...
which is one of the code segments that should be called, as the factory is creating events in the future:
#spec/facories/event.rb
require 'faker'
FactoryGirl.define do
factory :event do
....
the_date { Faker::Date.forward(30) }
....
end
end
The code works fine when running on the browser.
Here is the stack trace:
Failures:
1) events/index.html.erb should display all the events in a matrix
Failure/Error: render
ActionView::Template::Error:
No route matches {:action=>"show", :controller=>"events", :format=>nil, :id=>nil, :locale=>#<Event id: 1, name: "Columbus Goodwin", description: "[\"Quam est officia adipisci.\", \"Molestiae cumque vo...", image: "event.jpg", location: nil, created_at: "2015-08-09 20:22:27", updated_at: "2015-08-09 20:22:27", whenwhen: "2015-09-08 04:00:00", speaker_id: 1, map_address: "800 Rene Levesque, Montreal, H3G 5K4", lon: 0.0, lat: 0.0, price: 3550>} missing required keys: [:id]
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_dispatch/journey/formatter.rb:39:in `generate'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_dispatch/routing/route_set.rb:595:in `generate'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_dispatch/routing/route_set.rb:625:in `generate'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_dispatch/routing/route_set.rb:661:in `url_for'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_dispatch/routing/url_for.rb:155:in `url_for'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/routing_url_for.rb:83:in `url_for'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/turbolinks-2.5.3/lib/turbolinks/xhr_url_for.rb:12:in `url_for_with_xhr_referer'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_dispatch/routing/route_set.rb:228:in `call'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_dispatch/routing/route_set.rb:268:in `block (2 levels) in define_url_helper'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_dispatch/routing/polymorphic_routes.rb:129:in `polymorphic_url'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_dispatch/routing/polymorphic_routes.rb:135:in `polymorphic_path'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/routing_url_for.rb:87:in `url_for'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/turbolinks-2.5.3/lib/turbolinks/xhr_url_for.rb:12:in `url_for_with_xhr_referer'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/helpers/url_helper.rb:180:in `link_to'
# ./app/views/events/_speaker_in_event_index.html.erb:6:in `_app_views_events__speaker_in_event_index_html_erb__148285862205269253_56219800'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/template.rb:143:in `block in render'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.4/lib/active_support/notifications.rb:159:in `block in instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.4/lib/active_support/notifications.rb:159:in `instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/template.rb:141:in `render'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/partial_renderer.rb:306:in `render_partial'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/partial_renderer.rb:279:in `block in render'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.4/lib/active_support/notifications.rb:159:in `block in instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.4/lib/active_support/notifications.rb:159:in `instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/partial_renderer.rb:278:in `render'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/renderer.rb:47:in `render_partial'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/helpers/rendering_helper.rb:27:in `render'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/test_case.rb:198:in `render'
# ./app/helpers/events_helper.rb:21:in `display_matrix_events'
# ./app/views/events/index.html.erb:18:in `_app_views_events_index_html_erb__3520103631403717635_53363480'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/template.rb:143:in `block in render'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.4/lib/active_support/notifications.rb:159:in `block in instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.4/lib/active_support/notifications.rb:159:in `instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/template.rb:141:in `render'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/template_renderer.rb:49:in `block (2 levels) in render_template'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.4/lib/active_support/notifications.rb:159:in `block in instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.4/lib/active_support/notifications.rb:159:in `instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/template_renderer.rb:48:in `block in render_template'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/template_renderer.rb:56:in `render_with_layout'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/template_renderer.rb:47:in `render_template'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/template_renderer.rb:17:in `render'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/renderer.rb:42:in `render_template'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/renderer/renderer.rb:23:in `render'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/helpers/rendering_helper.rb:24:in `render'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/test_case.rb:198:in `render'
# /home/mancilla/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.4/lib/action_view/test_case.rb:118:in `render'
# ./spec/views/events/index.html.erb_spec.rb:28:in `block (2 levels) in <top (required)>'
Finished in 2.11 seconds (files took 3.79 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/views/events/index.html.erb_spec.rb:10 # events/index.html.erb should display all the events in a matrix formation
The action index is executed correctly but it has a sequence of renders and method calls which lead to a show action.
The app/views/events/index.html.erb file has a call to a method which renders a partial containing the line
<%= link_to image_tag(e.speaker.image.to_s, width: '150%'), e %>
RSpec interprets e in the link_to as is (i.e. an event object) instead of using its id to build the actual link as Rails does.
Changing e to e.id throws the error:
undefined method `model_name' for Fixnum:Class
in both the browser and RSpec.
Deleting this line make the tests pass, but of course, gives the wrong output.

NameError - uninitialized constant error in rails 4

I have the following code in my "ProgramsController.rb " file where, Im using a class called "DataTableDelegate" which is in a separate file called: "datatable_delegate.rb"
# GET /programs
# GET /programs.json
def index
puts "Running Program/index"
puts "Model name = #{controller_name.classify}"
respond_to do |format|
format.html
#datatable_options = generate_datatable_hash(view_context, controller_name.classify, Program.data_table_attribute_array )
log_with_blue("============================================")
log_with_yellow("#{#datatable_options.inspect}")
log_with_blue("============================================")
>>>>>> format.json { render json: DataTableDelegate.new( #datatable_options) }
end
end
The file "datatable_delegate.rb" is located at
app/datatables/datatable_delegate.rb
When I load the Programs url in the browser I get the following in my log:
Completed 500 in 237ms
NameError - uninitialized constant ProgramsController::DataTableDelegate:
activesupport (4.0.0) lib/active_support/dependencies.rb:500:in `load_missing_constant'
activesupport (4.0.0) lib/active_support/dependencies.rb:183:in `const_missing'
app/controllers/programs_controller.rb:22:in `block (2 levels) in index'
actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:191:in `respond_to'
app/controllers/programs_controller.rb:13:in `index'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
......
I tried to put a require statement in my programs controller file but I still am getting the error.....
What should I do?
Thanks
You do not need the require statement in your ProgramsController as all files in the app/ directory are autoloaded by Rails.
The problem is the way you're accessing the DataTableDelegate. It is namespaced with Datatable, hence the placement of this file is in app/datatables/ directory.
Try with the following:
::Datatable::DatatableDelegate.new( #datatable_options)
Please note the case of characters in the module and class names above.
Rename your file to 'data_table_delegate.rb'. Also check whether the path app/datatables is in your autoload_paths.

using end as column name

I'm maintaining a rails 2.1 application that has some unfortunate choices for column names. For instance, an Event has a start and an end date. Instead of using start_at and end_at the original design uses start and end. Of course this leads to
def end
read_attribute(:end) || 1.hour.from_now
end
I'm surprised this even parses. Is this legal ruby? The real issue is that erb is blowing up with 'stack level too deep' when running a backgroundrb job to send the reminder emails. The template is
<%= [#event.name, #event.when_pretty, #event.location, #event.association,
#event.notes].reject(&:blank?) * "\n" %>
If I deliver_reminder in the console there is no error, but when deliver_reminder is called during the background job, the error occurs.
Question: should I refactor to remove the end method, or is the stack error being caused by something else?
On line #1 of foo/mailer/reminder.rhtml
1: <%= [#event.name, #event.when_pretty, #event.location, #event.association, #event.notes].reject(&:blank?) * "\n" %>
lib/virtual_attributes_and_associations.rb:59:in `virtual_attribute_names'
lib/virtual_attributes_and_associations.rb:83:in `read_attribute_without_virtual'
lib/virtual_attributes_and_associations.rb:86:in `read_attribute'
vendor/rails/activerecord/lib/active_record/base.rb:2720:in `send'
vendor/rails/activerecord/lib/active_record/base.rb:2720:in `clone_attribute_value'
vendor/rails/activerecord/lib/active_record/dirty.rb:127:in `write_attribute'
vendor/rails/activerecord/lib/active_record/attribute_methods.rb:211:in `data='
lib/virtual_attributes_and_associations.rb:9:in `included'
vendor/rails/activesupport/lib/active_support/callbacks.rb:177:in `call'
vendor/rails/activesupport/lib/active_support/callbacks.rb:177:in `evaluate_method'
vendor/rails/activesupport/lib/active_support/callbacks.rb:161:in `call'
vendor/rails/activesupport/lib/active_support/callbacks.rb:93:in `run'
vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `each'
vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `send'
vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `run'
vendor/rails/activesupport/lib/active_support/callbacks.rb:272:in `run_callbacks'
vendor/rails/activerecord/lib/active_record/callbacks.rb:298:in `callback'
vendor/rails/activerecord/lib/active_record/base.rb:1450:in `send'
vendor/rails/activerecord/lib/active_record/base.rb:1450:in `instantiate'
vendor/rails/activerecord/lib/active_record/base.rb:582:in `find_by_sql'
vendor/rails/activerecord/lib/active_record/base.rb:582:in `collect!'
vendor/rails/activerecord/lib/active_record/base.rb:582:in `find_by_sql'
vendor/rails/activerecord/lib/active_record/base.rb:1341:in `find_every'
vendor/rails/activerecord/lib/active_record/base.rb:1376:in `find_one'
vendor/rails/activerecord/lib/active_record/base.rb:1362:in `find_from_ids'
vendor/rails/activerecord/lib/active_record/base.rb:537:in `find'
vendor/rails/activerecord/lib/active_record/associations/belongs_to_association.rb:44:in `find_target'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:196:in `load_target'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:99:in `reload'
vendor/rails/activerecord/lib/active_record/associations.rb:1084:in `contact'
lib/association.rb:52:in `associated_object'
lib/association.rb:48:in `association'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:177:in `send'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:177:in `method_missing'
app/views/foo/mailer/reminder.rhtml:1:in `_run_erb_47app47views47foo47mailer47reminder46rhtml'
Turns out the issue was with a library method called association, when I changed that to call associated_object (which was called by Association#association), the stack error no longer occurred.

Resources