Giter Club home page Giter Club logo

enumerations_mixin's People

Contributors

protocool avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

enumerations_mixin's Issues

Does not work with FactoryGirl

My env:

  • Rails 3.1
  • Ruby 1.8.7

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'

Shoulda's matcher validate_uniqueness_of(:name) does not work

My env:

  • Rails 3.1
  • Ruby 1.8.7

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'

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.