GithubHelp home page GithubHelp logo

melekes / valle Goto Github PK

View Code? Open in Web Editor NEW
104.0 25.0 8.0 107 KB

[MAINTAINERS WANTED] Built-in limit validations for your ActiveRecord model

License: MIT License

Ruby 74.46% Makefile 0.83% Gherkin 24.71%
activerecord activerecord-model validations

valle's Introduction

Valle Build Status Code Climate Gem Version

Valle automatically creates validations for the minimum and maximum values of fields in your ActiveRecord model(s). No more worrying that string lengths or ID values will exceed the permissible DB limits!

For example, the maximum length of the string type in PostgreSQL is 255. Valle creates the following validator for you, so you no longer need to write it by hand:

validates :field_name, length: { maximum: 255 }

Note: If you do not do this (and usually you are) and try to enter 2147483648 into a field of type integer (see the Numeric types section of PostgreSQL docs), you will get a 500 error.

Example:

PG::Error: ERROR:  value "2147483648" is out of range for type integer
: SELECT  "users".* FROM "users"  WHERE "users"."id" = $1 LIMIT 1

Supported ActiveRecord field types

  • :primary_key
  • :integer
  • :string
  • :text

Installation

Add this line to your application's Gemfile:

gem 'valle'

And then execute:

$ bundle

Or install it yourself:

$ gem install valle

If you are using other framework than Rails (e.g. Sinatra), call Valle::Hooks.init method during the boot process.

Usage

By default, this gem adds validators to all your ActiveRecord models. If that is the behavior you want, you don't need to tweak it.

However, you can skip some of them by adding the file config/initializers/valle.rb containing:

Valle.configure do |config|
  config.exclude_models = %w(Post)
end

Also, you can disable it temporarily by setting the enabled configuration option to false.

Valle.configure do |config|
  config.enabled = false
end

Disabling Valle on specific attributes

