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

Using a default value for decimal data types results in a failing mock class generated in 2.2.3 and a mock class syntax error in version 2.0.0 #81

Closed
jdcalvin opened this issue Aug 12, 2016 · 5 comments

Comments

@jdcalvin
Copy link

A table using a default value for a decimal column results in an error when building mock files. I tested this by creating a new rails app with the following schema:

create_table "test_data", force: :cascade do |t|
    t.datetime "created_at",                                                                         null: false
    t.datetime "updated_at",                                                                         null: false
    t.decimal  "decimal_default_neg",                        precision: 19, scale: 6, default: -1.0
    t.decimal  "decimal_default_pos",                        precision: 19, scale: 6, default: 1.0
    t.decimal  "decimal_no_default",                         precision: 19, scale: 6
    t.decimal  "decimal_no_precision_no_scale_with_default",                          default: 1.0
    t.integer  "integer_default_neg",                                                 default: -1
    t.integer  "integer_default_pos",                                                 default: 2
end

On active_mocker v 2.2.3, running rake_active_mocker:buildwith verbosity 3 results in the following: (full stack trace omitted)

TestDatum has the following errors:
unexpected token kEND
warn
unexpected token kEND
/Users/john/.rvm/gems/ruby-2.1.7/gems/parser-2.3.1.2/lib/parser/diagnostic/engine.rb:71:in `process'

Parser::SyntaxError
Error Summary
errors: 0, warn: 1, info: 0
Failed models: TestDatum
1 mock(s) out of 1 failed.

Downgrading to version 2.0.0 results in a successfully generated mock class. However, the #attributes method is partially commented out due to #<BigDecimal> being inserted as a value for decimal attributes, resulting in a syntax error.

def attributes
  @attributes ||= HashWithIndifferentAccess.new({"id"=>nil, "created_at"=>nil, "updated_at"=>nil, "decimal_default_neg"=>#<BigDecimal:7fde7db90ab0,'-0.1E1',9(18)>, "decimal_default_pos"=>#<BigDecimal:7fde7dbc3f50,'0.1E1',9(18)>, "decimal_no_default"=>nil, "decimal_no_precision_no_scale_with_default"=>#<BigDecimal:7fde7dbc32d0,'0.1E1',9(18)>, "integer_default_neg"=>-1, "integer_default_pos"=>2}).merge(super)
end

I'm trying to upgrade from 1.8.3, and the mock file generated will correctly show the value in this version:

def attributes
  @attributes ||= HashWithIndifferentAccess.new({"id"=>nil, "created_at"=>nil, "updated_at"=>nil, "decimal_default_neg"=>-1.0, "decimal_default_pos"=>1.0, "decimal_no_default"=>nil, "decimal_no_precision_no_scale_with_default"=>1.0, "integer_default_neg"=>-1, "integer_default_pos"=>2}).merge(super)
end
@zeisler
Copy link
Owner

zeisler commented Aug 12, 2016

Hey @jdcalvin nice to hear from you. I'll take a look at this.

@zeisler
Copy link
Owner

zeisler commented Aug 13, 2016

Fix merged with #82
Will release v2.2.4

@zeisler
Copy link
Owner

zeisler commented Aug 13, 2016

@zeisler zeisler closed this as completed Aug 13, 2016
@zeisler
Copy link
Owner

zeisler commented Aug 13, 2016

@jdcalvin Let me know if you have other issues and I try to address them ASAP. Also if you have any reasonable feature requests they'll be high priority.

@jdcalvin
Copy link
Author

Thanks Dustin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants