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

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

Open
greyblake opened this issue Sep 15, 2011 · 3 comments
Open

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

greyblake opened this issue Sep 15, 2011 · 3 comments

Comments

@greyblake
Copy link

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'
@fourcolors
Copy link

I'm having a very simular issue: thoughtbot/shoulda-matchers#58

@greyblake
Copy link
Author

I switched to a supported fork (power_enum): https://github.com/albertosaurus/enumerations_mixin

@mjacobus
Copy link

mjacobus commented Oct 2, 2012

I have the same issue.

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

3 participants