Getting undefined method `to_sym' from FactoryGirl create - ruby-on-rails

I have a simple spec:
describe Setting do
subject { create(:setting) }
it { should be_valid }
end
with the factory:
FactoryGirl.define do
factory :setting do
key "some_key"
value "The appropriate value"
end
end
When I run the spec:
rake spec SPEC=spec/models/setting_spec.rb
I get the following error:
1) Setting should be valid
Failure/Error: it { should be_valid }
NoMethodError:
undefined method `to_sym' for nil:NilClass
# ./spec/models/setting_spec.rb:6:in `block (2 levels) in <top (required)>'
I tried using a let(:setting) in place of the subject line and got the same error.
EDIT Per comments:
The error refers to the line it { should be_valid }
The model is:
class Setting < ActiveRecord::Base
attr_accessor :key, :value
validates_uniqueness_of :key
end
Here's the trace:
# /var/lib/gems/1.9.1/gems/activerecord-3.2.16/lib/active_record/validations/uniqueness.rb:26:in `validate_each'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validator.rb:153:in `block in validate'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validator.rb:150:in `each'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validator.rb:150:in `validate'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:310:in `_callback_before_1986'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:407:in `_run__3464288744618424855__validate__1974049388273351148__callbacks'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `__run_callback'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:385:in `_run_validate_callbacks'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validations.rb:228:in `run_validations!'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:403:in `_run__3464288744618424855__validation__1974049388273351148__callbacks'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `__run_callback'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validations.rb:195:in `valid?'
# /var/lib/gems/1.9.1/gems/activerecord-3.2.16/lib/active_record/validations.rb:69:in `valid?'
# /var/lib/gems/1.9.1/gems/rspec-expectations-2.14.5/lib/rspec/expectations/handler.rb:24:in `handle_matcher'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/memoized_helpers.rb:68:in `should'
# ./spec/models/setting_spec.rb:6:in `block (2 levels) in <top (required)>'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:114:in `instance_eval'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:114:in `block in run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:254:in `with_around_each_hooks'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:111:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:390:in `block in run_examples'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:386:in `map'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:386:in `run_examples'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:371:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `map'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `block in run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/reporter.rb:58:in `report'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:25:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:77:in `rescue in run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:73:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'
spec_helper.rb: http://pastebin.com/6fzDXnux

The direct cause for this error is that the class derives from ActiveRecord::Base, and ActiveRecord can't determine the primary key (required by AR for validating uniqueness). Most likely, this is happening either because you haven't run migrations to create the settings table, or you created the settings table without a primary key.
The offending line (based on the backtrace provided):
relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.send(:id))) if record.persisted?
Note that to_sym is being called on finder_class.primary_key.

you can also solve same by adding below line in your model.
self.primary_key = 'id'
e.g.
Class Person
self.primary_key = 'id'
end

Related

Unidirectional Relation failing with Factory Girl `can't write unknown attribute`

