Error running Heckle? `current_code': undefined method `translate' for Ruby2Ruby - ruby-on-rails

I'm trying to run Heckle, and I keep getting an error:
> spec spec/controllers/my_controller_spec.rb --heckle MyController
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! exception= has a thick skin. There's nothing to heckle.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
(Runs through several mutations...)
/home/developer/.gem/ruby/1.8/gems/heckle-1.4.3/lib/heckle.rb:603:in `current_code': undefined method `translate' for Ruby2Ruby:Class (NoMethodError)
Any thoughts?
EDIT: I forgot the gem versions:
heckle (1.4.3)
ruby2ruby (1.2.3)
rails (2.3.2, 2.2.2)
rspec (1.2.6)
rspec-rails(1.2.6, 1.1.12)

Install ruby2ruby 1.2.2. There seems to be an API change in 1.2.3.
Just generated the docs for 1.2.2 and 1.2.3
Looks like the class method 'translate' has been totally removed, although the docs don't reflect this

Related

Why does Ruby 2.5.0 not show a stacktrace in Rails 5.1.4?

Here are two examples of the Rails server log for an error I encountered while only changing the Ruby version.
Ruby 2.4.2, Rails 5.1.4, Puma 3.11.0:
NoMethodError - undefined method `recent' for #<Event:0x00007f08507bf8b8>:
path/to/show.html.haml:50:in `block in _path_to_show_html_haml___4224769623360811234_28796540'
path/to/show.html.haml:30:in `_path_to_show_html_haml___4224769623360811234_28796540'
Ruby 2.5.0, Rails 5.1.4, Puma 3.11.0:
NoMethodError - undefined method `recent' for #<Event:0x00007f8ccc1b9508>:
What can I do to re-enable the stack trace in the Rails log? It doesn't look like there's a way to view which file/line number to look at.
To assist in investigating, I added this to my ApplicationController:
rescue_from Exception do |exception|
byebug
1+1
end
Ruby 2.4.2
(byebug) exception.backtrace
# A very large array of paths appears
Ruby 2.5.0
(byebug) exception.backtrace
nil
The binding_of_caller gem in the Gemfile was out of date. I upgraded from 0.7.3 to 0.8.0 and the problem went away.

Why does Rails / ActiveRecord gives a Postgres SyntaxError "non-integer constant in ORDER"?

