Why is the column_types method undefined in Rails 5.0?

I am assigning to a class and using the column_types method in the 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 on the command line.
Rails 5.0
Ubuntu 14.10

Error / 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)>'
+4
source share
4 answers

The method has been removed at this commit . Finding him is not so easy.

But the reason was not documented, because the method itself is not documented (perhaps this is for internal use only).

. :nodoc: , :

def column_types # :nodoc:
    @column_types ||= columns_hash.transform_values(&:cast_type).tap do |h|
      h.default = Type::Value.new
    end
  end

commit, , , , , - , .

, , attributes_types columns_hash .

+2

column_types Rails 5.

, :

User.column_for_attribute('username').type

, : :string

+3

5, column_types

+1

, _types

User.columns_hash.each_with_object({}) { |obj, h| h[obj[1].name] = obj[1].sql_type }
0

Source: https://habr.com/ru/post/1650279/


All Articles