I have a model Event
class Event < ActiveRecord::Base
belongs_to :approved_by, class_name: 'User', foreign_key: 'approved_by'
end
And a model User which does not care about the reverse relation
class User < ActiveRecord::Base
include Authenticatable
end
With a Event factory like so:
FactoryGirl.define do
factory :event do
title "MyString"
description "...snip..."
start_time "2017-06-26 15:31:55"
end_time "2017-06-26 15:31:55"
venue "MyPlace"
status :active
approved_by { build :user }
trait :pending do
status :pending
approved_by nil
end
trait :active do
#no-op
end
end
end
When I try to assert that they factory works as intended, like so...
RSpec.describe Event, type: :model do
describe 'sanity checks' do
it { expect(build :event).to be_valid }
it { expect(create :event).to be_persisted }
end
end
I get the following errors:
```
drew$ rspec -b spec/models/event_spec.rb
FF
Failures:
1) Event sanity checks
Failure/Error: it { expect(build :event).to be_valid }
ActiveModel::MissingAttributeError:
can't write unknown attribute `approved_by`
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute.rb:138:in `with_value_from_database'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_set.rb:39:in `write_from_user'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods/write.rb:74:in `write_attribute_with_type_cast'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods/write.rb:56:in `write_attribute'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods/dirty.rb:96:in `write_attribute'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods.rb:373:in `[]='
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/belongs_to_association.rb:83:in `replace_keys'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/belongs_to_association.rb:14:in `replace'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/singular_association.rb:17:in `writer'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/builder/association.rb:123:in `approved_by='
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:16:in `public_send'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:16:in `block (2 levels) in object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:15:in `each'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:15:in `block in object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:14:in `tap'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:14:in `object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/evaluation.rb:12:in `object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/strategy/build.rb:9:in `result'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/factory.rb:42:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:29:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activesupport-4.2.5/lib/active_support/notifications.rb:166:in `instrument'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:28:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
# ./spec/models/event_spec.rb:5:in `block (3 levels) in <top (required)>'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:254:in `instance_exec'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:254:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:496:in `block in with_around_and_singleton_context_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:453:in `block in with_around_example_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:464:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:604:in `block in run_around_example_hooks_for'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-rails-3.5.2/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:375:in `execute_with'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:607:in `run_around_example_hooks_for'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:464:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:453:in `with_around_example_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:496:in `with_around_and_singleton_context_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:251:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:627:in `block in run_examples'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:623:in `map'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:623:in `run_examples'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:589:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `map'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `block (3 levels) in run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `map'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `block (2 levels) in run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1835:in `with_suite_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/reporter.rb:77:in `report'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:111:in `run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:87:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/exe/rspec:4:in `<top (required)>'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/rspec:23:in `load'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/rspec:23:in `<main>'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/ruby_executable_hooks:15:in `eval'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/ruby_executable_hooks:15:in `<main>'
2) Event sanity checks
Failure/Error: it { expect(create :event).to be_persisted }
ActiveModel::MissingAttributeError:
can't write unknown attribute `approved_by`
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute.rb:138:in `with_value_from_database'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_set.rb:39:in `write_from_user'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods/write.rb:74:in `write_attribute_with_type_cast'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods/write.rb:56:in `write_attribute'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods/dirty.rb:96:in `write_attribute'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods.rb:373:in `[]='
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/belongs_to_association.rb:83:in `replace_keys'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/belongs_to_association.rb:14:in `replace'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/singular_association.rb:17:in `writer'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/builder/association.rb:123:in `approved_by='
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:16:in `public_send'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:16:in `block (2 levels) in object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:15:in `each'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:15:in `block in object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:14:in `tap'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:14:in `object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/evaluation.rb:12:in `object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/strategy/create.rb:9:in `result'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/factory.rb:42:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:29:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activesupport-4.2.5/lib/active_support/notifications.rb:166:in `instrument'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:28:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
# ./spec/models/event_spec.rb:6:in `block (3 levels) in <top (required)>'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:254:in `instance_exec'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:254:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:496:in `block in with_around_and_singleton_context_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:453:in `block in with_around_example_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:464:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:604:in `block in run_around_example_hooks_for'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-rails-3.5.2/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:375:in `execute_with'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:607:in `run_around_example_hooks_for'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:464:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:453:in `with_around_example_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:496:in `with_around_and_singleton_context_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:251:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:627:in `block in run_examples'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:623:in `map'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:623:in `run_examples'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:589:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `map'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `block (3 levels) in run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `map'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `block (2 levels) in run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1835:in `with_suite_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/reporter.rb:77:in `report'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:111:in `run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:87:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/exe/rspec:4:in `<top (required)>'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/rspec:23:in `load'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/rspec:23:in `<main>'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/ruby_executable_hooks:15:in `eval'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/ruby_executable_hooks:15:in `<main>'
Finished in 0.75142 seconds (files took 2.6 seconds to load)
2 examples, 2 failures
Failed examples:
rspec ./spec/models/event_spec.rb:5 # Event sanity checks
rspec ./spec/models/event_spec.rb:6 # Event sanity checks
```
However when I try this via console it works fine...
[4] pry(main)> e = FactoryGirl.build(:event)
=> #<Event:0x007fe5ef1643d8
id: nil,
title: "MyString",
description:
"..snip..",
start_time: Mon, 26 Jun 2017 15:31:55 UTC +00:00,
end_time: Mon, 26 Jun 2017 15:31:55 UTC +00:00,
venue: "MyPlace",
main_image_cloudinary_id: nil,
status: 1,
approved_by: nil,
created_at: nil,
updated_at: nil>
[5] pry(main)> e.approved_by
=> #<User:0x007fe5ef157340
id: nil,
name: "Luther Johnston",
email: "guadalupe#brakus.com",
password_hash: "...snip...",
authentication_token: "...snip...",
activation_token: nil,
activation_date: Tue, 27 Jun 2017 00:00:00 UTC +00:00,
reset_password_token: nil,
created_at: nil,
updated_at: nil>
Since I rubber ducked myself about 2 seconds after hitting the post button, I'll go ahead and answer it.
My test database and development database were out of sync.
Running rake db:test:prepare solved the issue.