I have some Ruby on Rails / ActiveRecord code that is giving me the following Postgres error:
PG::SyntaxError: ERROR: non-integer constant in ORDER
I'm not sure why since it is a simple fetch ordered by created_at
self.posts.order(created_at: :desc).limit(25)
What do I do to change this?
I am not sure that syntax is supported in older versions of Rails, which is where I suspect you are. Try this instead:
self.posts.order("created_at desc").limit(25)
I have experienced this error as well after switching my Rails app from MySQL to PostgreSQL (my development environment and Gem list are at the bottom of this post).
The error appears to be caused by PostgreSQL expecting the column names in a SQL query to be double-quoted, as I am able to eliminate the error by changing my ".order()" parameter from hash-format to a literal string:
This Rails code triggers the error:
ModelName.where(:attribute => self.id).order(col1: :desc, col2: :asc)
...and the resulting error:
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
ModelName Load (1.0ms) SELECT "model_name".* FROM "model_name" WHERE ("model_name"."attribute" = 14) ORDER BY '{:col1=>:desc, :col2=>:asc}'
PG::SyntaxError: ERROR: non-integer constant in ORDER BY
LINE 1: ...E ("model_name"."attribute" = 14) ORDER BY '{:col1=...
^
Whereas this Rails code works without triggering the error message:
ModelName.where(:attribute => self.id).order("\"col1\" desc, \"col2\" asc")
I know that PostgreSQL is able to correctly interpret non-quoted identifiers, but the format of the query that ActiveRecord generates in this case appears to be ambiguous to Postgresql. Here's a description of PostgreSQL query syntax: http://www.postgresql.org/docs/9.1/static/sql-syntax-lexical.html
Here's my development environment:
Windows 7
Ruby 2.1.5p273
Rails 3.0.3 (I know it's old...)
PostgreSQL 9.4 (on windows)
...and here's the pertinent part of my gem list:
*** LOCAL GEMS ***
abstract (1.0.0)
afm (0.2.2)
arel (2.0.10)
builder (2.1.2)
bundler (1.7.7)
hashery (2.1.1)
i18n (0.6.11)
mysql (2.9.1)
pg (0.18.1 x86-mingw32)
rack (1.2.8)
rails (3.0.3)
railties (3.0.3)
rake (0.9.2.2)
ruby-rc4 (0.1.5)
sequel (3.31.0)
valkyrie (0.0.2)

Sunspot_rails isn't respecting :auto_index and :auto_remove

I'm trying to make our application more resilient to downtime from our search server. To achieve this, I'm trying to disable the automatic indexing and removal, and manual perform them in a background process.
I'm trying
searchable :auto_index => false, :auto_remove => false do
...
end
But am still receiving a connection error, every time I try to save or destroy the record.
The backtrace shows that the error is coming from the solr searchable file, so it's definetly sunspot_rails causing the problem. Here is a slice from the backtrace on destroy:
...
rsolr (1.0.8) lib/rsolr/client.rb:67:in `update'
rsolr (1.0.8) lib/rsolr/client.rb:121:in `delete_by_id'
sunspot (1.3.3) lib/sunspot/indexer.rb:36:in `remove'
sunspot (1.3.3) lib/sunspot/session.rb:137:in `block in remove'
sunspot (1.3.3) lib/sunspot/session.rb:136:in `each'
sunspot (1.3.3) lib/sunspot/session.rb:136:in `remove'
sunspot (1.3.3) lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `remove'
sunspot (1.3.3) lib/sunspot.rb:410:in `remove'
sunspot_rails (1.3.3) lib/sunspot/rails/searchable.rb:390:in `solr_remove_from_index'
sunspot_rails (1.3.3) lib/sunspot/rails/searchable.rb:93:in `block in searchable'
...
Any idea why the options to disable these hooks aren't working? Any idea how to actually disable them?
Thanks
Found the answer to my own question:
Turns out that while automatic callbacks were disabled, I was still making it dirty in a different step. sunspot_rails has a cleanup step that runs at the end of a request and tries to commit all dirty records to the solr server. To disable it add auto_commit_after_request: false to your sunspot.yml.

Encoding Error when using Devise ldap authentication

I have been scouring the Internet for an answer to this but I'm out of ideas. I am using Devise with Rails 3 to authenticate with LDAP. I'm using Rails 3 with Ruby 1.9.2. I'm using mysql2 as the database connector.
I can get this to work with the rails console so I know my addresses and everything are correct.
We have an active directory and in order to authenticate we have to prefix the login name with systems. So my login would be systems\crudbasher.
This works in the console but when I have a form with login name and password I get this error.
Encoding::CompatibilityError in Devise::SessionsController#create
incompatible character encodings: ASCII-8BIT and UTF-8
Ok I get that it is having a problem with the backslash. What I don't understand is how to fix it.
The full stack trace if it helps is this:
net-ldap (0.2.2) lib/net/ber/core_ext/array.rb:62:in `to_ber_seq_internal'
net-ldap (0.2.2) lib/net/ber/core_ext/array.rb:54:in `to_ber_contextspecific'
net-ldap (0.2.2) lib/net/ldap/filter.rb:509:in `to_ber'
net-ldap (0.2.2) lib/net/ldap.rb:1380:in `block in search'
net-ldap (0.2.2) lib/net/ldap.rb:1361:in `loop'
net-ldap (0.2.2) lib/net/ldap.rb:1361:in `search'
net-ldap (0.2.2) lib/net/ldap.rb:635:in `search'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/ldap_adapter.rb:208:in `search_for_login'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/ldap_adapter.rb:86:in `dn'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/ldap_adapter.rb:124:in `authorized?'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/ldap_adapter.rb:14:in `valid_credentials?'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/model.rb:39:in `valid_ldap_authentication?'
activesupport (3.1.1) lib/active_support/core_ext/object/try.rb:32:in `try'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/model.rb:85:in `authenticate_with_ldap'
devise_ldap_authenticatable (0.6.0) lib/devise_ldap_authenticatable/strategy.rb:12:in `authenticate!'
I'm really stumped. Thank you to anyone who can help!!
Encoding is always a mess. Have you tried toying around with encode and force_encoding?
I had this same problem and I fixed by updating net-ldap library to 0.3.1, but that broke mine get_ldap_email (which is just like devise_ldap_authenticatable main page example, Querying LDAP)
Also everything seemed to be ok but I'm not 100% sure if nothing else is broken.
Edit: Apparently I also need to update devise_ldap_authenticatable to version 0.4.7 or higher -> Ruby on Rails 3: Devise::LdapAdapter.get_ldap_param undefined method error
But I'm not sure how to update both, devise_ldap and net-ldap, and not breaking my bundle update

undefined local variable or method `acts_as_taggable' in gem

I'm working on converting a plugin to a gem. In one of the models I'm using acts_as_taggable_on, and it looks like this
class BlogPost < ActiveRecord::Base
acts_as_taggable
....
end
However, I get this error when I run it:
undefined local variable or method `acts_as_taggable' for #<Class:0x000000060799b8>
and the stack trace looks like this:
activerecord (3.1.0) lib/active_record/base.rb:1082:in `method_missing'
test_gem (0.1.0) app/models/blog_post.rb:28:in `<class:BlogPost>'
test_gem (0.1.0) app/models/blog_post.rb:2:in `<top (required)>'
The acts_as_taggable gem is included in my gemspec file and is installed on the system.
gem install acts-as-taggable-on
Successfully installed acts-as-taggable-on-2.1.1
1 gem installed
Installing ri documentation for acts-as-taggable-on-2.1.1...
Installing RDoc documentation for acts-as-taggable-on-2.1.1...
I have no idea what could be wrong - please help me out
I had the same issue. I restarted my server and it worked fine after
none of above answers works for me, what I did was put :
require 'acts-as-taggable-on'
in the beginning the model where I'm using the gem :)
Have you put the following in you Gemfile:
gem 'acts-as-taggable-on', '~>2.1.0'
then
bundle install

Resources