Im doing an assignment for a class and it uses column_types method in a rspec test.
it "User database structure in place" do
expect(User.column_names).to include "password_digest", "username"
expect(User.column_types["username"].type).to eq :string
expect(User.column_types["password_digest"].type).to eq :string
expect(User.column_types["created_at"].type).to eq :datetime
expect(User.column_types["updated_at"].type).to eq :datetime
end
Error: when i run rpsec in the command line.
Rails 5.0
Ubuntu 14.10
Failure/Error: expect(User.column_types["username"].type).to eq :string
NoMethodError:
undefined method `column_types' for #<Class:0x000000053a0188>
Did you mean? columns
column_names
# ./spec/assignment_spec.rb:67:in `block (5 levels) in <top (required)>'
# ./spec/assignment_spec.rb:14:in `block (2 levels) in <top (required)>'
The method was removed in this commit. It's not so easy to find it.
But, the reason is was not documented, it's because the method itself is not documented (Maybe it's just for internal use).
See this comment :nodoc:
on the method when it existed:
def column_types # :nodoc:
@column_types ||= columns_hash.transform_values(&:cast_type).tap do |h|
h.default = Type::Value.new
end
end
You can read through the commit's description to understand the why and maybe see if there's something else you can do.
EDIT
Take a look at these lines maybe attributes_types
or columns_hash
can solve your problem.
The method column_types
is removed in Rails 5.
To get the type of column you can try following code:
User.column_for_attribute('username').type
This will return the type, here in your case: :string
looks like in rails 5, column_types
method no longer exist
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With