Why are my view specs behaving inconsistently?

I'm getting some strange results from view specs
Failure/Error: assert_select "div.fileinput-new.thumbnail"
ArgumentError:
wrong number of arguments (3 for 1)
Ok, so this seems self explanatory (though I'm not sure what are the 3 arguments referenced).
However, if I run the suite again, I might get 0 errors. And the next, 5 errors, of the same type as above but referencing different DOM elements.
There is nothing fancy in any of these specs
describe do
build :object / create :object
#object = assign(:object, object )
it 'displays the DOM elements' do
render
asset_select #DOM_elements
end
end
What could cause this kind of inconsistent coverage of view specs?
An example stack trace
Failure/Error: assert_select "div.fileinput-new.thumbnail"
ArgumentError:
wrong number of arguments (3 for 1)
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/actionview-4.2.6/lib/action_view/helpers/text_helper.rb:52:in `concat'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:165:in `evaluate'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:165:in `block in xpath'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:156:in `map'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:156:in `xpath'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:193:in `css_internal'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:76:in `block in css'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:187:in `block in each'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:186:in `upto'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:186:in `each'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:75:in `inject'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:75:in `css'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions/html_selector.rb:20:in `select'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `assert_select'
# ./spec/views/users/settings/profile.html.erb_spec.rb:24:in `block (4 levels) in <top (required)>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:295:in `nest_selection'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:177:in `block in assert_select'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `tap'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `assert_select'
# ./spec/views/users/settings/profile.html.erb_spec.rb:22:in `block (3 levels) in <top (required)>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:236:in `instance_exec'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:236:in `block in run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:478:in `block in with_around_and_singleton_context_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:435:in `block in with_around_example_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:478:in `block in run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:618:in `block in run_around_example_hooks_for'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:320:in `call'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:320:in `call'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-rails-3.4.2/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:425:in `instance_exec'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:425:in `instance_exec'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:389:in `execute_with'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:620:in `block (2 levels) in run_around_example_hooks_for'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:320:in `call'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:320:in `call'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:621:in `run_around_example_hooks_for'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:478:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:435:in `with_around_example_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:478:in `with_around_and_singleton_context_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:233:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:581:in `block in run_examples'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:577:in `map'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:577:in `run_examples'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:543:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:544:in `block in run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:544:in `map'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:544:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:119:in `block (3 levels) in run_specs'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:119:in `map'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:119:in `block (2 levels) in run_specs'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1680:in `with_suite_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:118:in `block in run_specs'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/reporter.rb:77:in `report'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:117:in `run_specs'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:93:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/bin/rspec:23:in `load'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/bin/rspec:23:in `<main>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/bin/ruby_executable_hooks:15:in `eval'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/bin/ruby_executable_hooks:15:in `<main>'
This is not a definitive answer: it appears that, for some weird reason, the evaluate method in the Nokogiri's Searchable module considers the concat() function as a custom XPath function instead of the internal XPath function.
External XPath functions are called as normal ruby methods in the context of the handler attribute of evaluate. Normally the handler is the SubstitutionContext class but in your case it seems that sometimes this gets the context of the TextHelper module where the concat method is defined, accepting just 1 parameter (whereas the XPath's concat() function accepts any number of parameters). I think that this can lead to the errors you observe.
Could you open the searchable.rb file (see the stack trace for its location) on this line and add before it some debug messages to inspect the contents of the following variables?
puts "ctx #{ctx.inspect}"
puts "path #{path.inspect}"
puts "handler #{handler.inspect}"
if handler.respond_to?(:concat)
puts "concat #{handler.method(:concat).inspect}"
else
puts "not responding to :concat"
end
Then, can you provide the output printed for one of the failing tests?
Update: the output showed that indeed the tests context was being polluted by the ActionView::TextHelpers module and in the end it turned out that there was a ActionView::Helpers module included in a model used in the tests.

FactoryGirl::create throwing NoMethodError: undefined method `stringify_keys'

I have the follwing in my factories.rb:
factory :ffsupervisor, class: Supervisor do
first_name "ffsupervisor"
email "ffsupervisor#abc.com"
password "123456"
type "Supervisor"
association :agency, name: "FFAgency", full_fee: "2.0", partial_fee: "1.0", agency_type: "Fulfilment"
end
I'm able to build and save an instance of Supervisor in my DB with FactoryGirl::create(:ffsupervisor) in the Rails Console. When I try to do the same thing in my feature specs, I end up getting:
NoMethodError: undefined method `stringify_keys'.
I've looked into a lot of questions in SO regarding this issue. Haven't been able to figure out what I'm missing out though. Any heads up on this would be great. TIA!
EDIT:
This is the stack trace I'm getting:
1) Workflow order_item lifecycle.
Failure/Error: #supervisor= FactoryGirl::create(:ffsupervisor) # Creates both agency & supervisor.
NoMethodError:
undefined method `stringify_keys' for #<Supervisor:0x0000000baa9410>
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:436:in `method_missing'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:131:in `method_missing'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/attribute_assignment.rb:17:in `assign_attributes'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/core.rb:192:in `initialize'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/devise-3.3.0/lib/devise/models/confirmable.rb:47:in `initialize'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/inheritance.rb:27:in `new'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/inheritance.rb:27:in `new'
# ./app/mailers/synup_mailer.rb:13:in `confirmation_instructions'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/actionpack-4.0.0/lib/abstract_controller/base.rb:189:in `process_action'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/actionpack-4.0.0/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:373:in `_run__1572042514373682743__process_action__callbacks'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/actionpack-4.0.0/lib/abstract_controller/callbacks.rb:17:in `process_action'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/actionpack-4.0.0/lib/abstract_controller/base.rb:136:in `process'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/actionpack-4.0.0/lib/abstract_controller/rendering.rb:44:in `process'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:503:in `process'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:497:in `initialize'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:121:in `new'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:121:in `actual_message'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:97:in `initialize'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:40:in `new'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:40:in `method_missing'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/devise-3.3.0/lib/devise/models/authenticatable.rb:173:in `send_devise_notification'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/devise-3.3.0/lib/devise/models/confirmable.rb:102:in `send_confirmation_instructions'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/devise-3.3.0/lib/devise/models/confirmable.rb:158:in `send_on_create_confirmation_instructions'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:397:in `_run__462299154380556768__create__callbacks'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/callbacks.rb:303:in `create_record'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/timestamp.rb:57:in `create_record'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/persistence.rb:466:in `create_or_update'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/callbacks.rb:299:in `block in create_or_update'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:393:in `_run__462299154380556768__save__callbacks'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/callbacks.rb:299:in `create_or_update'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/persistence.rb:128:in `save!'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/validations.rb:57:in `save!'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/attribute_methods/dirty.rb:41:in `save!'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/transactions.rb:275:in `block in save!'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/ar_after_transaction-0.4.0/lib/ar_after_transaction.rb:19:in `block in transaction_with_after'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/transactions.rb:209:in `transaction'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/ar_after_transaction-0.4.0/lib/ar_after_transaction.rb:17:in `transaction_with_after'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/transactions.rb:275:in `save!'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.2.0/lib/factory_girl/configuration.rb:14:in `block in initialize'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.2.0/lib/factory_girl/evaluation.rb:15:in `[]'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.2.0/lib/factory_girl/evaluation.rb:15:in `create'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.2.0/lib/factory_girl/strategy/create.rb:12:in `block in result'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.2.0/lib/factory_girl/strategy/create.rb:9:in `tap'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.2.0/lib/factory_girl/strategy/create.rb:9:in `result'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.2.0/lib/factory_girl/factory.rb:42:in `run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.2.0/lib/factory_girl/factory_runner.rb:23:in `block in run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.0/lib/active_support/notifications.rb:161:in `instrument'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.2.0/lib/factory_girl/factory_runner.rb:22:in `run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/factory_girl-4.2.0/lib/factory_girl/strategy_syntax_method_registrar.rb:19:in `block in define_singular_strategy_method'
# ./spec/features/workflow_spec.rb:39:in `block (2 levels) in <top (required)>'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in `instance_eval'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in `block in run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:179:in `call'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:179:in `run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:247:in `instance_eval_with_args'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:87:in `block (2 levels) in run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:89:in `call'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:89:in `run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:418:in `run_hook'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:329:in `run_around_each_hooks'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:256:in `with_around_each_hooks'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:111:in `run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:390:in `block in run_examples'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in `map'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in `run_examples'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:371:in `run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `map'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block in run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/reporter.rb:34:in `report'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:25:in `run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
# /home/ananth/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

Postgresql prepared statement in Rails : PG::Error: ERROR: bind message supplies 1 parameters, but prepared statement "a4" requires 0

I have introduced a new field to a model file in my 4.0.0 Ruby on Rails application and added a validation to make sure it is unique using the following line:
validates_uniqueness_of :source_id
Immediately after that my RSpec/Capybara test suite started breaking with the following error message:
Failure/Error: let(:product) { FactoryGirl.create(:product) }
ActiveRecord::StatementInvalid:
PG::Error: ERROR: bind message supplies 1 parameters, but prepared statement "a4" requires 0
SELECT 1 AS one FROM "products" WHERE "products"."source_id" = 'Product GUID6' LIMIT 1
I understand this has to do with Postgresql prepared statements, but am not sure as to what needs to be done exactly to resolve this issue.
As an additional piece of information, I have updated the DB table with index for field "source_id" with unique: true option.
Your input is greatly appreciated.
I am using FactoryGirl gem to handle the creation of my model object such as:
let(:product) { FactoryGirl.create(:product) }
subject { product_dimension }
describe "method" do
it { should respond_to(:product) }
end
and here is the snippet from the actual Factories.rb file:
factory :product do
sequence(:source_id) { |n| "Product GUID#{n}" }
sequence(:title) { |n| "Prodcut #{n}" }
content "Lorem ipsum"
channel_id 1
end
Here is the exception stack trace:
1) ProductDimension method dimension
Failure/Error: let(:product) { FactoryGirl.create(:product) }
ActiveRecord::StatementInvalid:
PG::Error: ERROR: bind message supplies 1 parameters, but prepared statement "a4" requires 0
: SELECT 1 AS one FROM "products" WHERE "products"."source_id" = 'Product GUID6' LIMIT 1
# ./spec/models/product_dimension_spec.rb:4:in `block (2 levels) in <top (required)>'
# ./spec/models/product_dimension_spec.rb:7:in `block (2 levels) in <top (required)>'
# ./spec/models/product_dimension_spec.rb:9:in `block (2 levels) in <top (required)>'
# ./spec/models/product_dimension_spec.rb:28:in `block (3 levels) in <top (required)>'
Here is a more detailed stack trace:
1) ProductDimension methods dimension
Failure/Error: let(:product) { FactoryGirl.create(:product) }
ActiveRecord::StatementInvalid:
PG::Error: ERROR: bind message supplies 1 parameters, but prepared statement "a4" requires 0
: SELECT 1 AS one FROM "products" WHERE "products"."source_id" = 'GUID 6' LIMIT 1
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:780:in `get_last_result'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:780:in `exec_cache'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:139:in `block in exec_query'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:425:in `block in log'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:420:in `log'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:885:in `select'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:24:in `select_all'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:30:in `select_one'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:36:in `select_value'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/relation/finder_methods.rb:174:in `exists?'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/validations/uniqueness.rb:28:in `validate_each'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activemodel-4.0.0/lib/active_model/validator.rb:153:in `block in validate'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activemodel-4.0.0/lib/active_model/validator.rb:150:in `each'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activemodel-4.0.0/lib/active_model/validator.rb:150:in `validate'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:283:in `_callback_before_17'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:467:in `_run__2082443422329982594__validate__callbacks'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activemodel-4.0.0/lib/active_model/validations.rb:373:in `run_validations!'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activemodel-4.0.0/lib/active_model/validations/callbacks.rb:106:in `block in run_validations!'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:373:in `_run__2082443422329982594__validation__callbacks'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activemodel-4.0.0/lib/active_model/validations/callbacks.rb:106:in `run_validations!'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activemodel-4.0.0/lib/active_model/validations.rb:314:in `valid?'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/validations.rb:70:in `valid?'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/validations.rb:77:in `perform_validations'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/validations.rb:57:in `save!'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/attribute_methods/dirty.rb:41:in `save!'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/transactions.rb:275:in `block in save!'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/transactions.rb:209:in `transaction'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/transactions.rb:275:in `save!'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/factory_girl-4.2.0/lib/factory_girl/configuration.rb:14:in `block in initialize'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/factory_girl-4.2.0/lib/factory_girl/evaluation.rb:15:in `[]'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/factory_girl-4.2.0/lib/factory_girl/evaluation.rb:15:in `create'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/factory_girl-4.2.0/lib/factory_girl/strategy/create.rb:12:in `block in result'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/factory_girl-4.2.0/lib/factory_girl/strategy/create.rb:9:in `tap'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/factory_girl-4.2.0/lib/factory_girl/strategy/create.rb:9:in `result'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/factory_girl-4.2.0/lib/factory_girl/factory.rb:42:in `run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/factory_girl-4.2.0/lib/factory_girl/factory_runner.rb:23:in `block in run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/notifications.rb:161:in `instrument'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/factory_girl-4.2.0/lib/factory_girl/factory_runner.rb:22:in `run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/factory_girl-4.2.0/lib/factory_girl/strategy_syntax_method_registrar.rb:19:in `block in define_singular_strategy_method'
# ./spec/models/event_dimension_spec.rb:5:in `block (2 levels) in <top (required)>'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:199:in `block (2 levels) in let'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:199:in `fetch'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:199:in `block in let'
# ./spec/models/event_dimension_spec.rb:8:in `block (2 levels) in <top (required)>'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:199:in `block (2 levels) in let'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:199:in `fetch'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:199:in `block in let'
# ./spec/models/event_dimension_spec.rb:10:in `block (2 levels) in <top (required)>'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:199:in `block (2 levels) in let'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:199:in `fetch'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:199:in `block in let'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:433:in `block (2 levels) in its'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:199:in `block (2 levels) in let'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:199:in `fetch'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:199:in `block in let'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/memoized_helpers.rb:440:in `should'
# ./spec/models/event_dimension_spec.rb:32:in `block (3 levels) in <top (required)>'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example.rb:114:in `instance_eval'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example.rb:114:in `block in run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example.rb:179:in `call'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example.rb:179:in `run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example.rb:247:in `instance_eval_with_args'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/hooks.rb:87:in `block (2 levels) in run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/hooks.rb:89:in `call'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/hooks.rb:89:in `run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/hooks.rb:427:in `run_hook'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example_group.rb:339:in `run_around_each_hooks'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example.rb:256:in `with_around_each_hooks'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example.rb:111:in `run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example_group.rb:400:in `block in run_examples'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example_group.rb:396:in `map'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example_group.rb:396:in `run_examples'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example_group.rb:381:in `run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example_group.rb:382:in `block in run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example_group.rb:382:in `map'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example_group.rb:382:in `run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example_group.rb:382:in `block in run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example_group.rb:382:in `map'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/example_group.rb:382:in `run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/command_line.rb:28:in `map'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/command_line.rb:28:in `block in run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/reporter.rb:58:in `report'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/command_line.rb:25:in `run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/runner.rb:80:in `run'
# /Users/kirillberlin/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.4/lib/rspec/core/runner.rb:17:in `block in autorun'
This is a bug in ActiveRecord. It will be fixed in Rails 4.0.3.
I have figured it out. Thanks to #muistooshort for pointing me in the right direction with the last comment. There was an issue with the relationship between my models. It prompted me to revise the need for my ProductDimension model at which point I completely discarded it in favour of another approach.
I came across this error while Upgrading Rails from 5.1.3 to 5.2 and I was able to fix it by updating cancancan gem to the latest version i.e 3.0.2.