There are cases where you need to skip validation for a particular attribute (see #4). For example, CarrierWave stores images temporarily in attributes, so calling save on them will fail because of its LengthValidator (255 characters maximum). You can disable Valle for such fields using the exclude_attributes configuration option:

Valle.configure do |config|
  config.exclude_attributes = {
    'User' => %w(image)
  }
end

Alternatives

There is a similar gem, called validates_lengths_from_database. It solves only one part of the problem — applicable to strings. Valle, however, is designed to work with all possible field types.

Developing

Docker container

If you have docker installed on your machine, you can spin up a sandbox and run test suite in a few seconds:

$ docker build -t valle .
$ docker run -it --rm -v "$PWD":/usr/src/lib valle bundle exec rake

Or simply use Makefile commands:

$ make docker_build
$ make docker_test

Debugging Cucumber tests

Uncomment @announce-output tag at the top of the .feature file.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Run test suite (rake test_suite)
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

Credits

Original authors:

Thank you to all our amazing contributors!

License

Valle is released under the MIT License.

valle's People

Contributors

akirill0v avatar andrew8xx8 avatar asiniy avatar marcusg avatar melekes avatar mokevnin avatar oddlyzen avatar oliverklee avatar plugin73 avatar qblake avatar radanisk avatar zzet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

valle's Issues

incorrect work with carrierwave

[8/17/14, 11:24:46 PM] Kirill Mokevnin: LessonVersionImporterTest#test_#import_lesson_with_missing_file:
ActiveRecord::RecordInvalid: Возникли ошибки: Tarball слишком большой длины (не может быть больше чем 255 символов)
[8/17/14, 11:24:56 PM] Kirill Mokevnin: 7 tarball { fixture_file_upload("example_lesson.tar.gz") }

Cucumber tests are failing

Currently (with today's latest master), the cucumber tests are failing on my machine:

klee@gonzales:~/src/ruby/valle$ bundle exec rake
/home/klee/.rvm/rubies/ruby-2.3.1/bin/ruby -w -I"lib:test" -I"/home/klee/.rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib" "/home/klee/.rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/rake_test_loader.rb" "test/lib/abstract_adapter/character_limited_column_test.rb" "test/lib/abstract_adapter/column_wrapper_test.rb" 

# Running tests with run options --seed 27866:

.....

Finished tests in 0.002080s, 2404.3779 tests/s, 2404.3779 assertions/s.


5 tests, 5 assertions, 0 failures, 0 errors, 0 skips
/home/klee/.rvm/rubies/ruby-2.3.1/bin/ruby -S bundle exec cucumber --format progress
.....F-----.....F--------.....F-----....F-----

(::) failed steps (::)

expected "bundle exec rails g model User name:string" to be successfully executed (RSpec::Expectations::ExpectationNotMetError)
features/configuration.feature:11:in `And I successfully run `bundle exec rails g model User name:string`'

expected "bundle exec rails g model User name:string" to be successfully executed (RSpec::Expectations::ExpectationNotMetError)
features/configuration.feature:11:in `And I successfully run `bundle exec rails g model User name:string`'

expected "bundle exec rails g model User name:string" to be successfully executed (RSpec::Expectations::ExpectationNotMetError)
features/configuration.feature:11:in `And I successfully run `bundle exec rails g model User name:string`'

expected "bundle install" to be successfully executed (RSpec::Expectations::ExpectationNotMetError)
features/sets_validations.feature:7:in `And I successfully run `bundle install`'

Failing Scenarios:
cucumber features/configuration.feature:14 # Scenario: Setting enabled option to false disable Valle
cucumber features/configuration.feature:39 # Scenario: Using the exclude_models option should skip the models specified in the list
cucumber features/configuration.feature:80 # Scenario: Using exclude_attributes option should allow us to skip some attributes
cucumber features/sets_validations.feature:12 # Scenario: Using Valle automatically sets validations

4 scenarios (4 failed)
46 steps (4 failed, 23 skipped, 19 passed)
0m10.387s

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

  spec.license = 'MIT'
  # or
  spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Ошибка, если есть модели с нестандартным именем таблицы

Например, есть такая модель

module Doorkeeper
  class AccessGrant < ActiveRecord::Base
    self.table_name = :oauth_access_grants
  end
end

при загрузке приложения возникает ошибка

Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1158:in async_exec': PG::Error: ERROR: relation "access_grants" does not exist (ActiveRecord::StatementInvalid) LINE 4: WHERE a.attrelid = '"access_grants"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"access_grants"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1158:inexec_no_cache'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:664:in block in exec_query' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:280:inblock in log'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in instrument' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:275:inlog'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:663:in exec_query' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1283:incolumn_definitions'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:859:in columns' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/schema_cache.rb:12:inblock in initialize'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in yield' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:indefault'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in columns' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/bundler/gems/valle-f85bc6a06f92/lib/valle/bounds_manager.rb:12:inadd_validators'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/bundler/gems/valle-f85bc6a06f92/lib/valle/hooks.rb:13:in inherited_with_valle_validators' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/doorkeeper-0.5.0/lib/doorkeeper/models/active_record/access_grant.rb:2:inmodule:Doorkeeper'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/doorkeeper-0.5.0/lib/doorkeeper/models/active_record/access_grant.rb:1:in <top (required)>' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/backports-2.6.5/lib/backports/tools.rb:314:inrequire'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/backports-2.6.5/lib/backports/tools.rb:314:in require_with_backports' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:inblock in require'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in load_dependency' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:inrequire'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/doorkeeper-0.5.0/lib/doorkeeper/config.rb:13:in enable_orm' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/doorkeeper-0.5.0/lib/doorkeeper/config.rb:4:inconfigure'
from /Users/SomeUser/SomeProject/config/initializers/doorkeeper.rb:1:in <top (required)>' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:inload'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in block in load' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:inload_dependency'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in load' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/engine.rb:588:inblock (2 levels) in class:Engine'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/engine.rb:587:in each' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/engine.rb:587:inblock in class:Engine'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:30:in instance_exec' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:30:inrun'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:55:in block in run_initializers' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:54:ineach'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:54:in run_initializers' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application.rb:136:ininitialize!'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in method_missing' from /Users/SomeUser/SomeProject/config/environment.rb:5:in<top (required)>'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/backports-2.6.5/lib/backports/tools.rb:314:in require' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/backports-2.6.5/lib/backports/tools.rb:314:inrequire_with_backports'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in block in require' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:inload_dependency'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in require' from /Users/SomeUser/SomeProject/config.ru:4:inblock in

'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in instance_eval' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:ininitialize'
from /Users/SomeUser/SomeProject/config.ru:1:in new' from /Users/SomeUser/SomeProject/config.ru:1:in'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:40:in eval' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:40:inparse_file'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:200:in app' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/server.rb:46:inapp'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:301:in wrapped_app' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:252:instart'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/server.rb:70:in start' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:55:inblock in <top (required)>'
from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:50:in tap' from /Users/SomeUser/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:50:in<top (required)>'
from script/rails:6:in require' from script/rails:6:in'

has_and_belongs_to_many causes Model to crash on initialization

We have a model like this:

class Tag < ActiveRecord::Base
has_and_belongs_to_many :offerers

If I instantiate this model in a spec using Tag.new, I get the following crash when running rspec:

galadriel:justworkshops klee$ bin/rspec spec/models/tag_spec.rb
/Users/klee/.rvm/gems/ruby-2.1.2/gems/activemodel-4.1.4/lib/active_model/naming.rb:148:in `initialize': Class name cannot be blank. You need to supply a name argument when anonymous class given (ArgumentError)

В development-е работает, а в production нет.

Один и тот-же код в developmеnt-е нормально ловит валидацию на длину строки. А в продавшее нет. И там и там postgresql. Может есть секретик какой?

not work for integer

Hi! I am add valle with default config, not set any options.
Then i use my model Realty and do next commands in rails console

r = Realty.last
r.lot = 123123123123123
r.save

and get

ActiveRecord::StatementInvalid: PG::Error: ERROR:  integer out of range
: UPDATE "realty" SET "lot" = 123123123123123, "updated_at" = '2015-05-28 15:13:16.308810' WHERE "realty"."id" = 1028
from /home/vagrant/.rvm/gems/ruby-2.1.5/gems/activerecord-3.2.21/lib/active_record/connection_adapters/postgresql_adapter.rb:1163:in `exec'

But other valle validations are work (string for example)

r.legacy_geo = "a" * 300
r.valid? => false
r.errors.messages
=> {:legacy_geo=>
  ["слишком большой длины (не может быть больше чем 255 символов)"]

lot - integer, legacy_geo - string

create_table "realty", :force => true do |t|
    t.integer  "lot",  :null => false
    t.string   "legacy_geo"
end

Rails 3.2.21
What i am doing wrong?

Breaking migration for schema

Using valle breaks my rake db:migrate:reset command. When I remove the gem, everything is fine. Any ideas? Here is the stacktrace:

rake db:migrate:reset
==  DeviseCreateUsers: migrating ==============================================
-- create_table(:users)
   -> 0.0390s
-- add_index(:users, :email, {:unique=>true})
   -> 0.0081s
-- add_index(:users, :reset_password_token, {:unique=>true})
   -> 0.0082s
==  DeviseCreateUsers: migrated (0.0558s) =====================================

rake aborted!
An error has occurred, this and all later migrations canceled:

PG::UndefinedColumn: ERROR:  column "id" does not exist
LINE 1: ...O "schema_migrations" ("version") VALUES ($1) RETURNING "id"
                                                                   ^
: INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "id"/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:817:in `prepare'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:817:in `prepare_statement'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:778:in `exec_cache'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:139:in `block in exec_query'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activesupport-4.0.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:184:in `exec_insert'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:96:in `insert'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/relation.rb:76:in `insert'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/persistence.rb:509:in `create_record'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/attribute_methods/dirty.rb:78:in `create_record'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/callbacks.rb:306:in `block in create_record'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activesupport-4.0.1/lib/active_support/callbacks.rb:373:in `_run__1271211780199784139__create__callbacks'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activesupport-4.0.1/lib/active_support/callbacks.rb:80:in `run_callbacks'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/callbacks.rb:306:in `create_record'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/timestamp.rb:57:in `create_record'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/persistence.rb:477:in `create_or_update'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/callbacks.rb:302:in `block in create_or_update'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activesupport-4.0.1/lib/active_support/callbacks.rb:373:in `_run__1271211780199784139__save__callbacks'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activesupport-4.0.1/lib/active_support/callbacks.rb:80:in `run_callbacks'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/callbacks.rb:302:in `create_or_update'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/persistence.rb:128:in `save!'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/validations.rb:57:in `save!'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/attribute_methods/dirty.rb:41:in `save!'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/transactions.rb:275:in `block in save!'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:200:in `transaction'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/transactions.rb:209:in `transaction'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/transactions.rb:275:in `save!'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/validations.rb:41:in `create!'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/migration.rb:990:in `record_version_state_after_migrating'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/migration.rb:960:in `block in execute_migration_in_transaction'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/migration.rb:1005:in `block in ddl_transaction'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/transactions.rb:209:in `transaction'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/migration.rb:1005:in `ddl_transaction'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/migration.rb:958:in `execute_migration_in_transaction'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/migration.rb:920:in `block in migrate'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/migration.rb:916:in `each'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/migration.rb:916:in `migrate'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/migration.rb:764:in `up'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/migration.rb:742:in `migrate'
/home/marcus/.rvm/gems/ruby-2.0.0-p247@onecolor/gems/activerecord-4.0.1/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate:reset => db:migrate
(See full trace by running task with --trace)

Automatic table names are broken in Rails 5

When using the ApplicationRecord class that was introduced in Rails 5, the automatic table names are broken.

About the ApplicationRecord class:
http://blog.bigbinary.com/2015/12/28/application-record-in-rails-5.html

A new Rails application without valle and with a simple Book model (that has just a "title" attribute) works like this:

klee@gonzales:~/src/ruby/rails-new$ bin/rails c
Running via Spring preloader in process 16671
Loading development environment (Rails 5.0.0.1)
2.3.1 :001 > Book.table_name
 => "books" 

After adding valle to the Gemfile, the output looks like this:

klee@gonzales:~/src/ruby/rails-new$ bin/rails c
Running via Spring preloader in process 16814
Loading development environment (Rails 5.0.0.1)
2.3.1 :001 > Book.table_name
 => "application_records" 

My educated guess is that valle needs to add its methods to the ApplicationRecord class instead of the ActiveRecord::Base class for Rails 5.

Didn't work for serialized field

We have a model that uses a serialized attribute

serialize :toggled_modules, Array

valle did not seem to catch that the serialized field was being blown.

Can't access Model.attribute_names in valle initializer

I use carrierwave, so I have to exclude the image column from valle. I tried to access the model attributes via User.attribute_names and assign these to valle. But that won't work, I have to manually assign the values - what is not what I want, since the array have to be changed when the model attributes change.

config.attributes = {
  'Model' => ["id", "email", ...]
}

Is it possible to dynamically get all attributes and assign (a changed) array to valle like the following code shows?

config.attributes = {
  'User' => Model.attribute_names
}

carrierwave support

class Person < ActiveRecord::Base  
  mount_uploader :photo, PersonUploader  #iphoto of type string in db
end
...
@attrs = attributes_for :person #FactoryGirl
puts @attrs[:photo] #=> #<Rack::Test::UploadedFile:0x00000005a73c30>
puts @attrs[:photo].length #=> 9759

I have validtion error because 9759 > string length(255).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.