protocool / enumerations_mixin Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
My env:
I have the next factory:
Factory.define :main_model do |f|
f.submodel { Submodel[:submodel_name] }
end
I have submodel with name = "submodel_name" created with seeds.
And I want Factory(:main_model)
to return a new saved instance of MainModel. But I get the next exception:
Failure/Error: @mm = Factory(:main_model)
NoMethodError:
undefined method `text?' for nil:NilClass
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activesupport-3.0.10/lib/active_support/whiny_nil.rb:48:in `method_missing'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activerecord-3.0.10/lib/active_record/validations/uniqueness.rb:66:in `mount_sql_and_params'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activerecord-3.0.10/lib/active_record/validations/uniqueness.rb:25:in `validate_each'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activemodel-3.0.10/lib/active_model/validator.rb:154:in `validate'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activemodel-3.0.10/lib/active_model/validator.rb:151:in `each'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activemodel-3.0.10/lib/active_model/validator.rb:151:in `validate'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activesupport-3.0.10/lib/active_support/callbacks.rb:315:in `send'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activesupport-3.0.10/lib/active_support/callbacks.rb:315:in `_callback_before_673'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activesupport-3.0.10/lib/active_support/callbacks.rb:425:in `_run_validate_callbacks'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activemodel-3.0.10/lib/active_model/validations.rb:212:in `run_validations!'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activemodel-3.0.10/lib/active_model/validations/callbacks.rb:67:in `run_validations!'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activesupport-3.0.10/lib/active_support/callbacks.rb:414:in `_run_validation_callbacks'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activemodel-3.0.10/lib/active_model/validations/callbacks.rb:67:in `run_validations!'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activemodel-3.0.10/lib/active_model/validations.rb:179:in `valid?'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activerecord-3.0.10/lib/active_record/validations.rb:55:in `valid?'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activerecord-3.0.10/lib/active_record/validations.rb:75:in `perform_validations'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activerecord-3.0.10/lib/active_record/validations.rb:49:in `save!'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activerecord-3.0.10/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activerecord-3.0.10/lib/active_record/transactions.rb:245:in `save!'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activerecord-3.0.10/lib/active_record/transactions.rb:292:in `with_transaction_returning_status'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activerecord-3.0.10/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activerecord-3.0.10/lib/active_record/transactions.rb:207:in `transaction'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activerecord-3.0.10/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/activerecord-3.0.10/lib/active_record/transactions.rb:245:in `save!'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/factory_girl-2.1.0/lib/factory_girl/proxy/create.rb:9:in `result'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/factory_girl-2.1.0/lib/factory_girl/factory.rb:116:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/factory_girl-2.1.0/lib/factory_girl/syntax/methods.rb:54:in `create'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/factory_girl-2.1.0/lib/factory_girl/syntax/vintage.rb:53:in `send'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/factory_girl-2.1.0/lib/factory_girl/syntax/vintage.rb:53:in `default_strategy'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/factory_girl-2.1.0/lib/factory_girl/syntax/vintage.rb:146:in `Factory'
# ./spec/models/main_model.rb:5
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/hooks.rb:35:in `instance_eval'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/hooks.rb:35:in `run_in'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/hooks.rb:74:in `run_all!'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/hooks.rb:122:in `run_hook!'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:207:in `eval_before_alls'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:261:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `map'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/reporter.rb:12:in `report'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:21:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:80:in `run_in_process'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:69:in `run'
My env:
I've got the next model:
class Submodel < ActiveRecord::Base
acts_as_enumerated :name_column => :code
validates :code, :presence => true, :uniqueness => true
validates :name, :presence => true, :uniqueness => true
end
I've got the next RSpec test:
describe Submodel
before(:all) do
Vehicle::Make.enumeration_model_updates_permitted = true
@make = Factory('vehicle/make')
end
it { should validate_presence_of :code }
it { should validate_uniqueness_of :code }
it { should validate_presence_of :name}
# NOTE: validation for :name column don't work when acts_as_enumerated is used
it { should validate_uniqueness_of :name}
end
When I run it I've got the 4th test failed (all other are passed):
1) Submodel validations
Failure/Error: it { should validate_uniqueness_of :name}
Expected errors to include "has already been taken" when name is set to "unique_string_5", got errors: code can't be blank (nil)name can't be blank (nil)
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-expectations-2.6.0/lib/rspec/expectations/fail_with.rb:29:in `fail_with'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-expectations-2.6.0/lib/rspec/expectations/handler.rb:21:in `handle_matcher'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-expectations-2.6.0/lib/rspec/expectations/extensions/kernel.rb:27:in `should'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/subject.rb:54:in `should'
# ./spec/models/submodel_spec.rb:29
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example.rb:48:in `instance_eval'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example.rb:48:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example.rb:107:in `with_around_hooks'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example.rb:45:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:294:in `run_examples'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:290:in `map'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:290:in `run_examples'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:262:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:263:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:263:in `map'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:263:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `map'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/reporter.rb:12:in `report'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:21:in `run'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:80:in `run_in_process'
# ~/.rvm/gems/ree-1.8.7-2011.03@gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:69:in `run'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.