Testing models with RSpec using devise

I am using devise for authentication in my rails app and I'm unable to test any model with RSpec. Controller specs work fine, but I'm unable to make model specs work.
I am getting this error:
Failures:
1) Group should create new group
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `env' for nil:NilClass
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/whiny_nil.rb:48:in `method_missing'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/devise-1.4.2/lib/devise/test_helpers.rb:25:in `setup_controller_for_warden'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-rails-2.5.0/lib/rspec/rails/adapters.rb:11:in `block (2 levels) in setup'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:29:in `instance_eval'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:29:in `run_in'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `block in run_all'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `each'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `run_all'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:110:in `run_hook'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `block in eval_before_eachs'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `each'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `eval_before_eachs'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:144:in `run_before_each'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:48:in `block (2 levels) in run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:106:in `with_around_hooks'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:46:in `block in run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:99:in `block in with_pending_capture'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:98:in `catch'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:98:in `with_pending_capture'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:45:in `run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:262:in `block in run_examples'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:258:in `map'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:258:in `run_examples'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:232:in `run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `block (2 levels) in run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `map'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `block in run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/reporter.rb:12:in `report'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:24:in `run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:55:in `run_in_process'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:46:in `run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:10:in `block in autorun'
I have included
config.include Devise::TestHelpers
in my spec_helper.rb.
Here is my model test file
require 'spec_helper'
describe Group do
before :each do
#group = Factory.build(:group)
end
it "should create new group" do
Group.create!(#group)
end
end
This is my factories.rb file
Factory.define :group do |group|
group.name "Example group"
group.description "Example description"
end
How to fix this?
config.include Devise::TestHelpers, :type => :controller

Resources