You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I run the following spec in MRI everything works:
it { is_expected.to have_db_column(:example).of_type(:string) }
When I run it on JRuby 9.1.2 and with activerecord-jdbc-adapter (github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5') I get:
Expected Keyword to have db column named language_code of type string of limit 2 (FooBar has a db column named example of type #ActiveModel::Type::String:0x4c082a7d, not string.)
This seems to be the case for all types of attributes, not only strings. A possible workaround, i.e. comparing to ActiveModel::Type::String on JRuby, is not possible since were getting a instance instead of class when we call to_s i.e. ActiveModel::Type::String:0x4c082a7d.
That means shoulda-matchers will not be compatible with rails 5 on JRuby.
Found similar issues with have_db_column(:example).with_options(limit: 42) and enum_for matchers. I wrote the following monkeypatch to get my specs running again:
if RUBY_PLATFORM == 'java'
class Shoulda::Matchers::ActiveRecord::HaveDbColumnMatcher
protected
def correct_column_type?
return true unless @options.key?(:column_type)
if matched_column.type.class.to_s =~ /#{@options[:column_type].to_s}/i
true
else
@missing = "#{model_class} has a db column named #{@column} " <<
"of type #{matched_column.type.class.to_s} which did not match #{@options[:column_type]}."
false
end
end
def correct_limit?
return true unless @options.key?(:limit)
if matched_column.type.limit.to_s == @options[:limit].to_s
true
else
@missing = "#{model_class} has a db column named #{@column} " <<
"of limit #{matched_column.type.limit}, " <<
"not #{@options[:limit]}."
false
end
end
end
class Shoulda::Matchers::ActiveRecord::DefineEnumForMatcher
protected
def column_type_is_integer?
column.type.class.to_s =~ /Integer/
end
end
end
@wintersolutions Unfortunately, we don't officially support JRuby and haven't in quite some time. I'm not sure when this will be addressed, but I will keep this here in the meantime. Sorry I can't give you more :(
When I run the following spec in MRI everything works:
it { is_expected.to have_db_column(:example).of_type(:string) }
When I run it on JRuby 9.1.2 and with activerecord-jdbc-adapter (github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5') I get:
This seems to be the case for all types of attributes, not only strings. A possible workaround, i.e. comparing to
ActiveModel::Type::String
on JRuby, is not possible since were getting a instance instead of class when we callto_s
i.e. ActiveModel::Type::String:0x4c082a7d.That means
shoulda-matchers
will not be compatible with rails 5 on JRuby.Relevant line:
https://github.com/thoughtbot/shoulda-matchers/blob/v3.1.1/lib/shoulda/matchers/active_record/have_db_column_matcher.rb#L152
The text was updated successfully, but these errors were encountered: