Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 4.2.0.beta2 #212

Closed
fmbiete opened this issue Oct 23, 2014 · 4 comments
Closed

Rails 4.2.0.beta2 #212

fmbiete opened this issue Oct 23, 2014 · 4 comments
Assignees
Labels
Milestone

Comments

@fmbiete
Copy link

fmbiete commented Oct 23, 2014

Upgrading to Rails 4.2.0.beta2 changes some already annotated models:

-#  size_pagination     :integer          default(20), not null
+#  size_pagination     :integer          default("20"), not null
-#  has_vpn             :boolean          default(FALSE)
+#  has_vpn             :boolean          default("f")

Only integer and boolean seems to change.

@ctran
Copy link
Owner

ctran commented Oct 23, 2014

Thanks for the heads-up. I'm not sure what needs to be done though.

@fmbiete
Copy link
Author

fmbiete commented Oct 24, 2014

I added this test to the spec/annotate/annotate_models_spec.rb

  it "should get schema info as boolean" do
    klass = mock_class(:users, :id, [
                                     mock_column(:id, :integer),
                                     mock_column(:size, :integer, :default => 20),
                                     mock_column(:flag, :boolean, :default => false)
                                    ])
    expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS)
# Schema Info
#
# Table name: users
#
#  id   :integer          not null, primary key
#  size :integer          default(20), not null
#  flag :boolean          default(FALSE), not null
#
EOS
  end

It will pass when using ActiveRecord 4.2.0.beta2

But this test will give you the wrong annotation:

Installs 'rails', '4.2.0.beta2'

rails new test_annotate
cd test_annotate

add gem 'annotate' to Gemfile

bundle
rails g active_record:model user size:integer flag:boolean

change the migration file, to add the default values

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.integer :size, :default => 20
      t.boolean :flag, :default => false

      t.timestamps null: false
    end
  end
end
bundle exec rake db:migrate
bundle exec annotate

And the app/model/user.rb will have wrongly annotated defaults

# == Schema Information
#
# Table name: users
#
#  id         :integer          not null, primary key
#  size       :integer          default("20")
#  flag       :boolean          default("f")
#  created_at :datetime         not null
#  updated_at :datetime         not null
#

class User < ActiveRecord::Base
end

Since the spec doesn't fails with the mock class, it would be safe to assume that the problem is within the code that "discover" the column type... Maybe that's changed into ActiveRecord 4.2.0

@JanStevens
Copy link

bump any update for rails 4.2? All our annotations changed (massive diff) just because of a rails upgrade. It would be nice to have a constant annotation independent of the rails version.

It seems that the column defaults are now all converted to string?

-#  config_properties :hstore           default({}), not null
+#  config_properties :hstore           default(""), not null

@ctran ctran added the feature label Jan 14, 2015
@ctran ctran added this to the v2.6.6 milestone Jan 14, 2015
@ctran ctran self-assigned this Jan 14, 2015
@CyborgMaster
Copy link
Contributor

I'm still getting this issue on rails 4.2.0.

My booleans changed as follows:

-#  disabled    :boolean          default(TRUE), not null
-#  simple      :boolean          default(FALSE), not null
+#  disabled    :boolean          default("1"), not null
+#  simple      :boolean          default("0"), not null

my integers like this:

-#  appt_email_done             :integer          default(0), not null
+#  appt_email_done             :integer          default("0"), not null

and my text fields like this:

-#  body            :text
+#  body            :text(65535)

It seems like default values are being converted to strings (or not converted back into their proper ruby types) before being added to the comment.

@ctran ctran added bug and removed feature labels Mar 8, 2015
@ctran ctran closed this as completed in 026cee5 Mar 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants